From 066a0c08d27994d1be6aafd6e686a8bb54c07dbb Mon Sep 17 00:00:00 2001 From: djmaze Date: Thu, 13 May 2021 00:32:28 +0200 Subject: [PATCH] Fix OpenPGP error --- vendors/openpgp-2.6.2/dist/openpgp.js | 51 +++---------- vendors/openpgp-2.6.2/src/crypto/gcm.js | 3 +- .../openpgp-2.6.2/src/crypto/hash/index.js | 4 +- .../src/crypto/public_key/jsbn.js | 73 ------------------- .../openpgp-2.6.2/src/keyring/localstore.js | 1 - .../sym_encrypted_integrity_protected.js | 5 +- vendors/openpgp-2.6.2/src/util.js | 44 +++-------- 7 files changed, 29 insertions(+), 152 deletions(-) diff --git a/vendors/openpgp-2.6.2/dist/openpgp.js b/vendors/openpgp-2.6.2/dist/openpgp.js index 6a27fcddc..f4c10c465 100644 --- a/vendors/openpgp-2.6.2/dist/openpgp.js +++ b/vendors/openpgp-2.6.2/dist/openpgp.js @@ -52,23 +52,6 @@ function string_to_bytes ( str, utf8 ) { return bytes.subarray(0, j); } -function hex_to_bytes ( str ) { - var len = str.length; - if ( len & 1 ) { - str = '0'+str; - len++; - } - var bytes = new Uint8Array(len>>1); - for ( var i = 0; i < len; i += 2 ) { - bytes[i>>1] = parseInt( str.substr( i, 2), 16 ); - } - return bytes; -} - -function base64_to_bytes ( str ) { - return string_to_bytes( atob( str ) ); -} - function bytes_to_string ( bytes, utf8 ) { utf8 = !!utf8; @@ -1848,6 +1831,8 @@ function AES_GCM_Decrypt_finish () { for ( var i = rlen; i & 15; i++ ) heap[ pos + i ] = 0; + asm.mac( AES_asm.MAC.GCM, AES_asm.HEAP_DATA + pos, i ); + asm.cipher( AES_asm.DEC.CTR, AES_asm.HEAP_DATA + pos, i ); if ( rlen ) result.set( heap.subarray( pos, pos+rlen ) ); var alen = ( adata !== null ) ? adata.length : 0, @@ -6040,7 +6025,7 @@ exports.default = { Object.defineProperty(exports, "__esModule", { value: true }); -exports.ivLength = 12; // size of the IV in bytes +exports.ivLength = undefined; exports.encrypt = encrypt; exports.decrypt = decrypt; @@ -6060,6 +6045,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de var webCrypto = _util2.default.getWebCrypto(); // no GCM support in IE11, Safari 9 +var ivLength = exports.ivLength = 12; // size of the IV in bytes var TAG_LEN = 16; // size of the tag in bytes var ALGO = 'AES-GCM'; @@ -7086,7 +7072,6 @@ function binb2b64(binarray, formatOpts) { * @private * @param {Array.} binarray Array of integers to be converted to * a raw bytes string representation - * @param {!Object} formatOpts Unused Hash list * @return {string} Raw bytes representation of the parameter in string * form */ @@ -7110,7 +7095,6 @@ function binb2bytes(binarray) { * @private * @param {Array.} binarray Array of integers to be converted to * a raw bytes string representation - * @param {!Object} formatOpts Unused Hash list * @return {Uint8Array} Raw bytes representation of the parameter */ function binb2typed(binarray) { @@ -13578,10 +13562,6 @@ Object.defineProperty(exports, "__esModule", { }); exports.default = LocalStore; -var _config = _dereq_('../config'); - -var _config2 = _interopRequireDefault(_config); - var _key = _dereq_('../key.js'); var keyModule = _interopRequireWildcard(_key); @@ -15007,7 +14987,7 @@ function nativeAEAD() { return _util2.default.getWebCrypto() && _config2.default.aead_protect; } -},{"./cleartext.js":5,"./config/config.js":9,"./key.js":38,"./message.js":42,"./util":70,"./worker/async_proxy.js":71,"es6-promise":2}], +},{"./cleartext.js":5,"./config/config.js":9,"./key.js":38,"./message.js":42,"./util":70,"./worker/async_proxy.js":71}], 44:[function(_dereq_,module,exports){ /** * @requires enums @@ -18324,7 +18304,8 @@ function aesEncrypt(algo, prefix, pt, key) { function aesDecrypt(algo, ct, key) { // asm.js fallback - return _asmcryptoLite2.default.AES_CFB.decrypt(ct, key).subarray(_crypto2.default.cipher[algo].blockSize + 2, pt.length); // Remove random prefix + var pt = _asmcryptoLite2.default.AES_CFB.decrypt(ct, key); + return pt.subarray(_crypto2.default.cipher[algo].blockSize + 2, pt.length); // Remove random prefix } },{"../crypto":24,"../enums.js":35,"../util.js":70,"asmcrypto-lite":1}], @@ -19401,17 +19382,11 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de exports.default = { - isString: function isString(data) { - return typeof data === 'string' || String.prototype.isPrototypeOf(data); - }, + isString: data => typeof data === 'string' || String.prototype.isPrototypeOf(data), - isArray: function isArray(data) { - return Array.prototype.isPrototypeOf(data); - }, + isArray: data => Array.isArray(data), - isUint8Array: function isUint8Array(data) { - return Uint8Array.prototype.isPrototypeOf(data); - }, + isUint8Array: data => Uint8Array.prototype.isPrototypeOf(data), isEmailAddress: function isEmailAddress(data) { if (!this.isString(data)) { @@ -19422,11 +19397,7 @@ exports.default = { }, isUserId: function isUserId(data) { - if (!this.isString(data)) { - return false; - } - return (/$/.test(data) - ); + return this.isString(data) ? /<.+>$/.test(data) : false; }, /** diff --git a/vendors/openpgp-2.6.2/src/crypto/gcm.js b/vendors/openpgp-2.6.2/src/crypto/gcm.js index 309f8428f..1ce54c2cb 100644 --- a/vendors/openpgp-2.6.2/src/crypto/gcm.js +++ b/vendors/openpgp-2.6.2/src/crypto/gcm.js @@ -24,11 +24,10 @@ import util from '../util.js'; import config from '../config'; -import asmCrypto from 'asmcrypto-lite'; +import asmCrypto from '../asmcrypto.js'; const webCrypto = util.getWebCrypto(); // no GCM support in IE11, Safari 9 export const ivLength = 12; // size of the IV in bytes -const TAG_LEN = 16; // size of the tag in bytes const ALGO = 'AES-GCM'; /** 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 a5e4c0b61..bc5d90584 100644 --- a/vendors/openpgp-2.6.2/src/crypto/hash/index.js +++ b/vendors/openpgp-2.6.2/src/crypto/hash/index.js @@ -9,8 +9,8 @@ 'use strict'; import sha from './sha.js'; -import asmCrypto from 'asmcrypto-lite'; -import Rusha from 'rusha'; +import asmCrypto from '../../asmcrypto.js'; +import Rusha from '../../rusha.js'; import md5 from './md5.js'; import ripemd from './ripe-md.js'; import util from '../../util.js'; diff --git a/vendors/openpgp-2.6.2/src/crypto/public_key/jsbn.js b/vendors/openpgp-2.6.2/src/crypto/public_key/jsbn.js index bc8b6a3f4..e26cce61b 100644 --- a/vendors/openpgp-2.6.2/src/crypto/public_key/jsbn.js +++ b/vendors/openpgp-2.6.2/src/crypto/public_key/jsbn.js @@ -44,10 +44,6 @@ import util from '../../util.js'; // Bits per digit var dbits; -// JavaScript engine analysis -var canary = 0xdeadbeefcafe; -var j_lm = ((canary & 0xffffff) == 0xefcafe); - // (public) Constructor export default function BigInteger(a, b, c) { @@ -80,52 +76,9 @@ function am1(i, x, w, j, c, n) { } return c; } -// am2 avoids a big mult-and-extract completely. -// Max digit bits should be <= 30 because we do bitwise ops -// on values up to 2*hdvalue^2-hdvalue-1 (< 2^31) -function am2(i, x, w, j, c, n) { - var xl = x & 0x7fff, - xh = x >> 15; - while (--n >= 0) { - var l = this[i] & 0x7fff; - var h = this[i++] >> 15; - var m = xh * l + h * xl; - l = xl * l + ((m & 0x7fff) << 15) + w[j] + (c & 0x3fffffff); - c = (l >>> 30) + (m >>> 15) + xh * h + (c >>> 30); - w[j++] = l & 0x3fffffff; - } - return c; -} -// Alternately, set max digit bits to 28 since some -// browsers slow down when dealing with 32-bit numbers. - -function am3(i, x, w, j, c, n) { - var xl = x & 0x3fff, - xh = x >> 14; - while (--n >= 0) { - var l = this[i] & 0x3fff; - var h = this[i++] >> 14; - var m = xh * l + h * xl; - l = xl * l + ((m & 0x3fff) << 14) + w[j] + c; - c = (l >> 28) + (m >> 14) + xh * h; - w[j++] = l & 0xfffffff; - } - return c; -} -/*if(j_lm && (navigator != undefined && - navigator.appName == "Microsoft Internet Explorer")) { - BigInteger.prototype.am = am2; - dbits = 30; -} -else if(j_lm && (navigator != undefined && navigator.appName != "Netscape")) {*/ BigInteger.prototype.am = am1; dbits = 26; -/*} -else { // Mozilla/Netscape seems to prefer am3 - BigInteger.prototype.am = am3; - dbits = 28; -}*/ BigInteger.prototype.DB = dbits; BigInteger.prototype.DM = ((1 << dbits) - 1); @@ -1584,32 +1537,6 @@ function bnIsProbablePrime(t) { /* added by Recurity Labs */ -function nbits(x) { - var n = 1, - t; - if ((t = x >>> 16) != 0) { - x = t; - n += 16; - } - if ((t = x >> 8) != 0) { - x = t; - n += 8; - } - if ((t = x >> 4) != 0) { - x = t; - n += 4; - } - if ((t = x >> 2) != 0) { - x = t; - n += 2; - } - if ((t = x >> 1) != 0) { - x = t; - n += 1; - } - return n; -} - function bnToMPI() { var ba = this.toByteArray(); var size = (ba.length - 1) * 8 + nbits(ba[0]); diff --git a/vendors/openpgp-2.6.2/src/keyring/localstore.js b/vendors/openpgp-2.6.2/src/keyring/localstore.js index b3fc03a8d..06c9b5ced 100644 --- a/vendors/openpgp-2.6.2/src/keyring/localstore.js +++ b/vendors/openpgp-2.6.2/src/keyring/localstore.js @@ -24,7 +24,6 @@ 'use strict'; -import config from '../config'; import * as keyModule from '../key.js'; import util from '../util.js'; 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 9f216afbb..5ac8c8bc4 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 @@ -37,7 +37,7 @@ import util from '../util.js'; import crypto from '../crypto'; import enums from '../enums.js'; -import asmCrypto from 'asmcrypto-lite'; +import asmCrypto from '../asmcrypto.js'; const VERSION = 1; // A one-octet version number of the data packet. @@ -146,5 +146,6 @@ function aesEncrypt(algo, prefix, pt, key) { } function aesDecrypt(algo, ct, key) { - return asmCrypto.AES_CFB.decrypt(ct, key).subarray(crypto.cipher[algo].blockSize + 2, pt.length); // Remove random prefix + var pt = asmCrypto.AES_CFB.decrypt(ct, key); + return pt.subarray(crypto.cipher[algo].blockSize + 2, pt.length); // Remove random prefix } diff --git a/vendors/openpgp-2.6.2/src/util.js b/vendors/openpgp-2.6.2/src/util.js index a4999dbd3..92ebe36af 100644 --- a/vendors/openpgp-2.6.2/src/util.js +++ b/vendors/openpgp-2.6.2/src/util.js @@ -25,19 +25,15 @@ import config from './config'; +var browser = window || self; + export default { - isString: function(data) { - return typeof data === 'string' || String.prototype.isPrototypeOf(data); - }, + isString: data => typeof data === 'string' || String.prototype.isPrototypeOf(data), - isArray: function(data) { - return Array.prototype.isPrototypeOf(data); - }, + isArray: data => Array.isArray(data), - isUint8Array: function(data) { - return Uint8Array.prototype.isPrototypeOf(data); - }, + isUint8Array: data => Uint8Array.prototype.isPrototypeOf(data), isEmailAddress: function(data) { if (!this.isString(data)) { @@ -48,10 +44,7 @@ export default { }, isUserId: function(data) { - if (!this.isString(data)) { - return false; - } - return /$/.test(data); + return this.isString(data) ? /$/.test(data) : false; }, /** @@ -455,13 +448,7 @@ export default { * be deactivated with config.use_native * @return {Object} The SubtleCrypto api or 'undefined' */ - getWebCrypto: function() { - if (!config.use_native) { - return; - } - - return typeof window !== 'undefined' && window.crypto && window.crypto.subtle; - }, + getWebCrypto: () => config.use_native && browser && browser.crypto && browser.crypto.subtle, /** * Get native Web Cryptography api for all browsers, including legacy @@ -475,21 +462,14 @@ export default { return; } - if (typeof window !== 'undefined') { - if (window.crypto) { - return window.crypto.subtle || window.crypto.webkitSubtle; + if (browser) { + if (browser.crypto) { + return browser.crypto.subtle || browser.crypto.webkitSubtle; } - if (window.msCrypto) { - return window.msCrypto.subtle; + if (browser.msCrypto) { + return browser.msCrypto.subtle; } } - }, - - /** - * Detect Node.js runtime. - */ - detectNode: function() { - return typeof window === 'undefined'; } };