Lightpanda: the headless browser designed for AI and automation
webapi: test raw-* formats on EC keys, match formats exactly in importKind
orezraey093e02e26f03
diff --git a/src/browser/tests/crypto.html b/src/browser/tests/crypto.htmlindex 537a667c5..6171892d1 100644--- a/src/browser/tests/crypto.html+++ b/src/browser/tests/crypto.html@@ -2951,6 +2951,11 @@results["import bogus"] = await outcome(() => subtle.importKey("bogus", new Uint8Array(16), "NOPE", true, ["encrypt"]));results["import raw-public aes"] = await outcome(() => subtle.importKey("raw-public", new Uint8Array(16), "AES-GCM", true, ["encrypt"]));results["export raw-secret aes"] = await outcome(() => subtle.exportKey("raw-secret", aes));+ const ec = await subtle.generateKey({ name: "ECDSA", namedCurve: "P-256" }, true, ["sign", "verify"]);+ const ecRaw = await subtle.exportKey("raw", ec.publicKey);+ results["export raw-public ec"] = await outcome(() => subtle.exportKey("raw-public", ec.publicKey));+ results["import raw-public ec"] = await outcome(() => subtle.importKey("raw-public", ecRaw, { name: "ECDSA", namedCurve: "P-256" }, true, ["verify"]));+ results["import raw-private ec"] = await outcome(() => subtle.importKey("raw-private", new Uint8Array(32), { name: "ECDSA", namedCurve: "P-256" }, true, ["sign"]));results["wrap bogus"] = await outcome(() => subtle.wrapKey("bogus", aes, kw, "NOPE"));results["unwrap bogus"] = await outcome(() => subtle.unwrapKey("bogus", new Uint8Array(24), kw, "NOPE", "AES-GCM", true, ["encrypt"]));@@ -2977,8 +2982,11 @@"export bogus hkdf": "TypeError","import bogus": "TypeError","import raw-public aes": "NotSupportedError",- // Chrome supports raw-secret for AES.+ // Chrome supports raw-secret for AES, and raw-public for EC keys."export raw-secret aes": "NotSupportedError",+ "export raw-public ec": "NotSupportedError",+ "import raw-public ec": "NotSupportedError",+ "import raw-private ec": "NotSupportedError","wrap bogus": "TypeError","unwrap bogus": "TypeError",}, results);diff --git a/src/browser/webapi/SubtleCrypto.zig b/src/browser/webapi/SubtleCrypto.zigindex 8f99c4e2b..17430fae0 100644--- a/src/browser/webapi/SubtleCrypto.zig+++ b/src/browser/webapi/SubtleCrypto.zig@@ -264,10 +264,10 @@ fn importNormalized(/// Whether the requested format/key-data describe a private key. The format/// alone decides for DER/raw variants; for JWK the presence of `d` marks it.fn importKind(format: []const u8, key_data: algorithm.KeyData) bool {- if (eqlIgnoreCase(format, "pkcs8") or eqlIgnoreCase(format, "raw-private") or eqlIgnoreCase(format, "raw-seed")) {+ if (std.mem.eql(u8, format, "pkcs8") or std.mem.eql(u8, format, "raw-private") or std.mem.eql(u8, format, "raw-seed")) {return true;}- if (eqlIgnoreCase(format, "jwk")) {+ if (std.mem.eql(u8, format, "jwk")) {return switch (key_data) {.jwk => |j| j.d != null,.bytes => false,@@ -622,9 +622,9 @@ pub fn unwrapKey(return importNormalized(format, key_data, unwrapped_key_algo, extractable, key_usages, exec);}-/// A KeyFormat, including the raw-* ones of the Modern Algorithms draft (which-/// Chrome recognizes; none is supported here, so they're NotSupportedError-/// later). Any other string fails the WebIDL enum conversion of the format+/// A KeyFormat, including the raw-* ones of the Modern Algorithms draft. None+/// is supported here, so they're NotSupportedError later (Chrome takes+/// raw-public for EC/OKP keys and raw-secret for symmetric ones). Any other string fails the WebIDL enum conversion of the format/// argument, a TypeError before any other step.fn checkFormat(format: []const u8, local: *const js.Local) !void {const formats = [_][]const u8{ "raw", "spki", "pkcs8", "jwk", "raw-public", "raw-private", "raw-seed", "raw-secret" };