remove excess compression testing, fix cleartext signing with multiple keys test

This commit is contained in:
Bart Butler 2018-02-14 15:19:52 -08:00
parent c8adaff826
commit 7e1731f2bb

View File

@ -617,13 +617,12 @@ describe('OpenPGP.js public api tests', function() {
});
});
withCompression(function (modifyCompressionEncryptOptions, verifyCompressionDecrypted) {
it('roundtrip workflow: encrypt, decryptSessionKeys, decrypt with pgp key pair', function () {
let msgAsciiArmored;
return openpgp.encrypt(modifyCompressionEncryptOptions({
return openpgp.encrypt({
data: plaintext,
publicKeys: publicKey.keys
})).then(function (encrypted) {
}).then(function (encrypted) {
msgAsciiArmored = encrypted.data;
return openpgp.decryptSessionKeys({
message: openpgp.message.readArmored(msgAsciiArmored),
@ -638,16 +637,15 @@ describe('OpenPGP.js public api tests', function() {
});
}).then(function (decrypted) {
expect(decrypted.data).to.equal(plaintext);
verifyCompressionDecrypted(decrypted);
});
});
it('roundtrip workflow: encrypt, decryptSessionKeys, decrypt with password', function () {
let msgAsciiArmored;
return openpgp.encrypt(modifyCompressionEncryptOptions({
return openpgp.encrypt({
data: plaintext,
passwords: password1
})).then(function (encrypted) {
}).then(function (encrypted) {
msgAsciiArmored = encrypted.data;
return openpgp.decryptSessionKeys({
message: openpgp.message.readArmored(msgAsciiArmored),
@ -662,16 +660,15 @@ describe('OpenPGP.js public api tests', function() {
}).then(function (decrypted) {
expect(decrypted.data).to.equal(plaintext);
verifyCompressionDecrypted(decrypted);
});
});
it('roundtrip workflow: encrypt with multiple passwords, decryptSessionKeys, decrypt with multiple passwords', function () {
let msgAsciiArmored;
return openpgp.encrypt(modifyCompressionEncryptOptions({
return openpgp.encrypt({
data: plaintext,
passwords: [password1, password2]
})).then(function (encrypted) {
}).then(function (encrypted) {
msgAsciiArmored = encrypted.data;
return openpgp.decryptSessionKeys({
message: openpgp.message.readArmored(msgAsciiArmored),
@ -686,16 +683,15 @@ describe('OpenPGP.js public api tests', function() {
}).then(function (decrypted) {
expect(decrypted.data).to.equal(plaintext);
verifyCompressionDecrypted(decrypted);
});
});
it('roundtrip workflow: encrypt twice with one password, decryptSessionKeys, only one session key', function () {
let msgAsciiArmored;
return openpgp.encrypt(modifyCompressionEncryptOptions({
return openpgp.encrypt({
data: plaintext,
passwords: [password1, password1]
})).then(function (encrypted) {
}).then(function (encrypted) {
msgAsciiArmored = encrypted.data;
return openpgp.decryptSessionKeys({
message: openpgp.message.readArmored(msgAsciiArmored),
@ -709,8 +705,6 @@ describe('OpenPGP.js public api tests', function() {
});
}).then(function (decrypted) {
expect(decrypted.data).to.equal(plaintext);
verifyCompressionDecrypted(decrypted);
});
});
});
});
@ -733,12 +727,11 @@ describe('OpenPGP.js public api tests', function() {
privateKey.keys[0].verifyPrimaryUser().then(() => done());
});
withCompression(function (modifyCompressionEncryptOptions, verifyCompressionDecrypted) {
it('should encrypt then decrypt', function () {
const encOpt = modifyCompressionEncryptOptions({
const encOpt = {
data: plaintext,
publicKeys: publicKey.keys
});
};
const decOpt = {
privateKeys: privateKey.keys
};
@ -750,15 +743,14 @@ describe('OpenPGP.js public api tests', function() {
expect(decrypted.data).to.equal(plaintext);
expect(decrypted.signatures).to.exist;
expect(decrypted.signatures.length).to.equal(0);
verifyCompressionDecrypted(decrypted);
});
});
it('should encrypt then decrypt', function () {
const encOpt = modifyCompressionEncryptOptions({
const encOpt = {
data: plaintext,
publicKeys: publicKey.keys
});
};
const decOpt = {
privateKeys: privateKey.keys
};
@ -770,7 +762,6 @@ describe('OpenPGP.js public api tests', function() {
expect(decrypted.data).to.equal(plaintext);
expect(decrypted.signatures).to.exist;
expect(decrypted.signatures.length).to.equal(0);
verifyCompressionDecrypted(decrypted);
});
});
@ -778,10 +769,10 @@ describe('OpenPGP.js public api tests', function() {
const privKeyDE = openpgp.key.readArmored(priv_key_de).keys[0];
privKeyDE.decrypt(passphrase);
const encOpt = modifyCompressionEncryptOptions({
const encOpt = {
data: plaintext,
publicKeys: publicKey.keys
});
};
const decOpt = {
privateKeys: [privKeyDE, privateKey.keys[0]]
};
@ -793,16 +784,15 @@ describe('OpenPGP.js public api tests', function() {
expect(decrypted.data).to.equal(plaintext);
expect(decrypted.signatures).to.exist;
expect(decrypted.signatures.length).to.equal(0);
verifyCompressionDecrypted(decrypted);
});
});
it('should encrypt then decrypt with wildcard', function () {
const encOpt = modifyCompressionEncryptOptions({
const encOpt = {
data: plaintext,
publicKeys: publicKey.keys,
wildcard: true
});
};
const decOpt = {
privateKeys: privateKey.keys
};
@ -814,7 +804,6 @@ describe('OpenPGP.js public api tests', function() {
expect(decrypted.data).to.equal(plaintext);
expect(decrypted.signatures).to.exist;
expect(decrypted.signatures.length).to.equal(0);
verifyCompressionDecrypted(decrypted);
});
});
@ -822,11 +811,11 @@ describe('OpenPGP.js public api tests', function() {
const privKeyDE = openpgp.key.readArmored(priv_key_de).keys[0];
privKeyDE.decrypt(passphrase);
const encOpt = modifyCompressionEncryptOptions({
const encOpt = {
data: plaintext,
publicKeys: publicKey.keys,
wildcard: true
});
};
const decOpt = {
privateKeys: [privKeyDE, privateKey.keys[0]]
};
@ -838,16 +827,15 @@ describe('OpenPGP.js public api tests', function() {
expect(decrypted.data).to.equal(plaintext);
expect(decrypted.signatures).to.exist;
expect(decrypted.signatures.length).to.equal(0);
verifyCompressionDecrypted(decrypted);
});
});
it('should encrypt then decrypt using returned session key', function () {
const encOpt = modifyCompressionEncryptOptions({
const encOpt = {
data: plaintext,
publicKeys: publicKey.keys,
returnSessionKey: true
});
};
return openpgp.encrypt(encOpt).then(function (encrypted) {
expect(encrypted.data).to.match(/^-----BEGIN PGP MESSAGE/);
@ -860,7 +848,6 @@ describe('OpenPGP.js public api tests', function() {
expect(decrypted.data).to.equal(plaintext);
expect(decrypted.signatures).to.exist;
expect(decrypted.signatures.length).to.equal(0);
verifyCompressionDecrypted(decrypted);
});
});
@ -869,11 +856,11 @@ describe('OpenPGP.js public api tests', function() {
data: openpgp.crypto.generateSessionKey('aes256'),
algorithm: 'aes256'
};
const encOpt = modifyCompressionEncryptOptions({
const encOpt = {
data: plaintext,
sessionKey: sessionKey,
publicKeys: publicKey.keys
});
};
const decOpt = {
sessionKeys: sessionKey
};
@ -883,7 +870,6 @@ describe('OpenPGP.js public api tests', function() {
return openpgp.decrypt(decOpt);
}).then(function (decrypted) {
expect(decrypted.data).to.equal(plaintext);
verifyCompressionDecrypted(decrypted);
});
});
@ -892,11 +878,11 @@ describe('OpenPGP.js public api tests', function() {
data: openpgp.crypto.generateSessionKey('aes128'),
algorithm: 'aes128'
};
const encOpt = modifyCompressionEncryptOptions({
const encOpt = {
data: plaintext,
sessionKeys: sessionKey,
publicKeys: publicKey.keys
});
};
const decOpt = {
privateKeys: privateKey.keys[0]
};
@ -906,16 +892,15 @@ describe('OpenPGP.js public api tests', function() {
return openpgp.decrypt(decOpt);
}).then(function (decrypted) {
expect(decrypted.data).to.equal(plaintext);
verifyCompressionDecrypted(decrypted);
});
});
it('should encrypt/sign and decrypt/verify', function () {
const encOpt = modifyCompressionEncryptOptions({
const encOpt = {
data: plaintext,
publicKeys: publicKey.keys,
privateKeys: privateKey.keys
});
};
const decOpt = {
privateKeys: privateKey.keys[0],
publicKeys: publicKey.keys
@ -928,16 +913,15 @@ describe('OpenPGP.js public api tests', function() {
expect(decrypted.signatures[0].valid).to.be.true;
expect(decrypted.signatures[0].keyid.toHex()).to.equal(privateKey.keys[0].getSigningKeyPacket().getKeyId().toHex());
expect(decrypted.signatures[0].signature.packets.length).to.equal(1);
verifyCompressionDecrypted(decrypted);
});
});
it('should encrypt/sign and decrypt/verify with null string input', function () {
const encOpt = modifyCompressionEncryptOptions({
const encOpt = {
data: '',
publicKeys: publicKey.keys,
privateKeys: privateKey.keys
});
};
const decOpt = {
privateKeys: privateKey.keys[0],
publicKeys: publicKey.keys
@ -950,17 +934,16 @@ describe('OpenPGP.js public api tests', function() {
expect(decrypted.signatures[0].valid).to.be.true;
expect(decrypted.signatures[0].keyid.toHex()).to.equal(privateKey.keys[0].getSigningKeyPacket().getKeyId().toHex());
expect(decrypted.signatures[0].signature.packets.length).to.equal(1);
verifyCompressionDecrypted(decrypted);
});
});
it('should encrypt/sign and decrypt/verify with detached signatures', function () {
const encOpt = modifyCompressionEncryptOptions({
const encOpt = {
data: plaintext,
publicKeys: publicKey.keys,
privateKeys: privateKey.keys,
detached: true
});
};
const decOpt = {
privateKeys: privateKey.keys[0],
publicKeys: publicKey.keys
@ -974,7 +957,6 @@ describe('OpenPGP.js public api tests', function() {
expect(decrypted.signatures[0].valid).to.be.true;
expect(decrypted.signatures[0].keyid.toHex()).to.equal(privateKey.keys[0].getSigningKeyPacket().getKeyId().toHex());
expect(decrypted.signatures[0].signature.packets.length).to.equal(1);
verifyCompressionDecrypted(decrypted);
});
});
@ -985,11 +967,11 @@ describe('OpenPGP.js public api tests', function() {
detached: true
};
const encOpt = modifyCompressionEncryptOptions({
const encOpt = {
data: plaintext,
publicKeys: publicKey.keys,
detached: true
});
};
const decOpt = {
privateKeys: privateKey.keys[0],
@ -1008,7 +990,6 @@ describe('OpenPGP.js public api tests', function() {
expect(decrypted.signatures[0].valid).to.be.true;
expect(decrypted.signatures[0].keyid.toHex()).to.equal(privateKey.keys[0].getSigningKeyPacket().getKeyId().toHex());
expect(decrypted.signatures[0].signature.packets.length).to.equal(1);
verifyCompressionDecrypted(decrypted);
});
});
@ -1024,11 +1005,11 @@ describe('OpenPGP.js public api tests', function() {
detached: true
};
const encOpt = modifyCompressionEncryptOptions({
const encOpt = {
data: plaintext,
publicKeys: publicKey.keys,
privateKeys: privateKey.keys[0]
});
};
const decOpt = {
privateKeys: privateKey.keys[0],
@ -1047,7 +1028,6 @@ describe('OpenPGP.js public api tests', function() {
expect(decrypted.signatures[0].keyid.toHex()).to.equal(privateKey.keys[0].getSigningKeyPacket().getKeyId().toHex());
expect(decrypted.signatures[0].signature.packets.length).to.equal(1);
expect(decrypted.signatures[1].valid).to.be.true;
verifyCompressionDecrypted(decrypted);
return privKeyDE.verifyPrimaryUser().then(() => {
expect(decrypted.signatures[1].keyid.toHex()).to.equal(privKeyDE.getSigningKeyPacket().getKeyId().toHex());
expect(decrypted.signatures[1].signature.packets.length).to.equal(1);
@ -1062,11 +1042,11 @@ describe('OpenPGP.js public api tests', function() {
detached: true
};
const encOpt = modifyCompressionEncryptOptions({
const encOpt = {
data: plaintext,
publicKeys: publicKey.keys,
detached: true
});
};
const decOpt = {
privateKeys: privateKey.keys[0],
@ -1085,7 +1065,6 @@ describe('OpenPGP.js public api tests', function() {
expect(decrypted.signatures[0].valid).to.be.null;
expect(decrypted.signatures[0].keyid.toHex()).to.equal(privateKey.keys[0].getSigningKeyPacket().getKeyId().toHex());
expect(decrypted.signatures[0].signature.packets.length).to.equal(1);
verifyCompressionDecrypted(decrypted);
});
});
@ -1096,10 +1075,10 @@ describe('OpenPGP.js public api tests', function() {
detached: true
};
const encOpt = modifyCompressionEncryptOptions({
const encOpt = {
data: plaintext,
publicKeys: publicKey.keys
});
};
const decOpt = {
privateKeys: privateKey.keys[0],
@ -1117,16 +1096,15 @@ describe('OpenPGP.js public api tests', function() {
expect(decrypted.signatures[0].valid).to.be.null;
expect(decrypted.signatures[0].keyid.toHex()).to.equal(privateKey.keys[0].getSigningKeyPacket().getKeyId().toHex());
expect(decrypted.signatures[0].signature.packets.length).to.equal(1);
verifyCompressionDecrypted(decrypted);
});
});
it('should fail to verify decrypted data with wrong public pgp key', function () {
const encOpt = modifyCompressionEncryptOptions({
const encOpt = {
data: plaintext,
publicKeys: publicKey.keys,
privateKeys: privateKey.keys
});
};
const decOpt = {
privateKeys: privateKey.keys[0],
publicKeys: openpgp.key.readArmored(wrong_pubkey).keys
@ -1139,16 +1117,15 @@ describe('OpenPGP.js public api tests', function() {
expect(decrypted.signatures[0].valid).to.be.null;
expect(decrypted.signatures[0].keyid.toHex()).to.equal(privateKey.keys[0].getSigningKeyPacket().getKeyId().toHex());
expect(decrypted.signatures[0].signature.packets.length).to.equal(1);
verifyCompressionDecrypted(decrypted);
});
});
it('should fail to verify decrypted null string with wrong public pgp key', function () {
const encOpt = modifyCompressionEncryptOptions({
const encOpt = {
data: '',
publicKeys: publicKey.keys,
privateKeys: privateKey.keys
});
};
const decOpt = {
privateKeys: privateKey.keys[0],
publicKeys: openpgp.key.readArmored(wrong_pubkey).keys
@ -1161,16 +1138,15 @@ describe('OpenPGP.js public api tests', function() {
expect(decrypted.signatures[0].valid).to.be.null;
expect(decrypted.signatures[0].keyid.toHex()).to.equal(privateKey.keys[0].getSigningKeyPacket().getKeyId().toHex());
expect(decrypted.signatures[0].signature.packets.length).to.equal(1);
verifyCompressionDecrypted(decrypted);
});
});
it('should successfully decrypt signed message without public keys to verify', function () {
const encOpt = modifyCompressionEncryptOptions({
const encOpt = {
data: plaintext,
publicKeys: publicKey.keys,
privateKeys: privateKey.keys
});
};
const decOpt = {
privateKeys: privateKey.keys[0]
};
@ -1182,17 +1158,16 @@ describe('OpenPGP.js public api tests', function() {
expect(decrypted.signatures[0].valid).to.be.null;
expect(decrypted.signatures[0].keyid.toHex()).to.equal(privateKey.keys[0].getSigningKeyPacket().getKeyId().toHex());
expect(decrypted.signatures[0].signature.packets.length).to.equal(1);
verifyCompressionDecrypted(decrypted);
});
});
it('should fail to verify decrypted data with wrong public pgp key with detached signatures', function () {
const encOpt = modifyCompressionEncryptOptions({
const encOpt = {
data: plaintext,
publicKeys: publicKey.keys,
privateKeys: privateKey.keys,
detached: true
});
};
const decOpt = {
privateKeys: privateKey.keys[0],
publicKeys: openpgp.key.readArmored(wrong_pubkey).keys
@ -1206,7 +1181,6 @@ describe('OpenPGP.js public api tests', function() {
expect(decrypted.signatures[0].valid).to.be.null;
expect(decrypted.signatures[0].keyid.toHex()).to.equal(privateKey.keys[0].getSigningKeyPacket().getKeyId().toHex());
expect(decrypted.signatures[0].signature.packets.length).to.equal(1);
verifyCompressionDecrypted(decrypted);
});
});
@ -1216,11 +1190,11 @@ describe('OpenPGP.js public api tests', function() {
const pubKeyDE = openpgp.key.readArmored(pub_key_de).keys[0];
const encOpt = modifyCompressionEncryptOptions({
const encOpt = {
data: plaintext,
publicKeys: publicKey.keys,
privateKeys: [privateKey.keys[0], privKeyDE]
});
};
const decOpt = {
privateKeys: privateKey.keys[0],
@ -1236,7 +1210,6 @@ describe('OpenPGP.js public api tests', function() {
expect(decrypted.signatures[0].keyid.toHex()).to.equal(privateKey.keys[0].getSigningKeyPacket().getKeyId().toHex());
expect(decrypted.signatures[0].signature.packets.length).to.equal(1);
expect(decrypted.signatures[1].valid).to.be.true;
verifyCompressionDecrypted(decrypted);
return privKeyDE.verifyPrimaryUser().then(() => {
expect(decrypted.signatures[1].keyid.toHex()).to.equal(privKeyDE.getSigningKeyPacket().getKeyId().toHex());
expect(decrypted.signatures[1].signature.packets.length).to.equal(1);
@ -1285,10 +1258,12 @@ describe('OpenPGP.js public api tests', function() {
expect(verified.signatures[0].keyid.toHex()).to.equal(privateKey.keys[0].getSigningKeyPacket().getKeyId().toHex());
expect(verified.signatures[0].signature.packets.length).to.equal(1);
expect(verified.signatures[1].valid).to.be.true;
return privKeyDE.verifyPrimaryUser().then(() => {
expect(verified.signatures[1].keyid.toHex()).to.equal(privKeyDE.getSigningKeyPacket().getKeyId().toHex());
expect(verified.signatures[1].signature.packets.length).to.equal(1);
});
});
});
it('should sign and verify cleartext data with detached signatures', function () {
const signOpt = {
@ -1393,19 +1368,18 @@ describe('OpenPGP.js public api tests', function() {
});
});
});
});
describe('ELG / DSA encrypt, decrypt, sign, verify', function() {
withCompression(function (modifyCompressionEncryptOptions, verifyCompressionDecrypted) {
it('round trip test', function () {
const pubKeyDE = openpgp.key.readArmored(pub_key_de).keys[0];
const privKeyDE = openpgp.key.readArmored(priv_key_de).keys[0];
privKeyDE.decrypt(passphrase);
return openpgp.encrypt(modifyCompressionEncryptOptions({
return openpgp.encrypt({
publicKeys: pubKeyDE,
privateKeys: privKeyDE,
data: plaintext
})).then(function (encrypted) {
}).then(function (encrypted) {
return openpgp.decrypt({
privateKeys: privKeyDE,
publicKeys: pubKeyDE,
@ -1422,7 +1396,6 @@ describe('OpenPGP.js public api tests', function() {
});
});
});
});
describe("3DES decrypt", function() {
const pgp_msg =
@ -1489,12 +1462,12 @@ describe('OpenPGP.js public api tests', function() {
});
describe('AES encrypt, decrypt', function() {
withCompression(function (modifyCompressionEncryptOptions, verifyCompressionDecrypted) {
it('should encrypt and decrypt with one password', function () {
const encOpt = modifyCompressionEncryptOptions({
const encOpt = {
data: plaintext,
passwords: password1
});
};
const decOpt = {
passwords: password1
};
@ -1504,15 +1477,14 @@ describe('OpenPGP.js public api tests', function() {
}).then(function (decrypted) {
expect(decrypted.data).to.equal(plaintext);
expect(decrypted.signatures.length).to.equal(0);
verifyCompressionDecrypted(decrypted);
});
});
it('should encrypt and decrypt with two passwords', function () {
const encOpt = modifyCompressionEncryptOptions({
const encOpt = {
data: plaintext,
passwords: [password1, password2]
});
};
const decOpt = {
passwords: password2
};
@ -1522,7 +1494,6 @@ describe('OpenPGP.js public api tests', function() {
}).then(function (decrypted) {
expect(decrypted.data).to.equal(plaintext);
expect(decrypted.signatures.length).to.equal(0);
verifyCompressionDecrypted(decrypted);
});
});
@ -1539,11 +1510,11 @@ describe('OpenPGP.js public api tests', function() {
});
it('should encrypt and decrypt with password and not ascii armor', function () {
const encOpt = modifyCompressionEncryptOptions({
const encOpt = {
data: plaintext,
passwords: password1,
armor: false
});
};
const decOpt = {
passwords: password1
};
@ -1553,17 +1524,16 @@ describe('OpenPGP.js public api tests', function() {
}).then(function (decrypted) {
expect(decrypted.data).to.equal(plaintext);
expect(decrypted.signatures.length).to.equal(0);
verifyCompressionDecrypted(decrypted);
});
});
it('should encrypt and decrypt with binary data and transferable objects', function () {
openpgp.config.zero_copy = true; // activate transferable objects
const encOpt = modifyCompressionEncryptOptions({
const encOpt = {
data: new Uint8Array([0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01]),
passwords: password1,
armor: false
});
};
const decOpt = {
passwords: password1,
format: 'binary'
@ -1577,6 +1547,26 @@ describe('OpenPGP.js public api tests', function() {
}
expect(decrypted.data).to.deep.equal(new Uint8Array([0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01]));
expect(decrypted.signatures.length).to.equal(0);
});
});
});
describe('Encrypt, decrypt with compression', function() {
withCompression(function (modifyCompressionEncryptOptions, verifyCompressionDecrypted) {
it('should encrypt and decrypt with one password', function () {
const encOpt = modifyCompressionEncryptOptions({
data: plaintext,
passwords: password1
});
const decOpt = {
passwords: password1
};
return openpgp.encrypt(encOpt).then(function (encrypted) {
decOpt.message = openpgp.message.readArmored(encrypted.data);
return openpgp.decrypt(decOpt);
}).then(function (decrypted) {
expect(decrypted.data).to.equal(plaintext);
expect(decrypted.signatures.length).to.equal(0);
verifyCompressionDecrypted(decrypted);
});
});