Finish merging key validation

This commit is contained in:
larabr 2020-07-17 14:19:03 +02:00 committed by Daniel Huigens
parent b9afd26912
commit f6ee6e959e
5 changed files with 297 additions and 293 deletions

View File

@ -198,7 +198,7 @@ class SecretKeyPacket extends PublicKeyPacket {
} }
arr.push(new Uint8Array(optionalFieldsArr)); arr.push(new Uint8Array(optionalFieldsArr));
if (!this.s2k || this.s2k.type !== 'gnu-dummy') { if (!this.isDummy()) {
if (!this.s2k_usage) { if (!this.s2k_usage) {
const cleartextParams = write_cleartext_params(this.params, this.algorithm); const cleartextParams = write_cleartext_params(this.params, this.algorithm);
this.keyMaterial = util.concatUint8Array([ this.keyMaterial = util.concatUint8Array([
@ -395,7 +395,7 @@ class SecretKeyPacket extends PublicKeyPacket {
* Clear private key parameters * Clear private key parameters
*/ */
clearPrivateParams() { clearPrivateParams() {
if (this.s2k && this.s2k.type === 'gnu-dummy') { if (this.isDummy()) {
this.isEncrypted = true; this.isEncrypted = true;
return; return;
} }

View File

@ -10,5 +10,5 @@ module.exports = () => describe('Crypto', function () {
require('./eax.js')(); require('./eax.js')();
require('./ocb.js')(); require('./ocb.js')();
require('./rsa.js')(); require('./rsa.js')();
require('./validate.js'); require('./validate.js')();
}); });

View File

@ -1,4 +1,4 @@
const openpgp = typeof window !== 'undefined' && window.openpgp ? window.openpgp : require('../../dist/openpgp'); const openpgp = typeof window !== 'undefined' && window.openpgp ? window.openpgp : require('../..');
const chai = require('chai'); const chai = require('chai');
const BN = require('bn.js'); const BN = require('bn.js');
@ -74,6 +74,7 @@ vqBGKJzmO5q3cECw
=X9kJ =X9kJ
-----END PGP PRIVATE KEY BLOCK-----`; -----END PGP PRIVATE KEY BLOCK-----`;
module.exports = () => {
describe('EdDSA parameter validation', function() { describe('EdDSA parameter validation', function() {
let keyParams; let keyParams;
before(async () => { before(async () => {
@ -208,7 +209,7 @@ curves.forEach(curve => {
describe('RSA parameter validation', function() { describe('RSA parameter validation', function() {
let keyParams; let keyParams;
before(async () => { before(async () => {
keyParams = await openpgp.crypto.generateParams(openpgp.enums.publicKey.rsa_sign, 2048); keyParams = await openpgp.crypto.generateParams(openpgp.enums.publicKey.rsaSign, 2048);
}); });
it('generated RSA params are valid', async function() { it('generated RSA params are valid', async function() {
@ -252,7 +253,7 @@ describe('RSA parameter validation', function() {
describe('DSA parameter validation', function() { describe('DSA parameter validation', function() {
let dsaKey; let dsaKey;
before(async () => { before(async () => {
dsaKey = (await openpgp.key.readArmored(armoredDSAKey)).keys[0]; dsaKey = await openpgp.key.readArmored(armoredDSAKey);
}); });
it('DSA params should be valid', async function() { it('DSA params should be valid', async function() {
@ -315,7 +316,7 @@ describe('DSA parameter validation', function() {
describe('ElGamal parameter validation', function() { describe('ElGamal parameter validation', function() {
let egKey; let egKey;
before(async () => { before(async () => {
egKey = (await openpgp.key.readArmored(armoredElGamalKey)).keys[0].subKeys[0]; egKey = (await openpgp.key.readArmored(armoredElGamalKey)).subKeys[0];
}); });
it('params should be valid', async function() { it('params should be valid', async function() {
@ -385,3 +386,4 @@ describe('ElGamal parameter validation', function() {
expect(valid).to.be.false; expect(valid).to.be.false;
}); });
}); });
};

View File

@ -2861,7 +2861,7 @@ module.exports = () => describe('Key', function() {
}); });
it('clearPrivateParams() - detect that private key parameters were zeroed out', async function() { it('clearPrivateParams() - detect that private key parameters were zeroed out', async function() {
const { keys: [key] } = await openpgp.key.readArmored(priv_key_rsa); const key = await openpgp.key.readArmored(priv_key_rsa);
await key.decrypt('hello world'); await key.decrypt('hello world');
const signingKeyPacket = key.subKeys[0].keyPacket; const signingKeyPacket = key.subKeys[0].keyPacket;
const params = signingKeyPacket.params.slice(); const params = signingKeyPacket.params.slice();

View File

@ -740,7 +740,7 @@ module.exports = () => describe('OpenPGP.js public api tests', function() {
privateKeys: privateKey privateKeys: privateKey
}; };
const encrypted = await openpgp.encrypt(encOpt); const encrypted = await openpgp.encrypt(encOpt);
decOpt.message = await openpgp.message.readArmored(encrypted.data); decOpt.message = await openpgp.message.readArmored(encrypted);
await expect(openpgp.decrypt(decOpt)).to.be.rejectedWith('Error decrypting message: Private key is not decrypted.'); await expect(openpgp.decrypt(decOpt)).to.be.rejectedWith('Error decrypting message: Private key is not decrypted.');
}); });
@ -842,12 +842,14 @@ module.exports = () => describe('OpenPGP.js public api tests', function() {
return openpgp.encryptSessionKey({ return openpgp.encryptSessionKey({
data: sk, data: sk,
algorithm: 'aes128', algorithm: 'aes128',
publicKeys: publicKey.keys publicKeys: publicKey,
armor: false
}).then(async function(encrypted) { }).then(async function(encrypted) {
const invalidPrivateKey = (await openpgp.key.readArmored(priv_key)).keys[0]; const message = await openpgp.message.read(encrypted);
const invalidPrivateKey = await openpgp.key.readArmored(priv_key);
invalidPrivateKey.subKeys[0].bindingSignatures = []; invalidPrivateKey.subKeys[0].bindingSignatures = [];
return openpgp.decryptSessionKeys({ return openpgp.decryptSessionKeys({
message: encrypted.message, message,
privateKeys: invalidPrivateKey privateKeys: invalidPrivateKey
}).then(() => { }).then(() => {
throw new Error('Should not decrypt with invalid key'); throw new Error('Should not decrypt with invalid key');