Port general tests to chai/mocha
This commit is contained in:
parent
8449062191
commit
e5e1675615
|
@ -1464,7 +1464,7 @@ var config = function() {
|
||||||
this.integrity_protect = true;
|
this.integrity_protect = true;
|
||||||
this.keyserver = "keyserver.linux.it"; // "pgp.mit.edu:11371"
|
this.keyserver = "keyserver.linux.it"; // "pgp.mit.edu:11371"
|
||||||
|
|
||||||
this.versionstring = "OpenPGP.js v0.0.1.20131222";
|
this.versionstring = "OpenPGP.js VERSION";
|
||||||
this.commentstring = "http://openpgpjs.org";
|
this.commentstring = "http://openpgpjs.org";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1 +1,2 @@
|
||||||
require('./ci-quick.js');
|
require('./ci-quick.js');
|
||||||
|
require('./general');
|
||||||
|
|
|
@ -1,46 +1,63 @@
|
||||||
var unit = require('../unit.js');
|
|
||||||
|
|
||||||
unit.register("Key generation/encryption/decryption", function() {
|
|
||||||
var openpgp = require('openpgp');
|
var openpgp = require('openpgp');
|
||||||
var result = [];
|
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
var expect = chai.expect;
|
||||||
|
|
||||||
|
describe('Basic tests', function() {
|
||||||
|
|
||||||
|
describe("Key generation/encryption/decryption", function() {
|
||||||
var testHelper = function(passphrase, userid, message) {
|
var testHelper = function(passphrase, userid, message) {
|
||||||
var key = openpgp.generateKeyPair(openpgp.enums.publicKey.rsa_encrypt_sign, 512,
|
var key = openpgp.generateKeyPair(openpgp.enums.publicKey.rsa_encrypt_sign, 512, userid, passphrase);
|
||||||
userid, passphrase);
|
expect(key).to.exist;
|
||||||
|
expect(key.key).to.exist;
|
||||||
|
expect(key.privateKeyArmored).to.exist;
|
||||||
|
expect(key.publicKeyArmored).to.exist;
|
||||||
|
|
||||||
var info = '\npassphrase: ' + passphrase + '\n'
|
var info = '\npassphrase: ' + passphrase + '\n' + 'userid: ' + userid + '\n' + 'message: ' + message;
|
||||||
+ 'userid: ' + userid + '\n'
|
|
||||||
+ 'message: ' + message;
|
|
||||||
|
|
||||||
var privKey = openpgp.key.readArmored(key.privateKeyArmored).keys[0];
|
var privKeys = openpgp.key.readArmored(key.privateKeyArmored);
|
||||||
|
|
||||||
|
expect(privKeys).to.exist;
|
||||||
|
expect(privKeys.err).to.not.exist;
|
||||||
|
expect(privKeys.keys).to.have.length(1);
|
||||||
|
|
||||||
|
var privKey = privKeys.keys[0];
|
||||||
|
|
||||||
|
expect(privKey).to.exist;
|
||||||
|
|
||||||
var encrypted = openpgp.encryptMessage([privKey], message);
|
var encrypted = openpgp.encryptMessage([privKey], message);
|
||||||
|
|
||||||
|
expect(encrypted).to.exist;
|
||||||
|
|
||||||
var msg = openpgp.message.readArmored(encrypted);
|
var msg = openpgp.message.readArmored(encrypted);
|
||||||
|
|
||||||
|
expect(msg).to.exist;
|
||||||
|
|
||||||
var keyids = msg.getEncryptionKeyIds();
|
var keyids = msg.getEncryptionKeyIds();
|
||||||
|
|
||||||
privKey.decryptKeyPacket(keyids, passphrase);
|
expect(keyids).to.exist;
|
||||||
|
|
||||||
|
var success = privKey.decryptKeyPacket(keyids, passphrase);
|
||||||
|
|
||||||
|
expect(success).to.be.true;
|
||||||
|
|
||||||
try {
|
|
||||||
var decrypted = openpgp.decryptMessage(privKey, msg);
|
var decrypted = openpgp.decryptMessage(privKey, msg);
|
||||||
return new unit.result(message + ' == ' + decrypted + info, message == decrypted);
|
expect(decrypted).to.exist;
|
||||||
} catch (e) {
|
expect(decrypted).to.equal(message);
|
||||||
return new unit.result("Exception on decrypt of private key packet!" + info, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
result.push(testHelper('password', 'Test McTestington <test@example.com>', 'hello world'));
|
it('ASCII Text', function (done) {
|
||||||
result.push(testHelper('●●●●', '♔♔♔♔ <test@example.com>', 'łäóć'));
|
testHelper('password', 'Test McTestington <test@example.com>', 'hello world');
|
||||||
|
done();
|
||||||
return result;
|
});
|
||||||
|
it('Unicode Text', function (done) {
|
||||||
|
testHelper('●●●●', '♔♔♔♔ <test@example.com>', 'łäóć');
|
||||||
|
done();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
unit.register("Message encryption/decryption", function() {
|
describe("Message encryption/decryption", function() {
|
||||||
var openpgp = require('openpgp');
|
|
||||||
|
|
||||||
var result = [];
|
|
||||||
|
|
||||||
var pub_key =
|
var pub_key =
|
||||||
['-----BEGIN PGP PUBLIC KEY BLOCK-----',
|
['-----BEGIN PGP PUBLIC KEY BLOCK-----',
|
||||||
'Version: GnuPG v2.0.19 (GNU/Linux)',
|
'Version: GnuPG v2.0.19 (GNU/Linux)',
|
||||||
|
@ -111,38 +128,76 @@ unit.register("Message encryption/decryption", function() {
|
||||||
|
|
||||||
var plaintext = 'short message\nnext line\n한국어/조선말';
|
var plaintext = 'short message\nnext line\n한국어/조선말';
|
||||||
|
|
||||||
var key = openpgp.key.readArmored(pub_key).keys[0];
|
var privKey, message, keyids;
|
||||||
|
|
||||||
var encrypted = openpgp.encryptMessage([key], plaintext);
|
it('Test initialization', function (done) {
|
||||||
|
var pubKeys = openpgp.key.readArmored(pub_key);
|
||||||
|
|
||||||
var message = openpgp.message.readArmored(encrypted);
|
expect(pubKeys).to.exist;
|
||||||
|
expect(pubKeys.err).to.not.exist;
|
||||||
|
expect(pubKeys.keys).to.have.length(1);
|
||||||
|
|
||||||
var privKey = openpgp.key.readArmored(priv_key).keys[0];
|
var pubKey = pubKeys.keys[0];
|
||||||
|
|
||||||
|
expect(pubKey).to.exist;
|
||||||
|
|
||||||
|
var encrypted = openpgp.encryptMessage([pubKey], plaintext);
|
||||||
|
|
||||||
|
expect(encrypted).to.exist;
|
||||||
|
|
||||||
|
message = openpgp.message.readArmored(encrypted);
|
||||||
|
|
||||||
|
expect(message).to.exist;
|
||||||
|
|
||||||
|
var privKeys = openpgp.key.readArmored(priv_key);
|
||||||
|
|
||||||
|
expect(privKeys).to.exist;
|
||||||
|
expect(privKeys.err).to.not.exist;
|
||||||
|
expect(privKeys.keys).to.have.length(1);
|
||||||
|
|
||||||
|
privKey = privKeys.keys[0];
|
||||||
|
|
||||||
|
expect(privKey).to.exist;
|
||||||
|
|
||||||
// get key IDs the message is encrypted for
|
// get key IDs the message is encrypted for
|
||||||
var keyids = message.getEncryptionKeyIds();
|
keyids = message.getEncryptionKeyIds();
|
||||||
|
|
||||||
|
expect(keyids).to.exist;
|
||||||
|
expect(keyids).to.have.length(1);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Decrypting key packet with wrong password returns false', function (done) {
|
||||||
// decrypt only required key packets
|
// decrypt only required key packets
|
||||||
var success = privKey.decryptKeyPacket(keyids, 'hello what?')
|
var success = privKey.decryptKeyPacket(keyids, 'hello what?');
|
||||||
|
|
||||||
result.push(new unit.result('Decrypting key packet with wrong password returns false', !success));
|
expect(success).to.be.false;
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
|
||||||
var decrypted, error;
|
var decrypted, error;
|
||||||
try {
|
|
||||||
|
it('Calling decryptMessage with not decrypted key packet leads to exception', function (done) {
|
||||||
|
function exceptionTest() {
|
||||||
decrypted = openpgp.decryptMessage(privKey, message);
|
decrypted = openpgp.decryptMessage(privKey, message);
|
||||||
} catch (e) {
|
|
||||||
error = e;
|
|
||||||
}
|
}
|
||||||
result.push(new unit.result('Calling decryptMessage with not decrypted key packet leads to exception: \'' + (error || '') + '\'', error));
|
|
||||||
|
|
||||||
success = privKey.decryptKeyPacket(keyids, 'hello world');
|
|
||||||
|
|
||||||
result.push(new unit.result('Decrypting key packet with correct password returns true', success));
|
|
||||||
|
|
||||||
decrypted = openpgp.decryptMessage(privKey, message);
|
|
||||||
|
|
||||||
result.push(new unit.result('Encrypt plain text and afterwards decrypt leads to same result', plaintext == decrypted));
|
|
||||||
|
|
||||||
return result;
|
|
||||||
|
|
||||||
|
expect(exceptionTest).to.throw(Error);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Decrypting key packet with correct password returns true', function (done) {
|
||||||
|
var success = privKey.decryptKeyPacket(keyids, 'hello world');
|
||||||
|
|
||||||
|
expect(success).to.be.true;
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Encrypt plain text and afterwards decrypt leads to same result', function (done) {
|
||||||
|
decrypted = openpgp.decryptMessage(privKey, message);
|
||||||
|
expect(decrypted).to.exist;
|
||||||
|
expect(decrypted).to.equal(plaintext);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
8
test/general/index.js
Normal file
8
test/general/index.js
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
describe('General tests', function () {
|
||||||
|
require('./basic.js');
|
||||||
|
require('./key.js');
|
||||||
|
require('./keyring.js');
|
||||||
|
require('./packet.js');
|
||||||
|
require('./signature.js');
|
||||||
|
});
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
var unit = require('../unit.js');
|
|
||||||
|
|
||||||
unit.register("Key testing", function() {
|
|
||||||
var openpgp = require('openpgp');
|
var openpgp = require('openpgp');
|
||||||
|
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
var expect = chai.expect;
|
||||||
|
|
||||||
|
describe('Key tests', function() {
|
||||||
var twoKeys =
|
var twoKeys =
|
||||||
['-----BEGIN PGP PUBLIC KEY BLOCK-----',
|
['-----BEGIN PGP PUBLIC KEY BLOCK-----',
|
||||||
'Version: GnuPG v2.0.19 (GNU/Linux)',
|
'Version: GnuPG v2.0.19 (GNU/Linux)',
|
||||||
|
@ -218,49 +220,77 @@ unit.register("Key testing", function() {
|
||||||
'=e8xo',
|
'=e8xo',
|
||||||
'-----END PGP PUBLIC KEY BLOCK-----'].join('\n');
|
'-----END PGP PUBLIC KEY BLOCK-----'].join('\n');
|
||||||
|
|
||||||
|
it('Parsing armored text with two keys', function(done) {
|
||||||
|
var pubKeys = openpgp.key.readArmored(twoKeys);
|
||||||
var tests = [function() {
|
expect(pubKeys).to.exist;
|
||||||
var pubKey = openpgp.key.readArmored(twoKeys);
|
expect(pubKeys.err).to.not.exist;
|
||||||
var verified = !pubKey.err && pubKey.keys.length == 2 &&
|
expect(pubKeys.keys).to.have.length(2);
|
||||||
pubKey.keys[0].getKeyPacket().getKeyId().toHex() == '4a63613a4d6e4094' &&
|
expect(pubKeys.keys[0].getKeyPacket().getKeyId().toHex()).to.equal('4a63613a4d6e4094');
|
||||||
pubKey.keys[1].getKeyPacket().getKeyId().toHex() == 'dbf223e870534df4';
|
expect(pubKeys.keys[1].getKeyPacket().getKeyId().toHex()).to.equal('dbf223e870534df4');
|
||||||
return new unit.result("Parsing armored text with two keys", verified);
|
done();
|
||||||
|
});
|
||||||
},function() {
|
|
||||||
var pubKeyV4 = openpgp.key.readArmored(twoKeys).keys[0];
|
it('Testing key ID and fingerprint for V3 and V4 keys', function(done) {
|
||||||
var pubKeyV3 = openpgp.key.readArmored(pub_v3).keys[0];
|
var pubKeysV4 = openpgp.key.readArmored(twoKeys);
|
||||||
var verified = pubKeyV4.getKeyPacket().getKeyId().toHex() == '4a63613a4d6e4094' &&
|
expect(pubKeysV4).to.exist;
|
||||||
openpgp.util.hexstrdump(pubKeyV4.getKeyPacket().getFingerprint()) == 'f470e50dcb1ad5f1e64e08644a63613a4d6e4094' &&
|
expect(pubKeysV4.err).to.not.exist;
|
||||||
pubKeyV3.getKeyPacket().getKeyId().toHex() == 'e5b7a014a237ba9d' &&
|
expect(pubKeysV4.keys).to.have.length(2);
|
||||||
openpgp.util.hexstrdump(pubKeyV3.getKeyPacket().getFingerprint()) == 'a44fcee620436a443bc4913640ab3e49';
|
|
||||||
|
var pubKeyV4 = pubKeysV4.keys[0];
|
||||||
return new unit.result("Testing key ID and fingerprint for V3 and V4 keys", verified);
|
expect(pubKeyV4).to.exist;
|
||||||
|
|
||||||
},function() {
|
var pubKeysV3 = openpgp.key.readArmored(pub_v3)
|
||||||
var pubKey = openpgp.key.readArmored(pub_sig_test).keys[0];
|
|
||||||
var packetlist = new openpgp.packet.list();
|
expect(pubKeysV3).to.exist;
|
||||||
packetlist.read(openpgp.armor.decode(pub_sig_test).data);
|
expect(pubKeysV3.err).to.not.exist;
|
||||||
var subkeys = pubKey.getSubkeyPackets();
|
expect(pubKeysV3.keys).to.have.length(1);
|
||||||
var verified = subkeys.length == 2 &&
|
|
||||||
subkeys[0].getKeyId().equals(packetlist[8].getKeyId()) &&
|
var pubKeyV3 = pubKeysV3.keys[0];
|
||||||
subkeys[1].getKeyId().equals(packetlist[11].getKeyId());
|
expect(pubKeyV3).to.exist;
|
||||||
return new unit.result("Testing key method getSubkeyPackets", verified);
|
|
||||||
|
expect(pubKeyV4.getKeyPacket().getKeyId().toHex()).to.equal('4a63613a4d6e4094');
|
||||||
},function() {
|
expect(openpgp.util.hexstrdump(pubKeyV4.getKeyPacket().getFingerprint())).to.equal('f470e50dcb1ad5f1e64e08644a63613a4d6e4094');
|
||||||
var pubKey = openpgp.key.readArmored(pub_sig_test).keys[0];
|
expect(pubKeyV3.getKeyPacket().getKeyId().toHex()).to.equal('e5b7a014a237ba9d');
|
||||||
var status = pubKey.subKeys[0].verify(pubKey.primaryKey);
|
expect(openpgp.util.hexstrdump(pubKeyV3.getKeyPacket().getFingerprint())).to.equal('a44fcee620436a443bc4913640ab3e49');
|
||||||
return new unit.result("Verify status of revoked subkey", status == openpgp.enums.keyStatus.revoked);
|
done();
|
||||||
|
});
|
||||||
}];
|
|
||||||
|
it('Testing key method getSubkeyPackets', function(done) {
|
||||||
var results = [];
|
var pubKeys = openpgp.key.readArmored(pub_sig_test)
|
||||||
|
|
||||||
for(var i in tests) {
|
expect(pubKeys).to.exist;
|
||||||
results.push(tests[i]());
|
expect(pubKeys.err).to.not.exist;
|
||||||
}
|
expect(pubKeys.keys).to.have.length(1);
|
||||||
|
|
||||||
return results;
|
var pubKey = pubKeys.keys[0];
|
||||||
|
expect(pubKey).to.exist;
|
||||||
|
|
||||||
|
var packetlist = new openpgp.packet.list();
|
||||||
|
|
||||||
|
packetlist.read(openpgp.armor.decode(pub_sig_test).data);
|
||||||
|
|
||||||
|
var subkeys = pubKey.getSubkeyPackets();
|
||||||
|
expect(subkeys).to.exist;
|
||||||
|
expect(subkeys).to.have.length(2);
|
||||||
|
expect(subkeys[0].getKeyId().equals(packetlist[8].getKeyId())).to.be.true;
|
||||||
|
expect(subkeys[1].getKeyId().equals(packetlist[11].getKeyId())).to.be.true;
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Verify status of revoked subkey', function(done) {
|
||||||
|
var pubKeys = openpgp.key.readArmored(pub_sig_test);
|
||||||
|
expect(pubKeys).to.exist;
|
||||||
|
expect(pubKeys.err).to.not.exist;
|
||||||
|
expect(pubKeys.keys).to.have.length(1);
|
||||||
|
|
||||||
|
var pubKey = pubKeys.keys[0];
|
||||||
|
expect(pubKey).to.exist;
|
||||||
|
expect(pubKey.subKeys).to.exist;
|
||||||
|
expect(pubKey.subKeys).to.have.length(2);
|
||||||
|
|
||||||
|
var status = pubKey.subKeys[0].verify(pubKey.primaryKey);
|
||||||
|
expect(status).to.equal(openpgp.enums.keyStatus.revoked);
|
||||||
|
done();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
var unit = require('../unit.js');
|
|
||||||
|
|
||||||
unit.register("Keyring testing", function() {
|
|
||||||
var openpgp = require('openpgp');
|
var openpgp = require('openpgp');
|
||||||
var keyringClass = new require('keyring');
|
|
||||||
var keyring = new keyringClass();
|
'use strict';
|
||||||
var result = [];
|
|
||||||
|
var expect = chai.expect;
|
||||||
|
|
||||||
|
describe("Keyring testing", function() {
|
||||||
|
var keyring = new (new require('keyring'))();
|
||||||
|
|
||||||
keyring.init();
|
keyring.init();
|
||||||
keyring.importKey([
|
keyring.importKey([
|
||||||
|
@ -49,14 +50,19 @@ unit.register("Keyring testing", function() {
|
||||||
'=WaSx',
|
'=WaSx',
|
||||||
'-----END PGP MESSAGE-----'
|
'-----END PGP MESSAGE-----'
|
||||||
].join("\n"));
|
].join("\n"));
|
||||||
|
|
||||||
|
it('Testing keyring getKeysForKeyId method', function (done) {
|
||||||
var signingKeyIds = msg2.getSigningKeyIds();
|
var signingKeyIds = msg2.getSigningKeyIds();
|
||||||
var key = keyring.getKeysForKeyId(signingKeyIds[0].toHex());
|
var key = keyring.getKeysForKeyId(signingKeyIds[0].toHex());
|
||||||
|
expect(key).to.exist;
|
||||||
|
expect(key).to.have.length(1);
|
||||||
|
|
||||||
var verified = msg2.verify(key);
|
var verified = msg2.verify(key);
|
||||||
result[2] = new unit.result("Testing keyring getKeysForKeyId method",
|
expect(verified).to.exist;
|
||||||
key !== null &&
|
expect(verified).to.have.length(1);
|
||||||
key.length == 1 &&
|
expect(verified[0].valid).to.be.true;
|
||||||
verified[0].valid);
|
done();
|
||||||
return result;
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
var unit = require('../unit.js');
|
|
||||||
|
|
||||||
unit.register("Packet testing", function() {
|
|
||||||
|
|
||||||
var openpgp = require('openpgp');
|
var openpgp = require('openpgp');
|
||||||
|
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
var expect = chai.expect;
|
||||||
|
|
||||||
|
describe("Packet testing", function() {
|
||||||
var armored_key =
|
var armored_key =
|
||||||
'-----BEGIN PGP PRIVATE KEY BLOCK-----\n' +
|
'-----BEGIN PGP PRIVATE KEY BLOCK-----\n' +
|
||||||
'Version: GnuPG v2.0.19 (GNU/Linux)\n' +
|
'Version: GnuPG v2.0.19 (GNU/Linux)\n' +
|
||||||
|
@ -41,8 +42,7 @@ unit.register("Packet testing", function() {
|
||||||
'=KXkj\n' +
|
'=KXkj\n' +
|
||||||
'-----END PGP PRIVATE KEY BLOCK-----';
|
'-----END PGP PRIVATE KEY BLOCK-----';
|
||||||
|
|
||||||
|
it('Symmetrically encrypted packet', function(done) {
|
||||||
var tests = [function() {
|
|
||||||
var message = new openpgp.packet.list();
|
var message = new openpgp.packet.list();
|
||||||
|
|
||||||
var literal = new openpgp.packet.literal();
|
var literal = new openpgp.packet.literal();
|
||||||
|
@ -57,17 +57,16 @@ unit.register("Packet testing", function() {
|
||||||
|
|
||||||
enc.encrypt(algo, key);
|
enc.encrypt(algo, key);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var msg2 = new openpgp.packet.list();
|
var msg2 = new openpgp.packet.list();
|
||||||
msg2.read(message.write());
|
msg2.read(message.write());
|
||||||
|
|
||||||
msg2[0].decrypt(algo, key);
|
msg2[0].decrypt(algo, key);
|
||||||
|
|
||||||
return new unit.result('Symmetrically encrypted packet',
|
expect(msg2[0].packets[0].data).to.equal(literal.data);
|
||||||
msg2[0].packets[0].data == literal.data);
|
done();
|
||||||
|
});
|
||||||
|
|
||||||
}, function() {
|
it('Sym. encrypted integrity protected packet', function(done) {
|
||||||
var key = '12345678901234567890123456789012',
|
var key = '12345678901234567890123456789012',
|
||||||
algo = 'aes256';
|
algo = 'aes256';
|
||||||
|
|
||||||
|
@ -80,18 +79,16 @@ unit.register("Packet testing", function() {
|
||||||
enc.packets.push(literal);
|
enc.packets.push(literal);
|
||||||
enc.encrypt(algo, key);
|
enc.encrypt(algo, key);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var msg2 = new openpgp.packet.list();
|
var msg2 = new openpgp.packet.list();
|
||||||
msg2.read(msg.write());
|
msg2.read(msg.write());
|
||||||
|
|
||||||
msg2[0].decrypt(algo, key);
|
msg2[0].decrypt(algo, key);
|
||||||
|
|
||||||
return new unit.result('Sym. encrypted integrity protected packet',
|
expect(msg2[0].packets[0].data).to.equal(literal.data);
|
||||||
msg2[0].packets[0].data == literal.data);
|
done();
|
||||||
|
});
|
||||||
}, function() {
|
|
||||||
|
|
||||||
|
it('Sym encrypted session key with a compressed packet', function(done) {
|
||||||
var msg =
|
var msg =
|
||||||
'-----BEGIN PGP MESSAGE-----\n' +
|
'-----BEGIN PGP MESSAGE-----\n' +
|
||||||
'Version: GnuPG v2.0.19 (GNU/Linux)\n' +
|
'Version: GnuPG v2.0.19 (GNU/Linux)\n' +
|
||||||
|
@ -101,8 +98,6 @@ unit.register("Packet testing", function() {
|
||||||
'=VZ0/\n' +
|
'=VZ0/\n' +
|
||||||
'-----END PGP MESSAGE-----';
|
'-----END PGP MESSAGE-----';
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var msgbytes = openpgp.armor.decode(msg).data;
|
var msgbytes = openpgp.armor.decode(msg).data;
|
||||||
|
|
||||||
var parsed = new openpgp.packet.list();
|
var parsed = new openpgp.packet.list();
|
||||||
|
@ -116,11 +111,11 @@ unit.register("Packet testing", function() {
|
||||||
|
|
||||||
var result = compressed.packets[0].data;
|
var result = compressed.packets[0].data;
|
||||||
|
|
||||||
return new unit.result('Sym encrypted session key with a compressed packet',
|
expect(result).to.equal('Hello world!\n');
|
||||||
result == 'Hello world!\n');
|
done();
|
||||||
|
});
|
||||||
}, function() {
|
|
||||||
|
|
||||||
|
it('Public key encrypted symmetric key packet', function(done) {
|
||||||
var rsa = new openpgp.crypto.publicKey.rsa(),
|
var rsa = new openpgp.crypto.publicKey.rsa(),
|
||||||
mpi = rsa.generate(512, "10001")
|
mpi = rsa.generate(512, "10001")
|
||||||
|
|
||||||
|
@ -148,10 +143,12 @@ unit.register("Packet testing", function() {
|
||||||
|
|
||||||
msg2[0].decrypt({ mpi: mpi });
|
msg2[0].decrypt({ mpi: mpi });
|
||||||
|
|
||||||
return new unit.result('Public key encrypted symmetric key packet',
|
expect(msg2[0].sessionKey).to.equal(enc.sessionKey);
|
||||||
msg2[0].sessionKey == enc.sessionKey &&
|
expect(msg2[0].sessionKeyAlgorithm).to.equal(enc.sessionKeyAlgorithm);
|
||||||
msg2[0].sessionKeyAlgorithm == enc.sessionKeyAlgorithm);
|
done();
|
||||||
}, function() {
|
});
|
||||||
|
|
||||||
|
it('Secret key packet (reading, unencrpted)', function(done) {
|
||||||
var armored_key =
|
var armored_key =
|
||||||
'-----BEGIN PGP PRIVATE KEY BLOCK-----\n' +
|
'-----BEGIN PGP PRIVATE KEY BLOCK-----\n' +
|
||||||
'Version: GnuPG v2.0.19 (GNU/Linux)\n' +
|
'Version: GnuPG v2.0.19 (GNU/Linux)\n' +
|
||||||
|
@ -174,7 +171,7 @@ unit.register("Packet testing", function() {
|
||||||
'=lKiS\n' +
|
'=lKiS\n' +
|
||||||
'-----END PGP PRIVATE KEY BLOCK-----';
|
'-----END PGP PRIVATE KEY BLOCK-----';
|
||||||
|
|
||||||
key = new openpgp.packet.list();
|
var key = new openpgp.packet.list();
|
||||||
key.read(openpgp.armor.decode(armored_key).data);
|
key.read(openpgp.armor.decode(armored_key).data);
|
||||||
key = key[0];
|
key = key[0];
|
||||||
|
|
||||||
|
@ -190,10 +187,11 @@ unit.register("Packet testing", function() {
|
||||||
|
|
||||||
enc.decrypt(key);
|
enc.decrypt(key);
|
||||||
|
|
||||||
return new unit.result('Secret key packet (reading, unencrpted)',
|
expect(enc.sessionKey).to.equal(secret);
|
||||||
enc.sessionKey == secret);
|
done();
|
||||||
}, function() {
|
});
|
||||||
|
|
||||||
|
it('Public key encrypted packet (reading, GPG)', function(done) {
|
||||||
var armored_key =
|
var armored_key =
|
||||||
'-----BEGIN PGP PRIVATE KEY BLOCK-----\n' +
|
'-----BEGIN PGP PRIVATE KEY BLOCK-----\n' +
|
||||||
'Version: GnuPG v2.0.19 (GNU/Linux)\n' +
|
'Version: GnuPG v2.0.19 (GNU/Linux)\n' +
|
||||||
|
@ -254,11 +252,11 @@ unit.register("Packet testing", function() {
|
||||||
|
|
||||||
var text = msg[1].packets[0].packets[0].data;
|
var text = msg[1].packets[0].packets[0].data;
|
||||||
|
|
||||||
|
expect(text).to.equal('Hello world!');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
|
||||||
return new unit.result('Public key encrypted packet (reading, GPG)',
|
it('Sym encrypted session key reading/writing', function(done) {
|
||||||
text == 'Hello world!');
|
|
||||||
}, function() {
|
|
||||||
|
|
||||||
var passphrase = 'hello',
|
var passphrase = 'hello',
|
||||||
algo = 'aes256';
|
algo = 'aes256';
|
||||||
|
|
||||||
|
@ -287,11 +285,11 @@ unit.register("Packet testing", function() {
|
||||||
var key2 = msg2[0].sessionKey;
|
var key2 = msg2[0].sessionKey;
|
||||||
msg2[1].decrypt(msg2[0].sessionKeyAlgorithm, key2);
|
msg2[1].decrypt(msg2[0].sessionKeyAlgorithm, key2);
|
||||||
|
|
||||||
|
expect(msg2[1].packets[0].data).to.equal(literal.data);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
|
||||||
return new unit.result('Sym encrypted session key reading/writing',
|
it('Secret key encryption/decryption test', function(done) {
|
||||||
msg2[1].packets[0].data == literal.data);
|
|
||||||
|
|
||||||
}, function() {
|
|
||||||
var armored_msg =
|
var armored_msg =
|
||||||
'-----BEGIN PGP MESSAGE-----\n' +
|
'-----BEGIN PGP MESSAGE-----\n' +
|
||||||
'Version: GnuPG v2.0.19 (GNU/Linux)\n' +
|
'Version: GnuPG v2.0.19 (GNU/Linux)\n' +
|
||||||
|
@ -317,13 +315,11 @@ unit.register("Packet testing", function() {
|
||||||
|
|
||||||
var text = msg[1].packets[0].packets[0].data;
|
var text = msg[1].packets[0].packets[0].data;
|
||||||
|
|
||||||
|
expect(text).to.equal('Hello world!');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Secret key reading with signature verification.', function(done) {
|
||||||
return new unit.result('Secret key encryption/decryption test',
|
|
||||||
text == 'Hello world!');
|
|
||||||
}, function() {
|
|
||||||
|
|
||||||
|
|
||||||
var key = new openpgp.packet.list();
|
var key = new openpgp.packet.list();
|
||||||
key.read(openpgp.armor.decode(armored_key).data);
|
key.read(openpgp.armor.decode(armored_key).data);
|
||||||
|
|
||||||
|
@ -337,14 +333,14 @@ unit.register("Packet testing", function() {
|
||||||
verified = verified && key[4].verify(key[0],
|
verified = verified && key[4].verify(key[0],
|
||||||
{
|
{
|
||||||
key: key[0],
|
key: key[0],
|
||||||
bind: key[3],
|
bind: key[3]
|
||||||
})
|
});
|
||||||
|
|
||||||
|
expect(verified).to.be.true;
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
|
||||||
return new unit.result('Secret key reading with signature verification.',
|
it('Reading a signed, encrypted message.', function(done) {
|
||||||
verified == true);
|
|
||||||
}, function() {
|
|
||||||
|
|
||||||
var armored_msg =
|
var armored_msg =
|
||||||
'-----BEGIN PGP MESSAGE-----\n' +
|
'-----BEGIN PGP MESSAGE-----\n' +
|
||||||
'Version: GnuPG v2.0.19 (GNU/Linux)\n' +
|
'Version: GnuPG v2.0.19 (GNU/Linux)\n' +
|
||||||
|
@ -368,21 +364,18 @@ unit.register("Packet testing", function() {
|
||||||
var msg = new openpgp.packet.list();
|
var msg = new openpgp.packet.list();
|
||||||
msg.read(openpgp.armor.decode(armored_msg).data);
|
msg.read(openpgp.armor.decode(armored_msg).data);
|
||||||
|
|
||||||
|
|
||||||
msg[0].decrypt(key[3]);
|
msg[0].decrypt(key[3]);
|
||||||
msg[1].decrypt(msg[0].sessionKeyAlgorithm, msg[0].sessionKey);
|
msg[1].decrypt(msg[0].sessionKeyAlgorithm, msg[0].sessionKey);
|
||||||
|
|
||||||
var payload = msg[1].packets[0].packets
|
var payload = msg[1].packets[0].packets
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var verified = payload[2].verify(key[0], payload[1]);
|
var verified = payload[2].verify(key[0], payload[1]);
|
||||||
|
|
||||||
|
expect(verified).to.be.true;
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Writing and encryption of a secret key packet.', function(done) {
|
||||||
return new unit.result('Reading a signed, encrypted message.',
|
|
||||||
verified == true);
|
|
||||||
}, function() {
|
|
||||||
var key = new openpgp.packet.list();
|
var key = new openpgp.packet.list();
|
||||||
key.push(new openpgp.packet.secret_key);
|
key.push(new openpgp.packet.secret_key);
|
||||||
|
|
||||||
|
@ -408,11 +401,11 @@ unit.register("Packet testing", function() {
|
||||||
key2.read(raw);
|
key2.read(raw);
|
||||||
key2[0].decrypt('hello');
|
key2[0].decrypt('hello');
|
||||||
|
|
||||||
|
expect(key[0].mpi.toString()).to.equal(key2[0].mpi.toString());
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
|
||||||
return new unit.result('Writing and encryptio of a secret key packet.',
|
it('Writing and verification of a signature packet.', function(done) {
|
||||||
key[0].mpi.toString() == key2[0].mpi.toString());
|
|
||||||
}, function() {
|
|
||||||
|
|
||||||
var key = new openpgp.packet.secret_key();
|
var key = new openpgp.packet.secret_key();
|
||||||
|
|
||||||
var rsa = new openpgp.crypto.publicKey.rsa,
|
var rsa = new openpgp.crypto.publicKey.rsa,
|
||||||
|
@ -450,21 +443,7 @@ unit.register("Packet testing", function() {
|
||||||
|
|
||||||
var verified = signed2[1].verify(key, signed2[0]);
|
var verified = signed2[1].verify(key, signed2[0]);
|
||||||
|
|
||||||
|
expect(verified).to.be.true;
|
||||||
return new unit.result('Writing and verification of a signature packet.',
|
done();
|
||||||
verified == true);
|
});
|
||||||
}];
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
tests.reverse();
|
|
||||||
|
|
||||||
var results = [];
|
|
||||||
|
|
||||||
for(var i in tests) {
|
|
||||||
results.push(tests[i]());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
return results;
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
var unit = require('../unit.js');
|
|
||||||
|
|
||||||
unit.register("Signature testing", function() {
|
|
||||||
var openpgp = require('openpgp');
|
var openpgp = require('openpgp');
|
||||||
|
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
var expect = chai.expect;
|
||||||
|
|
||||||
|
describe("Signature testing", function() {
|
||||||
var priv_key_arm1 =
|
var priv_key_arm1 =
|
||||||
[ '-----BEGIN PGP PRIVATE KEY BLOCK-----',
|
[ '-----BEGIN PGP PRIVATE KEY BLOCK-----',
|
||||||
'Version: GnuPG v1.4.11 (GNU/Linux)',
|
'Version: GnuPG v1.4.11 (GNU/Linux)',
|
||||||
|
@ -32,6 +34,7 @@ unit.register("Signature testing", function() {
|
||||||
'=LSrW',
|
'=LSrW',
|
||||||
'-----END PGP PRIVATE KEY BLOCK-----'
|
'-----END PGP PRIVATE KEY BLOCK-----'
|
||||||
].join("\n");
|
].join("\n");
|
||||||
|
|
||||||
var pub_key_arm1 =
|
var pub_key_arm1 =
|
||||||
[ '-----BEGIN PGP PUBLIC KEY BLOCK-----',
|
[ '-----BEGIN PGP PUBLIC KEY BLOCK-----',
|
||||||
'Version: GnuPG v1.4.11 (GNU/Linux)',
|
'Version: GnuPG v1.4.11 (GNU/Linux)',
|
||||||
|
@ -51,6 +54,7 @@ unit.register("Signature testing", function() {
|
||||||
'=b2Ln',
|
'=b2Ln',
|
||||||
'-----END PGP PUBLIC KEY BLOCK-----'
|
'-----END PGP PUBLIC KEY BLOCK-----'
|
||||||
].join("\n");
|
].join("\n");
|
||||||
|
|
||||||
var msg_arm1 =
|
var msg_arm1 =
|
||||||
[ '-----BEGIN PGP MESSAGE-----',
|
[ '-----BEGIN PGP MESSAGE-----',
|
||||||
'Version: GnuPG v1.4.11 (GNU/Linux)',
|
'Version: GnuPG v1.4.11 (GNU/Linux)',
|
||||||
|
@ -109,7 +113,8 @@ unit.register("Signature testing", function() {
|
||||||
'SXuqKcWqoEuO7OBSEFThCXBfUYMC01OrqKEswPm/V3zZkLu01q12UMwZach28QwK',
|
'SXuqKcWqoEuO7OBSEFThCXBfUYMC01OrqKEswPm/V3zZkLu01q12UMwZach28QwK',
|
||||||
'/YZly4ioND2tdazj17u2rU2dwtiHPe1iMqGgVMoQirfLc+k=',
|
'/YZly4ioND2tdazj17u2rU2dwtiHPe1iMqGgVMoQirfLc+k=',
|
||||||
'=lw5e',
|
'=lw5e',
|
||||||
'-----END PGP PRIVATE KEY BLOCK-----'].join('\n');
|
'-----END PGP PRIVATE KEY BLOCK-----'
|
||||||
|
].join('\n');
|
||||||
|
|
||||||
var pub_key_arm2 =
|
var pub_key_arm2 =
|
||||||
[ '-----BEGIN PGP PUBLIC KEY BLOCK-----',
|
[ '-----BEGIN PGP PUBLIC KEY BLOCK-----',
|
||||||
|
@ -135,7 +140,8 @@ unit.register("Signature testing", function() {
|
||||||
'AtNTq6ihLMD5v1d82ZC7tNatdlDMGWnIdvEMCv2GZcuIqDQ9rXWs49e7tq1NncLY',
|
'AtNTq6ihLMD5v1d82ZC7tNatdlDMGWnIdvEMCv2GZcuIqDQ9rXWs49e7tq1NncLY',
|
||||||
'hz3tYjKhoFTKEIq3y3Pp',
|
'hz3tYjKhoFTKEIq3y3Pp',
|
||||||
'=h/aX',
|
'=h/aX',
|
||||||
'-----END PGP PUBLIC KEY BLOCK-----'].join('\n');
|
'-----END PGP PUBLIC KEY BLOCK-----'
|
||||||
|
].join('\n');
|
||||||
|
|
||||||
var pub_key_arm3 =
|
var pub_key_arm3 =
|
||||||
[ '-----BEGIN PGP PUBLIC KEY BLOCK-----',
|
[ '-----BEGIN PGP PUBLIC KEY BLOCK-----',
|
||||||
|
@ -167,7 +173,8 @@ var pub_key_arm3 =
|
||||||
'znN6qtN5gMlGY1ofWDY+I02gO4qzaZ/FxRZfittCw7v5dmQYKot9qRi2Kx3Fvw+h',
|
'znN6qtN5gMlGY1ofWDY+I02gO4qzaZ/FxRZfittCw7v5dmQYKot9qRi2Kx3Fvw+h',
|
||||||
'ivFBpC4TWgppFBnJJnAsFXZJQcejMW4nEmOViRQXY8N8PepQmgsu',
|
'ivFBpC4TWgppFBnJJnAsFXZJQcejMW4nEmOViRQXY8N8PepQmgsu',
|
||||||
'=ummy',
|
'=ummy',
|
||||||
'-----END PGP PUBLIC KEY BLOCK-----'].join('\n');
|
'-----END PGP PUBLIC KEY BLOCK-----'
|
||||||
|
].join('\n');
|
||||||
|
|
||||||
var pub_revoked =
|
var pub_revoked =
|
||||||
[ '-----BEGIN PGP PUBLIC KEY BLOCK-----',
|
[ '-----BEGIN PGP PUBLIC KEY BLOCK-----',
|
||||||
|
@ -219,7 +226,8 @@ var pub_revoked =
|
||||||
'jgvGbcTzxnvrRmDevmJUdXBSAE11OYQuDGlhgFCU0o9cdX+k+QqP5wNycXhoJ+yk',
|
'jgvGbcTzxnvrRmDevmJUdXBSAE11OYQuDGlhgFCU0o9cdX+k+QqP5wNycXhoJ+yk',
|
||||||
'pMiJM+NJAQ==',
|
'pMiJM+NJAQ==',
|
||||||
'=ok+o',
|
'=ok+o',
|
||||||
'-----END PGP PUBLIC KEY BLOCK-----'].join('\n');
|
'-----END PGP PUBLIC KEY BLOCK-----'
|
||||||
|
].join('\n');
|
||||||
|
|
||||||
var pub_v3 =
|
var pub_v3 =
|
||||||
[ '-----BEGIN PGP PUBLIC KEY BLOCK-----',
|
[ '-----BEGIN PGP PUBLIC KEY BLOCK-----',
|
||||||
|
@ -248,25 +256,25 @@ var pub_v3 =
|
||||||
'O+Ag4qwKKH+y/ke9CeZL6AnrU9c0pux150dHsDeHtpTPyInkjgKI7BofprydvpiFNd0nlAi4',
|
'O+Ag4qwKKH+y/ke9CeZL6AnrU9c0pux150dHsDeHtpTPyInkjgKI7BofprydvpiFNd0nlAi4',
|
||||||
'J4SAEYr3q92Qn/IiKpnLgo6Ls/GFb7q6y1O/2LL8PC2zrYU=',
|
'J4SAEYr3q92Qn/IiKpnLgo6Ls/GFb7q6y1O/2LL8PC2zrYU=',
|
||||||
'=eoGb',
|
'=eoGb',
|
||||||
'-----END PGP PUBLIC KEY BLOCK-----'].join('\n');
|
'-----END PGP PUBLIC KEY BLOCK-----'
|
||||||
|
].join('\n');
|
||||||
|
|
||||||
|
it('Testing signature checking on CAST5-enciphered message', function(done) {
|
||||||
var tests = [function() {
|
|
||||||
var priv_key = openpgp.key.readArmored(priv_key_arm1).keys[0];
|
var priv_key = openpgp.key.readArmored(priv_key_arm1).keys[0];
|
||||||
var pub_key = openpgp.key.readArmored(pub_key_arm1).keys[0];
|
var pub_key = openpgp.key.readArmored(pub_key_arm1).keys[0];
|
||||||
var msg = openpgp.message.readArmored(msg_arm1);
|
var msg = openpgp.message.readArmored(msg_arm1);
|
||||||
priv_key.decrypt("abcd");
|
priv_key.decrypt("abcd");
|
||||||
var decrypted = openpgp.decryptAndVerifyMessage(priv_key, [pub_key], msg);
|
var decrypted = openpgp.decryptAndVerifyMessage(priv_key, [pub_key], msg);
|
||||||
var verified = decrypted && decrypted.signatures[0].valid;
|
expect(decrypted).to.exist;
|
||||||
return new unit.result("Testing signature checking on CAST5-enciphered message",
|
expect(decrypted.signatures[0].valid).to.be.true;
|
||||||
verified);
|
done();
|
||||||
|
});
|
||||||
}, function() {
|
|
||||||
|
|
||||||
|
it('Testing GnuPG stripped-key extensions', function(done) {
|
||||||
// exercises the GnuPG s2k type 1001 extension:
|
// exercises the GnuPG s2k type 1001 extension:
|
||||||
// the secrets on the primary key have been stripped.
|
// the secrets on the primary key have been stripped.
|
||||||
var priv_key_gnupg_ext = openpgp.key.readArmored([
|
var priv_key_gnupg_ext = openpgp.key.readArmored(
|
||||||
'-----BEGIN PGP PRIVATE KEY BLOCK-----',
|
[ '-----BEGIN PGP PRIVATE KEY BLOCK-----',
|
||||||
'Version: GnuPG v1.4.11 (GNU/Linux)',
|
'Version: GnuPG v1.4.11 (GNU/Linux)',
|
||||||
'',
|
'',
|
||||||
'lQGqBFERnrMRBADmM0hIfkI3yosjgbWo9v0Lnr3CCE+8KsMszgVS+hBu0XfGraKm',
|
'lQGqBFERnrMRBADmM0hIfkI3yosjgbWo9v0Lnr3CCE+8KsMszgVS+hBu0XfGraKm',
|
||||||
|
@ -291,7 +299,7 @@ var pub_v3 =
|
||||||
'nrMCGwwACgkQESeUA8sWnvhBswCfdXjznvHCc73/6/MhWcv3dbeTT/wAoLyiZg8+',
|
'nrMCGwwACgkQESeUA8sWnvhBswCfdXjznvHCc73/6/MhWcv3dbeTT/wAoLyiZg8+',
|
||||||
'iY3UT9QkV9d0sMgyLkug',
|
'iY3UT9QkV9d0sMgyLkug',
|
||||||
'=GQsY',
|
'=GQsY',
|
||||||
'-----END PGP PRIVATE KEY BLOCK-----',
|
'-----END PGP PRIVATE KEY BLOCK-----'
|
||||||
].join("\n")).keys[0];
|
].join("\n")).keys[0];
|
||||||
var pub_key = openpgp.key.readArmored(pub_key_arm1).keys[0];
|
var pub_key = openpgp.key.readArmored(pub_key_arm1).keys[0];
|
||||||
var msg = openpgp.message.readArmored(msg_arm1);
|
var msg = openpgp.message.readArmored(msg_arm1);
|
||||||
|
@ -299,11 +307,13 @@ var pub_v3 =
|
||||||
priv_key_gnupg_ext.subKeys[0].subKey.decrypt("abcd");
|
priv_key_gnupg_ext.subKeys[0].subKey.decrypt("abcd");
|
||||||
msg = msg.decrypt(priv_key_gnupg_ext);
|
msg = msg.decrypt(priv_key_gnupg_ext);
|
||||||
var verified = msg.verify([pub_key]);
|
var verified = msg.verify([pub_key]);
|
||||||
return new unit.result("Testing GnuPG stripped-key extensions",
|
expect(verified).to.exist;
|
||||||
verified[0].valid);
|
expect(verified).to.have.length(1);
|
||||||
|
expect(verified[0].valid).to.be.true;
|
||||||
}, function() {
|
done();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Verify V4 signature. Hash: SHA1. PK: RSA. Signature Type: 0x00 (binary document)', function(done) {
|
||||||
var signedArmor =
|
var signedArmor =
|
||||||
[ '-----BEGIN PGP MESSAGE-----',
|
[ '-----BEGIN PGP MESSAGE-----',
|
||||||
'Version: GnuPG v2.0.19 (GNU/Linux)',
|
'Version: GnuPG v2.0.19 (GNU/Linux)',
|
||||||
|
@ -314,14 +324,19 @@ var pub_v3 =
|
||||||
'cw6U57n3/Z4X0pEZ68C5/o/6NpPICD7fuEOz3936raZ6wXGzueY8pfPnVjY0ajAc',
|
'cw6U57n3/Z4X0pEZ68C5/o/6NpPICD7fuEOz3936raZ6wXGzueY8pfPnVjY0ajAc',
|
||||||
'PtJzvvqj+ubYaT1sK9wWhd9lL3/V+9Zuua9QjOWC22buchsCroh8fLoZAA==',
|
'PtJzvvqj+ubYaT1sK9wWhd9lL3/V+9Zuua9QjOWC22buchsCroh8fLoZAA==',
|
||||||
'=VH8F',
|
'=VH8F',
|
||||||
'-----END PGP MESSAGE-----'].join('\n');
|
'-----END PGP MESSAGE-----'
|
||||||
|
].join('\n');
|
||||||
|
|
||||||
var sMsg = openpgp.message.readArmored(signedArmor);
|
var sMsg = openpgp.message.readArmored(signedArmor);
|
||||||
var pub_key = openpgp.key.readArmored(pub_key_arm2).keys[0];
|
var pub_key = openpgp.key.readArmored(pub_key_arm2).keys[0];
|
||||||
var verified = sMsg.verify([pub_key]);
|
var verified = sMsg.verify([pub_key]);
|
||||||
return new unit.result("Verify V4 signature. Hash: SHA1. PK: RSA. Signature Type: 0x00 (binary document)", verified[0].valid);
|
expect(verified).to.exist;
|
||||||
}, function() {
|
expect(verified).to.have.length(1);
|
||||||
|
expect(verified[0].valid).to.be.true;
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Verify V3 signature. Hash: MD5. PK: RSA. Signature Type: 0x01 (text document)', function(done) {
|
||||||
var signedArmor =
|
var signedArmor =
|
||||||
[ '-----BEGIN PGP MESSAGE-----',
|
[ '-----BEGIN PGP MESSAGE-----',
|
||||||
'Version: GnuPG v2.0.19 (GNU/Linux)',
|
'Version: GnuPG v2.0.19 (GNU/Linux)',
|
||||||
|
@ -332,14 +347,19 @@ var pub_v3 =
|
||||||
'aPJyvm9TTpobW/O+P1n2THLS4UCvWt12Oa2lJ04GLwk/bDF1u+8ZpfPCpsxLVzcs',
|
'aPJyvm9TTpobW/O+P1n2THLS4UCvWt12Oa2lJ04GLwk/bDF1u+8ZpfPCpsxLVzcs',
|
||||||
'ZGtbq/f23XxV/jkL47hr3s3Ic4yoZTW4oZO27GYf37TPp9L3VboCAA==',
|
'ZGtbq/f23XxV/jkL47hr3s3Ic4yoZTW4oZO27GYf37TPp9L3VboCAA==',
|
||||||
'=pa6B',
|
'=pa6B',
|
||||||
'-----END PGP MESSAGE-----'].join('\n');
|
'-----END PGP MESSAGE-----'
|
||||||
|
].join('\n');
|
||||||
|
|
||||||
var sMsg = openpgp.message.readArmored(signedArmor);
|
var sMsg = openpgp.message.readArmored(signedArmor);
|
||||||
var pub_key = openpgp.key.readArmored(pub_key_arm2).keys[0];
|
var pub_key = openpgp.key.readArmored(pub_key_arm2).keys[0];
|
||||||
var verified = sMsg.verify([pub_key]);
|
var verified = sMsg.verify([pub_key]);
|
||||||
return new unit.result("Verify V3 signature. Hash: MD5. PK: RSA. Signature Type: 0x01 (text document)", verified[0].valid);
|
expect(verified).to.exist;
|
||||||
}, function() {
|
expect(verified).to.have.length(1);
|
||||||
|
expect(verified[0].valid).to.be.true;
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Verify signature of signed and encrypted message from GPG2 with openpgp.decryptAndVerifyMessage', function(done) {
|
||||||
var msg_armor =
|
var msg_armor =
|
||||||
[ '-----BEGIN PGP MESSAGE-----',
|
[ '-----BEGIN PGP MESSAGE-----',
|
||||||
'Version: GnuPG v2.0.19 (GNU/Linux)',
|
'Version: GnuPG v2.0.19 (GNU/Linux)',
|
||||||
|
@ -354,7 +374,8 @@ var pub_v3 =
|
||||||
'ifxyV4zia9RvaCUY8vXGM+gQJ3NNXx2LkZA3kWUEyxFVL1Vl/XUQY0M6U+uccSk4',
|
'ifxyV4zia9RvaCUY8vXGM+gQJ3NNXx2LkZA3kWUEyxFVL1Vl/XUQY0M6U+uccSk4',
|
||||||
'eMXm6eyEWDcj0lBRckqKoKo1w/uan11jPuHsnRz6jO9DsuKEz79UDgI=',
|
'eMXm6eyEWDcj0lBRckqKoKo1w/uan11jPuHsnRz6jO9DsuKEz79UDgI=',
|
||||||
'=cFi7',
|
'=cFi7',
|
||||||
'-----END PGP MESSAGE-----'].join('\n');
|
'-----END PGP MESSAGE-----'
|
||||||
|
].join('\n');
|
||||||
|
|
||||||
var plaintext = 'short message\nnext line\n한국어/조선말';
|
var plaintext = 'short message\nnext line\n한국어/조선말';
|
||||||
var esMsg = openpgp.message.readArmored(msg_armor);
|
var esMsg = openpgp.message.readArmored(msg_armor);
|
||||||
|
@ -365,11 +386,15 @@ var pub_v3 =
|
||||||
privKey.decryptKeyPacket(keyids, 'hello world');
|
privKey.decryptKeyPacket(keyids, 'hello world');
|
||||||
|
|
||||||
var decrypted = openpgp.decryptAndVerifyMessage(privKey, [pubKey], esMsg);
|
var decrypted = openpgp.decryptAndVerifyMessage(privKey, [pubKey], esMsg);
|
||||||
var verified = decrypted.text == plaintext && decrypted.signatures[0].valid;
|
|
||||||
|
|
||||||
return new unit.result("Verify signature of signed and encrypted message from GPG2 with openpgp.decryptAndVerifyMessage", verified);
|
expect(decrypted).to.exist;
|
||||||
}, function() {
|
expect(decrypted.text).to.equal(plaintext);
|
||||||
|
expect(decrypted.signatures).to.have.length(1);
|
||||||
|
expect(decrypted.signatures[0].valid).to.be.true;
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Verify signature of signed and encrypted message from PGP 10.3.0 with openpgp.decryptAndVerifyMessage', function(done) {
|
||||||
var msg_armor =
|
var msg_armor =
|
||||||
[ '-----BEGIN PGP MESSAGE-----',
|
[ '-----BEGIN PGP MESSAGE-----',
|
||||||
'Version: Encryption Desktop 10.3.0 (Build 9307)',
|
'Version: Encryption Desktop 10.3.0 (Build 9307)',
|
||||||
|
@ -385,7 +410,8 @@ var pub_v3 =
|
||||||
'oyqzb9Vsgu1gS7SCb6qTbnbV9PlSyU4wJB6siX8hz/U0urokT5se3uYRjiV0KbkA',
|
'oyqzb9Vsgu1gS7SCb6qTbnbV9PlSyU4wJB6siX8hz/U0urokT5se3uYRjiV0KbkA',
|
||||||
'zl1/r/wCrmwX4Gl9VN9+33cQgYZAlJLsRw8N82GhbVweZS8qwv24GQ==',
|
'zl1/r/wCrmwX4Gl9VN9+33cQgYZAlJLsRw8N82GhbVweZS8qwv24GQ==',
|
||||||
'=nx90',
|
'=nx90',
|
||||||
'-----END PGP MESSAGE-----'].join('\n');
|
'-----END PGP MESSAGE-----'
|
||||||
|
].join('\n');
|
||||||
|
|
||||||
var plaintext = 'short message\nnext line\n한국어/조선말\n\n';
|
var plaintext = 'short message\nnext line\n한국어/조선말\n\n';
|
||||||
var esMsg = openpgp.message.readArmored(msg_armor);
|
var esMsg = openpgp.message.readArmored(msg_armor);
|
||||||
|
@ -396,11 +422,15 @@ var pub_v3 =
|
||||||
privKey.decryptKeyPacket(keyids, 'hello world');
|
privKey.decryptKeyPacket(keyids, 'hello world');
|
||||||
|
|
||||||
var decrypted = openpgp.decryptAndVerifyMessage(privKey, [pubKey], esMsg);
|
var decrypted = openpgp.decryptAndVerifyMessage(privKey, [pubKey], esMsg);
|
||||||
var verified = decrypted.text == plaintext && decrypted.signatures[0].valid;
|
|
||||||
|
|
||||||
return new unit.result("Verify signature of signed and encrypted message from PGP 10.3.0 with openpgp.decryptAndVerifyMessage", verified);
|
expect(decrypted).to.exist;
|
||||||
}, function() {
|
expect(decrypted.text).to.equal(plaintext);
|
||||||
|
expect(decrypted.signatures).to.have.length(1);
|
||||||
|
expect(decrypted.signatures[0].valid).to.be.true;
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Verify signed message with two one pass signatures', function(done) {
|
||||||
var msg_armor =
|
var msg_armor =
|
||||||
[ '-----BEGIN PGP MESSAGE-----',
|
[ '-----BEGIN PGP MESSAGE-----',
|
||||||
'Version: GnuPG v2.0.19 (GNU/Linux)',
|
'Version: GnuPG v2.0.19 (GNU/Linux)',
|
||||||
|
@ -417,7 +447,8 @@ var pub_v3 =
|
||||||
'axdLZ9yd0OJNZv4P501If24W4vTGz6nI7Ser8Yd2PiOvE5MWMT0wLZQ+zPX1sv0/',
|
'axdLZ9yd0OJNZv4P501If24W4vTGz6nI7Ser8Yd2PiOvE5MWMT0wLZQ+zPX1sv0/',
|
||||||
's8PvkyWmVM0O0fB/ZSHovHNNPffDg/rWhzOmXQ9/7vTn477F+aWm5sYzJ75/BQA=',
|
's8PvkyWmVM0O0fB/ZSHovHNNPffDg/rWhzOmXQ9/7vTn477F+aWm5sYzJ75/BQA=',
|
||||||
'=+L0S',
|
'=+L0S',
|
||||||
'-----END PGP MESSAGE-----'].join('\n');
|
'-----END PGP MESSAGE-----'
|
||||||
|
].join('\n');
|
||||||
|
|
||||||
var plaintext = 'short message\nnext line\n한국어/조선말';
|
var plaintext = 'short message\nnext line\n한국어/조선말';
|
||||||
var sMsg = openpgp.message.readArmored(msg_armor);
|
var sMsg = openpgp.message.readArmored(msg_armor);
|
||||||
|
@ -426,17 +457,21 @@ var pub_v3 =
|
||||||
|
|
||||||
var keyids = sMsg.getSigningKeyIds();
|
var keyids = sMsg.getSigningKeyIds();
|
||||||
|
|
||||||
var verified = pubKey2.getPublicKeyPacket(keyids) !== null && pubKey3.getPublicKeyPacket(keyids) !== null;
|
expect(pubKey2.getPublicKeyPacket(keyids)).to.exist;
|
||||||
|
expect(pubKey3.getPublicKeyPacket(keyids)).to.exist;
|
||||||
|
|
||||||
verified = verified && sMsg.getText() == plaintext;
|
expect(sMsg.getText()).to.equal(plaintext);
|
||||||
|
|
||||||
var verifiedSig = sMsg.verify([pubKey2, pubKey3]);
|
var verifiedSig = sMsg.verify([pubKey2, pubKey3]);
|
||||||
|
|
||||||
verified = verified && verifiedSig[0].valid && verifiedSig[1].valid;
|
expect(verifiedSig).to.exist;
|
||||||
|
expect(verifiedSig).to.have.length(2);
|
||||||
return new unit.result("Verify signed message with two one pass signatures", verified);
|
expect(verifiedSig[0].valid).to.be.true;
|
||||||
}, function() {
|
expect(verifiedSig[1].valid).to.be.true;
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Verify cleartext signed message with two signatures with openpgp.verifyClearSignedMessage', function(done) {
|
||||||
var msg_armor =
|
var msg_armor =
|
||||||
[ '-----BEGIN PGP SIGNED MESSAGE-----',
|
[ '-----BEGIN PGP SIGNED MESSAGE-----',
|
||||||
'Hash: SHA256',
|
'Hash: SHA256',
|
||||||
|
@ -458,7 +493,8 @@ var pub_v3 =
|
||||||
'vCCq7fgaUz8ksxvQ9bSwv0iIIbbBdTP7Z8y2c1Oof6NDl7irH+QCeNT7IIGs8Smn',
|
'vCCq7fgaUz8ksxvQ9bSwv0iIIbbBdTP7Z8y2c1Oof6NDl7irH+QCeNT7IIGs8Smn',
|
||||||
'BEzv/FqkQAhjy3Krxg==',
|
'BEzv/FqkQAhjy3Krxg==',
|
||||||
'=3Pkl',
|
'=3Pkl',
|
||||||
'-----END PGP SIGNATURE-----'].join('\n');
|
'-----END PGP SIGNATURE-----'
|
||||||
|
].join('\n');
|
||||||
|
|
||||||
var plaintext = 'short message\nnext line\n한국어/조선말';
|
var plaintext = 'short message\nnext line\n한국어/조선말';
|
||||||
var csMsg = openpgp.cleartext.readArmored(msg_armor);
|
var csMsg = openpgp.cleartext.readArmored(msg_armor);
|
||||||
|
@ -467,17 +503,20 @@ var pub_v3 =
|
||||||
|
|
||||||
var keyids = csMsg.getSigningKeyIds();
|
var keyids = csMsg.getSigningKeyIds();
|
||||||
|
|
||||||
var verified = pubKey2.getPublicKeyPacket(keyids) !== null && pubKey3.getPublicKeyPacket(keyids) !== null;
|
expect(pubKey2.getPublicKeyPacket(keyids)).to.exist;
|
||||||
|
expect(pubKey3.getPublicKeyPacket(keyids)).to.exist;
|
||||||
|
|
||||||
var cleartextSig = openpgp.verifyClearSignedMessage([pubKey2, pubKey3], csMsg);
|
var cleartextSig = openpgp.verifyClearSignedMessage([pubKey2, pubKey3], csMsg);
|
||||||
|
|
||||||
verified = verified && cleartextSig.text == plaintext;
|
expect(cleartextSig).to.exist;
|
||||||
|
expect(cleartextSig.text).to.equal(plaintext);
|
||||||
verified = verified && cleartextSig.signatures[0].valid && cleartextSig.signatures[1].valid;
|
expect(cleartextSig.signatures).to.have.length(2);
|
||||||
|
expect(cleartextSig.signatures[0].valid).to.be.true;
|
||||||
return new unit.result("Verify cleartext signed message with two signatures with openpgp.verifyClearSignedMessage", verified);
|
expect(cleartextSig.signatures[1].valid).to.be.true;
|
||||||
}, function() {
|
done();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Sign text with openpgp.signClearMessage and verify with openpgp.verifyClearSignedMessage leads to same cleartext and valid signatures', function(done) {
|
||||||
var plaintext = 'short message\nnext line\n한국어/조선말';
|
var plaintext = 'short message\nnext line\n한국어/조선말';
|
||||||
var pubKey = openpgp.key.readArmored(pub_key_arm2).keys[0];
|
var pubKey = openpgp.key.readArmored(pub_key_arm2).keys[0];
|
||||||
var privKey = openpgp.key.readArmored(priv_key_arm2).keys[0];
|
var privKey = openpgp.key.readArmored(priv_key_arm2).keys[0];
|
||||||
|
@ -489,48 +528,46 @@ var pub_v3 =
|
||||||
|
|
||||||
var cleartextSig = openpgp.verifyClearSignedMessage([pubKey], csMsg);
|
var cleartextSig = openpgp.verifyClearSignedMessage([pubKey], csMsg);
|
||||||
|
|
||||||
var verified = cleartextSig.text == plaintext.replace(/\r/g,'');
|
expect(cleartextSig).to.exist;
|
||||||
|
expect(cleartextSig.text).to.equal(plaintext.replace(/\r/g,''));
|
||||||
verified = verified && cleartextSig.signatures[0].valid;
|
expect(cleartextSig.signatures).to.have.length(1);
|
||||||
|
expect(cleartextSig.signatures[0].valid).to.be.true;
|
||||||
return new unit.result("Sign text with openpgp.signClearMessage and verify with openpgp.verifyClearSignedMessage leads to same cleartext and valid signatures", verified);
|
done();
|
||||||
}, function() {
|
});
|
||||||
|
|
||||||
|
it('Verify primary key revocation signature', function(done) {
|
||||||
var pubKey = openpgp.key.readArmored(pub_revoked).keys[0];
|
var pubKey = openpgp.key.readArmored(pub_revoked).keys[0];
|
||||||
|
|
||||||
var verified = pubKey.revocationSignature.verify(pubKey.primaryKey, {key: pubKey.primaryKey});
|
var verified = pubKey.revocationSignature.verify(pubKey.primaryKey, {key: pubKey.primaryKey});
|
||||||
|
|
||||||
return new unit.result("Verify primary key revocation signature", verified);
|
expect(verified).to.be.true;
|
||||||
}, function() {
|
done();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Verify subkey revocation signature', function(done) {
|
||||||
var pubKey = openpgp.key.readArmored(pub_revoked).keys[0];
|
var pubKey = openpgp.key.readArmored(pub_revoked).keys[0];
|
||||||
|
|
||||||
var verified = pubKey.subKeys[0].revocationSignature.verify(pubKey.primaryKey, {key: pubKey.subKeys[0].subKey});
|
var verified = pubKey.subKeys[0].revocationSignature.verify(pubKey.primaryKey, {key: pubKey.subKeys[0].subKey});
|
||||||
|
|
||||||
return new unit.result("Verify subkey revocation signature", verified);
|
expect(verified).to.be.true;
|
||||||
}, function() {
|
done();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Verify key expiration date', function(done) {
|
||||||
var pubKey = openpgp.key.readArmored(pub_revoked).keys[0];
|
var pubKey = openpgp.key.readArmored(pub_revoked).keys[0];
|
||||||
|
|
||||||
var verified = !pubKey.users[0].selfCertifications[0].keyNeverExpires &&
|
expect(pubKey).to.exist;
|
||||||
pubKey.users[0].selfCertifications[0].keyExpirationTime == 5*365*24*60*60;
|
expect(pubKey.users[0].selfCertifications[0].keyNeverExpires).to.be.false;
|
||||||
|
expect(pubKey.users[0].selfCertifications[0].keyExpirationTime).to.equal(5*365*24*60*60);
|
||||||
return new unit.result("Verify key expiration date", verified);
|
done();
|
||||||
}, function() {
|
});
|
||||||
|
|
||||||
|
it('Verify V3 certification signature', function(done) {
|
||||||
var pubKey = openpgp.key.readArmored(pub_v3).keys[0];
|
var pubKey = openpgp.key.readArmored(pub_v3).keys[0];
|
||||||
|
|
||||||
var verified = pubKey.users[0].selfCertifications[0].verify(pubKey.primaryKey, {key: pubKey.primaryKey, userid: pubKey.users[0].userId});
|
var verified = pubKey.users[0].selfCertifications[0].verify(pubKey.primaryKey, {key: pubKey.primaryKey, userid: pubKey.users[0].userId});
|
||||||
|
|
||||||
return new unit.result("Verify V3 certification signature", verified);
|
expect(verified).to.be.true;
|
||||||
}];
|
done();
|
||||||
|
});
|
||||||
var results = [];
|
|
||||||
|
|
||||||
for(var i in tests) {
|
|
||||||
results.push(tests[i]());
|
|
||||||
}
|
|
||||||
|
|
||||||
return results;
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue
Block a user