@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.js 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
  var openpgp = (function (exports) {
3
3
  'use strict';
4
4
 
@@ -244,18 +244,17 @@ var openpgp = (function (exports) {
244
244
  this.push(null);
245
245
  break;
246
246
  }
247
- if (!this.push(value) || this._cancelling) {
248
- this._reading = false;
247
+ if (!this.push(value)) {
249
248
  break;
250
249
  }
251
250
  }
252
- } catch(e) {
253
- this.emit('error', e);
251
+ } catch (e) {
252
+ this.destroy(e);
254
253
  }
255
254
  }
256
255
 
257
- _destroy(reason) {
258
- this._reader.cancel(reason);
256
+ async _destroy(error, callback) {
257
+ this._reader.cancel(error).then(callback, callback);
259
258
  }
260
259
  }
261
260
 
@@ -290,7 +289,7 @@ var openpgp = (function (exports) {
290
289
  const reader = input.getReader();
291
290
  this._read = reader.read.bind(reader);
292
291
  this._releaseLock = () => {};
293
- this._cancel = () => {};
292
+ this._cancel = async () => {};
294
293
  return;
295
294
  }
296
295
  let streamType = isStream(input);
@@ -1555,17 +1554,21 @@ var openpgp = (function (exports) {
1555
1554
  '2b8104000a': 'secp256k1',
1556
1555
  '2B8104000A': 'secp256k1',
1557
1556
 
1558
- /** Ed25519 */
1557
+ /** Ed25519 - deprecated by crypto-refresh (replaced by standaone Ed25519 algo) */
1558
+ 'ed25519Legacy': 'ed25519',
1559
1559
  'ED25519': 'ed25519',
1560
+ /** @deprecated use `ed25519Legacy` instead */
1560
1561
  'ed25519': 'ed25519',
1561
1562
  'Ed25519': 'ed25519',
1562
1563
  '1.3.6.1.4.1.11591.15.1': 'ed25519',
1563
1564
  '2b06010401da470f01': 'ed25519',
1564
1565
  '2B06010401DA470F01': 'ed25519',
1565
1566
 
1566
- /** Curve25519 */
1567
+ /** Curve25519 - deprecated by crypto-refresh (replaced by standaone X25519 algo) */
1568
+ 'curve25519Legacy': 'curve25519',
1567
1569
  'X25519': 'curve25519',
1568
1570
  'cv25519': 'curve25519',
1571
+ /** @deprecated use `curve25519Legacy` instead */
1569
1572
  'curve25519': 'curve25519',
1570
1573
  'Curve25519': 'curve25519',
1571
1574
  '1.3.6.1.4.1.3029.1.5.1': 'curve25519',
@@ -1636,8 +1639,11 @@ var openpgp = (function (exports) {
1636
1639
  ecdsa: 19,
1637
1640
  /** EdDSA (Sign only) - deprecated by crypto-refresh (replaced by `ed25519` identifier below)
1638
1641
  * [{@link https://tools.ietf.org/html/draft-koch-eddsa-for-openpgp-04|Draft RFC}] */
1639
- ed25519Legacy: 22, // NB: this is declared before `eddsa` to translate 22 to 'eddsa' for backwards compatibility
1640
- eddsa: 22, // to be deprecated in v6
1642
+ eddsaLegacy: 22, // NB: this is declared before `eddsa` to translate 22 to 'eddsa' for backwards compatibility
1643
+ /** @deprecated use `eddsaLegacy` instead */
1644
+ ed25519Legacy: 22,
1645
+ /** @deprecated use `eddsaLegacy` instead */
1646
+ eddsa: 22,
1641
1647
  /** Reserved for AEDH */
1642
1648
  aedh: 23,
1643
1649
  /** Reserved for AEDSA */
@@ -2947,7 +2953,7 @@ var openpgp = (function (exports) {
2947
2953
  * @memberof module:config
2948
2954
  * @property {String} versionString A version string to be included in armored messages
2949
2955
  */
2950
- versionString: 'OpenPGP.js 5.10.2',
2956
+ versionString: 'OpenPGP.js 5.11.1-0',
2951
2957
  /**
2952
2958
  * @memberof module:config
2953
2959
  * @property {String} commentString A comment string to be included in armored messages
@@ -2998,7 +3004,14 @@ var openpgp = (function (exports) {
2998
3004
  * @memberof module:config
2999
3005
  * @property {Set<String>} rejectCurves {@link module:enums.curve}
3000
3006
  */
3001
- rejectCurves: new Set([enums.curve.secp256k1])
3007
+ rejectCurves: new Set([enums.curve.secp256k1]),
3008
+ /**
3009
+ * Whether to validate generated EdDSA signatures before returning them, to ensure they are not faulty signatures.
3010
+ * This check will make signing 2-3 times slower.
3011
+ * Faulty signatures may be generated (in principle) if random bitflips occur at specific points in the signature
3012
+ * computation, and could be used to recover the signer's secret key given a second signature over the same data.
3013
+ */
3014
+ checkEdDSAFaultySignatures: true
3002
3015
  };
3003
3016
 
3004
3017
  /**
@@ -10974,42 +10987,42 @@ var openpgp = (function (exports) {
10974
10987
  throw new Error('GCM mode supports only AES cipher');
10975
10988
  }
10976
10989
 
10977
- if (util.getWebCrypto() && key.length !== 24) { // WebCrypto (no 192 bit support) see: https://www.chromium.org/blink/webcrypto#TOC-AES-support
10978
- const _key = await webCrypto$4.importKey('raw', key, { name: ALGO }, false, ['encrypt', 'decrypt']);
10979
-
10990
+ if (util.getNodeCrypto()) { // Node crypto library
10980
10991
  return {
10981
10992
  encrypt: async function(pt, iv, adata = new Uint8Array()) {
10982
- if (!pt.length) { // iOS does not support GCM-en/decrypting empty messages
10983
- return AES_GCM.encrypt(pt, key, iv, adata);
10984
- }
10985
- const ct = await webCrypto$4.encrypt({ name: ALGO, iv, additionalData: adata, tagLength: tagLength$2 * 8 }, _key, pt);
10993
+ const en = new nodeCrypto$4.createCipheriv('aes-' + (key.length * 8) + '-gcm', key, iv);
10994
+ en.setAAD(adata);
10995
+ const ct = Buffer$2.concat([en.update(pt), en.final(), en.getAuthTag()]); // append auth tag to ciphertext
10986
10996
  return new Uint8Array(ct);
10987
10997
  },
10988
10998
 
10989
10999
  decrypt: async function(ct, iv, adata = new Uint8Array()) {
10990
- if (ct.length === tagLength$2) { // iOS does not support GCM-en/decrypting empty messages
10991
- return AES_GCM.decrypt(ct, key, iv, adata);
10992
- }
10993
- const pt = await webCrypto$4.decrypt({ name: ALGO, iv, additionalData: adata, tagLength: tagLength$2 * 8 }, _key, ct);
11000
+ const de = new nodeCrypto$4.createDecipheriv('aes-' + (key.length * 8) + '-gcm', key, iv);
11001
+ de.setAAD(adata);
11002
+ de.setAuthTag(ct.slice(ct.length - tagLength$2, ct.length)); // read auth tag at end of ciphertext
11003
+ const pt = Buffer$2.concat([de.update(ct.slice(0, ct.length - tagLength$2)), de.final()]);
10994
11004
  return new Uint8Array(pt);
10995
11005
  }
10996
11006
  };
10997
11007
  }
10998
11008
 
10999
- if (util.getNodeCrypto()) { // Node crypto library
11009
+ if (util.getWebCrypto() && key.length !== 24) { // WebCrypto (no 192 bit support) see: https://www.chromium.org/blink/webcrypto#TOC-AES-support
11010
+ const _key = await webCrypto$4.importKey('raw', key, { name: ALGO }, false, ['encrypt', 'decrypt']);
11011
+
11000
11012
  return {
11001
11013
  encrypt: async function(pt, iv, adata = new Uint8Array()) {
11002
- const en = new nodeCrypto$4.createCipheriv('aes-' + (key.length * 8) + '-gcm', key, iv);
11003
- en.setAAD(adata);
11004
- const ct = Buffer$2.concat([en.update(pt), en.final(), en.getAuthTag()]); // append auth tag to ciphertext
11014
+ if (!pt.length) { // iOS does not support GCM-en/decrypting empty messages
11015
+ return AES_GCM.encrypt(pt, key, iv, adata);
11016
+ }
11017
+ const ct = await webCrypto$4.encrypt({ name: ALGO, iv, additionalData: adata, tagLength: tagLength$2 * 8 }, _key, pt);
11005
11018
  return new Uint8Array(ct);
11006
11019
  },
11007
11020
 
11008
11021
  decrypt: async function(ct, iv, adata = new Uint8Array()) {
11009
- const de = new nodeCrypto$4.createDecipheriv('aes-' + (key.length * 8) + '-gcm', key, iv);
11010
- de.setAAD(adata);
11011
- de.setAuthTag(ct.slice(ct.length - tagLength$2, ct.length)); // read auth tag at end of ciphertext
11012
- const pt = Buffer$2.concat([de.update(ct.slice(0, ct.length - tagLength$2)), de.final()]);
11022
+ if (ct.length === tagLength$2) { // iOS does not support GCM-en/decrypting empty messages
11023
+ return AES_GCM.decrypt(ct, key, iv, adata);
11024
+ }
11025
+ const pt = await webCrypto$4.decrypt({ name: ALGO, iv, additionalData: adata, tagLength: tagLength$2 * 8 }, _key, ct);
11013
11026
  return new Uint8Array(pt);
11014
11027
  }
11015
11028
  };
@@ -12012,11 +12025,11 @@ var openpgp = (function (exports) {
12012
12025
  */
12013
12026
  function getRandomBytes(length) {
12014
12027
  const buf = new Uint8Array(length);
12015
- if (typeof crypto !== 'undefined' && crypto.getRandomValues) {
12016
- crypto.getRandomValues(buf);
12017
- } else if (nodeCrypto$5) {
12028
+ if (nodeCrypto$5) {
12018
12029
  const bytes = nodeCrypto$5.randomBytes(buf.length);
12019
12030
  buf.set(bytes);
12031
+ } else if (typeof crypto !== 'undefined' && crypto.getRandomValues) {
12032
+ crypto.getRandomValues(buf);
12020
12033
  } else {
12021
12034
  throw new Error('No secure random number generator available.');
12022
12035
  }
@@ -13578,7 +13591,7 @@ var openpgp = (function (exports) {
13578
13591
  },
13579
13592
  ed25519: {
13580
13593
  oid: [0x06, 0x09, 0x2B, 0x06, 0x01, 0x04, 0x01, 0xDA, 0x47, 0x0F, 0x01],
13581
- keyType: enums.publicKey.eddsa,
13594
+ keyType: enums.publicKey.eddsaLegacy,
13582
13595
  hash: enums.hash.sha512,
13583
13596
  node: false, // nodeCurves.ed25519 TODO
13584
13597
  payloadSize: 32
@@ -14183,10 +14196,24 @@ var openpgp = (function (exports) {
14183
14196
  async function sign$2(oid, hashAlgo, message, publicKey, privateKey, hashed) {
14184
14197
  if (hash.getHashByteLength(hashAlgo) < hash.getHashByteLength(enums.hash.sha256)) {
14185
14198
  // see https://tools.ietf.org/id/draft-ietf-openpgp-rfc4880bis-10.html#section-15-7.2
14186
- throw new Error('Hash algorithm too weak: sha256 or stronger is required for EdDSA.');
14199
+ throw new Error('Hash algorithm too weak for EdDSA.');
14187
14200
  }
14188
14201
  const secretKey = util.concatUint8Array([privateKey, publicKey.subarray(1)]);
14189
14202
  const signature = naclFastLight.sign.detached(hashed, secretKey);
14203
+ if (config.checkEdDSAFaultySignatures && !naclFastLight.sign.detached.verify(hashed, signature, publicKey.subarray(1))) {
14204
+ /**
14205
+ * Detect faulty signatures caused by random bitflips during `crypto_sign` which could lead to private key extraction
14206
+ * if two signatures over the same message are obtained.
14207
+ * See https://github.com/jedisct1/libsodium/issues/170.
14208
+ * If the input data is not deterministic, e.g. thanks to the random salt in v6 OpenPGP signatures (not yet implemented),
14209
+ * then the generated signature is always safe, and the verification step is skipped.
14210
+ * Otherwise, we need to verify the generated to ensure that no bitflip occured:
14211
+ * - in M between the computation of `r` and `h`.
14212
+ * - in the public key before computing `h`
14213
+ * 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.
14214
+ */
14215
+ throw new Error('Transient signing failure');
14216
+ }
14190
14217
  // EdDSA signature params are returned in little-endian format
14191
14218
  return {
14192
14219
  r: signature.subarray(0, 32),
@@ -14207,6 +14234,9 @@ var openpgp = (function (exports) {
14207
14234
  * @async
14208
14235
  */
14209
14236
  async function verify$2(oid, hashAlgo, { r, s }, m, publicKey, hashed) {
14237
+ if (hash.getHashByteLength(hashAlgo) < hash.getHashByteLength(enums.hash.sha256)) {
14238
+ throw new Error('Hash algorithm too weak for EdDSA.');
14239
+ }
14210
14240
  const signature = util.concatUint8Array([r, s]);
14211
14241
  return naclFastLight.sign.detached.verify(hashed, signature, publicKey.subarray(1));
14212
14242
  }
@@ -14276,14 +14306,27 @@ var openpgp = (function (exports) {
14276
14306
  * @async
14277
14307
  */
14278
14308
  async function sign$3(algo, hashAlgo, message, publicKey, privateKey, hashed) {
14279
- if (hash.getHashByteLength(hashAlgo) < hash.getHashByteLength(enums.hash.sha256)) {
14280
- // see https://tools.ietf.org/id/draft-ietf-openpgp-rfc4880bis-10.html#section-15-7.2
14281
- throw new Error('Hash algorithm too weak: sha256 or stronger is required for EdDSA.');
14309
+ if (hash.getHashByteLength(hashAlgo) < hash.getHashByteLength(getPreferredHashAlgo$1(algo))) {
14310
+ throw new Error('Hash algorithm too weak for EdDSA.');
14282
14311
  }
14283
14312
  switch (algo) {
14284
14313
  case enums.publicKey.ed25519: {
14285
14314
  const secretKey = util.concatUint8Array([privateKey, publicKey]);
14286
14315
  const signature = naclFastLight.sign.detached(hashed, secretKey);
14316
+ if (config.checkEdDSAFaultySignatures && !naclFastLight.sign.detached.verify(hashed, signature, publicKey)) {
14317
+ /**
14318
+ * Detect faulty signatures caused by random bitflips during `crypto_sign` which could lead to private key extraction
14319
+ * if two signatures over the same message are obtained.
14320
+ * See https://github.com/jedisct1/libsodium/issues/170.
14321
+ * If the input data is not deterministic, e.g. thanks to the random salt in v6 OpenPGP signatures (not yet implemented),
14322
+ * then the generated signature is always safe, and the verification step is skipped.
14323
+ * Otherwise, we need to verify the generated to ensure that no bitflip occured:
14324
+ * - in M between the computation of `r` and `h`.
14325
+ * - in the public key before computing `h`
14326
+ * 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.
14327
+ */
14328
+ throw new Error('Transient signing failure');
14329
+ }
14287
14330
  return { RS: signature };
14288
14331
  }
14289
14332
  case enums.publicKey.ed448:
@@ -14305,6 +14348,9 @@ var openpgp = (function (exports) {
14305
14348
  * @async
14306
14349
  */
14307
14350
  async function verify$3(algo, hashAlgo, { RS }, m, publicKey, hashed) {
14351
+ if (hash.getHashByteLength(hashAlgo) < hash.getHashByteLength(getPreferredHashAlgo$1(algo))) {
14352
+ throw new Error('Hash algorithm too weak for EdDSA.');
14353
+ }
14308
14354
  switch (algo) {
14309
14355
  case enums.publicKey.ed25519: {
14310
14356
  return naclFastLight.sign.detached.verify(hashed, RS, publicKey);
@@ -14340,12 +14386,22 @@ var openpgp = (function (exports) {
14340
14386
  }
14341
14387
  }
14342
14388
 
14389
+ function getPreferredHashAlgo$1(algo) {
14390
+ switch (algo) {
14391
+ case enums.publicKey.ed25519:
14392
+ return enums.hash.sha256;
14393
+ default:
14394
+ throw new Error('Unknown EdDSA algo');
14395
+ }
14396
+ }
14397
+
14343
14398
  var eddsa = /*#__PURE__*/Object.freeze({
14344
14399
  __proto__: null,
14345
14400
  generate: generate$2,
14346
14401
  sign: sign$3,
14347
14402
  verify: verify$3,
14348
- validateParams: validateParams$4
14403
+ validateParams: validateParams$4,
14404
+ getPreferredHashAlgo: getPreferredHashAlgo$1
14349
14405
  });
14350
14406
 
14351
14407
  // OpenPGP.js - An OpenPGP implementation in javascript
@@ -14959,8 +15015,6 @@ var openpgp = (function (exports) {
14959
15015
  case enums.publicKey.x25519: {
14960
15016
  // k stays in little-endian, unlike legacy ECDH over curve25519
14961
15017
  const k = getRandomBytes(32);
14962
- k[0] &= 248;
14963
- k[31] = (k[31] & 127) | 64;
14964
15018
  const { publicKey: A } = naclFastLight.box.keyPair.fromSecretKey(k);
14965
15019
  return { A, k };
14966
15020
  }
@@ -15395,8 +15449,7 @@ var openpgp = (function (exports) {
15395
15449
  // Algorithm-Specific Fields for legacy EdDSA signatures:
15396
15450
  // - MPI of an EC point r.
15397
15451
  // - EdDSA value s, in MPI, in the little endian representation
15398
- case enums.publicKey.eddsa:
15399
- case enums.publicKey.ed25519Legacy: {
15452
+ case enums.publicKey.eddsaLegacy: {
15400
15453
  // When parsing little-endian MPI data, we always need to left-pad it, as done with big-endian values:
15401
15454
  // https://www.ietf.org/archive/id/draft-ietf-openpgp-rfc4880bis-10.html#section-3.2-9
15402
15455
  let r = util.readMPI(signature.subarray(read)); read += r.length + 2;
@@ -15457,8 +15510,7 @@ var openpgp = (function (exports) {
15457
15510
  const s = util.leftPad(signature.s, curveSize);
15458
15511
  return publicKey.elliptic.ecdsa.verify(oid, hashAlgo, { r, s }, data, Q, hashed);
15459
15512
  }
15460
- case enums.publicKey.eddsa:
15461
- case enums.publicKey.ed25519Legacy: {
15513
+ case enums.publicKey.eddsaLegacy: {
15462
15514
  const { oid, Q } = publicParams;
15463
15515
  // signature already padded on parsing
15464
15516
  return publicKey.elliptic.eddsaLegacy.verify(oid, hashAlgo, signature, data, Q, hashed);
@@ -15521,8 +15573,7 @@ var openpgp = (function (exports) {
15521
15573
  const { d } = privateKeyParams;
15522
15574
  return publicKey.elliptic.ecdsa.sign(oid, hashAlgo, data, Q, d, hashed);
15523
15575
  }
15524
- case enums.publicKey.eddsa:
15525
- case enums.publicKey.ed25519Legacy: {
15576
+ case enums.publicKey.eddsaLegacy: {
15526
15577
  const { oid, Q } = publicKeyParams;
15527
15578
  const { seed } = privateKeyParams;
15528
15579
  return publicKey.elliptic.eddsaLegacy.sign(oid, hashAlgo, data, Q, seed, hashed);
@@ -15913,8 +15964,7 @@ var openpgp = (function (exports) {
15913
15964
  const Q = util.readMPI(bytes.subarray(read)); read += Q.length + 2;
15914
15965
  return { read: read, publicParams: { oid, Q } };
15915
15966
  }
15916
- case enums.publicKey.eddsa:
15917
- case enums.publicKey.ed25519Legacy: {
15967
+ case enums.publicKey.eddsaLegacy: {
15918
15968
  const oid = new OID(); read += oid.read(bytes);
15919
15969
  checkSupportedCurve(oid);
15920
15970
  let Q = util.readMPI(bytes.subarray(read)); read += Q.length + 2;
@@ -15976,8 +16026,7 @@ var openpgp = (function (exports) {
15976
16026
  d = util.leftPad(d, curve.payloadSize);
15977
16027
  return { read, privateParams: { d } };
15978
16028
  }
15979
- case enums.publicKey.eddsa:
15980
- case enums.publicKey.ed25519Legacy: {
16029
+ case enums.publicKey.eddsaLegacy: {
15981
16030
  const curve = new CurveWithOID(publicParams.oid);
15982
16031
  let seed = util.readMPI(bytes.subarray(read)); read += seed.length + 2;
15983
16032
  seed = util.leftPad(seed, curve.payloadSize);
@@ -16112,8 +16161,7 @@ var openpgp = (function (exports) {
16112
16161
  privateParams: { d: secret },
16113
16162
  publicParams: { oid: new OID(oid), Q }
16114
16163
  }));
16115
- case enums.publicKey.eddsa:
16116
- case enums.publicKey.ed25519Legacy:
16164
+ case enums.publicKey.eddsaLegacy:
16117
16165
  return publicKey.elliptic.generate(oid).then(({ oid, Q, secret }) => ({
16118
16166
  privateParams: { seed: secret },
16119
16167
  publicParams: { oid: new OID(oid), Q }
@@ -16207,8 +16255,7 @@ var openpgp = (function (exports) {
16207
16255
  const { d } = privateParams;
16208
16256
  return algoModule.validateParams(oid, Q, d);
16209
16257
  }
16210
- case enums.publicKey.eddsa:
16211
- case enums.publicKey.ed25519Legacy: {
16258
+ case enums.publicKey.eddsaLegacy: {
16212
16259
  const { Q, oid } = publicParams;
16213
16260
  const { seed } = privateParams;
16214
16261
  return publicKey.elliptic.eddsaLegacy.validateParams(oid, Q, seed);
@@ -16291,6 +16338,23 @@ var openpgp = (function (exports) {
16291
16338
  }
16292
16339
  }
16293
16340
 
16341
+ /**
16342
+ * Get preferred hash algo for a given elliptic algo
16343
+ * @param {module:enums.publicKey} algo - alrogithm identifier
16344
+ * @param {module:type/oid} [oid] - curve OID if needed by algo
16345
+ */
16346
+ function getPreferredCurveHashAlgo(algo, oid) {
16347
+ switch (algo) {
16348
+ case enums.publicKey.ecdsa:
16349
+ case enums.publicKey.eddsaLegacy:
16350
+ return publicKey.elliptic.getPreferredHashAlgo(oid);
16351
+ case enums.publicKey.ed25519:
16352
+ return publicKey.elliptic.eddsa.getPreferredHashAlgo(algo);
16353
+ default:
16354
+ throw new Error('Unknown elliptic signing algo');
16355
+ }
16356
+ }
16357
+
16294
16358
  var crypto$1 = /*#__PURE__*/Object.freeze({
16295
16359
  __proto__: null,
16296
16360
  publicKeyEncrypt: publicKeyEncrypt,
@@ -16304,7 +16368,8 @@ var openpgp = (function (exports) {
16304
16368
  getPrefixRandom: getPrefixRandom,
16305
16369
  generateSessionKey: generateSessionKey,
16306
16370
  getAEADMode: getAEADMode,
16307
- getCipher: getCipher
16371
+ getCipher: getCipher,
16372
+ getPreferredCurveHashAlgo: getPreferredCurveHashAlgo
16308
16373
  });
16309
16374
 
16310
16375
  /**
@@ -28062,25 +28127,22 @@ var openpgp = (function (exports) {
28062
28127
  const dataToSign = {};
28063
28128
  dataToSign.key = primaryKey;
28064
28129
  dataToSign.bind = subkey;
28065
- const subkeySignaturePacket = new SignaturePacket();
28066
- subkeySignaturePacket.signatureType = enums.signature.subkeyBinding;
28067
- subkeySignaturePacket.publicKeyAlgorithm = primaryKey.algorithm;
28068
- subkeySignaturePacket.hashAlgorithm = await getPreferredHashAlgo$1(null, subkey, undefined, undefined, config);
28130
+ const signatureProperties = { signatureType: enums.signature.subkeyBinding };
28069
28131
  if (options.sign) {
28070
- subkeySignaturePacket.keyFlags = [enums.keyFlags.signData];
28071
- subkeySignaturePacket.embeddedSignature = await createSignaturePacket(dataToSign, null, subkey, {
28132
+ signatureProperties.keyFlags = [enums.keyFlags.signData];
28133
+ signatureProperties.embeddedSignature = await createSignaturePacket(dataToSign, null, subkey, {
28072
28134
  signatureType: enums.signature.keyBinding
28073
28135
  }, options.date, undefined, undefined, undefined, config);
28074
28136
  } else {
28075
- subkeySignaturePacket.keyFlags = options.forwarding ?
28137
+ signatureProperties.keyFlags = options.forwarding ?
28076
28138
  [enums.keyFlags.forwardedCommunication] :
28077
28139
  [enums.keyFlags.encryptCommunication | enums.keyFlags.encryptStorage];
28078
28140
  }
28079
28141
  if (options.keyExpirationTime > 0) {
28080
- subkeySignaturePacket.keyExpirationTime = options.keyExpirationTime;
28081
- subkeySignaturePacket.keyNeverExpires = false;
28142
+ signatureProperties.keyExpirationTime = options.keyExpirationTime;
28143
+ signatureProperties.keyNeverExpires = false;
28082
28144
  }
28083
- await subkeySignaturePacket.sign(primaryKey, dataToSign, options.date);
28145
+ const subkeySignaturePacket = await createSignaturePacket(dataToSign, null, primaryKey, signatureProperties, options.date, undefined, undefined, undefined, config);
28084
28146
  return subkeySignaturePacket;
28085
28147
  }
28086
28148
 
@@ -28094,7 +28156,7 @@ var openpgp = (function (exports) {
28094
28156
  * @returns {Promise<enums.hash>}
28095
28157
  * @async
28096
28158
  */
28097
- async function getPreferredHashAlgo$1(key, keyPacket, date = new Date(), userID = {}, config) {
28159
+ async function getPreferredHashAlgo$2(key, keyPacket, date = new Date(), userID = {}, config) {
28098
28160
  let hashAlgo = config.preferredHashAlgorithm;
28099
28161
  let prefAlgo = hashAlgo;
28100
28162
  if (key) {
@@ -28105,17 +28167,11 @@ var openpgp = (function (exports) {
28105
28167
  prefAlgo : hashAlgo;
28106
28168
  }
28107
28169
  }
28108
- switch (Object.getPrototypeOf(keyPacket)) {
28109
- case SecretKeyPacket.prototype:
28110
- case PublicKeyPacket.prototype:
28111
- case SecretSubkeyPacket.prototype:
28112
- case PublicSubkeyPacket.prototype:
28113
- switch (keyPacket.algorithm) {
28114
- case enums.publicKey.ecdh:
28115
- case enums.publicKey.ecdsa:
28116
- case enums.publicKey.eddsa:
28117
- prefAlgo = mod.publicKey.elliptic.getPreferredHashAlgo(keyPacket.publicParams.oid);
28118
- }
28170
+ switch (keyPacket.algorithm) {
28171
+ case enums.publicKey.ecdsa:
28172
+ case enums.publicKey.eddsaLegacy:
28173
+ case enums.publicKey.ed25519:
28174
+ prefAlgo = mod.getPreferredCurveHashAlgo(keyPacket.algorithm, keyPacket.publicParams.oid);
28119
28175
  }
28120
28176
  return mod.hash.getHashByteLength(hashAlgo) <= mod.hash.getHashByteLength(prefAlgo) ?
28121
28177
  prefAlgo : hashAlgo;
@@ -28183,7 +28239,7 @@ var openpgp = (function (exports) {
28183
28239
  const signaturePacket = new SignaturePacket();
28184
28240
  Object.assign(signaturePacket, signatureProperties);
28185
28241
  signaturePacket.publicKeyAlgorithm = signingKeyPacket.algorithm;
28186
- signaturePacket.hashAlgorithm = await getPreferredHashAlgo$1(privateKey, signingKeyPacket, date, userID, config);
28242
+ signaturePacket.hashAlgorithm = await getPreferredHashAlgo$2(privateKey, signingKeyPacket, date, userID, config);
28187
28243
  signaturePacket.rawNotations = notations;
28188
28244
  await signaturePacket.sign(signingKeyPacket, dataToSign, date, detached);
28189
28245
  return signaturePacket;
@@ -28324,11 +28380,11 @@ var openpgp = (function (exports) {
28324
28380
  } catch (e) {
28325
28381
  throw new Error('Unknown curve');
28326
28382
  }
28327
- if (options.curve === enums.curve.ed25519 || options.curve === enums.curve.curve25519) {
28328
- options.curve = options.sign ? enums.curve.ed25519 : enums.curve.curve25519;
28383
+ if (options.curve === enums.curve.ed25519Legacy || options.curve === enums.curve.curve25519Legacy) {
28384
+ options.curve = options.sign ? enums.curve.ed25519Legacy : enums.curve.curve25519Legacy;
28329
28385
  }
28330
28386
  if (options.sign) {
28331
- options.algorithm = options.curve === enums.curve.ed25519 ? enums.publicKey.eddsa : enums.publicKey.ecdsa;
28387
+ options.algorithm = options.curve === enums.curve.ed25519Legacy ? enums.publicKey.eddsaLegacy : enums.publicKey.ecdsa;
28332
28388
  } else {
28333
28389
  options.algorithm = enums.publicKey.ecdh;
28334
28390
  }
@@ -28366,7 +28422,7 @@ var openpgp = (function (exports) {
28366
28422
  return keyAlgo !== enums.publicKey.dsa &&
28367
28423
  keyAlgo !== enums.publicKey.rsaSign &&
28368
28424
  keyAlgo !== enums.publicKey.ecdsa &&
28369
- keyAlgo !== enums.publicKey.eddsa &&
28425
+ keyAlgo !== enums.publicKey.eddsaLegacy &&
28370
28426
  keyAlgo !== enums.publicKey.ed25519 &&
28371
28427
  (!signature.keyFlags ||
28372
28428
  (signature.keyFlags[0] & enums.keyFlags.encryptCommunication) !== 0 ||
@@ -28412,7 +28468,7 @@ var openpgp = (function (exports) {
28412
28468
  }
28413
28469
  break;
28414
28470
  case enums.publicKey.ecdsa:
28415
- case enums.publicKey.eddsa:
28471
+ case enums.publicKey.eddsaLegacy:
28416
28472
  case enums.publicKey.ecdh:
28417
28473
  if (config.rejectCurves.has(algoInfo.curve)) {
28418
28474
  throw new Error(`Support for ${algoInfo.algorithm} keys using curve ${algoInfo.curve} is disabled.`);
@@ -30039,50 +30095,50 @@ var openpgp = (function (exports) {
30039
30095
  const dataToSign = {};
30040
30096
  dataToSign.userID = userIDPacket;
30041
30097
  dataToSign.key = secretKeyPacket;
30042
- const signaturePacket = new SignaturePacket();
30043
- signaturePacket.signatureType = enums.signature.certGeneric;
30044
- signaturePacket.publicKeyAlgorithm = secretKeyPacket.algorithm;
30045
- signaturePacket.hashAlgorithm = await getPreferredHashAlgo$1(null, secretKeyPacket, undefined, undefined, config);
30046
- signaturePacket.keyFlags = [enums.keyFlags.certifyKeys | enums.keyFlags.signData];
30047
- signaturePacket.preferredSymmetricAlgorithms = createPreferredAlgos([
30098
+
30099
+ const signatureProperties = {};
30100
+ signatureProperties.signatureType = enums.signature.certGeneric;
30101
+ signatureProperties.keyFlags = [enums.keyFlags.certifyKeys | enums.keyFlags.signData];
30102
+ signatureProperties.preferredSymmetricAlgorithms = createPreferredAlgos([
30048
30103
  // prefer aes256, aes128, then aes192 (no WebCrypto support: https://www.chromium.org/blink/webcrypto#TOC-AES-support)
30049
30104
  enums.symmetric.aes256,
30050
30105
  enums.symmetric.aes128,
30051
30106
  enums.symmetric.aes192
30052
30107
  ], config.preferredSymmetricAlgorithm);
30053
30108
  if (config.aeadProtect) {
30054
- signaturePacket.preferredAEADAlgorithms = createPreferredAlgos([
30109
+ signatureProperties.preferredAEADAlgorithms = createPreferredAlgos([
30055
30110
  enums.aead.eax,
30056
30111
  enums.aead.ocb
30057
30112
  ], config.preferredAEADAlgorithm);
30058
30113
  }
30059
- signaturePacket.preferredHashAlgorithms = createPreferredAlgos([
30114
+ signatureProperties.preferredHashAlgorithms = createPreferredAlgos([
30060
30115
  // prefer fast asm.js implementations (SHA-256)
30061
30116
  enums.hash.sha256,
30062
30117
  enums.hash.sha512
30063
30118
  ], config.preferredHashAlgorithm);
30064
- signaturePacket.preferredCompressionAlgorithms = createPreferredAlgos([
30119
+ signatureProperties.preferredCompressionAlgorithms = createPreferredAlgos([
30065
30120
  enums.compression.zlib,
30066
30121
  enums.compression.zip,
30067
30122
  enums.compression.uncompressed
30068
30123
  ], config.preferredCompressionAlgorithm);
30069
30124
  if (index === 0) {
30070
- signaturePacket.isPrimaryUserID = true;
30125
+ signatureProperties.isPrimaryUserID = true;
30071
30126
  }
30072
30127
  // integrity protection always enabled
30073
- signaturePacket.features = [0];
30074
- signaturePacket.features[0] |= enums.features.modificationDetection;
30128
+ signatureProperties.features = [0];
30129
+ signatureProperties.features[0] |= enums.features.modificationDetection;
30075
30130
  if (config.aeadProtect) {
30076
- signaturePacket.features[0] |= enums.features.aead;
30131
+ signatureProperties.features[0] |= enums.features.aead;
30077
30132
  }
30078
30133
  if (config.v5Keys) {
30079
- signaturePacket.features[0] |= enums.features.v5Keys;
30134
+ signatureProperties.features[0] |= enums.features.v5Keys;
30080
30135
  }
30081
30136
  if (options.keyExpirationTime > 0) {
30082
- signaturePacket.keyExpirationTime = options.keyExpirationTime;
30083
- signaturePacket.keyNeverExpires = false;
30137
+ signatureProperties.keyExpirationTime = options.keyExpirationTime;
30138
+ signatureProperties.keyNeverExpires = false;
30084
30139
  }
30085
- await signaturePacket.sign(secretKeyPacket, dataToSign, options.date);
30140
+
30141
+ const signaturePacket = await createSignaturePacket(dataToSign, null, secretKeyPacket, signatureProperties, options.date, undefined, undefined, undefined, config);
30086
30142
 
30087
30143
  return { userIDPacket, signaturePacket };
30088
30144
  })).then(list => {
@@ -30784,7 +30840,7 @@ var openpgp = (function (exports) {
30784
30840
  const signingKey = await primaryKey.getSigningKey(signingKeyID, date, userIDs, config$1);
30785
30841
  const onePassSig = new OnePassSignaturePacket();
30786
30842
  onePassSig.signatureType = signatureType;
30787
- onePassSig.hashAlgorithm = await getPreferredHashAlgo$1(primaryKey, signingKey.keyPacket, date, userIDs, config$1);
30843
+ onePassSig.hashAlgorithm = await getPreferredHashAlgo$2(primaryKey, signingKey.keyPacket, date, userIDs, config$1);
30788
30844
  onePassSig.publicKeyAlgorithm = signingKey.keyPacket.algorithm;
30789
30845
  onePassSig.issuerKeyID = signingKey.getKeyID();
30790
30846
  if (i === signingKeys.length - 1) {
@@ -45303,6 +45359,8 @@ var openpgp = (function (exports) {
45303
45359
  });
45304
45360
 
45305
45361
  exports.AEADEncryptedDataPacket = AEADEncryptedDataPacket;
45362
+ exports.Argon2OutOfMemoryError = Argon2OutOfMemoryError;
45363
+ exports.Argon2S2K = Argon2S2K;
45306
45364
  exports.CleartextMessage = CleartextMessage;
45307
45365
  exports.CompressedDataPacket = CompressedDataPacket;
45308
45366
  exports.KDFParams = KDFParams;