@protontech/openpgp 5.4.0 → 5.5.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.
@@ -1,4 +1,4 @@
1
- /*! OpenPGP.js v5.4.0 - 2022-08-08 - this is LGPL licensed code, see LICENSE/our website https://openpgpjs.org/ for more information. */
1
+ /*! OpenPGP.js v5.5.0 - 2022-10-31 - this is LGPL licensed code, see LICENSE/our website https://openpgpjs.org/ for more information. */
2
2
  const globalThis = typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
3
3
 
4
4
  import buffer from 'buffer';
@@ -1776,7 +1776,7 @@ const util = {
1776
1776
  */
1777
1777
  printDebug: function (str) {
1778
1778
  if (debugMode) {
1779
- console.log(str);
1779
+ console.log('[OpenPGP.js debug]', str);
1780
1780
  }
1781
1781
  },
1782
1782
 
@@ -1787,7 +1787,7 @@ const util = {
1787
1787
  */
1788
1788
  printDebugError: function (error) {
1789
1789
  if (debugMode) {
1790
- console.error(error);
1790
+ console.error('[OpenPGP.js debug]', error);
1791
1791
  }
1792
1792
  },
1793
1793
 
@@ -2890,7 +2890,7 @@ var defaultConfig = {
2890
2890
  * @memberof module:config
2891
2891
  * @property {String} versionString A version string to be included in armored messages
2892
2892
  */
2893
- versionString: 'OpenPGP.js 5.4.0',
2893
+ versionString: 'OpenPGP.js 5.5.0',
2894
2894
  /**
2895
2895
  * @memberof module:config
2896
2896
  * @property {String} commentString A comment string to be included in armored messages
@@ -3107,15 +3107,17 @@ function createcrc24(input) {
3107
3107
  }
3108
3108
 
3109
3109
  /**
3110
- * Verify armored headers. RFC4880, section 6.3: "OpenPGP should consider improperly formatted
3111
- * Armor Headers to be corruption of the ASCII Armor."
3110
+ * Verify armored headers. crypto-refresh-06, section 6.2:
3111
+ * "An OpenPGP implementation may consider improperly formatted Armor
3112
+ * Headers to be corruption of the ASCII Armor, but SHOULD make an
3113
+ * effort to recover."
3112
3114
  * @private
3113
3115
  * @param {Array<String>} headers - Armor headers
3114
3116
  */
3115
3117
  function verifyHeaders(headers) {
3116
3118
  for (let i = 0; i < headers.length; i++) {
3117
3119
  if (!/^([^\s:]|[^\s:][^:]*[^\s:]): .+$/.test(headers[i])) {
3118
- throw new Error('Improperly formatted armor header: ' + headers[i]);
3120
+ util.printDebugError(new Error('Improperly formatted armor header: ' + headers[i]));
3119
3121
  }
3120
3122
  if (!/^(Version|Comment|MessageID|Hash|Charset): .+$/.test(headers[i])) {
3121
3123
  util.printDebugError(new Error('Unknown header: ' + headers[i]));
@@ -3309,7 +3311,7 @@ function armor(messageType, body, partIndex, partTotal, customComment, config =
3309
3311
  result.push('-----END PGP MESSAGE, PART ' + partIndex + '-----\n');
3310
3312
  break;
3311
3313
  case enums.armor.signed:
3312
- result.push('\n-----BEGIN PGP SIGNED MESSAGE-----\n');
3314
+ result.push('-----BEGIN PGP SIGNED MESSAGE-----\n');
3313
3315
  result.push('Hash: ' + hash + '\n\n');
3314
3316
  result.push(text.replace(/^-/mg, '- -'));
3315
3317
  result.push('\n-----BEGIN PGP SIGNATURE-----\n');
@@ -23266,6 +23268,11 @@ class SignaturePacket {
23266
23268
  // Add hashed subpackets
23267
23269
  arr.push(this.writeHashedSubPackets());
23268
23270
 
23271
+ // Remove unhashed subpackets, in case some allowed unhashed
23272
+ // subpackets existed, in order not to duplicate them (in both
23273
+ // the hashed and unhashed subpackets) when re-signing.
23274
+ this.unhashedSubpackets = [];
23275
+
23269
23276
  this.signatureData = util.concat(arr);
23270
23277
 
23271
23278
  const toHash = this.toHash(this.signatureType, data, detached);
@@ -23328,6 +23335,11 @@ class SignaturePacket {
23328
23335
  bytes = util.concat([bytes, this.revocationKeyFingerprint]);
23329
23336
  arr.push(writeSubPacket(sub.revocationKey, bytes));
23330
23337
  }
23338
+ if (!this.issuerKeyID.isNull() && this.issuerKeyVersion !== 5) {
23339
+ // If the version of [the] key is greater than 4, this subpacket
23340
+ // MUST NOT be included in the signature.
23341
+ arr.push(writeSubPacket(sub.issuer, this.issuerKeyID.write()));
23342
+ }
23331
23343
  this.rawNotations.forEach(([{ name, value, humanReadable }]) => {
23332
23344
  bytes = [new Uint8Array([humanReadable ? 0x80 : 0, 0, 0, 0])];
23333
23345
  // 2 octets of name length
@@ -23381,6 +23393,14 @@ class SignaturePacket {
23381
23393
  bytes = util.concat(bytes);
23382
23394
  arr.push(writeSubPacket(sub.signatureTarget, bytes));
23383
23395
  }
23396
+ if (this.embeddedSignature !== null) {
23397
+ arr.push(writeSubPacket(sub.embeddedSignature, this.embeddedSignature.write()));
23398
+ }
23399
+ if (this.issuerFingerprint !== null) {
23400
+ bytes = [new Uint8Array([this.issuerKeyVersion]), this.issuerFingerprint];
23401
+ bytes = util.concat(bytes);
23402
+ arr.push(writeSubPacket(sub.issuerFingerprint, bytes));
23403
+ }
23384
23404
  if (this.preferredAEADAlgorithms !== null) {
23385
23405
  bytes = util.stringToUint8Array(util.uint8ArrayToString(this.preferredAEADAlgorithms));
23386
23406
  arr.push(writeSubPacket(sub.preferredAEADAlgorithms, bytes));
@@ -23393,26 +23413,11 @@ class SignaturePacket {
23393
23413
  }
23394
23414
 
23395
23415
  /**
23396
- * Creates Uint8Array of bytes of Issuer and Embedded Signature subpackets
23416
+ * Creates an Uint8Array containing the unhashed subpackets
23397
23417
  * @returns {Uint8Array} Subpacket data.
23398
23418
  */
23399
23419
  writeUnhashedSubPackets() {
23400
- const sub = enums.signatureSubpacket;
23401
23420
  const arr = [];
23402
- let bytes;
23403
- if (!this.issuerKeyID.isNull() && this.issuerKeyVersion !== 5) {
23404
- // If the version of [the] key is greater than 4, this subpacket
23405
- // MUST NOT be included in the signature.
23406
- arr.push(writeSubPacket(sub.issuer, this.issuerKeyID.write()));
23407
- }
23408
- if (this.embeddedSignature !== null) {
23409
- arr.push(writeSubPacket(sub.embeddedSignature, this.embeddedSignature.write()));
23410
- }
23411
- if (this.issuerFingerprint !== null) {
23412
- bytes = [new Uint8Array([this.issuerKeyVersion]), this.issuerFingerprint];
23413
- bytes = util.concat(bytes);
23414
- arr.push(writeSubPacket(sub.issuerFingerprint, bytes));
23415
- }
23416
23421
  this.unhashedSubpackets.forEach(data => {
23417
23422
  arr.push(writeSimpleLength(data.length));
23418
23423
  arr.push(data);
@@ -23432,9 +23437,11 @@ class SignaturePacket {
23432
23437
  const critical = bytes[mypos] & 0x80;
23433
23438
  const type = bytes[mypos] & 0x7F;
23434
23439
 
23435
- if (!hashed && !allowedUnhashedSubpackets.has(type)) {
23440
+ if (!hashed) {
23436
23441
  this.unhashedSubpackets.push(bytes.subarray(mypos, bytes.length));
23437
- return;
23442
+ if (!allowedUnhashedSubpackets.has(type)) {
23443
+ return;
23444
+ }
23438
23445
  }
23439
23446
 
23440
23447
  mypos++;
package/dist/openpgp.js CHANGED
@@ -1,4 +1,4 @@
1
- /*! OpenPGP.js v5.4.0 - 2022-08-08 - this is LGPL licensed code, see LICENSE/our website https://openpgpjs.org/ for more information. */
1
+ /*! OpenPGP.js v5.5.0 - 2022-10-31 - 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
 
@@ -1773,7 +1773,7 @@ var openpgp = (function (exports) {
1773
1773
  */
1774
1774
  printDebug: function (str) {
1775
1775
  if (debugMode) {
1776
- console.log(str);
1776
+ console.log('[OpenPGP.js debug]', str);
1777
1777
  }
1778
1778
  },
1779
1779
 
@@ -1784,7 +1784,7 @@ var openpgp = (function (exports) {
1784
1784
  */
1785
1785
  printDebugError: function (error) {
1786
1786
  if (debugMode) {
1787
- console.error(error);
1787
+ console.error('[OpenPGP.js debug]', error);
1788
1788
  }
1789
1789
  },
1790
1790
 
@@ -2887,7 +2887,7 @@ var openpgp = (function (exports) {
2887
2887
  * @memberof module:config
2888
2888
  * @property {String} versionString A version string to be included in armored messages
2889
2889
  */
2890
- versionString: 'OpenPGP.js 5.4.0',
2890
+ versionString: 'OpenPGP.js 5.5.0',
2891
2891
  /**
2892
2892
  * @memberof module:config
2893
2893
  * @property {String} commentString A comment string to be included in armored messages
@@ -3104,15 +3104,17 @@ var openpgp = (function (exports) {
3104
3104
  }
3105
3105
 
3106
3106
  /**
3107
- * Verify armored headers. RFC4880, section 6.3: "OpenPGP should consider improperly formatted
3108
- * Armor Headers to be corruption of the ASCII Armor."
3107
+ * Verify armored headers. crypto-refresh-06, section 6.2:
3108
+ * "An OpenPGP implementation may consider improperly formatted Armor
3109
+ * Headers to be corruption of the ASCII Armor, but SHOULD make an
3110
+ * effort to recover."
3109
3111
  * @private
3110
3112
  * @param {Array<String>} headers - Armor headers
3111
3113
  */
3112
3114
  function verifyHeaders(headers) {
3113
3115
  for (let i = 0; i < headers.length; i++) {
3114
3116
  if (!/^([^\s:]|[^\s:][^:]*[^\s:]): .+$/.test(headers[i])) {
3115
- throw new Error('Improperly formatted armor header: ' + headers[i]);
3117
+ util.printDebugError(new Error('Improperly formatted armor header: ' + headers[i]));
3116
3118
  }
3117
3119
  if (!/^(Version|Comment|MessageID|Hash|Charset): .+$/.test(headers[i])) {
3118
3120
  util.printDebugError(new Error('Unknown header: ' + headers[i]));
@@ -3306,7 +3308,7 @@ var openpgp = (function (exports) {
3306
3308
  result.push('-----END PGP MESSAGE, PART ' + partIndex + '-----\n');
3307
3309
  break;
3308
3310
  case enums.armor.signed:
3309
- result.push('\n-----BEGIN PGP SIGNED MESSAGE-----\n');
3311
+ result.push('-----BEGIN PGP SIGNED MESSAGE-----\n');
3310
3312
  result.push('Hash: ' + hash + '\n\n');
3311
3313
  result.push(text.replace(/^-/mg, '- -'));
3312
3314
  result.push('\n-----BEGIN PGP SIGNATURE-----\n');
@@ -23257,6 +23259,11 @@ var openpgp = (function (exports) {
23257
23259
  // Add hashed subpackets
23258
23260
  arr.push(this.writeHashedSubPackets());
23259
23261
 
23262
+ // Remove unhashed subpackets, in case some allowed unhashed
23263
+ // subpackets existed, in order not to duplicate them (in both
23264
+ // the hashed and unhashed subpackets) when re-signing.
23265
+ this.unhashedSubpackets = [];
23266
+
23260
23267
  this.signatureData = util.concat(arr);
23261
23268
 
23262
23269
  const toHash = this.toHash(this.signatureType, data, detached);
@@ -23319,6 +23326,11 @@ var openpgp = (function (exports) {
23319
23326
  bytes = util.concat([bytes, this.revocationKeyFingerprint]);
23320
23327
  arr.push(writeSubPacket(sub.revocationKey, bytes));
23321
23328
  }
23329
+ if (!this.issuerKeyID.isNull() && this.issuerKeyVersion !== 5) {
23330
+ // If the version of [the] key is greater than 4, this subpacket
23331
+ // MUST NOT be included in the signature.
23332
+ arr.push(writeSubPacket(sub.issuer, this.issuerKeyID.write()));
23333
+ }
23322
23334
  this.rawNotations.forEach(([{ name, value, humanReadable }]) => {
23323
23335
  bytes = [new Uint8Array([humanReadable ? 0x80 : 0, 0, 0, 0])];
23324
23336
  // 2 octets of name length
@@ -23372,6 +23384,14 @@ var openpgp = (function (exports) {
23372
23384
  bytes = util.concat(bytes);
23373
23385
  arr.push(writeSubPacket(sub.signatureTarget, bytes));
23374
23386
  }
23387
+ if (this.embeddedSignature !== null) {
23388
+ arr.push(writeSubPacket(sub.embeddedSignature, this.embeddedSignature.write()));
23389
+ }
23390
+ if (this.issuerFingerprint !== null) {
23391
+ bytes = [new Uint8Array([this.issuerKeyVersion]), this.issuerFingerprint];
23392
+ bytes = util.concat(bytes);
23393
+ arr.push(writeSubPacket(sub.issuerFingerprint, bytes));
23394
+ }
23375
23395
  if (this.preferredAEADAlgorithms !== null) {
23376
23396
  bytes = util.stringToUint8Array(util.uint8ArrayToString(this.preferredAEADAlgorithms));
23377
23397
  arr.push(writeSubPacket(sub.preferredAEADAlgorithms, bytes));
@@ -23384,26 +23404,11 @@ var openpgp = (function (exports) {
23384
23404
  }
23385
23405
 
23386
23406
  /**
23387
- * Creates Uint8Array of bytes of Issuer and Embedded Signature subpackets
23407
+ * Creates an Uint8Array containing the unhashed subpackets
23388
23408
  * @returns {Uint8Array} Subpacket data.
23389
23409
  */
23390
23410
  writeUnhashedSubPackets() {
23391
- const sub = enums.signatureSubpacket;
23392
23411
  const arr = [];
23393
- let bytes;
23394
- if (!this.issuerKeyID.isNull() && this.issuerKeyVersion !== 5) {
23395
- // If the version of [the] key is greater than 4, this subpacket
23396
- // MUST NOT be included in the signature.
23397
- arr.push(writeSubPacket(sub.issuer, this.issuerKeyID.write()));
23398
- }
23399
- if (this.embeddedSignature !== null) {
23400
- arr.push(writeSubPacket(sub.embeddedSignature, this.embeddedSignature.write()));
23401
- }
23402
- if (this.issuerFingerprint !== null) {
23403
- bytes = [new Uint8Array([this.issuerKeyVersion]), this.issuerFingerprint];
23404
- bytes = util.concat(bytes);
23405
- arr.push(writeSubPacket(sub.issuerFingerprint, bytes));
23406
- }
23407
23412
  this.unhashedSubpackets.forEach(data => {
23408
23413
  arr.push(writeSimpleLength(data.length));
23409
23414
  arr.push(data);
@@ -23423,9 +23428,11 @@ var openpgp = (function (exports) {
23423
23428
  const critical = bytes[mypos] & 0x80;
23424
23429
  const type = bytes[mypos] & 0x7F;
23425
23430
 
23426
- if (!hashed && !allowedUnhashedSubpackets.has(type)) {
23431
+ if (!hashed) {
23427
23432
  this.unhashedSubpackets.push(bytes.subarray(mypos, bytes.length));
23428
- return;
23433
+ if (!allowedUnhashedSubpackets.has(type)) {
23434
+ return;
23435
+ }
23429
23436
  }
23430
23437
 
23431
23438
  mypos++;