88
99namespace WpOrg \Requests ;
1010
11+ use WpOrg \Requests \Exception \InvalidArgument ;
12+ use WpOrg \Requests \Utility \InputValidator ;
13+
1114/**
1215 * SSL utilities for Requests
1316 *
@@ -28,8 +31,18 @@ final class Ssl {
2831 * @param string $host Host name to verify against
2932 * @param array $cert Certificate data from openssl_x509_parse()
3033 * @return bool
34+ * @throws \WpOrg\Requests\Exception\InvalidArgument When the passed $host argument is not a string or a stringable object.
35+ * @throws \WpOrg\Requests\Exception\InvalidArgument When the passed $cert argument is not an array or array accessible.
3136 */
3237 public static function verify_certificate ($ host , $ cert ) {
38+ if (InputValidator::is_string_or_stringable ($ host ) === false ) {
39+ throw InvalidArgument::create (1 , '$host ' , 'string|Stringable ' , gettype ($ host ));
40+ }
41+
42+ if (InputValidator::has_array_access ($ cert ) === false ) {
43+ throw InvalidArgument::create (2 , '$cert ' , 'array|ArrayAccess ' , gettype ($ cert ));
44+ }
45+
3346 $ has_dns_alt = false ;
3447
3548 // Check the subjectAltName
@@ -82,8 +95,13 @@ public static function verify_certificate($host, $cert) {
8295 *
8396 * @param string $reference Reference dNSName
8497 * @return boolean Is the name valid?
98+ * @throws \WpOrg\Requests\Exception\InvalidArgument When the passed argument is not a string or a stringable object.
8599 */
86100 public static function verify_reference_name ($ reference ) {
101+ if (InputValidator::is_string_or_stringable ($ reference ) === false ) {
102+ throw InvalidArgument::create (1 , '$reference ' , 'string|Stringable ' , gettype ($ reference ));
103+ }
104+
87105 $ parts = explode ('. ' , $ reference );
88106
89107 // Check the first part of the name
@@ -118,8 +136,13 @@ public static function verify_reference_name($reference) {
118136 * @param string $host Requested host
119137 * @param string $reference dNSName to match against
120138 * @return boolean Does the domain match?
139+ * @throws \WpOrg\Requests\Exception\InvalidArgument When either of the passed arguments is not a string or a stringable object.
121140 */
122141 public static function match_domain ($ host , $ reference ) {
142+ if (InputValidator::is_string_or_stringable ($ host ) === false ) {
143+ throw InvalidArgument::create (1 , '$host ' , 'string|Stringable ' , gettype ($ host ));
144+ }
145+
123146 // Check if the reference is blocklisted first
124147 if (self ::verify_reference_name ($ reference ) !== true ) {
125148 return false ;
0 commit comments