@protontech/openpgp 5.7.0 → 5.8.0-0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lightweight/argon2id.min.mjs +3 -0
- package/dist/lightweight/argon2id.min.mjs.map +1 -0
- package/dist/lightweight/{index.mjs → argon2id.mjs} +6 -7
- package/dist/lightweight/bn.interface.min.mjs +1 -1
- package/dist/lightweight/bn.interface.mjs +1 -1
- package/dist/lightweight/bn.min.mjs +1 -1
- package/dist/lightweight/bn.mjs +1 -1
- package/dist/lightweight/elliptic.min.mjs +1 -1
- package/dist/lightweight/elliptic.mjs +1 -1
- package/dist/lightweight/openpgp.min.mjs +2 -2
- package/dist/lightweight/openpgp.min.mjs.map +1 -1
- package/dist/lightweight/openpgp.mjs +379 -171
- package/dist/lightweight/ponyfill.es6.min.mjs +1 -1
- package/dist/lightweight/ponyfill.es6.mjs +1 -1
- package/dist/lightweight/web-streams-adapter.min.mjs +1 -1
- package/dist/lightweight/web-streams-adapter.mjs +1 -1
- package/dist/node/openpgp.js +1100 -180
- package/dist/node/openpgp.min.js +3 -3
- package/dist/node/openpgp.min.js.map +1 -1
- package/dist/node/openpgp.min.mjs +3 -3
- package/dist/node/openpgp.min.mjs.map +1 -1
- package/dist/node/openpgp.mjs +1100 -180
- package/dist/openpgp.js +1085 -171
- package/dist/openpgp.min.js +3 -3
- package/dist/openpgp.min.js.map +1 -1
- package/dist/openpgp.min.mjs +3 -3
- package/dist/openpgp.min.mjs.map +1 -1
- package/dist/openpgp.mjs +1085 -171
- package/openpgp.d.ts +10 -0
- package/package.json +3 -1
- package/dist/lightweight/index.min.mjs +0 -3
- package/dist/lightweight/index.min.mjs.map +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! OpenPGP.js v5.
|
|
1
|
+
/*! OpenPGP.js v5.8.0-0 - 2023-03-17 - this is LGPL licensed code, see LICENSE/our website https://openpgpjs.org/ for more information. */
|
|
2
2
|
const globalThis = typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
|
|
3
3
|
|
|
4
4
|
const doneWritingPromise = Symbol('doneWritingPromise');
|
|
@@ -2303,6 +2303,7 @@ var enums = {
|
|
|
2303
2303
|
simple: 0,
|
|
2304
2304
|
salted: 1,
|
|
2305
2305
|
iterated: 3,
|
|
2306
|
+
argon2: 4,
|
|
2306
2307
|
gnu: 101
|
|
2307
2308
|
},
|
|
2308
2309
|
|
|
@@ -2767,12 +2768,41 @@ var config = {
|
|
|
2767
2768
|
*/
|
|
2768
2769
|
v5Keys: false,
|
|
2769
2770
|
/**
|
|
2770
|
-
*
|
|
2771
|
-
*
|
|
2771
|
+
* S2K (String to Key) type, used for key derivation in the context of secret key encryption
|
|
2772
|
+
* and password-encrypted data. Weaker s2k options are not allowed.
|
|
2773
|
+
* Note: Argon2 is the strongest option but not all OpenPGP implementations are compatible with it
|
|
2774
|
+
* (pending standardisation).
|
|
2775
|
+
* @memberof module:config
|
|
2776
|
+
* @property {enums.s2k.argon2|enums.s2k.iterated} s2kType {@link module:enums.s2k}
|
|
2777
|
+
*/
|
|
2778
|
+
s2kType: enums.s2k.iterated,
|
|
2779
|
+
/**
|
|
2780
|
+
* {@link https://tools.ietf.org/html/rfc4880#section-3.7.1.3| RFC4880 3.7.1.3}:
|
|
2781
|
+
* Iteration Count Byte for Iterated and Salted S2K (String to Key).
|
|
2782
|
+
* Only relevant if `config.s2kType` is set to `enums.s2k.iterated`.
|
|
2783
|
+
* Note: this is the exponent value, not the final number of iterations (refer to specs for more details).
|
|
2772
2784
|
* @memberof module:config
|
|
2773
2785
|
* @property {Integer} s2kIterationCountByte
|
|
2774
2786
|
*/
|
|
2775
2787
|
s2kIterationCountByte: 224,
|
|
2788
|
+
/**
|
|
2789
|
+
* {@link https://tools.ietf.org/html/draft-ietf-openpgp-crypto-refresh-07.html#section-3.7.1.4| draft-crypto-refresh 3.7.1.4}:
|
|
2790
|
+
* Argon2 parameters for S2K (String to Key).
|
|
2791
|
+
* Only relevant if `config.s2kType` is set to `enums.s2k.argon2`.
|
|
2792
|
+
* Default settings correspond to the second recommendation from RFC9106 ("uniformly safe option"),
|
|
2793
|
+
* to ensure compatibility with memory-constrained environments.
|
|
2794
|
+
* For more details on the choice of parameters, see https://tools.ietf.org/html/rfc9106#section-4.
|
|
2795
|
+
* @memberof module:config
|
|
2796
|
+
* @property {Object} params
|
|
2797
|
+
* @property {Integer} params.passes - number of iterations t
|
|
2798
|
+
* @property {Integer} params.parallelism - degree of parallelism p
|
|
2799
|
+
* @property {Integer} params.memoryExponent - one-octet exponent indicating the memory size, which will be: 2**memoryExponent kibibytes.
|
|
2800
|
+
*/
|
|
2801
|
+
s2kArgon2Params: {
|
|
2802
|
+
passes: 3,
|
|
2803
|
+
parallelism: 4, // lanes
|
|
2804
|
+
memoryExponent: 16 // 64 MiB of RAM
|
|
2805
|
+
},
|
|
2776
2806
|
/**
|
|
2777
2807
|
* Allow decryption of messages without integrity protection.
|
|
2778
2808
|
* This is an **insecure** setting:
|
|
@@ -2882,7 +2912,7 @@ var config = {
|
|
|
2882
2912
|
* @memberof module:config
|
|
2883
2913
|
* @property {String} versionString A version string to be included in armored messages
|
|
2884
2914
|
*/
|
|
2885
|
-
versionString: 'OpenPGP.js 5.
|
|
2915
|
+
versionString: 'OpenPGP.js 5.8.0-0',
|
|
2886
2916
|
/**
|
|
2887
2917
|
* @memberof module:config
|
|
2888
2918
|
* @property {String} commentString A comment string to be included in armored messages
|
|
@@ -15863,6 +15893,339 @@ const mod = {
|
|
|
15863
15893
|
|
|
15864
15894
|
Object.assign(mod, crypto$1);
|
|
15865
15895
|
|
|
15896
|
+
const ARGON2_TYPE = 0x02; // id
|
|
15897
|
+
const ARGON2_VERSION = 0x13;
|
|
15898
|
+
const ARGON2_SALT_SIZE = 16;
|
|
15899
|
+
|
|
15900
|
+
class Argon2OutOfMemoryError extends Error {
|
|
15901
|
+
constructor(...params) {
|
|
15902
|
+
super(...params);
|
|
15903
|
+
|
|
15904
|
+
if (Error.captureStackTrace) {
|
|
15905
|
+
Error.captureStackTrace(this, Argon2OutOfMemoryError);
|
|
15906
|
+
}
|
|
15907
|
+
|
|
15908
|
+
this.name = 'Argon2OutOfMemoryError';
|
|
15909
|
+
}
|
|
15910
|
+
}
|
|
15911
|
+
|
|
15912
|
+
// cache argon wasm module
|
|
15913
|
+
let loadArgonWasmModule;
|
|
15914
|
+
let argon2Promise;
|
|
15915
|
+
// reload wasm module above this treshold, to deallocated used memory
|
|
15916
|
+
const ARGON2_WASM_MEMORY_THRESHOLD_RELOAD = 2 << 19;
|
|
15917
|
+
|
|
15918
|
+
class Argon2S2K {
|
|
15919
|
+
/**
|
|
15920
|
+
* @param {Object} [config] - Full configuration, defaults to openpgp.config
|
|
15921
|
+
*/
|
|
15922
|
+
constructor(config$1 = config) {
|
|
15923
|
+
const { passes, parallelism, memoryExponent } = config$1.s2kArgon2Params;
|
|
15924
|
+
|
|
15925
|
+
this.type = 'argon2';
|
|
15926
|
+
/** @type {Uint8Array} 16 bytes of salt */
|
|
15927
|
+
this.salt = null;
|
|
15928
|
+
/** @type {Integer} number of passes */
|
|
15929
|
+
this.t = passes;
|
|
15930
|
+
/** @type {Integer} degree of parallelism (lanes) */
|
|
15931
|
+
this.p = parallelism;
|
|
15932
|
+
/** @type {Integer} exponent indicating memory size */
|
|
15933
|
+
this.encodedM = memoryExponent;
|
|
15934
|
+
}
|
|
15935
|
+
|
|
15936
|
+
generateSalt() {
|
|
15937
|
+
this.salt = mod.random.getRandomBytes(ARGON2_SALT_SIZE);
|
|
15938
|
+
}
|
|
15939
|
+
|
|
15940
|
+
/**
|
|
15941
|
+
* Parsing function for argon2 string-to-key specifier.
|
|
15942
|
+
* @param {Uint8Array} bytes - Payload of argon2 string-to-key specifier
|
|
15943
|
+
* @returns {Integer} Actual length of the object.
|
|
15944
|
+
*/
|
|
15945
|
+
read(bytes) {
|
|
15946
|
+
let i = 0;
|
|
15947
|
+
|
|
15948
|
+
this.salt = bytes.subarray(i, i + 16);
|
|
15949
|
+
i += 16;
|
|
15950
|
+
|
|
15951
|
+
this.t = bytes[i++];
|
|
15952
|
+
this.p = bytes[i++];
|
|
15953
|
+
this.encodedM = bytes[i++]; // memory size exponent, one-octect
|
|
15954
|
+
|
|
15955
|
+
return i;
|
|
15956
|
+
}
|
|
15957
|
+
|
|
15958
|
+
/**
|
|
15959
|
+
* Serializes s2k information
|
|
15960
|
+
* @returns {Uint8Array} Binary representation of s2k.
|
|
15961
|
+
*/
|
|
15962
|
+
write() {
|
|
15963
|
+
const arr = [
|
|
15964
|
+
new Uint8Array([enums.write(enums.s2k, this.type)]),
|
|
15965
|
+
this.salt,
|
|
15966
|
+
new Uint8Array([this.t, this.p, this.encodedM])
|
|
15967
|
+
];
|
|
15968
|
+
|
|
15969
|
+
return util.concatUint8Array(arr);
|
|
15970
|
+
}
|
|
15971
|
+
|
|
15972
|
+
/**
|
|
15973
|
+
* Produces a key using the specified passphrase and the defined
|
|
15974
|
+
* hashAlgorithm
|
|
15975
|
+
* @param {String} passphrase - Passphrase containing user input
|
|
15976
|
+
* @returns {Promise<Uint8Array>} Produced key with a length corresponding to `keySize`
|
|
15977
|
+
* @throws {Argon2OutOfMemoryError|Errors}
|
|
15978
|
+
* @async
|
|
15979
|
+
*/
|
|
15980
|
+
async produceKey(passphrase, keySize) {
|
|
15981
|
+
const decodedM = 2 << (this.encodedM - 1);
|
|
15982
|
+
|
|
15983
|
+
try {
|
|
15984
|
+
if (!argon2Promise) { // first load
|
|
15985
|
+
loadArgonWasmModule = loadArgonWasmModule || (await import('./argon2id.mjs')).default;
|
|
15986
|
+
argon2Promise = loadArgonWasmModule();
|
|
15987
|
+
}
|
|
15988
|
+
// important to keep local ref to argon2 in case the module is reloaded by another instance
|
|
15989
|
+
const argon2 = await argon2Promise;
|
|
15990
|
+
|
|
15991
|
+
const passwordBytes = util.encodeUTF8(passphrase);
|
|
15992
|
+
const hash = argon2({
|
|
15993
|
+
version: ARGON2_VERSION,
|
|
15994
|
+
type: ARGON2_TYPE,
|
|
15995
|
+
password: passwordBytes,
|
|
15996
|
+
salt: this.salt,
|
|
15997
|
+
tagLength: keySize,
|
|
15998
|
+
memorySize: decodedM,
|
|
15999
|
+
parallelism: this.p,
|
|
16000
|
+
passes: this.t
|
|
16001
|
+
});
|
|
16002
|
+
|
|
16003
|
+
// a lot of memory was used, reload to deallocate
|
|
16004
|
+
if (decodedM > ARGON2_WASM_MEMORY_THRESHOLD_RELOAD) {
|
|
16005
|
+
// it will be awaited if needed at the next `produceKey` invocation
|
|
16006
|
+
argon2Promise = loadArgonWasmModule();
|
|
16007
|
+
}
|
|
16008
|
+
return hash;
|
|
16009
|
+
} catch (e) {
|
|
16010
|
+
if (e.message && (
|
|
16011
|
+
e.message.includes('Unable to grow instance memory') || // Chrome
|
|
16012
|
+
e.message.includes('failed to grow memory') || // Firefox
|
|
16013
|
+
e.message.includes('WebAssembly.Memory.grow') || // Safari
|
|
16014
|
+
e.message.includes('Out of memory') // Safari iOS
|
|
16015
|
+
)) {
|
|
16016
|
+
throw new Argon2OutOfMemoryError('Could not allocate required memory for Argon2');
|
|
16017
|
+
} else {
|
|
16018
|
+
throw e;
|
|
16019
|
+
}
|
|
16020
|
+
}
|
|
16021
|
+
}
|
|
16022
|
+
}
|
|
16023
|
+
|
|
16024
|
+
// GPG4Browsers - An OpenPGP implementation in javascript
|
|
16025
|
+
|
|
16026
|
+
class GenericS2K {
|
|
16027
|
+
/**
|
|
16028
|
+
* @param {Object} [config] - Full configuration, defaults to openpgp.config
|
|
16029
|
+
*/
|
|
16030
|
+
constructor(s2kType, config$1 = config) {
|
|
16031
|
+
/**
|
|
16032
|
+
* Hash function identifier, or 0 for gnu-dummy keys
|
|
16033
|
+
* @type {module:enums.hash | 0}
|
|
16034
|
+
*/
|
|
16035
|
+
this.algorithm = enums.hash.sha256;
|
|
16036
|
+
/**
|
|
16037
|
+
* enums.s2k identifier or 'gnu-dummy'
|
|
16038
|
+
* @type {String}
|
|
16039
|
+
*/
|
|
16040
|
+
this.type = enums.read(enums.s2k, s2kType);
|
|
16041
|
+
/** @type {Integer} */
|
|
16042
|
+
this.c = config$1.s2kIterationCountByte;
|
|
16043
|
+
/** Eight bytes of salt in a binary string.
|
|
16044
|
+
* @type {Uint8Array}
|
|
16045
|
+
*/
|
|
16046
|
+
this.salt = null;
|
|
16047
|
+
}
|
|
16048
|
+
|
|
16049
|
+
generateSalt() {
|
|
16050
|
+
switch (this.type) {
|
|
16051
|
+
case 'salted':
|
|
16052
|
+
case 'iterated':
|
|
16053
|
+
this.salt = mod.random.getRandomBytes(8);
|
|
16054
|
+
}
|
|
16055
|
+
}
|
|
16056
|
+
|
|
16057
|
+
getCount() {
|
|
16058
|
+
// Exponent bias, defined in RFC4880
|
|
16059
|
+
const expbias = 6;
|
|
16060
|
+
|
|
16061
|
+
return (16 + (this.c & 15)) << ((this.c >> 4) + expbias);
|
|
16062
|
+
}
|
|
16063
|
+
|
|
16064
|
+
/**
|
|
16065
|
+
* Parsing function for a string-to-key specifier ({@link https://tools.ietf.org/html/rfc4880#section-3.7|RFC 4880 3.7}).
|
|
16066
|
+
* @param {Uint8Array} bytes - Payload of string-to-key specifier
|
|
16067
|
+
* @returns {Integer} Actual length of the object.
|
|
16068
|
+
*/
|
|
16069
|
+
read(bytes) {
|
|
16070
|
+
let i = 0;
|
|
16071
|
+
this.algorithm = bytes[i++];
|
|
16072
|
+
|
|
16073
|
+
switch (this.type) {
|
|
16074
|
+
case 'simple':
|
|
16075
|
+
break;
|
|
16076
|
+
|
|
16077
|
+
case 'salted':
|
|
16078
|
+
this.salt = bytes.subarray(i, i + 8);
|
|
16079
|
+
i += 8;
|
|
16080
|
+
break;
|
|
16081
|
+
|
|
16082
|
+
case 'iterated':
|
|
16083
|
+
this.salt = bytes.subarray(i, i + 8);
|
|
16084
|
+
i += 8;
|
|
16085
|
+
|
|
16086
|
+
// Octet 10: count, a one-octet, coded value
|
|
16087
|
+
this.c = bytes[i++];
|
|
16088
|
+
break;
|
|
16089
|
+
case 'gnu':
|
|
16090
|
+
if (util.uint8ArrayToString(bytes.subarray(i, i + 3)) === 'GNU') {
|
|
16091
|
+
i += 3; // GNU
|
|
16092
|
+
const gnuExtType = 1000 + bytes[i++];
|
|
16093
|
+
if (gnuExtType === 1001) {
|
|
16094
|
+
this.type = 'gnu-dummy';
|
|
16095
|
+
// GnuPG extension mode 1001 -- don't write secret key at all
|
|
16096
|
+
} else {
|
|
16097
|
+
throw new Error('Unknown s2k gnu protection mode.');
|
|
16098
|
+
}
|
|
16099
|
+
} else {
|
|
16100
|
+
throw new Error('Unknown s2k type.');
|
|
16101
|
+
}
|
|
16102
|
+
break;
|
|
16103
|
+
|
|
16104
|
+
default:
|
|
16105
|
+
throw new Error('Unknown s2k type.');
|
|
16106
|
+
}
|
|
16107
|
+
|
|
16108
|
+
return i;
|
|
16109
|
+
}
|
|
16110
|
+
|
|
16111
|
+
/**
|
|
16112
|
+
* Serializes s2k information
|
|
16113
|
+
* @returns {Uint8Array} Binary representation of s2k.
|
|
16114
|
+
*/
|
|
16115
|
+
write() {
|
|
16116
|
+
if (this.type === 'gnu-dummy') {
|
|
16117
|
+
return new Uint8Array([101, 0, ...util.stringToUint8Array('GNU'), 1]);
|
|
16118
|
+
}
|
|
16119
|
+
const arr = [new Uint8Array([enums.write(enums.s2k, this.type), this.algorithm])];
|
|
16120
|
+
|
|
16121
|
+
switch (this.type) {
|
|
16122
|
+
case 'simple':
|
|
16123
|
+
break;
|
|
16124
|
+
case 'salted':
|
|
16125
|
+
arr.push(this.salt);
|
|
16126
|
+
break;
|
|
16127
|
+
case 'iterated':
|
|
16128
|
+
arr.push(this.salt);
|
|
16129
|
+
arr.push(new Uint8Array([this.c]));
|
|
16130
|
+
break;
|
|
16131
|
+
case 'gnu':
|
|
16132
|
+
throw new Error('GNU s2k type not supported.');
|
|
16133
|
+
default:
|
|
16134
|
+
throw new Error('Unknown s2k type.');
|
|
16135
|
+
}
|
|
16136
|
+
|
|
16137
|
+
return util.concatUint8Array(arr);
|
|
16138
|
+
}
|
|
16139
|
+
|
|
16140
|
+
/**
|
|
16141
|
+
* Produces a key using the specified passphrase and the defined
|
|
16142
|
+
* hashAlgorithm
|
|
16143
|
+
* @param {String} passphrase - Passphrase containing user input
|
|
16144
|
+
* @returns {Promise<Uint8Array>} Produced key with a length corresponding to.
|
|
16145
|
+
* hashAlgorithm hash length
|
|
16146
|
+
* @async
|
|
16147
|
+
*/
|
|
16148
|
+
async produceKey(passphrase, numBytes) {
|
|
16149
|
+
passphrase = util.encodeUTF8(passphrase);
|
|
16150
|
+
|
|
16151
|
+
const arr = [];
|
|
16152
|
+
let rlength = 0;
|
|
16153
|
+
|
|
16154
|
+
let prefixlen = 0;
|
|
16155
|
+
while (rlength < numBytes) {
|
|
16156
|
+
let toHash;
|
|
16157
|
+
switch (this.type) {
|
|
16158
|
+
case 'simple':
|
|
16159
|
+
toHash = util.concatUint8Array([new Uint8Array(prefixlen), passphrase]);
|
|
16160
|
+
break;
|
|
16161
|
+
case 'salted':
|
|
16162
|
+
toHash = util.concatUint8Array([new Uint8Array(prefixlen), this.salt, passphrase]);
|
|
16163
|
+
break;
|
|
16164
|
+
case 'iterated': {
|
|
16165
|
+
const data = util.concatUint8Array([this.salt, passphrase]);
|
|
16166
|
+
let datalen = data.length;
|
|
16167
|
+
const count = Math.max(this.getCount(), datalen);
|
|
16168
|
+
toHash = new Uint8Array(prefixlen + count);
|
|
16169
|
+
toHash.set(data, prefixlen);
|
|
16170
|
+
for (let pos = prefixlen + datalen; pos < count; pos += datalen, datalen *= 2) {
|
|
16171
|
+
toHash.copyWithin(pos, prefixlen, pos);
|
|
16172
|
+
}
|
|
16173
|
+
break;
|
|
16174
|
+
}
|
|
16175
|
+
case 'gnu':
|
|
16176
|
+
throw new Error('GNU s2k type not supported.');
|
|
16177
|
+
default:
|
|
16178
|
+
throw new Error('Unknown s2k type.');
|
|
16179
|
+
}
|
|
16180
|
+
const result = await mod.hash.digest(this.algorithm, toHash);
|
|
16181
|
+
arr.push(result);
|
|
16182
|
+
rlength += result.length;
|
|
16183
|
+
prefixlen++;
|
|
16184
|
+
}
|
|
16185
|
+
|
|
16186
|
+
return util.concatUint8Array(arr).subarray(0, numBytes);
|
|
16187
|
+
}
|
|
16188
|
+
}
|
|
16189
|
+
|
|
16190
|
+
const allowedS2KTypesForEncryption = new Set([enums.s2k.argon2, enums.s2k.iterated]);
|
|
16191
|
+
|
|
16192
|
+
/**
|
|
16193
|
+
* Instantiate a new S2K instance of the given type
|
|
16194
|
+
* @param {module:enums.s2k} type
|
|
16195
|
+
* @oaram {Object} [config]
|
|
16196
|
+
* @returns {Object} New s2k object
|
|
16197
|
+
* @throws {Error} for unknown or unsupported types
|
|
16198
|
+
*/
|
|
16199
|
+
function newS2KFromType(type, config$1 = config) {
|
|
16200
|
+
switch (type) {
|
|
16201
|
+
case enums.s2k.argon2:
|
|
16202
|
+
return new Argon2S2K(config$1);
|
|
16203
|
+
case enums.s2k.iterated:
|
|
16204
|
+
case enums.s2k.gnu:
|
|
16205
|
+
case enums.s2k.salted:
|
|
16206
|
+
case enums.s2k.simple:
|
|
16207
|
+
return new GenericS2K(type, config$1);
|
|
16208
|
+
default:
|
|
16209
|
+
throw new Error(`Unsupported S2K type ${type}`);
|
|
16210
|
+
}
|
|
16211
|
+
}
|
|
16212
|
+
|
|
16213
|
+
/**
|
|
16214
|
+
* Instantiate a new S2K instance based on the config settings
|
|
16215
|
+
* @oaram {Object} config
|
|
16216
|
+
* @returns {Object} New s2k object
|
|
16217
|
+
* @throws {Error} for unknown or unsupported types
|
|
16218
|
+
*/
|
|
16219
|
+
function newS2KFromConfig(config) {
|
|
16220
|
+
const { s2kType } = config;
|
|
16221
|
+
|
|
16222
|
+
if (!allowedS2KTypesForEncryption.has(s2kType)) {
|
|
16223
|
+
throw new Error('The provided `config.s2kType` value is not allowed');
|
|
16224
|
+
}
|
|
16225
|
+
|
|
16226
|
+
return newS2KFromType(s2kType, config);
|
|
16227
|
+
}
|
|
16228
|
+
|
|
15866
16229
|
var TYPED_OK = typeof Uint8Array !== "undefined" &&
|
|
15867
16230
|
typeof Uint16Array !== "undefined" &&
|
|
15868
16231
|
typeof Int32Array !== "undefined";
|
|
@@ -24684,166 +25047,6 @@ class PublicKeyEncryptedSessionKeyPacket {
|
|
|
24684
25047
|
|
|
24685
25048
|
// GPG4Browsers - An OpenPGP implementation in javascript
|
|
24686
25049
|
|
|
24687
|
-
class S2K {
|
|
24688
|
-
/**
|
|
24689
|
-
* @param {Object} [config] - Full configuration, defaults to openpgp.config
|
|
24690
|
-
*/
|
|
24691
|
-
constructor(config$1 = config) {
|
|
24692
|
-
/**
|
|
24693
|
-
* Hash function identifier, or 0 for gnu-dummy keys
|
|
24694
|
-
* @type {module:enums.hash | 0}
|
|
24695
|
-
*/
|
|
24696
|
-
this.algorithm = enums.hash.sha256;
|
|
24697
|
-
/**
|
|
24698
|
-
* enums.s2k identifier or 'gnu-dummy'
|
|
24699
|
-
* @type {String}
|
|
24700
|
-
*/
|
|
24701
|
-
this.type = 'iterated';
|
|
24702
|
-
/** @type {Integer} */
|
|
24703
|
-
this.c = config$1.s2kIterationCountByte;
|
|
24704
|
-
/** Eight bytes of salt in a binary string.
|
|
24705
|
-
* @type {Uint8Array}
|
|
24706
|
-
*/
|
|
24707
|
-
this.salt = null;
|
|
24708
|
-
}
|
|
24709
|
-
|
|
24710
|
-
getCount() {
|
|
24711
|
-
// Exponent bias, defined in RFC4880
|
|
24712
|
-
const expbias = 6;
|
|
24713
|
-
|
|
24714
|
-
return (16 + (this.c & 15)) << ((this.c >> 4) + expbias);
|
|
24715
|
-
}
|
|
24716
|
-
|
|
24717
|
-
/**
|
|
24718
|
-
* Parsing function for a string-to-key specifier ({@link https://tools.ietf.org/html/rfc4880#section-3.7|RFC 4880 3.7}).
|
|
24719
|
-
* @param {Uint8Array} bytes - Payload of string-to-key specifier
|
|
24720
|
-
* @returns {Integer} Actual length of the object.
|
|
24721
|
-
*/
|
|
24722
|
-
read(bytes) {
|
|
24723
|
-
let i = 0;
|
|
24724
|
-
this.type = enums.read(enums.s2k, bytes[i++]);
|
|
24725
|
-
this.algorithm = bytes[i++];
|
|
24726
|
-
|
|
24727
|
-
switch (this.type) {
|
|
24728
|
-
case 'simple':
|
|
24729
|
-
break;
|
|
24730
|
-
|
|
24731
|
-
case 'salted':
|
|
24732
|
-
this.salt = bytes.subarray(i, i + 8);
|
|
24733
|
-
i += 8;
|
|
24734
|
-
break;
|
|
24735
|
-
|
|
24736
|
-
case 'iterated':
|
|
24737
|
-
this.salt = bytes.subarray(i, i + 8);
|
|
24738
|
-
i += 8;
|
|
24739
|
-
|
|
24740
|
-
// Octet 10: count, a one-octet, coded value
|
|
24741
|
-
this.c = bytes[i++];
|
|
24742
|
-
break;
|
|
24743
|
-
|
|
24744
|
-
case 'gnu':
|
|
24745
|
-
if (util.uint8ArrayToString(bytes.subarray(i, i + 3)) === 'GNU') {
|
|
24746
|
-
i += 3; // GNU
|
|
24747
|
-
const gnuExtType = 1000 + bytes[i++];
|
|
24748
|
-
if (gnuExtType === 1001) {
|
|
24749
|
-
this.type = 'gnu-dummy';
|
|
24750
|
-
// GnuPG extension mode 1001 -- don't write secret key at all
|
|
24751
|
-
} else {
|
|
24752
|
-
throw new Error('Unknown s2k gnu protection mode.');
|
|
24753
|
-
}
|
|
24754
|
-
} else {
|
|
24755
|
-
throw new Error('Unknown s2k type.');
|
|
24756
|
-
}
|
|
24757
|
-
break;
|
|
24758
|
-
|
|
24759
|
-
default:
|
|
24760
|
-
throw new Error('Unknown s2k type.');
|
|
24761
|
-
}
|
|
24762
|
-
|
|
24763
|
-
return i;
|
|
24764
|
-
}
|
|
24765
|
-
|
|
24766
|
-
/**
|
|
24767
|
-
* Serializes s2k information
|
|
24768
|
-
* @returns {Uint8Array} Binary representation of s2k.
|
|
24769
|
-
*/
|
|
24770
|
-
write() {
|
|
24771
|
-
if (this.type === 'gnu-dummy') {
|
|
24772
|
-
return new Uint8Array([101, 0, ...util.stringToUint8Array('GNU'), 1]);
|
|
24773
|
-
}
|
|
24774
|
-
const arr = [new Uint8Array([enums.write(enums.s2k, this.type), this.algorithm])];
|
|
24775
|
-
|
|
24776
|
-
switch (this.type) {
|
|
24777
|
-
case 'simple':
|
|
24778
|
-
break;
|
|
24779
|
-
case 'salted':
|
|
24780
|
-
arr.push(this.salt);
|
|
24781
|
-
break;
|
|
24782
|
-
case 'iterated':
|
|
24783
|
-
arr.push(this.salt);
|
|
24784
|
-
arr.push(new Uint8Array([this.c]));
|
|
24785
|
-
break;
|
|
24786
|
-
case 'gnu':
|
|
24787
|
-
throw new Error('GNU s2k type not supported.');
|
|
24788
|
-
default:
|
|
24789
|
-
throw new Error('Unknown s2k type.');
|
|
24790
|
-
}
|
|
24791
|
-
|
|
24792
|
-
return util.concatUint8Array(arr);
|
|
24793
|
-
}
|
|
24794
|
-
|
|
24795
|
-
/**
|
|
24796
|
-
* Produces a key using the specified passphrase and the defined
|
|
24797
|
-
* hashAlgorithm
|
|
24798
|
-
* @param {String} passphrase - Passphrase containing user input
|
|
24799
|
-
* @returns {Promise<Uint8Array>} Produced key with a length corresponding to.
|
|
24800
|
-
* hashAlgorithm hash length
|
|
24801
|
-
* @async
|
|
24802
|
-
*/
|
|
24803
|
-
async produceKey(passphrase, numBytes) {
|
|
24804
|
-
passphrase = util.encodeUTF8(passphrase);
|
|
24805
|
-
|
|
24806
|
-
const arr = [];
|
|
24807
|
-
let rlength = 0;
|
|
24808
|
-
|
|
24809
|
-
let prefixlen = 0;
|
|
24810
|
-
while (rlength < numBytes) {
|
|
24811
|
-
let toHash;
|
|
24812
|
-
switch (this.type) {
|
|
24813
|
-
case 'simple':
|
|
24814
|
-
toHash = util.concatUint8Array([new Uint8Array(prefixlen), passphrase]);
|
|
24815
|
-
break;
|
|
24816
|
-
case 'salted':
|
|
24817
|
-
toHash = util.concatUint8Array([new Uint8Array(prefixlen), this.salt, passphrase]);
|
|
24818
|
-
break;
|
|
24819
|
-
case 'iterated': {
|
|
24820
|
-
const data = util.concatUint8Array([this.salt, passphrase]);
|
|
24821
|
-
let datalen = data.length;
|
|
24822
|
-
const count = Math.max(this.getCount(), datalen);
|
|
24823
|
-
toHash = new Uint8Array(prefixlen + count);
|
|
24824
|
-
toHash.set(data, prefixlen);
|
|
24825
|
-
for (let pos = prefixlen + datalen; pos < count; pos += datalen, datalen *= 2) {
|
|
24826
|
-
toHash.copyWithin(pos, prefixlen, pos);
|
|
24827
|
-
}
|
|
24828
|
-
break;
|
|
24829
|
-
}
|
|
24830
|
-
case 'gnu':
|
|
24831
|
-
throw new Error('GNU s2k type not supported.');
|
|
24832
|
-
default:
|
|
24833
|
-
throw new Error('Unknown s2k type.');
|
|
24834
|
-
}
|
|
24835
|
-
const result = await mod.hash.digest(this.algorithm, toHash);
|
|
24836
|
-
arr.push(result);
|
|
24837
|
-
rlength += result.length;
|
|
24838
|
-
prefixlen++;
|
|
24839
|
-
}
|
|
24840
|
-
|
|
24841
|
-
return util.concatUint8Array(arr).subarray(0, numBytes);
|
|
24842
|
-
}
|
|
24843
|
-
}
|
|
24844
|
-
|
|
24845
|
-
// GPG4Browsers - An OpenPGP implementation in javascript
|
|
24846
|
-
|
|
24847
25050
|
/**
|
|
24848
25051
|
* Symmetric-Key Encrypted Session Key Packets (Tag 3)
|
|
24849
25052
|
*
|
|
@@ -24911,7 +25114,8 @@ class SymEncryptedSessionKeyPacket {
|
|
|
24911
25114
|
}
|
|
24912
25115
|
|
|
24913
25116
|
// A string-to-key (S2K) specifier, length as defined above.
|
|
24914
|
-
|
|
25117
|
+
const s2kType = bytes[offset++];
|
|
25118
|
+
this.s2k = newS2KFromType(s2kType);
|
|
24915
25119
|
offset += this.s2k.read(bytes.subarray(offset, bytes.length));
|
|
24916
25120
|
|
|
24917
25121
|
if (this.version === 5) {
|
|
@@ -25000,8 +25204,8 @@ class SymEncryptedSessionKeyPacket {
|
|
|
25000
25204
|
|
|
25001
25205
|
this.sessionKeyEncryptionAlgorithm = algo;
|
|
25002
25206
|
|
|
25003
|
-
this.s2k =
|
|
25004
|
-
this.s2k.
|
|
25207
|
+
this.s2k = newS2KFromConfig(config$1);
|
|
25208
|
+
this.s2k.generateSalt();
|
|
25005
25209
|
|
|
25006
25210
|
const { blockSize, keySize } = mod.getCipher(algo);
|
|
25007
25211
|
const encryptionKey = await this.s2k.produceKey(passphrase, keySize);
|
|
@@ -25627,7 +25831,8 @@ class SecretKeyPacket extends PublicKeyPacket {
|
|
|
25627
25831
|
// - [Optional] If string-to-key usage octet was 255, 254, or 253, a
|
|
25628
25832
|
// string-to-key specifier. The length of the string-to-key
|
|
25629
25833
|
// specifier is implied by its type, as described above.
|
|
25630
|
-
|
|
25834
|
+
const s2kType = bytes[i++];
|
|
25835
|
+
this.s2k = newS2KFromType(s2kType);
|
|
25631
25836
|
i += this.s2k.read(bytes.subarray(i, bytes.length));
|
|
25632
25837
|
|
|
25633
25838
|
if (this.s2k.type === 'gnu-dummy') {
|
|
@@ -25765,7 +25970,7 @@ class SecretKeyPacket extends PublicKeyPacket {
|
|
|
25765
25970
|
}
|
|
25766
25971
|
this.isEncrypted = null;
|
|
25767
25972
|
this.keyMaterial = null;
|
|
25768
|
-
this.s2k =
|
|
25973
|
+
this.s2k = newS2KFromType(enums.s2k.gnu, config$1);
|
|
25769
25974
|
this.s2k.algorithm = 0;
|
|
25770
25975
|
this.s2k.c = 0;
|
|
25771
25976
|
this.s2k.type = 'gnu-dummy';
|
|
@@ -25796,8 +26001,8 @@ class SecretKeyPacket extends PublicKeyPacket {
|
|
|
25796
26001
|
throw new Error('A non-empty passphrase is required for key encryption.');
|
|
25797
26002
|
}
|
|
25798
26003
|
|
|
25799
|
-
this.s2k =
|
|
25800
|
-
this.s2k.
|
|
26004
|
+
this.s2k = newS2KFromConfig(config$1);
|
|
26005
|
+
this.s2k.generateSalt();
|
|
25801
26006
|
const cleartext = mod.serializeParams(this.algorithm, this.privateParams);
|
|
25802
26007
|
this.symmetric = enums.symmetric.aes256;
|
|
25803
26008
|
const key = await produceEncryptionKey(this.s2k, passphrase, this.symmetric);
|
|
@@ -29675,6 +29880,9 @@ class Message {
|
|
|
29675
29880
|
decryptedSessionKeyPackets.push(skeskPacket);
|
|
29676
29881
|
} catch (err) {
|
|
29677
29882
|
util.printDebugError(err);
|
|
29883
|
+
if (err instanceof Argon2OutOfMemoryError) {
|
|
29884
|
+
exception = err;
|
|
29885
|
+
}
|
|
29678
29886
|
}
|
|
29679
29887
|
}));
|
|
29680
29888
|
}));
|