mirror of
https://github.com/danog/phpseclib.git
synced 2024-12-03 18:18:05 +01:00
X509: fix niche issue with computeKeyIdentifier
This commit is contained in:
parent
e8b4e4d4df
commit
3d4767301c
@ -43,6 +43,7 @@ use phpseclib3\Exception\UnsupportedAlgorithmException;
|
||||
use phpseclib3\File\ASN1\Element;
|
||||
use phpseclib3\File\ASN1\Maps;
|
||||
use phpseclib3\Math\BigInteger;
|
||||
use phpseclib3\Crypt\PublicKeyLoader;
|
||||
|
||||
/**
|
||||
* Pure-PHP X.509 Parser
|
||||
@ -3690,14 +3691,11 @@ class X509
|
||||
return false;
|
||||
}
|
||||
// If the key is private, compute identifier from its corresponding public key.
|
||||
$key = new RSA();
|
||||
if (!$key->load($raw)) {
|
||||
return false; // Not an unencrypted RSA key.
|
||||
}
|
||||
if ($key->getPrivateKey() !== false) { // If private.
|
||||
$key = PublicKeyLoader::load($raw);
|
||||
if ($key instanceof PrivateKey) { // If private.
|
||||
return $this->computeKeyIdentifier($key, $method);
|
||||
}
|
||||
$key = $raw; // Is a public key.
|
||||
$key = $raw; // Is a public key.
|
||||
break;
|
||||
case $key instanceof X509:
|
||||
if (isset($key->publicKey)) {
|
||||
|
@ -1176,4 +1176,18 @@ qzFkAKWjJj4KjfrbZX4C0Spfxw==
|
||||
|
||||
$this->assertIsArray($r);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group github1586
|
||||
*/
|
||||
public function testComputeKeyIdentifier()
|
||||
{
|
||||
$key = RSA::createKey(512);
|
||||
$key = ASN1::extractBER("$key");
|
||||
$key = ASN1::encodeDER($key, ['type' => ASN1::TYPE_BIT_STRING]);
|
||||
$key = new Element($key);
|
||||
|
||||
$x509 = new X509;
|
||||
$this->assertIsString($x509->computeKeyIdentifier($key));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user