mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 14:38:11 +00: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:
parent
008c89edde
commit
a9d240c647
12 changed files with 536 additions and 81 deletions
99
Userland/Libraries/LibWeb/Crypto/KeyAlgorithms.h
Normal file
99
Userland/Libraries/LibWeb/Crypto/KeyAlgorithms.h
Normal file
|
@ -0,0 +1,99 @@
|
|||
/*
|
||||
* Copyright (c) 2023, stelar7 <dudedbz@gmail.com>
|
||||
* Copyright (c) 2024, Andrew Kaster <akaster@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <AK/String.h>
|
||||
#include <LibCrypto/BigInt/UnsignedBigInteger.h>
|
||||
#include <LibJS/Runtime/Object.h>
|
||||
#include <LibWeb/Crypto/CryptoAlgorithms.h>
|
||||
#include <LibWeb/WebIDL/ExceptionOr.h>
|
||||
|
||||
namespace Web::Crypto {
|
||||
|
||||
// https://w3c.github.io/webcrypto/#key-algorithm-dictionary
|
||||
class KeyAlgorithm : public JS::Object {
|
||||
JS_OBJECT(KeyAlgorithm, Object);
|
||||
JS_DECLARE_ALLOCATOR(KeyAlgorithm);
|
||||
|
||||
public:
|
||||
static JS::NonnullGCPtr<KeyAlgorithm> create(JS::Realm&);
|
||||
virtual ~KeyAlgorithm() override = default;
|
||||
|
||||
String const& name() const { return m_name; }
|
||||
void set_name(String name) { m_name = move(name); }
|
||||
|
||||
JS::Realm& realm() const { return m_realm; }
|
||||
|
||||
protected:
|
||||
KeyAlgorithm(JS::Realm&);
|
||||
|
||||
virtual void initialize(JS::Realm&) override;
|
||||
|
||||
private:
|
||||
JS_DECLARE_NATIVE_FUNCTION(name_getter);
|
||||
|
||||
String m_name;
|
||||
JS::Realm& m_realm;
|
||||
};
|
||||
|
||||
// https://w3c.github.io/webcrypto/#RsaKeyAlgorithm-dictionary
|
||||
class RsaKeyAlgorithm : public KeyAlgorithm {
|
||||
JS_OBJECT(RsaKeyAlgorithm, KeyAlgorithm);
|
||||
JS_DECLARE_ALLOCATOR(RsaKeyAlgorithm);
|
||||
|
||||
public:
|
||||
static JS::NonnullGCPtr<RsaKeyAlgorithm> create(JS::Realm&);
|
||||
|
||||
virtual ~RsaKeyAlgorithm() override = default;
|
||||
|
||||
u32 modulus_length() const { return m_modulus_length; }
|
||||
void set_modulus_length(u32 modulus_length) { m_modulus_length = modulus_length; }
|
||||
|
||||
JS::NonnullGCPtr<JS::Uint8Array> public_exponent() const { return m_public_exponent; }
|
||||
void set_public_exponent(JS::NonnullGCPtr<JS::Uint8Array> public_exponent) { m_public_exponent = public_exponent; }
|
||||
WebIDL::ExceptionOr<void> set_public_exponent(::Crypto::UnsignedBigInteger);
|
||||
|
||||
protected:
|
||||
RsaKeyAlgorithm(JS::Realm&);
|
||||
|
||||
virtual void initialize(JS::Realm&) override;
|
||||
virtual void visit_edges(Visitor&) override;
|
||||
|
||||
private:
|
||||
JS_DECLARE_NATIVE_FUNCTION(modulus_length_getter);
|
||||
JS_DECLARE_NATIVE_FUNCTION(public_exponent_getter);
|
||||
|
||||
u32 m_modulus_length { 0 };
|
||||
JS::NonnullGCPtr<JS::Uint8Array> m_public_exponent;
|
||||
};
|
||||
|
||||
// https://w3c.github.io/webcrypto/#RsaHashedKeyAlgorithm-dictionary
|
||||
class RsaHashedKeyAlgorithm : public RsaKeyAlgorithm {
|
||||
JS_OBJECT(RsaHashedKeyAlgorithm, RsaKeyAlgorithm);
|
||||
JS_DECLARE_ALLOCATOR(RsaHashedKeyAlgorithm);
|
||||
|
||||
public:
|
||||
static JS::NonnullGCPtr<RsaHashedKeyAlgorithm> create(JS::Realm&);
|
||||
|
||||
virtual ~RsaHashedKeyAlgorithm() override = default;
|
||||
|
||||
HashAlgorithmIdentifier const& hash() const { return m_hash; }
|
||||
void set_hash(HashAlgorithmIdentifier hash) { m_hash = move(hash); }
|
||||
|
||||
protected:
|
||||
RsaHashedKeyAlgorithm(JS::Realm&);
|
||||
|
||||
virtual void initialize(JS::Realm&) override;
|
||||
|
||||
private:
|
||||
JS_DECLARE_NATIVE_FUNCTION(hash_getter);
|
||||
|
||||
HashAlgorithmIdentifier m_hash;
|
||||
};
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue