From 1f5324772f6fd8766dc7a3486a10ea3e4d2a361d Mon Sep 17 00:00:00 2001 From: Florent Morselli Date: Sat, 30 Mar 2024 17:39:38 +0100 Subject: [PATCH] Add RSASSA-PSS support to CryptoTypes Implemented support for the RSASSA-PSS encryption algorithm by adding its OID to AlgorithmIdentifier class. Also, updated the method that determines private key type in OneAsymmetricKey class to recognize RSASSA-PSS encryption. This ensures compatibility with more diverse RSA key types. --- src/CryptoTypes/AlgorithmIdentifier/AlgorithmIdentifier.php | 2 ++ src/CryptoTypes/Asymmetric/OneAsymmetricKey.php | 6 ++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/CryptoTypes/AlgorithmIdentifier/AlgorithmIdentifier.php b/src/CryptoTypes/AlgorithmIdentifier/AlgorithmIdentifier.php index 71226d4..c78e174 100644 --- a/src/CryptoTypes/AlgorithmIdentifier/AlgorithmIdentifier.php +++ b/src/CryptoTypes/AlgorithmIdentifier/AlgorithmIdentifier.php @@ -29,6 +29,8 @@ abstract class AlgorithmIdentifier implements AlgorithmIdentifierType final public const OID_SHA1_WITH_RSA_ENCRYPTION = '1.2.840.113549.1.1.5'; + final public const OID_RSASSA_PSS_ENCRYPTION = '1.2.840.113549.1.1.10'; + final public const OID_SHA256_WITH_RSA_ENCRYPTION = '1.2.840.113549.1.1.11'; final public const OID_SHA384_WITH_RSA_ENCRYPTION = '1.2.840.113549.1.1.12'; diff --git a/src/CryptoTypes/Asymmetric/OneAsymmetricKey.php b/src/CryptoTypes/Asymmetric/OneAsymmetricKey.php index 0ead218..ec231a2 100644 --- a/src/CryptoTypes/Asymmetric/OneAsymmetricKey.php +++ b/src/CryptoTypes/Asymmetric/OneAsymmetricKey.php @@ -181,8 +181,9 @@ public function privateKey(): PrivateKey { $algo = $this->algorithmIdentifier(); switch ($algo->oid()) { - // RSA + // RSA (including RSASSA-PSS) case AlgorithmIdentifier::OID_RSA_ENCRYPTION: + case AlgorithmIdentifier::OID_RSASSA_PSS_ENCRYPTION: return RSAPrivateKey::fromDER($this->privateKeyData); // elliptic curve case AlgorithmIdentifier::OID_EC_PUBLIC_KEY: @@ -225,8 +226,9 @@ public function privateKey(): PrivateKey return X448PrivateKey::fromOctetString(OctetString::fromDER($this->privateKeyData), $pubkey) ->withVersion($this->version) ->withAttributes($this->attributes); + default: + throw new RuntimeException('Private key ' . $algo->name() . ' not supported.'); } - throw new RuntimeException('Private key ' . $algo->name() . ' not supported.'); } /**