$key->getLoadedFormat didn't work on EC / DSA keys

This commit is contained in:
terrafrost 2020-04-06 07:53:42 -05:00
parent ceff4cfbbc
commit 327a13d133
8 changed files with 14 additions and 15 deletions

View File

@ -24,7 +24,7 @@ use phpseclib3\Crypt\DSA;
use phpseclib3\Crypt\ECDSA;
/**
* Base Class for all stream cipher classes
* Base Class for all asymmetric cipher classes
*
* @package AsymmetricKey
* @author Jim Wigginton <terrafrost@php.net>
@ -173,8 +173,8 @@ abstract class AsymmetricKey
}
$components['format'] = $format;
$new = static::onLoad($components);
$new->format = $format;
return $new instanceof PrivateKey ?
$new->withPassword($password) :
$new;
@ -304,7 +304,7 @@ abstract class AsymmetricKey
* Returns the format of the loaded key.
*
* If the key that was loaded wasn't in a valid or if the key was auto-generated
* with RSA::createKey() then this will return false.
* with RSA::createKey() then this will throw an exception.
*
* @see self::load()
* @access public
@ -312,8 +312,8 @@ abstract class AsymmetricKey
*/
public function getLoadedFormat()
{
if ($this->format === false) {
return false;
if (empty($this->format)) {
throw new NoKeyLoadedException('This key was created with createKey - it was not loaded with load. Therefore there is no "loaded format"');
}
$meta = new \ReflectionClass($this->format);

View File

@ -95,7 +95,7 @@ abstract class DSA extends AsymmetricKey
* @var string
* @access private
*/
protected $format;
protected $sigFormat;
/**
* Signature Format (Short)
@ -263,7 +263,7 @@ abstract class DSA extends AsymmetricKey
*/
protected function __construct()
{
$this->format = self::validatePlugin('Signature', 'ASN1');
$this->sigFormat = self::validatePlugin('Signature', 'ASN1');
$this->shortFormat = 'ASN1';
parent::__construct();
@ -329,7 +329,7 @@ abstract class DSA extends AsymmetricKey
{
$new = clone $this;
$new->shortFormat = $format;
$new->format = self::validatePlugin('Signature', $format);
$new->sigFormat = self::validatePlugin('Signature', $format);
return $new;
}

View File

@ -85,7 +85,7 @@ class PrivateKey extends DSA implements Common\PrivateKey
*/
public function sign($message)
{
$format = $this->format;
$format = $this->sigFormat;
if (self::$engines['OpenSSL'] && in_array($this->hash->getHash(), openssl_get_md_methods())) {
$signature = '';

View File

@ -40,7 +40,7 @@ class PublicKey extends DSA implements Common\PublicKey
*/
public function verify($message, $signature)
{
$format = $this->format;
$format = $this->sigFormat;
$params = $format::load($signature);
if ($params === false || count($params) != 2) {

View File

@ -244,7 +244,7 @@ abstract class EC extends AsymmetricKey
*/
protected function __construct()
{
$this->format = self::validatePlugin('Signature', 'ASN1');
$this->sigFormat = self::validatePlugin('Signature', 'ASN1');
$this->shortFormat = 'ASN1';
parent::__construct();
@ -383,7 +383,7 @@ abstract class EC extends AsymmetricKey
$new = clone $this;
$new->shortFormat = $format;
$new->format = self::validatePlugin('Signature', $format);
$new->sigFormat = self::validatePlugin('Signature', $format);
return $new;
}

View File

@ -100,7 +100,7 @@ class PrivateKey extends EC implements Common\PrivateKey
$order = $this->curve->getOrder();
$shortFormat = $this->shortFormat;
$format = $this->format;
$format = $this->sigFormat;
if ($format === false) {
return false;
}

View File

@ -52,7 +52,7 @@ class PublicKey extends EC implements Common\PublicKey
}
$shortFormat = $this->shortFormat;
$format = $this->format;
$format = $this->sigFormat;
if ($format === false) {
return false;
}

View File

@ -407,7 +407,6 @@ abstract class RSA extends AsymmetricKey
new PublicKey :
new PrivateKey;
$key->format = $components['format'];
$key->modulus = $components['modulus'];
$key->publicExponent = $components['publicExponent'];
$key->k = $key->modulus->getLengthInBytes();