From f4fc274f14362493da1fe8f259e15ee83bbb2e1c Mon Sep 17 00:00:00 2001 From: Tankred Hase Date: Thu, 24 Mar 2016 13:24:18 +0800 Subject: [PATCH] Fix: use worker for CFB w/ webcrypto support --- src/openpgp.js | 13 +++++++++++-- src/util.js | 2 +- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/openpgp.js b/src/openpgp.js index d8a312e3..b0b35f4e 100644 --- a/src/openpgp.js +++ b/src/openpgp.js @@ -158,7 +158,7 @@ export function decryptKey({ privateKey, passphrase }) { export function encrypt({ data, publicKeys, privateKeys, passwords, filename, armor=true }) { checkData(data); publicKeys = toArray(publicKeys); privateKeys = toArray(privateKeys); passwords = toArray(passwords); - if (!util.getWebCrypto() && asyncProxy) { // use web worker if web crypto apis are not supported + if (!useAEAD() && asyncProxy) { // use web worker if web crypto apis are not supported return asyncProxy.delegate('encrypt', { data, publicKeys, privateKeys, passwords, filename, armor }); } @@ -200,7 +200,7 @@ export function encrypt({ data, publicKeys, privateKeys, passwords, filename, ar export function decrypt({ message, privateKey, publicKeys, sessionKey, password, format='utf8' }) { checkMessage(message); publicKeys = toArray(publicKeys); - if (!util.getWebCrypto() && asyncProxy) { // use web worker if web crypto apis are not supported + if (!useAEAD() && asyncProxy) { // use web worker if web crypto apis are not supported return asyncProxy.delegate('decrypt', { message, privateKey, publicKeys, sessionKey, password, format }); } @@ -473,3 +473,12 @@ function onError(message, error) { // rethrow new high level error for api users throw new Error(message + ': ' + error.message); } + +/** + * Check for AES-GCM support and configuration by the user. Note that only browsers that + * implement the current WebCrypto specification support AES-GCM. + * @return {Boolean} If authenticated encryption should be used + */ +function useAEAD() { + return util.getWebCrypto() && config.aead_protect; +} \ No newline at end of file diff --git a/src/util.js b/src/util.js index 4ac04c8e..e937274d 100644 --- a/src/util.js +++ b/src/util.js @@ -450,7 +450,7 @@ export default { }, /** - * Get native Web Cryptography api, only the current versioon of the spec. + * Get native Web Cryptography api, only the current version of the spec. * The default configuration is to use the api when available. But it can * be deactivated with config.useNative * @return {Object} The SubtleCrypto api or 'undefined'