Drop MS Edge Legacy support (#1474)
This commit is contained in:
parent
255926ab19
commit
f54b133085
|
@ -77,7 +77,7 @@ if (nodeCrypto) { // Use Node native crypto for all hash functions
|
||||||
} else { // Use JS fallbacks
|
} else { // Use JS fallbacks
|
||||||
hashFunctions = {
|
hashFunctions = {
|
||||||
md5: md5,
|
md5: md5,
|
||||||
sha1: asmcryptoHash(Sha1, (!navigator.userAgent || navigator.userAgent.indexOf('Edge') === -1) && 'SHA-1'),
|
sha1: asmcryptoHash(Sha1, 'SHA-1'),
|
||||||
sha224: hashjsHash(sha224),
|
sha224: hashjsHash(sha224),
|
||||||
sha256: asmcryptoHash(Sha256, 'SHA-256'),
|
sha256: asmcryptoHash(Sha256, 'SHA-256'),
|
||||||
sha384: hashjsHash(sha384, 'SHA-384'),
|
sha384: hashjsHash(sha384, 'SHA-384'),
|
||||||
|
|
|
@ -50,8 +50,7 @@ async function OMAC(key) {
|
||||||
async function CTR(key) {
|
async function CTR(key) {
|
||||||
if (
|
if (
|
||||||
util.getWebCrypto() &&
|
util.getWebCrypto() &&
|
||||||
key.length !== 24 && // WebCrypto (no 192 bit support) see: https://www.chromium.org/blink/webcrypto#TOC-AES-support
|
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 = await webCrypto.importKey('raw', key, { name: 'AES-CTR', length: key.length * 8 }, false, ['encrypt']);
|
key = await webCrypto.importKey('raw', key, { name: 'AES-CTR', length: key.length * 8 }, false, ['encrypt']);
|
||||||
return async function(pt, iv) {
|
return async function(pt, iv) {
|
||||||
|
|
|
@ -52,13 +52,7 @@ async function GCM(cipher, key) {
|
||||||
|
|
||||||
return {
|
return {
|
||||||
encrypt: async function(pt, iv, adata = new Uint8Array()) {
|
encrypt: async function(pt, iv, adata = new Uint8Array()) {
|
||||||
if (
|
if (!pt.length) { // iOS does not support GCM-en/decrypting empty messages
|
||||||
!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
|
|
||||||
) {
|
|
||||||
return AES_GCM.encrypt(pt, key, iv, adata);
|
return AES_GCM.encrypt(pt, key, iv, adata);
|
||||||
}
|
}
|
||||||
const ct = await webCrypto.encrypt({ name: ALGO, iv, additionalData: adata, tagLength: tagLength * 8 }, _key, pt);
|
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()) {
|
decrypt: async function(ct, iv, adata = new Uint8Array()) {
|
||||||
if (
|
if (ct.length === tagLength) { // iOS does not support GCM-en/decrypting empty messages
|
||||||
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
|
|
||||||
) {
|
|
||||||
return AES_GCM.decrypt(ct, key, iv, adata);
|
return AES_GCM.decrypt(ct, key, iv, adata);
|
||||||
}
|
}
|
||||||
const pt = await webCrypto.decrypt({ name: ALGO, iv, additionalData: adata, tagLength: tagLength * 8 }, _key, ct);
|
const pt = await webCrypto.decrypt({ name: ALGO, iv, additionalData: adata, tagLength: tagLength * 8 }, _key, ct);
|
||||||
|
|
|
@ -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,
|
* We swap them in privateToJWK, so it usually works out, but nevertheless,
|
||||||
* not all OpenPGP keys are compatible with this requirement.
|
* not all OpenPGP keys are compatible with this requirement.
|
||||||
* OpenPGP.js used to generate RSA keys the wrong way around (p > q), and still
|
* 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 jwk = await privateToJWK(n, e, d, p, q, u);
|
||||||
const algo = {
|
const algo = {
|
||||||
|
@ -325,8 +326,7 @@ async function webSign(hashName, data, n, e, d, p, q, u) {
|
||||||
hash: { name: hashName }
|
hash: { name: hashName }
|
||||||
};
|
};
|
||||||
const key = await webCrypto.importKey('jwk', jwk, algo, false, ['sign']);
|
const key = await webCrypto.importKey('jwk', jwk, algo, false, ['sign']);
|
||||||
// add hash field for ms edge support
|
return new Uint8Array(await webCrypto.sign('RSASSA-PKCS1-v1_5', key, data));
|
||||||
return new Uint8Array(await webCrypto.sign({ 'name': 'RSASSA-PKCS1-v1_5', 'hash': hashName }, key, data));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function nodeSign(hashAlgo, data, n, e, d, p, q, u) {
|
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',
|
name: 'RSASSA-PKCS1-v1_5',
|
||||||
hash: { name: hashName }
|
hash: { name: hashName }
|
||||||
}, false, ['verify']);
|
}, false, ['verify']);
|
||||||
// add hash field for ms edge support
|
return webCrypto.verify('RSASSA-PKCS1-v1_5', key, s, data);
|
||||||
return webCrypto.verify({ 'name': 'RSASSA-PKCS1-v1_5', 'hash': hashName }, key, s, data);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function nodeVerify(hashAlgo, data, s, n, e) {
|
async function nodeVerify(hashAlgo, data, s, n, e) {
|
||||||
|
|
|
@ -12,9 +12,6 @@ module.exports = () => tryTests('Application Worker', tests, {
|
||||||
function tests() {
|
function tests() {
|
||||||
|
|
||||||
it('Should support loading OpenPGP.js from inside a Web Worker', async function() {
|
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 {
|
try {
|
||||||
globalThis.eval('(async function() {})');
|
globalThis.eval('(async function() {})');
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user