mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-05-03 13:02:09 +02:00
LibWeb: Implement SubtleCrypto.generateKey for RSA-OAEP
This patch implements and tests window.crypto.sublte.generateKey with an RSA-OAEP algorithm. In order for the types to be happy, the KeyAlgorithms objects are moved to their own .h/.cpp pair, and the new KeyAlgorithms for RSA are added there.
This commit is contained in:
committed by
Andrew Kaster
parent
008c89edde
commit
a9d240c647
Notes:
sideshowbarker
2024-07-17 07:25:39 +09:00
Author: https://github.com/ADKaster Commit: https://github.com/SerenityOS/serenity/commit/a9d240c647 Pull-request: https://github.com/SerenityOS/serenity/pull/23532
@@ -8,6 +8,7 @@
|
||||
|
||||
#include <AK/EnumBits.h>
|
||||
#include <AK/String.h>
|
||||
#include <LibCrypto/BigInt/UnsignedBigInteger.h>
|
||||
#include <LibJS/Forward.h>
|
||||
#include <LibJS/Heap/GCPtr.h>
|
||||
#include <LibWeb/Bindings/SubtleCryptoPrototype.h>
|
||||
@@ -18,12 +19,11 @@
|
||||
|
||||
namespace Web::Crypto {
|
||||
|
||||
using KeyDataType = Variant<JS::Handle<WebIDL::BufferSource>, Bindings::JsonWebKey>;
|
||||
using AlgorithmIdentifier = Variant<JS::Handle<JS::Object>, String>;
|
||||
using HashAlgorithmIdentifier = AlgorithmIdentifier;
|
||||
using KeyDataType = Variant<JS::Handle<WebIDL::BufferSource>, Bindings::JsonWebKey>;
|
||||
|
||||
// https://w3c.github.io/webcrypto/#algorithm-overview
|
||||
|
||||
struct AlgorithmParams {
|
||||
String name;
|
||||
|
||||
@@ -39,6 +39,22 @@ struct PBKDF2Params : public AlgorithmParams {
|
||||
static JS::ThrowCompletionOr<NonnullOwnPtr<AlgorithmParams>> from_value(JS::VM&, JS::Value);
|
||||
};
|
||||
|
||||
// https://w3c.github.io/webcrypto/#dfn-RsaKeyGenParams
|
||||
struct RsaKeyGenParams : public AlgorithmParams {
|
||||
u32 modulus_length;
|
||||
// NOTE that the raw data is going to be in Big Endian u8[] format
|
||||
::Crypto::UnsignedBigInteger public_exponent;
|
||||
|
||||
static JS::ThrowCompletionOr<NonnullOwnPtr<AlgorithmParams>> from_value(JS::VM&, JS::Value);
|
||||
};
|
||||
|
||||
// https://w3c.github.io/webcrypto/#dfn-RsaHashedKeyGenParams
|
||||
struct RsaHashedKeyGenParams : public RsaKeyGenParams {
|
||||
HashAlgorithmIdentifier hash;
|
||||
|
||||
static JS::ThrowCompletionOr<NonnullOwnPtr<AlgorithmParams>> from_value(JS::VM&, JS::Value);
|
||||
};
|
||||
|
||||
class AlgorithmMethods {
|
||||
public:
|
||||
virtual ~AlgorithmMethods();
|
||||
@@ -69,6 +85,19 @@ protected:
|
||||
JS::Realm& m_realm;
|
||||
};
|
||||
|
||||
class RSAOAEP : public AlgorithmMethods {
|
||||
public:
|
||||
virtual WebIDL::ExceptionOr<Variant<JS::NonnullGCPtr<CryptoKey>, JS::NonnullGCPtr<CryptoKeyPair>>> generate_key(AlgorithmParams const&, bool, Vector<Bindings::KeyUsage> const&) override;
|
||||
|
||||
static NonnullOwnPtr<AlgorithmMethods> create(JS::Realm& realm) { return adopt_own(*new RSAOAEP(realm)); }
|
||||
|
||||
private:
|
||||
explicit RSAOAEP(JS::Realm& realm)
|
||||
: AlgorithmMethods(realm)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
class PBKDF2 : public AlgorithmMethods {
|
||||
public:
|
||||
virtual WebIDL::ExceptionOr<JS::NonnullGCPtr<CryptoKey>> import_key(AlgorithmParams const&, Bindings::KeyFormat, CryptoKey::InternalKeyData, bool, Vector<Bindings::KeyUsage> const&) override;
|
||||
|
||||
Reference in New Issue
Block a user