mirror of
https://github.com/phpseclib/phpseclib.git
synced 2025-01-13 18:02:58 +00:00
X509: URL validation didn't work (#1203)
This commit is contained in:
parent
817bebef47
commit
ffcff461c4
@ -2062,30 +2062,32 @@ class File_X509
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($names = $this->getExtension('id-ce-subjectAltName')) {
|
if ($names = $this->getExtension('id-ce-subjectAltName')) {
|
||||||
foreach ($names as $key => $value) {
|
foreach ($names as $name) {
|
||||||
$value = str_replace(array('.', '*'), array('\.', '[^.]*'), $value);
|
foreach ($name as $key => $value) {
|
||||||
switch ($key) {
|
$value = str_replace(array('.', '*'), array('\.', '[^.]*'), $value);
|
||||||
case 'dNSName':
|
switch ($key) {
|
||||||
/* From RFC2818 "HTTP over TLS":
|
case 'dNSName':
|
||||||
|
/* From RFC2818 "HTTP over TLS":
|
||||||
|
|
||||||
If a subjectAltName extension of type dNSName is present, that MUST
|
If a subjectAltName extension of type dNSName is present, that MUST
|
||||||
be used as the identity. Otherwise, the (most specific) Common Name
|
be used as the identity. Otherwise, the (most specific) Common Name
|
||||||
field in the Subject field of the certificate MUST be used. Although
|
field in the Subject field of the certificate MUST be used. Although
|
||||||
the use of the Common Name is existing practice, it is deprecated and
|
the use of the Common Name is existing practice, it is deprecated and
|
||||||
Certification Authorities are encouraged to use the dNSName instead. */
|
Certification Authorities are encouraged to use the dNSName instead. */
|
||||||
if (preg_match('#^' . $value . '$#', $components['host'])) {
|
if (preg_match('#^' . $value . '$#', $components['host'])) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'iPAddress':
|
case 'iPAddress':
|
||||||
/* From RFC2818 "HTTP over TLS":
|
/* From RFC2818 "HTTP over TLS":
|
||||||
|
|
||||||
In some cases, the URI is specified as an IP address rather than a
|
In some cases, the URI is specified as an IP address rather than a
|
||||||
hostname. In this case, the iPAddress subjectAltName must be present
|
hostname. In this case, the iPAddress subjectAltName must be present
|
||||||
in the certificate and must exactly match the IP in the URI. */
|
in the certificate and must exactly match the IP in the URI. */
|
||||||
if (preg_match('#(?:\d{1-3}\.){4}#', $components['host'] . '.') && preg_match('#^' . $value . '$#', $components['host'])) {
|
if (preg_match('#(?:\d{1-3}\.){4}#', $components['host'] . '.') && preg_match('#^' . $value . '$#', $components['host'])) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -458,4 +458,41 @@ F7xAUxmPUnNb2teatMf2Rmj0fs+d
|
|||||||
$this->assertEquals($cert['tbsCertificate']['validity']['notBefore']['utcTime'], 'Tue, 07 Jan 2014 00:00:00 +0000');
|
$this->assertEquals($cert['tbsCertificate']['validity']['notBefore']['utcTime'], 'Tue, 07 Jan 2014 00:00:00 +0000');
|
||||||
$this->assertEquals($cert['tbsCertificate']['validity']['notAfter']['utcTime'], 'Fri, 01 Apr 2016 07:00:00 +0000');
|
$this->assertEquals($cert['tbsCertificate']['validity']['notAfter']['utcTime'], 'Fri, 01 Apr 2016 07:00:00 +0000');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testValidateURL()
|
||||||
|
{
|
||||||
|
$test = '-----BEGIN CERTIFICATE-----
|
||||||
|
MIIEgDCCA2igAwIBAgIIPUwrl6kGL2QwDQYJKoZIhvcNAQELBQAwSTELMAkGA1UE
|
||||||
|
BhMCVVMxEzARBgNVBAoTCkdvb2dsZSBJbmMxJTAjBgNVBAMTHEdvb2dsZSBJbnRl
|
||||||
|
cm5ldCBBdXRob3JpdHkgRzIwHhcNMTcxMDI0MDkwMjMxWhcNMTcxMjI5MDAwMDAw
|
||||||
|
WjBoMQswCQYDVQQGEwJVUzETMBEGA1UECAwKQ2FsaWZvcm5pYTEWMBQGA1UEBwwN
|
||||||
|
TW91bnRhaW4gVmlldzETMBEGA1UECgwKR29vZ2xlIEluYzEXMBUGA1UEAwwOd3d3
|
||||||
|
Lmdvb2dsZS5jb20wggEiMA0GCS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||
|
oFzpU8xsv/87L7UcJoCge2ZR4kANgjmJ12TG7dCcPpbH2qu7Y8wnWubik5U68gsI
|
||||||
|
Qopg3hKg24p645o4exwsd/lOrsqh3vPorwZwU2Ekd2wKdxBID3puQA1jvWOBUcJI
|
||||||
|
Oe2K7+R2Cf6p8bYmm3OABuYkvO8D+u8gIdIO5cP+ic+SDOGVNJaT949YPes/S99R
|
||||||
|
9NQRFKcjEPl1UYh5bpPTKYzS7cTcDYG6xvbtG/XKEsK5U9UggzY6PCOPDDYpF+rq
|
||||||
|
C47x9g==
|
||||||
|
-----END CERTIFICATE-----';
|
||||||
|
|
||||||
|
$x509 = new File_X509();
|
||||||
|
|
||||||
|
$cert = $x509->loadX509($test);
|
||||||
|
|
||||||
|
$this->assertTrue($x509->validateURL('https://www.google.com'));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user