diff --git a/Userland/Libraries/LibWeb/Crypto/CryptoAlgorithms.cpp b/Userland/Libraries/LibWeb/Crypto/CryptoAlgorithms.cpp index 0aba4d280ed..5a8ea53f8a6 100644 --- a/Userland/Libraries/LibWeb/Crypto/CryptoAlgorithms.cpp +++ b/Userland/Libraries/LibWeb/Crypto/CryptoAlgorithms.cpp @@ -373,6 +373,34 @@ WebIDL::ExceptionOr> RSAOAEP::encrypt(Algorith return JS::ArrayBuffer::create(realm, move(ciphertext)); } +// https://w3c.github.io/webcrypto/#rsa-oaep-operations +WebIDL::ExceptionOr> RSAOAEP::decrypt(AlgorithmParams const& params, JS::NonnullGCPtr key, AK::ByteBuffer const& ciphertext) +{ + auto& realm = m_realm; + auto& vm = realm.vm(); + auto const& normalized_algorithm = static_cast(params); + + // 1. If the [[type]] internal slot of key is not "private", then throw an InvalidAccessError. + if (key->type() != Bindings::KeyType::Private) + return WebIDL::InvalidAccessError::create(realm, "Key is not a private key"_fly_string); + + // 2. Let label be the contents of the label member of normalizedAlgorithm or the empty octet string if the label member of normalizedAlgorithm is not present. + [[maybe_unused]] auto const& label = normalized_algorithm.label; + + // 3. Perform the decryption operation defined in Section 7.1 of [RFC3447] with the key represented by key as the recipient's RSA private key, + // the contents of ciphertext as the ciphertext to be decrypted, C, and label as the label, L, and with the hash function specified by the hash attribute + // of the [[algorithm]] internal slot of key as the Hash option and MGF1 (defined in Section B.2.1 of [RFC3447]) as the MGF option. + + // 4. If performing the operation results in an error, then throw an OperationError. + + // 5. Let plaintext the value M that results from performing the operation. + // FIXME: Actually decrypt the data + auto plaintext = TRY_OR_THROW_OOM(vm, ByteBuffer::copy(ciphertext)); + + // 6. Return the result of creating an ArrayBuffer containing plaintext. + return JS::ArrayBuffer::create(realm, move(plaintext)); +} + // https://w3c.github.io/webcrypto/#rsa-oaep-operations WebIDL::ExceptionOr, JS::NonnullGCPtr>> RSAOAEP::generate_key(AlgorithmParams const& params, bool extractable, Vector const& key_usages) { diff --git a/Userland/Libraries/LibWeb/Crypto/CryptoAlgorithms.h b/Userland/Libraries/LibWeb/Crypto/CryptoAlgorithms.h index 4e621dcb75c..9cc6325a394 100644 --- a/Userland/Libraries/LibWeb/Crypto/CryptoAlgorithms.h +++ b/Userland/Libraries/LibWeb/Crypto/CryptoAlgorithms.h @@ -165,6 +165,7 @@ protected: class RSAOAEP : public AlgorithmMethods { public: virtual WebIDL::ExceptionOr> encrypt(AlgorithmParams const&, JS::NonnullGCPtr, ByteBuffer const&) override; + virtual WebIDL::ExceptionOr> decrypt(AlgorithmParams const&, JS::NonnullGCPtr, ByteBuffer const&) override; virtual WebIDL::ExceptionOr, JS::NonnullGCPtr>> generate_key(AlgorithmParams const&, bool, Vector const&) override; diff --git a/Userland/Libraries/LibWeb/Crypto/SubtleCrypto.cpp b/Userland/Libraries/LibWeb/Crypto/SubtleCrypto.cpp index a8270a11fc6..680b5d4151d 100644 --- a/Userland/Libraries/LibWeb/Crypto/SubtleCrypto.cpp +++ b/Userland/Libraries/LibWeb/Crypto/SubtleCrypto.cpp @@ -516,7 +516,7 @@ SupportedAlgorithmsMap supported_algorithms() define_an_algorithm("exportKey"_string, "RSA-OAEP"_string); define_an_algorithm("importKey"_string, "RSA-OAEP"_string); define_an_algorithm("encrypt"_string, "RSA-OAEP"_string); - // FIXME: decrypt + define_an_algorithm("decrypt"_string, "RSA-OAEP"_string); return internal_object; }