From 3c2871a0e40e2139604ded10b0a72940cc099e42 Mon Sep 17 00:00:00 2001 From: Bart Butler Date: Thu, 15 Feb 2018 15:34:32 -0800 Subject: [PATCH] only access window.crypto.webkitSubtle in fallback --- src/crypto/public_key/rsa.js | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/src/crypto/public_key/rsa.js b/src/crypto/public_key/rsa.js index f479ee3a..834220e3 100644 --- a/src/crypto/public_key/rsa.js +++ b/src/crypto/public_key/rsa.js @@ -146,18 +146,7 @@ export default function RSA() { let keyGenOpt; let keys; - if (window.crypto && window.crypto.webkitSubtle) { - // outdated spec implemented by Webkit - keyGenOpt = { - name: 'RSA-OAEP', - modulusLength: B, // the specified keysize in bits - publicExponent: Euint8.subarray(0, 3), // take three bytes (max 65537) - hash: { - name: 'SHA-1' // not required for actual RSA keys, but for crypto api 'sign' and 'verify' - } - }; - keys = webCrypto.generateKey(keyGenOpt, true, ['encrypt', 'decrypt']); - } else { + if ((window.crypto && window.crypto.subtle) || window.msCrypto) { // current standard spec keyGenOpt = { name: 'RSASSA-PKCS1-v1_5', @@ -173,6 +162,21 @@ export default function RSA() { keys = util.promisifyIE11Op(keys, 'Error generating RSA key pair.'); } } + else if (window.crypto && window.crypto.webkitSubtle) { + // outdated spec implemented by old Webkit + keyGenOpt = { + name: 'RSA-OAEP', + modulusLength: B, // the specified keysize in bits + publicExponent: Euint8.subarray(0, 3), // take three bytes (max 65537) + hash: { + name: 'SHA-1' // not required for actual RSA keys, but for crypto api 'sign' and 'verify' + } + }; + keys = webCrypto.generateKey(keyGenOpt, true, ['encrypt', 'decrypt']); + } + else { + throw new Error('Unknown WebCrypto implementation'); + } return keys.then(exportKey).then(function(key) { if (key instanceof ArrayBuffer) {