Commit graph

20 commits

Author SHA1 Message Date
Daniel Adams
3d8f99c4e6
crypto: Include key_ops in exported JWKs, support JWK for HMAC import (#34317)
* Improve JWK handling, HMAC import

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

* Update expectations

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

* Fix logic in parse_jwk, properly stringify key_ops

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

---------

Signed-off-by: Daniel Adams <msub2official@gmail.com>
2024-11-21 11:44:33 +00:00
Simon Wülker
83f8e88818
Implement AES-GCM support for subtlecrypto (#34269)
* Support normalizing AES-GCM for encryption

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>

* Implement "encrypt" operation for AES-GCM

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>

* Allow importing AES-GCM keys

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>

* Implement AES-GCM decryption

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>

* Allow normalizing AES-GCM for "generate key"

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>

* Update WPT expectations

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>

* fmt

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>

* Fix clippy errors

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>

* Remove silly checks

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>

* Support AES-GCM 128-bit encryption with 128 bit IV

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>

* Support AES-GCM with wrapKey/unwrapKey

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>

* Update WPT expectations (again)

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>

---------

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
2024-11-19 12:42:37 +00:00
Daniel Adams
124c5bbbf3
crypto: Support key wrap operations + AES-KW (#34262)
* Support key wrapping operations + AES-KW

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

* Update expectations

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

* tidy

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

* Add allow for clippy

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

* Add missing spec links

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

* Improve JWK handling

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

* Fix clippy warnings

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

* ./mach fmt

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

---------

Signed-off-by: Daniel Adams <msub2official@gmail.com>
2024-11-18 22:54:58 +00:00
Simon Wülker
2485bd9a63
Implement HMAC key generation (#34278)
* Implement HMAC key generation

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>

* Update WPT expectations

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>

---------

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
2024-11-18 17:28:24 +00:00
Simon Wülker
ee63174d6f
subtlecrypto: Don't throw exceptions twice when converting to Algorithm object (#34239)
* Don't throw exceptions twice when converting to Algorithm object

Removes match statements like
```rust
let Ok(ConversionResult::Success(algorithm)) = Algorithm::new(cx, value.handle())
else {
    return Err(Error::Syntax);
};
```
These don't cause issues if `Algorithm::new` returns `Ok(ConversionResult::Failure`,
but in the case of `Err(())` the implementation already called `throw_type_error`
and we must not throw an additional Syntax error, otherwise we'll crash.

Luckily, this case is already handled elsewhere by the
`value_from_js_object` macro.

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>

* Test that calling subtlecrypto methods with empty algorithm objects throws a TypeError

The WebCryptoAPI spec does not tell us which error to throw exactly, but
according to https://webidl.spec.whatwg.org/ it should be a TypeError.

This previously crashed servo.

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>

---------

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
2024-11-15 23:15:32 +00:00
Simon Wülker
5e7664b72e
Implement "get key length" operation for HMAC algorithm (#34230)
* Implement "get key length" for HMAC keys

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>

* Update WPT expectations

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>

---------

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
2024-11-12 23:50:13 +00:00
Simon Wülker
8d3d7b7403
Implement crypto.subtle.sign/verify with HMAC (#34223)
* Allow importing HMAC keys

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>

* Implement crypto.subtle.sign with HMAC

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>

* Implement crypto.subtle.verify with HMAC

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>

* Update WPT expectations

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>

---------

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
2024-11-11 19:32:51 +00:00
Simon Wülker
cdd0006e3d
Implement HKDF support for subtlecrypto.deriveBits (#34200)
* Implement subtlecrypto.deriveBits with HKDF

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>

* Update WPT expectations

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>

---------

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
2024-11-10 00:59:39 +00:00
Simon Wülker
67ac59b809
subtlecrypto: Replace NormalizedAlgorithm with specialized variants (#34193)
* Implement specialized normalize_algorithm for "get key length" operation

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>

* Implement specialized normalize_algorithm for "digest"

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>

* Implement specialized normalize_algorithm for "importKey"

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>

* Implement specialized normalize_algorithm for "deriveBits"

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>

* Implement specialized normalize_algorithm for "decrypt"

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>

* Implement specialized normalize_algorithm for "generateKey"

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>

* Implement specialized normalize_algorithm for "encrypt"

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>

* Remove normalize_algorithm

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>

* Update WPT expectations

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>

* Replace obj.get_unsafe() with obj.get()

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>

* Replace BitwiseOr with LogicalOr (typo)

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>

* Update more WPT expectations outside of WebCryptoAPI

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>

---------

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
2024-11-09 16:43:47 +00:00
Simon Wülker
6b94b2c684
Implement subtlecrypto.deriveKey (#34185)
* Implement NormalizedAlgorithm::get_key_length

This is a minimal implementation, which will make
the DeriveKey operation work for AES-CTR keys in
the future.

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>

* Implement SubtleCrypto.deriveKey

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>

* Update WPT expectations

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>

---------

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
2024-11-08 12:59:01 +00:00
Simon Wülker
2f6ca9407b
Implement SubtleCrypto.deriveBits with PBDKF2 (#34164)
* Start implementing SubtleCrypto.deriveBits

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>

* Move shared crypto operations into their own functions

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>

* Update some doclinks

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>

* Remove note about potential no-op

It is, indeed, a no-op.

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>

* Move normalized algorithm digest operation into its own function

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>

* Implement mvp for pbkdf2 derivation

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>

* Add missing division to derive bytes instead of bits

The length argument specifies the number of bits that
we need to derive, so we should divide it by 8 to
get the number of bytes.

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>

* Allow using PBKDF2 with usage "importKey"

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>

* Update WPT expectations

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>

* Fix test-tidy errors

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>

* Fix clippy warnings

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>

---------

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
2024-11-06 15:52:15 +00:00
Simon Wülker
73d2f3c453
Return cached object from CryptoKey.algorithm getter (#34092)
* Return cached object from CryptoKey.algorithm getter

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>

* Test that CryptoKey.algorithm returns a cached object

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>

* Move duplicated code into a helper function

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>

---------

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
2024-11-04 17:49:01 +00:00
Simon Wülker
7fa548f555
Implement SubtleCrypto.digest (#34034)
* Implement SubtleCrypto.digest

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>

* Update WPT expectations

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>

---------

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
2024-10-30 02:06:02 +00:00
Daniel Adams
7b392db02f
crypto: Add support for AES-CTR operations (#33963)
* Add support for AES-CTR operations

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

* Update expectations

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

* clippy

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

* Consolidate encrypt/decrypt for AES-CTR

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

* Update expectations

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

---------

Signed-off-by: Daniel Adams <msub2official@gmail.com>
2024-10-22 22:32:41 +00:00
Josh Matthews
575e885529
Mark promise creation methods with CanGc (#33928)
* Add CanGc annotations to promise constructor.

Signed-off-by: Josh Matthews <josh@joshmatthews.net>

* Propagate CanGc arguments for Promise::new_in_current_realm.

Signed-off-by: Josh Matthews <josh@joshmatthews.net>

* Fix out-of-order entries.

Signed-off-by: Josh Matthews <josh@joshmatthews.net>

* Propagate CanGc from Promise::new.

Signed-off-by: Josh Matthews <josh@joshmatthews.net>

* Suppress clippy warning.

Signed-off-by: Josh Matthews <josh@joshmatthews.net>

* Formatting.

Signed-off-by: Josh Matthews <josh@joshmatthews.net>

---------

Signed-off-by: Josh Matthews <josh@joshmatthews.net>
2024-10-22 09:35:20 +00:00
tanishka
66695d2f7e
clippy: Fix warnings in subtlecrypto.rs (#33943)
Signed-off-by: taniishkaaa <tanishkasingh2004@gmail.com>
2024-10-21 10:43:47 +00:00
Daniel Adams
45267c9f28
crypto: Implement encrypt/decrypt for AES-CBC + JWK support (#33795)
* Add support for raw importKey with AES-CBC

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

* Support JWK import/export, importKey for AES-CBC

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

* Implement encrypt/decrypt for AES-CBC

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

* Update expectations

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

* Update Cargo.lock

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

* Pass MutableHandleObject as arg instead of returning raw pointer

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

* Swap order of checks in generate_key_aes_cbc

- Fixes WPT tests that expect to error on algorithm first before usages

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

* Avoid potential GC hazard with array_buffer_ptr

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

* Update expectations for discards context

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

---------

Signed-off-by: Daniel Adams <msub2official@gmail.com>
2024-10-21 07:32:19 +00:00
tanishka
9a8e7f4867
clippy: Fix warnings in components/script/dom (#33771)
Signed-off-by: taniishkaaa <tanishkasingh2004@gmail.com>
2024-10-09 21:44:01 +00:00
chickenleaf
589f0d7018
Fix clippy warning: slow zero-filling initialization (#33740)
Signed-off-by: L Ashwin B <lashwinib@gmail.com>
2024-10-08 23:36:52 +00:00
Daniel Adams
fc0d4d8157
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>
2024-10-08 03:51:08 +00:00