@protontech/openpgp 5.10.2 → 5.11.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 +1 -1
- package/dist/lightweight/argon2id.mjs +1 -1
- 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 +161 -105
- 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 +161 -105
- 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 +161 -105
- package/dist/openpgp.js +161 -105
- 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 +161 -105
- package/openpgp.d.ts +8 -2
- package/package.json +2 -2
package/dist/node/openpgp.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! OpenPGP.js v5.
|
|
1
|
+
/*! OpenPGP.js v5.11.0 - 2023-11-27 - 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
|
import buffer from 'buffer';
|
|
@@ -249,18 +249,17 @@ if (NodeReadableStream$1) {
|
|
|
249
249
|
this.push(null);
|
|
250
250
|
break;
|
|
251
251
|
}
|
|
252
|
-
if (!this.push(value)
|
|
253
|
-
this._reading = false;
|
|
252
|
+
if (!this.push(value)) {
|
|
254
253
|
break;
|
|
255
254
|
}
|
|
256
255
|
}
|
|
257
|
-
} catch(e) {
|
|
258
|
-
this.
|
|
256
|
+
} catch (e) {
|
|
257
|
+
this.destroy(e);
|
|
259
258
|
}
|
|
260
259
|
}
|
|
261
260
|
|
|
262
|
-
_destroy(
|
|
263
|
-
this._reader.cancel(
|
|
261
|
+
async _destroy(error, callback) {
|
|
262
|
+
this._reader.cancel(error).then(callback, callback);
|
|
264
263
|
}
|
|
265
264
|
}
|
|
266
265
|
|
|
@@ -295,7 +294,7 @@ function Reader(input) {
|
|
|
295
294
|
const reader = input.getReader();
|
|
296
295
|
this._read = reader.read.bind(reader);
|
|
297
296
|
this._releaseLock = () => {};
|
|
298
|
-
this._cancel = () => {};
|
|
297
|
+
this._cancel = async () => {};
|
|
299
298
|
return;
|
|
300
299
|
}
|
|
301
300
|
let streamType = isStream(input);
|
|
@@ -1560,17 +1559,21 @@ var enums = {
|
|
|
1560
1559
|
'2b8104000a': 'secp256k1',
|
|
1561
1560
|
'2B8104000A': 'secp256k1',
|
|
1562
1561
|
|
|
1563
|
-
/** Ed25519 */
|
|
1562
|
+
/** Ed25519 - deprecated by crypto-refresh (replaced by standaone Ed25519 algo) */
|
|
1563
|
+
'ed25519Legacy': 'ed25519',
|
|
1564
1564
|
'ED25519': 'ed25519',
|
|
1565
|
+
/** @deprecated use `ed25519Legacy` instead */
|
|
1565
1566
|
'ed25519': 'ed25519',
|
|
1566
1567
|
'Ed25519': 'ed25519',
|
|
1567
1568
|
'1.3.6.1.4.1.11591.15.1': 'ed25519',
|
|
1568
1569
|
'2b06010401da470f01': 'ed25519',
|
|
1569
1570
|
'2B06010401DA470F01': 'ed25519',
|
|
1570
1571
|
|
|
1571
|
-
/** Curve25519 */
|
|
1572
|
+
/** Curve25519 - deprecated by crypto-refresh (replaced by standaone X25519 algo) */
|
|
1573
|
+
'curve25519Legacy': 'curve25519',
|
|
1572
1574
|
'X25519': 'curve25519',
|
|
1573
1575
|
'cv25519': 'curve25519',
|
|
1576
|
+
/** @deprecated use `curve25519Legacy` instead */
|
|
1574
1577
|
'curve25519': 'curve25519',
|
|
1575
1578
|
'Curve25519': 'curve25519',
|
|
1576
1579
|
'1.3.6.1.4.1.3029.1.5.1': 'curve25519',
|
|
@@ -1641,8 +1644,11 @@ var enums = {
|
|
|
1641
1644
|
ecdsa: 19,
|
|
1642
1645
|
/** EdDSA (Sign only) - deprecated by crypto-refresh (replaced by `ed25519` identifier below)
|
|
1643
1646
|
* [{@link https://tools.ietf.org/html/draft-koch-eddsa-for-openpgp-04|Draft RFC}] */
|
|
1644
|
-
|
|
1645
|
-
|
|
1647
|
+
eddsaLegacy: 22, // NB: this is declared before `eddsa` to translate 22 to 'eddsa' for backwards compatibility
|
|
1648
|
+
/** @deprecated use `eddsaLegacy` instead */
|
|
1649
|
+
ed25519Legacy: 22,
|
|
1650
|
+
/** @deprecated use `eddsaLegacy` instead */
|
|
1651
|
+
eddsa: 22,
|
|
1646
1652
|
/** Reserved for AEDH */
|
|
1647
1653
|
aedh: 23,
|
|
1648
1654
|
/** Reserved for AEDSA */
|
|
@@ -2950,7 +2956,7 @@ var config = {
|
|
|
2950
2956
|
* @memberof module:config
|
|
2951
2957
|
* @property {String} versionString A version string to be included in armored messages
|
|
2952
2958
|
*/
|
|
2953
|
-
versionString: 'OpenPGP.js 5.
|
|
2959
|
+
versionString: 'OpenPGP.js 5.11.0',
|
|
2954
2960
|
/**
|
|
2955
2961
|
* @memberof module:config
|
|
2956
2962
|
* @property {String} commentString A comment string to be included in armored messages
|
|
@@ -3001,7 +3007,14 @@ var config = {
|
|
|
3001
3007
|
* @memberof module:config
|
|
3002
3008
|
* @property {Set<String>} rejectCurves {@link module:enums.curve}
|
|
3003
3009
|
*/
|
|
3004
|
-
rejectCurves: new Set([enums.curve.secp256k1])
|
|
3010
|
+
rejectCurves: new Set([enums.curve.secp256k1]),
|
|
3011
|
+
/**
|
|
3012
|
+
* Whether to validate generated EdDSA signatures before returning them, to ensure they are not faulty signatures.
|
|
3013
|
+
* This check will make signing 2-3 times slower.
|
|
3014
|
+
* Faulty signatures may be generated (in principle) if random bitflips occur at specific points in the signature
|
|
3015
|
+
* computation, and could be used to recover the signer's secret key given a second signature over the same data.
|
|
3016
|
+
*/
|
|
3017
|
+
checkEdDSAFaultySignatures: true
|
|
3005
3018
|
};
|
|
3006
3019
|
|
|
3007
3020
|
/**
|
|
@@ -10987,42 +11000,42 @@ async function GCM(cipher, key) {
|
|
|
10987
11000
|
throw new Error('GCM mode supports only AES cipher');
|
|
10988
11001
|
}
|
|
10989
11002
|
|
|
10990
|
-
if (util.
|
|
10991
|
-
const _key = await webCrypto$4.importKey('raw', key, { name: ALGO }, false, ['encrypt', 'decrypt']);
|
|
10992
|
-
|
|
11003
|
+
if (util.getNodeCrypto()) { // Node crypto library
|
|
10993
11004
|
return {
|
|
10994
11005
|
encrypt: async function(pt, iv, adata = new Uint8Array()) {
|
|
10995
|
-
|
|
10996
|
-
|
|
10997
|
-
|
|
10998
|
-
const ct = await webCrypto$4.encrypt({ name: ALGO, iv, additionalData: adata, tagLength: tagLength$2 * 8 }, _key, pt);
|
|
11006
|
+
const en = new nodeCrypto$4.createCipheriv('aes-' + (key.length * 8) + '-gcm', key, iv);
|
|
11007
|
+
en.setAAD(adata);
|
|
11008
|
+
const ct = Buffer$3.concat([en.update(pt), en.final(), en.getAuthTag()]); // append auth tag to ciphertext
|
|
10999
11009
|
return new Uint8Array(ct);
|
|
11000
11010
|
},
|
|
11001
11011
|
|
|
11002
11012
|
decrypt: async function(ct, iv, adata = new Uint8Array()) {
|
|
11003
|
-
|
|
11004
|
-
|
|
11005
|
-
|
|
11006
|
-
const pt =
|
|
11013
|
+
const de = new nodeCrypto$4.createDecipheriv('aes-' + (key.length * 8) + '-gcm', key, iv);
|
|
11014
|
+
de.setAAD(adata);
|
|
11015
|
+
de.setAuthTag(ct.slice(ct.length - tagLength$2, ct.length)); // read auth tag at end of ciphertext
|
|
11016
|
+
const pt = Buffer$3.concat([de.update(ct.slice(0, ct.length - tagLength$2)), de.final()]);
|
|
11007
11017
|
return new Uint8Array(pt);
|
|
11008
11018
|
}
|
|
11009
11019
|
};
|
|
11010
11020
|
}
|
|
11011
11021
|
|
|
11012
|
-
if (util.
|
|
11022
|
+
if (util.getWebCrypto() && key.length !== 24) { // WebCrypto (no 192 bit support) see: https://www.chromium.org/blink/webcrypto#TOC-AES-support
|
|
11023
|
+
const _key = await webCrypto$4.importKey('raw', key, { name: ALGO }, false, ['encrypt', 'decrypt']);
|
|
11024
|
+
|
|
11013
11025
|
return {
|
|
11014
11026
|
encrypt: async function(pt, iv, adata = new Uint8Array()) {
|
|
11015
|
-
|
|
11016
|
-
|
|
11017
|
-
|
|
11027
|
+
if (!pt.length) { // iOS does not support GCM-en/decrypting empty messages
|
|
11028
|
+
return AES_GCM.encrypt(pt, key, iv, adata);
|
|
11029
|
+
}
|
|
11030
|
+
const ct = await webCrypto$4.encrypt({ name: ALGO, iv, additionalData: adata, tagLength: tagLength$2 * 8 }, _key, pt);
|
|
11018
11031
|
return new Uint8Array(ct);
|
|
11019
11032
|
},
|
|
11020
11033
|
|
|
11021
11034
|
decrypt: async function(ct, iv, adata = new Uint8Array()) {
|
|
11022
|
-
|
|
11023
|
-
|
|
11024
|
-
|
|
11025
|
-
const pt =
|
|
11035
|
+
if (ct.length === tagLength$2) { // iOS does not support GCM-en/decrypting empty messages
|
|
11036
|
+
return AES_GCM.decrypt(ct, key, iv, adata);
|
|
11037
|
+
}
|
|
11038
|
+
const pt = await webCrypto$4.decrypt({ name: ALGO, iv, additionalData: adata, tagLength: tagLength$2 * 8 }, _key, ct);
|
|
11026
11039
|
return new Uint8Array(pt);
|
|
11027
11040
|
}
|
|
11028
11041
|
};
|
|
@@ -12025,11 +12038,11 @@ const nodeCrypto$5 = util.getNodeCrypto();
|
|
|
12025
12038
|
*/
|
|
12026
12039
|
function getRandomBytes(length) {
|
|
12027
12040
|
const buf = new Uint8Array(length);
|
|
12028
|
-
if (
|
|
12029
|
-
crypto.getRandomValues(buf);
|
|
12030
|
-
} else if (nodeCrypto$5) {
|
|
12041
|
+
if (nodeCrypto$5) {
|
|
12031
12042
|
const bytes = nodeCrypto$5.randomBytes(buf.length);
|
|
12032
12043
|
buf.set(bytes);
|
|
12044
|
+
} else if (typeof crypto !== 'undefined' && crypto.getRandomValues) {
|
|
12045
|
+
crypto.getRandomValues(buf);
|
|
12033
12046
|
} else {
|
|
12034
12047
|
throw new Error('No secure random number generator available.');
|
|
12035
12048
|
}
|
|
@@ -13589,7 +13602,7 @@ const curves = {
|
|
|
13589
13602
|
},
|
|
13590
13603
|
ed25519: {
|
|
13591
13604
|
oid: [0x06, 0x09, 0x2B, 0x06, 0x01, 0x04, 0x01, 0xDA, 0x47, 0x0F, 0x01],
|
|
13592
|
-
keyType: enums.publicKey.
|
|
13605
|
+
keyType: enums.publicKey.eddsaLegacy,
|
|
13593
13606
|
hash: enums.hash.sha512,
|
|
13594
13607
|
node: false, // nodeCurves.ed25519 TODO
|
|
13595
13608
|
payloadSize: 32
|
|
@@ -14192,10 +14205,24 @@ naclFastLight.hash = bytes => new Uint8Array(_512().update(bytes).digest());
|
|
|
14192
14205
|
async function sign$2(oid, hashAlgo, message, publicKey, privateKey, hashed) {
|
|
14193
14206
|
if (hash.getHashByteLength(hashAlgo) < hash.getHashByteLength(enums.hash.sha256)) {
|
|
14194
14207
|
// see https://tools.ietf.org/id/draft-ietf-openpgp-rfc4880bis-10.html#section-15-7.2
|
|
14195
|
-
throw new Error('Hash algorithm too weak
|
|
14208
|
+
throw new Error('Hash algorithm too weak for EdDSA.');
|
|
14196
14209
|
}
|
|
14197
14210
|
const secretKey = util.concatUint8Array([privateKey, publicKey.subarray(1)]);
|
|
14198
14211
|
const signature = naclFastLight.sign.detached(hashed, secretKey);
|
|
14212
|
+
if (config.checkEdDSAFaultySignatures && !naclFastLight.sign.detached.verify(hashed, signature, publicKey.subarray(1))) {
|
|
14213
|
+
/**
|
|
14214
|
+
* Detect faulty signatures caused by random bitflips during `crypto_sign` which could lead to private key extraction
|
|
14215
|
+
* if two signatures over the same message are obtained.
|
|
14216
|
+
* See https://github.com/jedisct1/libsodium/issues/170.
|
|
14217
|
+
* If the input data is not deterministic, e.g. thanks to the random salt in v6 OpenPGP signatures (not yet implemented),
|
|
14218
|
+
* then the generated signature is always safe, and the verification step is skipped.
|
|
14219
|
+
* Otherwise, we need to verify the generated to ensure that no bitflip occured:
|
|
14220
|
+
* - in M between the computation of `r` and `h`.
|
|
14221
|
+
* - in the public key before computing `h`
|
|
14222
|
+
* The verification step is almost 2-3 times as slow as signing, but it's faster than re-signing + re-deriving the public key for separate checks.
|
|
14223
|
+
*/
|
|
14224
|
+
throw new Error('Transient signing failure');
|
|
14225
|
+
}
|
|
14199
14226
|
// EdDSA signature params are returned in little-endian format
|
|
14200
14227
|
return {
|
|
14201
14228
|
r: signature.subarray(0, 32),
|
|
@@ -14216,6 +14243,9 @@ async function sign$2(oid, hashAlgo, message, publicKey, privateKey, hashed) {
|
|
|
14216
14243
|
* @async
|
|
14217
14244
|
*/
|
|
14218
14245
|
async function verify$2(oid, hashAlgo, { r, s }, m, publicKey, hashed) {
|
|
14246
|
+
if (hash.getHashByteLength(hashAlgo) < hash.getHashByteLength(enums.hash.sha256)) {
|
|
14247
|
+
throw new Error('Hash algorithm too weak for EdDSA.');
|
|
14248
|
+
}
|
|
14219
14249
|
const signature = util.concatUint8Array([r, s]);
|
|
14220
14250
|
return naclFastLight.sign.detached.verify(hashed, signature, publicKey.subarray(1));
|
|
14221
14251
|
}
|
|
@@ -14285,14 +14315,27 @@ async function generate$2(algo) {
|
|
|
14285
14315
|
* @async
|
|
14286
14316
|
*/
|
|
14287
14317
|
async function sign$3(algo, hashAlgo, message, publicKey, privateKey, hashed) {
|
|
14288
|
-
if (hash.getHashByteLength(hashAlgo) < hash.getHashByteLength(
|
|
14289
|
-
|
|
14290
|
-
throw new Error('Hash algorithm too weak: sha256 or stronger is required for EdDSA.');
|
|
14318
|
+
if (hash.getHashByteLength(hashAlgo) < hash.getHashByteLength(getPreferredHashAlgo$1(algo))) {
|
|
14319
|
+
throw new Error('Hash algorithm too weak for EdDSA.');
|
|
14291
14320
|
}
|
|
14292
14321
|
switch (algo) {
|
|
14293
14322
|
case enums.publicKey.ed25519: {
|
|
14294
14323
|
const secretKey = util.concatUint8Array([privateKey, publicKey]);
|
|
14295
14324
|
const signature = naclFastLight.sign.detached(hashed, secretKey);
|
|
14325
|
+
if (config.checkEdDSAFaultySignatures && !naclFastLight.sign.detached.verify(hashed, signature, publicKey)) {
|
|
14326
|
+
/**
|
|
14327
|
+
* Detect faulty signatures caused by random bitflips during `crypto_sign` which could lead to private key extraction
|
|
14328
|
+
* if two signatures over the same message are obtained.
|
|
14329
|
+
* See https://github.com/jedisct1/libsodium/issues/170.
|
|
14330
|
+
* If the input data is not deterministic, e.g. thanks to the random salt in v6 OpenPGP signatures (not yet implemented),
|
|
14331
|
+
* then the generated signature is always safe, and the verification step is skipped.
|
|
14332
|
+
* Otherwise, we need to verify the generated to ensure that no bitflip occured:
|
|
14333
|
+
* - in M between the computation of `r` and `h`.
|
|
14334
|
+
* - in the public key before computing `h`
|
|
14335
|
+
* The verification step is almost 2-3 times as slow as signing, but it's faster than re-signing + re-deriving the public key for separate checks.
|
|
14336
|
+
*/
|
|
14337
|
+
throw new Error('Transient signing failure');
|
|
14338
|
+
}
|
|
14296
14339
|
return { RS: signature };
|
|
14297
14340
|
}
|
|
14298
14341
|
case enums.publicKey.ed448:
|
|
@@ -14314,6 +14357,9 @@ async function sign$3(algo, hashAlgo, message, publicKey, privateKey, hashed) {
|
|
|
14314
14357
|
* @async
|
|
14315
14358
|
*/
|
|
14316
14359
|
async function verify$3(algo, hashAlgo, { RS }, m, publicKey, hashed) {
|
|
14360
|
+
if (hash.getHashByteLength(hashAlgo) < hash.getHashByteLength(getPreferredHashAlgo$1(algo))) {
|
|
14361
|
+
throw new Error('Hash algorithm too weak for EdDSA.');
|
|
14362
|
+
}
|
|
14317
14363
|
switch (algo) {
|
|
14318
14364
|
case enums.publicKey.ed25519: {
|
|
14319
14365
|
return naclFastLight.sign.detached.verify(hashed, RS, publicKey);
|
|
@@ -14349,12 +14395,22 @@ async function validateParams$4(algo, A, seed) {
|
|
|
14349
14395
|
}
|
|
14350
14396
|
}
|
|
14351
14397
|
|
|
14398
|
+
function getPreferredHashAlgo$1(algo) {
|
|
14399
|
+
switch (algo) {
|
|
14400
|
+
case enums.publicKey.ed25519:
|
|
14401
|
+
return enums.hash.sha256;
|
|
14402
|
+
default:
|
|
14403
|
+
throw new Error('Unknown EdDSA algo');
|
|
14404
|
+
}
|
|
14405
|
+
}
|
|
14406
|
+
|
|
14352
14407
|
var eddsa = /*#__PURE__*/Object.freeze({
|
|
14353
14408
|
__proto__: null,
|
|
14354
14409
|
generate: generate$2,
|
|
14355
14410
|
sign: sign$3,
|
|
14356
14411
|
verify: verify$3,
|
|
14357
|
-
validateParams: validateParams$4
|
|
14412
|
+
validateParams: validateParams$4,
|
|
14413
|
+
getPreferredHashAlgo: getPreferredHashAlgo$1
|
|
14358
14414
|
});
|
|
14359
14415
|
|
|
14360
14416
|
// OpenPGP.js - An OpenPGP implementation in javascript
|
|
@@ -14968,8 +15024,6 @@ async function generate$3(algo) {
|
|
|
14968
15024
|
case enums.publicKey.x25519: {
|
|
14969
15025
|
// k stays in little-endian, unlike legacy ECDH over curve25519
|
|
14970
15026
|
const k = getRandomBytes(32);
|
|
14971
|
-
k[0] &= 248;
|
|
14972
|
-
k[31] = (k[31] & 127) | 64;
|
|
14973
15027
|
const { publicKey: A } = naclFastLight.box.keyPair.fromSecretKey(k);
|
|
14974
15028
|
return { A, k };
|
|
14975
15029
|
}
|
|
@@ -15404,8 +15458,7 @@ function parseSignatureParams(algo, signature) {
|
|
|
15404
15458
|
// Algorithm-Specific Fields for legacy EdDSA signatures:
|
|
15405
15459
|
// - MPI of an EC point r.
|
|
15406
15460
|
// - EdDSA value s, in MPI, in the little endian representation
|
|
15407
|
-
case enums.publicKey.
|
|
15408
|
-
case enums.publicKey.ed25519Legacy: {
|
|
15461
|
+
case enums.publicKey.eddsaLegacy: {
|
|
15409
15462
|
// When parsing little-endian MPI data, we always need to left-pad it, as done with big-endian values:
|
|
15410
15463
|
// https://www.ietf.org/archive/id/draft-ietf-openpgp-rfc4880bis-10.html#section-3.2-9
|
|
15411
15464
|
let r = util.readMPI(signature.subarray(read)); read += r.length + 2;
|
|
@@ -15466,8 +15519,7 @@ async function verify$5(algo, hashAlgo, signature, publicParams, privateParams,
|
|
|
15466
15519
|
const s = util.leftPad(signature.s, curveSize);
|
|
15467
15520
|
return publicKey.elliptic.ecdsa.verify(oid, hashAlgo, { r, s }, data, Q, hashed);
|
|
15468
15521
|
}
|
|
15469
|
-
case enums.publicKey.
|
|
15470
|
-
case enums.publicKey.ed25519Legacy: {
|
|
15522
|
+
case enums.publicKey.eddsaLegacy: {
|
|
15471
15523
|
const { oid, Q } = publicParams;
|
|
15472
15524
|
// signature already padded on parsing
|
|
15473
15525
|
return publicKey.elliptic.eddsaLegacy.verify(oid, hashAlgo, signature, data, Q, hashed);
|
|
@@ -15530,8 +15582,7 @@ async function sign$5(algo, hashAlgo, publicKeyParams, privateKeyParams, data, h
|
|
|
15530
15582
|
const { d } = privateKeyParams;
|
|
15531
15583
|
return publicKey.elliptic.ecdsa.sign(oid, hashAlgo, data, Q, d, hashed);
|
|
15532
15584
|
}
|
|
15533
|
-
case enums.publicKey.
|
|
15534
|
-
case enums.publicKey.ed25519Legacy: {
|
|
15585
|
+
case enums.publicKey.eddsaLegacy: {
|
|
15535
15586
|
const { oid, Q } = publicKeyParams;
|
|
15536
15587
|
const { seed } = privateKeyParams;
|
|
15537
15588
|
return publicKey.elliptic.eddsaLegacy.sign(oid, hashAlgo, data, Q, seed, hashed);
|
|
@@ -15922,8 +15973,7 @@ function parsePublicKeyParams(algo, bytes) {
|
|
|
15922
15973
|
const Q = util.readMPI(bytes.subarray(read)); read += Q.length + 2;
|
|
15923
15974
|
return { read: read, publicParams: { oid, Q } };
|
|
15924
15975
|
}
|
|
15925
|
-
case enums.publicKey.
|
|
15926
|
-
case enums.publicKey.ed25519Legacy: {
|
|
15976
|
+
case enums.publicKey.eddsaLegacy: {
|
|
15927
15977
|
const oid = new OID(); read += oid.read(bytes);
|
|
15928
15978
|
checkSupportedCurve(oid);
|
|
15929
15979
|
let Q = util.readMPI(bytes.subarray(read)); read += Q.length + 2;
|
|
@@ -15985,8 +16035,7 @@ function parsePrivateKeyParams(algo, bytes, publicParams) {
|
|
|
15985
16035
|
d = util.leftPad(d, curve.payloadSize);
|
|
15986
16036
|
return { read, privateParams: { d } };
|
|
15987
16037
|
}
|
|
15988
|
-
case enums.publicKey.
|
|
15989
|
-
case enums.publicKey.ed25519Legacy: {
|
|
16038
|
+
case enums.publicKey.eddsaLegacy: {
|
|
15990
16039
|
const curve = new CurveWithOID(publicParams.oid);
|
|
15991
16040
|
let seed = util.readMPI(bytes.subarray(read)); read += seed.length + 2;
|
|
15992
16041
|
seed = util.leftPad(seed, curve.payloadSize);
|
|
@@ -16121,8 +16170,7 @@ function generateParams(algo, bits, oid, symmetric) {
|
|
|
16121
16170
|
privateParams: { d: secret },
|
|
16122
16171
|
publicParams: { oid: new OID(oid), Q }
|
|
16123
16172
|
}));
|
|
16124
|
-
case enums.publicKey.
|
|
16125
|
-
case enums.publicKey.ed25519Legacy:
|
|
16173
|
+
case enums.publicKey.eddsaLegacy:
|
|
16126
16174
|
return publicKey.elliptic.generate(oid).then(({ oid, Q, secret }) => ({
|
|
16127
16175
|
privateParams: { seed: secret },
|
|
16128
16176
|
publicParams: { oid: new OID(oid), Q }
|
|
@@ -16216,8 +16264,7 @@ async function validateParams$8(algo, publicParams, privateParams) {
|
|
|
16216
16264
|
const { d } = privateParams;
|
|
16217
16265
|
return algoModule.validateParams(oid, Q, d);
|
|
16218
16266
|
}
|
|
16219
|
-
case enums.publicKey.
|
|
16220
|
-
case enums.publicKey.ed25519Legacy: {
|
|
16267
|
+
case enums.publicKey.eddsaLegacy: {
|
|
16221
16268
|
const { Q, oid } = publicParams;
|
|
16222
16269
|
const { seed } = privateParams;
|
|
16223
16270
|
return publicKey.elliptic.eddsaLegacy.validateParams(oid, Q, seed);
|
|
@@ -16300,6 +16347,23 @@ function checkSupportedCurve(oid) {
|
|
|
16300
16347
|
}
|
|
16301
16348
|
}
|
|
16302
16349
|
|
|
16350
|
+
/**
|
|
16351
|
+
* Get preferred hash algo for a given elliptic algo
|
|
16352
|
+
* @param {module:enums.publicKey} algo - alrogithm identifier
|
|
16353
|
+
* @param {module:type/oid} [oid] - curve OID if needed by algo
|
|
16354
|
+
*/
|
|
16355
|
+
function getPreferredCurveHashAlgo(algo, oid) {
|
|
16356
|
+
switch (algo) {
|
|
16357
|
+
case enums.publicKey.ecdsa:
|
|
16358
|
+
case enums.publicKey.eddsaLegacy:
|
|
16359
|
+
return publicKey.elliptic.getPreferredHashAlgo(oid);
|
|
16360
|
+
case enums.publicKey.ed25519:
|
|
16361
|
+
return publicKey.elliptic.eddsa.getPreferredHashAlgo(algo);
|
|
16362
|
+
default:
|
|
16363
|
+
throw new Error('Unknown elliptic signing algo');
|
|
16364
|
+
}
|
|
16365
|
+
}
|
|
16366
|
+
|
|
16303
16367
|
var crypto$1 = /*#__PURE__*/Object.freeze({
|
|
16304
16368
|
__proto__: null,
|
|
16305
16369
|
publicKeyEncrypt: publicKeyEncrypt,
|
|
@@ -16313,7 +16377,8 @@ var crypto$1 = /*#__PURE__*/Object.freeze({
|
|
|
16313
16377
|
getPrefixRandom: getPrefixRandom,
|
|
16314
16378
|
generateSessionKey: generateSessionKey,
|
|
16315
16379
|
getAEADMode: getAEADMode,
|
|
16316
|
-
getCipher: getCipher
|
|
16380
|
+
getCipher: getCipher,
|
|
16381
|
+
getPreferredCurveHashAlgo: getPreferredCurveHashAlgo
|
|
16317
16382
|
});
|
|
16318
16383
|
|
|
16319
16384
|
/**
|
|
@@ -28071,25 +28136,22 @@ async function createBindingSignature(subkey, primaryKey, options, config) {
|
|
|
28071
28136
|
const dataToSign = {};
|
|
28072
28137
|
dataToSign.key = primaryKey;
|
|
28073
28138
|
dataToSign.bind = subkey;
|
|
28074
|
-
const
|
|
28075
|
-
subkeySignaturePacket.signatureType = enums.signature.subkeyBinding;
|
|
28076
|
-
subkeySignaturePacket.publicKeyAlgorithm = primaryKey.algorithm;
|
|
28077
|
-
subkeySignaturePacket.hashAlgorithm = await getPreferredHashAlgo$1(null, subkey, undefined, undefined, config);
|
|
28139
|
+
const signatureProperties = { signatureType: enums.signature.subkeyBinding };
|
|
28078
28140
|
if (options.sign) {
|
|
28079
|
-
|
|
28080
|
-
|
|
28141
|
+
signatureProperties.keyFlags = [enums.keyFlags.signData];
|
|
28142
|
+
signatureProperties.embeddedSignature = await createSignaturePacket(dataToSign, null, subkey, {
|
|
28081
28143
|
signatureType: enums.signature.keyBinding
|
|
28082
28144
|
}, options.date, undefined, undefined, undefined, config);
|
|
28083
28145
|
} else {
|
|
28084
|
-
|
|
28146
|
+
signatureProperties.keyFlags = options.forwarding ?
|
|
28085
28147
|
[enums.keyFlags.forwardedCommunication] :
|
|
28086
28148
|
[enums.keyFlags.encryptCommunication | enums.keyFlags.encryptStorage];
|
|
28087
28149
|
}
|
|
28088
28150
|
if (options.keyExpirationTime > 0) {
|
|
28089
|
-
|
|
28090
|
-
|
|
28151
|
+
signatureProperties.keyExpirationTime = options.keyExpirationTime;
|
|
28152
|
+
signatureProperties.keyNeverExpires = false;
|
|
28091
28153
|
}
|
|
28092
|
-
await
|
|
28154
|
+
const subkeySignaturePacket = await createSignaturePacket(dataToSign, null, primaryKey, signatureProperties, options.date, undefined, undefined, undefined, config);
|
|
28093
28155
|
return subkeySignaturePacket;
|
|
28094
28156
|
}
|
|
28095
28157
|
|
|
@@ -28103,7 +28165,7 @@ async function createBindingSignature(subkey, primaryKey, options, config) {
|
|
|
28103
28165
|
* @returns {Promise<enums.hash>}
|
|
28104
28166
|
* @async
|
|
28105
28167
|
*/
|
|
28106
|
-
async function getPreferredHashAlgo$
|
|
28168
|
+
async function getPreferredHashAlgo$2(key, keyPacket, date = new Date(), userID = {}, config) {
|
|
28107
28169
|
let hashAlgo = config.preferredHashAlgorithm;
|
|
28108
28170
|
let prefAlgo = hashAlgo;
|
|
28109
28171
|
if (key) {
|
|
@@ -28114,17 +28176,11 @@ async function getPreferredHashAlgo$1(key, keyPacket, date = new Date(), userID
|
|
|
28114
28176
|
prefAlgo : hashAlgo;
|
|
28115
28177
|
}
|
|
28116
28178
|
}
|
|
28117
|
-
switch (
|
|
28118
|
-
case
|
|
28119
|
-
case
|
|
28120
|
-
case
|
|
28121
|
-
|
|
28122
|
-
switch (keyPacket.algorithm) {
|
|
28123
|
-
case enums.publicKey.ecdh:
|
|
28124
|
-
case enums.publicKey.ecdsa:
|
|
28125
|
-
case enums.publicKey.eddsa:
|
|
28126
|
-
prefAlgo = mod.publicKey.elliptic.getPreferredHashAlgo(keyPacket.publicParams.oid);
|
|
28127
|
-
}
|
|
28179
|
+
switch (keyPacket.algorithm) {
|
|
28180
|
+
case enums.publicKey.ecdsa:
|
|
28181
|
+
case enums.publicKey.eddsaLegacy:
|
|
28182
|
+
case enums.publicKey.ed25519:
|
|
28183
|
+
prefAlgo = mod.getPreferredCurveHashAlgo(keyPacket.algorithm, keyPacket.publicParams.oid);
|
|
28128
28184
|
}
|
|
28129
28185
|
return mod.hash.getHashByteLength(hashAlgo) <= mod.hash.getHashByteLength(prefAlgo) ?
|
|
28130
28186
|
prefAlgo : hashAlgo;
|
|
@@ -28192,7 +28248,7 @@ async function createSignaturePacket(dataToSign, privateKey, signingKeyPacket, s
|
|
|
28192
28248
|
const signaturePacket = new SignaturePacket();
|
|
28193
28249
|
Object.assign(signaturePacket, signatureProperties);
|
|
28194
28250
|
signaturePacket.publicKeyAlgorithm = signingKeyPacket.algorithm;
|
|
28195
|
-
signaturePacket.hashAlgorithm = await getPreferredHashAlgo$
|
|
28251
|
+
signaturePacket.hashAlgorithm = await getPreferredHashAlgo$2(privateKey, signingKeyPacket, date, userID, config);
|
|
28196
28252
|
signaturePacket.rawNotations = notations;
|
|
28197
28253
|
await signaturePacket.sign(signingKeyPacket, dataToSign, date, detached);
|
|
28198
28254
|
return signaturePacket;
|
|
@@ -28333,11 +28389,11 @@ function sanitizeKeyOptions(options, subkeyDefaults = {}) {
|
|
|
28333
28389
|
} catch (e) {
|
|
28334
28390
|
throw new Error('Unknown curve');
|
|
28335
28391
|
}
|
|
28336
|
-
if (options.curve === enums.curve.
|
|
28337
|
-
options.curve = options.sign ? enums.curve.
|
|
28392
|
+
if (options.curve === enums.curve.ed25519Legacy || options.curve === enums.curve.curve25519Legacy) {
|
|
28393
|
+
options.curve = options.sign ? enums.curve.ed25519Legacy : enums.curve.curve25519Legacy;
|
|
28338
28394
|
}
|
|
28339
28395
|
if (options.sign) {
|
|
28340
|
-
options.algorithm = options.curve === enums.curve.
|
|
28396
|
+
options.algorithm = options.curve === enums.curve.ed25519Legacy ? enums.publicKey.eddsaLegacy : enums.publicKey.ecdsa;
|
|
28341
28397
|
} else {
|
|
28342
28398
|
options.algorithm = enums.publicKey.ecdh;
|
|
28343
28399
|
}
|
|
@@ -28375,7 +28431,7 @@ function isValidEncryptionKeyPacket(keyPacket, signature) {
|
|
|
28375
28431
|
return keyAlgo !== enums.publicKey.dsa &&
|
|
28376
28432
|
keyAlgo !== enums.publicKey.rsaSign &&
|
|
28377
28433
|
keyAlgo !== enums.publicKey.ecdsa &&
|
|
28378
|
-
keyAlgo !== enums.publicKey.
|
|
28434
|
+
keyAlgo !== enums.publicKey.eddsaLegacy &&
|
|
28379
28435
|
keyAlgo !== enums.publicKey.ed25519 &&
|
|
28380
28436
|
(!signature.keyFlags ||
|
|
28381
28437
|
(signature.keyFlags[0] & enums.keyFlags.encryptCommunication) !== 0 ||
|
|
@@ -28421,7 +28477,7 @@ function checkKeyRequirements(keyPacket, config) {
|
|
|
28421
28477
|
}
|
|
28422
28478
|
break;
|
|
28423
28479
|
case enums.publicKey.ecdsa:
|
|
28424
|
-
case enums.publicKey.
|
|
28480
|
+
case enums.publicKey.eddsaLegacy:
|
|
28425
28481
|
case enums.publicKey.ecdh:
|
|
28426
28482
|
if (config.rejectCurves.has(algoInfo.curve)) {
|
|
28427
28483
|
throw new Error(`Support for ${algoInfo.algorithm} keys using curve ${algoInfo.curve} is disabled.`);
|
|
@@ -30048,50 +30104,50 @@ async function wrapKeyObject(secretKeyPacket, secretSubkeyPackets, options, conf
|
|
|
30048
30104
|
const dataToSign = {};
|
|
30049
30105
|
dataToSign.userID = userIDPacket;
|
|
30050
30106
|
dataToSign.key = secretKeyPacket;
|
|
30051
|
-
|
|
30052
|
-
|
|
30053
|
-
|
|
30054
|
-
|
|
30055
|
-
|
|
30056
|
-
signaturePacket.preferredSymmetricAlgorithms = createPreferredAlgos([
|
|
30107
|
+
|
|
30108
|
+
const signatureProperties = {};
|
|
30109
|
+
signatureProperties.signatureType = enums.signature.certGeneric;
|
|
30110
|
+
signatureProperties.keyFlags = [enums.keyFlags.certifyKeys | enums.keyFlags.signData];
|
|
30111
|
+
signatureProperties.preferredSymmetricAlgorithms = createPreferredAlgos([
|
|
30057
30112
|
// prefer aes256, aes128, then aes192 (no WebCrypto support: https://www.chromium.org/blink/webcrypto#TOC-AES-support)
|
|
30058
30113
|
enums.symmetric.aes256,
|
|
30059
30114
|
enums.symmetric.aes128,
|
|
30060
30115
|
enums.symmetric.aes192
|
|
30061
30116
|
], config.preferredSymmetricAlgorithm);
|
|
30062
30117
|
if (config.aeadProtect) {
|
|
30063
|
-
|
|
30118
|
+
signatureProperties.preferredAEADAlgorithms = createPreferredAlgos([
|
|
30064
30119
|
enums.aead.eax,
|
|
30065
30120
|
enums.aead.ocb
|
|
30066
30121
|
], config.preferredAEADAlgorithm);
|
|
30067
30122
|
}
|
|
30068
|
-
|
|
30123
|
+
signatureProperties.preferredHashAlgorithms = createPreferredAlgos([
|
|
30069
30124
|
// prefer fast asm.js implementations (SHA-256)
|
|
30070
30125
|
enums.hash.sha256,
|
|
30071
30126
|
enums.hash.sha512
|
|
30072
30127
|
], config.preferredHashAlgorithm);
|
|
30073
|
-
|
|
30128
|
+
signatureProperties.preferredCompressionAlgorithms = createPreferredAlgos([
|
|
30074
30129
|
enums.compression.zlib,
|
|
30075
30130
|
enums.compression.zip,
|
|
30076
30131
|
enums.compression.uncompressed
|
|
30077
30132
|
], config.preferredCompressionAlgorithm);
|
|
30078
30133
|
if (index === 0) {
|
|
30079
|
-
|
|
30134
|
+
signatureProperties.isPrimaryUserID = true;
|
|
30080
30135
|
}
|
|
30081
30136
|
// integrity protection always enabled
|
|
30082
|
-
|
|
30083
|
-
|
|
30137
|
+
signatureProperties.features = [0];
|
|
30138
|
+
signatureProperties.features[0] |= enums.features.modificationDetection;
|
|
30084
30139
|
if (config.aeadProtect) {
|
|
30085
|
-
|
|
30140
|
+
signatureProperties.features[0] |= enums.features.aead;
|
|
30086
30141
|
}
|
|
30087
30142
|
if (config.v5Keys) {
|
|
30088
|
-
|
|
30143
|
+
signatureProperties.features[0] |= enums.features.v5Keys;
|
|
30089
30144
|
}
|
|
30090
30145
|
if (options.keyExpirationTime > 0) {
|
|
30091
|
-
|
|
30092
|
-
|
|
30146
|
+
signatureProperties.keyExpirationTime = options.keyExpirationTime;
|
|
30147
|
+
signatureProperties.keyNeverExpires = false;
|
|
30093
30148
|
}
|
|
30094
|
-
|
|
30149
|
+
|
|
30150
|
+
const signaturePacket = await createSignaturePacket(dataToSign, null, secretKeyPacket, signatureProperties, options.date, undefined, undefined, undefined, config);
|
|
30095
30151
|
|
|
30096
30152
|
return { userIDPacket, signaturePacket };
|
|
30097
30153
|
})).then(list => {
|
|
@@ -30793,7 +30849,7 @@ class Message {
|
|
|
30793
30849
|
const signingKey = await primaryKey.getSigningKey(signingKeyID, date, userIDs, config$1);
|
|
30794
30850
|
const onePassSig = new OnePassSignaturePacket();
|
|
30795
30851
|
onePassSig.signatureType = signatureType;
|
|
30796
|
-
onePassSig.hashAlgorithm = await getPreferredHashAlgo$
|
|
30852
|
+
onePassSig.hashAlgorithm = await getPreferredHashAlgo$2(primaryKey, signingKey.keyPacket, date, userIDs, config$1);
|
|
30797
30853
|
onePassSig.publicKeyAlgorithm = signingKey.keyPacket.algorithm;
|
|
30798
30854
|
onePassSig.issuerKeyID = signingKey.getKeyID();
|
|
30799
30855
|
if (i === signingKeys.length - 1) {
|