Remove duplicate tests
Many tests would run for every encryption mode, or for both V4 and V5 keys, without there being any difference between the different test runs. `grunt coverage` before and after this commit reports almost identical statistics, providing some confidence that no code coverage was lost.
This commit is contained in:
parent
225f586970
commit
67b067b1da
File diff suppressed because it is too large
Load Diff
|
@ -654,6 +654,53 @@ describe('OpenPGP.js public api tests', function() {
|
|||
openpgp.config.aead_chunk_size_byte = aead_chunk_size_byteVal;
|
||||
});
|
||||
|
||||
it('Configuration', function() {
|
||||
openpgp.config.show_version = false;
|
||||
openpgp.config.commentstring = 'different';
|
||||
if (openpgp.getWorker()) { // init again to trigger config event
|
||||
openpgp.initWorker({ path:'../dist/openpgp.worker.js' });
|
||||
}
|
||||
return openpgp.encrypt({ publicKeys:publicKey.keys, message:openpgp.message.fromText(plaintext) }).then(function(encrypted) {
|
||||
expect(encrypted.data).to.exist;
|
||||
expect(encrypted.data).not.to.match(/^Version:/);
|
||||
expect(encrypted.data).to.match(/Comment: different/);
|
||||
});
|
||||
});
|
||||
|
||||
it('Test multiple workers', async function() {
|
||||
openpgp.config.show_version = false;
|
||||
openpgp.config.commentstring = 'different';
|
||||
if (!openpgp.getWorker()) {
|
||||
return;
|
||||
}
|
||||
const { workers } = openpgp.getWorker();
|
||||
try {
|
||||
await privateKey.keys[0].decrypt(passphrase)
|
||||
openpgp.initWorker({path: '../dist/openpgp.worker.js', workers, n: 2});
|
||||
|
||||
const workerTest = (_, index) => {
|
||||
const plaintext = input.createSomeMessage() + index;
|
||||
return openpgp.encrypt({
|
||||
publicKeys: publicKey.keys,
|
||||
data: plaintext
|
||||
}).then(function (encrypted) {
|
||||
expect(encrypted.data).to.exist;
|
||||
expect(encrypted.data).not.to.match(/^Version:/);
|
||||
expect(encrypted.data).to.match(/Comment: different/);
|
||||
return openpgp.decrypt({
|
||||
privateKeys: privateKey.keys[0],
|
||||
message: openpgp.message.readArmored(encrypted.data)
|
||||
});
|
||||
}).then(function (decrypted) {
|
||||
expect(decrypted.data).to.equal(plaintext);
|
||||
});
|
||||
};
|
||||
await Promise.all(Array(10).fill(null).map(workerTest));
|
||||
} finally {
|
||||
openpgp.initWorker({path: '../dist/openpgp.worker.js', workers, n: 1 });
|
||||
}
|
||||
});
|
||||
|
||||
it('Decrypting key with wrong passphrase rejected', async function () {
|
||||
await expect(privateKey.keys[0].decrypt('wrong passphrase')).to.eventually.be.rejectedWith('Incorrect key passphrase');
|
||||
});
|
||||
|
@ -662,6 +709,43 @@ describe('OpenPGP.js public api tests', function() {
|
|||
expect(await privateKey.keys[0].decrypt(passphrase)).to.be.true;
|
||||
});
|
||||
|
||||
describe('decryptKey', function() {
|
||||
it('should work for correct passphrase', function() {
|
||||
return openpgp.decryptKey({
|
||||
privateKey: privateKey.keys[0],
|
||||
passphrase: passphrase
|
||||
}).then(function(unlocked){
|
||||
expect(unlocked.key.getKeyId().toHex()).to.equal(privateKey.keys[0].getKeyId().toHex());
|
||||
expect(unlocked.key.isDecrypted()).to.be.true;
|
||||
});
|
||||
});
|
||||
|
||||
it('should fail for incorrect passphrase', function() {
|
||||
return openpgp.decryptKey({
|
||||
privateKey: privateKey.keys[0],
|
||||
passphrase: 'incorrect'
|
||||
}).catch(function(error){
|
||||
expect(error.message).to.match(/Incorrect key passphrase/);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('Calling decrypt with not decrypted key leads to exception', function() {
|
||||
const encOpt = {
|
||||
message: openpgp.message.fromText(plaintext),
|
||||
publicKeys: publicKey.keys
|
||||
};
|
||||
const decOpt = {
|
||||
privateKeys: privateKey.keys[0]
|
||||
};
|
||||
return openpgp.encrypt(encOpt).then(async function(encrypted) {
|
||||
decOpt.message = await openpgp.message.readArmored(encrypted.data);
|
||||
return openpgp.decrypt(decOpt);
|
||||
}).catch(function(error) {
|
||||
expect(error.message).to.match(/not decrypted/);
|
||||
});
|
||||
});
|
||||
|
||||
tryTests('CFB mode (asm.js)', tests, {
|
||||
if: !(typeof window !== 'undefined' && window.Worker),
|
||||
beforeEach: function() {
|
||||
|
@ -730,90 +814,6 @@ describe('OpenPGP.js public api tests', function() {
|
|||
});
|
||||
|
||||
function tests() {
|
||||
it('Configuration', function() {
|
||||
openpgp.config.show_version = false;
|
||||
openpgp.config.commentstring = 'different';
|
||||
if (openpgp.getWorker()) { // init again to trigger config event
|
||||
openpgp.initWorker({ path:'../dist/openpgp.worker.js' });
|
||||
}
|
||||
return openpgp.encrypt({ publicKeys:publicKey.keys, message:openpgp.message.fromText(plaintext) }).then(function(encrypted) {
|
||||
expect(encrypted.data).to.exist;
|
||||
expect(encrypted.data).not.to.match(/^Version:/);
|
||||
expect(encrypted.data).to.match(/Comment: different/);
|
||||
});
|
||||
});
|
||||
|
||||
it('Test multiple workers', async function() {
|
||||
openpgp.config.show_version = false;
|
||||
openpgp.config.commentstring = 'different';
|
||||
if (!openpgp.getWorker()) {
|
||||
return;
|
||||
}
|
||||
const { workers } = openpgp.getWorker();
|
||||
try {
|
||||
await privateKey.keys[0].decrypt(passphrase)
|
||||
openpgp.initWorker({path: '../dist/openpgp.worker.js', workers, n: 2});
|
||||
|
||||
const workerTest = (_, index) => {
|
||||
const plaintext = input.createSomeMessage() + index;
|
||||
return openpgp.encrypt({
|
||||
publicKeys: publicKey.keys,
|
||||
data: plaintext
|
||||
}).then(function (encrypted) {
|
||||
expect(encrypted.data).to.exist;
|
||||
expect(encrypted.data).not.to.match(/^Version:/);
|
||||
expect(encrypted.data).to.match(/Comment: different/);
|
||||
return openpgp.decrypt({
|
||||
privateKeys: privateKey.keys[0],
|
||||
message: openpgp.message.readArmored(encrypted.data)
|
||||
});
|
||||
}).then(function (decrypted) {
|
||||
expect(decrypted.data).to.equal(plaintext);
|
||||
});
|
||||
};
|
||||
await Promise.all(Array(10).fill(null).map(workerTest));
|
||||
} finally {
|
||||
openpgp.initWorker({path: '../dist/openpgp.worker.js', workers, n: 1 });
|
||||
}
|
||||
});
|
||||
|
||||
it('Calling decrypt with not decrypted key leads to exception', function() {
|
||||
const encOpt = {
|
||||
message: openpgp.message.fromText(plaintext),
|
||||
publicKeys: publicKey.keys
|
||||
};
|
||||
const decOpt = {
|
||||
privateKeys: privateKey.keys[0]
|
||||
};
|
||||
return openpgp.encrypt(encOpt).then(async function(encrypted) {
|
||||
decOpt.message = await openpgp.message.readArmored(encrypted.data);
|
||||
return openpgp.decrypt(decOpt);
|
||||
}).catch(function(error) {
|
||||
expect(error.message).to.match(/not decrypted/);
|
||||
});
|
||||
});
|
||||
|
||||
describe('decryptKey', function() {
|
||||
it('should work for correct passphrase', function() {
|
||||
return openpgp.decryptKey({
|
||||
privateKey: privateKey.keys[0],
|
||||
passphrase: passphrase
|
||||
}).then(function(unlocked){
|
||||
expect(unlocked.key.getKeyId().toHex()).to.equal(privateKey.keys[0].getKeyId().toHex());
|
||||
expect(unlocked.key.isDecrypted()).to.be.true;
|
||||
});
|
||||
});
|
||||
|
||||
it('should fail for incorrect passphrase', function() {
|
||||
return openpgp.decryptKey({
|
||||
privateKey: privateKey.keys[0],
|
||||
passphrase: 'incorrect'
|
||||
}).catch(function(error){
|
||||
expect(error.message).to.match(/Incorrect key passphrase/);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('encryptSessionKey, decryptSessionKeys', function() {
|
||||
const sk = new Uint8Array([0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01]);
|
||||
|
||||
|
@ -1538,6 +1538,265 @@ describe('OpenPGP.js public api tests', function() {
|
|||
expect(decrypted.signatures[1].signature.packets.length).to.equal(1);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('ELG / DSA encrypt, decrypt, sign, verify', function() {
|
||||
|
||||
it('round trip test', async function () {
|
||||
const pubKeyDE = (await openpgp.key.readArmored(pub_key_de)).keys[0];
|
||||
const privKeyDE = (await openpgp.key.readArmored(priv_key_de)).keys[0];
|
||||
await privKeyDE.decrypt(passphrase);
|
||||
pubKeyDE.users[0].selfCertifications[0].features = [7]; // Monkey-patch AEAD feature flag
|
||||
return openpgp.encrypt({
|
||||
publicKeys: pubKeyDE,
|
||||
privateKeys: privKeyDE,
|
||||
message: openpgp.message.fromText(plaintext)
|
||||
}).then(async function (encrypted) {
|
||||
return openpgp.decrypt({
|
||||
privateKeys: privKeyDE,
|
||||
publicKeys: pubKeyDE,
|
||||
message: await openpgp.message.readArmored(encrypted.data)
|
||||
});
|
||||
}).then(async function (decrypted) {
|
||||
expect(decrypted.data).to.exist;
|
||||
expect(decrypted.data).to.equal(plaintext);
|
||||
expect(decrypted.signatures[0].valid).to.be.true;
|
||||
const signingKey = await privKeyDE.getSigningKey();
|
||||
expect(decrypted.signatures[0].keyid.toHex()).to.equal(signingKey.getKeyId().toHex());
|
||||
expect(decrypted.signatures[0].signature.packets.length).to.equal(1);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("3DES decrypt", function() {
|
||||
const pgp_msg =
|
||||
['-----BEGIN PGP MESSAGE-----',
|
||||
'Version: GnuPG/MacGPG2 v2.0.19 (Darwin)',
|
||||
'Comment: GPGTools - https://gpgtools.org',
|
||||
'',
|
||||
'hIwDBU4Dycfvp2EBA/9tuhQgOrcATcm2PRmIOcs6q947YhlsBTZZdVJDfVjkKlyM',
|
||||
'M0yE+lnNplWb041Cpfkkl6IvorKQd2iPbAkOL0IXwmVN41l+PvVgMcuFvvzetehG',
|
||||
'Ca0/VEYOaTZRNqyr9FIzcnVy1I/PaWT3iqVAYa+G8TEA5Dh9RLfsx8ZA9UNIaNI+',
|
||||
'ASm9aZ3H6FerNhm8RezDY5vRn6xw3o/wH5YEBvV2BEmmFKZ2BlqFQxqChr8UNwd1',
|
||||
'Ieebnq0HtBPE8YU/L0U=',
|
||||
'=JyIa',
|
||||
'-----END PGP MESSAGE-----'].join('\n');
|
||||
|
||||
const priv_key =
|
||||
['-----BEGIN PGP PRIVATE KEY BLOCK-----',
|
||||
'Version: GnuPG/MacGPG2 v2.0.19 (Darwin)',
|
||||
'Comment: GPGTools - https://gpgtools.org',
|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
'=IkKW',
|
||||
'-----END PGP PRIVATE KEY BLOCK-----'].join('\n');
|
||||
|
||||
it('Decrypt message', async function() {
|
||||
const privKey = (await openpgp.key.readArmored(priv_key)).keys[0];
|
||||
await privKey.decrypt('1234');
|
||||
const message = await openpgp.message.readArmored(pgp_msg);
|
||||
|
||||
return openpgp.decrypt({ privateKeys:privKey, message:message }).then(function(decrypted) {
|
||||
expect(decrypted.data).to.equal('hello 3des\n');
|
||||
expect(decrypted.signatures.length).to.equal(0);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('AES encrypt, decrypt', function() {
|
||||
|
||||
it('should encrypt and decrypt with one password', function () {
|
||||
const encOpt = {
|
||||
message: openpgp.message.fromText(plaintext),
|
||||
passwords: password1
|
||||
};
|
||||
const decOpt = {
|
||||
passwords: password1
|
||||
};
|
||||
return openpgp.encrypt(encOpt).then(async function (encrypted) {
|
||||
decOpt.message = await 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);
|
||||
});
|
||||
});
|
||||
|
||||
it('should encrypt and decrypt with two passwords', function () {
|
||||
const encOpt = {
|
||||
message: openpgp.message.fromText(plaintext),
|
||||
passwords: [password1, password2]
|
||||
};
|
||||
const decOpt = {
|
||||
passwords: password2
|
||||
};
|
||||
return openpgp.encrypt(encOpt).then(async function (encrypted) {
|
||||
decOpt.message = await 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);
|
||||
});
|
||||
});
|
||||
|
||||
it('should decrypt with two passwords message which GPG fails on', async function () {
|
||||
|
||||
const decOpt = {
|
||||
message: await openpgp.message.readArmored(twoPasswordGPGFail),
|
||||
passwords: password2
|
||||
};
|
||||
return openpgp.decrypt(decOpt).then(function (decrypted) {
|
||||
expect(decrypted.data).to.equal('short message\nnext line\n한국어/조선말');
|
||||
expect(decrypted.signatures.length).to.equal(0);
|
||||
});
|
||||
});
|
||||
|
||||
it('should encrypt and decrypt with password and not ascii armor', function () {
|
||||
const encOpt = {
|
||||
message: openpgp.message.fromText(plaintext),
|
||||
passwords: password1,
|
||||
armor: false
|
||||
};
|
||||
const decOpt = {
|
||||
passwords: password1
|
||||
};
|
||||
return openpgp.encrypt(encOpt).then(function (encrypted) {
|
||||
decOpt.message = encrypted.message;
|
||||
return openpgp.decrypt(decOpt);
|
||||
}).then(function (decrypted) {
|
||||
expect(decrypted.data).to.equal(plaintext);
|
||||
expect(decrypted.signatures.length).to.equal(0);
|
||||
});
|
||||
});
|
||||
|
||||
it('should encrypt and decrypt with binary data and transferable objects', function () {
|
||||
openpgp.config.zero_copy = true; // activate transferable objects
|
||||
const encOpt = {
|
||||
message: openpgp.message.fromBinary(new Uint8Array([0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01])),
|
||||
passwords: password1,
|
||||
armor: false
|
||||
};
|
||||
const decOpt = {
|
||||
passwords: password1,
|
||||
format: 'binary'
|
||||
};
|
||||
return openpgp.encrypt(encOpt).then(function (encrypted) {
|
||||
decOpt.message = encrypted.message;
|
||||
return openpgp.decrypt(decOpt);
|
||||
}).then(function (decrypted) {
|
||||
if (openpgp.getWorker()) {
|
||||
expect(encOpt.message.packets[0].data.byteLength).to.equal(0); // transferred buffer should be empty
|
||||
}
|
||||
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({
|
||||
message: openpgp.message.fromText(plaintext),
|
||||
passwords: password1
|
||||
});
|
||||
const decOpt = {
|
||||
passwords: password1
|
||||
};
|
||||
return openpgp.encrypt(encOpt).then(async function (encrypted) {
|
||||
decOpt.message = await 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);
|
||||
});
|
||||
});
|
||||
|
||||
it('Streaming encrypt and decrypt small message roundtrip', async function() {
|
||||
let plaintext = [];
|
||||
let i = 0;
|
||||
const data = new ReadableStream({
|
||||
async pull(controller) {
|
||||
if (i++ < 4) {
|
||||
let randomBytes = await openpgp.crypto.random.getRandomBytes(10);
|
||||
controller.enqueue(randomBytes);
|
||||
plaintext.push(randomBytes);
|
||||
} else {
|
||||
controller.close();
|
||||
}
|
||||
}
|
||||
});
|
||||
const encrypted = await openpgp.encrypt(modifyCompressionEncryptOptions({
|
||||
message: openpgp.message.fromBinary(data),
|
||||
passwords: ['test'],
|
||||
}));
|
||||
|
||||
const msgAsciiArmored = encrypted.data;
|
||||
const message = await openpgp.message.readArmored(msgAsciiArmored);
|
||||
const decrypted = await openpgp.decrypt({
|
||||
passwords: ['test'],
|
||||
message,
|
||||
format: 'binary'
|
||||
});
|
||||
expect(openpgp.util.isStream(decrypted.data)).to.equal('web');
|
||||
expect(await openpgp.stream.readToEnd(decrypted.data)).to.deep.equal(openpgp.util.concatUint8Array(plaintext));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
describe('AES / RSA sign, verify', function() {
|
||||
const wrong_pubkey = '-----BEGIN PGP PUBLIC KEY BLOCK-----\r\n' +
|
||||
'Version: OpenPGP.js v0.9.0\r\n' +
|
||||
'Comment: Hoodiecrow - https://hoodiecrow.com\r\n' +
|
||||
'\r\n' +
|
||||
'xk0EUlhMvAEB/2MZtCUOAYvyLFjDp3OBMGn3Ev8FwjzyPbIF0JUw+L7y2XR5\r\n' +
|
||||
'RVGvbK88unV3cU/1tOYdNsXI6pSp/Ztjyv7vbBUAEQEAAc0pV2hpdGVvdXQg\r\n' +
|
||||
'VXNlciA8d2hpdGVvdXQudGVzdEB0LW9ubGluZS5kZT7CXAQQAQgAEAUCUlhM\r\n' +
|
||||
'vQkQ9vYOm0LN/0wAAAW4Af9C+kYW1AvNWmivdtr0M0iYCUjM9DNOQH1fcvXq\r\n' +
|
||||
'IiN602mWrkd8jcEzLsW5IUNzVPLhrFIuKyBDTpLnC07Loce1\r\n' +
|
||||
'=6XMW\r\n' +
|
||||
'-----END PGP PUBLIC KEY BLOCK-----\r\n\r\n';
|
||||
|
||||
let decryptedPrivateKey;
|
||||
beforeEach(async function() {
|
||||
if (!decryptedPrivateKey) {
|
||||
expect(await privateKey.keys[0].decrypt(passphrase)).to.be.true;
|
||||
decryptedPrivateKey = privateKey;
|
||||
}
|
||||
privateKey = decryptedPrivateKey;
|
||||
});
|
||||
|
||||
it('should sign and verify cleartext data', function () {
|
||||
const message = openpgp.cleartext.fromText(plaintext);
|
||||
|
@ -1988,240 +2247,7 @@ describe('OpenPGP.js public api tests', function() {
|
|||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('ELG / DSA encrypt, decrypt, sign, verify', function() {
|
||||
|
||||
it('round trip test', async function () {
|
||||
const pubKeyDE = (await openpgp.key.readArmored(pub_key_de)).keys[0];
|
||||
const privKeyDE = (await openpgp.key.readArmored(priv_key_de)).keys[0];
|
||||
await privKeyDE.decrypt(passphrase);
|
||||
pubKeyDE.users[0].selfCertifications[0].features = [7]; // Monkey-patch AEAD feature flag
|
||||
return openpgp.encrypt({
|
||||
publicKeys: pubKeyDE,
|
||||
privateKeys: privKeyDE,
|
||||
message: openpgp.message.fromText(plaintext)
|
||||
}).then(async function (encrypted) {
|
||||
return openpgp.decrypt({
|
||||
privateKeys: privKeyDE,
|
||||
publicKeys: pubKeyDE,
|
||||
message: await openpgp.message.readArmored(encrypted.data)
|
||||
});
|
||||
}).then(async function (decrypted) {
|
||||
expect(decrypted.data).to.exist;
|
||||
expect(decrypted.data).to.equal(plaintext);
|
||||
expect(decrypted.signatures[0].valid).to.be.true;
|
||||
const signingKey = await privKeyDE.getSigningKey();
|
||||
expect(decrypted.signatures[0].keyid.toHex()).to.equal(signingKey.getKeyId().toHex());
|
||||
expect(decrypted.signatures[0].signature.packets.length).to.equal(1);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("3DES decrypt", function() {
|
||||
const pgp_msg =
|
||||
['-----BEGIN PGP MESSAGE-----',
|
||||
'Version: GnuPG/MacGPG2 v2.0.19 (Darwin)',
|
||||
'Comment: GPGTools - https://gpgtools.org',
|
||||
'',
|
||||
'hIwDBU4Dycfvp2EBA/9tuhQgOrcATcm2PRmIOcs6q947YhlsBTZZdVJDfVjkKlyM',
|
||||
'M0yE+lnNplWb041Cpfkkl6IvorKQd2iPbAkOL0IXwmVN41l+PvVgMcuFvvzetehG',
|
||||
'Ca0/VEYOaTZRNqyr9FIzcnVy1I/PaWT3iqVAYa+G8TEA5Dh9RLfsx8ZA9UNIaNI+',
|
||||
'ASm9aZ3H6FerNhm8RezDY5vRn6xw3o/wH5YEBvV2BEmmFKZ2BlqFQxqChr8UNwd1',
|
||||
'Ieebnq0HtBPE8YU/L0U=',
|
||||
'=JyIa',
|
||||
'-----END PGP MESSAGE-----'].join('\n');
|
||||
|
||||
const priv_key =
|
||||
['-----BEGIN PGP PRIVATE KEY BLOCK-----',
|
||||
'Version: GnuPG/MacGPG2 v2.0.19 (Darwin)',
|
||||
'Comment: GPGTools - https://gpgtools.org',
|
||||
'',
|
||||
'lQH+BFLqLegBBAC/rN3g30Jrcpx5lTb7Kxe+ZfS7ppOIoBjjN+qcOh81cJJVS5dT',
|
||||
'UGcDsm2tCLVS3P2dGaYhfU9fsoSq/wK/tXsdoWXvXdjHbbueyi1kTZqlnyT190UE',
|
||||
'vmDxH0y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CKDC8D9ZJf13iwUjYkfn/e/bDqCS2piyd63zI0xDJo+s2bXCIJxgrhbOqFDeFd6',
|
||||
'4W8PfBOvUuRjABEBAAH+AwMCuBAcySe6tBfLV0P5MbBesR3Ifu/ppjzLoXKhwkqm',
|
||||
'PXf09taLcRfUHeMbPjboj2P2m2UOnSrbXK9qsDQ8XOMtdsEWGLWpmiqnMlkiOchv',
|
||||
'MsNRYpZ67iX3JVdxNuhs5+g5bdP1PNVbKiTzx73u1h0SS93IJp1jFj50/kyGl1Eq',
|
||||
'tkr0TWe5uXCh6cSZDPwhto0a12GeDHehdTw6Yq4KoZHccneHhN9ySFy0DZOeULIi',
|
||||
'Y61qtR0io52T7w69fBe9Q5/d5SwpwWKMpCTOqvvzdHX7JmeFtV+2vRVilIif7AfP',
|
||||
'AD+OjQ/OhMu3jYO+XNhm3raPT2tIBsBdl2UiHOnj4AUNuLuUJeVghtz4Qt6dvjyz',
|
||||
'PlBvSF+ESqALjM8IqnG15FX4LmEDFrFcfNCsnmeyZ2nr1h2mV5jOON0EmBtCyhCt',
|
||||
'D/Ivi4/SZk+tBVhsBI+7ZECZYDJzZQnyPDsUv31MU4OwdWi7FhzHvDj/0bhYY7+I',
|
||||
'nwQYAQIACQUCUuot6AIbDAAKCRCSTaGiPl24PwYAA/sGIHvCKWP5+4ZlBHuOdbP9',
|
||||
'9v3PXFCm61qFEL0DTSq7NgBcuf0ASRElRI3wIKlfkwaiSzVPfNLiMTexdc7XaiTz',
|
||||
'CHaOn1Xl2gmYTq2KiJkgtLuwptYU1iSj7vvSHKy0+nYIckOZB4pRCOjknT08O4ZJ',
|
||||
'22q10ausyQXoOxXfDWVwKA==',
|
||||
'=IkKW',
|
||||
'-----END PGP PRIVATE KEY BLOCK-----'].join('\n');
|
||||
|
||||
it('Decrypt message', async function() {
|
||||
const privKey = (await openpgp.key.readArmored(priv_key)).keys[0];
|
||||
await privKey.decrypt('1234');
|
||||
const message = await openpgp.message.readArmored(pgp_msg);
|
||||
|
||||
return openpgp.decrypt({ privateKeys:privKey, message:message }).then(function(decrypted) {
|
||||
expect(decrypted.data).to.equal('hello 3des\n');
|
||||
expect(decrypted.signatures.length).to.equal(0);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('AES encrypt, decrypt', function() {
|
||||
|
||||
it('should encrypt and decrypt with one password', function () {
|
||||
const encOpt = {
|
||||
message: openpgp.message.fromText(plaintext),
|
||||
passwords: password1
|
||||
};
|
||||
const decOpt = {
|
||||
passwords: password1
|
||||
};
|
||||
return openpgp.encrypt(encOpt).then(async function (encrypted) {
|
||||
decOpt.message = await 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);
|
||||
});
|
||||
});
|
||||
|
||||
it('should encrypt and decrypt with two passwords', function () {
|
||||
const encOpt = {
|
||||
message: openpgp.message.fromText(plaintext),
|
||||
passwords: [password1, password2]
|
||||
};
|
||||
const decOpt = {
|
||||
passwords: password2
|
||||
};
|
||||
return openpgp.encrypt(encOpt).then(async function (encrypted) {
|
||||
decOpt.message = await 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);
|
||||
});
|
||||
});
|
||||
|
||||
it('should decrypt with two passwords message which GPG fails on', async function () {
|
||||
|
||||
const decOpt = {
|
||||
message: await openpgp.message.readArmored(twoPasswordGPGFail),
|
||||
passwords: password2
|
||||
};
|
||||
return openpgp.decrypt(decOpt).then(function (decrypted) {
|
||||
expect(decrypted.data).to.equal('short message\nnext line\n한국어/조선말');
|
||||
expect(decrypted.signatures.length).to.equal(0);
|
||||
});
|
||||
});
|
||||
|
||||
it('should encrypt and decrypt with password and not ascii armor', function () {
|
||||
const encOpt = {
|
||||
message: openpgp.message.fromText(plaintext),
|
||||
passwords: password1,
|
||||
armor: false
|
||||
};
|
||||
const decOpt = {
|
||||
passwords: password1
|
||||
};
|
||||
return openpgp.encrypt(encOpt).then(function (encrypted) {
|
||||
decOpt.message = encrypted.message;
|
||||
return openpgp.decrypt(decOpt);
|
||||
}).then(function (decrypted) {
|
||||
expect(decrypted.data).to.equal(plaintext);
|
||||
expect(decrypted.signatures.length).to.equal(0);
|
||||
});
|
||||
});
|
||||
|
||||
it('should encrypt and decrypt with binary data and transferable objects', function () {
|
||||
openpgp.config.zero_copy = true; // activate transferable objects
|
||||
const encOpt = {
|
||||
message: openpgp.message.fromBinary(new Uint8Array([0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01])),
|
||||
passwords: password1,
|
||||
armor: false
|
||||
};
|
||||
const decOpt = {
|
||||
passwords: password1,
|
||||
format: 'binary'
|
||||
};
|
||||
return openpgp.encrypt(encOpt).then(function (encrypted) {
|
||||
decOpt.message = encrypted.message;
|
||||
return openpgp.decrypt(decOpt);
|
||||
}).then(function (decrypted) {
|
||||
if (openpgp.getWorker()) {
|
||||
expect(encOpt.message.packets[0].data.byteLength).to.equal(0); // transferred buffer should be empty
|
||||
}
|
||||
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({
|
||||
message: openpgp.message.fromText(plaintext),
|
||||
passwords: password1
|
||||
});
|
||||
const decOpt = {
|
||||
passwords: password1
|
||||
};
|
||||
return openpgp.encrypt(encOpt).then(async function (encrypted) {
|
||||
decOpt.message = await 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);
|
||||
});
|
||||
});
|
||||
|
||||
it('Streaming encrypt and decrypt small message roundtrip', async function() {
|
||||
let plaintext = [];
|
||||
let i = 0;
|
||||
const data = new ReadableStream({
|
||||
async pull(controller) {
|
||||
if (i++ < 4) {
|
||||
let randomBytes = await openpgp.crypto.random.getRandomBytes(10);
|
||||
controller.enqueue(randomBytes);
|
||||
plaintext.push(randomBytes);
|
||||
} else {
|
||||
controller.close();
|
||||
}
|
||||
}
|
||||
});
|
||||
const encrypted = await openpgp.encrypt(modifyCompressionEncryptOptions({
|
||||
message: openpgp.message.fromBinary(data),
|
||||
passwords: ['test'],
|
||||
}));
|
||||
|
||||
const msgAsciiArmored = encrypted.data;
|
||||
const message = await openpgp.message.readArmored(msgAsciiArmored);
|
||||
const decrypted = await openpgp.decrypt({
|
||||
passwords: ['test'],
|
||||
message,
|
||||
format: 'binary'
|
||||
});
|
||||
expect(openpgp.util.isStream(decrypted.data)).to.equal('web');
|
||||
expect(await openpgp.stream.readToEnd(decrypted.data)).to.deep.equal(openpgp.util.concatUint8Array(plaintext));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('Errors', function() {
|
||||
|
@ -2241,8 +2267,6 @@ describe('OpenPGP.js public api tests', function() {
|
|||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue
Block a user