mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-05-03 04:52:06 +02:00
LibWeb: Fix X448 JWK key export format
The presence of padding in the base64 fields made plenty of WPT tests fail. Additionally, export was performed with the wrong public key. The issue was discovered while implementing `wrapKey` and `unwrapKey` in the next commits.
This commit is contained in:
Notes:
github-actions[bot]
2024-12-16 10:36:22 +00:00
Author: https://github.com/devgianlu Commit: https://github.com/LadybirdBrowser/ladybird/commit/880401030d0 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2915
@@ -5463,12 +5463,18 @@ WebIDL::ExceptionOr<GC::Ref<JS::Object>> X448::export_key(Bindings::KeyFormat fo
|
||||
jwk.crv = "X448"_string;
|
||||
|
||||
// 4. Set the x attribute of jwk according to the definition in Section 2 of [RFC8037].
|
||||
jwk.x = TRY_OR_THROW_OOM(m_realm->vm(), encode_base64url(key_data));
|
||||
if (key->type() == Bindings::KeyType::Public) {
|
||||
jwk.x = TRY_OR_THROW_OOM(m_realm->vm(), encode_base64url(key_data, AK::OmitPadding::Yes));
|
||||
} else {
|
||||
::Crypto::Curves::X448 curve;
|
||||
auto public_key = TRY_OR_THROW_OOM(m_realm->vm(), curve.generate_public_key(key_data));
|
||||
jwk.x = TRY_OR_THROW_OOM(m_realm->vm(), encode_base64url(public_key, AK::OmitPadding::Yes));
|
||||
}
|
||||
|
||||
// 5. If the [[type]] internal slot of key is "private"
|
||||
if (key->type() == Bindings::KeyType::Private) {
|
||||
// 1. Set the d attribute of jwk according to the definition in Section 2 of [RFC8037].
|
||||
jwk.d = TRY_OR_THROW_OOM(m_realm->vm(), encode_base64url(key_data));
|
||||
jwk.d = TRY_OR_THROW_OOM(m_realm->vm(), encode_base64url(key_data, AK::OmitPadding::Yes));
|
||||
}
|
||||
|
||||
// 6. Set the key_ops attribute of jwk to the usages attribute of key.
|
||||
|
||||
Reference in New Issue
Block a user