Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incomplete validation of IP Address fields in subjectAltNames #9356

Closed
lucasnetau opened this issue Aug 17, 2022 · 0 comments
Closed

Incomplete validation of IP Address fields in subjectAltNames #9356

lucasnetau opened this issue Aug 17, 2022 · 0 comments

Comments

@lucasnetau
Copy link
Contributor

Description

Peer verification [ext/openssl/xp_ssl.c -> php_openssl_matches_san_list()] via an IP address in the SAN list is incomplete

  • IPv4 Addresses are validated on all IP ranges including including reserve IP addresses which is deprecated
  • IPv6 Addresses validation is not implemented at all with the follow comment

No, we aren't bothering to check IPv6 addresses. Why?
Because IP SAN names are officially deprecated and are
not allowed by CAs starting in 2015. Deal with it.

IPv6 addresses not in reserved IP range can be included in SAN lists per https://www.digicert.com/kb/advisories/internal-names.htm and is used by Google and CloudFlare for their DNS over HTTPS services

Connecting to a HTTPS server via IPv6 is useful for DNS over HTTPS clients, not verifying peer removes the security gained.

The following code:

<?php

$dns = '2001:4860:4860::8888'; //dns.google IPv6

$context = stream_context_create();
stream_context_set_option($context, 'ssl', 'verify_host', true);
stream_context_set_option($context, 'ssl', 'verify_peer_name', true);
stream_context_set_option($context, 'ssl', 'SNI_server_name', $dns);
stream_context_set_option($context, 'ssl', 'peer_name', $dns);

$socket = stream_socket_client("tls://[$dns]:443", $errno, $errstr, 5, STREAM_CLIENT_CONNECT, $context);
if($socket == FALSE)
{
    echo "error: $errstr ($errno)\n";
    exit(1);
}

echo 'connected';

Resulted in this output:

Warning: stream_socket_client(): Peer certificate CN=`dns.google' did not match expected CN=`2001:4860:4860:0000:0000:0000:0000:8888'
PHP Warning:  stream_socket_client(): Failed to enable crypto 

But I expected this output instead:

connected

PHP Version

PHP 8.1.9

Operating System

No response

lucasnetau added a commit to lucasnetau/php-src that referenced this issue Apr 28, 2023
…ectAltNames

IPv6 addresses are valid entries in subjectAltNames. Certificate Authorities may issue certificates including IPv6 addresses except if they fall within addresses in the RFC 4193 range. Google and CloudFlare provide IPv6 addresses in their DNS over HTTPS services.

Internal CAs do not have those restrictions and can issue Unique local addresses in certificates.
lucasnetau added a commit to lucasnetau/php-src that referenced this issue May 9, 2023
…ectAltNames

IPv6 addresses are valid entries in subjectAltNames. Certificate Authorities may issue certificates including IPv6 addresses except if they fall within addresses in the RFC 4193 range. Google and CloudFlare provide IPv6 addresses in their DNS over HTTPS services.

Internal CAs do not have those restrictions and can issue Unique local addresses in certificates.
bukka pushed a commit that referenced this issue Jun 9, 2023
IPv6 addresses are valid entries in subjectAltNames. Certificate
Authorities may issue certificates including IPv6 addresses except
if they fall within addresses in the RFC 4193 range. Google and
CloudFlare provide IPv6 addresses in their DNS over HTTPS services.

Internal CAs do not have those restrictions and can issue Unique
local addresses in certificates.

Closes GH-11145
@nielsdos nielsdos closed this as completed Jun 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants