@protontech/openpgp 5.10.2 → 5.11.1-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/openpgp.mjs CHANGED
@@ -1,4 +1,4 @@
1
- /*! OpenPGP.js v5.10.2 - 2023-09-18 - this is LGPL licensed code, see LICENSE/our website https://openpgpjs.org/ for more information. */
1
+ /*! OpenPGP.js v5.11.1-0 - 2024-02-14 - 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');
@@ -241,18 +241,17 @@ if (NodeReadableStream$1) {
241
241
  this.push(null);
242
242
  break;
243
243
  }
244
- if (!this.push(value) || this._cancelling) {
245
- this._reading = false;
244
+ if (!this.push(value)) {
246
245
  break;
247
246
  }
248
247
  }
249
- } catch(e) {
250
- this.emit('error', e);
248
+ } catch (e) {
249
+ this.destroy(e);
251
250
  }
252
251
  }
253
252
 
254
- _destroy(reason) {
255
- this._reader.cancel(reason);
253
+ async _destroy(error, callback) {
254
+ this._reader.cancel(error).then(callback, callback);
256
255
  }
257
256
  }
258
257
 
@@ -287,7 +286,7 @@ function Reader(input) {
287
286
  const reader = input.getReader();
288
287
  this._read = reader.read.bind(reader);
289
288
  this._releaseLock = () => {};
290
- this._cancel = () => {};
289
+ this._cancel = async () => {};
291
290
  return;
292
291
  }
293
292
  let streamType = isStream(input);
@@ -1552,17 +1551,21 @@ var enums = {
1552
1551
  '2b8104000a': 'secp256k1',
1553
1552
  '2B8104000A': 'secp256k1',
1554
1553
 
1555
- /** Ed25519 */
1554
+ /** Ed25519 - deprecated by crypto-refresh (replaced by standaone Ed25519 algo) */
1555
+ 'ed25519Legacy': 'ed25519',
1556
1556
  'ED25519': 'ed25519',
1557
+ /** @deprecated use `ed25519Legacy` instead */
1557
1558
  'ed25519': 'ed25519',
1558
1559
  'Ed25519': 'ed25519',
1559
1560
  '1.3.6.1.4.1.11591.15.1': 'ed25519',
1560
1561
  '2b06010401da470f01': 'ed25519',
1561
1562
  '2B06010401DA470F01': 'ed25519',
1562
1563
 
1563
- /** Curve25519 */
1564
+ /** Curve25519 - deprecated by crypto-refresh (replaced by standaone X25519 algo) */
1565
+ 'curve25519Legacy': 'curve25519',
1564
1566
  'X25519': 'curve25519',
1565
1567
  'cv25519': 'curve25519',
1568
+ /** @deprecated use `curve25519Legacy` instead */
1566
1569
  'curve25519': 'curve25519',
1567
1570
  'Curve25519': 'curve25519',
1568
1571
  '1.3.6.1.4.1.3029.1.5.1': 'curve25519',
@@ -1633,8 +1636,11 @@ var enums = {
1633
1636
  ecdsa: 19,
1634
1637
  /** EdDSA (Sign only) - deprecated by crypto-refresh (replaced by `ed25519` identifier below)
1635
1638
  * [{@link https://tools.ietf.org/html/draft-koch-eddsa-for-openpgp-04|Draft RFC}] */
1636
- ed25519Legacy: 22, // NB: this is declared before `eddsa` to translate 22 to 'eddsa' for backwards compatibility
1637
- eddsa: 22, // to be deprecated in v6
1639
+ eddsaLegacy: 22, // NB: this is declared before `eddsa` to translate 22 to 'eddsa' for backwards compatibility
1640
+ /** @deprecated use `eddsaLegacy` instead */
1641
+ ed25519Legacy: 22,
1642
+ /** @deprecated use `eddsaLegacy` instead */
1643
+ eddsa: 22,
1638
1644
  /** Reserved for AEDH */
1639
1645
  aedh: 23,
1640
1646
  /** Reserved for AEDSA */
@@ -2944,7 +2950,7 @@ var config = {
2944
2950
  * @memberof module:config
2945
2951
  * @property {String} versionString A version string to be included in armored messages
2946
2952
  */
2947
- versionString: 'OpenPGP.js 5.10.2',
2953
+ versionString: 'OpenPGP.js 5.11.1-0',
2948
2954
  /**
2949
2955
  * @memberof module:config
2950
2956
  * @property {String} commentString A comment string to be included in armored messages
@@ -2995,7 +3001,14 @@ var config = {
2995
3001
  * @memberof module:config
2996
3002
  * @property {Set<String>} rejectCurves {@link module:enums.curve}
2997
3003
  */
2998
- rejectCurves: new Set([enums.curve.secp256k1])
3004
+ rejectCurves: new Set([enums.curve.secp256k1]),
3005
+ /**
3006
+ * Whether to validate generated EdDSA signatures before returning them, to ensure they are not faulty signatures.
3007
+ * This check will make signing 2-3 times slower.
3008
+ * Faulty signatures may be generated (in principle) if random bitflips occur at specific points in the signature
3009
+ * computation, and could be used to recover the signer's secret key given a second signature over the same data.
3010
+ */
3011
+ checkEdDSAFaultySignatures: true
2999
3012
  };
3000
3013
 
3001
3014
  /**
@@ -10971,42 +10984,42 @@ async function GCM(cipher, key) {
10971
10984
  throw new Error('GCM mode supports only AES cipher');
10972
10985
  }
10973
10986
 
10974
- if (util.getWebCrypto() && key.length !== 24) { // WebCrypto (no 192 bit support) see: https://www.chromium.org/blink/webcrypto#TOC-AES-support
10975
- const _key = await webCrypto$4.importKey('raw', key, { name: ALGO }, false, ['encrypt', 'decrypt']);
10976
-
10987
+ if (util.getNodeCrypto()) { // Node crypto library
10977
10988
  return {
10978
10989
  encrypt: async function(pt, iv, adata = new Uint8Array()) {
10979
- if (!pt.length) { // iOS does not support GCM-en/decrypting empty messages
10980
- return AES_GCM.encrypt(pt, key, iv, adata);
10981
- }
10982
- const ct = await webCrypto$4.encrypt({ name: ALGO, iv, additionalData: adata, tagLength: tagLength$2 * 8 }, _key, pt);
10990
+ const en = new nodeCrypto$4.createCipheriv('aes-' + (key.length * 8) + '-gcm', key, iv);
10991
+ en.setAAD(adata);
10992
+ const ct = Buffer$2.concat([en.update(pt), en.final(), en.getAuthTag()]); // append auth tag to ciphertext
10983
10993
  return new Uint8Array(ct);
10984
10994
  },
10985
10995
 
10986
10996
  decrypt: async function(ct, iv, adata = new Uint8Array()) {
10987
- if (ct.length === tagLength$2) { // iOS does not support GCM-en/decrypting empty messages
10988
- return AES_GCM.decrypt(ct, key, iv, adata);
10989
- }
10990
- const pt = await webCrypto$4.decrypt({ name: ALGO, iv, additionalData: adata, tagLength: tagLength$2 * 8 }, _key, ct);
10997
+ const de = new nodeCrypto$4.createDecipheriv('aes-' + (key.length * 8) + '-gcm', key, iv);
10998
+ de.setAAD(adata);
10999
+ de.setAuthTag(ct.slice(ct.length - tagLength$2, ct.length)); // read auth tag at end of ciphertext
11000
+ const pt = Buffer$2.concat([de.update(ct.slice(0, ct.length - tagLength$2)), de.final()]);
10991
11001
  return new Uint8Array(pt);
10992
11002
  }
10993
11003
  };
10994
11004
  }
10995
11005
 
10996
- if (util.getNodeCrypto()) { // Node crypto library
11006
+ if (util.getWebCrypto() && key.length !== 24) { // WebCrypto (no 192 bit support) see: https://www.chromium.org/blink/webcrypto#TOC-AES-support
11007
+ const _key = await webCrypto$4.importKey('raw', key, { name: ALGO }, false, ['encrypt', 'decrypt']);
11008
+
10997
11009
  return {
10998
11010
  encrypt: async function(pt, iv, adata = new Uint8Array()) {
10999
- const en = new nodeCrypto$4.createCipheriv('aes-' + (key.length * 8) + '-gcm', key, iv);
11000
- en.setAAD(adata);
11001
- const ct = Buffer$2.concat([en.update(pt), en.final(), en.getAuthTag()]); // append auth tag to ciphertext
11011
+ if (!pt.length) { // iOS does not support GCM-en/decrypting empty messages
11012
+ return AES_GCM.encrypt(pt, key, iv, adata);
11013
+ }
11014
+ const ct = await webCrypto$4.encrypt({ name: ALGO, iv, additionalData: adata, tagLength: tagLength$2 * 8 }, _key, pt);
11002
11015
  return new Uint8Array(ct);
11003
11016
  },
11004
11017
 
11005
11018
  decrypt: async function(ct, iv, adata = new Uint8Array()) {
11006
- const de = new nodeCrypto$4.createDecipheriv('aes-' + (key.length * 8) + '-gcm', key, iv);
11007
- de.setAAD(adata);
11008
- de.setAuthTag(ct.slice(ct.length - tagLength$2, ct.length)); // read auth tag at end of ciphertext
11009
- const pt = Buffer$2.concat([de.update(ct.slice(0, ct.length - tagLength$2)), de.final()]);
11019
+ if (ct.length === tagLength$2) { // iOS does not support GCM-en/decrypting empty messages
11020
+ return AES_GCM.decrypt(ct, key, iv, adata);
11021
+ }
11022
+ const pt = await webCrypto$4.decrypt({ name: ALGO, iv, additionalData: adata, tagLength: tagLength$2 * 8 }, _key, ct);
11010
11023
  return new Uint8Array(pt);
11011
11024
  }
11012
11025
  };
@@ -12009,11 +12022,11 @@ const nodeCrypto$5 = util.getNodeCrypto();
12009
12022
  */
12010
12023
  function getRandomBytes(length) {
12011
12024
  const buf = new Uint8Array(length);
12012
- if (typeof crypto !== 'undefined' && crypto.getRandomValues) {
12013
- crypto.getRandomValues(buf);
12014
- } else if (nodeCrypto$5) {
12025
+ if (nodeCrypto$5) {
12015
12026
  const bytes = nodeCrypto$5.randomBytes(buf.length);
12016
12027
  buf.set(bytes);
12028
+ } else if (typeof crypto !== 'undefined' && crypto.getRandomValues) {
12029
+ crypto.getRandomValues(buf);
12017
12030
  } else {
12018
12031
  throw new Error('No secure random number generator available.');
12019
12032
  }
@@ -13575,7 +13588,7 @@ const curves = {
13575
13588
  },
13576
13589
  ed25519: {
13577
13590
  oid: [0x06, 0x09, 0x2B, 0x06, 0x01, 0x04, 0x01, 0xDA, 0x47, 0x0F, 0x01],
13578
- keyType: enums.publicKey.eddsa,
13591
+ keyType: enums.publicKey.eddsaLegacy,
13579
13592
  hash: enums.hash.sha512,
13580
13593
  node: false, // nodeCurves.ed25519 TODO
13581
13594
  payloadSize: 32
@@ -14180,10 +14193,24 @@ naclFastLight.hash = bytes => new Uint8Array(_512().update(bytes).digest());
14180
14193
  async function sign$2(oid, hashAlgo, message, publicKey, privateKey, hashed) {
14181
14194
  if (hash.getHashByteLength(hashAlgo) < hash.getHashByteLength(enums.hash.sha256)) {
14182
14195
  // see https://tools.ietf.org/id/draft-ietf-openpgp-rfc4880bis-10.html#section-15-7.2
14183
- throw new Error('Hash algorithm too weak: sha256 or stronger is required for EdDSA.');
14196
+ throw new Error('Hash algorithm too weak for EdDSA.');
14184
14197
  }
14185
14198
  const secretKey = util.concatUint8Array([privateKey, publicKey.subarray(1)]);
14186
14199
  const signature = naclFastLight.sign.detached(hashed, secretKey);
14200
+ if (config.checkEdDSAFaultySignatures && !naclFastLight.sign.detached.verify(hashed, signature, publicKey.subarray(1))) {
14201
+ /**
14202
+ * Detect faulty signatures caused by random bitflips during `crypto_sign` which could lead to private key extraction
14203
+ * if two signatures over the same message are obtained.
14204
+ * See https://github.com/jedisct1/libsodium/issues/170.
14205
+ * If the input data is not deterministic, e.g. thanks to the random salt in v6 OpenPGP signatures (not yet implemented),
14206
+ * then the generated signature is always safe, and the verification step is skipped.
14207
+ * Otherwise, we need to verify the generated to ensure that no bitflip occured:
14208
+ * - in M between the computation of `r` and `h`.
14209
+ * - in the public key before computing `h`
14210
+ * 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.
14211
+ */
14212
+ throw new Error('Transient signing failure');
14213
+ }
14187
14214
  // EdDSA signature params are returned in little-endian format
14188
14215
  return {
14189
14216
  r: signature.subarray(0, 32),
@@ -14204,6 +14231,9 @@ async function sign$2(oid, hashAlgo, message, publicKey, privateKey, hashed) {
14204
14231
  * @async
14205
14232
  */
14206
14233
  async function verify$2(oid, hashAlgo, { r, s }, m, publicKey, hashed) {
14234
+ if (hash.getHashByteLength(hashAlgo) < hash.getHashByteLength(enums.hash.sha256)) {
14235
+ throw new Error('Hash algorithm too weak for EdDSA.');
14236
+ }
14207
14237
  const signature = util.concatUint8Array([r, s]);
14208
14238
  return naclFastLight.sign.detached.verify(hashed, signature, publicKey.subarray(1));
14209
14239
  }
@@ -14273,14 +14303,27 @@ async function generate$2(algo) {
14273
14303
  * @async
14274
14304
  */
14275
14305
  async function sign$3(algo, hashAlgo, message, publicKey, privateKey, hashed) {
14276
- if (hash.getHashByteLength(hashAlgo) < hash.getHashByteLength(enums.hash.sha256)) {
14277
- // see https://tools.ietf.org/id/draft-ietf-openpgp-rfc4880bis-10.html#section-15-7.2
14278
- throw new Error('Hash algorithm too weak: sha256 or stronger is required for EdDSA.');
14306
+ if (hash.getHashByteLength(hashAlgo) < hash.getHashByteLength(getPreferredHashAlgo$1(algo))) {
14307
+ throw new Error('Hash algorithm too weak for EdDSA.');
14279
14308
  }
14280
14309
  switch (algo) {
14281
14310
  case enums.publicKey.ed25519: {
14282
14311
  const secretKey = util.concatUint8Array([privateKey, publicKey]);
14283
14312
  const signature = naclFastLight.sign.detached(hashed, secretKey);
14313
+ if (config.checkEdDSAFaultySignatures && !naclFastLight.sign.detached.verify(hashed, signature, publicKey)) {
14314
+ /**
14315
+ * Detect faulty signatures caused by random bitflips during `crypto_sign` which could lead to private key extraction
14316
+ * if two signatures over the same message are obtained.
14317
+ * See https://github.com/jedisct1/libsodium/issues/170.
14318
+ * If the input data is not deterministic, e.g. thanks to the random salt in v6 OpenPGP signatures (not yet implemented),
14319
+ * then the generated signature is always safe, and the verification step is skipped.
14320
+ * Otherwise, we need to verify the generated to ensure that no bitflip occured:
14321
+ * - in M between the computation of `r` and `h`.
14322
+ * - in the public key before computing `h`
14323
+ * 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.
14324
+ */
14325
+ throw new Error('Transient signing failure');
14326
+ }
14284
14327
  return { RS: signature };
14285
14328
  }
14286
14329
  case enums.publicKey.ed448:
@@ -14302,6 +14345,9 @@ async function sign$3(algo, hashAlgo, message, publicKey, privateKey, hashed) {
14302
14345
  * @async
14303
14346
  */
14304
14347
  async function verify$3(algo, hashAlgo, { RS }, m, publicKey, hashed) {
14348
+ if (hash.getHashByteLength(hashAlgo) < hash.getHashByteLength(getPreferredHashAlgo$1(algo))) {
14349
+ throw new Error('Hash algorithm too weak for EdDSA.');
14350
+ }
14305
14351
  switch (algo) {
14306
14352
  case enums.publicKey.ed25519: {
14307
14353
  return naclFastLight.sign.detached.verify(hashed, RS, publicKey);
@@ -14337,12 +14383,22 @@ async function validateParams$4(algo, A, seed) {
14337
14383
  }
14338
14384
  }
14339
14385
 
14386
+ function getPreferredHashAlgo$1(algo) {
14387
+ switch (algo) {
14388
+ case enums.publicKey.ed25519:
14389
+ return enums.hash.sha256;
14390
+ default:
14391
+ throw new Error('Unknown EdDSA algo');
14392
+ }
14393
+ }
14394
+
14340
14395
  var eddsa = /*#__PURE__*/Object.freeze({
14341
14396
  __proto__: null,
14342
14397
  generate: generate$2,
14343
14398
  sign: sign$3,
14344
14399
  verify: verify$3,
14345
- validateParams: validateParams$4
14400
+ validateParams: validateParams$4,
14401
+ getPreferredHashAlgo: getPreferredHashAlgo$1
14346
14402
  });
14347
14403
 
14348
14404
  // OpenPGP.js - An OpenPGP implementation in javascript
@@ -14956,8 +15012,6 @@ async function generate$3(algo) {
14956
15012
  case enums.publicKey.x25519: {
14957
15013
  // k stays in little-endian, unlike legacy ECDH over curve25519
14958
15014
  const k = getRandomBytes(32);
14959
- k[0] &= 248;
14960
- k[31] = (k[31] & 127) | 64;
14961
15015
  const { publicKey: A } = naclFastLight.box.keyPair.fromSecretKey(k);
14962
15016
  return { A, k };
14963
15017
  }
@@ -15392,8 +15446,7 @@ function parseSignatureParams(algo, signature) {
15392
15446
  // Algorithm-Specific Fields for legacy EdDSA signatures:
15393
15447
  // - MPI of an EC point r.
15394
15448
  // - EdDSA value s, in MPI, in the little endian representation
15395
- case enums.publicKey.eddsa:
15396
- case enums.publicKey.ed25519Legacy: {
15449
+ case enums.publicKey.eddsaLegacy: {
15397
15450
  // When parsing little-endian MPI data, we always need to left-pad it, as done with big-endian values:
15398
15451
  // https://www.ietf.org/archive/id/draft-ietf-openpgp-rfc4880bis-10.html#section-3.2-9
15399
15452
  let r = util.readMPI(signature.subarray(read)); read += r.length + 2;
@@ -15454,8 +15507,7 @@ async function verify$5(algo, hashAlgo, signature, publicParams, privateParams,
15454
15507
  const s = util.leftPad(signature.s, curveSize);
15455
15508
  return publicKey.elliptic.ecdsa.verify(oid, hashAlgo, { r, s }, data, Q, hashed);
15456
15509
  }
15457
- case enums.publicKey.eddsa:
15458
- case enums.publicKey.ed25519Legacy: {
15510
+ case enums.publicKey.eddsaLegacy: {
15459
15511
  const { oid, Q } = publicParams;
15460
15512
  // signature already padded on parsing
15461
15513
  return publicKey.elliptic.eddsaLegacy.verify(oid, hashAlgo, signature, data, Q, hashed);
@@ -15518,8 +15570,7 @@ async function sign$5(algo, hashAlgo, publicKeyParams, privateKeyParams, data, h
15518
15570
  const { d } = privateKeyParams;
15519
15571
  return publicKey.elliptic.ecdsa.sign(oid, hashAlgo, data, Q, d, hashed);
15520
15572
  }
15521
- case enums.publicKey.eddsa:
15522
- case enums.publicKey.ed25519Legacy: {
15573
+ case enums.publicKey.eddsaLegacy: {
15523
15574
  const { oid, Q } = publicKeyParams;
15524
15575
  const { seed } = privateKeyParams;
15525
15576
  return publicKey.elliptic.eddsaLegacy.sign(oid, hashAlgo, data, Q, seed, hashed);
@@ -15910,8 +15961,7 @@ function parsePublicKeyParams(algo, bytes) {
15910
15961
  const Q = util.readMPI(bytes.subarray(read)); read += Q.length + 2;
15911
15962
  return { read: read, publicParams: { oid, Q } };
15912
15963
  }
15913
- case enums.publicKey.eddsa:
15914
- case enums.publicKey.ed25519Legacy: {
15964
+ case enums.publicKey.eddsaLegacy: {
15915
15965
  const oid = new OID(); read += oid.read(bytes);
15916
15966
  checkSupportedCurve(oid);
15917
15967
  let Q = util.readMPI(bytes.subarray(read)); read += Q.length + 2;
@@ -15973,8 +16023,7 @@ function parsePrivateKeyParams(algo, bytes, publicParams) {
15973
16023
  d = util.leftPad(d, curve.payloadSize);
15974
16024
  return { read, privateParams: { d } };
15975
16025
  }
15976
- case enums.publicKey.eddsa:
15977
- case enums.publicKey.ed25519Legacy: {
16026
+ case enums.publicKey.eddsaLegacy: {
15978
16027
  const curve = new CurveWithOID(publicParams.oid);
15979
16028
  let seed = util.readMPI(bytes.subarray(read)); read += seed.length + 2;
15980
16029
  seed = util.leftPad(seed, curve.payloadSize);
@@ -16109,8 +16158,7 @@ function generateParams(algo, bits, oid, symmetric) {
16109
16158
  privateParams: { d: secret },
16110
16159
  publicParams: { oid: new OID(oid), Q }
16111
16160
  }));
16112
- case enums.publicKey.eddsa:
16113
- case enums.publicKey.ed25519Legacy:
16161
+ case enums.publicKey.eddsaLegacy:
16114
16162
  return publicKey.elliptic.generate(oid).then(({ oid, Q, secret }) => ({
16115
16163
  privateParams: { seed: secret },
16116
16164
  publicParams: { oid: new OID(oid), Q }
@@ -16204,8 +16252,7 @@ async function validateParams$8(algo, publicParams, privateParams) {
16204
16252
  const { d } = privateParams;
16205
16253
  return algoModule.validateParams(oid, Q, d);
16206
16254
  }
16207
- case enums.publicKey.eddsa:
16208
- case enums.publicKey.ed25519Legacy: {
16255
+ case enums.publicKey.eddsaLegacy: {
16209
16256
  const { Q, oid } = publicParams;
16210
16257
  const { seed } = privateParams;
16211
16258
  return publicKey.elliptic.eddsaLegacy.validateParams(oid, Q, seed);
@@ -16288,6 +16335,23 @@ function checkSupportedCurve(oid) {
16288
16335
  }
16289
16336
  }
16290
16337
 
16338
+ /**
16339
+ * Get preferred hash algo for a given elliptic algo
16340
+ * @param {module:enums.publicKey} algo - alrogithm identifier
16341
+ * @param {module:type/oid} [oid] - curve OID if needed by algo
16342
+ */
16343
+ function getPreferredCurveHashAlgo(algo, oid) {
16344
+ switch (algo) {
16345
+ case enums.publicKey.ecdsa:
16346
+ case enums.publicKey.eddsaLegacy:
16347
+ return publicKey.elliptic.getPreferredHashAlgo(oid);
16348
+ case enums.publicKey.ed25519:
16349
+ return publicKey.elliptic.eddsa.getPreferredHashAlgo(algo);
16350
+ default:
16351
+ throw new Error('Unknown elliptic signing algo');
16352
+ }
16353
+ }
16354
+
16291
16355
  var crypto$1 = /*#__PURE__*/Object.freeze({
16292
16356
  __proto__: null,
16293
16357
  publicKeyEncrypt: publicKeyEncrypt,
@@ -16301,7 +16365,8 @@ var crypto$1 = /*#__PURE__*/Object.freeze({
16301
16365
  getPrefixRandom: getPrefixRandom,
16302
16366
  generateSessionKey: generateSessionKey,
16303
16367
  getAEADMode: getAEADMode,
16304
- getCipher: getCipher
16368
+ getCipher: getCipher,
16369
+ getPreferredCurveHashAlgo: getPreferredCurveHashAlgo
16305
16370
  });
16306
16371
 
16307
16372
  /**
@@ -28059,25 +28124,22 @@ async function createBindingSignature(subkey, primaryKey, options, config) {
28059
28124
  const dataToSign = {};
28060
28125
  dataToSign.key = primaryKey;
28061
28126
  dataToSign.bind = subkey;
28062
- const subkeySignaturePacket = new SignaturePacket();
28063
- subkeySignaturePacket.signatureType = enums.signature.subkeyBinding;
28064
- subkeySignaturePacket.publicKeyAlgorithm = primaryKey.algorithm;
28065
- subkeySignaturePacket.hashAlgorithm = await getPreferredHashAlgo$1(null, subkey, undefined, undefined, config);
28127
+ const signatureProperties = { signatureType: enums.signature.subkeyBinding };
28066
28128
  if (options.sign) {
28067
- subkeySignaturePacket.keyFlags = [enums.keyFlags.signData];
28068
- subkeySignaturePacket.embeddedSignature = await createSignaturePacket(dataToSign, null, subkey, {
28129
+ signatureProperties.keyFlags = [enums.keyFlags.signData];
28130
+ signatureProperties.embeddedSignature = await createSignaturePacket(dataToSign, null, subkey, {
28069
28131
  signatureType: enums.signature.keyBinding
28070
28132
  }, options.date, undefined, undefined, undefined, config);
28071
28133
  } else {
28072
- subkeySignaturePacket.keyFlags = options.forwarding ?
28134
+ signatureProperties.keyFlags = options.forwarding ?
28073
28135
  [enums.keyFlags.forwardedCommunication] :
28074
28136
  [enums.keyFlags.encryptCommunication | enums.keyFlags.encryptStorage];
28075
28137
  }
28076
28138
  if (options.keyExpirationTime > 0) {
28077
- subkeySignaturePacket.keyExpirationTime = options.keyExpirationTime;
28078
- subkeySignaturePacket.keyNeverExpires = false;
28139
+ signatureProperties.keyExpirationTime = options.keyExpirationTime;
28140
+ signatureProperties.keyNeverExpires = false;
28079
28141
  }
28080
- await subkeySignaturePacket.sign(primaryKey, dataToSign, options.date);
28142
+ const subkeySignaturePacket = await createSignaturePacket(dataToSign, null, primaryKey, signatureProperties, options.date, undefined, undefined, undefined, config);
28081
28143
  return subkeySignaturePacket;
28082
28144
  }
28083
28145
 
@@ -28091,7 +28153,7 @@ async function createBindingSignature(subkey, primaryKey, options, config) {
28091
28153
  * @returns {Promise<enums.hash>}
28092
28154
  * @async
28093
28155
  */
28094
- async function getPreferredHashAlgo$1(key, keyPacket, date = new Date(), userID = {}, config) {
28156
+ async function getPreferredHashAlgo$2(key, keyPacket, date = new Date(), userID = {}, config) {
28095
28157
  let hashAlgo = config.preferredHashAlgorithm;
28096
28158
  let prefAlgo = hashAlgo;
28097
28159
  if (key) {
@@ -28102,17 +28164,11 @@ async function getPreferredHashAlgo$1(key, keyPacket, date = new Date(), userID
28102
28164
  prefAlgo : hashAlgo;
28103
28165
  }
28104
28166
  }
28105
- switch (Object.getPrototypeOf(keyPacket)) {
28106
- case SecretKeyPacket.prototype:
28107
- case PublicKeyPacket.prototype:
28108
- case SecretSubkeyPacket.prototype:
28109
- case PublicSubkeyPacket.prototype:
28110
- switch (keyPacket.algorithm) {
28111
- case enums.publicKey.ecdh:
28112
- case enums.publicKey.ecdsa:
28113
- case enums.publicKey.eddsa:
28114
- prefAlgo = mod.publicKey.elliptic.getPreferredHashAlgo(keyPacket.publicParams.oid);
28115
- }
28167
+ switch (keyPacket.algorithm) {
28168
+ case enums.publicKey.ecdsa:
28169
+ case enums.publicKey.eddsaLegacy:
28170
+ case enums.publicKey.ed25519:
28171
+ prefAlgo = mod.getPreferredCurveHashAlgo(keyPacket.algorithm, keyPacket.publicParams.oid);
28116
28172
  }
28117
28173
  return mod.hash.getHashByteLength(hashAlgo) <= mod.hash.getHashByteLength(prefAlgo) ?
28118
28174
  prefAlgo : hashAlgo;
@@ -28180,7 +28236,7 @@ async function createSignaturePacket(dataToSign, privateKey, signingKeyPacket, s
28180
28236
  const signaturePacket = new SignaturePacket();
28181
28237
  Object.assign(signaturePacket, signatureProperties);
28182
28238
  signaturePacket.publicKeyAlgorithm = signingKeyPacket.algorithm;
28183
- signaturePacket.hashAlgorithm = await getPreferredHashAlgo$1(privateKey, signingKeyPacket, date, userID, config);
28239
+ signaturePacket.hashAlgorithm = await getPreferredHashAlgo$2(privateKey, signingKeyPacket, date, userID, config);
28184
28240
  signaturePacket.rawNotations = notations;
28185
28241
  await signaturePacket.sign(signingKeyPacket, dataToSign, date, detached);
28186
28242
  return signaturePacket;
@@ -28321,11 +28377,11 @@ function sanitizeKeyOptions(options, subkeyDefaults = {}) {
28321
28377
  } catch (e) {
28322
28378
  throw new Error('Unknown curve');
28323
28379
  }
28324
- if (options.curve === enums.curve.ed25519 || options.curve === enums.curve.curve25519) {
28325
- options.curve = options.sign ? enums.curve.ed25519 : enums.curve.curve25519;
28380
+ if (options.curve === enums.curve.ed25519Legacy || options.curve === enums.curve.curve25519Legacy) {
28381
+ options.curve = options.sign ? enums.curve.ed25519Legacy : enums.curve.curve25519Legacy;
28326
28382
  }
28327
28383
  if (options.sign) {
28328
- options.algorithm = options.curve === enums.curve.ed25519 ? enums.publicKey.eddsa : enums.publicKey.ecdsa;
28384
+ options.algorithm = options.curve === enums.curve.ed25519Legacy ? enums.publicKey.eddsaLegacy : enums.publicKey.ecdsa;
28329
28385
  } else {
28330
28386
  options.algorithm = enums.publicKey.ecdh;
28331
28387
  }
@@ -28363,7 +28419,7 @@ function isValidEncryptionKeyPacket(keyPacket, signature) {
28363
28419
  return keyAlgo !== enums.publicKey.dsa &&
28364
28420
  keyAlgo !== enums.publicKey.rsaSign &&
28365
28421
  keyAlgo !== enums.publicKey.ecdsa &&
28366
- keyAlgo !== enums.publicKey.eddsa &&
28422
+ keyAlgo !== enums.publicKey.eddsaLegacy &&
28367
28423
  keyAlgo !== enums.publicKey.ed25519 &&
28368
28424
  (!signature.keyFlags ||
28369
28425
  (signature.keyFlags[0] & enums.keyFlags.encryptCommunication) !== 0 ||
@@ -28409,7 +28465,7 @@ function checkKeyRequirements(keyPacket, config) {
28409
28465
  }
28410
28466
  break;
28411
28467
  case enums.publicKey.ecdsa:
28412
- case enums.publicKey.eddsa:
28468
+ case enums.publicKey.eddsaLegacy:
28413
28469
  case enums.publicKey.ecdh:
28414
28470
  if (config.rejectCurves.has(algoInfo.curve)) {
28415
28471
  throw new Error(`Support for ${algoInfo.algorithm} keys using curve ${algoInfo.curve} is disabled.`);
@@ -30036,50 +30092,50 @@ async function wrapKeyObject(secretKeyPacket, secretSubkeyPackets, options, conf
30036
30092
  const dataToSign = {};
30037
30093
  dataToSign.userID = userIDPacket;
30038
30094
  dataToSign.key = secretKeyPacket;
30039
- const signaturePacket = new SignaturePacket();
30040
- signaturePacket.signatureType = enums.signature.certGeneric;
30041
- signaturePacket.publicKeyAlgorithm = secretKeyPacket.algorithm;
30042
- signaturePacket.hashAlgorithm = await getPreferredHashAlgo$1(null, secretKeyPacket, undefined, undefined, config);
30043
- signaturePacket.keyFlags = [enums.keyFlags.certifyKeys | enums.keyFlags.signData];
30044
- signaturePacket.preferredSymmetricAlgorithms = createPreferredAlgos([
30095
+
30096
+ const signatureProperties = {};
30097
+ signatureProperties.signatureType = enums.signature.certGeneric;
30098
+ signatureProperties.keyFlags = [enums.keyFlags.certifyKeys | enums.keyFlags.signData];
30099
+ signatureProperties.preferredSymmetricAlgorithms = createPreferredAlgos([
30045
30100
  // prefer aes256, aes128, then aes192 (no WebCrypto support: https://www.chromium.org/blink/webcrypto#TOC-AES-support)
30046
30101
  enums.symmetric.aes256,
30047
30102
  enums.symmetric.aes128,
30048
30103
  enums.symmetric.aes192
30049
30104
  ], config.preferredSymmetricAlgorithm);
30050
30105
  if (config.aeadProtect) {
30051
- signaturePacket.preferredAEADAlgorithms = createPreferredAlgos([
30106
+ signatureProperties.preferredAEADAlgorithms = createPreferredAlgos([
30052
30107
  enums.aead.eax,
30053
30108
  enums.aead.ocb
30054
30109
  ], config.preferredAEADAlgorithm);
30055
30110
  }
30056
- signaturePacket.preferredHashAlgorithms = createPreferredAlgos([
30111
+ signatureProperties.preferredHashAlgorithms = createPreferredAlgos([
30057
30112
  // prefer fast asm.js implementations (SHA-256)
30058
30113
  enums.hash.sha256,
30059
30114
  enums.hash.sha512
30060
30115
  ], config.preferredHashAlgorithm);
30061
- signaturePacket.preferredCompressionAlgorithms = createPreferredAlgos([
30116
+ signatureProperties.preferredCompressionAlgorithms = createPreferredAlgos([
30062
30117
  enums.compression.zlib,
30063
30118
  enums.compression.zip,
30064
30119
  enums.compression.uncompressed
30065
30120
  ], config.preferredCompressionAlgorithm);
30066
30121
  if (index === 0) {
30067
- signaturePacket.isPrimaryUserID = true;
30122
+ signatureProperties.isPrimaryUserID = true;
30068
30123
  }
30069
30124
  // integrity protection always enabled
30070
- signaturePacket.features = [0];
30071
- signaturePacket.features[0] |= enums.features.modificationDetection;
30125
+ signatureProperties.features = [0];
30126
+ signatureProperties.features[0] |= enums.features.modificationDetection;
30072
30127
  if (config.aeadProtect) {
30073
- signaturePacket.features[0] |= enums.features.aead;
30128
+ signatureProperties.features[0] |= enums.features.aead;
30074
30129
  }
30075
30130
  if (config.v5Keys) {
30076
- signaturePacket.features[0] |= enums.features.v5Keys;
30131
+ signatureProperties.features[0] |= enums.features.v5Keys;
30077
30132
  }
30078
30133
  if (options.keyExpirationTime > 0) {
30079
- signaturePacket.keyExpirationTime = options.keyExpirationTime;
30080
- signaturePacket.keyNeverExpires = false;
30134
+ signatureProperties.keyExpirationTime = options.keyExpirationTime;
30135
+ signatureProperties.keyNeverExpires = false;
30081
30136
  }
30082
- await signaturePacket.sign(secretKeyPacket, dataToSign, options.date);
30137
+
30138
+ const signaturePacket = await createSignaturePacket(dataToSign, null, secretKeyPacket, signatureProperties, options.date, undefined, undefined, undefined, config);
30083
30139
 
30084
30140
  return { userIDPacket, signaturePacket };
30085
30141
  })).then(list => {
@@ -30781,7 +30837,7 @@ class Message {
30781
30837
  const signingKey = await primaryKey.getSigningKey(signingKeyID, date, userIDs, config$1);
30782
30838
  const onePassSig = new OnePassSignaturePacket();
30783
30839
  onePassSig.signatureType = signatureType;
30784
- onePassSig.hashAlgorithm = await getPreferredHashAlgo$1(primaryKey, signingKey.keyPacket, date, userIDs, config$1);
30840
+ onePassSig.hashAlgorithm = await getPreferredHashAlgo$2(primaryKey, signingKey.keyPacket, date, userIDs, config$1);
30785
30841
  onePassSig.publicKeyAlgorithm = signingKey.keyPacket.algorithm;
30786
30842
  onePassSig.issuerKeyID = signingKey.getKeyID();
30787
30843
  if (i === signingKeys.length - 1) {
@@ -45299,4 +45355,4 @@ var index = /*#__PURE__*/Object.freeze({
45299
45355
  'default': loadWasm
45300
45356
  });
45301
45357
 
45302
- export { AEADEncryptedDataPacket, CleartextMessage, CompressedDataPacket, KDFParams, LiteralDataPacket, MarkerPacket, Message, OnePassSignaturePacket, PacketList, PrivateKey, PublicKey, PublicKeyEncryptedSessionKeyPacket, PublicKeyPacket, PublicSubkeyPacket, SecretKeyPacket, SecretSubkeyPacket, Signature, SignaturePacket, Subkey, SymEncryptedIntegrityProtectedDataPacket, SymEncryptedSessionKeyPacket, SymmetricallyEncryptedDataPacket, TrustPacket, UnparseablePacket, UserAttributePacket, UserIDPacket, armor, config, createCleartextMessage, createMessage, decrypt$5 as decrypt, decryptKey, decryptSessionKeys, encrypt$5 as encrypt, encryptKey, encryptSessionKey, enums, generateKey, generateSessionKey$1 as generateSessionKey, readCleartextMessage, readKey, readKeys, readMessage, readPrivateKey, readPrivateKeys, readSignature, reformatKey, revokeKey, sign$6 as sign, unarmor, verify$6 as verify };
45358
+ export { AEADEncryptedDataPacket, Argon2OutOfMemoryError, Argon2S2K, CleartextMessage, CompressedDataPacket, KDFParams, LiteralDataPacket, MarkerPacket, Message, OnePassSignaturePacket, PacketList, PrivateKey, PublicKey, PublicKeyEncryptedSessionKeyPacket, PublicKeyPacket, PublicSubkeyPacket, SecretKeyPacket, SecretSubkeyPacket, Signature, SignaturePacket, Subkey, SymEncryptedIntegrityProtectedDataPacket, SymEncryptedSessionKeyPacket, SymmetricallyEncryptedDataPacket, TrustPacket, UnparseablePacket, UserAttributePacket, UserIDPacket, armor, config, createCleartextMessage, createMessage, decrypt$5 as decrypt, decryptKey, decryptSessionKeys, encrypt$5 as encrypt, encryptKey, encryptSessionKey, enums, generateKey, generateSessionKey$1 as generateSessionKey, readCleartextMessage, readKey, readKeys, readMessage, readPrivateKey, readPrivateKeys, readSignature, reformatKey, revokeKey, sign$6 as sign, unarmor, verify$6 as verify };
package/openpgp.d.ts CHANGED
@@ -345,7 +345,7 @@ interface Config {
345
345
  rejectPublicKeyAlgorithms: Set<enums.publicKey>;
346
346
  rejectCurves: Set<enums.curve>;
347
347
  }
348
- export var config: Config;
348
+ export var config: Config & { checkEdDSAFaultySignatures: boolean }; // option only supported if set at the global openpgp.config level
349
349
 
350
350
  // PartialConfig has the same properties as Config, but declared as optional.
351
351
  // This interface is relevant for top-level functions, which accept a subset of configuration options
@@ -661,7 +661,7 @@ interface VerifyOptions {
661
661
  /** (optional) detached signature for verification */
662
662
  signature?: Signature;
663
663
  /** (optional) use the given date for verification instead of the current time */
664
- date?: Date;
664
+ date?: Date | null;
665
665
  config?: PartialConfig;
666
666
  }
667
667
 
@@ -824,7 +824,9 @@ export namespace enums {
824
824
  dsa = 17,
825
825
  ecdh = 18,
826
826
  ecdsa = 19,
827
+ /** @deprecated use `eddsaLegacy` instead */
827
828
  eddsa = 22,
829
+ eddsaLegacy = 22,
828
830
  aedh = 23,
829
831
  aedsa = 24,
830
832
  }
@@ -833,8 +835,12 @@ export namespace enums {
833
835
  p256 = 'p256',
834
836
  p384 = 'p384',
835
837
  p521 = 'p521',
838
+ /** @deprecated use `ed25519Legacy` instead */
836
839
  ed25519 = 'ed25519',
840
+ ed25519Legacy = 'ed25519',
841
+ /** @deprecated use `curve25519Legacy` instead */
837
842
  curve25519 = 'curve25519',
843
+ curve25519Legacy = 'curve25519',
838
844
  secp256k1 = 'secp256k1',
839
845
  brainpoolP256r1 = 'brainpoolP256r1',
840
846
  brainpoolP384r1 = 'brainpoolP384r1',
@@ -918,6 +924,13 @@ export namespace enums {
918
924
  }
919
925
  }
920
926
 
927
+ export declare class Argon2S2K {
928
+ constructor(config: Config);
929
+ salt: Uint8Array;
930
+ /** @throws Argon2OutOfMemoryError */
931
+ produceKey(passphrase: string, keySize: number): Promise<Uint8Array>;
932
+ }
933
+
921
934
  interface KDFParamsData {
922
935
  version: number;
923
936
  hash: enums.hash;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@protontech/openpgp",
3
3
  "description": "OpenPGP.js is a Javascript implementation of the OpenPGP protocol. This is defined in RFC 4880.",
4
- "version": "5.10.2",
4
+ "version": "5.11.1-0",
5
5
  "license": "LGPL-3.0+",
6
6
  "homepage": "https://openpgpjs.org/",
7
7
  "engines": {
@@ -60,7 +60,7 @@
60
60
  "@openpgp/pako": "^1.0.12",
61
61
  "@openpgp/seek-bzip": "^1.0.5-git",
62
62
  "@openpgp/tweetnacl": "^1.0.3",
63
- "@openpgp/web-stream-tools": "^0.0.11",
63
+ "@openpgp/web-stream-tools": "0.0.11-patch-0",
64
64
  "@rollup/plugin-commonjs": "^11.1.0",
65
65
  "@rollup/plugin-node-resolve": "^7.1.3",
66
66
  "@rollup/plugin-replace": "^2.3.2",