Skip to content

Commit fe3765f

Browse files
committed
X509: don't validate self-signed certs by default
1 parent 9bcee47 commit fe3765f

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

phpseclib/File/X509.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,9 @@
5353
/**
5454
* Flag to only accept signatures signed by certificate authorities
5555
*
56+
* Not really used anymore but retained all the same to suppress E_NOTICEs from old installs
57+
*
5658
* @access public
57-
* @see File_X509::validateSignature()
5859
*/
5960
define('FILE_X509_VALIDATE_SIGNATURE_BY_CA', 1);
6061

@@ -1989,13 +1990,16 @@ function validateDate($date = NULL)
19891990
* Works on X.509 certs, CSR's and CRL's.
19901991
* Returns true if the signature is verified, false if it is not correct or NULL on error
19911992
*
1993+
* By default returns false for self-signed certs. Call validateSignature(false) to make this support
1994+
* self-signed.
1995+
*
19921996
* The behavior of this function is inspired by {@link http://php.net/openssl-verify openssl_verify}.
19931997
*
1994-
* @param Integer $options optional
1998+
* @param Boolean $caonly optional
19951999
* @access public
19962000
* @return Mixed
19972001
*/
1998-
function validateSignature($options = 0)
2002+
function validateSignature($caonly = true)
19992003
{
20002004
if (!is_array($this->currentCert) || !isset($this->signatureSubject)) {
20012005
return 0;
@@ -2036,10 +2040,10 @@ function validateSignature($options = 0)
20362040
}
20372041
}
20382042
}
2039-
if (count($this->CAs) == $i && ($options & FILE_X509_VALIDATE_SIGNATURE_BY_CA)) {
2043+
if (count($this->CAs) == $i && $caonly) {
20402044
return false;
20412045
}
2042-
} elseif (!isset($signingCert) || ($options & FILE_X509_VALIDATE_SIGNATURE_BY_CA)) {
2046+
} elseif (!isset($signingCert) || $caonly) {
20432047
return false;
20442048
}
20452049
return $this->_validateSignature(

0 commit comments

Comments
 (0)