|
|
|
@ -560,7 +560,7 @@ const pgp_desktop_priv =
|
|
|
|
|
'=63Nq',
|
|
|
|
|
'-----END PGP PRIVATE KEY BLOCK-----'].join('\n');
|
|
|
|
|
|
|
|
|
|
const rsa_ecc_pub =
|
|
|
|
|
const rsa_ecc_pub =
|
|
|
|
|
['pub rsa4096/C9DEDC77 2015-10-17 [expires: 2018-10-16]',
|
|
|
|
|
'uid Google Security Team <security@google.com>',
|
|
|
|
|
'sub nistp384/70C16E3C 2015-10-17 [expires: 2018-10-16]',
|
|
|
|
@ -1995,7 +1995,7 @@ function versionSpecificTests() {
|
|
|
|
|
}
|
|
|
|
|
expect(key.users[0].selfCertifications[0].features).to.eql(expectedFeatures);
|
|
|
|
|
};
|
|
|
|
|
const opt = {userIds: 'test <a@b.com>', passphrase: 'hello'};
|
|
|
|
|
const opt = { userIds: 'test <a@b.com>', passphrase: 'hello' };
|
|
|
|
|
return openpgp.generateKey(opt).then(async function(key) {
|
|
|
|
|
testPref(key.key);
|
|
|
|
|
testPref(await openpgp.key.readArmored(key.publicKeyArmored));
|
|
|
|
@ -2040,7 +2040,7 @@ function versionSpecificTests() {
|
|
|
|
|
}
|
|
|
|
|
expect(key.users[0].selfCertifications[0].features).to.eql(expectedFeatures);
|
|
|
|
|
};
|
|
|
|
|
const opt = {userIds: 'test <a@b.com>', passphrase: 'hello'};
|
|
|
|
|
const opt = { userIds: 'test <a@b.com>', passphrase: 'hello' };
|
|
|
|
|
try {
|
|
|
|
|
const key = await openpgp.generateKey(opt);
|
|
|
|
|
testPref(key.key);
|
|
|
|
@ -2054,7 +2054,7 @@ function versionSpecificTests() {
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('Generated key is not unlocked by default', function() {
|
|
|
|
|
const opt = {userIds: 'test <a@b.com>', passphrase: '123'};
|
|
|
|
|
const opt = { userIds: 'test <a@b.com>', passphrase: '123' };
|
|
|
|
|
let key;
|
|
|
|
|
return openpgp.generateKey(opt).then(function(newKey) {
|
|
|
|
|
key = newKey.key;
|
|
|
|
@ -2068,7 +2068,7 @@ function versionSpecificTests() {
|
|
|
|
|
|
|
|
|
|
it('Generate key - single userid', function() {
|
|
|
|
|
const userId = { name: 'test', email: 'a@b.com', comment: 'test comment' };
|
|
|
|
|
const opt = {userIds: userId, passphrase: '123'};
|
|
|
|
|
const opt = { userIds: userId, passphrase: '123' };
|
|
|
|
|
return openpgp.generateKey(opt).then(function(key) {
|
|
|
|
|
key = key.key;
|
|
|
|
|
expect(key.users.length).to.equal(1);
|
|
|
|
@ -2081,7 +2081,7 @@ function versionSpecificTests() {
|
|
|
|
|
|
|
|
|
|
it('Generate key - single userid (all missing)', function() {
|
|
|
|
|
const userId = { name: '', email: '', comment: '' };
|
|
|
|
|
const opt = {userIds: userId, passphrase: '123'};
|
|
|
|
|
const opt = { userIds: userId, passphrase: '123' };
|
|
|
|
|
return openpgp.generateKey(opt).then(function(key) {
|
|
|
|
|
key = key.key;
|
|
|
|
|
expect(key.users.length).to.equal(1);
|
|
|
|
@ -2094,7 +2094,7 @@ function versionSpecificTests() {
|
|
|
|
|
|
|
|
|
|
it('Generate key - single userid (missing email)', function() {
|
|
|
|
|
const userId = { name: 'test', email: '', comment: 'test comment' };
|
|
|
|
|
const opt = {userIds: userId, passphrase: '123'};
|
|
|
|
|
const opt = { userIds: userId, passphrase: '123' };
|
|
|
|
|
return openpgp.generateKey(opt).then(function(key) {
|
|
|
|
|
key = key.key;
|
|
|
|
|
expect(key.users.length).to.equal(1);
|
|
|
|
@ -2107,7 +2107,7 @@ function versionSpecificTests() {
|
|
|
|
|
|
|
|
|
|
it('Generate key - single userid (missing comment)', function() {
|
|
|
|
|
const userId = { name: 'test', email: 'a@b.com', comment: '' };
|
|
|
|
|
const opt = {userIds: userId, passphrase: '123'};
|
|
|
|
|
const opt = { userIds: userId, passphrase: '123' };
|
|
|
|
|
return openpgp.generateKey(opt).then(function(key) {
|
|
|
|
|
key = key.key;
|
|
|
|
|
expect(key.users.length).to.equal(1);
|
|
|
|
@ -2153,7 +2153,7 @@ function versionSpecificTests() {
|
|
|
|
|
it('Generate key - multi userid', function() {
|
|
|
|
|
const userId1 = 'test <a@b.com>';
|
|
|
|
|
const userId2 = 'test <b@c.com>';
|
|
|
|
|
const opt = {userIds: [userId1, userId2], passphrase: '123'};
|
|
|
|
|
const opt = { userIds: [userId1, userId2], passphrase: '123' };
|
|
|
|
|
return openpgp.generateKey(opt).then(function(key) {
|
|
|
|
|
key = key.key;
|
|
|
|
|
expect(key.users.length).to.equal(2);
|
|
|
|
@ -2166,7 +2166,7 @@ function versionSpecificTests() {
|
|
|
|
|
|
|
|
|
|
it('Generate key - two subkeys with default values', function() {
|
|
|
|
|
const userId = 'test <a@b.com>';
|
|
|
|
|
const opt = {userIds: [userId], passphrase: '123', subkeys:[{},{}]};
|
|
|
|
|
const opt = { userIds: [userId], passphrase: '123', subkeys:[{},{}] };
|
|
|
|
|
return openpgp.generateKey(opt).then(function(key) {
|
|
|
|
|
key = key.key;
|
|
|
|
|
expect(key.users.length).to.equal(1);
|
|
|
|
@ -2180,7 +2180,7 @@ function versionSpecificTests() {
|
|
|
|
|
|
|
|
|
|
it('Generate RSA key - two subkeys with default values', function() {
|
|
|
|
|
const userId = 'test <a@b.com>';
|
|
|
|
|
const opt = {rsaBits: 512, userIds: [userId], passphrase: '123', subkeys:[{},{}]};
|
|
|
|
|
const opt = { rsaBits: 512, userIds: [userId], passphrase: '123', subkeys:[{},{}] };
|
|
|
|
|
if (openpgp.util.getWebCryptoAll()) { opt.rsaBits = 2048; } // webkit webcrypto accepts minimum 2048 bit keys
|
|
|
|
|
|
|
|
|
|
return openpgp.generateKey(opt).then(function(key) {
|
|
|
|
@ -2196,7 +2196,7 @@ function versionSpecificTests() {
|
|
|
|
|
|
|
|
|
|
it('Generate key - one signing subkey', function() {
|
|
|
|
|
const userId = 'test <a@b.com>';
|
|
|
|
|
const opt = {userIds: [userId], passphrase: '123', subkeys:[{}, {sign: true}]};
|
|
|
|
|
const opt = { userIds: [userId], passphrase: '123', subkeys:[{}, { sign: true }] };
|
|
|
|
|
return openpgp.generateKey(opt).then(async function({ privateKeyArmored }) {
|
|
|
|
|
const key = await openpgp.key.readArmored(privateKeyArmored);
|
|
|
|
|
expect(key.users.length).to.equal(1);
|
|
|
|
@ -2212,7 +2212,7 @@ function versionSpecificTests() {
|
|
|
|
|
|
|
|
|
|
it('Reformat key - one signing subkey', function() {
|
|
|
|
|
const userId = 'test <a@b.com>';
|
|
|
|
|
const opt = {userIds: [userId], passphrase: '123', subkeys:[{}, {sign: true}]};
|
|
|
|
|
const opt = { userIds: [userId], passphrase: '123', subkeys:[{}, { sign: true }] };
|
|
|
|
|
return openpgp.generateKey(opt).then(async function({ key }) {
|
|
|
|
|
await key.decrypt('123');
|
|
|
|
|
return openpgp.reformatKey({ privateKey: key, userIds: [userId] });
|
|
|
|
@ -2231,7 +2231,7 @@ function versionSpecificTests() {
|
|
|
|
|
|
|
|
|
|
it('Generate key - override main RSA key options for subkey', function() {
|
|
|
|
|
const userId = 'test <a@b.com>';
|
|
|
|
|
const opt = {rsaBits: 512, userIds: [userId], passphrase: '123', subkeys:[{curve: 'curve25519'}]};
|
|
|
|
|
const opt = { rsaBits: 512, userIds: [userId], passphrase: '123', subkeys:[{ curve: 'curve25519' }] };
|
|
|
|
|
if (openpgp.util.getWebCryptoAll()) { opt.rsaBits = 2048; } // webkit webcrypto accepts minimum 2048 bit keys
|
|
|
|
|
return openpgp.generateKey(opt).then(function(key) {
|
|
|
|
|
key = key.key;
|
|
|
|
@ -2247,7 +2247,7 @@ function versionSpecificTests() {
|
|
|
|
|
|
|
|
|
|
it('Encrypt key with new passphrase', async function() {
|
|
|
|
|
const userId = 'test <a@b.com>';
|
|
|
|
|
const opt = {userIds: userId, passphrase: 'passphrase'};
|
|
|
|
|
const opt = { userIds: userId, passphrase: 'passphrase' };
|
|
|
|
|
const key = (await openpgp.generateKey(opt)).key;
|
|
|
|
|
const armor1 = key.armor();
|
|
|
|
|
const armor2 = key.armor();
|
|
|
|
@ -2267,7 +2267,7 @@ function versionSpecificTests() {
|
|
|
|
|
it('Generate key - ensure keyExpirationTime works', function() {
|
|
|
|
|
const expect_delta = 365 * 24 * 60 * 60;
|
|
|
|
|
const userId = 'test <a@b.com>';
|
|
|
|
|
const opt = {userIds: userId, passphrase: '123', keyExpirationTime: expect_delta};
|
|
|
|
|
const opt = { userIds: userId, passphrase: '123', keyExpirationTime: expect_delta };
|
|
|
|
|
return openpgp.generateKey(opt).then(async function(key) {
|
|
|
|
|
key = key.key;
|
|
|
|
|
|
|
|
|
@ -2366,7 +2366,7 @@ function versionSpecificTests() {
|
|
|
|
|
it('Reformat key without passphrase', function() {
|
|
|
|
|
const userId1 = 'test1 <a@b.com>';
|
|
|
|
|
const userId2 = 'test2 <b@a.com>';
|
|
|
|
|
const opt = {userIds: userId1};
|
|
|
|
|
const opt = { userIds: userId1 };
|
|
|
|
|
return openpgp.generateKey(opt).then(function(key) {
|
|
|
|
|
key = key.key;
|
|
|
|
|
expect(key.users.length).to.equal(1);
|
|
|
|
@ -2386,7 +2386,7 @@ function versionSpecificTests() {
|
|
|
|
|
it('Reformat key with no subkey with passphrase', async function() {
|
|
|
|
|
const userId = 'test1 <a@b.com>';
|
|
|
|
|
const key = await openpgp.key.readArmored(key_without_subkey);
|
|
|
|
|
const opt = {privateKey: key, userIds: [userId], passphrase: "test"};
|
|
|
|
|
const opt = { privateKey: key, userIds: [userId], passphrase: "test" };
|
|
|
|
|
return openpgp.reformatKey(opt).then(function(newKey) {
|
|
|
|
|
newKey = newKey.key;
|
|
|
|
|
expect(newKey.users.length).to.equal(1);
|
|
|
|
@ -2400,14 +2400,14 @@ function versionSpecificTests() {
|
|
|
|
|
const userId2 = 'test <b@c.com>';
|
|
|
|
|
const now = openpgp.util.normalizeDate(new Date());
|
|
|
|
|
const before = openpgp.util.normalizeDate(new Date(0));
|
|
|
|
|
const opt1 = {userIds: [userId1], date: now};
|
|
|
|
|
const opt1 = { userIds: [userId1], date: now };
|
|
|
|
|
return openpgp.generateKey(opt1).then(function(newKey) {
|
|
|
|
|
newKey = newKey.key;
|
|
|
|
|
expect(newKey.users[0].userId.userid).to.equal(userId1);
|
|
|
|
|
expect(+newKey.getCreationTime()).to.equal(+now);
|
|
|
|
|
expect(+newKey.subKeys[0].getCreationTime()).to.equal(+now);
|
|
|
|
|
expect(+newKey.subKeys[0].bindingSignatures[0].created).to.equal(+now);
|
|
|
|
|
const opt2 = {privateKey: newKey, userIds: [userId2], date: before};
|
|
|
|
|
const opt2 = { privateKey: newKey, userIds: [userId2], date: before };
|
|
|
|
|
return openpgp.reformatKey(opt2).then(function(refKey) {
|
|
|
|
|
refKey = refKey.key;
|
|
|
|
|
expect(refKey.users.length).to.equal(1);
|
|
|
|
@ -2420,15 +2420,15 @@ function versionSpecificTests() {
|
|
|
|
|
it('Reformat key with no subkey without passphrase', async function() {
|
|
|
|
|
const userId = 'test1 <a@b.com>';
|
|
|
|
|
const key = await openpgp.key.readArmored(key_without_subkey);
|
|
|
|
|
const opt = {privateKey: key, userIds: [userId]};
|
|
|
|
|
const opt = { privateKey: key, userIds: [userId] };
|
|
|
|
|
return openpgp.reformatKey(opt).then(function(newKey) {
|
|
|
|
|
newKey = newKey.key;
|
|
|
|
|
expect(newKey.users.length).to.equal(1);
|
|
|
|
|
expect(newKey.users[0].userId.userid).to.equal(userId);
|
|
|
|
|
expect(newKey.isDecrypted()).to.be.true;
|
|
|
|
|
return openpgp.sign({message: openpgp.cleartext.fromText('hello'), privateKeys: newKey, armor: true}).then(async function(signed) {
|
|
|
|
|
return openpgp.sign({ message: openpgp.cleartext.fromText('hello'), privateKeys: newKey, armor: true }).then(async function(signed) {
|
|
|
|
|
return openpgp.verify(
|
|
|
|
|
{message: await openpgp.cleartext.readArmored(signed), publicKeys: newKey.toPublic()}
|
|
|
|
|
{ message: await openpgp.cleartext.readArmored(signed), publicKeys: newKey.toPublic() }
|
|
|
|
|
).then(async function(verified) {
|
|
|
|
|
expect(verified.signatures[0].valid).to.be.true;
|
|
|
|
|
const newSigningKey = await newKey.getSigningKey();
|
|
|
|
@ -2443,7 +2443,7 @@ function versionSpecificTests() {
|
|
|
|
|
const userId1 = 'test1 <a@b.com>';
|
|
|
|
|
const userId2 = 'test2 <b@c.com>';
|
|
|
|
|
const userId3 = 'test3 <c@d.com>';
|
|
|
|
|
const opt = {userIds: userId1};
|
|
|
|
|
const opt = { userIds: userId1 };
|
|
|
|
|
return openpgp.generateKey(opt).then(function(key) {
|
|
|
|
|
key = key.key;
|
|
|
|
|
opt.privateKey = key;
|
|
|
|
@ -2463,15 +2463,15 @@ function versionSpecificTests() {
|
|
|
|
|
it('Sign and encrypt with reformatted key', function() {
|
|
|
|
|
const userId1 = 'test1 <a@b.com>';
|
|
|
|
|
const userId2 = 'test2 <b@a.com>';
|
|
|
|
|
const opt = {userIds: userId1};
|
|
|
|
|
const opt = { userIds: userId1 };
|
|
|
|
|
return openpgp.generateKey(opt).then(function(key) {
|
|
|
|
|
key = key.key;
|
|
|
|
|
opt.privateKey = key;
|
|
|
|
|
opt.userIds = userId2;
|
|
|
|
|
return openpgp.reformatKey(opt).then(function(newKey) {
|
|
|
|
|
newKey = newKey.key;
|
|
|
|
|
return openpgp.encrypt({message: openpgp.message.fromText('hello'), publicKeys: newKey.toPublic(), privateKeys: newKey, armor: true}).then(async function(encrypted) {
|
|
|
|
|
return openpgp.decrypt({message: await openpgp.message.readArmored(encrypted), privateKeys: newKey, publicKeys: newKey.toPublic()}).then(function(decrypted) {
|
|
|
|
|
return openpgp.encrypt({ message: openpgp.message.fromText('hello'), publicKeys: newKey.toPublic(), privateKeys: newKey, armor: true }).then(async function(encrypted) {
|
|
|
|
|
return openpgp.decrypt({ message: await openpgp.message.readArmored(encrypted), privateKeys: newKey, publicKeys: newKey.toPublic() }).then(function(decrypted) {
|
|
|
|
|
expect(decrypted.data).to.equal('hello');
|
|
|
|
|
expect(decrypted.signatures[0].valid).to.be.true;
|
|
|
|
|
});
|
|
|
|
@ -2481,9 +2481,9 @@ function versionSpecificTests() {
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('Reject with user-friendly error when reformatting encrypted key', function() {
|
|
|
|
|
const opt = {userIds: 'test1 <a@b.com>', passphrase: '1234'};
|
|
|
|
|
const opt = { userIds: 'test1 <a@b.com>', passphrase: '1234' };
|
|
|
|
|
return openpgp.generateKey(opt).then(function(original) {
|
|
|
|
|
return openpgp.reformatKey({privateKey: original.key, userIds: 'test2 <b@a.com>', passphrase: '1234'}).then(function() {
|
|
|
|
|
return openpgp.reformatKey({ privateKey: original.key, userIds: 'test2 <b@a.com>', passphrase: '1234' }).then(function() {
|
|
|
|
|
throw new Error('reformatKey should result in error when key not decrypted');
|
|
|
|
|
}).catch(function(error) {
|
|
|
|
|
expect(error.message).to.equal('Error reformatting keypair: Key not decrypted');
|
|
|
|
@ -2492,9 +2492,9 @@ function versionSpecificTests() {
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('Revoke generated key with revocation certificate', function() {
|
|
|
|
|
const opt = {userIds: 'test1 <a@b.com>', passphrase: '1234'};
|
|
|
|
|
const opt = { userIds: 'test1 <a@b.com>', passphrase: '1234' };
|
|
|
|
|
return openpgp.generateKey(opt).then(function(original) {
|
|
|
|
|
return openpgp.revokeKey({key: original.key.toPublic(), revocationCertificate: original.revocationCertificate}).then(async function(revKey) {
|
|
|
|
|
return openpgp.revokeKey({ key: original.key.toPublic(), revocationCertificate: original.revocationCertificate }).then(async function(revKey) {
|
|
|
|
|
revKey = revKey.publicKey;
|
|
|
|
|
expect(revKey.revocationSignatures[0].reasonForRevocationFlag).to.equal(openpgp.enums.reasonForRevocation.noReason);
|
|
|
|
|
expect(revKey.revocationSignatures[0].reasonForRevocationString).to.equal('');
|
|
|
|
@ -2504,10 +2504,10 @@ function versionSpecificTests() {
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('Revoke generated key with private key', function() {
|
|
|
|
|
const opt = {userIds: 'test1 <a@b.com>', passphrase: '1234'};
|
|
|
|
|
const opt = { userIds: 'test1 <a@b.com>', passphrase: '1234' };
|
|
|
|
|
return openpgp.generateKey(opt).then(async function(original) {
|
|
|
|
|
await original.key.decrypt('1234');
|
|
|
|
|
return openpgp.revokeKey({key: original.key, reasonForRevocation: {string: 'Testing key revocation'}}).then(async function(revKey) {
|
|
|
|
|
return openpgp.revokeKey({ key: original.key, reasonForRevocation: { string: 'Testing key revocation' } }).then(async function(revKey) {
|
|
|
|
|
revKey = revKey.publicKey;
|
|
|
|
|
expect(revKey.revocationSignatures[0].reasonForRevocationFlag).to.equal(openpgp.enums.reasonForRevocation.noReason);
|
|
|
|
|
expect(revKey.revocationSignatures[0].reasonForRevocationString).to.equal('Testing key revocation');
|
|
|
|
@ -2533,7 +2533,7 @@ module.exports = () => describe('Key', function() {
|
|
|
|
|
let rsaGenStub;
|
|
|
|
|
let v5KeysVal;
|
|
|
|
|
let aeadProtectVal;
|
|
|
|
|
let rsaGenValue = {
|
|
|
|
|
const rsaGenValue = {
|
|
|
|
|
512: openpgp.crypto.publicKey.rsa.generate(512, "10001"),
|
|
|
|
|
1024: openpgp.crypto.publicKey.rsa.generate(1024, "10001"),
|
|
|
|
|
2048: openpgp.crypto.publicKey.rsa.generate(2048, "10001")
|
|
|
|
@ -2602,16 +2602,16 @@ module.exports = () => describe('Key', function() {
|
|
|
|
|
|
|
|
|
|
it('Parsing V5 public key packet', async function() {
|
|
|
|
|
// Manually modified from https://gitlab.com/openpgp-wg/rfc4880bis/blob/00b2092/back.mkd#sample-eddsa-key
|
|
|
|
|
let packetBytes = openpgp.util.hexToUint8Array(`
|
|
|
|
|
const packetBytes = openpgp.util.hexToUint8Array(`
|
|
|
|
|
98 37 05 53 f3 5f 0b 16 00 00 00 2d 09 2b 06 01 04 01 da 47
|
|
|
|
|
0f 01 01 07 40 3f 09 89 94 bd d9 16 ed 40 53 19
|
|
|
|
|
79 34 e4 a8 7c 80 73 3a 12 80 d6 2f 80 10 99 2e
|
|
|
|
|
43 ee 3b 24 06
|
|
|
|
|
`.replace(/\s+/g, ''));
|
|
|
|
|
|
|
|
|
|
let packetlist = new openpgp.PacketList();
|
|
|
|
|
const packetlist = new openpgp.PacketList();
|
|
|
|
|
await packetlist.read(packetBytes, { PublicKeyPacket: openpgp.PublicKeyPacket });
|
|
|
|
|
let key = packetlist[0];
|
|
|
|
|
const key = packetlist[0];
|
|
|
|
|
expect(key).to.exist;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
@ -2774,7 +2774,7 @@ module.exports = () => describe('Key', function() {
|
|
|
|
|
|
|
|
|
|
it("decrypt(keyId) - throw if key parameters don't correspond", async function() {
|
|
|
|
|
const key = await openpgp.key.readArmored(mismatchingKeyParams);
|
|
|
|
|
const subKeyId = key.subKeys[0].getKeyId()
|
|
|
|
|
const subKeyId = key.subKeys[0].getKeyId();
|
|
|
|
|
await expect(key.decrypt('userpass', subKeyId)).to.be.rejectedWith('Key is invalid');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
@ -3179,43 +3179,43 @@ VYGdb3eNlV8CfoEC
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('Generate session key - latest created user', async function() {
|
|
|
|
|
let publicKey = await openpgp.key.readArmored(multi_uid_key);
|
|
|
|
|
const publicKey = await openpgp.key.readArmored(multi_uid_key);
|
|
|
|
|
const privateKey = await openpgp.key.readArmored(priv_key_rsa);
|
|
|
|
|
await privateKey.decrypt('hello world');
|
|
|
|
|
// Set second user to prefer aes128. We should select this user by default, since it was created later.
|
|
|
|
|
publicKey.users[1].selfCertifications[0].preferredSymmetricAlgorithms = [openpgp.enums.symmetric.aes128];
|
|
|
|
|
const sessionKey = await openpgp.generateSessionKey({publicKeys: publicKey});
|
|
|
|
|
const sessionKey = await openpgp.generateSessionKey({ publicKeys: publicKey });
|
|
|
|
|
expect(sessionKey.algorithm).to.equal('aes128');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('Generate session key - primary user', async function() {
|
|
|
|
|
let publicKey = await openpgp.key.readArmored(multi_uid_key);
|
|
|
|
|
const publicKey = await openpgp.key.readArmored(multi_uid_key);
|
|
|
|
|
const privateKey = await openpgp.key.readArmored(priv_key_rsa);
|
|
|
|
|
await privateKey.decrypt('hello world');
|
|
|
|
|
// Set first user to primary. We should select this user by default.
|
|
|
|
|
publicKey.users[0].selfCertifications[0].isPrimaryUserID = true;
|
|
|
|
|
// Set first user to prefer aes128.
|
|
|
|
|
publicKey.users[0].selfCertifications[0].preferredSymmetricAlgorithms = [openpgp.enums.symmetric.aes128];
|
|
|
|
|
const sessionKey = await openpgp.generateSessionKey({publicKeys: publicKey});
|
|
|
|
|
const sessionKey = await openpgp.generateSessionKey({ publicKeys: publicKey });
|
|
|
|
|
expect(sessionKey.algorithm).to.equal('aes128');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('Generate session key - specific user', async function() {
|
|
|
|
|
let publicKey = await openpgp.key.readArmored(multi_uid_key);
|
|
|
|
|
const publicKey = await openpgp.key.readArmored(multi_uid_key);
|
|
|
|
|
const privateKey = await openpgp.key.readArmored(priv_key_rsa);
|
|
|
|
|
await privateKey.decrypt('hello world');
|
|
|
|
|
// Set first user to primary. We won't select this user, this is to test that.
|
|
|
|
|
publicKey.users[0].selfCertifications[0].isPrimaryUserID = true;
|
|
|
|
|
// Set second user to prefer aes128. We will select this user.
|
|
|
|
|
publicKey.users[1].selfCertifications[0].preferredSymmetricAlgorithms = [openpgp.enums.symmetric.aes128];
|
|
|
|
|
const sessionKey = await openpgp.generateSessionKey({publicKeys: publicKey, toUserIds: {name: 'Test User', email: 'b@c.com'}});
|
|
|
|
|
const sessionKey = await openpgp.generateSessionKey({ publicKeys: publicKey, toUserIds: { name: 'Test User', email: 'b@c.com' } });
|
|
|
|
|
expect(sessionKey.algorithm).to.equal('aes128');
|
|
|
|
|
await openpgp.encrypt({message: openpgp.message.fromText('hello'), publicKeys: publicKey, privateKeys: privateKey, toUserIds: {name: 'Test User', email: 'b@c.com'}, armor: false});
|
|
|
|
|
await expect(openpgp.encrypt({message: openpgp.message.fromText('hello'), publicKeys: publicKey, privateKeys: privateKey, toUserIds: {name: 'Test User', email: 'c@c.com'}, armor: false})).to.be.rejectedWith('Could not find user that matches that user ID');
|
|
|
|
|
await openpgp.encrypt({ message: openpgp.message.fromText('hello'), publicKeys: publicKey, privateKeys: privateKey, toUserIds: { name: 'Test User', email: 'b@c.com' }, armor: false });
|
|
|
|
|
await expect(openpgp.encrypt({ message: openpgp.message.fromText('hello'), publicKeys: publicKey, privateKeys: privateKey, toUserIds: { name: 'Test User', email: 'c@c.com' }, armor: false })).to.be.rejectedWith('Could not find user that matches that user ID');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('Sign - specific user', async function() {
|
|
|
|
|
let publicKey = await openpgp.key.readArmored(multi_uid_key);
|
|
|
|
|
const publicKey = await openpgp.key.readArmored(multi_uid_key);
|
|
|
|
|
const privateKey = await openpgp.key.readArmored(priv_key_rsa);
|
|
|
|
|
await privateKey.decrypt('hello world');
|
|
|
|
|
const privateKeyClone = await openpgp.key.readArmored(priv_key_rsa);
|
|
|
|
@ -3227,13 +3227,13 @@ VYGdb3eNlV8CfoEC
|
|
|
|
|
privateKey.users[0].userId.parse('Test User <b@c.com>');
|
|
|
|
|
// Set second user to prefer aes128. We will select this user.
|
|
|
|
|
privateKey.users[1].selfCertifications[0].preferredHashAlgorithms = [openpgp.enums.hash.sha512];
|
|
|
|
|
const signed = await openpgp.sign({message: openpgp.message.fromText('hello'), privateKeys: privateKey, fromUserIds: {name: 'Test McTestington', email: 'test@example.com'}, armor: false});
|
|
|
|
|
const signed = await openpgp.sign({ message: openpgp.message.fromText('hello'), privateKeys: privateKey, fromUserIds: { name: 'Test McTestington', email: 'test@example.com' }, armor: false });
|
|
|
|
|
const signature = await openpgp.message.read(signed);
|
|
|
|
|
expect(signature.packets[0].hashAlgorithm).to.equal(openpgp.enums.hash.sha512);
|
|
|
|
|
const encrypted = await openpgp.encrypt({message: openpgp.message.fromText('hello'), passwords: 'test', privateKeys: privateKey, fromUserIds: {name: 'Test McTestington', email: 'test@example.com'}, armor: false});
|
|
|
|
|
const { signatures } = await openpgp.decrypt({message: await openpgp.message.read(encrypted), passwords: 'test'});
|
|
|
|
|
const encrypted = await openpgp.encrypt({ message: openpgp.message.fromText('hello'), passwords: 'test', privateKeys: privateKey, fromUserIds: { name: 'Test McTestington', email: 'test@example.com' }, armor: false });
|
|
|
|
|
const { signatures } = await openpgp.decrypt({ message: await openpgp.message.read(encrypted), passwords: 'test' });
|
|
|
|
|
expect(signatures[0].signature.packets[0].hashAlgorithm).to.equal(openpgp.enums.hash.sha512);
|
|
|
|
|
await expect(openpgp.encrypt({message: openpgp.message.fromText('hello'), publicKeys: publicKey, privateKeys: privateKey, fromUserIds: {name: 'Not Test McTestington', email: 'test@example.com'}, armor: false})).to.be.rejectedWith('Could not find user that matches that user ID');
|
|
|
|
|
await expect(openpgp.encrypt({ message: openpgp.message.fromText('hello'), publicKeys: publicKey, privateKeys: privateKey, fromUserIds: { name: 'Not Test McTestington', email: 'test@example.com' }, armor: false })).to.be.rejectedWith('Could not find user that matches that user ID');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('Find a valid subkey binding signature among many invalid ones', async function() {
|
|
|
|
@ -3268,7 +3268,7 @@ VYGdb3eNlV8CfoEC
|
|
|
|
|
|
|
|
|
|
it('Reject encryption with revoked primary user', async function() {
|
|
|
|
|
const key = await openpgp.key.readArmored(pub_revoked_subkeys);
|
|
|
|
|
return openpgp.encrypt({publicKeys: [key], message: openpgp.message.fromText('random data')}).then(() => {
|
|
|
|
|
return openpgp.encrypt({ publicKeys: [key], message: openpgp.message.fromText('random data') }).then(() => {
|
|
|
|
|
throw new Error('encryptSessionKey should not encrypt with revoked public key');
|
|
|
|
|
}).catch(function(error) {
|
|
|
|
|
expect(error.message).to.equal('Error encrypting message: Primary user is revoked');
|
|
|
|
@ -3279,7 +3279,7 @@ VYGdb3eNlV8CfoEC
|
|
|
|
|
const key = await openpgp.key.readArmored(pub_revoked_subkeys);
|
|
|
|
|
key.revocationSignatures = [];
|
|
|
|
|
key.users[0].revocationSignatures = [];
|
|
|
|
|
return openpgp.encrypt({publicKeys: [key], message: openpgp.message.fromText('random data'), date: new Date(1386842743000)}).then(() => {
|
|
|
|
|
return openpgp.encrypt({ publicKeys: [key], message: openpgp.message.fromText('random data'), date: new Date(1386842743000) }).then(() => {
|
|
|
|
|
throw new Error('encryptSessionKey should not encrypt with revoked public key');
|
|
|
|
|
}).catch(function(error) {
|
|
|
|
|
expect(error.message).to.equal('Error encrypting message: Could not find valid encryption key packet in key ' + key.getKeyId().toHex() + ': Subkey is revoked');
|
|
|
|
@ -3288,7 +3288,7 @@ VYGdb3eNlV8CfoEC
|
|
|
|
|
|
|
|
|
|
it('Reject encryption with key revoked with appended revocation cert', async function() {
|
|
|
|
|
const key = await openpgp.key.readArmored(pub_revoked_with_cert);
|
|
|
|
|
return openpgp.encrypt({publicKeys: [key], message: openpgp.message.fromText('random data')}).then(() => {
|
|
|
|
|
return openpgp.encrypt({ publicKeys: [key], message: openpgp.message.fromText('random data') }).then(() => {
|
|
|
|
|
throw new Error('encryptSessionKey should not encrypt with revoked public key');
|
|
|
|
|
}).catch(function(error) {
|
|
|
|
|
expect(error.message).to.equal('Error encrypting message: Primary key is revoked');
|
|
|
|
@ -3311,8 +3311,8 @@ VYGdb3eNlV8CfoEC
|
|
|
|
|
|
|
|
|
|
it("Should throw when trying to encrypt a key that's already encrypted", async function() {
|
|
|
|
|
await expect((async function() {
|
|
|
|
|
let { privateKeyArmored } = await openpgp.generateKey({ userIds: [{ email: 'hello@user.com' }], passphrase: 'pass' });
|
|
|
|
|
let k = await openpgp.key.readArmored(privateKeyArmored);
|
|
|
|
|
const { privateKeyArmored } = await openpgp.generateKey({ userIds: [{ email: 'hello@user.com' }], passphrase: 'pass' });
|
|
|
|
|
const k = await openpgp.key.readArmored(privateKeyArmored);
|
|
|
|
|
await k.decrypt('pass');
|
|
|
|
|
await k.encrypt('pass');
|
|
|
|
|
await k.encrypt('pass');
|
|
|
|
@ -3335,7 +3335,7 @@ VYGdb3eNlV8CfoEC
|
|
|
|
|
newPrivateKey = await openpgp.key.readArmored(armoredKey);
|
|
|
|
|
const subKey = newPrivateKey.subKeys[total];
|
|
|
|
|
expect(subKey).to.exist;
|
|
|
|
|
expect(newPrivateKey.subKeys.length).to.be.equal(total+1);
|
|
|
|
|
expect(newPrivateKey.subKeys.length).to.be.equal(total + 1);
|
|
|
|
|
const subkeyN = subKey.keyPacket.params[0];
|
|
|
|
|
const pkN = privateKey.primaryKey.params[0];
|
|
|
|
|
expect(subkeyN.byteLength()).to.be.equal(rsaBits ? (rsaBits / 8) : pkN.byteLength());
|
|
|
|
@ -3347,7 +3347,7 @@ VYGdb3eNlV8CfoEC
|
|
|
|
|
it('should throw when trying to encrypt a subkey separately from key', async function() {
|
|
|
|
|
const privateKey = await openpgp.key.readArmored(priv_key_rsa);
|
|
|
|
|
await privateKey.decrypt('hello world');
|
|
|
|
|
const opt = { rsaBits: rsaBits, passphrase: 'subkey passphrase'};
|
|
|
|
|
const opt = { rsaBits: rsaBits, passphrase: 'subkey passphrase' };
|
|
|
|
|
await expect(privateKey.addSubkey(opt)).to.be.rejectedWith('Subkey could not be encrypted here, please encrypt whole key');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
@ -3359,20 +3359,20 @@ VYGdb3eNlV8CfoEC
|
|
|
|
|
newPrivateKey = await openpgp.key.readArmored(newPrivateKey.armor());
|
|
|
|
|
await newPrivateKey.encrypt('12345678');
|
|
|
|
|
const armoredKey = newPrivateKey.armor();
|
|
|
|
|
let importedPrivateKey = await openpgp.key.readArmored(armoredKey);
|
|
|
|
|
const importedPrivateKey = await openpgp.key.readArmored(armoredKey);
|
|
|
|
|
await importedPrivateKey.decrypt('12345678');
|
|
|
|
|
const subKey = importedPrivateKey.subKeys[total];
|
|
|
|
|
expect(subKey).to.exist;
|
|
|
|
|
expect(importedPrivateKey.subKeys.length).to.be.equal(total+1);
|
|
|
|
|
expect(importedPrivateKey.subKeys.length).to.be.equal(total + 1);
|
|
|
|
|
await subKey.verify(importedPrivateKey.primaryKey);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('create and add a new ec subkey to a ec key', async function() {
|
|
|
|
|
const userId = 'test <a@b.com>';
|
|
|
|
|
const opt = {curve: 'curve25519', userIds: [userId], subkeys:[]};
|
|
|
|
|
const opt = { curve: 'curve25519', userIds: [userId], subkeys:[] };
|
|
|
|
|
const privateKey = (await openpgp.generateKey(opt)).key;
|
|
|
|
|
const total = privateKey.subKeys.length;
|
|
|
|
|
const opt2 = {curve: 'curve25519', userIds: [userId], sign: true};
|
|
|
|
|
const opt2 = { curve: 'curve25519', userIds: [userId], sign: true };
|
|
|
|
|
let newPrivateKey = await privateKey.addSubkey(opt2);
|
|
|
|
|
const subKey1 = newPrivateKey.subKeys[total];
|
|
|
|
|
await newPrivateKey.encrypt('12345678');
|
|
|
|
@ -3383,7 +3383,7 @@ VYGdb3eNlV8CfoEC
|
|
|
|
|
expect(subKey.isDecrypted()).to.be.true;
|
|
|
|
|
expect(subKey1.getKeyId().toHex()).to.be.equal(subKey.getKeyId().toHex());
|
|
|
|
|
expect(subKey).to.exist;
|
|
|
|
|
expect(newPrivateKey.subKeys.length).to.be.equal(total+1);
|
|
|
|
|
expect(newPrivateKey.subKeys.length).to.be.equal(total + 1);
|
|
|
|
|
const subkeyOid = subKey.keyPacket.params[0];
|
|
|
|
|
const pkOid = privateKey.primaryKey.params[0];
|
|
|
|
|
expect(subkeyOid.getName()).to.be.equal(pkOid.getName());
|
|
|
|
@ -3395,13 +3395,13 @@ VYGdb3eNlV8CfoEC
|
|
|
|
|
const privateKey = await openpgp.key.readArmored(priv_key_rsa);
|
|
|
|
|
await privateKey.decrypt('hello world');
|
|
|
|
|
const total = privateKey.subKeys.length;
|
|
|
|
|
const opt2 = {curve: 'curve25519'};
|
|
|
|
|
const opt2 = { curve: 'curve25519' };
|
|
|
|
|
let newPrivateKey = await privateKey.addSubkey(opt2);
|
|
|
|
|
const armoredKey = newPrivateKey.armor();
|
|
|
|
|
newPrivateKey = await openpgp.key.readArmored(armoredKey);
|
|
|
|
|
const subKey = newPrivateKey.subKeys[total];
|
|
|
|
|
expect(subKey).to.exist;
|
|
|
|
|
expect(newPrivateKey.subKeys.length).to.be.equal(total+1);
|
|
|
|
|
expect(newPrivateKey.subKeys.length).to.be.equal(total + 1);
|
|
|
|
|
expect(subKey.keyPacket.params[0].getName()).to.be.equal(openpgp.enums.curve.curve25519);
|
|
|
|
|
expect(subKey.getAlgorithmInfo().algorithm).to.be.equal('ecdh');
|
|
|
|
|
await subKey.verify(privateKey.primaryKey);
|
|
|
|
@ -3409,10 +3409,10 @@ VYGdb3eNlV8CfoEC
|
|
|
|
|
|
|
|
|
|
it('sign/verify data with the new subkey correctly using curve25519', async function() {
|
|
|
|
|
const userId = 'test <a@b.com>';
|
|
|
|
|
const opt = {curve: 'curve25519', userIds: [userId], subkeys:[]};
|
|
|
|
|
const opt = { curve: 'curve25519', userIds: [userId], subkeys:[] };
|
|
|
|
|
const privateKey = (await openpgp.generateKey(opt)).key;
|
|
|
|
|
const total = privateKey.subKeys.length;
|
|
|
|
|
const opt2 = {sign: true};
|
|
|
|
|
const opt2 = { sign: true };
|
|
|
|
|
let newPrivateKey = await privateKey.addSubkey(opt2);
|
|
|
|
|
const armoredKey = newPrivateKey.armor();
|
|
|
|
|
newPrivateKey = await openpgp.key.readArmored(armoredKey);
|
|
|
|
@ -3423,9 +3423,9 @@ VYGdb3eNlV8CfoEC
|
|
|
|
|
expect(subKey.getAlgorithmInfo().algorithm).to.be.equal('eddsa');
|
|
|
|
|
await subKey.verify(newPrivateKey.primaryKey);
|
|
|
|
|
expect(await newPrivateKey.getSigningKey()).to.be.equal(subKey);
|
|
|
|
|
const signed = await openpgp.sign({message: openpgp.message.fromText('the data to signed'), privateKeys: newPrivateKey, armor:false});
|
|
|
|
|
const signed = await openpgp.sign({ message: openpgp.message.fromText('the data to signed'), privateKeys: newPrivateKey, armor:false });
|
|
|
|
|
const message = await openpgp.message.read(signed);
|
|
|
|
|
const { signatures } = await openpgp.verify({message, publicKeys: [newPrivateKey.toPublic()]});
|
|
|
|
|
const { signatures } = await openpgp.verify({ message, publicKeys: [newPrivateKey.toPublic()] });
|
|
|
|
|
expect(signatures).to.exist;
|
|
|
|
|
expect(signatures.length).to.be.equal(1);
|
|
|
|
|
expect(signatures[0].keyid.toHex()).to.be.equal(subKey.getKeyId().toHex());
|
|
|
|
@ -3435,7 +3435,7 @@ VYGdb3eNlV8CfoEC
|
|
|
|
|
it('encrypt/decrypt data with the new subkey correctly using curve25519', async function() {
|
|
|
|
|
const userId = 'test <a@b.com>';
|
|
|
|
|
const vData = 'the data to encrypted!';
|
|
|
|
|
const opt = {curve: 'curve25519', userIds: [userId], subkeys:[]};
|
|
|
|
|
const opt = { curve: 'curve25519', userIds: [userId], subkeys:[] };
|
|
|
|
|
const privateKey = (await openpgp.generateKey(opt)).key;
|
|
|
|
|
const total = privateKey.subKeys.length;
|
|
|
|
|
let newPrivateKey = await privateKey.addSubkey();
|
|
|
|
@ -3445,14 +3445,14 @@ VYGdb3eNlV8CfoEC
|
|
|
|
|
const publicKey = newPrivateKey.toPublic();
|
|
|
|
|
await subKey.verify(newPrivateKey.primaryKey);
|
|
|
|
|
expect(await newPrivateKey.getEncryptionKey()).to.be.equal(subKey);
|
|
|
|
|
const encrypted = await openpgp.encrypt({message: openpgp.message.fromText(vData), publicKeys: publicKey, armor:false});
|
|
|
|
|
const encrypted = await openpgp.encrypt({ message: openpgp.message.fromText(vData), publicKeys: publicKey, armor:false });
|
|
|
|
|
expect(encrypted).to.be.exist;
|
|
|
|
|
const message = await openpgp.message.read(encrypted);
|
|
|
|
|
const pkSessionKeys = message.packets.filterByTag(openpgp.enums.packet.publicKeyEncryptedSessionKey);
|
|
|
|
|
expect(pkSessionKeys).to.exist;
|
|
|
|
|
expect(pkSessionKeys.length).to.be.equal(1);
|
|
|
|
|
expect(pkSessionKeys[0].publicKeyId.toHex()).to.be.equals(subKey.keyPacket.getKeyId().toHex());
|
|
|
|
|
const decrypted = await openpgp.decrypt({message, privateKeys: newPrivateKey})
|
|
|
|
|
const decrypted = await openpgp.decrypt({ message, privateKeys: newPrivateKey });
|
|
|
|
|
expect(decrypted).to.exist;
|
|
|
|
|
expect(decrypted.data).to.be.equal(vData);
|
|
|
|
|
});
|
|
|
|
@ -3469,9 +3469,9 @@ VYGdb3eNlV8CfoEC
|
|
|
|
|
expect(subKey.getAlgorithmInfo().algorithm).to.be.equal('rsaEncryptSign');
|
|
|
|
|
await subKey.verify(newPrivateKey.primaryKey);
|
|
|
|
|
expect(await newPrivateKey.getSigningKey()).to.be.equal(subKey);
|
|
|
|
|
const signed = await openpgp.sign({message: openpgp.message.fromText('the data to signed'), privateKeys: newPrivateKey, armor:false});
|
|
|
|
|
const signed = await openpgp.sign({ message: openpgp.message.fromText('the data to signed'), privateKeys: newPrivateKey, armor:false });
|
|
|
|
|
const message = await openpgp.message.read(signed);
|
|
|
|
|
const { signatures } = await openpgp.verify({message, publicKeys: [newPrivateKey.toPublic()]});
|
|
|
|
|
const { signatures } = await openpgp.verify({ message, publicKeys: [newPrivateKey.toPublic()] });
|
|
|
|
|
expect(signatures).to.exist;
|
|
|
|
|
expect(signatures.length).to.be.equal(1);
|
|
|
|
|
expect(signatures[0].keyid.toHex()).to.be.equal(subKey.getKeyId().toHex());
|
|
|
|
@ -3489,14 +3489,14 @@ VYGdb3eNlV8CfoEC
|
|
|
|
|
const publicKey = newPrivateKey.toPublic();
|
|
|
|
|
const vData = 'the data to encrypted!';
|
|
|
|
|
expect(await newPrivateKey.getEncryptionKey()).to.be.equal(subKey);
|
|
|
|
|
const encrypted = await openpgp.encrypt({message: openpgp.message.fromText(vData), publicKeys: publicKey, armor:false});
|
|
|
|
|
const encrypted = await openpgp.encrypt({ message: openpgp.message.fromText(vData), publicKeys: publicKey, armor:false });
|
|
|
|
|
expect(encrypted).to.be.exist;
|
|
|
|
|
const message = await openpgp.message.read(encrypted);
|
|
|
|
|
const pkSessionKeys = message.packets.filterByTag(openpgp.enums.packet.publicKeyEncryptedSessionKey);
|
|
|
|
|
expect(pkSessionKeys).to.exist;
|
|
|
|
|
expect(pkSessionKeys.length).to.be.equal(1);
|
|
|
|
|
expect(pkSessionKeys[0].publicKeyId.toHex()).to.be.equals(subKey.keyPacket.getKeyId().toHex());
|
|
|
|
|
const decrypted = await openpgp.decrypt({message, privateKeys: newPrivateKey})
|
|
|
|
|
const decrypted = await openpgp.decrypt({ message, privateKeys: newPrivateKey });
|
|
|
|
|
expect(decrypted).to.exist;
|
|
|
|
|
expect(decrypted.data).to.be.equal(vData);
|
|
|
|
|
});
|
|
|
|
|