crypto: Begin SubtleCrypto implementation (#33628)

* Update IDLs and Bindings conf

Signed-off-by: Daniel Adams <msub2official@gmail.com>

* Add AES crate

Signed-off-by: Daniel Adams <msub2official@gmail.com>

* Implement DOM interfaces

Signed-off-by: Daniel Adams <msub2official@gmail.com>

* IDL tidy

Signed-off-by: Daniel Adams <msub2official@gmail.com>

* Remove deriveKey from inRealms for now until implemented

Signed-off-by: Daniel Adams <msub2official@gmail.com>

* Fix CryptoKey rustdoc comments

Signed-off-by: Daniel Adams <msub2official@gmail.com>

* Move string constants to top of file

Signed-off-by: Daniel Adams <msub2official@gmail.com>

* Use properly rooted CryptoKey

Signed-off-by: Daniel Adams <msub2official@gmail.com>

* Code clarity

Signed-off-by: Daniel Adams <msub2official@gmail.com>

* Rework NormalizedAlgorithm to not hold a DOMString

Signed-off-by: Daniel Adams <msub2official@gmail.com>

* Add Rustdoc for CryptoKey interface

Signed-off-by: Daniel Adams <msub2official@gmail.com>

* Move ignore mallocsizeof to rand crate, remove from crypto

Signed-off-by: Daniel Adams <msub2official@gmail.com>

* Update cargo lock

Signed-off-by: Daniel Adams <msub2official@gmail.com>

* Fix key handling, implement exportKey with JWK TODO

Signed-off-by: Daniel Adams <msub2official@gmail.com>

* Add missing spec link

Signed-off-by: Daniel Adams <msub2official@gmail.com>

* Use create_buffer_source, remove aes dep from libservo

Signed-off-by: Daniel Adams <msub2official@gmail.com>

* Fix crash when running in worker

Signed-off-by: Daniel Adams <msub2official@gmail.com>

* Update expectations

Signed-off-by: Daniel Adams <msub2official@gmail.com>

* fmt

Signed-off-by: Daniel Adams <msub2official@gmail.com>

* Move CryptoKey and SubtleCrypto behind pref for now

Signed-off-by: Daniel Adams <msub2official@gmail.com>

* Update expectations

Signed-off-by: Daniel Adams <msub2official@gmail.com>

* Readd timeout expectation

Signed-off-by: Daniel Adams <msub2official@gmail.com>

---------

Signed-off-by: Daniel Adams <msub2official@gmail.com>
This commit is contained in:
Daniel Adams 2024-10-08 03:51:08 +00:00 committed by GitHub
parent 66bc430b24
commit fc0d4d8157
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
82 changed files with 39536 additions and 557 deletions

View file

@ -17,7 +17,7 @@ WorkerGlobalScope includes GlobalCrypto;
[Exposed=(Window,Worker)]
interface Crypto {
//readonly attribute SubtleCrypto subtle;
[SecureContext] readonly attribute SubtleCrypto subtle;
[Throws]
ArrayBufferView getRandomValues(ArrayBufferView array);

View file

@ -0,0 +1,17 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
// https://w3c.github.io/webcrypto/#cryptokey-interface
enum KeyType { "public", "private", "secret" };
enum KeyUsage { "encrypt", "decrypt", "sign", "verify", "deriveKey", "deriveBits", "wrapKey", "unwrapKey" };
[SecureContext, Exposed=(Window,Worker), Serializable, Pref="dom.crypto.subtle.enabled"]
interface CryptoKey {
readonly attribute KeyType type;
readonly attribute boolean extractable;
readonly attribute object algorithm;
readonly attribute object usages;
};

View file

@ -0,0 +1,87 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
// https://w3c.github.io/webcrypto/#subtlecrypto-interface
typedef (object or DOMString) AlgorithmIdentifier;
typedef AlgorithmIdentifier HashAlgorithmIdentifier;
dictionary Algorithm {
required DOMString name;
};
dictionary KeyAlgorithm {
required DOMString name;
};
enum KeyFormat { "raw", "spki", "pkcs8", "jwk" };
[SecureContext,Exposed=(Window,Worker),Pref="dom.crypto.subtle.enabled"]
interface SubtleCrypto {
// Promise<any> encrypt(AlgorithmIdentifier algorithm,
// CryptoKey key,
// BufferSource data);
// Promise<any> decrypt(AlgorithmIdentifier algorithm,
// CryptoKey key,
// BufferSource data);
// Promise<any> sign(AlgorithmIdentifier algorithm,
// CryptoKey key,
// BufferSource data);
// Promise<any> verify(AlgorithmIdentifier algorithm,
// CryptoKey key,
// BufferSource signature,
// BufferSource data);
// Promise<any> digest(AlgorithmIdentifier algorithm,
// BufferSource data);
Promise<any> generateKey(AlgorithmIdentifier algorithm,
boolean extractable,
sequence<KeyUsage> keyUsages );
// Promise<any> deriveKey(AlgorithmIdentifier algorithm,
// CryptoKey baseKey,
// AlgorithmIdentifier derivedKeyType,
// boolean extractable,
// sequence<KeyUsage> keyUsages );
// Promise<ArrayBuffer> deriveBits(AlgorithmIdentifier algorithm,
// CryptoKey baseKey,
// optional unsigned long? length = null);
// Promise<CryptoKey> importKey(KeyFormat format,
// (BufferSource or JsonWebKey) keyData,
// AlgorithmIdentifier algorithm,
// boolean extractable,
// sequence<KeyUsage> keyUsages );
Promise<any> exportKey(KeyFormat format, CryptoKey key);
// Promise<any> wrapKey(KeyFormat format,
// CryptoKey key,
// CryptoKey wrappingKey,
// AlgorithmIdentifier wrapAlgorithm);
// Promise<CryptoKey> unwrapKey(KeyFormat format,
// BufferSource wrappedKey,
// CryptoKey unwrappingKey,
// AlgorithmIdentifier unwrapAlgorithm,
// AlgorithmIdentifier unwrappedKeyAlgorithm,
// boolean extractable,
// sequence<KeyUsage> keyUsages );
};
// AES shared
dictionary AesKeyAlgorithm : KeyAlgorithm {
required unsigned short length;
};
dictionary AesKeyGenParams : Algorithm {
required [EnforceRange] unsigned short length;
};
dictionary AesDerivedKeyParams : Algorithm {
required [EnforceRange] unsigned short length;
};
// AES_CBC
dictionary AesCbcParams : Algorithm {
required BufferSource iv;
};