LibWeb: Implement skeleton of RSA-OAEP decrypt for SubtleCrypto

The actual Crypto algorithm part isn't implemented yet, so we just copy
the ciphertext and claim that's the plaintext :^)
This commit is contained in:
Andrew Kaster 2024-03-14 23:12:13 -06:00 committed by Andrew Kaster
parent 29b68a1b10
commit cddbdf5ae9
Notes: sideshowbarker 2024-07-16 17:05:37 +09:00
3 changed files with 30 additions and 1 deletions

View file

@ -373,6 +373,34 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<JS::ArrayBuffer>> RSAOAEP::encrypt(Algorith
return JS::ArrayBuffer::create(realm, move(ciphertext));
}
// https://w3c.github.io/webcrypto/#rsa-oaep-operations
WebIDL::ExceptionOr<JS::NonnullGCPtr<JS::ArrayBuffer>> RSAOAEP::decrypt(AlgorithmParams const& params, JS::NonnullGCPtr<CryptoKey> key, AK::ByteBuffer const& ciphertext)
{
auto& realm = m_realm;
auto& vm = realm.vm();
auto const& normalized_algorithm = static_cast<RsaOaepParams const&>(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<Variant<JS::NonnullGCPtr<CryptoKey>, JS::NonnullGCPtr<CryptoKeyPair>>> RSAOAEP::generate_key(AlgorithmParams const& params, bool extractable, Vector<Bindings::KeyUsage> const& key_usages)
{