Merge branch '3.0'

This commit is contained in:
terrafrost 2022-07-15 09:18:37 -05:00
commit a9c3f10de4
2 changed files with 8 additions and 12 deletions

View File

@ -600,12 +600,15 @@ abstract class PKCS8 extends PKCS
$key = [ $key = [
'publicKeyAlgorithm' => [ 'publicKeyAlgorithm' => [
'algorithm' => is_string(static::OID_NAME) ? static::OID_NAME : $oid, 'algorithm' => is_string(static::OID_NAME) ? static::OID_NAME : $oid
'parameters' => $params
], ],
'publicKey' => "\0" . $key 'publicKey' => "\0" . $key
]; ];
if ($oid != 'id-Ed25519' && $oid != 'id-Ed448') {
$key['publicKeyAlgorithm']['parameters'] = $params;
}
$key = ASN1::encodeDER($key, Maps\PublicKeyInfo::MAP); $key = ASN1::encodeDER($key, Maps\PublicKeyInfo::MAP);
return "-----BEGIN PUBLIC KEY-----\r\n" . return "-----BEGIN PUBLIC KEY-----\r\n" .

View File

@ -258,18 +258,11 @@ BjoJZJZQztmlj7Qep/sf1l8=
// from https://tools.ietf.org/html/draft-ietf-curdle-pkix-07#section-10.1 // from https://tools.ietf.org/html/draft-ietf-curdle-pkix-07#section-10.1
public function testEd25519PublicKey(): void public function testEd25519PublicKey(): void
{ {
$key = PublicKeyLoader::load('-----BEGIN PUBLIC KEY-----
MCowBQYDK2VwAyEAGb9ECWmEzf6FQbrBZ9w7lshQhqowtrbLDFw4rXAxZuE=
-----END PUBLIC KEY-----');
$this->assertSameNL('Ed25519', $key->getCurve());
// in the above key AlgorithmIdentifier has a single "child". in the
// following key it has two. The second one is ("optional") NULL.
// https://security.stackexchange.com/q/110330/15922 elaborates on
// why phpseclib is encoding the NULL as opposed to omitting it.
$expected = '-----BEGIN PUBLIC KEY----- $expected = '-----BEGIN PUBLIC KEY-----
MCwwBwYDK2VwBQADIQAZv0QJaYTN/oVBusFn3DuWyFCGqjC2tssMXDitcDFm4Q== MCowBQYDK2VwAyEAGb9ECWmEzf6FQbrBZ9w7lshQhqowtrbLDFw4rXAxZuE=
-----END PUBLIC KEY-----'; -----END PUBLIC KEY-----';
$key = PublicKeyLoader::load($expected);
$this->assertSameNL('Ed25519', $key->getCurve());
$this->assertSameNL($expected, $key->toString('PKCS8')); $this->assertSameNL($expected, $key->toString('PKCS8'));
} }