|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #68265 TLS/SSL connections do not honour the SubjectAltName within certificates
Submitted: 2014-10-19 12:57 UTC Modified: 2015-03-05 07:07 UTC
Avg. Score:4.9 ± 0.3
Reproduced:7 of 7 (100.0%)
Same Version:6 (85.7%)
Same OS:7 (100.0%)
From: Assigned: rdlowrey (profile)
Status: Closed Package: OpenSSL related
PHP Version: 5.6.2 OS: Linux
Private report: No CVE-ID: None
 [2014-10-19 12:57 UTC]
As reported here

--cut here--
Dear Maintainer,

as PHP5.6 enabled peer verification by default I noticed that the
verification does not account the Subject Alternative Names within the
certificate. Upstream knows already a bug to this:
  Bug #55236	Can't open a connection via TLS

The problem get noticeable, when you try to connect to an SSL secured
service via fsockopen() and the hostname used to connect is differing
from the certificates Common Name. Take this example:

kandre@mainframe(pts/12) ~ % openssl s_client -starttls smtp -connect -CApath /etc/ssl/certs
depth=2 C = BE, O = GlobalSign nv-sa, OU = Root CA, CN = GlobalSign Root CA
verify return:1
depth=1 C = BE, O = GlobalSign nv-sa, CN = GlobalSign Organization Validation CA - G2
verify return:1
depth=0 C = US, ST = Washington, L = Redmond, O = Microsoft Corporation, CN = *
verify return:1
Certificate chain
 0 s:/C=US/ST=Washington/L=Redmond/O=Microsoft Corporation/CN=*
   i:/C=BE/O=GlobalSign nv-sa/CN=GlobalSign Organization Validation CA - G2
 1 s:/C=BE/O=GlobalSign nv-sa/CN=GlobalSign Organization Validation CA - G2
   i:/C=BE/O=GlobalSign nv-sa/OU=Root CA/CN=GlobalSign Root CA

Openssl is properly verifying the certificate and comes to the
conclusion, that the certificate CN=*,X509v3 Subject
Alternative Name: DNS:*, DNS:*, DNS:*, is valid for, but php fails to do so.

This could break any application that connects to a SSL secured service
where the connection hostname is not directly within the CommonName
field. From my perspective there is no workaround available except
changing the hostname to connect to into one that is mentioned in the
common name, which fails for the mentioned example, as Microsoft is
(seemingly) not offering any alternative hostname.

Thanks and kind regards,
--cut here--

The example cert can be retrieved by doing:

# openssl s_client -connect

and copy the PEM output to a file (cert.pem).

The x509 content can be checked with:

# openssl x509 -text -in cert.pem -noout

and it has following names:
        Subject: C=DE, ST=SN, L=Dresden, O=Andre Kl\xE4rner IT-Dienstleistungen, OU=Hosting,
            X509v3 Subject Alternative Name: 


Test script:
c_rehash .
cat > ssl-test-debs.php << EOF
# run with the following is you have hashed root certificates under /etc/ssl/certs
# -d openssl.capath=$(pwd)

foreach (array("ssl://","ssl://") as $host){
	echo "trying to connect to $host\n";
	$fp = fsockopen($host, 993, $errno, $errstr, 3);
	if (!$fp) {
	    echo "$errstr ($errno)\n";
	} else {
	    echo "connection succeeded\n";
php -d openssl.capath=$(pwd) ssl-test-debs.php 

Expected result:
connection succeeded
connection succeeded

Actual result:
trying to connect to ssl://
PHP Warning:  fsockopen(): Peer certificate CN=`' did not match expected CN=`' in /tmp/php/ssl-test-debs.php on line 8
PHP Warning:  fsockopen(): Failed to enable crypto in /tmp/php/ssl-test-debs.php on line 8
PHP Warning:  fsockopen(): unable to connect to ssl:// (Unknown error) in /tmp/php/ssl-test-debs.php on line 8
trying to connect to ssl://
connection succeeded


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2015-03-05 06:59 UTC]
Automatic comment on behalf of rdlowrey
Log: Fixed bug #68265 (SAN match fails with trailing DNS dot)
 [2015-03-05 06:59 UTC]
-Status: Open +Status: Closed
 [2015-03-05 07:00 UTC]
Automatic comment on behalf of rdlowrey
Log: Fixed bug #68265 (SAN match fails with trailing DNS dot)
 [2015-03-05 07:07 UTC]
-Assigned To: +Assigned To: rdlowrey
 [2015-03-05 07:07 UTC]
SAN fields are consulted for peer name verification as of 5.6.0. However, the problem here was actually that valid FQDN names ending in dots were not matched correctly during the SAN checks. This meant that the (valid) DNS names in your SAN entry were not correctly matched:,

^ The trailing dots were the issue.

Your transfers would have succeeded by simply assigning a manual "peer_name" => "" setting (without the trailing dot). However, as the trailing period is technically correct this scenario is now accounted for when checking SAN names.

Thanks for the report.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 05:01:33 2024 UTC