@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.js
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
|
'use strict';
|
|
3
3
|
|
|
4
4
|
const globalThis = typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
|
|
@@ -263,18 +263,17 @@ if (NodeReadableStream$1) {
|
|
|
263
263
|
this.push(null);
|
|
264
264
|
break;
|
|
265
265
|
}
|
|
266
|
-
if (!this.push(value)
|
|
267
|
-
this._reading = false;
|
|
266
|
+
if (!this.push(value)) {
|
|
268
267
|
break;
|
|
269
268
|
}
|
|
270
269
|
}
|
|
271
|
-
} catch(e) {
|
|
272
|
-
this.
|
|
270
|
+
} catch (e) {
|
|
271
|
+
this.destroy(e);
|
|
273
272
|
}
|
|
274
273
|
}
|
|
275
274
|
|
|
276
|
-
_destroy(
|
|
277
|
-
this._reader.cancel(
|
|
275
|
+
async _destroy(error, callback) {
|
|
276
|
+
this._reader.cancel(error).then(callback, callback);
|
|
278
277
|
}
|
|
279
278
|
}
|
|
280
279
|
|
|
@@ -309,7 +308,7 @@ function Reader(input) {
|
|
|
309
308
|
const reader = input.getReader();
|
|
310
309
|
this._read = reader.read.bind(reader);
|
|
311
310
|
this._releaseLock = () => {};
|
|
312
|
-
this._cancel = () => {};
|
|
311
|
+
this._cancel = async () => {};
|
|
313
312
|
return;
|
|
314
313
|
}
|
|
315
314
|
let streamType = isStream(input);
|
|
@@ -1574,17 +1573,21 @@ var enums = {
|
|
|
1574
1573
|
'2b8104000a': 'secp256k1',
|
|
1575
1574
|
'2B8104000A': 'secp256k1',
|
|
1576
1575
|
|
|
1577
|
-
/** Ed25519 */
|
|
1576
|
+
/** Ed25519 - deprecated by crypto-refresh (replaced by standaone Ed25519 algo) */
|
|
1577
|
+
'ed25519Legacy': 'ed25519',
|
|
1578
1578
|
'ED25519': 'ed25519',
|
|
1579
|
+
/** @deprecated use `ed25519Legacy` instead */
|
|
1579
1580
|
'ed25519': 'ed25519',
|
|
1580
1581
|
'Ed25519': 'ed25519',
|
|
1581
1582
|
'1.3.6.1.4.1.11591.15.1': 'ed25519',
|
|
1582
1583
|
'2b06010401da470f01': 'ed25519',
|
|
1583
1584
|
'2B06010401DA470F01': 'ed25519',
|
|
1584
1585
|
|
|
1585
|
-
/** Curve25519 */
|
|
1586
|
+
/** Curve25519 - deprecated by crypto-refresh (replaced by standaone X25519 algo) */
|
|
1587
|
+
'curve25519Legacy': 'curve25519',
|
|
1586
1588
|
'X25519': 'curve25519',
|
|
1587
1589
|
'cv25519': 'curve25519',
|
|
1590
|
+
/** @deprecated use `curve25519Legacy` instead */
|
|
1588
1591
|
'curve25519': 'curve25519',
|
|
1589
1592
|
'Curve25519': 'curve25519',
|
|
1590
1593
|
'1.3.6.1.4.1.3029.1.5.1': 'curve25519',
|
|
@@ -1655,8 +1658,11 @@ var enums = {
|
|
|
1655
1658
|
ecdsa: 19,
|
|
1656
1659
|
/** EdDSA (Sign only) - deprecated by crypto-refresh (replaced by `ed25519` identifier below)
|
|
1657
1660
|
* [{@link https://tools.ietf.org/html/draft-koch-eddsa-for-openpgp-04|Draft RFC}] */
|
|
1658
|
-
|
|
1659
|
-
|
|
1661
|
+
eddsaLegacy: 22, // NB: this is declared before `eddsa` to translate 22 to 'eddsa' for backwards compatibility
|
|
1662
|
+
/** @deprecated use `eddsaLegacy` instead */
|
|
1663
|
+
ed25519Legacy: 22,
|
|
1664
|
+
/** @deprecated use `eddsaLegacy` instead */
|
|
1665
|
+
eddsa: 22,
|
|
1660
1666
|
/** Reserved for AEDH */
|
|
1661
1667
|
aedh: 23,
|
|
1662
1668
|
/** Reserved for AEDSA */
|
|
@@ -2964,7 +2970,7 @@ var config = {
|
|
|
2964
2970
|
* @memberof module:config
|
|
2965
2971
|
* @property {String} versionString A version string to be included in armored messages
|
|
2966
2972
|
*/
|
|
2967
|
-
versionString: 'OpenPGP.js 5.
|
|
2973
|
+
versionString: 'OpenPGP.js 5.11.0',
|
|
2968
2974
|
/**
|
|
2969
2975
|
* @memberof module:config
|
|
2970
2976
|
* @property {String} commentString A comment string to be included in armored messages
|
|
@@ -3015,7 +3021,14 @@ var config = {
|
|
|
3015
3021
|
* @memberof module:config
|
|
3016
3022
|
* @property {Set<String>} rejectCurves {@link module:enums.curve}
|
|
3017
3023
|
*/
|
|
3018
|
-
rejectCurves: new Set([enums.curve.secp256k1])
|
|
3024
|
+
rejectCurves: new Set([enums.curve.secp256k1]),
|
|
3025
|
+
/**
|
|
3026
|
+
* Whether to validate generated EdDSA signatures before returning them, to ensure they are not faulty signatures.
|
|
3027
|
+
* This check will make signing 2-3 times slower.
|
|
3028
|
+
* Faulty signatures may be generated (in principle) if random bitflips occur at specific points in the signature
|
|
3029
|
+
* computation, and could be used to recover the signer's secret key given a second signature over the same data.
|
|
3030
|
+
*/
|
|
3031
|
+
checkEdDSAFaultySignatures: true
|
|
3019
3032
|
};
|
|
3020
3033
|
|
|
3021
3034
|
/**
|
|
@@ -11001,42 +11014,42 @@ async function GCM(cipher, key) {
|
|
|
11001
11014
|
throw new Error('GCM mode supports only AES cipher');
|
|
11002
11015
|
}
|
|
11003
11016
|
|
|
11004
|
-
if (util.
|
|
11005
|
-
const _key = await webCrypto$4.importKey('raw', key, { name: ALGO }, false, ['encrypt', 'decrypt']);
|
|
11006
|
-
|
|
11017
|
+
if (util.getNodeCrypto()) { // Node crypto library
|
|
11007
11018
|
return {
|
|
11008
11019
|
encrypt: async function(pt, iv, adata = new Uint8Array()) {
|
|
11009
|
-
|
|
11010
|
-
|
|
11011
|
-
|
|
11012
|
-
const ct = await webCrypto$4.encrypt({ name: ALGO, iv, additionalData: adata, tagLength: tagLength$2 * 8 }, _key, pt);
|
|
11020
|
+
const en = new nodeCrypto$4.createCipheriv('aes-' + (key.length * 8) + '-gcm', key, iv);
|
|
11021
|
+
en.setAAD(adata);
|
|
11022
|
+
const ct = Buffer$3.concat([en.update(pt), en.final(), en.getAuthTag()]); // append auth tag to ciphertext
|
|
11013
11023
|
return new Uint8Array(ct);
|
|
11014
11024
|
},
|
|
11015
11025
|
|
|
11016
11026
|
decrypt: async function(ct, iv, adata = new Uint8Array()) {
|
|
11017
|
-
|
|
11018
|
-
|
|
11019
|
-
|
|
11020
|
-
const pt =
|
|
11027
|
+
const de = new nodeCrypto$4.createDecipheriv('aes-' + (key.length * 8) + '-gcm', key, iv);
|
|
11028
|
+
de.setAAD(adata);
|
|
11029
|
+
de.setAuthTag(ct.slice(ct.length - tagLength$2, ct.length)); // read auth tag at end of ciphertext
|
|
11030
|
+
const pt = Buffer$3.concat([de.update(ct.slice(0, ct.length - tagLength$2)), de.final()]);
|
|
11021
11031
|
return new Uint8Array(pt);
|
|
11022
11032
|
}
|
|
11023
11033
|
};
|
|
11024
11034
|
}
|
|
11025
11035
|
|
|
11026
|
-
if (util.
|
|
11036
|
+
if (util.getWebCrypto() && key.length !== 24) { // WebCrypto (no 192 bit support) see: https://www.chromium.org/blink/webcrypto#TOC-AES-support
|
|
11037
|
+
const _key = await webCrypto$4.importKey('raw', key, { name: ALGO }, false, ['encrypt', 'decrypt']);
|
|
11038
|
+
|
|
11027
11039
|
return {
|
|
11028
11040
|
encrypt: async function(pt, iv, adata = new Uint8Array()) {
|
|
11029
|
-
|
|
11030
|
-
|
|
11031
|
-
|
|
11041
|
+
if (!pt.length) { // iOS does not support GCM-en/decrypting empty messages
|
|
11042
|
+
return AES_GCM.encrypt(pt, key, iv, adata);
|
|
11043
|
+
}
|
|
11044
|
+
const ct = await webCrypto$4.encrypt({ name: ALGO, iv, additionalData: adata, tagLength: tagLength$2 * 8 }, _key, pt);
|
|
11032
11045
|
return new Uint8Array(ct);
|
|
11033
11046
|
},
|
|
11034
11047
|
|
|
11035
11048
|
decrypt: async function(ct, iv, adata = new Uint8Array()) {
|
|
11036
|
-
|
|
11037
|
-
|
|
11038
|
-
|
|
11039
|
-
const pt =
|
|
11049
|
+
if (ct.length === tagLength$2) { // iOS does not support GCM-en/decrypting empty messages
|
|
11050
|
+
return AES_GCM.decrypt(ct, key, iv, adata);
|
|
11051
|
+
}
|
|
11052
|
+
const pt = await webCrypto$4.decrypt({ name: ALGO, iv, additionalData: adata, tagLength: tagLength$2 * 8 }, _key, ct);
|
|
11040
11053
|
return new Uint8Array(pt);
|
|
11041
11054
|
}
|
|
11042
11055
|
};
|
|
@@ -12039,11 +12052,11 @@ const nodeCrypto$5 = util.getNodeCrypto();
|
|
|
12039
12052
|
*/
|
|
12040
12053
|
function getRandomBytes(length) {
|
|
12041
12054
|
const buf = new Uint8Array(length);
|
|
12042
|
-
if (
|
|
12043
|
-
crypto.getRandomValues(buf);
|
|
12044
|
-
} else if (nodeCrypto$5) {
|
|
12055
|
+
if (nodeCrypto$5) {
|
|
12045
12056
|
const bytes = nodeCrypto$5.randomBytes(buf.length);
|
|
12046
12057
|
buf.set(bytes);
|
|
12058
|
+
} else if (typeof crypto !== 'undefined' && crypto.getRandomValues) {
|
|
12059
|
+
crypto.getRandomValues(buf);
|
|
12047
12060
|
} else {
|
|
12048
12061
|
throw new Error('No secure random number generator available.');
|
|
12049
12062
|
}
|
|
@@ -13603,7 +13616,7 @@ const curves = {
|
|
|
13603
13616
|
},
|
|
13604
13617
|
ed25519: {
|
|
13605
13618
|
oid: [0x06, 0x09, 0x2B, 0x06, 0x01, 0x04, 0x01, 0xDA, 0x47, 0x0F, 0x01],
|
|
13606
|
-
keyType: enums.publicKey.
|
|
13619
|
+
keyType: enums.publicKey.eddsaLegacy,
|
|
13607
13620
|
hash: enums.hash.sha512,
|
|
13608
13621
|
node: false, // nodeCurves.ed25519 TODO
|
|
13609
13622
|
payloadSize: 32
|
|
@@ -14206,10 +14219,24 @@ naclFastLight.hash = bytes => new Uint8Array(_512().update(bytes).digest());
|
|
|
14206
14219
|
async function sign$2(oid, hashAlgo, message, publicKey, privateKey, hashed) {
|
|
14207
14220
|
if (hash.getHashByteLength(hashAlgo) < hash.getHashByteLength(enums.hash.sha256)) {
|
|
14208
14221
|
// see https://tools.ietf.org/id/draft-ietf-openpgp-rfc4880bis-10.html#section-15-7.2
|
|
14209
|
-
throw new Error('Hash algorithm too weak
|
|
14222
|
+
throw new Error('Hash algorithm too weak for EdDSA.');
|
|
14210
14223
|
}
|
|
14211
14224
|
const secretKey = util.concatUint8Array([privateKey, publicKey.subarray(1)]);
|
|
14212
14225
|
const signature = naclFastLight.sign.detached(hashed, secretKey);
|
|
14226
|
+
if (config.checkEdDSAFaultySignatures && !naclFastLight.sign.detached.verify(hashed, signature, publicKey.subarray(1))) {
|
|
14227
|
+
/**
|
|
14228
|
+
* Detect faulty signatures caused by random bitflips during `crypto_sign` which could lead to private key extraction
|
|
14229
|
+
* if two signatures over the same message are obtained.
|
|
14230
|
+
* See https://github.com/jedisct1/libsodium/issues/170.
|
|
14231
|
+
* If the input data is not deterministic, e.g. thanks to the random salt in v6 OpenPGP signatures (not yet implemented),
|
|
14232
|
+
* then the generated signature is always safe, and the verification step is skipped.
|
|
14233
|
+
* Otherwise, we need to verify the generated to ensure that no bitflip occured:
|
|
14234
|
+
* - in M between the computation of `r` and `h`.
|
|
14235
|
+
* - in the public key before computing `h`
|
|
14236
|
+
* 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.
|
|
14237
|
+
*/
|
|
14238
|
+
throw new Error('Transient signing failure');
|
|
14239
|
+
}
|
|
14213
14240
|
// EdDSA signature params are returned in little-endian format
|
|
14214
14241
|
return {
|
|
14215
14242
|
r: signature.subarray(0, 32),
|
|
@@ -14230,6 +14257,9 @@ async function sign$2(oid, hashAlgo, message, publicKey, privateKey, hashed) {
|
|
|
14230
14257
|
* @async
|
|
14231
14258
|
*/
|
|
14232
14259
|
async function verify$2(oid, hashAlgo, { r, s }, m, publicKey, hashed) {
|
|
14260
|
+
if (hash.getHashByteLength(hashAlgo) < hash.getHashByteLength(enums.hash.sha256)) {
|
|
14261
|
+
throw new Error('Hash algorithm too weak for EdDSA.');
|
|
14262
|
+
}
|
|
14233
14263
|
const signature = util.concatUint8Array([r, s]);
|
|
14234
14264
|
return naclFastLight.sign.detached.verify(hashed, signature, publicKey.subarray(1));
|
|
14235
14265
|
}
|
|
@@ -14299,14 +14329,27 @@ async function generate$2(algo) {
|
|
|
14299
14329
|
* @async
|
|
14300
14330
|
*/
|
|
14301
14331
|
async function sign$3(algo, hashAlgo, message, publicKey, privateKey, hashed) {
|
|
14302
|
-
if (hash.getHashByteLength(hashAlgo) < hash.getHashByteLength(
|
|
14303
|
-
|
|
14304
|
-
throw new Error('Hash algorithm too weak: sha256 or stronger is required for EdDSA.');
|
|
14332
|
+
if (hash.getHashByteLength(hashAlgo) < hash.getHashByteLength(getPreferredHashAlgo$1(algo))) {
|
|
14333
|
+
throw new Error('Hash algorithm too weak for EdDSA.');
|
|
14305
14334
|
}
|
|
14306
14335
|
switch (algo) {
|
|
14307
14336
|
case enums.publicKey.ed25519: {
|
|
14308
14337
|
const secretKey = util.concatUint8Array([privateKey, publicKey]);
|
|
14309
14338
|
const signature = naclFastLight.sign.detached(hashed, secretKey);
|
|
14339
|
+
if (config.checkEdDSAFaultySignatures && !naclFastLight.sign.detached.verify(hashed, signature, publicKey)) {
|
|
14340
|
+
/**
|
|
14341
|
+
* Detect faulty signatures caused by random bitflips during `crypto_sign` which could lead to private key extraction
|
|
14342
|
+
* if two signatures over the same message are obtained.
|
|
14343
|
+
* See https://github.com/jedisct1/libsodium/issues/170.
|
|
14344
|
+
* If the input data is not deterministic, e.g. thanks to the random salt in v6 OpenPGP signatures (not yet implemented),
|
|
14345
|
+
* then the generated signature is always safe, and the verification step is skipped.
|
|
14346
|
+
* Otherwise, we need to verify the generated to ensure that no bitflip occured:
|
|
14347
|
+
* - in M between the computation of `r` and `h`.
|
|
14348
|
+
* - in the public key before computing `h`
|
|
14349
|
+
* 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.
|
|
14350
|
+
*/
|
|
14351
|
+
throw new Error('Transient signing failure');
|
|
14352
|
+
}
|
|
14310
14353
|
return { RS: signature };
|
|
14311
14354
|
}
|
|
14312
14355
|
case enums.publicKey.ed448:
|
|
@@ -14328,6 +14371,9 @@ async function sign$3(algo, hashAlgo, message, publicKey, privateKey, hashed) {
|
|
|
14328
14371
|
* @async
|
|
14329
14372
|
*/
|
|
14330
14373
|
async function verify$3(algo, hashAlgo, { RS }, m, publicKey, hashed) {
|
|
14374
|
+
if (hash.getHashByteLength(hashAlgo) < hash.getHashByteLength(getPreferredHashAlgo$1(algo))) {
|
|
14375
|
+
throw new Error('Hash algorithm too weak for EdDSA.');
|
|
14376
|
+
}
|
|
14331
14377
|
switch (algo) {
|
|
14332
14378
|
case enums.publicKey.ed25519: {
|
|
14333
14379
|
return naclFastLight.sign.detached.verify(hashed, RS, publicKey);
|
|
@@ -14363,12 +14409,22 @@ async function validateParams$4(algo, A, seed) {
|
|
|
14363
14409
|
}
|
|
14364
14410
|
}
|
|
14365
14411
|
|
|
14412
|
+
function getPreferredHashAlgo$1(algo) {
|
|
14413
|
+
switch (algo) {
|
|
14414
|
+
case enums.publicKey.ed25519:
|
|
14415
|
+
return enums.hash.sha256;
|
|
14416
|
+
default:
|
|
14417
|
+
throw new Error('Unknown EdDSA algo');
|
|
14418
|
+
}
|
|
14419
|
+
}
|
|
14420
|
+
|
|
14366
14421
|
var eddsa = /*#__PURE__*/Object.freeze({
|
|
14367
14422
|
__proto__: null,
|
|
14368
14423
|
generate: generate$2,
|
|
14369
14424
|
sign: sign$3,
|
|
14370
14425
|
verify: verify$3,
|
|
14371
|
-
validateParams: validateParams$4
|
|
14426
|
+
validateParams: validateParams$4,
|
|
14427
|
+
getPreferredHashAlgo: getPreferredHashAlgo$1
|
|
14372
14428
|
});
|
|
14373
14429
|
|
|
14374
14430
|
// OpenPGP.js - An OpenPGP implementation in javascript
|
|
@@ -14982,8 +15038,6 @@ async function generate$3(algo) {
|
|
|
14982
15038
|
case enums.publicKey.x25519: {
|
|
14983
15039
|
// k stays in little-endian, unlike legacy ECDH over curve25519
|
|
14984
15040
|
const k = getRandomBytes(32);
|
|
14985
|
-
k[0] &= 248;
|
|
14986
|
-
k[31] = (k[31] & 127) | 64;
|
|
14987
15041
|
const { publicKey: A } = naclFastLight.box.keyPair.fromSecretKey(k);
|
|
14988
15042
|
return { A, k };
|
|
14989
15043
|
}
|
|
@@ -15418,8 +15472,7 @@ function parseSignatureParams(algo, signature) {
|
|
|
15418
15472
|
// Algorithm-Specific Fields for legacy EdDSA signatures:
|
|
15419
15473
|
// - MPI of an EC point r.
|
|
15420
15474
|
// - EdDSA value s, in MPI, in the little endian representation
|
|
15421
|
-
case enums.publicKey.
|
|
15422
|
-
case enums.publicKey.ed25519Legacy: {
|
|
15475
|
+
case enums.publicKey.eddsaLegacy: {
|
|
15423
15476
|
// When parsing little-endian MPI data, we always need to left-pad it, as done with big-endian values:
|
|
15424
15477
|
// https://www.ietf.org/archive/id/draft-ietf-openpgp-rfc4880bis-10.html#section-3.2-9
|
|
15425
15478
|
let r = util.readMPI(signature.subarray(read)); read += r.length + 2;
|
|
@@ -15480,8 +15533,7 @@ async function verify$5(algo, hashAlgo, signature, publicParams, privateParams,
|
|
|
15480
15533
|
const s = util.leftPad(signature.s, curveSize);
|
|
15481
15534
|
return publicKey.elliptic.ecdsa.verify(oid, hashAlgo, { r, s }, data, Q, hashed);
|
|
15482
15535
|
}
|
|
15483
|
-
case enums.publicKey.
|
|
15484
|
-
case enums.publicKey.ed25519Legacy: {
|
|
15536
|
+
case enums.publicKey.eddsaLegacy: {
|
|
15485
15537
|
const { oid, Q } = publicParams;
|
|
15486
15538
|
// signature already padded on parsing
|
|
15487
15539
|
return publicKey.elliptic.eddsaLegacy.verify(oid, hashAlgo, signature, data, Q, hashed);
|
|
@@ -15544,8 +15596,7 @@ async function sign$5(algo, hashAlgo, publicKeyParams, privateKeyParams, data, h
|
|
|
15544
15596
|
const { d } = privateKeyParams;
|
|
15545
15597
|
return publicKey.elliptic.ecdsa.sign(oid, hashAlgo, data, Q, d, hashed);
|
|
15546
15598
|
}
|
|
15547
|
-
case enums.publicKey.
|
|
15548
|
-
case enums.publicKey.ed25519Legacy: {
|
|
15599
|
+
case enums.publicKey.eddsaLegacy: {
|
|
15549
15600
|
const { oid, Q } = publicKeyParams;
|
|
15550
15601
|
const { seed } = privateKeyParams;
|
|
15551
15602
|
return publicKey.elliptic.eddsaLegacy.sign(oid, hashAlgo, data, Q, seed, hashed);
|
|
@@ -15936,8 +15987,7 @@ function parsePublicKeyParams(algo, bytes) {
|
|
|
15936
15987
|
const Q = util.readMPI(bytes.subarray(read)); read += Q.length + 2;
|
|
15937
15988
|
return { read: read, publicParams: { oid, Q } };
|
|
15938
15989
|
}
|
|
15939
|
-
case enums.publicKey.
|
|
15940
|
-
case enums.publicKey.ed25519Legacy: {
|
|
15990
|
+
case enums.publicKey.eddsaLegacy: {
|
|
15941
15991
|
const oid = new OID(); read += oid.read(bytes);
|
|
15942
15992
|
checkSupportedCurve(oid);
|
|
15943
15993
|
let Q = util.readMPI(bytes.subarray(read)); read += Q.length + 2;
|
|
@@ -15999,8 +16049,7 @@ function parsePrivateKeyParams(algo, bytes, publicParams) {
|
|
|
15999
16049
|
d = util.leftPad(d, curve.payloadSize);
|
|
16000
16050
|
return { read, privateParams: { d } };
|
|
16001
16051
|
}
|
|
16002
|
-
case enums.publicKey.
|
|
16003
|
-
case enums.publicKey.ed25519Legacy: {
|
|
16052
|
+
case enums.publicKey.eddsaLegacy: {
|
|
16004
16053
|
const curve = new CurveWithOID(publicParams.oid);
|
|
16005
16054
|
let seed = util.readMPI(bytes.subarray(read)); read += seed.length + 2;
|
|
16006
16055
|
seed = util.leftPad(seed, curve.payloadSize);
|
|
@@ -16135,8 +16184,7 @@ function generateParams(algo, bits, oid, symmetric) {
|
|
|
16135
16184
|
privateParams: { d: secret },
|
|
16136
16185
|
publicParams: { oid: new OID(oid), Q }
|
|
16137
16186
|
}));
|
|
16138
|
-
case enums.publicKey.
|
|
16139
|
-
case enums.publicKey.ed25519Legacy:
|
|
16187
|
+
case enums.publicKey.eddsaLegacy:
|
|
16140
16188
|
return publicKey.elliptic.generate(oid).then(({ oid, Q, secret }) => ({
|
|
16141
16189
|
privateParams: { seed: secret },
|
|
16142
16190
|
publicParams: { oid: new OID(oid), Q }
|
|
@@ -16230,8 +16278,7 @@ async function validateParams$8(algo, publicParams, privateParams) {
|
|
|
16230
16278
|
const { d } = privateParams;
|
|
16231
16279
|
return algoModule.validateParams(oid, Q, d);
|
|
16232
16280
|
}
|
|
16233
|
-
case enums.publicKey.
|
|
16234
|
-
case enums.publicKey.ed25519Legacy: {
|
|
16281
|
+
case enums.publicKey.eddsaLegacy: {
|
|
16235
16282
|
const { Q, oid } = publicParams;
|
|
16236
16283
|
const { seed } = privateParams;
|
|
16237
16284
|
return publicKey.elliptic.eddsaLegacy.validateParams(oid, Q, seed);
|
|
@@ -16314,6 +16361,23 @@ function checkSupportedCurve(oid) {
|
|
|
16314
16361
|
}
|
|
16315
16362
|
}
|
|
16316
16363
|
|
|
16364
|
+
/**
|
|
16365
|
+
* Get preferred hash algo for a given elliptic algo
|
|
16366
|
+
* @param {module:enums.publicKey} algo - alrogithm identifier
|
|
16367
|
+
* @param {module:type/oid} [oid] - curve OID if needed by algo
|
|
16368
|
+
*/
|
|
16369
|
+
function getPreferredCurveHashAlgo(algo, oid) {
|
|
16370
|
+
switch (algo) {
|
|
16371
|
+
case enums.publicKey.ecdsa:
|
|
16372
|
+
case enums.publicKey.eddsaLegacy:
|
|
16373
|
+
return publicKey.elliptic.getPreferredHashAlgo(oid);
|
|
16374
|
+
case enums.publicKey.ed25519:
|
|
16375
|
+
return publicKey.elliptic.eddsa.getPreferredHashAlgo(algo);
|
|
16376
|
+
default:
|
|
16377
|
+
throw new Error('Unknown elliptic signing algo');
|
|
16378
|
+
}
|
|
16379
|
+
}
|
|
16380
|
+
|
|
16317
16381
|
var crypto$1 = /*#__PURE__*/Object.freeze({
|
|
16318
16382
|
__proto__: null,
|
|
16319
16383
|
publicKeyEncrypt: publicKeyEncrypt,
|
|
@@ -16327,7 +16391,8 @@ var crypto$1 = /*#__PURE__*/Object.freeze({
|
|
|
16327
16391
|
getPrefixRandom: getPrefixRandom,
|
|
16328
16392
|
generateSessionKey: generateSessionKey,
|
|
16329
16393
|
getAEADMode: getAEADMode,
|
|
16330
|
-
getCipher: getCipher
|
|
16394
|
+
getCipher: getCipher,
|
|
16395
|
+
getPreferredCurveHashAlgo: getPreferredCurveHashAlgo
|
|
16331
16396
|
});
|
|
16332
16397
|
|
|
16333
16398
|
/**
|
|
@@ -28085,25 +28150,22 @@ async function createBindingSignature(subkey, primaryKey, options, config) {
|
|
|
28085
28150
|
const dataToSign = {};
|
|
28086
28151
|
dataToSign.key = primaryKey;
|
|
28087
28152
|
dataToSign.bind = subkey;
|
|
28088
|
-
const
|
|
28089
|
-
subkeySignaturePacket.signatureType = enums.signature.subkeyBinding;
|
|
28090
|
-
subkeySignaturePacket.publicKeyAlgorithm = primaryKey.algorithm;
|
|
28091
|
-
subkeySignaturePacket.hashAlgorithm = await getPreferredHashAlgo$1(null, subkey, undefined, undefined, config);
|
|
28153
|
+
const signatureProperties = { signatureType: enums.signature.subkeyBinding };
|
|
28092
28154
|
if (options.sign) {
|
|
28093
|
-
|
|
28094
|
-
|
|
28155
|
+
signatureProperties.keyFlags = [enums.keyFlags.signData];
|
|
28156
|
+
signatureProperties.embeddedSignature = await createSignaturePacket(dataToSign, null, subkey, {
|
|
28095
28157
|
signatureType: enums.signature.keyBinding
|
|
28096
28158
|
}, options.date, undefined, undefined, undefined, config);
|
|
28097
28159
|
} else {
|
|
28098
|
-
|
|
28160
|
+
signatureProperties.keyFlags = options.forwarding ?
|
|
28099
28161
|
[enums.keyFlags.forwardedCommunication] :
|
|
28100
28162
|
[enums.keyFlags.encryptCommunication | enums.keyFlags.encryptStorage];
|
|
28101
28163
|
}
|
|
28102
28164
|
if (options.keyExpirationTime > 0) {
|
|
28103
|
-
|
|
28104
|
-
|
|
28165
|
+
signatureProperties.keyExpirationTime = options.keyExpirationTime;
|
|
28166
|
+
signatureProperties.keyNeverExpires = false;
|
|
28105
28167
|
}
|
|
28106
|
-
await
|
|
28168
|
+
const subkeySignaturePacket = await createSignaturePacket(dataToSign, null, primaryKey, signatureProperties, options.date, undefined, undefined, undefined, config);
|
|
28107
28169
|
return subkeySignaturePacket;
|
|
28108
28170
|
}
|
|
28109
28171
|
|
|
@@ -28117,7 +28179,7 @@ async function createBindingSignature(subkey, primaryKey, options, config) {
|
|
|
28117
28179
|
* @returns {Promise<enums.hash>}
|
|
28118
28180
|
* @async
|
|
28119
28181
|
*/
|
|
28120
|
-
async function getPreferredHashAlgo$
|
|
28182
|
+
async function getPreferredHashAlgo$2(key, keyPacket, date = new Date(), userID = {}, config) {
|
|
28121
28183
|
let hashAlgo = config.preferredHashAlgorithm;
|
|
28122
28184
|
let prefAlgo = hashAlgo;
|
|
28123
28185
|
if (key) {
|
|
@@ -28128,17 +28190,11 @@ async function getPreferredHashAlgo$1(key, keyPacket, date = new Date(), userID
|
|
|
28128
28190
|
prefAlgo : hashAlgo;
|
|
28129
28191
|
}
|
|
28130
28192
|
}
|
|
28131
|
-
switch (
|
|
28132
|
-
case
|
|
28133
|
-
case
|
|
28134
|
-
case
|
|
28135
|
-
|
|
28136
|
-
switch (keyPacket.algorithm) {
|
|
28137
|
-
case enums.publicKey.ecdh:
|
|
28138
|
-
case enums.publicKey.ecdsa:
|
|
28139
|
-
case enums.publicKey.eddsa:
|
|
28140
|
-
prefAlgo = mod.publicKey.elliptic.getPreferredHashAlgo(keyPacket.publicParams.oid);
|
|
28141
|
-
}
|
|
28193
|
+
switch (keyPacket.algorithm) {
|
|
28194
|
+
case enums.publicKey.ecdsa:
|
|
28195
|
+
case enums.publicKey.eddsaLegacy:
|
|
28196
|
+
case enums.publicKey.ed25519:
|
|
28197
|
+
prefAlgo = mod.getPreferredCurveHashAlgo(keyPacket.algorithm, keyPacket.publicParams.oid);
|
|
28142
28198
|
}
|
|
28143
28199
|
return mod.hash.getHashByteLength(hashAlgo) <= mod.hash.getHashByteLength(prefAlgo) ?
|
|
28144
28200
|
prefAlgo : hashAlgo;
|
|
@@ -28206,7 +28262,7 @@ async function createSignaturePacket(dataToSign, privateKey, signingKeyPacket, s
|
|
|
28206
28262
|
const signaturePacket = new SignaturePacket();
|
|
28207
28263
|
Object.assign(signaturePacket, signatureProperties);
|
|
28208
28264
|
signaturePacket.publicKeyAlgorithm = signingKeyPacket.algorithm;
|
|
28209
|
-
signaturePacket.hashAlgorithm = await getPreferredHashAlgo$
|
|
28265
|
+
signaturePacket.hashAlgorithm = await getPreferredHashAlgo$2(privateKey, signingKeyPacket, date, userID, config);
|
|
28210
28266
|
signaturePacket.rawNotations = notations;
|
|
28211
28267
|
await signaturePacket.sign(signingKeyPacket, dataToSign, date, detached);
|
|
28212
28268
|
return signaturePacket;
|
|
@@ -28347,11 +28403,11 @@ function sanitizeKeyOptions(options, subkeyDefaults = {}) {
|
|
|
28347
28403
|
} catch (e) {
|
|
28348
28404
|
throw new Error('Unknown curve');
|
|
28349
28405
|
}
|
|
28350
|
-
if (options.curve === enums.curve.
|
|
28351
|
-
options.curve = options.sign ? enums.curve.
|
|
28406
|
+
if (options.curve === enums.curve.ed25519Legacy || options.curve === enums.curve.curve25519Legacy) {
|
|
28407
|
+
options.curve = options.sign ? enums.curve.ed25519Legacy : enums.curve.curve25519Legacy;
|
|
28352
28408
|
}
|
|
28353
28409
|
if (options.sign) {
|
|
28354
|
-
options.algorithm = options.curve === enums.curve.
|
|
28410
|
+
options.algorithm = options.curve === enums.curve.ed25519Legacy ? enums.publicKey.eddsaLegacy : enums.publicKey.ecdsa;
|
|
28355
28411
|
} else {
|
|
28356
28412
|
options.algorithm = enums.publicKey.ecdh;
|
|
28357
28413
|
}
|
|
@@ -28389,7 +28445,7 @@ function isValidEncryptionKeyPacket(keyPacket, signature) {
|
|
|
28389
28445
|
return keyAlgo !== enums.publicKey.dsa &&
|
|
28390
28446
|
keyAlgo !== enums.publicKey.rsaSign &&
|
|
28391
28447
|
keyAlgo !== enums.publicKey.ecdsa &&
|
|
28392
|
-
keyAlgo !== enums.publicKey.
|
|
28448
|
+
keyAlgo !== enums.publicKey.eddsaLegacy &&
|
|
28393
28449
|
keyAlgo !== enums.publicKey.ed25519 &&
|
|
28394
28450
|
(!signature.keyFlags ||
|
|
28395
28451
|
(signature.keyFlags[0] & enums.keyFlags.encryptCommunication) !== 0 ||
|
|
@@ -28435,7 +28491,7 @@ function checkKeyRequirements(keyPacket, config) {
|
|
|
28435
28491
|
}
|
|
28436
28492
|
break;
|
|
28437
28493
|
case enums.publicKey.ecdsa:
|
|
28438
|
-
case enums.publicKey.
|
|
28494
|
+
case enums.publicKey.eddsaLegacy:
|
|
28439
28495
|
case enums.publicKey.ecdh:
|
|
28440
28496
|
if (config.rejectCurves.has(algoInfo.curve)) {
|
|
28441
28497
|
throw new Error(`Support for ${algoInfo.algorithm} keys using curve ${algoInfo.curve} is disabled.`);
|
|
@@ -30062,50 +30118,50 @@ async function wrapKeyObject(secretKeyPacket, secretSubkeyPackets, options, conf
|
|
|
30062
30118
|
const dataToSign = {};
|
|
30063
30119
|
dataToSign.userID = userIDPacket;
|
|
30064
30120
|
dataToSign.key = secretKeyPacket;
|
|
30065
|
-
|
|
30066
|
-
|
|
30067
|
-
|
|
30068
|
-
|
|
30069
|
-
|
|
30070
|
-
signaturePacket.preferredSymmetricAlgorithms = createPreferredAlgos([
|
|
30121
|
+
|
|
30122
|
+
const signatureProperties = {};
|
|
30123
|
+
signatureProperties.signatureType = enums.signature.certGeneric;
|
|
30124
|
+
signatureProperties.keyFlags = [enums.keyFlags.certifyKeys | enums.keyFlags.signData];
|
|
30125
|
+
signatureProperties.preferredSymmetricAlgorithms = createPreferredAlgos([
|
|
30071
30126
|
// prefer aes256, aes128, then aes192 (no WebCrypto support: https://www.chromium.org/blink/webcrypto#TOC-AES-support)
|
|
30072
30127
|
enums.symmetric.aes256,
|
|
30073
30128
|
enums.symmetric.aes128,
|
|
30074
30129
|
enums.symmetric.aes192
|
|
30075
30130
|
], config.preferredSymmetricAlgorithm);
|
|
30076
30131
|
if (config.aeadProtect) {
|
|
30077
|
-
|
|
30132
|
+
signatureProperties.preferredAEADAlgorithms = createPreferredAlgos([
|
|
30078
30133
|
enums.aead.eax,
|
|
30079
30134
|
enums.aead.ocb
|
|
30080
30135
|
], config.preferredAEADAlgorithm);
|
|
30081
30136
|
}
|
|
30082
|
-
|
|
30137
|
+
signatureProperties.preferredHashAlgorithms = createPreferredAlgos([
|
|
30083
30138
|
// prefer fast asm.js implementations (SHA-256)
|
|
30084
30139
|
enums.hash.sha256,
|
|
30085
30140
|
enums.hash.sha512
|
|
30086
30141
|
], config.preferredHashAlgorithm);
|
|
30087
|
-
|
|
30142
|
+
signatureProperties.preferredCompressionAlgorithms = createPreferredAlgos([
|
|
30088
30143
|
enums.compression.zlib,
|
|
30089
30144
|
enums.compression.zip,
|
|
30090
30145
|
enums.compression.uncompressed
|
|
30091
30146
|
], config.preferredCompressionAlgorithm);
|
|
30092
30147
|
if (index === 0) {
|
|
30093
|
-
|
|
30148
|
+
signatureProperties.isPrimaryUserID = true;
|
|
30094
30149
|
}
|
|
30095
30150
|
// integrity protection always enabled
|
|
30096
|
-
|
|
30097
|
-
|
|
30151
|
+
signatureProperties.features = [0];
|
|
30152
|
+
signatureProperties.features[0] |= enums.features.modificationDetection;
|
|
30098
30153
|
if (config.aeadProtect) {
|
|
30099
|
-
|
|
30154
|
+
signatureProperties.features[0] |= enums.features.aead;
|
|
30100
30155
|
}
|
|
30101
30156
|
if (config.v5Keys) {
|
|
30102
|
-
|
|
30157
|
+
signatureProperties.features[0] |= enums.features.v5Keys;
|
|
30103
30158
|
}
|
|
30104
30159
|
if (options.keyExpirationTime > 0) {
|
|
30105
|
-
|
|
30106
|
-
|
|
30160
|
+
signatureProperties.keyExpirationTime = options.keyExpirationTime;
|
|
30161
|
+
signatureProperties.keyNeverExpires = false;
|
|
30107
30162
|
}
|
|
30108
|
-
|
|
30163
|
+
|
|
30164
|
+
const signaturePacket = await createSignaturePacket(dataToSign, null, secretKeyPacket, signatureProperties, options.date, undefined, undefined, undefined, config);
|
|
30109
30165
|
|
|
30110
30166
|
return { userIDPacket, signaturePacket };
|
|
30111
30167
|
})).then(list => {
|
|
@@ -30807,7 +30863,7 @@ class Message {
|
|
|
30807
30863
|
const signingKey = await primaryKey.getSigningKey(signingKeyID, date, userIDs, config$1);
|
|
30808
30864
|
const onePassSig = new OnePassSignaturePacket();
|
|
30809
30865
|
onePassSig.signatureType = signatureType;
|
|
30810
|
-
onePassSig.hashAlgorithm = await getPreferredHashAlgo$
|
|
30866
|
+
onePassSig.hashAlgorithm = await getPreferredHashAlgo$2(primaryKey, signingKey.keyPacket, date, userIDs, config$1);
|
|
30811
30867
|
onePassSig.publicKeyAlgorithm = signingKey.keyPacket.algorithm;
|
|
30812
30868
|
onePassSig.issuerKeyID = signingKey.getKeyID();
|
|
30813
30869
|
if (i === signingKeys.length - 1) {
|