1
0
mirror of https://github.com/danog/phpseclib.git synced 2024-12-12 00:59:48 +01:00

X509: fix niche issue with computeKeyIdentifier

This commit is contained in:
terrafrost 2021-01-25 12:17:36 -06:00
parent e8b4e4d4df
commit 3d4767301c
2 changed files with 18 additions and 6 deletions

View File

@ -43,6 +43,7 @@ use phpseclib3\Exception\UnsupportedAlgorithmException;
use phpseclib3\File\ASN1\Element; use phpseclib3\File\ASN1\Element;
use phpseclib3\File\ASN1\Maps; use phpseclib3\File\ASN1\Maps;
use phpseclib3\Math\BigInteger; use phpseclib3\Math\BigInteger;
use phpseclib3\Crypt\PublicKeyLoader;
/** /**
* Pure-PHP X.509 Parser * Pure-PHP X.509 Parser
@ -3690,11 +3691,8 @@ class X509
return false; return false;
} }
// If the key is private, compute identifier from its corresponding public key. // If the key is private, compute identifier from its corresponding public key.
$key = new RSA(); $key = PublicKeyLoader::load($raw);
if (!$key->load($raw)) { if ($key instanceof PrivateKey) { // If private.
return false; // Not an unencrypted RSA key.
}
if ($key->getPrivateKey() !== false) { // If private.
return $this->computeKeyIdentifier($key, $method); return $this->computeKeyIdentifier($key, $method);
} }
$key = $raw; // Is a public key. $key = $raw; // Is a public key.

View File

@ -1176,4 +1176,18 @@ qzFkAKWjJj4KjfrbZX4C0Spfxw==
$this->assertIsArray($r); $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));
}
} }