Skip to content

Commit

Permalink
Drop MS Edge Legacy support (#1474)
Browse files Browse the repository at this point in the history
  • Loading branch information
twiss committed Feb 10, 2022
1 parent 255926a commit f54b133
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 25 deletions.
2 changes: 1 addition & 1 deletion src/crypto/hash/index.js
Expand Up @@ -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'),
Expand Down
3 changes: 1 addition & 2 deletions src/crypto/mode/eax.js
Expand Up @@ -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) {
Expand Down
16 changes: 2 additions & 14 deletions src/crypto/mode/gcm.js
Expand Up @@ -52,27 +52,15 @@ 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);
return new Uint8Array(ct);
},

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);
Expand Down
9 changes: 4 additions & 5 deletions src/crypto/public_key/rsa.js
Expand Up @@ -317,16 +317,16 @@ 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 = {
name: 'RSASSA-PKCS1-v1_5',
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) {
Expand Down Expand Up @@ -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) {
Expand Down
3 changes: 0 additions & 3 deletions test/worker/application_worker.js
Expand Up @@ -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) {
Expand Down

0 comments on commit f54b133

Please sign in to comment.