@protontech/openpgp 5.3.1 → 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.
package/dist/openpgp.mjs CHANGED
@@ -1,4 +1,4 @@
1
- /*! OpenPGP.js v5.3.1 - 2022-07-12 - 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
  const doneWritingPromise = Symbol('doneWritingPromise');
@@ -1770,7 +1770,7 @@ const util = {
1770
1770
  */
1771
1771
  printDebug: function (str) {
1772
1772
  if (debugMode) {
1773
- console.log(str);
1773
+ console.log('[OpenPGP.js debug]', str);
1774
1774
  }
1775
1775
  },
1776
1776
 
@@ -1781,7 +1781,7 @@ const util = {
1781
1781
  */
1782
1782
  printDebugError: function (error) {
1783
1783
  if (debugMode) {
1784
- console.error(error);
1784
+ console.error('[OpenPGP.js debug]', error);
1785
1785
  }
1786
1786
  },
1787
1787
 
@@ -2001,12 +2001,12 @@ const util = {
2001
2001
  },
2002
2002
 
2003
2003
  /**
2004
- * Remove trailing spaces and tabs from each line
2004
+ * Remove trailing spaces, carriage returns and tabs from each line
2005
2005
  */
2006
2006
  removeTrailingSpaces: function(text) {
2007
2007
  return text.split('\n').map(line => {
2008
2008
  let i = line.length - 1;
2009
- for (; i >= 0 && (line[i] === ' ' || line[i] === '\t'); i--);
2009
+ for (; i >= 0 && (line[i] === ' ' || line[i] === '\t' || line[i] === '\r'); i--);
2010
2010
  return line.substr(0, i + 1);
2011
2011
  }).join('\n');
2012
2012
  },
@@ -2884,7 +2884,7 @@ var defaultConfig = {
2884
2884
  * @memberof module:config
2885
2885
  * @property {String} versionString A version string to be included in armored messages
2886
2886
  */
2887
- versionString: 'OpenPGP.js 5.3.1',
2887
+ versionString: 'OpenPGP.js 5.5.0',
2888
2888
  /**
2889
2889
  * @memberof module:config
2890
2890
  * @property {String} commentString A comment string to be included in armored messages
@@ -3101,15 +3101,17 @@ function createcrc24(input) {
3101
3101
  }
3102
3102
 
3103
3103
  /**
3104
- * Verify armored headers. RFC4880, section 6.3: "OpenPGP should consider improperly formatted
3105
- * Armor Headers to be corruption of the ASCII Armor."
3104
+ * Verify armored headers. crypto-refresh-06, section 6.2:
3105
+ * "An OpenPGP implementation may consider improperly formatted Armor
3106
+ * Headers to be corruption of the ASCII Armor, but SHOULD make an
3107
+ * effort to recover."
3106
3108
  * @private
3107
3109
  * @param {Array<String>} headers - Armor headers
3108
3110
  */
3109
3111
  function verifyHeaders(headers) {
3110
3112
  for (let i = 0; i < headers.length; i++) {
3111
3113
  if (!/^([^\s:]|[^\s:][^:]*[^\s:]): .+$/.test(headers[i])) {
3112
- throw new Error('Improperly formatted armor header: ' + headers[i]);
3114
+ util.printDebugError(new Error('Improperly formatted armor header: ' + headers[i]));
3113
3115
  }
3114
3116
  if (!/^(Version|Comment|MessageID|Hash|Charset): .+$/.test(headers[i])) {
3115
3117
  util.printDebugError(new Error('Unknown header: ' + headers[i]));
@@ -3303,7 +3305,7 @@ function armor(messageType, body, partIndex, partTotal, customComment, config =
3303
3305
  result.push('-----END PGP MESSAGE, PART ' + partIndex + '-----\n');
3304
3306
  break;
3305
3307
  case enums.armor.signed:
3306
- result.push('\n-----BEGIN PGP SIGNED MESSAGE-----\n');
3308
+ result.push('-----BEGIN PGP SIGNED MESSAGE-----\n');
3307
3309
  result.push('Hash: ' + hash + '\n\n');
3308
3310
  result.push(text.replace(/^-/mg, '- -'));
3309
3311
  result.push('\n-----BEGIN PGP SIGNATURE-----\n');
@@ -14288,16 +14290,17 @@ function parsePrivateKeyParams(algo, bytes, publicParams) {
14288
14290
  }
14289
14291
  case enums.publicKey.hmac: {
14290
14292
  const { cipher: algo } = publicParams;
14291
- const keySize = hash.getHashByteLength(algo);
14293
+ const keySize = hash.getHashByteLength(algo.getValue());
14292
14294
  const hashSeed = bytes.subarray(read, read + 32); read += 32;
14293
- const key = bytes.subarray(read, read + keySize); read += keySize;
14294
- return { read, privateParams: { key, hashSeed } };
14295
+ const keyMaterial = bytes.subarray(read, read + keySize); read += keySize;
14296
+ return { read, privateParams: { hashSeed, keyMaterial } };
14295
14297
  }
14296
14298
  case enums.publicKey.aead: {
14297
14299
  const { cipher: algo } = publicParams;
14300
+ const hashSeed = bytes.subarray(read, read + 32); read += 32;
14298
14301
  const { keySize } = getCipher(algo.getValue());
14299
14302
  const keyMaterial = bytes.subarray(read, read + keySize); read += keySize;
14300
- return { read, privateParams: { keyMaterial } };
14303
+ return { read, privateParams: { hashSeed, keyMaterial } };
14301
14304
  }
14302
14305
  default:
14303
14306
  throw new UnsupportedError('Unknown public key encryption algorithm.');
@@ -14343,13 +14346,12 @@ function parseEncSessionKeyParams(algo, bytes) {
14343
14346
  // - An authentication tag generated by the AEAD mode.
14344
14347
  case enums.publicKey.aead: {
14345
14348
  const aeadMode = new AEADEnum(); read += aeadMode.read(bytes.subarray(read));
14346
- const { tagLength, ivLength } = getAEADMode(aeadMode.getValue());
14349
+ const { ivLength } = getAEADMode(aeadMode.getValue());
14347
14350
 
14348
14351
  const iv = bytes.subarray(read, read + ivLength); read += ivLength;
14349
14352
  const c = new ShortByteString(); read += c.read(bytes.subarray(read));
14350
- const t = bytes.subarray(read, read + tagLength);
14351
14353
 
14352
- return { aeadMode, iv, c, t };
14354
+ return { aeadMode, iv, c };
14353
14355
  }
14354
14356
  default:
14355
14357
  throw new UnsupportedError('Unknown public key encryption algorithm.');
@@ -14443,8 +14445,8 @@ async function createSymmetricParams(key, algo) {
14443
14445
  const bindingHash = await hash.sha256(seed);
14444
14446
  return {
14445
14447
  privateParams: {
14446
- keyMaterial: key,
14447
- hashSeed: seed
14448
+ hashSeed: seed,
14449
+ keyMaterial: key
14448
14450
  },
14449
14451
  publicParams: {
14450
14452
  cipher: algo,
@@ -14497,14 +14499,14 @@ async function validateParams$6(algo, publicParams, privateParams) {
14497
14499
  }
14498
14500
  case enums.publicKey.hmac: {
14499
14501
  const { cipher: algo, digest } = publicParams;
14500
- const { keyMaterial, hashSeed } = privateParams;
14501
- const keySize = hash.getHashByteLength(algo);
14502
+ const { hashSeed, keyMaterial } = privateParams;
14503
+ const keySize = hash.getHashByteLength(algo.getValue());
14502
14504
  return keySize === keyMaterial.length &&
14503
14505
  util.equalsUint8Array(digest, await hash.sha256(hashSeed));
14504
14506
  }
14505
14507
  case enums.publicKey.aead: {
14506
14508
  const { cipher: algo, digest } = publicParams;
14507
- const { keyMaterial, hashSeed } = privateParams;
14509
+ const { hashSeed, keyMaterial } = privateParams;
14508
14510
  const { keySize } = getCipher(algo.getValue());
14509
14511
  return keySize === keyMaterial.length &&
14510
14512
  util.equalsUint8Array(digest, await hash.sha256(hashSeed));
@@ -23254,6 +23256,11 @@ class SignaturePacket {
23254
23256
  // Add hashed subpackets
23255
23257
  arr.push(this.writeHashedSubPackets());
23256
23258
 
23259
+ // Remove unhashed subpackets, in case some allowed unhashed
23260
+ // subpackets existed, in order not to duplicate them (in both
23261
+ // the hashed and unhashed subpackets) when re-signing.
23262
+ this.unhashedSubpackets = [];
23263
+
23257
23264
  this.signatureData = util.concat(arr);
23258
23265
 
23259
23266
  const toHash = this.toHash(this.signatureType, data, detached);
@@ -23316,6 +23323,11 @@ class SignaturePacket {
23316
23323
  bytes = util.concat([bytes, this.revocationKeyFingerprint]);
23317
23324
  arr.push(writeSubPacket(sub.revocationKey, bytes));
23318
23325
  }
23326
+ if (!this.issuerKeyID.isNull() && this.issuerKeyVersion !== 5) {
23327
+ // If the version of [the] key is greater than 4, this subpacket
23328
+ // MUST NOT be included in the signature.
23329
+ arr.push(writeSubPacket(sub.issuer, this.issuerKeyID.write()));
23330
+ }
23319
23331
  this.rawNotations.forEach(([{ name, value, humanReadable }]) => {
23320
23332
  bytes = [new Uint8Array([humanReadable ? 0x80 : 0, 0, 0, 0])];
23321
23333
  // 2 octets of name length
@@ -23369,6 +23381,14 @@ class SignaturePacket {
23369
23381
  bytes = util.concat(bytes);
23370
23382
  arr.push(writeSubPacket(sub.signatureTarget, bytes));
23371
23383
  }
23384
+ if (this.embeddedSignature !== null) {
23385
+ arr.push(writeSubPacket(sub.embeddedSignature, this.embeddedSignature.write()));
23386
+ }
23387
+ if (this.issuerFingerprint !== null) {
23388
+ bytes = [new Uint8Array([this.issuerKeyVersion]), this.issuerFingerprint];
23389
+ bytes = util.concat(bytes);
23390
+ arr.push(writeSubPacket(sub.issuerFingerprint, bytes));
23391
+ }
23372
23392
  if (this.preferredAEADAlgorithms !== null) {
23373
23393
  bytes = util.stringToUint8Array(util.uint8ArrayToString(this.preferredAEADAlgorithms));
23374
23394
  arr.push(writeSubPacket(sub.preferredAEADAlgorithms, bytes));
@@ -23381,26 +23401,11 @@ class SignaturePacket {
23381
23401
  }
23382
23402
 
23383
23403
  /**
23384
- * Creates Uint8Array of bytes of Issuer and Embedded Signature subpackets
23404
+ * Creates an Uint8Array containing the unhashed subpackets
23385
23405
  * @returns {Uint8Array} Subpacket data.
23386
23406
  */
23387
23407
  writeUnhashedSubPackets() {
23388
- const sub = enums.signatureSubpacket;
23389
23408
  const arr = [];
23390
- let bytes;
23391
- if (!this.issuerKeyID.isNull() && this.issuerKeyVersion !== 5) {
23392
- // If the version of [the] key is greater than 4, this subpacket
23393
- // MUST NOT be included in the signature.
23394
- arr.push(writeSubPacket(sub.issuer, this.issuerKeyID.write()));
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
- }
23404
23409
  this.unhashedSubpackets.forEach(data => {
23405
23410
  arr.push(writeSimpleLength(data.length));
23406
23411
  arr.push(data);
@@ -23420,9 +23425,11 @@ class SignaturePacket {
23420
23425
  const critical = bytes[mypos] & 0x80;
23421
23426
  const type = bytes[mypos] & 0x7F;
23422
23427
 
23423
- if (!hashed && !allowedUnhashedSubpackets.has(type)) {
23428
+ if (!hashed) {
23424
23429
  this.unhashedSubpackets.push(bytes.subarray(mypos, bytes.length));
23425
- return;
23430
+ if (!allowedUnhashedSubpackets.has(type)) {
23431
+ return;
23432
+ }
23426
23433
  }
23427
23434
 
23428
23435
  mypos++;
@@ -30488,7 +30495,7 @@ class CleartextMessage {
30488
30495
  * @param {Signature} signature - The detached signature or an empty signature for unsigned messages
30489
30496
  */
30490
30497
  constructor(text, signature) {
30491
- // normalize EOL to canonical form <CR><LF>
30498
+ // remove trailing whitespace and normalize EOL to canonical form <CR><LF>
30492
30499
  this.text = util.removeTrailingSpaces(text).replace(/\r?\n/g, '\r\n');
30493
30500
  if (signature && !(signature instanceof Signature)) {
30494
30501
  throw new Error('Invalid signature input');
@@ -30889,7 +30896,7 @@ async function encryptKey({ privateKey, passphrase, config, ...rest }) {
30889
30896
 
30890
30897
 
30891
30898
  /**
30892
- * Encrypts a message using public keys, passwords or both at once. At least one of `encryptionKeys` or `passwords`
30899
+ * Encrypts a message using public keys, passwords or both at once. At least one of `encryptionKeys`, `passwords` or `sessionKeys`
30893
30900
  * must be specified. If signing keys are specified, those will be used to sign the message.
30894
30901
  * @param {Object} options
30895
30902
  * @param {Message} options.message - Message to be encrypted as created by {@link createMessage}
@@ -31204,6 +31211,10 @@ async function encryptSessionKey({ data, algorithm, aeadAlgorithm, encryptionKey
31204
31211
  if (rest.publicKeys) throw new Error('The `publicKeys` option has been removed from openpgp.encryptSessionKey, pass `encryptionKeys` instead');
31205
31212
  const unknownOptions = Object.keys(rest); if (unknownOptions.length > 0) throw new Error(`Unknown option: ${unknownOptions.join(', ')}`);
31206
31213
 
31214
+ if ((!encryptionKeys || encryptionKeys.length === 0) && (!passwords || passwords.length === 0)) {
31215
+ throw new Error('No encryption keys or passwords provided.');
31216
+ }
31217
+
31207
31218
  try {
31208
31219
  const message = await Message.encryptSessionKey(data, algorithm, aeadAlgorithm, encryptionKeys, passwords, wildcard, encryptionKeyIDs, date, encryptionUserIDs, config);
31209
31220
  return formatObject(message, format, config);
package/openpgp.d.ts CHANGED
@@ -322,6 +322,7 @@ interface Config {
322
322
  versionString: string;
323
323
  commentString: string;
324
324
  allowInsecureDecryptionWithSigningKeys: boolean;
325
+ allowInsecureVerificationWithReformattedKeys: boolean;
325
326
  constantTimePKCS1Decryption: boolean;
326
327
  constantTimePKCS1DecryptionSupportedSymmetricAlgorithms: Set<enums.symmetric>;
327
328
  v5Keys: boolean;
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.3.1",
4
+ "version": "5.5.0",
5
5
  "license": "LGPL-3.0+",
6
6
  "homepage": "https://openpgpjs.org/",
7
7
  "engines": {