mirror of
https://github.com/openpgpjs/openpgpjs.git
synced 2026-03-13 11:55:01 +00:00
Return Uint8Array(Stream) instead of object when armor = false
This commit is contained in:
@@ -3178,8 +3178,8 @@ VYGdb3eNlV8CfoEC
|
||||
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 encrypted = await openpgp.encrypt({message: openpgp.message.fromText('hello'), publicKeys: publicKey, privateKeys: privateKey, armor: false});
|
||||
expect(encrypted.message.packets[0].sessionKeyAlgorithm).to.equal('aes128');
|
||||
const encrypted = await openpgp.encrypt({message: openpgp.message.fromText('hello'), publicKeys: publicKey, privateKeys: privateKey, armor: false, returnSessionKey: true});
|
||||
expect(encrypted.sessionKey.algorithm).to.equal('aes128');
|
||||
});
|
||||
|
||||
it('Encrypt - primary user', async function() {
|
||||
@@ -3190,8 +3190,8 @@ VYGdb3eNlV8CfoEC
|
||||
publicKey.users[0].selfCertifications[0].isPrimaryUserID = true;
|
||||
// Set first user to prefer aes128.
|
||||
publicKey.users[0].selfCertifications[0].preferredSymmetricAlgorithms = [openpgp.enums.symmetric.aes128];
|
||||
const encrypted = await openpgp.encrypt({message: openpgp.message.fromText('hello'), publicKeys: publicKey, privateKeys: privateKey, armor: false});
|
||||
expect(encrypted.message.packets[0].sessionKeyAlgorithm).to.equal('aes128');
|
||||
const encrypted = await openpgp.encrypt({message: openpgp.message.fromText('hello'), publicKeys: publicKey, privateKeys: privateKey, armor: false, returnSessionKey: true});
|
||||
expect(encrypted.sessionKey.algorithm).to.equal('aes128');
|
||||
});
|
||||
|
||||
it('Encrypt - specific user', async function() {
|
||||
@@ -3202,8 +3202,8 @@ VYGdb3eNlV8CfoEC
|
||||
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 encrypted = await openpgp.encrypt({message: openpgp.message.fromText('hello'), publicKeys: publicKey, privateKeys: privateKey, toUserIds: {name: 'Test User', email: 'b@c.com'}, armor: false});
|
||||
expect(encrypted.message.packets[0].sessionKeyAlgorithm).to.equal('aes128');
|
||||
const encrypted = await openpgp.encrypt({message: openpgp.message.fromText('hello'), publicKeys: publicKey, privateKeys: privateKey, toUserIds: {name: 'Test User', email: 'b@c.com'}, armor: false, returnSessionKey: true});
|
||||
expect(encrypted.sessionKey.algorithm).to.equal('aes128');
|
||||
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');
|
||||
});
|
||||
|
||||
@@ -3220,10 +3220,12 @@ 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.cleartext.fromText('hello'), privateKeys: privateKey, fromUserIds: {name: 'Test McTestington', email: 'test@example.com'}, armor: false});
|
||||
expect(signed.message.signature.packets[0].hashAlgorithm).to.equal(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 signature = await openpgp.message.read(signed.data);
|
||||
expect(signature.packets[0].hashAlgorithm).to.equal(openpgp.enums.hash.sha512);
|
||||
const encrypted = await openpgp.encrypt({message: openpgp.message.fromText('hello'), publicKeys: publicKey, privateKeys: privateKey, fromUserIds: {name: 'Test McTestington', email: 'test@example.com'}, detached: true, armor: false});
|
||||
expect(encrypted.signature.packets[0].hashAlgorithm).to.equal(openpgp.enums.hash.sha512);
|
||||
const signature2 = await openpgp.message.read(encrypted.signature);
|
||||
expect(signature2.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'}, detached: true, armor: false})).to.be.rejectedWith('Could not find user that matches that user ID');
|
||||
});
|
||||
|
||||
@@ -3415,12 +3417,13 @@ describe('addSubkey functionality testing', function(){
|
||||
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.cleartext.fromText('the data to signed'), privateKeys: newPrivateKey, armor:false});
|
||||
const verified = await signed.message.verify([newPrivateKey.toPublic()]);
|
||||
expect(verified).to.exist;
|
||||
expect(verified.length).to.be.equal(1);
|
||||
expect(await verified[0].keyid).to.be.equal(subKey.getKeyId());
|
||||
expect(await verified[0].verified).to.be.true;
|
||||
const signed = await openpgp.sign({message: openpgp.message.fromText('the data to signed'), privateKeys: newPrivateKey, armor:false});
|
||||
const message = await openpgp.message.read(signed.data);
|
||||
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());
|
||||
expect(await signatures[0].verified).to.be.true;
|
||||
});
|
||||
|
||||
it('encrypt/decrypt data with the new subkey correctly using curve25519', async function() {
|
||||
@@ -3437,12 +3440,13 @@ describe('addSubkey functionality testing', function(){
|
||||
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});
|
||||
expect(encrypted.message).to.be.exist;
|
||||
const pkSessionKeys = encrypted.message.packets.filterByTag(openpgp.enums.packet.publicKeyEncryptedSessionKey);
|
||||
expect(encrypted.data).to.be.exist;
|
||||
const message = await openpgp.message.read(encrypted.data);
|
||||
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: encrypted.message, privateKeys: newPrivateKey})
|
||||
const decrypted = await openpgp.decrypt({message, privateKeys: newPrivateKey})
|
||||
expect(decrypted).to.exist;
|
||||
expect(decrypted.data).to.be.equal(vData);
|
||||
});
|
||||
@@ -3459,12 +3463,13 @@ describe('addSubkey functionality testing', function(){
|
||||
expect(subKey.getAlgorithmInfo().algorithm).to.be.equal('rsa_encrypt_sign');
|
||||
await subKey.verify(newPrivateKey.primaryKey);
|
||||
expect(await newPrivateKey.getSigningKey()).to.be.equal(subKey);
|
||||
const signed = await openpgp.sign({message: openpgp.cleartext.fromText('the data to signed'), privateKeys: newPrivateKey, armor:false});
|
||||
const verified = await signed.message.verify([newPrivateKey.toPublic()]);
|
||||
expect(verified).to.exist;
|
||||
expect(verified.length).to.be.equal(1);
|
||||
expect(await verified[0].keyid).to.be.equal(subKey.getKeyId());
|
||||
expect(await verified[0].verified).to.be.true;
|
||||
const signed = await openpgp.sign({message: openpgp.message.fromText('the data to signed'), privateKeys: newPrivateKey, armor:false});
|
||||
const message = await openpgp.message.read(signed.data);
|
||||
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());
|
||||
expect(await signatures[0].verified).to.be.true;
|
||||
});
|
||||
|
||||
it('encrypt/decrypt data with the new subkey correctly using rsa', async function() {
|
||||
@@ -3479,12 +3484,13 @@ describe('addSubkey functionality testing', function(){
|
||||
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});
|
||||
expect(encrypted.message).to.be.exist;
|
||||
const pkSessionKeys = encrypted.message.packets.filterByTag(openpgp.enums.packet.publicKeyEncryptedSessionKey);
|
||||
expect(encrypted.data).to.be.exist;
|
||||
const message = await openpgp.message.read(encrypted.data);
|
||||
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: encrypted.message, privateKeys: newPrivateKey})
|
||||
const decrypted = await openpgp.decrypt({message, privateKeys: newPrivateKey})
|
||||
expect(decrypted).to.exist;
|
||||
expect(decrypted.data).to.be.equal(vData);
|
||||
});
|
||||
|
||||
@@ -1865,8 +1865,8 @@ describe('OpenPGP.js public api tests', function() {
|
||||
const decOpt = {
|
||||
passwords: password1
|
||||
};
|
||||
return openpgp.encrypt(encOpt).then(function (encrypted) {
|
||||
decOpt.message = encrypted.message;
|
||||
return openpgp.encrypt(encOpt).then(async function (encrypted) {
|
||||
decOpt.message = await openpgp.message.read(encrypted.data);
|
||||
return openpgp.decrypt(decOpt);
|
||||
}).then(function (decrypted) {
|
||||
expect(decrypted.data).to.equal(plaintext);
|
||||
@@ -1885,8 +1885,14 @@ describe('OpenPGP.js public api tests', function() {
|
||||
passwords: password1,
|
||||
format: 'binary'
|
||||
};
|
||||
return openpgp.encrypt(encOpt).then(function (encrypted) {
|
||||
decOpt.message = encrypted.message;
|
||||
return openpgp.encrypt(encOpt).then(async function (encrypted) {
|
||||
decOpt.message = await openpgp.message.read(encrypted.data);
|
||||
openpgp.config.zero_copy = false;
|
||||
if (openpgp.getWorker()) {
|
||||
openpgp.getWorker().workers.forEach(worker => {
|
||||
worker.postMessage({ event: 'configure', config: openpgp.config });
|
||||
});
|
||||
}
|
||||
return openpgp.decrypt(decOpt);
|
||||
}).then(function (decrypted) {
|
||||
if (openpgp.getWorker()) {
|
||||
@@ -1978,7 +1984,7 @@ describe('OpenPGP.js public api tests', function() {
|
||||
privateKey = decryptedPrivateKey;
|
||||
});
|
||||
|
||||
it('should sign and verify cleartext data', function () {
|
||||
it('should sign and verify cleartext message', function () {
|
||||
const message = openpgp.cleartext.fromText(plaintext);
|
||||
const signOpt = {
|
||||
message,
|
||||
@@ -2000,7 +2006,7 @@ describe('OpenPGP.js public api tests', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('should sign and verify cleartext data with multiple private keys', async function () {
|
||||
it('should sign and verify cleartext message with multiple private keys', async function () {
|
||||
const privKeyDE = (await openpgp.key.readArmored(priv_key_de)).keys[0];
|
||||
await privKeyDE.decrypt(passphrase);
|
||||
|
||||
@@ -2030,8 +2036,8 @@ describe('OpenPGP.js public api tests', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('should sign and verify cleartext data with detached signatures', function () {
|
||||
const message = openpgp.cleartext.fromText(plaintext);
|
||||
it('should sign and verify data with detached signatures', function () {
|
||||
const message = openpgp.message.fromText(plaintext);
|
||||
const signOpt = {
|
||||
message,
|
||||
privateKeys: privateKey.keys,
|
||||
@@ -2045,7 +2051,7 @@ describe('OpenPGP.js public api tests', function() {
|
||||
verifyOpt.signature = await openpgp.signature.readArmored(signed.signature);
|
||||
return openpgp.verify(verifyOpt);
|
||||
}).then(async function (verified) {
|
||||
expect(verified.data).to.equal(plaintext.replace(/[ \t]+$/mg, ''));
|
||||
expect(verified.data).to.equal(plaintext);
|
||||
expect(verified.signatures[0].valid).to.be.true;
|
||||
const signingKey = await privateKey.keys[0].getSigningKey();
|
||||
expect(verified.signatures[0].keyid.toHex()).to.equal(signingKey.getKeyId().toHex());
|
||||
@@ -2053,7 +2059,7 @@ describe('OpenPGP.js public api tests', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('should sign and fail to verify cleartext data with wrong public pgp key', async function () {
|
||||
it('should sign and fail to verify cleartext message with wrong public pgp key', async function () {
|
||||
const message = openpgp.cleartext.fromText(plaintext);
|
||||
const signOpt = {
|
||||
message,
|
||||
@@ -2074,8 +2080,8 @@ describe('OpenPGP.js public api tests', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('should sign and fail to verify cleartext data with wrong public pgp key with detached signature', async function () {
|
||||
const message = openpgp.cleartext.fromText(plaintext);
|
||||
it('should sign and fail to verify data with wrong public pgp key with detached signature', async function () {
|
||||
const message = openpgp.message.fromText(plaintext);
|
||||
const signOpt = {
|
||||
message,
|
||||
privateKeys: privateKey.keys,
|
||||
@@ -2089,7 +2095,7 @@ describe('OpenPGP.js public api tests', function() {
|
||||
verifyOpt.signature = await openpgp.signature.readArmored(signed.signature);
|
||||
return openpgp.verify(verifyOpt);
|
||||
}).then(async function (verified) {
|
||||
expect(verified.data).to.equal(plaintext.replace(/[ \t]+$/mg, ''));
|
||||
expect(verified.data).to.equal(plaintext);
|
||||
expect(verified.signatures[0].valid).to.be.null;
|
||||
const signingKey = await privateKey.keys[0].getSigningKey();
|
||||
expect(verified.signatures[0].keyid.toHex()).to.equal(signingKey.getKeyId().toHex());
|
||||
@@ -2097,8 +2103,8 @@ describe('OpenPGP.js public api tests', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('should sign and verify cleartext data and not armor', function () {
|
||||
const message = openpgp.cleartext.fromText(plaintext);
|
||||
it('should sign and verify data and not armor', function () {
|
||||
const message = openpgp.message.fromText(plaintext);
|
||||
const signOpt = {
|
||||
message,
|
||||
privateKeys: privateKey.keys,
|
||||
@@ -2107,11 +2113,11 @@ describe('OpenPGP.js public api tests', function() {
|
||||
const verifyOpt = {
|
||||
publicKeys: publicKey.keys
|
||||
};
|
||||
return openpgp.sign(signOpt).then(function (signed) {
|
||||
verifyOpt.message = signed.message;
|
||||
return openpgp.sign(signOpt).then(async function (signed) {
|
||||
verifyOpt.message = await openpgp.message.read(signed.data);
|
||||
return openpgp.verify(verifyOpt);
|
||||
}).then(async function (verified) {
|
||||
expect(verified.data).to.equal(plaintext.replace(/[ \t]+$/mg, ''));
|
||||
expect(verified.data).to.equal(plaintext);
|
||||
expect(verified.signatures[0].valid).to.be.true;
|
||||
const signingKey = await privateKey.keys[0].getSigningKey();
|
||||
expect(verified.signatures[0].keyid.toHex()).to.equal(signingKey.getKeyId().toHex());
|
||||
@@ -2119,9 +2125,9 @@ describe('OpenPGP.js public api tests', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('should sign and verify cleartext data and not armor with detached signatures', function () {
|
||||
it('should sign and verify data and not armor with detached signatures', function () {
|
||||
const start = openpgp.util.normalizeDate();
|
||||
const message = openpgp.cleartext.fromText(plaintext);
|
||||
const message = openpgp.message.fromText(plaintext);
|
||||
const signOpt = {
|
||||
message,
|
||||
privateKeys: privateKey.keys,
|
||||
@@ -2132,11 +2138,11 @@ describe('OpenPGP.js public api tests', function() {
|
||||
message,
|
||||
publicKeys: publicKey.keys
|
||||
};
|
||||
return openpgp.sign(signOpt).then(function (signed) {
|
||||
verifyOpt.signature = signed.signature;
|
||||
return openpgp.sign(signOpt).then(async function (signed) {
|
||||
verifyOpt.signature = await openpgp.signature.read(signed.signature);
|
||||
return openpgp.verify(verifyOpt);
|
||||
}).then(async function (verified) {
|
||||
expect(verified.data).to.equal(plaintext.replace(/[ \t]+$/mg, ''));
|
||||
expect(verified.data).to.equal(plaintext);
|
||||
expect(+verified.signatures[0].signature.packets[0].created).to.be.lte(+openpgp.util.normalizeDate());
|
||||
expect(+verified.signatures[0].signature.packets[0].created).to.be.gte(+start);
|
||||
expect(verified.signatures[0].valid).to.be.true;
|
||||
@@ -2146,8 +2152,8 @@ describe('OpenPGP.js public api tests', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('should sign and verify cleartext data with a date in the past', function () {
|
||||
const message = openpgp.cleartext.fromText(plaintext);
|
||||
it('should sign and verify data with a date in the past', function () {
|
||||
const message = openpgp.message.fromText(plaintext);
|
||||
const past = new Date(2000);
|
||||
const signOpt = {
|
||||
message,
|
||||
@@ -2161,11 +2167,11 @@ describe('OpenPGP.js public api tests', function() {
|
||||
publicKeys: publicKey_1337.keys,
|
||||
date: past
|
||||
};
|
||||
return openpgp.sign(signOpt).then(function (signed) {
|
||||
verifyOpt.signature = signed.signature;
|
||||
return openpgp.sign(signOpt).then(async function (signed) {
|
||||
verifyOpt.signature = await openpgp.signature.read(signed.signature);
|
||||
return openpgp.verify(verifyOpt).then(async function (verified) {
|
||||
expect(+verified.signatures[0].signature.packets[0].created).to.equal(+past);
|
||||
expect(verified.data).to.equal(plaintext.replace(/[ \t]+$/mg, ''));
|
||||
expect(verified.data).to.equal(plaintext);
|
||||
expect(verified.signatures[0].valid).to.be.true;
|
||||
expect(await signOpt.privateKeys[0].getSigningKey(verified.signatures[0].keyid, past))
|
||||
.to.be.not.null;
|
||||
@@ -2175,7 +2181,7 @@ describe('OpenPGP.js public api tests', function() {
|
||||
return openpgp.verify(verifyOpt);
|
||||
}).then(async function (verified) {
|
||||
expect(+verified.signatures[0].signature.packets[0].created).to.equal(+past);
|
||||
expect(verified.data).to.equal(plaintext.replace(/[ \t]+$/mg, ''));
|
||||
expect(verified.data).to.equal(plaintext);
|
||||
expect(verified.signatures[0].valid).to.be.true;
|
||||
expect(await signOpt.privateKeys[0].getSigningKey(verified.signatures[0].keyid, null))
|
||||
.to.be.not.null;
|
||||
@@ -2198,9 +2204,9 @@ describe('OpenPGP.js public api tests', function() {
|
||||
publicKeys: publicKey_2038_2045.keys,
|
||||
date: future
|
||||
};
|
||||
return openpgp.sign(signOpt).then(function (signed) {
|
||||
return openpgp.sign(signOpt).then(async function (signed) {
|
||||
verifyOpt.message = openpgp.message.fromBinary(data);
|
||||
verifyOpt.signature = signed.signature;
|
||||
verifyOpt.signature = await openpgp.signature.read(signed.signature);
|
||||
return openpgp.verify(verifyOpt);
|
||||
}).then(async function (verified) {
|
||||
expect(+verified.signatures[0].signature.packets[0].created).to.equal(+future);
|
||||
@@ -2222,10 +2228,12 @@ describe('OpenPGP.js public api tests', function() {
|
||||
const verifyOpt = {
|
||||
publicKeys: publicKey.keys
|
||||
};
|
||||
return openpgp.sign(signOpt).then(function (signed) {
|
||||
return openpgp.sign(signOpt).then(async function (signed) {
|
||||
const message = await openpgp.message.read(signed.data);
|
||||
message.packets.concat(await openpgp.stream.readToEnd(message.packets.stream, _ => _));
|
||||
const packets = new openpgp.packet.List();
|
||||
packets.push(signed.message.packets.findPacket(openpgp.enums.packet.signature));
|
||||
packets.push(signed.message.packets.findPacket(openpgp.enums.packet.literal));
|
||||
packets.push(message.packets.findPacket(openpgp.enums.packet.signature));
|
||||
packets.push(message.packets.findPacket(openpgp.enums.packet.literal));
|
||||
verifyOpt.message = new openpgp.message.Message(packets);
|
||||
return openpgp.verify(verifyOpt);
|
||||
}).then(async function (verified) {
|
||||
@@ -2249,10 +2257,13 @@ describe('OpenPGP.js public api tests', function() {
|
||||
publicKeys: publicKey.keys,
|
||||
streaming: 'web'
|
||||
};
|
||||
return openpgp.sign(signOpt).then(function (signed) {
|
||||
return openpgp.sign(signOpt).then(async function (signed) {
|
||||
expect(openpgp.util.isStream(signed.data)).to.equal('web');
|
||||
const message = await openpgp.message.read(signed.data);
|
||||
message.packets.concat(await openpgp.stream.readToEnd(message.packets.stream, _ => _));
|
||||
const packets = new openpgp.packet.List();
|
||||
packets.push(signed.message.packets.findPacket(openpgp.enums.packet.signature));
|
||||
packets.push(signed.message.packets.findPacket(openpgp.enums.packet.literal));
|
||||
packets.push(message.packets.findPacket(openpgp.enums.packet.signature));
|
||||
packets.push(message.packets.findPacket(openpgp.enums.packet.literal));
|
||||
verifyOpt.message = new openpgp.message.Message(packets);
|
||||
return openpgp.verify(verifyOpt);
|
||||
}).then(async function (verified) {
|
||||
@@ -2265,7 +2276,7 @@ describe('OpenPGP.js public api tests', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('should encrypt and decrypt cleartext data with a date in the future', function () {
|
||||
it('should encrypt and decrypt data with a date in the future', function () {
|
||||
const future = new Date(2040, 5, 5, 5, 5, 5, 0);
|
||||
const encryptOpt = {
|
||||
message: openpgp.message.fromText(plaintext, undefined, future),
|
||||
@@ -2273,14 +2284,10 @@ describe('OpenPGP.js public api tests', function() {
|
||||
date: future,
|
||||
armor: false
|
||||
};
|
||||
const decryptOpt = {
|
||||
privateKeys: privateKey_2038_2045.keys,
|
||||
date: future
|
||||
};
|
||||
|
||||
return openpgp.encrypt(encryptOpt).then(function (encrypted) {
|
||||
decryptOpt.message = encrypted.message;
|
||||
return encrypted.message.decrypt(decryptOpt.privateKeys);
|
||||
return openpgp.encrypt(encryptOpt).then(async function (encrypted) {
|
||||
const message = await openpgp.message.read(encrypted.data);
|
||||
return message.decrypt(privateKey_2038_2045.keys);
|
||||
}).then(async function (packets) {
|
||||
const literals = packets.packets.filterByTag(openpgp.enums.packet.literal);
|
||||
expect(literals.length).to.equal(1);
|
||||
@@ -2298,14 +2305,10 @@ describe('OpenPGP.js public api tests', function() {
|
||||
date: past,
|
||||
armor: false
|
||||
};
|
||||
const decryptOpt = {
|
||||
privateKeys: privateKey_2000_2008.keys,
|
||||
date: past
|
||||
};
|
||||
|
||||
return openpgp.encrypt(encryptOpt).then(function (encrypted) {
|
||||
decryptOpt.message = encrypted.message;
|
||||
return encrypted.message.decrypt(decryptOpt.privateKeys);
|
||||
return openpgp.encrypt(encryptOpt).then(async function (encrypted) {
|
||||
const message = await openpgp.message.read(encrypted.data);
|
||||
return message.decrypt(privateKey_2000_2008.keys);
|
||||
}).then(async function (packets) {
|
||||
const literals = packets.packets.filterByTag(openpgp.enums.packet.literal);
|
||||
expect(literals.length).to.equal(1);
|
||||
@@ -2314,7 +2317,7 @@ describe('OpenPGP.js public api tests', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('should sign, encrypt and decrypt, verify cleartext data with a date in the past', function () {
|
||||
it('should sign, encrypt and decrypt, verify data with a date in the past', function () {
|
||||
const past = new Date(2005, 5, 5, 5, 5, 5, 0);
|
||||
const encryptOpt = {
|
||||
message: openpgp.message.fromText(plaintext, undefined, past),
|
||||
@@ -2324,8 +2327,9 @@ describe('OpenPGP.js public api tests', function() {
|
||||
armor: false
|
||||
};
|
||||
|
||||
return openpgp.encrypt(encryptOpt).then(function (encrypted) {
|
||||
return encrypted.message.decrypt(encryptOpt.privateKeys);
|
||||
return openpgp.encrypt(encryptOpt).then(async function (encrypted) {
|
||||
const message = await openpgp.message.read(encrypted.data);
|
||||
return message.decrypt(encryptOpt.privateKeys);
|
||||
}).then(async function (packets) {
|
||||
const literals = packets.packets.filterByTag(openpgp.enums.packet.literal);
|
||||
expect(literals.length).to.equal(1);
|
||||
@@ -2351,8 +2355,9 @@ describe('OpenPGP.js public api tests', function() {
|
||||
armor: false
|
||||
};
|
||||
|
||||
return openpgp.encrypt(encryptOpt).then(function (encrypted) {
|
||||
return encrypted.message.decrypt(encryptOpt.privateKeys);
|
||||
return openpgp.encrypt(encryptOpt).then(async function (encrypted) {
|
||||
const message = await openpgp.message.read(encrypted.data);
|
||||
return message.decrypt(encryptOpt.privateKeys);
|
||||
}).then(async function (packets) {
|
||||
const literals = packets.packets.filterByTag(openpgp.enums.packet.literal);
|
||||
expect(literals.length).to.equal(1);
|
||||
@@ -2379,8 +2384,9 @@ describe('OpenPGP.js public api tests', function() {
|
||||
armor: false
|
||||
};
|
||||
|
||||
return openpgp.encrypt(encryptOpt).then(function (encrypted) {
|
||||
return encrypted.message.decrypt(encryptOpt.privateKeys);
|
||||
return openpgp.encrypt(encryptOpt).then(async function (encrypted) {
|
||||
const message = await openpgp.message.read(encrypted.data);
|
||||
return message.decrypt(encryptOpt.privateKeys);
|
||||
}).then(async function (packets) {
|
||||
const literals = packets.packets.filterByTag(openpgp.enums.packet.literal);
|
||||
expect(literals.length).to.equal(1);
|
||||
|
||||
@@ -1439,9 +1439,9 @@ hkJiXopCSWKSlQInL1devkJJUWJmTmZeugJYlpdLAagQJM0JpsCqIQZwKgAA
|
||||
const privKey = (await openpgp.key.readArmored(priv_key_arm2)).keys[0];
|
||||
await privKey.decrypt('hello world');
|
||||
|
||||
return openpgp.sign({ privateKeys:[privKey], message: openpgp.message.fromBinary(plaintext), armor:false }).then(function(signed) {
|
||||
return openpgp.sign({ privateKeys:[privKey], message: openpgp.message.fromBinary(plaintext), armor:false }).then(async function(signed) {
|
||||
|
||||
const csMsg = signed.message;
|
||||
const csMsg = await openpgp.message.read(signed.data);
|
||||
return openpgp.verify({ publicKeys:[pubKey], message:csMsg });
|
||||
|
||||
}).then(function(cleartextSig) {
|
||||
|
||||
@@ -234,10 +234,11 @@ function tests() {
|
||||
const encrypted = await openpgp.encrypt({
|
||||
message: openpgp.message.fromBinary(data),
|
||||
passwords: ['test'],
|
||||
armor: false
|
||||
});
|
||||
expect(util.isStream(encrypted.data)).to.equal(expectedType);
|
||||
|
||||
const msgAsciiArmored = encrypted.data;
|
||||
const message = await openpgp.message.readArmored(msgAsciiArmored);
|
||||
const message = await openpgp.message.read(encrypted.data);
|
||||
setTimeout(dataArrived, 3000); // Do not wait until data arrived, but wait a bit to check that it doesn't arrive early.
|
||||
const decrypted = await openpgp.decrypt({
|
||||
passwords: ['test'],
|
||||
@@ -258,10 +259,11 @@ function tests() {
|
||||
const encrypted = await openpgp.encrypt({
|
||||
message: openpgp.message.fromBinary(data),
|
||||
passwords: ['test'],
|
||||
armor: false
|
||||
});
|
||||
expect(util.isStream(encrypted.data)).to.equal(expectedType);
|
||||
|
||||
const msgAsciiArmored = encrypted.data;
|
||||
const message = await openpgp.message.readArmored(msgAsciiArmored);
|
||||
const message = await openpgp.message.read(encrypted.data);
|
||||
const decrypted = await openpgp.decrypt({
|
||||
passwords: ['test'],
|
||||
message,
|
||||
@@ -286,11 +288,12 @@ function tests() {
|
||||
const encrypted = await openpgp.encrypt({
|
||||
message: openpgp.message.fromBinary(data),
|
||||
publicKeys: pubKey,
|
||||
privateKeys: privKey
|
||||
privateKeys: privKey,
|
||||
armor: false
|
||||
});
|
||||
expect(util.isStream(encrypted.data)).to.equal(expectedType);
|
||||
|
||||
const msgAsciiArmored = encrypted.data;
|
||||
const message = await openpgp.message.readArmored(msgAsciiArmored);
|
||||
const message = await openpgp.message.read(encrypted.data);
|
||||
const decrypted = await openpgp.decrypt({
|
||||
publicKeys: pubKey,
|
||||
privateKeys: privKey,
|
||||
@@ -317,11 +320,12 @@ function tests() {
|
||||
const encrypted = await openpgp.encrypt({
|
||||
message: openpgp.message.fromBinary(data),
|
||||
publicKeys: pub,
|
||||
privateKeys: priv
|
||||
privateKeys: priv,
|
||||
armor: false
|
||||
});
|
||||
expect(util.isStream(encrypted.data)).to.equal(expectedType);
|
||||
|
||||
const msgAsciiArmored = encrypted.data;
|
||||
const message = await openpgp.message.readArmored(msgAsciiArmored);
|
||||
const message = await openpgp.message.read(encrypted.data);
|
||||
const decrypted = await openpgp.decrypt({
|
||||
publicKeys: pub,
|
||||
privateKeys: priv,
|
||||
@@ -348,11 +352,12 @@ function tests() {
|
||||
const encrypted = await openpgp.encrypt({
|
||||
message: openpgp.message.fromBinary(data),
|
||||
publicKeys: pub,
|
||||
privateKeys: priv
|
||||
privateKeys: priv,
|
||||
armor: false
|
||||
});
|
||||
expect(util.isStream(encrypted.data)).to.equal(expectedType);
|
||||
|
||||
const msgAsciiArmored = encrypted.data;
|
||||
const message = await openpgp.message.readArmored(msgAsciiArmored);
|
||||
const message = await openpgp.message.read(encrypted.data);
|
||||
const decrypted = await openpgp.decrypt({
|
||||
publicKeys: pub,
|
||||
privateKeys: priv,
|
||||
@@ -375,8 +380,9 @@ function tests() {
|
||||
try {
|
||||
const encrypted = await openpgp.encrypt({
|
||||
message: openpgp.message.fromBinary(data),
|
||||
passwords: ['test'],
|
||||
passwords: ['test']
|
||||
});
|
||||
expect(util.isStream(encrypted.data)).to.equal(expectedType);
|
||||
|
||||
const msgAsciiArmored = encrypted.data;
|
||||
const message = await openpgp.message.readArmored(openpgp.stream.transform(msgAsciiArmored, value => {
|
||||
@@ -412,6 +418,7 @@ function tests() {
|
||||
publicKeys: pubKey,
|
||||
privateKeys: privKey
|
||||
});
|
||||
expect(util.isStream(encrypted.data)).to.equal(expectedType);
|
||||
|
||||
const msgAsciiArmored = encrypted.data;
|
||||
const message = await openpgp.message.readArmored(openpgp.stream.transform(msgAsciiArmored, value => {
|
||||
@@ -447,6 +454,7 @@ function tests() {
|
||||
publicKeys: pubKey,
|
||||
privateKeys: privKey
|
||||
});
|
||||
expect(util.isStream(encrypted.data)).to.equal(expectedType);
|
||||
|
||||
const msgAsciiArmored = encrypted.data;
|
||||
const message = await openpgp.message.readArmored(openpgp.stream.transform(msgAsciiArmored, value => {
|
||||
@@ -478,6 +486,7 @@ function tests() {
|
||||
message: openpgp.message.fromBinary(data),
|
||||
privateKeys: privKey
|
||||
});
|
||||
expect(util.isStream(signed.data)).to.equal(expectedType);
|
||||
|
||||
const msgAsciiArmored = signed.data;
|
||||
const message = await openpgp.message.readArmored(openpgp.stream.transform(msgAsciiArmored, value => {
|
||||
@@ -504,14 +513,16 @@ function tests() {
|
||||
let aead_chunk_size_byteValue = openpgp.config.aead_chunk_size_byte;
|
||||
openpgp.config.aead_protect = true;
|
||||
openpgp.config.aead_chunk_size_byte = 4;
|
||||
|
||||
try {
|
||||
const encrypted = await openpgp.encrypt({
|
||||
message: openpgp.message.fromBinary(data),
|
||||
passwords: ['test'],
|
||||
armor: false
|
||||
});
|
||||
expect(util.isStream(encrypted.data)).to.equal(expectedType);
|
||||
|
||||
const msgAsciiArmored = encrypted.data;
|
||||
const message = await openpgp.message.readArmored(msgAsciiArmored);
|
||||
const message = await openpgp.message.read(encrypted.data);
|
||||
const decrypted = await openpgp.decrypt({
|
||||
passwords: ['test'],
|
||||
message,
|
||||
@@ -551,8 +562,9 @@ function tests() {
|
||||
const encrypted = await openpgp.encrypt({
|
||||
message: openpgp.message.fromText(data),
|
||||
streaming: expectedType,
|
||||
passwords: ['test'],
|
||||
passwords: ['test']
|
||||
});
|
||||
expect(util.isStream(encrypted.data)).to.equal(expectedType);
|
||||
|
||||
const msgAsciiArmored = encrypted.data;
|
||||
const message = await openpgp.message.readArmored(msgAsciiArmored);
|
||||
@@ -586,7 +598,7 @@ function tests() {
|
||||
}
|
||||
await writer.write(value);
|
||||
}
|
||||
} catch(e) {
|
||||
} catch (e) {
|
||||
await writer.abort(e);
|
||||
}
|
||||
});
|
||||
@@ -596,8 +608,8 @@ function tests() {
|
||||
});
|
||||
|
||||
it('Input stream should be canceled when canceling decrypted stream (AEAD)', async function() {
|
||||
let aead_protectValue = openpgp.config.aead_protect;
|
||||
let aead_chunk_size_byteValue = openpgp.config.aead_chunk_size_byte;
|
||||
const aead_protectValue = openpgp.config.aead_protect;
|
||||
const aead_chunk_size_byteValue = openpgp.config.aead_chunk_size_byte;
|
||||
openpgp.config.aead_protect = true;
|
||||
openpgp.config.aead_chunk_size_byte = 4;
|
||||
try {
|
||||
@@ -631,6 +643,7 @@ function tests() {
|
||||
message: openpgp.message.fromBinary(data),
|
||||
privateKeys: privKey
|
||||
});
|
||||
expect(util.isStream(signed.data)).to.equal(expectedType);
|
||||
|
||||
const msgAsciiArmored = signed.data;
|
||||
const message = await openpgp.message.readArmored(msgAsciiArmored);
|
||||
@@ -652,8 +665,10 @@ function tests() {
|
||||
it("Don't pull entire input stream when we're not pulling encrypted stream", async function() {
|
||||
const encrypted = await openpgp.encrypt({
|
||||
message: openpgp.message.fromBinary(data),
|
||||
passwords: ['test'],
|
||||
passwords: ['test']
|
||||
});
|
||||
expect(util.isStream(encrypted.data)).to.equal(expectedType);
|
||||
|
||||
const reader = openpgp.stream.getReader(encrypted.data);
|
||||
expect(await reader.readBytes(1024)).to.match(/^-----BEGIN PGP MESSAGE-----\r\n/);
|
||||
dataArrived();
|
||||
@@ -666,6 +681,8 @@ function tests() {
|
||||
message: openpgp.message.fromBinary(data),
|
||||
privateKeys: privKey
|
||||
});
|
||||
expect(util.isStream(signed.data)).to.equal(expectedType);
|
||||
|
||||
const reader = openpgp.stream.getReader(signed.data);
|
||||
expect(await reader.readBytes(1024)).to.match(/^-----BEGIN PGP MESSAGE-----\r\n/);
|
||||
dataArrived();
|
||||
@@ -683,8 +700,9 @@ function tests() {
|
||||
try {
|
||||
const encrypted = await openpgp.encrypt({
|
||||
message: openpgp.message.fromBinary(data),
|
||||
passwords: ['test'],
|
||||
passwords: ['test']
|
||||
});
|
||||
expect(util.isStream(encrypted.data)).to.equal(expectedType);
|
||||
const msgAsciiArmored = encrypted.data;
|
||||
const message = await openpgp.message.readArmored(msgAsciiArmored);
|
||||
const decrypted = await openpgp.decrypt({
|
||||
@@ -710,6 +728,7 @@ function tests() {
|
||||
message: openpgp.message.fromBinary(data),
|
||||
privateKeys: privKey
|
||||
});
|
||||
expect(util.isStream(signed.data)).to.equal(expectedType);
|
||||
const msgAsciiArmored = signed.data;
|
||||
const message = await openpgp.message.readArmored(msgAsciiArmored);
|
||||
const verified = await openpgp.verify({
|
||||
@@ -739,6 +758,7 @@ function tests() {
|
||||
detached: true,
|
||||
streaming: expectedType
|
||||
});
|
||||
expect(util.isStream(signed.signature)).to.equal(expectedType);
|
||||
const sigArmored = await openpgp.stream.readToEnd(signed.signature);
|
||||
const signature = await openpgp.message.readArmored(sigArmored);
|
||||
const verified = await openpgp.verify({
|
||||
@@ -765,9 +785,10 @@ function tests() {
|
||||
privateKeys: privKey,
|
||||
detached: true,
|
||||
streaming: false,
|
||||
armor: false
|
||||
});
|
||||
const sigArmored = await openpgp.stream.readToEnd(signed.signature);
|
||||
const signature = await openpgp.message.readArmored(sigArmored);
|
||||
expect(util.isStream(signed.signature)).to.be.false;
|
||||
const signature = await openpgp.message.read(signed.signature);
|
||||
const verified = await openpgp.verify({
|
||||
signature,
|
||||
publicKeys: pubKey,
|
||||
@@ -796,6 +817,7 @@ function tests() {
|
||||
detached: true,
|
||||
streaming: expectedType
|
||||
});
|
||||
expect(util.isStream(signed.signature)).to.equal(expectedType);
|
||||
const sigArmored = await openpgp.stream.readToEnd(signed.signature);
|
||||
const signature = await openpgp.message.readArmored(sigArmored);
|
||||
const verified = await openpgp.verify({
|
||||
@@ -826,6 +848,7 @@ function tests() {
|
||||
detached: true,
|
||||
streaming: expectedType
|
||||
});
|
||||
expect(util.isStream(signed.signature)).to.equal(expectedType);
|
||||
const sigArmored = await openpgp.stream.readToEnd(signed.signature);
|
||||
const signature = await openpgp.message.readArmored(sigArmored);
|
||||
const verified = await openpgp.verify({
|
||||
@@ -844,6 +867,7 @@ function tests() {
|
||||
privateKeys: privKey,
|
||||
detached: true
|
||||
});
|
||||
expect(util.isStream(signed.signature)).to.equal(expectedType);
|
||||
const reader = openpgp.stream.getReader(signed.signature);
|
||||
expect((await reader.readBytes(31)).toString('utf8')).to.equal('-----BEGIN PGP SIGNATURE-----\r\n');
|
||||
dataArrived();
|
||||
@@ -857,6 +881,7 @@ function tests() {
|
||||
privateKeys: privKey,
|
||||
detached: true
|
||||
});
|
||||
expect(util.isStream(signed.signature)).to.equal(expectedType);
|
||||
const reader = openpgp.stream.getReader(signed.signature);
|
||||
expect((await reader.readBytes(31)).toString('utf8')).to.equal('-----BEGIN PGP SIGNATURE-----\r\n');
|
||||
dataArrived();
|
||||
|
||||
Reference in New Issue
Block a user