LibWeb: Fix ED25519 JWK key export format

The presence of padding in the base64 fields and the typo made plenty of
WPT tests fail.

The issue was discovered while implementing `wrapKey` and `unwrapKey` in
the next commits.
This commit is contained in:
devgianlu 2024-12-13 22:34:12 +01:00 committed by Andreas Kling
parent a65110ec06
commit 6e33dbb533
Notes: github-actions[bot] 2024-12-16 10:36:55 +00:00
2 changed files with 25 additions and 25 deletions

View file

@ -4529,7 +4529,7 @@ WebIDL::ExceptionOr<GC::Ref<JS::Object>> ED25519::export_key(Bindings::KeyFormat
// 4. Set the x attribute of jwk according to the definition in Section 2 of [RFC8037]. // 4. Set the x attribute of jwk according to the definition in Section 2 of [RFC8037].
if (key->type() == Bindings::KeyType::Public) { if (key->type() == Bindings::KeyType::Public) {
jwk.x = TRY_OR_THROW_OOM(vm, encode_base64url(key_data)); jwk.x = TRY_OR_THROW_OOM(vm, encode_base64url(key_data, AK::OmitPadding::Yes));
} else { } else {
// The "x" parameter of the "epk" field is set as follows: // The "x" parameter of the "epk" field is set as follows:
// Apply the appropriate ECDH function to the ephemeral private key (as scalar input) // Apply the appropriate ECDH function to the ephemeral private key (as scalar input)
@ -4537,13 +4537,13 @@ WebIDL::ExceptionOr<GC::Ref<JS::Object>> ED25519::export_key(Bindings::KeyFormat
// The base64url encoding of the output is the value for the "x" parameter of the "epk" field. // The base64url encoding of the output is the value for the "x" parameter of the "epk" field.
::Crypto::Curves::Ed25519 curve; ::Crypto::Curves::Ed25519 curve;
auto public_key = TRY_OR_THROW_OOM(vm, curve.generate_public_key(key_data)); auto public_key = TRY_OR_THROW_OOM(vm, curve.generate_public_key(key_data));
jwk.x = TRY_OR_THROW_OOM(vm, encode_base64url(key_data)); jwk.x = TRY_OR_THROW_OOM(vm, encode_base64url(public_key, AK::OmitPadding::Yes));
} }
// 5. If the [[type]] internal slot of key is "private" // 5. If the [[type]] internal slot of key is "private"
if (key->type() == Bindings::KeyType::Private) { if (key->type() == Bindings::KeyType::Private) {
// 1. Set the d attribute of jwk according to the definition in Section 2 of [RFC8037]. // 1. Set the d attribute of jwk according to the definition in Section 2 of [RFC8037].
jwk.d = TRY_OR_THROW_OOM(vm, encode_base64url(key_data)); jwk.d = TRY_OR_THROW_OOM(vm, encode_base64url(key_data, AK::OmitPadding::Yes));
} }
// 6. Set the key_ops attribute of jwk to the usages attribute of key. // 6. Set the key_ops attribute of jwk to the usages attribute of key.

View file

@ -2,44 +2,44 @@ Harness status: OK
Found 62 tests Found 62 tests
32 Pass 52 Pass
30 Fail 10 Fail
Fail Good parameters: Ed25519 bits (spki, buffer(44), {name: Ed25519}, true, [verify]) Fail Good parameters: Ed25519 bits (spki, buffer(44), {name: Ed25519}, true, [verify])
Fail Good parameters: Ed25519 bits (spki, buffer(44), Ed25519, true, [verify]) Fail Good parameters: Ed25519 bits (spki, buffer(44), Ed25519, true, [verify])
Fail Good parameters: Ed25519 bits (jwk, object(kty, crv, x), {name: Ed25519}, true, [verify]) Pass Good parameters: Ed25519 bits (jwk, object(kty, crv, x), {name: Ed25519}, true, [verify])
Fail Good parameters: Ed25519 bits (jwk, object(kty, crv, x), Ed25519, true, [verify]) Pass Good parameters: Ed25519 bits (jwk, object(kty, crv, x), Ed25519, true, [verify])
Fail Good parameters with ignored JWK alg: Ed25519 (jwk, object(kty, crv, x), {name: Ed25519}, true, [verify]) Pass Good parameters with ignored JWK alg: Ed25519 (jwk, object(kty, crv, x), {name: Ed25519}, true, [verify])
Fail Good parameters with ignored JWK alg: Ed25519 (jwk, object(kty, crv, x), Ed25519, true, [verify]) Pass Good parameters with ignored JWK alg: Ed25519 (jwk, object(kty, crv, x), Ed25519, true, [verify])
Pass Good parameters: Ed25519 bits (raw, buffer(32), {name: Ed25519}, true, [verify]) Pass Good parameters: Ed25519 bits (raw, buffer(32), {name: Ed25519}, true, [verify])
Pass Good parameters: Ed25519 bits (raw, buffer(32), Ed25519, true, [verify]) Pass Good parameters: Ed25519 bits (raw, buffer(32), Ed25519, true, [verify])
Fail Good parameters: Ed25519 bits (spki, buffer(44), {name: Ed25519}, true, []) Fail Good parameters: Ed25519 bits (spki, buffer(44), {name: Ed25519}, true, [])
Fail Good parameters: Ed25519 bits (spki, buffer(44), Ed25519, true, []) Fail Good parameters: Ed25519 bits (spki, buffer(44), Ed25519, true, [])
Fail Good parameters: Ed25519 bits (jwk, object(kty, crv, x), {name: Ed25519}, true, []) Pass Good parameters: Ed25519 bits (jwk, object(kty, crv, x), {name: Ed25519}, true, [])
Fail Good parameters: Ed25519 bits (jwk, object(kty, crv, x), Ed25519, true, []) Pass Good parameters: Ed25519 bits (jwk, object(kty, crv, x), Ed25519, true, [])
Fail Good parameters with ignored JWK alg: Ed25519 (jwk, object(kty, crv, x), {name: Ed25519}, true, []) Pass Good parameters with ignored JWK alg: Ed25519 (jwk, object(kty, crv, x), {name: Ed25519}, true, [])
Fail Good parameters with ignored JWK alg: Ed25519 (jwk, object(kty, crv, x), Ed25519, true, []) Pass Good parameters with ignored JWK alg: Ed25519 (jwk, object(kty, crv, x), Ed25519, true, [])
Pass Good parameters: Ed25519 bits (raw, buffer(32), {name: Ed25519}, true, []) Pass Good parameters: Ed25519 bits (raw, buffer(32), {name: Ed25519}, true, [])
Pass Good parameters: Ed25519 bits (raw, buffer(32), Ed25519, true, []) Pass Good parameters: Ed25519 bits (raw, buffer(32), Ed25519, true, [])
Fail Good parameters: Ed25519 bits (spki, buffer(44), {name: Ed25519}, true, [verify, verify]) Fail Good parameters: Ed25519 bits (spki, buffer(44), {name: Ed25519}, true, [verify, verify])
Fail Good parameters: Ed25519 bits (spki, buffer(44), Ed25519, true, [verify, verify]) Fail Good parameters: Ed25519 bits (spki, buffer(44), Ed25519, true, [verify, verify])
Fail Good parameters: Ed25519 bits (jwk, object(kty, crv, x), {name: Ed25519}, true, [verify, verify]) Pass Good parameters: Ed25519 bits (jwk, object(kty, crv, x), {name: Ed25519}, true, [verify, verify])
Fail Good parameters: Ed25519 bits (jwk, object(kty, crv, x), Ed25519, true, [verify, verify]) Pass Good parameters: Ed25519 bits (jwk, object(kty, crv, x), Ed25519, true, [verify, verify])
Fail Good parameters with ignored JWK alg: Ed25519 (jwk, object(kty, crv, x), {name: Ed25519}, true, [verify, verify]) Pass Good parameters with ignored JWK alg: Ed25519 (jwk, object(kty, crv, x), {name: Ed25519}, true, [verify, verify])
Fail Good parameters with ignored JWK alg: Ed25519 (jwk, object(kty, crv, x), Ed25519, true, [verify, verify]) Pass Good parameters with ignored JWK alg: Ed25519 (jwk, object(kty, crv, x), Ed25519, true, [verify, verify])
Pass Good parameters: Ed25519 bits (raw, buffer(32), {name: Ed25519}, true, [verify, verify]) Pass Good parameters: Ed25519 bits (raw, buffer(32), {name: Ed25519}, true, [verify, verify])
Pass Good parameters: Ed25519 bits (raw, buffer(32), Ed25519, true, [verify, verify]) Pass Good parameters: Ed25519 bits (raw, buffer(32), Ed25519, true, [verify, verify])
Fail Good parameters: Ed25519 bits (pkcs8, buffer(48), {name: Ed25519}, true, [sign]) Fail Good parameters: Ed25519 bits (pkcs8, buffer(48), {name: Ed25519}, true, [sign])
Fail Good parameters: Ed25519 bits (pkcs8, buffer(48), Ed25519, true, [sign]) Fail Good parameters: Ed25519 bits (pkcs8, buffer(48), Ed25519, true, [sign])
Fail Good parameters: Ed25519 bits (jwk, object(crv, d, x, kty), {name: Ed25519}, true, [sign]) Pass Good parameters: Ed25519 bits (jwk, object(crv, d, x, kty), {name: Ed25519}, true, [sign])
Fail Good parameters: Ed25519 bits (jwk, object(crv, d, x, kty), Ed25519, true, [sign]) Pass Good parameters: Ed25519 bits (jwk, object(crv, d, x, kty), Ed25519, true, [sign])
Fail Good parameters with ignored JWK alg: Ed25519 (jwk, object(crv, d, x, kty), {name: Ed25519}, true, [sign]) Pass Good parameters with ignored JWK alg: Ed25519 (jwk, object(crv, d, x, kty), {name: Ed25519}, true, [sign])
Fail Good parameters with ignored JWK alg: Ed25519 (jwk, object(crv, d, x, kty), Ed25519, true, [sign]) Pass Good parameters with ignored JWK alg: Ed25519 (jwk, object(crv, d, x, kty), Ed25519, true, [sign])
Fail Good parameters: Ed25519 bits (pkcs8, buffer(48), {name: Ed25519}, true, [sign, sign]) Fail Good parameters: Ed25519 bits (pkcs8, buffer(48), {name: Ed25519}, true, [sign, sign])
Fail Good parameters: Ed25519 bits (pkcs8, buffer(48), Ed25519, true, [sign, sign]) Fail Good parameters: Ed25519 bits (pkcs8, buffer(48), Ed25519, true, [sign, sign])
Fail Good parameters: Ed25519 bits (jwk, object(crv, d, x, kty), {name: Ed25519}, true, [sign, sign]) Pass Good parameters: Ed25519 bits (jwk, object(crv, d, x, kty), {name: Ed25519}, true, [sign, sign])
Fail Good parameters: Ed25519 bits (jwk, object(crv, d, x, kty), Ed25519, true, [sign, sign]) Pass Good parameters: Ed25519 bits (jwk, object(crv, d, x, kty), Ed25519, true, [sign, sign])
Fail Good parameters with ignored JWK alg: Ed25519 (jwk, object(crv, d, x, kty), {name: Ed25519}, true, [sign, sign]) Pass Good parameters with ignored JWK alg: Ed25519 (jwk, object(crv, d, x, kty), {name: Ed25519}, true, [sign, sign])
Fail Good parameters with ignored JWK alg: Ed25519 (jwk, object(crv, d, x, kty), Ed25519, true, [sign, sign]) Pass Good parameters with ignored JWK alg: Ed25519 (jwk, object(crv, d, x, kty), Ed25519, true, [sign, sign])
Pass Good parameters: Ed25519 bits (spki, buffer(44), {name: Ed25519}, false, [verify]) Pass Good parameters: Ed25519 bits (spki, buffer(44), {name: Ed25519}, false, [verify])
Pass Good parameters: Ed25519 bits (spki, buffer(44), Ed25519, false, [verify]) Pass Good parameters: Ed25519 bits (spki, buffer(44), Ed25519, false, [verify])
Pass Good parameters: Ed25519 bits (jwk, object(kty, crv, x), {name: Ed25519}, false, [verify]) Pass Good parameters: Ed25519 bits (jwk, object(kty, crv, x), {name: Ed25519}, false, [verify])