Requests_SSL::verify_certificate() WordPress Method

The Requests_SSL::verify_certificate() method is used to verify the SSL certificate of a given domain. This is useful for ensuring that your connection to a given site is secure, and that the site is who it claims to be.

Requests_SSL::verify_certificate( string $host, array $cert ) #

Verify the certificate against common name and subject alternative names


Description

Unfortunately, PHP doesn’t check the certificate against the alternative names, leading things like ‘https://www.github.com/‘ to be invalid.

Top ↑

See also


Top ↑

Parameters

$host

(string)(Required)Host name to verify against

$cert

(array)(Required)Certificate data from openssl_x509_parse()


Top ↑

Return

(bool)


Top ↑

Source

File: wp-includes/Requests/SSL.php

	public static function verify_certificate($host, $cert) {
		$has_dns_alt = false;

		// Check the subjectAltName
		if (!empty($cert['extensions']) && !empty($cert['extensions']['subjectAltName'])) {
			$altnames = explode(',', $cert['extensions']['subjectAltName']);
			foreach ($altnames as $altname) {
				$altname = trim($altname);
				if (strpos($altname, 'DNS:') !== 0) {
					continue;
				}

				$has_dns_alt = true;

				// Strip the 'DNS:' prefix and trim whitespace
				$altname = trim(substr($altname, 4));

				// Check for a match
				if (self::match_domain($host, $altname) === true) {
					return true;
				}
			}
		}

		// Fall back to checking the common name if we didn't get any dNSName
		// alt names, as per RFC2818
		if (!$has_dns_alt && !empty($cert['subject']['CN'])) {
			// Check for a match
			if (self::match_domain($host, $cert['subject']['CN']) === true) {
				return true;
			}
		}

		return false;
	}

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.