Merge branch '3.0'

This commit is contained in:
terrafrost 2021-01-25 13:12:21 -06:00
commit 03e3db6ed2
6 changed files with 34 additions and 10 deletions

View File

@ -40,7 +40,7 @@ class Binary extends Base
/** /**
* Binary Field Integer factory * Binary Field Integer factory
* *
* @var \phpseclib3\Math\BinaryFields * @var \phpseclib3\Math\BinaryField
*/ */
protected $factory; protected $factory;

View File

@ -45,7 +45,7 @@ class Montgomery extends Base
/** /**
* Prime Field Integer factory * Prime Field Integer factory
* *
* @var \phpseclib3\Math\PrimeFields * @var \phpseclib3\Math\PrimeField
*/ */
protected $factory; protected $factory;

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
@ -303,6 +304,18 @@ class X509
*/ */
private static $extensions = []; private static $extensions = [];
/**
* @var ?array
* @access private
*/
private $ipAddresses = null;
/**
* @var ?array
* @access private
*/
private $domains = null;
/** /**
* Default Constructor. * Default Constructor.
* *
@ -3690,11 +3703,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

@ -1139,7 +1139,7 @@ abstract class Engine implements \Serializable
* Splits BigInteger's into chunks of $split bits * Splits BigInteger's into chunks of $split bits
* *
* @param int $split * @param int $split
* @return \phpseclib3\Math\BigInteger\Engine[] * @return \phpseclib3\Math\BigInteger\Engines\Engine[]
*/ */
public function bitwise_split($split) public function bitwise_split($split)
{ {

View File

@ -119,7 +119,7 @@ class Identity implements PrivateKey
*/ */
public function withPublicKey($key) public function withPublicKey($key)
{ {
if ($key instanceof ECDSA) { if ($key instanceof EC) {
if (is_array($key->getCurve()) || !isset(self::$curveAliases[$key->getCurve()])) { if (is_array($key->getCurve()) || !isset(self::$curveAliases[$key->getCurve()])) {
throw new UnsupportedAlgorithmException('The only supported curves are nistp256, nistp384, nistp512 and Ed25519'); throw new UnsupportedAlgorithmException('The only supported curves are nistp256, nistp384, nistp512 and Ed25519');
} }

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));
}
} }