diff --git a/phpseclib/Crypt/EC/BaseCurves/Binary.php b/phpseclib/Crypt/EC/BaseCurves/Binary.php index f35c01d2..d984ba4b 100644 --- a/phpseclib/Crypt/EC/BaseCurves/Binary.php +++ b/phpseclib/Crypt/EC/BaseCurves/Binary.php @@ -40,7 +40,7 @@ class Binary extends Base /** * Binary Field Integer factory * - * @var \phpseclib3\Math\BinaryFields + * @var \phpseclib3\Math\BinaryField */ protected $factory; diff --git a/phpseclib/Crypt/EC/BaseCurves/Montgomery.php b/phpseclib/Crypt/EC/BaseCurves/Montgomery.php index 5f5fdf0e..b4bba650 100644 --- a/phpseclib/Crypt/EC/BaseCurves/Montgomery.php +++ b/phpseclib/Crypt/EC/BaseCurves/Montgomery.php @@ -45,7 +45,7 @@ class Montgomery extends Base /** * Prime Field Integer factory * - * @var \phpseclib3\Math\PrimeFields + * @var \phpseclib3\Math\PrimeField */ protected $factory; diff --git a/phpseclib/File/X509.php b/phpseclib/File/X509.php index 639a0233..eb122b6b 100644 --- a/phpseclib/File/X509.php +++ b/phpseclib/File/X509.php @@ -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 @@ -303,6 +304,18 @@ class X509 */ private static $extensions = []; + /** + * @var ?array + * @access private + */ + private $ipAddresses = null; + + /** + * @var ?array + * @access private + */ + private $domains = null; + /** * Default Constructor. * @@ -3690,14 +3703,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)) { diff --git a/phpseclib/Math/BigInteger/Engines/Engine.php b/phpseclib/Math/BigInteger/Engines/Engine.php index 05d97431..10dd994b 100644 --- a/phpseclib/Math/BigInteger/Engines/Engine.php +++ b/phpseclib/Math/BigInteger/Engines/Engine.php @@ -1139,7 +1139,7 @@ abstract class Engine implements \Serializable * Splits BigInteger's into chunks of $split bits * * @param int $split - * @return \phpseclib3\Math\BigInteger\Engine[] + * @return \phpseclib3\Math\BigInteger\Engines\Engine[] */ public function bitwise_split($split) { diff --git a/phpseclib/System/SSH/Agent/Identity.php b/phpseclib/System/SSH/Agent/Identity.php index 9ef02dfa..20b0a958 100644 --- a/phpseclib/System/SSH/Agent/Identity.php +++ b/phpseclib/System/SSH/Agent/Identity.php @@ -119,7 +119,7 @@ class Identity implements PrivateKey */ public function withPublicKey($key) { - if ($key instanceof ECDSA) { + if ($key instanceof EC) { if (is_array($key->getCurve()) || !isset(self::$curveAliases[$key->getCurve()])) { throw new UnsupportedAlgorithmException('The only supported curves are nistp256, nistp384, nistp512 and Ed25519'); } diff --git a/tests/Unit/File/X509/X509Test.php b/tests/Unit/File/X509/X509Test.php index d8b51313..51b8cb1a 100644 --- a/tests/Unit/File/X509/X509Test.php +++ b/tests/Unit/File/X509/X509Test.php @@ -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)); + } }