Fix OpenPGP error

This commit is contained in:
djmaze 2021-05-13 00:32:28 +02:00
parent b2b576a69c
commit 066a0c08d2
7 changed files with 29 additions and 152 deletions

View file

@ -52,23 +52,6 @@ function string_to_bytes ( str, utf8 ) {
return bytes.subarray(0, j); 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 ) { function bytes_to_string ( bytes, utf8 ) {
utf8 = !!utf8; utf8 = !!utf8;
@ -1848,6 +1831,8 @@ function AES_GCM_Decrypt_finish () {
for ( var i = rlen; i & 15; i++ ) heap[ pos + i ] = 0; 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 ) ); if ( rlen ) result.set( heap.subarray( pos, pos+rlen ) );
var alen = ( adata !== null ) ? adata.length : 0, var alen = ( adata !== null ) ? adata.length : 0,
@ -6040,7 +6025,7 @@ exports.default = {
Object.defineProperty(exports, "__esModule", { Object.defineProperty(exports, "__esModule", {
value: true value: true
}); });
exports.ivLength = 12; // size of the IV in bytes exports.ivLength = undefined;
exports.encrypt = encrypt; exports.encrypt = encrypt;
exports.decrypt = decrypt; 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 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 TAG_LEN = 16; // size of the tag in bytes
var ALGO = 'AES-GCM'; var ALGO = 'AES-GCM';
@ -7086,7 +7072,6 @@ function binb2b64(binarray, formatOpts) {
* @private * @private
* @param {Array.<number>} binarray Array of integers to be converted to * @param {Array.<number>} binarray Array of integers to be converted to
* a raw bytes string representation * a raw bytes string representation
* @param {!Object} formatOpts Unused Hash list
* @return {string} Raw bytes representation of the parameter in string * @return {string} Raw bytes representation of the parameter in string
* form * form
*/ */
@ -7110,7 +7095,6 @@ function binb2bytes(binarray) {
* @private * @private
* @param {Array.<number>} binarray Array of integers to be converted to * @param {Array.<number>} binarray Array of integers to be converted to
* a raw bytes string representation * a raw bytes string representation
* @param {!Object} formatOpts Unused Hash list
* @return {Uint8Array} Raw bytes representation of the parameter * @return {Uint8Array} Raw bytes representation of the parameter
*/ */
function binb2typed(binarray) { function binb2typed(binarray) {
@ -13578,10 +13562,6 @@ Object.defineProperty(exports, "__esModule", {
}); });
exports.default = LocalStore; exports.default = LocalStore;
var _config = _dereq_('../config');
var _config2 = _interopRequireDefault(_config);
var _key = _dereq_('../key.js'); var _key = _dereq_('../key.js');
var keyModule = _interopRequireWildcard(_key); var keyModule = _interopRequireWildcard(_key);
@ -15007,7 +14987,7 @@ function nativeAEAD() {
return _util2.default.getWebCrypto() && _config2.default.aead_protect; 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){ 44:[function(_dereq_,module,exports){
/** /**
* @requires enums * @requires enums
@ -18324,7 +18304,8 @@ function aesEncrypt(algo, prefix, pt, key) {
function aesDecrypt(algo, ct, key) { function aesDecrypt(algo, ct, key) {
// asm.js fallback // 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}], },{"../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 = { exports.default = {
isString: function isString(data) { isString: data => typeof data === 'string' || String.prototype.isPrototypeOf(data),
return typeof data === 'string' || String.prototype.isPrototypeOf(data);
},
isArray: function isArray(data) { isArray: data => Array.isArray(data),
return Array.prototype.isPrototypeOf(data);
},
isUint8Array: function isUint8Array(data) { isUint8Array: data => Uint8Array.prototype.isPrototypeOf(data),
return Uint8Array.prototype.isPrototypeOf(data);
},
isEmailAddress: function isEmailAddress(data) { isEmailAddress: function isEmailAddress(data) {
if (!this.isString(data)) { if (!this.isString(data)) {
@ -19422,11 +19397,7 @@ exports.default = {
}, },
isUserId: function isUserId(data) { isUserId: function isUserId(data) {
if (!this.isString(data)) { return this.isString(data) ? /<.+>$/.test(data) : false;
return false;
}
return (/</.test(data) && />$/.test(data)
);
}, },
/** /**

View file

@ -24,11 +24,10 @@
import util from '../util.js'; import util from '../util.js';
import config from '../config'; 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 const webCrypto = util.getWebCrypto(); // no GCM support in IE11, Safari 9
export const ivLength = 12; // size of the IV in bytes export const ivLength = 12; // size of the IV in bytes
const TAG_LEN = 16; // size of the tag in bytes
const ALGO = 'AES-GCM'; const ALGO = 'AES-GCM';
/** /**

View file

@ -9,8 +9,8 @@
'use strict'; 'use strict';
import sha from './sha.js'; import sha from './sha.js';
import asmCrypto from 'asmcrypto-lite'; import asmCrypto from '../../asmcrypto.js';
import Rusha from 'rusha'; import Rusha from '../../rusha.js';
import md5 from './md5.js'; import md5 from './md5.js';
import ripemd from './ripe-md.js'; import ripemd from './ripe-md.js';
import util from '../../util.js'; import util from '../../util.js';

View file

@ -44,10 +44,6 @@ import util from '../../util.js';
// Bits per digit // Bits per digit
var dbits; var dbits;
// JavaScript engine analysis
var canary = 0xdeadbeefcafe;
var j_lm = ((canary & 0xffffff) == 0xefcafe);
// (public) Constructor // (public) Constructor
export default function BigInteger(a, b, c) { export default function BigInteger(a, b, c) {
@ -80,52 +76,9 @@ function am1(i, x, w, j, c, n) {
} }
return c; 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; BigInteger.prototype.am = am1;
dbits = 26; dbits = 26;
/*}
else { // Mozilla/Netscape seems to prefer am3
BigInteger.prototype.am = am3;
dbits = 28;
}*/
BigInteger.prototype.DB = dbits; BigInteger.prototype.DB = dbits;
BigInteger.prototype.DM = ((1 << dbits) - 1); BigInteger.prototype.DM = ((1 << dbits) - 1);
@ -1584,32 +1537,6 @@ function bnIsProbablePrime(t) {
/* added by Recurity Labs */ /* 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() { function bnToMPI() {
var ba = this.toByteArray(); var ba = this.toByteArray();
var size = (ba.length - 1) * 8 + nbits(ba[0]); var size = (ba.length - 1) * 8 + nbits(ba[0]);

View file

@ -24,7 +24,6 @@
'use strict'; 'use strict';
import config from '../config';
import * as keyModule from '../key.js'; import * as keyModule from '../key.js';
import util from '../util.js'; import util from '../util.js';

View file

@ -37,7 +37,7 @@
import util from '../util.js'; import util from '../util.js';
import crypto from '../crypto'; import crypto from '../crypto';
import enums from '../enums.js'; 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. 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) { 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
} }

View file

@ -25,19 +25,15 @@
import config from './config'; import config from './config';
var browser = window || self;
export default { export default {
isString: function(data) { isString: data => typeof data === 'string' || String.prototype.isPrototypeOf(data),
return typeof data === 'string' || String.prototype.isPrototypeOf(data);
},
isArray: function(data) { isArray: data => Array.isArray(data),
return Array.prototype.isPrototypeOf(data);
},
isUint8Array: function(data) { isUint8Array: data => Uint8Array.prototype.isPrototypeOf(data),
return Uint8Array.prototype.isPrototypeOf(data);
},
isEmailAddress: function(data) { isEmailAddress: function(data) {
if (!this.isString(data)) { if (!this.isString(data)) {
@ -48,10 +44,7 @@ export default {
}, },
isUserId: function(data) { isUserId: function(data) {
if (!this.isString(data)) { return this.isString(data) ? /</.test(data) && />$/.test(data) : false;
return false;
}
return /</.test(data) && />$/.test(data);
}, },
/** /**
@ -455,13 +448,7 @@ export default {
* be deactivated with config.use_native * be deactivated with config.use_native
* @return {Object} The SubtleCrypto api or 'undefined' * @return {Object} The SubtleCrypto api or 'undefined'
*/ */
getWebCrypto: function() { getWebCrypto: () => config.use_native && browser && browser.crypto && browser.crypto.subtle,
if (!config.use_native) {
return;
}
return typeof window !== 'undefined' && window.crypto && window.crypto.subtle;
},
/** /**
* Get native Web Cryptography api for all browsers, including legacy * Get native Web Cryptography api for all browsers, including legacy
@ -475,21 +462,14 @@ export default {
return; return;
} }
if (typeof window !== 'undefined') { if (browser) {
if (window.crypto) { if (browser.crypto) {
return window.crypto.subtle || window.crypto.webkitSubtle; return browser.crypto.subtle || browser.crypto.webkitSubtle;
} }
if (window.msCrypto) { if (browser.msCrypto) {
return window.msCrypto.subtle; return browser.msCrypto.subtle;
} }
} }
},
/**
* Detect Node.js runtime.
*/
detectNode: function() {
return typeof window === 'undefined';
} }
}; };