mirror of
https://github.com/phpseclib/phpseclib.git
synced 2024-12-24 02:55:30 +00:00
Added support for absent parameters field in PSS keys
See [here](https://tools.ietf.org/html/rfc4055#section-3.1) for details.
This commit is contained in:
parent
c1b70c21cb
commit
131459996b
@ -120,11 +120,16 @@ abstract class PSS extends Progenitor
|
||||
|
||||
$result = $components + PKCS1::load($key[$type . 'Key']);
|
||||
|
||||
$decoded = ASN1::decodeBER($key[$type . 'KeyAlgorithm']['parameters']);
|
||||
if ($decoded === false) {
|
||||
throw new \UnexpectedValueException('Unable to decode parameters');
|
||||
if (isset($key[$type . 'KeyAlgorithm']['parameters'])) {
|
||||
$decoded = ASN1::decodeBER($key[$type . 'KeyAlgorithm']['parameters']);
|
||||
if ($decoded === false) {
|
||||
throw new \UnexpectedValueException('Unable to decode parameters');
|
||||
}
|
||||
$params = ASN1::asn1map($decoded[0], Maps\RSASSA_PSS_params::MAP);
|
||||
} else {
|
||||
$params = [];
|
||||
}
|
||||
$params = ASN1::asn1map($decoded[0], Maps\RSASSA_PSS_params::MAP);
|
||||
|
||||
if (isset($params['maskGenAlgorithm']['parameters'])) {
|
||||
$decoded = ASN1::decodeBER($params['maskGenAlgorithm']['parameters']);
|
||||
if ($decoded === false) {
|
||||
@ -144,7 +149,9 @@ abstract class PSS extends Progenitor
|
||||
|
||||
$result['hash'] = str_replace('id-', '', $params['hashAlgorithm']['algorithm']);
|
||||
$result['MGFHash'] = str_replace('id-', '', $params['maskGenAlgorithm']['parameters']['algorithm']);
|
||||
$result['saltLength'] = (int) $params['saltLength']->toString();
|
||||
if (isset($params['saltLength'])) {
|
||||
$result['saltLength'] = (int) $params['saltLength']->toString();
|
||||
}
|
||||
|
||||
if (isset($key['meta'])) {
|
||||
$result['meta'] = $key['meta'];
|
||||
|
@ -246,6 +246,66 @@ ZQIDAQAB
|
||||
$this->assertInstanceOf(PublicKey::class, $rsa);
|
||||
}
|
||||
|
||||
|
||||
public function testPubKeyPssWithoutParams()
|
||||
{
|
||||
// extracted from a SubjectPublicKeyInfo of a CSR created by OpenSSL
|
||||
$key = '-----BEGIN PUBLIC KEY-----
|
||||
MIIBIDALBgkqhkiG9w0BAQoDggEPADCCAQoCggEBANHPPf5tjTmEHtQvzi6+rItj
|
||||
G3OUvh6Nihc9bXSu0xNFjl/9TdyIXstRUG/Lh07isHgZFEfXn4pmm/iZIQh09ACg
|
||||
TjEau8rpcLB0BS9dDgTh8hvgkbdxWR2UPxk34bFcdgIplckslAfB4+/ebL+ObvUa
|
||||
W3sZosTq3D6/qh0fujGZg/EKLJcNCHI27XMiAT5yWztSjHWwQm7LBwJ5uKlFLEDC
|
||||
Z/+LIV/vPEIMfE6lA/+OnLKwVFB540eXQPuWar1ARHXN8PpiCqJHanddYMA5l/Cw
|
||||
5R7kJ+CBoHzaPePXjB9V1bfzEBzBHb2ddiSjum+qtLWuH0Q7B8gPX9EjxIwuCzMC
|
||||
AwEAAQ==
|
||||
-----END PUBLIC KEY-----';
|
||||
$key = str_replace(["\r", "\n", "\r\n"], ' ', $key);
|
||||
|
||||
$rsa = PublicKeyLoader::load($key);
|
||||
|
||||
$this->assertInstanceOf(PublicKey::class, $rsa);
|
||||
$this->assertIsString("$rsa");
|
||||
}
|
||||
|
||||
public function testPrivateKeyPssWithoutParams()
|
||||
{
|
||||
$key = '-----BEGIN PRIVATE KEY-----
|
||||
MIIEugIBADALBgkqhkiG9w0BAQoEggSmMIIEogIBAAKCAQEA0c89/m2NOYQe1C/O
|
||||
Lr6si2Mbc5S+Ho2KFz1tdK7TE0WOX/1N3Ihey1FQb8uHTuKweBkUR9efimab+Jkh
|
||||
CHT0AKBOMRq7yulwsHQFL10OBOHyG+CRt3FZHZQ/GTfhsVx2AimVySyUB8Hj795s
|
||||
v45u9RpbexmixOrcPr+qHR+6MZmD8Qoslw0IcjbtcyIBPnJbO1KMdbBCbssHAnm4
|
||||
qUUsQMJn/4shX+88Qgx8TqUD/46csrBUUHnjR5dA+5ZqvUBEdc3w+mIKokdqd11g
|
||||
wDmX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R8mNzddsZCYorow5/izaDJzU+esJrNrzgmOFc5n7ofayTdip+knRlqW
|
||||
s7AUQn8K8mhb7ijxZjLysJjIRV1HC8epAnJKOMjvuRimM7H+3Qo2H1tPHtTKm1nt
|
||||
GNfYYFi7Dc0zHP0/YXxYwYRxs0mKLaP4mQxbAoGARHngPhGC0yM5KqxNrkHPVjLq
|
||||
CHQy+e9GTPXtDLC3D7HAYyyzKqy4mdBDzMeLqA3a+iT2PXjn4w5zOEW8GAcRYRtG
|
||||
3EyvclPmWtmCpU5xqD8ieFtQhMeW/XzJHjTXlcncz0PCkGVoQiuRvXWNAukNPg0D
|
||||
BocC2CO6SNi4Qjr3NlM=
|
||||
-----END PRIVATE KEY-----';
|
||||
|
||||
$key = str_replace(["\r", "\n", "\r\n"], ' ', $key);
|
||||
|
||||
$rsa = PublicKeyLoader::load($key);
|
||||
|
||||
$this->assertInstanceOf(PrivateKey::class, $rsa);
|
||||
$this->assertIsString("$rsa");
|
||||
}
|
||||
|
||||
public function testPubPrivateKey()
|
||||
{
|
||||
$key = '-----BEGIN RSA PUBLIC KEY-----
|
||||
|
Loading…
Reference in New Issue
Block a user