From 477f69cc6e6c13a61f941520a1683f3ec7e28aff Mon Sep 17 00:00:00 2001 From: ian Date: Mon, 7 Oct 2024 21:59:42 +0100 Subject: [PATCH] fix webcrypto verify in firefox use spki encoding for public keys as firefox doesn't understand raw --- vendor/priors/gwt.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/vendor/priors/gwt.js b/vendor/priors/gwt.js index 0dbe182a..b34336e6 100644 --- a/vendor/priors/gwt.js +++ b/vendor/priors/gwt.js @@ -1416,11 +1416,18 @@ function generateCrypto_sign_open(signed, publicSigningKey) { return future; } +var derHeaderPublic = [48, 42, 48, 5, 6, 3, 43, 101, 112, 3, 33, 0]; + function generateCrypto_sign_open_webcrypto(signed, publicSigningKey) { var future = peergos.shared.util.Futures.incomplete(); let signature = signed.slice(0, 64); let encoded = signed.slice(64, signed.length); - window.crypto.subtle.importKey("raw", publicSigningKey, "Ed25519", false, ["verify"]).then(publicKey => { + var spki = new Int8Array(44); + for (var i=0; i < 12; i++) + spki[i] = derHeaderPublic[i]; + for (var i=0; i < 32; i++) + spki[12+i] = publicSigningKey[i]; + window.crypto.subtle.importKey("spki", spki, "Ed25519", false, ["verify"]).then(publicKey => { return window.crypto.subtle.verify( "Ed25519", publicKey, @@ -1441,7 +1448,6 @@ function generateCrypto_sign_open_webcrypto(signed, publicSigningKey) { return future; } - var derHeader = [48, 46, 2, 1, 0, 48, 5, 6, 3, 43, 101, 112, 4, 34, 4, 32]; function generateCrypto_sign(message, secretSigningKey) { @@ -1703,7 +1709,10 @@ var tweetNaCl = { }; // use webcrypto verify if present -window.crypto.subtle.importKey("raw", new Int8Array(32), "Ed25519", false, ["verify"]).then(publicKey => { +var spki = new Int8Array(44); +for (var i=0; i < 12; i++) + spki[i] = derHeaderPublic[i]; +window.crypto.subtle.importKey("spki", spki, "Ed25519", false, ["verify"]).then(publicKey => { console.log("Using optimised webcrypto Ed25519 verify implementation."); tweetNaCl.useWebcryptoVerify = true; });