From be76df33b624338a17557abd4825caad7e8a1d44 Mon Sep 17 00:00:00 2001 From: djmaze Date: Mon, 3 May 2021 17:05:50 +0200 Subject: [PATCH] Remove OpenPGP support for IE and Node, and es6-promise polyfill --- README.md | 2 +- vendors/openpgp-2.6.2/dist/openpgp.js | 1796 ++--------------- vendors/openpgp-2.6.2/dist/openpgp.worker.js | 1 + .../openpgp-2.6.2/dist/openpgp.worker.min.js | 2 +- vendors/openpgp-2.6.2/src/crypto/gcm.js | 33 +- .../openpgp-2.6.2/src/crypto/hash/index.js | 70 +- .../src/crypto/public_key/rsa.js | 9 +- vendors/openpgp-2.6.2/src/crypto/random.js | 4 - vendors/openpgp-2.6.2/src/hkp.js | 4 +- .../openpgp-2.6.2/src/keyring/localstore.js | 6 +- vendors/openpgp-2.6.2/src/openpgp.js | 2 - .../sym_encrypted_integrity_protected.js | 33 +- vendors/openpgp-2.6.2/src/util.js | 60 - 13 files changed, 198 insertions(+), 1824 deletions(-) diff --git a/README.md b/README.md index 8e1622c5e..e76eb1575 100644 --- a/README.md +++ b/README.md @@ -139,7 +139,7 @@ RainLoop 1.15 vs SnappyMail |OpenPGP |RainLoop |Snappy |RL gzip |SM gzip |RL brotli |SM brotli | |--------------- |--------: |--------: |------: |------: |--------: |--------: | -|openpgp.min.js | 330.742 | 330.300 |102.388 |102.388 | 84.241 | 84.121 | +|openpgp.min.js | 330.742 | 320.189 |102.388 | 98.725 | 84.241 | 81.253 | |openpgp.worker | 1.499 | 1.125 | 824 | 567 | 695 | 467 | For a user its around 66% smaller and faster than traditional RainLoop. diff --git a/vendors/openpgp-2.6.2/dist/openpgp.js b/vendors/openpgp-2.6.2/dist/openpgp.js index ec68e8c69..f54de4208 100644 --- a/vendors/openpgp-2.6.2/dist/openpgp.js +++ b/vendors/openpgp-2.6.2/dist/openpgp.js @@ -1,4 +1,5 @@ -(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.openpgp = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o postsJSON - values[1] // => commentsJSON - - return values; - }); - ``` - - @class Promise - @param {function} resolver - Useful for tooling. - @constructor -*/ -function Promise$2(resolver) { - this[PROMISE_ID] = nextId(); - this._result = this._state = undefined; - this._subscribers = []; - - if (noop !== resolver) { - typeof resolver !== 'function' && needsResolver(); - this instanceof Promise$2 ? initializePromise(this, resolver) : needsNew(); - } -} - -Promise$2.all = all$1; -Promise$2.race = race$1; -Promise$2.resolve = resolve$1; -Promise$2.reject = reject$1; -Promise$2._setScheduler = setScheduler; -Promise$2._setAsap = setAsap; -Promise$2._asap = asap; - -Promise$2.prototype = { - constructor: Promise$2, - - /** - The primary way of interacting with a promise is through its `then` method, - which registers callbacks to receive either a promise's eventual value or the - reason why the promise cannot be fulfilled. - - ```js - findUser().then(function(user){ - // user is available - }, function(reason){ - // user is unavailable, and you are given the reason why - }); - ``` - - Chaining - -------- - - The return value of `then` is itself a promise. This second, 'downstream' - promise is resolved with the return value of the first promise's fulfillment - or rejection handler, or rejected if the handler throws an exception. - - ```js - findUser().then(function (user) { - return user.name; - }, function (reason) { - return 'default name'; - }).then(function (userName) { - // If `findUser` fulfilled, `userName` will be the user's name, otherwise it - // will be `'default name'` - }); - - findUser().then(function (user) { - throw new Error('Found user, but still unhappy'); - }, function (reason) { - throw new Error('`findUser` rejected and we're unhappy'); - }).then(function (value) { - // never reached - }, function (reason) { - // if `findUser` fulfilled, `reason` will be 'Found user, but still unhappy'. - // If `findUser` rejected, `reason` will be '`findUser` rejected and we're unhappy'. - }); - ``` - If the downstream promise does not specify a rejection handler, rejection reasons will be propagated further downstream. - - ```js - findUser().then(function (user) { - throw new PedagogicalException('Upstream error'); - }).then(function (value) { - // never reached - }).then(function (value) { - // never reached - }, function (reason) { - // The `PedgagocialException` is propagated all the way down to here - }); - ``` - - Assimilation - ------------ - - Sometimes the value you want to propagate to a downstream promise can only be - retrieved asynchronously. This can be achieved by returning a promise in the - fulfillment or rejection handler. The downstream promise will then be pending - until the returned promise is settled. This is called *assimilation*. - - ```js - findUser().then(function (user) { - return findCommentsByAuthor(user); - }).then(function (comments) { - // The user's comments are now available - }); - ``` - - If the assimliated promise rejects, then the downstream promise will also reject. - - ```js - findUser().then(function (user) { - return findCommentsByAuthor(user); - }).then(function (comments) { - // If `findCommentsByAuthor` fulfills, we'll have the value here - }, function (reason) { - // If `findCommentsByAuthor` rejects, we'll have the reason here - }); - ``` - - Simple Example - -------------- - - Synchronous Example - - ```javascript - let result; - - try { - result = findResult(); - // success - } catch(reason) { - // failure - } - ``` - - Errback Example - - ```js - findResult(function(result, err){ - if (err) { - // failure - } else { - // success - } - }); - ``` - - Promise Example; - - ```javascript - findResult().then(function(result){ - // success - }, function(reason){ - // failure - }); - ``` - - Advanced Example - -------------- - - Synchronous Example - - ```javascript - let author, books; - - try { - author = findAuthor(); - books = findBooksByAuthor(author); - // success - } catch(reason) { - // failure - } - ``` - - Errback Example - - ```js - - function foundBooks(books) { - - } - - function failure(reason) { - - } - - findAuthor(function(author, err){ - if (err) { - failure(err); - // failure - } else { - try { - findBoooksByAuthor(author, function(books, err) { - if (err) { - failure(err); - } else { - try { - foundBooks(books); - } catch(reason) { - failure(reason); - } - } - }); - } catch(error) { - failure(err); - } - // success - } - }); - ``` - - Promise Example; - - ```javascript - findAuthor(). - then(findBooksByAuthor). - then(function(books){ - // found books - }).catch(function(reason){ - // something went wrong - }); - ``` - - @method then - @param {Function} onFulfilled - @param {Function} onRejected - Useful for tooling. - @return {Promise} - */ - then: then, - - /** - `catch` is simply sugar for `then(undefined, onRejection)` which makes it the same - as the catch block of a try/catch statement. - - ```js - function findAuthor(){ - throw new Error('couldn't find that author'); - } - - // synchronous - try { - findAuthor(); - } catch(reason) { - // something went wrong - } - - // async with promises - findAuthor().catch(function(reason){ - // something went wrong - }); - ``` - - @method catch - @param {Function} onRejection - Useful for tooling. - @return {Promise} - */ - 'catch': function _catch(onRejection) { - return this.then(null, onRejection); - } -}; - -/*global self*/ -function polyfill$1() { - var local = undefined; - - if (typeof global !== 'undefined') { - local = global; - } else if (typeof self !== 'undefined') { - local = self; - } else { - try { - local = Function('return this')(); - } catch (e) { - throw new Error('polyfill failed because global object is unavailable in this environment'); - } - } - - var P = local.Promise; - - if (P) { - var promiseToString = null; - try { - promiseToString = Object.prototype.toString.call(P.resolve()); - } catch (e) { - // silently ignored - } - - if (promiseToString === '[object Promise]' && !P.cast) { - return; - } - } - - local.Promise = Promise$2; -} - -// Strange compat.. -Promise$2.polyfill = polyfill$1; -Promise$2.Promise = Promise$2; - -return Promise$2; - -}))); - - - -}).call(this,_dereq_('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) -},{"_process":3}],3:[function(_dereq_,module,exports){ -// shim for using process in browser -var process = module.exports = {}; - -// cached from whatever global is present so that test runners that stub it -// don't break things. But we need to wrap it in a try catch in case it is -// wrapped in strict mode code which doesn't define any globals. It's inside a -// function because try/catches deoptimize in certain engines. - -var cachedSetTimeout; -var cachedClearTimeout; - -function defaultSetTimout() { - throw new Error('setTimeout has not been defined'); -} -function defaultClearTimeout () { - throw new Error('clearTimeout has not been defined'); -} -(function () { - try { - if (typeof setTimeout === 'function') { - cachedSetTimeout = setTimeout; - } else { - cachedSetTimeout = defaultSetTimout; - } - } catch (e) { - cachedSetTimeout = defaultSetTimout; - } - try { - if (typeof clearTimeout === 'function') { - cachedClearTimeout = clearTimeout; - } else { - cachedClearTimeout = defaultClearTimeout; - } - } catch (e) { - cachedClearTimeout = defaultClearTimeout; - } -} ()) -function runTimeout(fun) { - if (cachedSetTimeout === setTimeout) { - //normal enviroments in sane situations - return setTimeout(fun, 0); - } - // if setTimeout wasn't available but was latter defined - if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) { - cachedSetTimeout = setTimeout; - return setTimeout(fun, 0); - } - try { - // when when somebody has screwed with setTimeout but no I.E. maddness - return cachedSetTimeout(fun, 0); - } catch(e){ - try { - // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally - return cachedSetTimeout.call(null, fun, 0); - } catch(e){ - // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error - return cachedSetTimeout.call(this, fun, 0); - } - } - - -} -function runClearTimeout(marker) { - if (cachedClearTimeout === clearTimeout) { - //normal enviroments in sane situations - return clearTimeout(marker); - } - // if clearTimeout wasn't available but was latter defined - if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) { - cachedClearTimeout = clearTimeout; - return clearTimeout(marker); - } - try { - // when when somebody has screwed with setTimeout but no I.E. maddness - return cachedClearTimeout(marker); - } catch (e){ - try { - // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally - return cachedClearTimeout.call(null, marker); - } catch (e){ - // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error. - // Some versions of I.E. have different rules for clearTimeout vs setTimeout - return cachedClearTimeout.call(this, marker); - } - } - - - -} -var queue = []; -var draining = false; -var currentQueue; -var queueIndex = -1; - -function cleanUpNextTick() { - if (!draining || !currentQueue) { - return; - } - draining = false; - if (currentQueue.length) { - queue = currentQueue.concat(queue); - } else { - queueIndex = -1; - } - if (queue.length) { - drainQueue(); - } -} - -function drainQueue() { - if (draining) { - return; - } - var timeout = runTimeout(cleanUpNextTick); - draining = true; - - var len = queue.length; - while(len) { - currentQueue = queue; - queue = []; - while (++queueIndex < len) { - if (currentQueue) { - currentQueue[queueIndex].run(); - } - } - queueIndex = -1; - len = queue.length; - } - currentQueue = null; - draining = false; - runClearTimeout(timeout); -} - -process.nextTick = function (fun) { - var args = new Array(arguments.length - 1); - if (arguments.length > 1) { - for (var i = 1; i < arguments.length; i++) { - args[i - 1] = arguments[i]; - } - } - queue.push(new Item(fun, args)); - if (queue.length === 1 && !draining) { - runTimeout(drainQueue); - } -}; - -// v8 likes predictible objects -function Item(fun, array) { - this.fun = fun; - this.array = array; -} -Item.prototype.run = function () { - this.fun.apply(null, this.array); -}; -process.title = 'browser'; -process.browser = true; -process.env = {}; -process.argv = []; -process.version = ''; // empty string to avoid regexp issues -process.versions = {}; - -function noop() {} - -process.on = noop; -process.addListener = noop; -process.once = noop; -process.off = noop; -process.removeListener = noop; -process.removeAllListeners = noop; -process.emit = noop; -process.prependListener = noop; -process.prependOnceListener = noop; - -process.listeners = function (name) { return [] } - -process.binding = function (name) { - throw new Error('process.binding is not supported'); -}; - -process.cwd = function () { return '/' }; -process.chdir = function (dir) { - throw new Error('process.chdir is not supported'); -}; -process.umask = function() { return 0; }; - -},{}],4:[function(_dereq_,module,exports){ +},{}], +4:[function(_dereq_,module,exports){ (function (global){ (function () { function Rusha(chunkSize) { @@ -4794,7 +3449,8 @@ process.umask = function() { return 0; }; } }()); }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) -},{}],5:[function(_dereq_,module,exports){ +},{}], +5:[function(_dereq_,module,exports){ // GPG4Browsers - An OpenPGP implementation in javascript // Copyright (C) 2011 Recurity Labs GmbH // @@ -5054,7 +3710,8 @@ function verifyHeaders(headers, packetlist) { } } -},{"./config":10,"./encoding/armor.js":33,"./enums.js":35,"./packet":47,"./signature.js":66}],6:[function(_dereq_,module,exports){ +},{"./config":10,"./encoding/armor.js":33,"./enums.js":35,"./packet":47,"./signature.js":66}], +6:[function(_dereq_,module,exports){ /** @license zlib.js 2012 - imaya [ https://github.com/imaya/zlib.js ] The MIT License */(function() {'use strict';var n=void 0,u=!0,aa=this;function ba(e,d){var c=e.split("."),f=aa;!(c[0]in f)&&f.execScript&&f.execScript("var "+c[0]);for(var a;c.length&&(a=c.shift());)!c.length&&d!==n?f[a]=d:f=f[a]?f[a]:f[a]={}};var C="undefined"!==typeof Uint8Array&&"undefined"!==typeof Uint16Array&&"undefined"!==typeof Uint32Array&&"undefined"!==typeof DataView;function K(e,d){this.index="number"===typeof d?d:0;this.d=0;this.buffer=e instanceof(C?Uint8Array:Array)?e:new (C?Uint8Array:Array)(32768);if(2*this.buffer.length<=this.index)throw Error("invalid index");this.buffer.length<=this.index&&ca(this)}function ca(e){var d=e.buffer,c,f=d.length,a=new (C?Uint8Array:Array)(f<<1);if(C)a.set(d);else for(c=0;c>>8&255]<<16|L[e>>>16&255]<<8|L[e>>>24&255])>>32-d:L[e]>>8-d);if(8>d+b)k=k<>d-m-1&1,8===++b&&(b=0,f[a++]=L[k],k=0,a===f.length&&(f=ca(this)));f[a]=k;this.buffer=f;this.d=b;this.index=a};K.prototype.finish=function(){var e=this.buffer,d=this.index,c;0M;++M){for(var R=M,S=R,ha=7,R=R>>>1;R;R>>>=1)S<<=1,S|=R&1,--ha;ga[M]=(S<>>0}var L=ga;function ja(e){this.buffer=new (C?Uint16Array:Array)(2*e);this.length=0}ja.prototype.getParent=function(e){return 2*((e-2)/4|0)};ja.prototype.push=function(e,d){var c,f,a=this.buffer,b;c=this.length;a[this.length++]=d;for(a[this.length++]=e;0a[f])b=a[c],a[c]=a[f],a[f]=b,b=a[c+1],a[c+1]=a[f+1],a[f+1]=b,c=f;else break;return this.length}; @@ -5079,7 +3736,8 @@ function Ja(e,d,c){function f(a){var b=g[a][p[a]];b===d?(f(a+1),f(a+1)):--k[b];+ 1][q]=e[q],g[c-1][q]=q;for(l=0;le[l]?(m[h][q]=t,g[h][q]=d,w+=2):(m[h][q]=e[l],g[h][q]=l,++l);p[h]=0;1===b[h]&&f(h)}return k} function pa(e){var d=new (C?Uint16Array:Array)(e.length),c=[],f=[],a=0,b,k,m,g;b=0;for(k=e.length;b>>=1}return d};ba("Zlib.RawDeflate",ka);ba("Zlib.RawDeflate.prototype.compress",ka.prototype.h);var Ka={NONE:0,FIXED:1,DYNAMIC:ma},V,La,$,Ma;if(Object.keys)V=Object.keys(Ka);else for(La in V=[],$=0,Ka)V[$++]=La;$=0;for(Ma=V.length;$a&&(a=c[p]),c[p]>=1;x=g<<16|p;for(s=n;s>>=1;switch(c){case 0:var d=this.input,a=this.d,b=this.b,e=this.a,f=d.length,g=k,h=k,l=b.length,n=k;this.c=this.f=0;if(a+1>=f)throw Error("invalid uncompressed block header: LEN");g=d[a++]|d[a++]<<8;if(a+1>=f)throw Error("invalid uncompressed block header: NLEN");h=d[a++]|d[a++]<<8;if(g===~h)throw Error("invalid uncompressed block header: length verify");if(a+g>d.length)throw Error("input buffer is broken");switch(this.i){case A:for(;e+g> @@ -5095,7 +3753,8 @@ w.prototype.u=function(c){var d,a=this.input.length/this.d+1|0,b,e,f,g=this.inpu w.prototype.m=function(){var c=0,d=this.b,a=this.g,b,e=new (t?Uint8Array:Array)(this.k+(this.a-32768)),f,g,h,l;if(0===a.length)return t?this.b.subarray(32768,this.a):this.b.slice(32768,this.a);f=0;for(g=a.length;fd&&(this.b.length=d),c=this.b);return this.buffer=c};r("Zlib.RawInflate",w);r("Zlib.RawInflate.prototype.decompress",w.prototype.t);var X={ADAPTIVE:y,BLOCK:A},Y,Z,$,fa;if(Object.keys)Y=Object.keys(X);else for(Z in Y=[],$=0,X)Y[$++]=Z;$=0;for(fa=Y.length;$>>8&255]<<16|Q[d>>>16&255]<<8|Q[d>>>24&255])>>32-a:Q[d]>>8-a);if(8>a+f)g=g<>a-h-1&1,8===++f&&(f=0,e[b++]=Q[g],g=0,b===e.length&&(e=this.f()));e[b]=g;this.buffer=e;this.i=f;this.index=b};I.prototype.finish=function(){var d=this.buffer,a=this.index,c;0ca;++ca){for(var R=ca,ha=R,ia=7,R=R>>>1;R;R>>>=1)ha<<=1,ha|=R&1,--ia;ba[ca]=(ha<>>0}var Q=ba;function ja(d){this.buffer=new (G?Uint16Array:Array)(2*d);this.length=0}ja.prototype.getParent=function(d){return 2*((d-2)/4|0)};ja.prototype.push=function(d,a){var c,e,b=this.buffer,f;c=this.length;b[this.length++]=a;for(b[this.length++]=d;0b[e])f=b[c],b[c]=b[e],b[e]=f,f=b[c+1],b[c+1]=b[e+1],b[e+1]=f,c=e;else break;return this.length}; @@ -5136,7 +3795,8 @@ jb.prototype.p=function(){var d=this.input,a,c;a=this.A.p();this.c=this.A.c;this lb.prototype.j=function(){var d,a,c,e,b,f,g,h=0;g=this.a;d=kb;switch(d){case kb:a=Math.LOG2E*Math.log(32768)-8;break;default:m(Error("invalid compression method"))}c=a<<4|d;g[h++]=c;switch(d){case kb:switch(this.h){case X.NONE:b=0;break;case X.r:b=1;break;case X.k:b=2;break;default:m(Error("unsupported compression type"))}break;default:m(Error("invalid compression method"))}e=b<<6|0;g[h++]=e|31-(256*c+e)%31;f=ib(this.input);this.z.b=h;g=this.z.j();h=g.length;G&&(g=new Uint8Array(g.buffer),g.length<= h+4&&(this.a=new Uint8Array(g.length+4),this.a.set(g),g=this.a),g=g.subarray(0,h+4));g[h++]=f>>24&255;g[h++]=f>>16&255;g[h++]=f>>8&255;g[h++]=f&255;return g};function mb(d,a){var c,e,b,f;if(Object.keys)c=Object.keys(a);else for(e in c=[],b=0,a)c[b++]=e;b=0;for(f=c.length;b{var n=e.data||{};switch(n.event){case"configure":configure(n.config);break;case"seed-random":seedRandom(n.buf);break;default:delegate(n.id,n.event,n.options||{})}}; +self.window={};importScripts("openpgp.min.js");var openpgp=window.openpgp,MIN_SIZE_RANDOM_BUFFER=4e4,MAX_SIZE_RANDOM_BUFFER=6e4;function configure(e){for(var n in e)openpgp.config[n]=e[n]}function seedRandom(e){e instanceof Uint8Array||(e=new Uint8Array(e)),openpgp.crypto.random.randomBuffer.set(e)}function delegate(e,n,o){"function"==typeof openpgp[n]?(o=openpgp.packet.clone.parseClonedPackets(o,n),openpgp[n](o).then((function(n){response({id:e,event:"method-return",data:openpgp.packet.clone.clonePackets(n)})})).catch((function(n){response({id:e,event:"method-return",err:n.message,stack:n.stack})}))):response({id:e,event:"method-return",err:"Unknown Worker Event"})}function response(e){openpgp.crypto.random.randomBuffer.size{var n=e.data||{};switch(n.event){case"configure":configure(n.config);break;case"seed-random":seedRandom(n.buf);break;default:delegate(n.id,n.event,n.options||{})}}; diff --git a/vendors/openpgp-2.6.2/src/crypto/gcm.js b/vendors/openpgp-2.6.2/src/crypto/gcm.js index b06b73184..309f8428f 100644 --- a/vendors/openpgp-2.6.2/src/crypto/gcm.js +++ b/vendors/openpgp-2.6.2/src/crypto/gcm.js @@ -26,8 +26,6 @@ import util from '../util.js'; import config from '../config'; import asmCrypto from 'asmcrypto-lite'; const webCrypto = util.getWebCrypto(); // no GCM support in IE11, Safari 9 -const nodeCrypto = util.getNodeCrypto(); -const Buffer = util.getNodeBuffer(); export const ivLength = 12; // size of the IV in bytes const TAG_LEN = 16; // size of the tag in bytes @@ -48,11 +46,9 @@ export function encrypt(cipher, plaintext, key, iv) { if (webCrypto && config.use_native && key.length !== 24) { // WebCrypto (no 192 bit support) see: https://www.chromium.org/blink/webcrypto#TOC-AES-support return webEncrypt(plaintext, key, iv); - } else if (nodeCrypto && config.use_native) { // Node crypto library - return nodeEncrypt(plaintext, key, iv) ; - } else { // asm.js fallback - return Promise.resolve(asmCrypto.AES_GCM.encrypt(plaintext, key, iv)); } + // asm.js fallback + return Promise.resolve(asmCrypto.AES_GCM.encrypt(plaintext, key, iv)); } /** @@ -70,11 +66,9 @@ export function decrypt(cipher, ciphertext, key, iv) { if (webCrypto && config.use_native && key.length !== 24) { // WebCrypto (no 192 bit support) see: https://www.chromium.org/blink/webcrypto#TOC-AES-support return webDecrypt(ciphertext, key, iv); - } else if (nodeCrypto && config.use_native) { // Node crypto library - return nodeDecrypt(ciphertext, key, iv); - } else { // asm.js fallback - return Promise.resolve(asmCrypto.AES_GCM.decrypt(ciphertext, key, iv)); } + // asm.js fallback + return Promise.resolve(asmCrypto.AES_GCM.decrypt(ciphertext, key, iv)); } @@ -96,22 +90,3 @@ function webDecrypt(ct, key, iv) { .then(keyObj => webCrypto.decrypt({ name: ALGO, iv }, keyObj, ct)) .then(pt => new Uint8Array(pt)); } - -function nodeEncrypt(pt, key, iv) { - pt = new Buffer(pt); - key = new Buffer(key); - iv = new Buffer(iv); - const en = new nodeCrypto.createCipheriv('aes-' + (key.length * 8) + '-gcm', key, iv); - const ct = Buffer.concat([en.update(pt), en.final(), en.getAuthTag()]); // append auth tag to ciphertext - return Promise.resolve(new Uint8Array(ct)); -} - -function nodeDecrypt(ct, key, iv) { - ct = new Buffer(ct); - key = new Buffer(key); - iv = new Buffer(iv); - const de = new nodeCrypto.createDecipheriv('aes-' + (key.length * 8) + '-gcm', key, iv); - de.setAuthTag(ct.slice(ct.length - TAG_LEN, ct.length)); // read auth tag at end of ciphertext - const pt = Buffer.concat([de.update(ct.slice(0, ct.length - TAG_LEN)), de.final()]); - return Promise.resolve(new Uint8Array(pt)); -} \ No newline at end of file diff --git a/vendors/openpgp-2.6.2/src/crypto/hash/index.js b/vendors/openpgp-2.6.2/src/crypto/hash/index.js index 27be2d774..a5e4c0b61 100644 --- a/vendors/openpgp-2.6.2/src/crypto/hash/index.js +++ b/vendors/openpgp-2.6.2/src/crypto/hash/index.js @@ -15,62 +15,26 @@ import md5 from './md5.js'; import ripemd from './ripe-md.js'; import util from '../../util.js'; -const rusha = new Rusha(), - nodeCrypto = util.getNodeCrypto(), - Buffer = util.getNodeBuffer(); - -function node_hash(type) { - return function (data) { - var shasum = nodeCrypto.createHash(type); - shasum.update(new Buffer(data)); - return new Uint8Array(shasum.digest()); - }; -} - -var hash_fns; -if(nodeCrypto) { // Use Node native crypto for all hash functions - - hash_fns = { - md5: node_hash('md5'), - sha1: node_hash('sha1'), - sha224: node_hash('sha224'), - sha256: node_hash('sha256'), - sha384: node_hash('sha384'), - sha512: node_hash('sha512'), - ripemd: node_hash('ripemd160') - }; - -} else { // Use JS fallbacks - - hash_fns = { - /** @see module:crypto/hash/md5 */ - md5: md5, - /** @see module:rusha */ - sha1: function(data) { - return util.str2Uint8Array(util.hex2bin(rusha.digest(data))); - }, - /** @see module:crypto/hash/sha.sha224 */ - sha224: sha.sha224, - /** @see module:asmcrypto */ - sha256: asmCrypto.SHA256.bytes, - /** @see module:crypto/hash/sha.sha384 */ - sha384: sha.sha384, - /** @see module:crypto/hash/sha.sha512 */ - sha512: sha.sha512, - /** @see module:crypto/hash/ripe-md */ - ripemd: ripemd - }; -} +const rusha = new Rusha(); export default { - md5: hash_fns.md5, - sha1: hash_fns.sha1, - sha224: hash_fns.sha224, - sha256: hash_fns.sha256, - sha384: hash_fns.sha384, - sha512: hash_fns.sha512, - ripemd: hash_fns.ripemd, + /** @see module:crypto/hash/md5 */ + md5: md5, + /** @see module:rusha */ + sha1: function(data) { + return util.str2Uint8Array(util.hex2bin(rusha.digest(data))); + }, + /** @see module:crypto/hash/sha.sha224 */ + sha224: sha.sha224, + /** @see module:asmcrypto */ + sha256: asmCrypto.SHA256.bytes, + /** @see module:crypto/hash/sha.sha384 */ + sha384: sha.sha384, + /** @see module:crypto/hash/sha.sha512 */ + sha512: sha.sha512, + /** @see module:crypto/hash/ripe-md */ + ripemd: ripemd, /** * Create a hash on the specified data using the specified algorithm diff --git a/vendors/openpgp-2.6.2/src/crypto/public_key/rsa.js b/vendors/openpgp-2.6.2/src/crypto/public_key/rsa.js index e87eb9041..af53cf126 100644 --- a/vendors/openpgp-2.6.2/src/crypto/public_key/rsa.js +++ b/vendors/openpgp-2.6.2/src/crypto/public_key/rsa.js @@ -172,9 +172,6 @@ export default function RSA() { }; keys = webCrypto.generateKey(keyGenOpt, true, ['sign', 'verify']); - if (typeof keys.then !== 'function') { // IE11 KeyOperation - keys = util.promisifyIE11Op(keys, 'Error generating RSA key pair.'); - } } return keys.then(exportKey).then(function(key) { @@ -189,11 +186,7 @@ export default function RSA() { function exportKey(keypair) { // export the generated keys as JsonWebKey (JWK) // https://tools.ietf.org/html/draft-ietf-jose-json-web-key-33 - var key = webCrypto.exportKey('jwk', keypair.privateKey); - if (typeof key.then !== 'function') { // IE11 KeyOperation - key = util.promisifyIE11Op(key, 'Error exporting RSA key pair.'); - } - return key; + return webCrypto.exportKey('jwk', keypair.privateKey); } function decodeKey(jwk) { diff --git a/vendors/openpgp-2.6.2/src/crypto/random.js b/vendors/openpgp-2.6.2/src/crypto/random.js index 4e2331a41..724bd1fd6 100644 --- a/vendors/openpgp-2.6.2/src/crypto/random.js +++ b/vendors/openpgp-2.6.2/src/crypto/random.js @@ -27,7 +27,6 @@ import type_mpi from '../type/mpi.js'; import util from '../util.js'; -const nodeCrypto = util.detectNode() && require('crypto'); export default { /** @@ -83,9 +82,6 @@ export default { window.crypto.getRandomValues(buf); } else if (typeof window !== 'undefined' && typeof window.msCrypto === 'object' && typeof window.msCrypto.getRandomValues === 'function') { window.msCrypto.getRandomValues(buf); - } else if (nodeCrypto) { - var bytes = nodeCrypto.randomBytes(buf.length); - buf.set(bytes); } else if (this.randomBuffer.buffer) { this.randomBuffer.get(buf); } else { diff --git a/vendors/openpgp-2.6.2/src/hkp.js b/vendors/openpgp-2.6.2/src/hkp.js index 5c967c8d0..0b89db420 100644 --- a/vendors/openpgp-2.6.2/src/hkp.js +++ b/vendors/openpgp-2.6.2/src/hkp.js @@ -32,7 +32,7 @@ import config from './config'; */ export default function HKP(keyServerBaseUrl) { this._baseUrl = keyServerBaseUrl ? keyServerBaseUrl : config.keyserver; - this._fetch = typeof window !== 'undefined' ? window.fetch : require('node-fetch'); + this._fetch = window.fetch; } /** @@ -83,4 +83,4 @@ HKP.prototype.upload = function(publicKeyArmored) { }, body: 'keytext=' + encodeURIComponent(publicKeyArmored) }); -}; \ No newline at end of file +}; diff --git a/vendors/openpgp-2.6.2/src/keyring/localstore.js b/vendors/openpgp-2.6.2/src/keyring/localstore.js index 3a1d6680a..b3fc03a8d 100644 --- a/vendors/openpgp-2.6.2/src/keyring/localstore.js +++ b/vendors/openpgp-2.6.2/src/keyring/localstore.js @@ -63,11 +63,7 @@ export default class LocalStore prefix = prefix || 'openpgp-'; this.publicKeysItem = prefix + this.publicKeysItem; this.privateKeysItem = prefix + this.privateKeysItem; - if (typeof window !== 'undefined' && window.localStorage) { - this.storage = window.localStorage; - } else { - this.storage = new (require('node-localstorage').LocalStorage)(config.node_store); - } + this.storage = window.localStorage; } /** diff --git a/vendors/openpgp-2.6.2/src/openpgp.js b/vendors/openpgp-2.6.2/src/openpgp.js index ba4d27aff..2d846d889 100644 --- a/vendors/openpgp-2.6.2/src/openpgp.js +++ b/vendors/openpgp-2.6.2/src/openpgp.js @@ -38,8 +38,6 @@ import * as key from './key.js'; import config from './config/config.js'; import util from './util'; import AsyncProxy from './worker/async_proxy.js'; -import es6Promise from 'es6-promise'; -es6Promise.polyfill(); // load ES6 Promises polyfill ////////////////////////// diff --git a/vendors/openpgp-2.6.2/src/packet/sym_encrypted_integrity_protected.js b/vendors/openpgp-2.6.2/src/packet/sym_encrypted_integrity_protected.js index 24fbd8423..9f216afbb 100644 --- a/vendors/openpgp-2.6.2/src/packet/sym_encrypted_integrity_protected.js +++ b/vendors/openpgp-2.6.2/src/packet/sym_encrypted_integrity_protected.js @@ -38,8 +38,6 @@ import util from '../util.js'; import crypto from '../crypto'; import enums from '../enums.js'; import asmCrypto from 'asmcrypto-lite'; -const nodeCrypto = util.getNodeCrypto(); -const Buffer = util.getNodeBuffer(); const VERSION = 1; // A one-octet version number of the data packet. @@ -144,36 +142,9 @@ SymEncryptedIntegrityProtected.prototype.decrypt = function (sessionKeyAlgorithm function aesEncrypt(algo, prefix, pt, key) { - if(nodeCrypto) { // Node crypto library. - return nodeEncrypt(algo, prefix, pt, key); - } else { // asm.js fallback - return asmCrypto.AES_CFB.encrypt(util.concatUint8Array([prefix, pt]), key); - } + return asmCrypto.AES_CFB.encrypt(util.concatUint8Array([prefix, pt]), key); } function aesDecrypt(algo, ct, key) { - let pt; - if(nodeCrypto) { // Node crypto library. - pt = nodeDecrypt(algo, ct, key); - } else { // asm.js fallback - pt = asmCrypto.AES_CFB.decrypt(ct, key); - } - return pt.subarray(crypto.cipher[algo].blockSize + 2, pt.length); // Remove random prefix + return asmCrypto.AES_CFB.decrypt(ct, key).subarray(crypto.cipher[algo].blockSize + 2, pt.length); // Remove random prefix } - -function nodeEncrypt(algo, prefix, pt, key) { - key = new Buffer(key); - const iv = new Buffer(new Uint8Array(crypto.cipher[algo].blockSize)); - const cipherObj = new nodeCrypto.createCipheriv('aes-' + algo.substr(3,3) + '-cfb', key, iv); - const ct = cipherObj.update(new Buffer(util.concatUint8Array([prefix, pt]))); - return new Uint8Array(ct); -} - -function nodeDecrypt(algo, ct, key) { - ct = new Buffer(ct); - key = new Buffer(key); - const iv = new Buffer(new Uint8Array(crypto.cipher[algo].blockSize)); - const decipherObj = new nodeCrypto.createDecipheriv('aes-' + algo.substr(3,3) + '-cfb', key, iv); - const pt = decipherObj.update(ct); - return new Uint8Array(pt); -} \ No newline at end of file diff --git a/vendors/openpgp-2.6.2/src/util.js b/vendors/openpgp-2.6.2/src/util.js index f2d8bdef5..a4999dbd3 100644 --- a/vendors/openpgp-2.6.2/src/util.js +++ b/vendors/openpgp-2.6.2/src/util.js @@ -485,71 +485,11 @@ export default { } }, - /** - * Wraps a generic synchronous function in an ES6 Promise. - * @param {Function} fn The function to be wrapped - * @return {Function} The function wrapped in a Promise - */ - promisify: function(fn) { - return function() { - var args = arguments; - return new Promise(function(resolve) { - var result = fn.apply(null, args); - resolve(result); - }); - }; - }, - - /** - * Converts an IE11 web crypro api result to a promise. - * This is required since IE11 implements an old version of the - * Web Crypto specification that does not use promises. - * @param {Object} cryptoOp The return value of an IE11 web cryptro api call - * @param {String} errmsg An error message for a specific operation - * @return {Promise} The resulting Promise - */ - promisifyIE11Op: function(cryptoOp, errmsg) { - return new Promise(function(resolve, reject) { - cryptoOp.onerror = function () { - reject(new Error(errmsg)); - }; - cryptoOp.oncomplete = function (e) { - resolve(e.target.result); - }; - }); - }, - /** * Detect Node.js runtime. */ detectNode: function() { return typeof window === 'undefined'; - }, - - /** - * Get native Node.js crypto api. The default configuration is to use - * the api when available. But it can also be deactivated with config.use_native - * @return {Object} The crypto module or 'undefined' - */ - getNodeCrypto: function() { - if (!this.detectNode() || !config.use_native) { - return; - } - - return require('crypto'); - }, - - /** - * Get native Node.js Buffer constructor. This should be used since - * Buffer is not available under browserify. - * @return {Function} The Buffer constructor or 'undefined' - */ - getNodeBuffer: function() { - if (!this.detectNode()) { - return; - } - - return require('buffer').Buffer; } };