From 615be9eb7ca88b20a13021cdf3eaf058c9059599 Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Mon, 13 Dec 2021 20:48:27 +0000 Subject: LibWeb: Add the SubtleCrypto interface Just some boilerplate code to get started :^) This adds both the SubtleCrypto constructor to the window object, as well as the crypto.subtle instance attribute. --- .../Libraries/LibWeb/Bindings/WindowObjectHelper.h | 3 ++ Userland/Libraries/LibWeb/Crypto/Crypto.cpp | 6 ++++ Userland/Libraries/LibWeb/Crypto/Crypto.h | 7 ++++- Userland/Libraries/LibWeb/Crypto/Crypto.idl | 2 +- Userland/Libraries/LibWeb/Crypto/SubtleCrypto.h | 34 ++++++++++++++++++++++ Userland/Libraries/LibWeb/Crypto/SubtleCrypto.idl | 3 ++ Userland/Libraries/LibWeb/Forward.h | 2 ++ 7 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 Userland/Libraries/LibWeb/Crypto/SubtleCrypto.h create mode 100644 Userland/Libraries/LibWeb/Crypto/SubtleCrypto.idl (limited to 'Userland/Libraries/LibWeb') diff --git a/Userland/Libraries/LibWeb/Bindings/WindowObjectHelper.h b/Userland/Libraries/LibWeb/Bindings/WindowObjectHelper.h index 3faa49a98e..b7f13c05e6 100644 --- a/Userland/Libraries/LibWeb/Bindings/WindowObjectHelper.h +++ b/Userland/Libraries/LibWeb/Bindings/WindowObjectHelper.h @@ -261,6 +261,8 @@ #include #include #include +#include +#include #include #include #include @@ -412,6 +414,7 @@ ADD_WINDOW_OBJECT_INTERFACE(StyleSheet) \ ADD_WINDOW_OBJECT_INTERFACE(StyleSheetList) \ ADD_WINDOW_OBJECT_INTERFACE(SubmitEvent) \ + ADD_WINDOW_OBJECT_INTERFACE(SubtleCrypto) \ ADD_WINDOW_OBJECT_INTERFACE(SVGElement) \ ADD_WINDOW_OBJECT_INTERFACE(SVGGeometryElement) \ ADD_WINDOW_OBJECT_INTERFACE(SVGGraphicsElement) \ diff --git a/Userland/Libraries/LibWeb/Crypto/Crypto.cpp b/Userland/Libraries/LibWeb/Crypto/Crypto.cpp index 64ba54f6ed..020f10c0d8 100644 --- a/Userland/Libraries/LibWeb/Crypto/Crypto.cpp +++ b/Userland/Libraries/LibWeb/Crypto/Crypto.cpp @@ -8,9 +8,15 @@ #include #include #include +#include namespace Web::Crypto { +Crypto::Crypto() + : m_subtle(SubtleCrypto::create()) +{ +} + DOM::ExceptionOr Crypto::get_random_values(JS::Value array) const { // 1. If array is not an Int8Array, Uint8Array, Uint8ClampedArray, Int16Array, Uint16Array, Int32Array, Uint32Array, BigInt64Array, or BigUint64Array, then throw a TypeMismatchError and terminate the algorithm. diff --git a/Userland/Libraries/LibWeb/Crypto/Crypto.h b/Userland/Libraries/LibWeb/Crypto/Crypto.h index d469b7a48f..172e7de4e8 100644 --- a/Userland/Libraries/LibWeb/Crypto/Crypto.h +++ b/Userland/Libraries/LibWeb/Crypto/Crypto.h @@ -8,6 +8,7 @@ #include #include +#include #include namespace Web::Crypto { @@ -23,10 +24,14 @@ public: return adopt_ref(*new Crypto()); } + NonnullRefPtr subtle() const { return m_subtle; } + DOM::ExceptionOr get_random_values(JS::Value array) const; private: - Crypto() = default; + Crypto(); + + NonnullRefPtr m_subtle; }; } diff --git a/Userland/Libraries/LibWeb/Crypto/Crypto.idl b/Userland/Libraries/LibWeb/Crypto/Crypto.idl index 64941a4980..8cedd797a4 100644 --- a/Userland/Libraries/LibWeb/Crypto/Crypto.idl +++ b/Userland/Libraries/LibWeb/Crypto/Crypto.idl @@ -1,6 +1,6 @@ [Exposed=(Window,Worker)] interface Crypto { - // TODO: [SecureContext] readonly attribute SubtleCrypto subtle; + [SecureContext] readonly attribute SubtleCrypto subtle; // FIXME: the argument and the return value should be of type ArrayBufferView any getRandomValues(any array); diff --git a/Userland/Libraries/LibWeb/Crypto/SubtleCrypto.h b/Userland/Libraries/LibWeb/Crypto/SubtleCrypto.h new file mode 100644 index 0000000000..7d3b0d7d31 --- /dev/null +++ b/Userland/Libraries/LibWeb/Crypto/SubtleCrypto.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2021, Linus Groh + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include + +namespace Web::Crypto { + +class SubtleCrypto + : public Bindings::Wrappable + , public RefCounted { +public: + using WrapperType = Bindings::SubtleCryptoWrapper; + + static NonnullRefPtr create() + { + return adopt_ref(*new SubtleCrypto()); + } + +private: + SubtleCrypto() = default; +}; + +} + +namespace Web::Bindings { + +SubtleCryptoWrapper* wrap(JS::GlobalObject&, Crypto::SubtleCrypto&); + +} diff --git a/Userland/Libraries/LibWeb/Crypto/SubtleCrypto.idl b/Userland/Libraries/LibWeb/Crypto/SubtleCrypto.idl new file mode 100644 index 0000000000..e0e9d5489c --- /dev/null +++ b/Userland/Libraries/LibWeb/Crypto/SubtleCrypto.idl @@ -0,0 +1,3 @@ +[SecureContext,Exposed=(Window,Worker)] +interface SubtleCrypto { +}; diff --git a/Userland/Libraries/LibWeb/Forward.h b/Userland/Libraries/LibWeb/Forward.h index 618a7cf1f8..0ef1d9ece1 100644 --- a/Userland/Libraries/LibWeb/Forward.h +++ b/Userland/Libraries/LibWeb/Forward.h @@ -15,6 +15,7 @@ enum class Source; namespace Web::Crypto { class Crypto; +class SubtleCrypto; } namespace Web::CSS { @@ -431,6 +432,7 @@ class SelectionWrapper; class StyleSheetListWrapper; class StyleSheetWrapper; class SubmitEventWrapper; +class SubtleCryptoWrapper; class SVGElementWrapper; class SVGGeometryElementWrapper; class SVGGraphicsElementWrapper; -- cgit v1.2.3