Merge branch '3.0'

This commit is contained in:
terrafrost 2022-02-14 21:19:59 -06:00
commit e2f9d10660
4 changed files with 12 additions and 13 deletions

View File

@ -523,11 +523,13 @@ abstract class PKCS8 extends PKCS
$key = [ $key = [
'version' => 'v1', 'version' => 'v1',
'privateKeyAlgorithm' => [ 'privateKeyAlgorithm' => [
'algorithm' => is_string(static::OID_NAME) ? static::OID_NAME : $oid, 'algorithm' => is_string(static::OID_NAME) ? static::OID_NAME : $oid
'parameters' => $params
], ],
'privateKey' => $key 'privateKey' => $key
]; ];
if ($oid != 'id-Ed25519' && $oid != 'id-Ed448') {
$key['privateKeyAlgorithm']['parameters'] = $params;
}
if (!empty($attr)) { if (!empty($attr)) {
$key['attributes'] = $attr; $key['attributes'] = $attr;
} }

View File

@ -130,7 +130,7 @@ abstract class PKCS8 extends Progenitor
$params = ASN1::encodeDER($params, Maps\DHParameter::MAP); $params = ASN1::encodeDER($params, Maps\DHParameter::MAP);
$params = new ASN1\Element($params); $params = new ASN1\Element($params);
$key = ASN1::encodeDER($privateKey, ['type' => ASN1::TYPE_INTEGER]); $key = ASN1::encodeDER($privateKey, ['type' => ASN1::TYPE_INTEGER]);
return self::wrapPrivateKey($key, [], $params, $password, $options); return self::wrapPrivateKey($key, [], $params, $password, null, '', $options);
} }
/** /**

View File

@ -226,8 +226,7 @@ abstract class PKCS8 extends Progenitor
[], [],
null, null,
$password, $password,
$curve instanceof Ed25519 ? 'id-Ed25519' : 'id-Ed448', $curve instanceof Ed25519 ? 'id-Ed25519' : 'id-Ed448'
"\0" . $curve->encodePoint($publicKey)
); );
} }

View File

@ -271,9 +271,11 @@ MCwwBwYDK2VwBQADIQAZv0QJaYTN/oVBusFn3DuWyFCGqjC2tssMXDitcDFm4Q==
public function testEd25519PrivateKey() public function testEd25519PrivateKey()
{ {
// without public key (public key should be derived) // without public key (public key should be derived)
$key = PublicKeyLoader::load('-----BEGIN PRIVATE KEY----- $expected = '-----BEGIN PRIVATE KEY-----
MC4CAQAwBQYDK2VwBCIEINTuctv5E1hK1bbY8fdp+K06/nwoy/HU++CXqI9EdVhC MC4CAQAwBQYDK2VwBCIEINTuctv5E1hK1bbY8fdp+K06/nwoy/HU++CXqI9EdVhC
-----END PRIVATE KEY-----'); -----END PRIVATE KEY-----';
$key = PublicKeyLoader::load($expected);
$this->assertSameNL($expected, $key->toString('PKCS8'));
$this->assertSameNL('Ed25519', $key->getCurve()); $this->assertSameNL('Ed25519', $key->getCurve());
$this->assertSameNL('Ed25519', $key->getPublicKey()->getCurve()); $this->assertSameNL('Ed25519', $key->getPublicKey()->getCurve());
@ -289,14 +291,10 @@ Z9w7lshQhqowtrbLDFw4rXAxZuE=
// the above key not only omits NULL - it also includes a // the above key not only omits NULL - it also includes a
// unstructuredName attribute with a value of "Curdle Chairs" // unstructuredName attribute with a value of "Curdle Chairs"
// that the following key does not have // that the following key does not have
$expected = '-----BEGIN PRIVATE KEY----- $key = PublicKeyLoader::load('-----BEGIN PRIVATE KEY-----
MFMCAQEwBwYDK2VwBQAEIgQg1O5y2/kTWErVttjx92n4rTr+fCjL8dT74Jeoj0R1 MFMCAQEwBwYDK2VwBQAEIgQg1O5y2/kTWErVttjx92n4rTr+fCjL8dT74Jeoj0R1
WEKBIQAZv0QJaYTN/oVBusFn3DuWyFCGqjC2tssMXDitcDFm4Q== WEKBIQAZv0QJaYTN/oVBusFn3DuWyFCGqjC2tssMXDitcDFm4Q==
-----END PRIVATE KEY-----'; -----END PRIVATE KEY-----');
$this->assertSameNL($expected, $key->toString('PKCS8'));
$expected = EC::createKey('Ed25519')->toString('PKCS8');
$key = PublicKeyLoader::load($expected);
$this->assertSameNL('Ed25519', $key->getCurve()); $this->assertSameNL('Ed25519', $key->getCurve());
$this->assertSameNL('Ed25519', $key->getPublicKey()->getCurve()); $this->assertSameNL('Ed25519', $key->getPublicKey()->getCurve());
} }