WpOrg\Requests

Ssl::verify_reference_name()public staticWP 1.0

Verify that a reference name is valid

Verifies a dNSName for HTTPS usage, (almost) as per Firefox's rules:

  • Wildcards can only occur in a name with more than 3 components
  • Wildcards can only occur as the last character in the first component
  • Wildcards may be preceded by additional characters

We modify these rules to be a bit stricter and only allow the wildcard character to be the full first component; that is, with the exclusion of the third rule.

Method of the class: Ssl{}

No Hooks.

Return

true|false. Is the name valid?

Usage

$result = Ssl::verify_reference_name( $reference );
$reference(string|Stringable) (required)
Reference dNSName

Ssl::verify_reference_name() code WP 6.6.2

public static function verify_reference_name($reference) {
	if (InputValidator::is_string_or_stringable($reference) === false) {
		throw InvalidArgument::create(1, '$reference', 'string|Stringable', gettype($reference));
	}

	if ($reference === '') {
		return false;
	}

	if (preg_match('`\s`', $reference) > 0) {
		// Whitespace detected. This can never be a dNSName.
		return false;
	}

	$parts = explode('.', $reference);
	if ($parts !== array_filter($parts)) {
		// DNSName cannot contain two dots next to each other.
		return false;
	}

	// Check the first part of the name
	$first = array_shift($parts);

	if (strpos($first, '*') !== false) {
		// Check that the wildcard is the full part
		if ($first !== '*') {
			return false;
		}

		// Check that we have at least 3 components (including first)
		if (count($parts) < 2) {
			return false;
		}
	}

	// Check the remaining parts
	foreach ($parts as $part) {
		if (strpos($part, '*') !== false) {
			return false;
		}
	}

	// Nothing found, verified!
	return true;
}