@protontech/openpgp 5.3.1 → 5.4.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.3.1 - 2022-07-12 - this is LGPL licensed code, see LICENSE/our website https://openpgpjs.org/ for more information. */
1
+ /*! OpenPGP.js v5.4.0 - 2022-08-08 - 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';
@@ -2007,12 +2007,12 @@ const util = {
2007
2007
  },
2008
2008
 
2009
2009
  /**
2010
- * Remove trailing spaces and tabs from each line
2010
+ * Remove trailing spaces, carriage returns and tabs from each line
2011
2011
  */
2012
2012
  removeTrailingSpaces: function(text) {
2013
2013
  return text.split('\n').map(line => {
2014
2014
  let i = line.length - 1;
2015
- for (; i >= 0 && (line[i] === ' ' || line[i] === '\t'); i--);
2015
+ for (; i >= 0 && (line[i] === ' ' || line[i] === '\t' || line[i] === '\r'); i--);
2016
2016
  return line.substr(0, i + 1);
2017
2017
  }).join('\n');
2018
2018
  },
@@ -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.3.1',
2893
+ versionString: 'OpenPGP.js 5.4.0',
2894
2894
  /**
2895
2895
  * @memberof module:config
2896
2896
  * @property {String} commentString A comment string to be included in armored messages
@@ -14300,16 +14300,17 @@ function parsePrivateKeyParams(algo, bytes, publicParams) {
14300
14300
  }
14301
14301
  case enums.publicKey.hmac: {
14302
14302
  const { cipher: algo } = publicParams;
14303
- const keySize = hash.getHashByteLength(algo);
14303
+ const keySize = hash.getHashByteLength(algo.getValue());
14304
14304
  const hashSeed = bytes.subarray(read, read + 32); read += 32;
14305
- const key = bytes.subarray(read, read + keySize); read += keySize;
14306
- return { read, privateParams: { key, hashSeed } };
14305
+ const keyMaterial = bytes.subarray(read, read + keySize); read += keySize;
14306
+ return { read, privateParams: { hashSeed, keyMaterial } };
14307
14307
  }
14308
14308
  case enums.publicKey.aead: {
14309
14309
  const { cipher: algo } = publicParams;
14310
+ const hashSeed = bytes.subarray(read, read + 32); read += 32;
14310
14311
  const { keySize } = getCipher(algo.getValue());
14311
14312
  const keyMaterial = bytes.subarray(read, read + keySize); read += keySize;
14312
- return { read, privateParams: { keyMaterial } };
14313
+ return { read, privateParams: { hashSeed, keyMaterial } };
14313
14314
  }
14314
14315
  default:
14315
14316
  throw new UnsupportedError('Unknown public key encryption algorithm.');
@@ -14355,13 +14356,12 @@ function parseEncSessionKeyParams(algo, bytes) {
14355
14356
  // - An authentication tag generated by the AEAD mode.
14356
14357
  case enums.publicKey.aead: {
14357
14358
  const aeadMode = new AEADEnum(); read += aeadMode.read(bytes.subarray(read));
14358
- const { tagLength, ivLength } = getAEADMode(aeadMode.getValue());
14359
+ const { ivLength } = getAEADMode(aeadMode.getValue());
14359
14360
 
14360
14361
  const iv = bytes.subarray(read, read + ivLength); read += ivLength;
14361
14362
  const c = new ShortByteString(); read += c.read(bytes.subarray(read));
14362
- const t = bytes.subarray(read, read + tagLength);
14363
14363
 
14364
- return { aeadMode, iv, c, t };
14364
+ return { aeadMode, iv, c };
14365
14365
  }
14366
14366
  default:
14367
14367
  throw new UnsupportedError('Unknown public key encryption algorithm.');
@@ -14455,8 +14455,8 @@ async function createSymmetricParams(key, algo) {
14455
14455
  const bindingHash = await hash.sha256(seed);
14456
14456
  return {
14457
14457
  privateParams: {
14458
- keyMaterial: key,
14459
- hashSeed: seed
14458
+ hashSeed: seed,
14459
+ keyMaterial: key
14460
14460
  },
14461
14461
  publicParams: {
14462
14462
  cipher: algo,
@@ -14509,14 +14509,14 @@ async function validateParams$6(algo, publicParams, privateParams) {
14509
14509
  }
14510
14510
  case enums.publicKey.hmac: {
14511
14511
  const { cipher: algo, digest } = publicParams;
14512
- const { keyMaterial, hashSeed } = privateParams;
14513
- const keySize = hash.getHashByteLength(algo);
14512
+ const { hashSeed, keyMaterial } = privateParams;
14513
+ const keySize = hash.getHashByteLength(algo.getValue());
14514
14514
  return keySize === keyMaterial.length &&
14515
14515
  util.equalsUint8Array(digest, await hash.sha256(hashSeed));
14516
14516
  }
14517
14517
  case enums.publicKey.aead: {
14518
14518
  const { cipher: algo, digest } = publicParams;
14519
- const { keyMaterial, hashSeed } = privateParams;
14519
+ const { hashSeed, keyMaterial } = privateParams;
14520
14520
  const { keySize } = getCipher(algo.getValue());
14521
14521
  return keySize === keyMaterial.length &&
14522
14522
  util.equalsUint8Array(digest, await hash.sha256(hashSeed));
@@ -30500,7 +30500,7 @@ class CleartextMessage {
30500
30500
  * @param {Signature} signature - The detached signature or an empty signature for unsigned messages
30501
30501
  */
30502
30502
  constructor(text, signature) {
30503
- // normalize EOL to canonical form <CR><LF>
30503
+ // remove trailing whitespace and normalize EOL to canonical form <CR><LF>
30504
30504
  this.text = util.removeTrailingSpaces(text).replace(/\r?\n/g, '\r\n');
30505
30505
  if (signature && !(signature instanceof Signature)) {
30506
30506
  throw new Error('Invalid signature input');
@@ -30901,7 +30901,7 @@ async function encryptKey({ privateKey, passphrase, config, ...rest }) {
30901
30901
 
30902
30902
 
30903
30903
  /**
30904
- * Encrypts a message using public keys, passwords or both at once. At least one of `encryptionKeys` or `passwords`
30904
+ * Encrypts a message using public keys, passwords or both at once. At least one of `encryptionKeys`, `passwords` or `sessionKeys`
30905
30905
  * must be specified. If signing keys are specified, those will be used to sign the message.
30906
30906
  * @param {Object} options
30907
30907
  * @param {Message} options.message - Message to be encrypted as created by {@link createMessage}
@@ -31216,6 +31216,10 @@ async function encryptSessionKey({ data, algorithm, aeadAlgorithm, encryptionKey
31216
31216
  if (rest.publicKeys) throw new Error('The `publicKeys` option has been removed from openpgp.encryptSessionKey, pass `encryptionKeys` instead');
31217
31217
  const unknownOptions = Object.keys(rest); if (unknownOptions.length > 0) throw new Error(`Unknown option: ${unknownOptions.join(', ')}`);
31218
31218
 
31219
+ if ((!encryptionKeys || encryptionKeys.length === 0) && (!passwords || passwords.length === 0)) {
31220
+ throw new Error('No encryption keys or passwords provided.');
31221
+ }
31222
+
31219
31223
  try {
31220
31224
  const message = await Message.encryptSessionKey(data, algorithm, aeadAlgorithm, encryptionKeys, passwords, wildcard, encryptionKeyIDs, date, encryptionUserIDs, config);
31221
31225
  return formatObject(message, format, config);
package/dist/openpgp.js 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.4.0 - 2022-08-08 - 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
 
@@ -2004,12 +2004,12 @@ var openpgp = (function (exports) {
2004
2004
  },
2005
2005
 
2006
2006
  /**
2007
- * Remove trailing spaces and tabs from each line
2007
+ * Remove trailing spaces, carriage returns and tabs from each line
2008
2008
  */
2009
2009
  removeTrailingSpaces: function(text) {
2010
2010
  return text.split('\n').map(line => {
2011
2011
  let i = line.length - 1;
2012
- for (; i >= 0 && (line[i] === ' ' || line[i] === '\t'); i--);
2012
+ for (; i >= 0 && (line[i] === ' ' || line[i] === '\t' || line[i] === '\r'); i--);
2013
2013
  return line.substr(0, i + 1);
2014
2014
  }).join('\n');
2015
2015
  },
@@ -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.3.1',
2890
+ versionString: 'OpenPGP.js 5.4.0',
2891
2891
  /**
2892
2892
  * @memberof module:config
2893
2893
  * @property {String} commentString A comment string to be included in armored messages
@@ -14291,16 +14291,17 @@ var openpgp = (function (exports) {
14291
14291
  }
14292
14292
  case enums.publicKey.hmac: {
14293
14293
  const { cipher: algo } = publicParams;
14294
- const keySize = hash.getHashByteLength(algo);
14294
+ const keySize = hash.getHashByteLength(algo.getValue());
14295
14295
  const hashSeed = bytes.subarray(read, read + 32); read += 32;
14296
- const key = bytes.subarray(read, read + keySize); read += keySize;
14297
- return { read, privateParams: { key, hashSeed } };
14296
+ const keyMaterial = bytes.subarray(read, read + keySize); read += keySize;
14297
+ return { read, privateParams: { hashSeed, keyMaterial } };
14298
14298
  }
14299
14299
  case enums.publicKey.aead: {
14300
14300
  const { cipher: algo } = publicParams;
14301
+ const hashSeed = bytes.subarray(read, read + 32); read += 32;
14301
14302
  const { keySize } = getCipher(algo.getValue());
14302
14303
  const keyMaterial = bytes.subarray(read, read + keySize); read += keySize;
14303
- return { read, privateParams: { keyMaterial } };
14304
+ return { read, privateParams: { hashSeed, keyMaterial } };
14304
14305
  }
14305
14306
  default:
14306
14307
  throw new UnsupportedError('Unknown public key encryption algorithm.');
@@ -14346,13 +14347,12 @@ var openpgp = (function (exports) {
14346
14347
  // - An authentication tag generated by the AEAD mode.
14347
14348
  case enums.publicKey.aead: {
14348
14349
  const aeadMode = new AEADEnum(); read += aeadMode.read(bytes.subarray(read));
14349
- const { tagLength, ivLength } = getAEADMode(aeadMode.getValue());
14350
+ const { ivLength } = getAEADMode(aeadMode.getValue());
14350
14351
 
14351
14352
  const iv = bytes.subarray(read, read + ivLength); read += ivLength;
14352
14353
  const c = new ShortByteString(); read += c.read(bytes.subarray(read));
14353
- const t = bytes.subarray(read, read + tagLength);
14354
14354
 
14355
- return { aeadMode, iv, c, t };
14355
+ return { aeadMode, iv, c };
14356
14356
  }
14357
14357
  default:
14358
14358
  throw new UnsupportedError('Unknown public key encryption algorithm.');
@@ -14446,8 +14446,8 @@ var openpgp = (function (exports) {
14446
14446
  const bindingHash = await hash.sha256(seed);
14447
14447
  return {
14448
14448
  privateParams: {
14449
- keyMaterial: key,
14450
- hashSeed: seed
14449
+ hashSeed: seed,
14450
+ keyMaterial: key
14451
14451
  },
14452
14452
  publicParams: {
14453
14453
  cipher: algo,
@@ -14500,14 +14500,14 @@ var openpgp = (function (exports) {
14500
14500
  }
14501
14501
  case enums.publicKey.hmac: {
14502
14502
  const { cipher: algo, digest } = publicParams;
14503
- const { keyMaterial, hashSeed } = privateParams;
14504
- const keySize = hash.getHashByteLength(algo);
14503
+ const { hashSeed, keyMaterial } = privateParams;
14504
+ const keySize = hash.getHashByteLength(algo.getValue());
14505
14505
  return keySize === keyMaterial.length &&
14506
14506
  util.equalsUint8Array(digest, await hash.sha256(hashSeed));
14507
14507
  }
14508
14508
  case enums.publicKey.aead: {
14509
14509
  const { cipher: algo, digest } = publicParams;
14510
- const { keyMaterial, hashSeed } = privateParams;
14510
+ const { hashSeed, keyMaterial } = privateParams;
14511
14511
  const { keySize } = getCipher(algo.getValue());
14512
14512
  return keySize === keyMaterial.length &&
14513
14513
  util.equalsUint8Array(digest, await hash.sha256(hashSeed));
@@ -30491,7 +30491,7 @@ var openpgp = (function (exports) {
30491
30491
  * @param {Signature} signature - The detached signature or an empty signature for unsigned messages
30492
30492
  */
30493
30493
  constructor(text, signature) {
30494
- // normalize EOL to canonical form <CR><LF>
30494
+ // remove trailing whitespace and normalize EOL to canonical form <CR><LF>
30495
30495
  this.text = util.removeTrailingSpaces(text).replace(/\r?\n/g, '\r\n');
30496
30496
  if (signature && !(signature instanceof Signature)) {
30497
30497
  throw new Error('Invalid signature input');
@@ -30892,7 +30892,7 @@ var openpgp = (function (exports) {
30892
30892
 
30893
30893
 
30894
30894
  /**
30895
- * Encrypts a message using public keys, passwords or both at once. At least one of `encryptionKeys` or `passwords`
30895
+ * Encrypts a message using public keys, passwords or both at once. At least one of `encryptionKeys`, `passwords` or `sessionKeys`
30896
30896
  * must be specified. If signing keys are specified, those will be used to sign the message.
30897
30897
  * @param {Object} options
30898
30898
  * @param {Message} options.message - Message to be encrypted as created by {@link createMessage}
@@ -31207,6 +31207,10 @@ var openpgp = (function (exports) {
31207
31207
  if (rest.publicKeys) throw new Error('The `publicKeys` option has been removed from openpgp.encryptSessionKey, pass `encryptionKeys` instead');
31208
31208
  const unknownOptions = Object.keys(rest); if (unknownOptions.length > 0) throw new Error(`Unknown option: ${unknownOptions.join(', ')}`);
31209
31209
 
31210
+ if ((!encryptionKeys || encryptionKeys.length === 0) && (!passwords || passwords.length === 0)) {
31211
+ throw new Error('No encryption keys or passwords provided.');
31212
+ }
31213
+
31210
31214
  try {
31211
31215
  const message = await Message.encryptSessionKey(data, algorithm, aeadAlgorithm, encryptionKeys, passwords, wildcard, encryptionKeyIDs, date, encryptionUserIDs, config);
31212
31216
  return formatObject(message, format, config);