LibWeb: Fix X25519 PCKS#8 key export format

The ASN1 structure for PCKS#8 was wrong and missing one wrapping of the
key in a OctetString.

The issue was discovered while implementing `wrapKey` and `unwrapKey` in
the next commits.
This commit is contained in:
devgianlu 2024-12-14 11:18:57 +01:00 committed by Andreas Kling
parent 880401030d
commit 89f1f3f31c
Notes: github-actions[bot] 2024-12-16 10:36:16 +00:00
2 changed files with 13 additions and 11 deletions

View file

@ -5202,7 +5202,10 @@ WebIDL::ExceptionOr<GC::Ref<JS::Object>> X25519::export_key(Bindings::KeyFormat
// Set the privateKey field to the result of DER-encoding a CurvePrivateKey ASN.1 type, as defined in Section 7 of [RFC8410],
// that represents the X25519 private key represented by the [[handle]] internal slot of key
auto private_key = handle.get<ByteBuffer>();
auto data = TRY_OR_THROW_OOM(vm, ::Crypto::PK::wrap_in_private_key_info(private_key, ::Crypto::ASN1::x25519_oid));
::Crypto::ASN1::Encoder encoder;
TRY_OR_THROW_OOM(vm, encoder.write(private_key));
auto data = TRY_OR_THROW_OOM(vm, ::Crypto::PK::wrap_in_private_key_info(encoder.finish(), ::Crypto::ASN1::x25519_oid));
// 3. Let result be a new ArrayBuffer associated with the relevant global object of this [HTML], and containing data.
result = JS::ArrayBuffer::create(m_realm, data);