From 85d21999714a43dcdc3be37d7d62586f769e98af Mon Sep 17 00:00:00 2001 From: Tankred Hase Date: Tue, 30 Sep 2014 19:31:12 +0200 Subject: [PATCH] Activate web crypto api (still fails tests) * Remove api support for safari * Fix error handling --- src/crypto/public_key/rsa.js | 16 +++++++++------- src/openpgp.js | 2 +- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/crypto/public_key/rsa.js b/src/crypto/public_key/rsa.js index f1222bd2..4b5d2923 100644 --- a/src/crypto/public_key/rsa.js +++ b/src/crypto/public_key/rsa.js @@ -139,9 +139,7 @@ function RSA() { // Native RSA keygen using Web Crypto // - if (false && typeof window !== 'undefined' && window.crypto && (window.crypto.subtle || window.crypto.webkitSubtle)) { - var subtle = window.crypto.subtle || window.crypto.webkitSubtle; - + if (typeof window !== 'undefined' && window.crypto && window.crypto.subtle) { var keyGenOpt = { name: 'RSASSA-PKCS1-v1_5', modulusLength: B, // the specified keysize in bits @@ -153,17 +151,21 @@ function RSA() { var extractable = true; // make generated key extractable - subtle.generateKey(keyGenOpt, extractable, ['sign', 'verify']) - .then(onGenerated, callback) - .then(onExported, callback); + window.crypto.subtle.generateKey(keyGenOpt, extractable, ['sign', 'verify']) + .then(onGenerated, onError) + .then(onExported, onError); return; } + function onError() { + callback(new Error('Generating key failed!')); + } + function onGenerated(key) { // export the generated keys as JsonWebKey (JWK) // https://tools.ietf.org/html/draft-ietf-jose-json-web-key-33 - return subtle.exportKey('jwk', key.privateKey); + return window.crypto.subtle.exportKey('jwk', key.privateKey); } function onExported(jwk) { diff --git a/src/openpgp.js b/src/openpgp.js index c2ecb783..24e9a026 100644 --- a/src/openpgp.js +++ b/src/openpgp.js @@ -272,7 +272,7 @@ function useWorker(callback) { * Check for WebCrypto support */ function useWebCrypto() { - return typeof window !== 'undefined' && window.crypto && (window.crypto.subtle || window.crypto.webkitSubtle); + return typeof window !== 'undefined' && window.crypto && window.crypto.subtle; } /**