From 83627e1c2150ca5bbbb17bc0d8d2c1cb6d70899e Mon Sep 17 00:00:00 2001 From: Daniel Huigens Date: Tue, 1 Feb 2022 17:19:52 +0100 Subject: [PATCH] Drop MS Edge Legacy support --- src/crypto/hash/index.js | 2 +- src/crypto/mode/eax.js | 3 +-- src/crypto/mode/gcm.js | 16 ++-------------- src/crypto/public_key/rsa.js | 9 ++++----- test/worker/application_worker.js | 3 --- 5 files changed, 8 insertions(+), 25 deletions(-) diff --git a/src/crypto/hash/index.js b/src/crypto/hash/index.js index 33cd4c089..27f42c6b5 100644 --- a/src/crypto/hash/index.js +++ b/src/crypto/hash/index.js @@ -77,7 +77,7 @@ if (nodeCrypto) { // Use Node native crypto for all hash functions } else { // Use JS fallbacks hashFunctions = { md5: md5, - sha1: asmcryptoHash(Sha1, (!navigator.userAgent || navigator.userAgent.indexOf('Edge') === -1) && 'SHA-1'), + sha1: asmcryptoHash(Sha1, 'SHA-1'), sha224: hashjsHash(sha224), sha256: asmcryptoHash(Sha256, 'SHA-256'), sha384: hashjsHash(sha384, 'SHA-384'), diff --git a/src/crypto/mode/eax.js b/src/crypto/mode/eax.js index 024ea6f76..2dfff46e6 100644 --- a/src/crypto/mode/eax.js +++ b/src/crypto/mode/eax.js @@ -50,8 +50,7 @@ async function OMAC(key) { async function CTR(key) { if ( util.getWebCrypto() && - key.length !== 24 && // WebCrypto (no 192 bit support) see: https://www.chromium.org/blink/webcrypto#TOC-AES-support - (!navigator.userAgent || navigator.userAgent.indexOf('Edge') === -1) + key.length !== 24 // WebCrypto (no 192 bit support) see: https://www.chromium.org/blink/webcrypto#TOC-AES-support ) { key = await webCrypto.importKey('raw', key, { name: 'AES-CTR', length: key.length * 8 }, false, ['encrypt']); return async function(pt, iv) { diff --git a/src/crypto/mode/gcm.js b/src/crypto/mode/gcm.js index 1155cfe19..5751ad673 100644 --- a/src/crypto/mode/gcm.js +++ b/src/crypto/mode/gcm.js @@ -52,13 +52,7 @@ async function GCM(cipher, key) { return { encrypt: async function(pt, iv, adata = new Uint8Array()) { - if ( - !pt.length || - // iOS does not support GCM-en/decrypting empty messages - // Also, synchronous en/decryption might be faster in this case. - (!adata.length && navigator.userAgent && navigator.userAgent.indexOf('Edge') !== -1) - // Edge does not support GCM-en/decrypting without ADATA - ) { + if (!pt.length) { // iOS does not support GCM-en/decrypting empty messages return AES_GCM.encrypt(pt, key, iv, adata); } const ct = await webCrypto.encrypt({ name: ALGO, iv, additionalData: adata, tagLength: tagLength * 8 }, _key, pt); @@ -66,13 +60,7 @@ async function GCM(cipher, key) { }, decrypt: async function(ct, iv, adata = new Uint8Array()) { - if ( - ct.length === tagLength || - // iOS does not support GCM-en/decrypting empty messages - // Also, synchronous en/decryption might be faster in this case. - (!adata.length && navigator.userAgent && navigator.userAgent.indexOf('Edge') !== -1) - // Edge does not support GCM-en/decrypting without ADATA - ) { + if (ct.length === tagLength) { // iOS does not support GCM-en/decrypting empty messages return AES_GCM.decrypt(ct, key, iv, adata); } const pt = await webCrypto.decrypt({ name: ALGO, iv, additionalData: adata, tagLength: tagLength * 8 }, _key, ct); diff --git a/src/crypto/public_key/rsa.js b/src/crypto/public_key/rsa.js index 4ad34d37c..1c081316c 100644 --- a/src/crypto/public_key/rsa.js +++ b/src/crypto/public_key/rsa.js @@ -317,7 +317,8 @@ async function webSign(hashName, data, n, e, d, p, q, u) { * We swap them in privateToJWK, so it usually works out, but nevertheless, * not all OpenPGP keys are compatible with this requirement. * OpenPGP.js used to generate RSA keys the wrong way around (p > q), and still - * does if the underlying Web Crypto does so (e.g. old MS Edge 50% of the time). + * does if the underlying Web Crypto does so (though the tested implementations + * don't do so). */ const jwk = await privateToJWK(n, e, d, p, q, u); const algo = { @@ -325,8 +326,7 @@ async function webSign(hashName, data, n, e, d, p, q, u) { hash: { name: hashName } }; const key = await webCrypto.importKey('jwk', jwk, algo, false, ['sign']); - // add hash field for ms edge support - return new Uint8Array(await webCrypto.sign({ 'name': 'RSASSA-PKCS1-v1_5', 'hash': hashName }, key, data)); + return new Uint8Array(await webCrypto.sign('RSASSA-PKCS1-v1_5', key, data)); } async function nodeSign(hashAlgo, data, n, e, d, p, q, u) { @@ -381,8 +381,7 @@ async function webVerify(hashName, data, s, n, e) { name: 'RSASSA-PKCS1-v1_5', hash: { name: hashName } }, false, ['verify']); - // add hash field for ms edge support - return webCrypto.verify({ 'name': 'RSASSA-PKCS1-v1_5', 'hash': hashName }, key, s, data); + return webCrypto.verify('RSASSA-PKCS1-v1_5', key, s, data); } async function nodeVerify(hashAlgo, data, s, n, e) { diff --git a/test/worker/application_worker.js b/test/worker/application_worker.js index e34188b25..b5d69678b 100644 --- a/test/worker/application_worker.js +++ b/test/worker/application_worker.js @@ -12,9 +12,6 @@ module.exports = () => tryTests('Application Worker', tests, { function tests() { it('Should support loading OpenPGP.js from inside a Web Worker', async function() { - if (navigator.userAgent && /Edge/.test(navigator.userAgent)) { - this.skip(); // Old Edge doesn't support crypto.getRandomValues inside a Worker. - } try { globalThis.eval('(async function() {})'); } catch (e) {