From 9cda9018eeeea3af724061c5ad78c6eb6ab3177f Mon Sep 17 00:00:00 2001 From: Filip Skokan Date: Mon, 2 Oct 2023 18:11:39 +0200 Subject: [PATCH] test: Safari 17 now supports Ed25519 --- tap/cookbook.ts | 9 ++++++++- tap/env.ts | 17 +++++++++++++++-- tap/jwk.ts | 2 +- tap/jws.ts | 2 +- tap/pem.ts | 18 +++++++++++++++--- 5 files changed, 40 insertions(+), 8 deletions(-) diff --git a/tap/cookbook.ts b/tap/cookbook.ts index cab3c5613d..aa529d675e 100644 --- a/tap/cookbook.ts +++ b/tap/cookbook.ts @@ -7,6 +7,13 @@ import jwsVectors from '../cookbook/jws.mjs' // @ts-ignore import jweVectors from '../cookbook/jwe.mjs' +// TODO: raise in issue in WebKit +if (env.isWebKit) { + // @ts-ignore + const ed25519 = jwsVectors.find((vector) => vector.title.includes('Ed25519')) + ed25519.reproducible = false +} + export default (QUnit: QUnit, lib: typeof jose) => { const { module, test } = QUnit @@ -34,7 +41,7 @@ export default (QUnit: QUnit, lib: typeof jose) => { return !env.isDeno } if (vector.input.alg === 'EdDSA') { - return !env.isBrowser + return (env.isWebKit && env.isWebKitAbove17) || !env.isBrowser } return true } diff --git a/tap/env.ts b/tap/env.ts index ef5855b5cb..1515114591 100644 --- a/tap/env.ts +++ b/tap/env.ts @@ -27,14 +27,27 @@ export const isWorkerd = const BOWSER = 'https://cdn.jsdelivr.net/npm/bowser@2.11.0/src/bowser.js' -async function isEngine(engine: string) { +let parsedUserAgent: any +async function parseUserAgent() { const { default: Bowser } = await import(BOWSER) - return Bowser.parse(window.navigator.userAgent).engine.name === engine + parsedUserAgent || (parsedUserAgent = Bowser.parse(window.navigator.userAgent)) + return parsedUserAgent +} + +async function isEngine(engine: string) { + const userAgentData = await parseUserAgent() + return userAgentData.engine.name === engine +} + +async function isVersionAtLeast(version: number) { + const userAgentData = await parseUserAgent() + return parseInt(userAgentData.browser.version.split('.')[0], 10) >= version } export const isBlink = isBrowser && (await isEngine('Blink')) export const isWebKit = isBrowser && (await isEngine('WebKit')) +export const isWebKitAbove17 = isBrowser && isWebKit && (await isVersionAtLeast(17)) export const isGecko = isBrowser && (await isEngine('Gecko')) diff --git a/tap/jwk.ts b/tap/jwk.ts index 5b6cdd6cc4..509c508192 100644 --- a/tap/jwk.ts +++ b/tap/jwk.ts @@ -19,7 +19,7 @@ export default (QUnit: QUnit, lib: typeof jose) => { env.isDeno, ], ['ECDH-ES', KEYS.X448.jwk, env.isNode || env.isEdgeRuntime], - ['EdDSA', KEYS.Ed25519.jwk, !env.isBrowser], + ['EdDSA', KEYS.Ed25519.jwk, (env.isWebKit && env.isWebKitAbove17) || !env.isBrowser], ['EdDSA', KEYS.Ed448.jwk, env.isNode || env.isEdgeRuntime], ['ES256', KEYS.P256.jwk, true], ['ES256K', KEYS.secp256k1.jwk, env.isNodeCrypto], diff --git a/tap/jws.ts b/tap/jws.ts index ae1ed081d4..6d7efd4b68 100644 --- a/tap/jws.ts +++ b/tap/jws.ts @@ -9,7 +9,7 @@ export default (QUnit: QUnit, lib: typeof jose) => { type Vector = [string, boolean] | [string, boolean, jose.GenerateKeyPairOptions] const algorithms: Vector[] = [ - ['EdDSA', !env.isBrowser], + ['EdDSA', (env.isWebKit && env.isWebKitAbove17) || !env.isBrowser], ['EdDSA', env.isNode || env.isEdgeRuntime, { crv: 'Ed448' }], ['ES256', true], ['ES256K', env.isNodeCrypto], diff --git a/tap/pem.ts b/tap/pem.ts index f478ad356a..06395ddbda 100644 --- a/tap/pem.ts +++ b/tap/pem.ts @@ -79,9 +79,21 @@ export default (QUnit: QUnit, lib: typeof jose) => { ], [['ECDH-ES', 'X448'], KEYS.X448.pkcs8, env.isNode || env.isEdgeRuntime], [['ECDH-ES', 'X448'], KEYS.X448.spki, env.isNode || env.isEdgeRuntime], - [['EdDSA', 'Ed25519'], KEYS.Ed25519.pkcs8, !env.isBrowser], - [['EdDSA', 'Ed25519'], KEYS.Ed25519.spki, !env.isBrowser], - [['EdDSA', 'Ed25519'], KEYS.Ed25519.x509, !env.isBrowser], + [ + ['EdDSA', 'Ed25519'], + KEYS.Ed25519.pkcs8, + (env.isWebKit && env.isWebKitAbove17) || !env.isBrowser, + ], + [ + ['EdDSA', 'Ed25519'], + KEYS.Ed25519.spki, + (env.isWebKit && env.isWebKitAbove17) || !env.isBrowser, + ], + [ + ['EdDSA', 'Ed25519'], + KEYS.Ed25519.x509, + (env.isWebKit && env.isWebKitAbove17) || !env.isBrowser, + ], [['EdDSA', 'Ed448'], KEYS.Ed448.pkcs8, env.isNode || env.isEdgeRuntime], [['EdDSA', 'Ed448'], KEYS.Ed448.spki, env.isNode || env.isEdgeRuntime], [['EdDSA', 'Ed448'], KEYS.Ed448.x509, env.isNode || env.isEdgeRuntime],