mirror of
https://github.com/moparisthebest/mail
synced 2024-12-22 15:28:49 -05:00
Merge branch 'dev/pgp-signature'
This commit is contained in:
commit
8a6a146225
@ -177,10 +177,15 @@ define(function(require) {
|
||||
* Decrypt and verify a pgp message for a single sender
|
||||
*/
|
||||
PGP.prototype.decrypt = function(ciphertext, senderKey, callback) {
|
||||
var privateKey, msg, keymat, sesskey, decrypted;
|
||||
var privateKey, publicKey, pubKeys, msg, keymat, sesskey, decrypted;
|
||||
|
||||
privateKey = openpgp.keyring.exportPrivateKey(0).obj;
|
||||
senderKey = openpgp.read_publicKey(senderKey)[0];
|
||||
publicKey = openpgp.read_publicKey(senderKey)[0];
|
||||
pubKeys = [{
|
||||
armored: senderKey,
|
||||
obj: publicKey,
|
||||
keyId: publicKey.getKeyId()
|
||||
}];
|
||||
|
||||
try {
|
||||
msg = openpgp.read_message(ciphertext)[0];
|
||||
@ -223,15 +228,26 @@ define(function(require) {
|
||||
|
||||
// decrypt and verify ciphertext
|
||||
try {
|
||||
decrypted = msg.decryptAndVerifySignature(keymat, sesskey, senderKey);
|
||||
decrypted = msg.decryptAndVerifySignature(keymat, sesskey, pubKeys);
|
||||
} catch (err) {
|
||||
callback({
|
||||
errMsg: 'Error reading PGP message!',
|
||||
errMsg: 'Error decrypting PGP message!',
|
||||
err: err
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
// check if signatures are ok
|
||||
for (var k = 0; k < decrypted.validSignatures.length; k++) {
|
||||
if (!decrypted.validSignatures[k]) {
|
||||
callback({
|
||||
errMsg: 'Error verifying PGP signature!'
|
||||
});
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// return decrypted plaintext
|
||||
callback(null, decrypted.text);
|
||||
};
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -118,8 +118,7 @@ define(function(require) {
|
||||
});
|
||||
|
||||
describe('Encryption', function() {
|
||||
var message = 'Hello, World!',
|
||||
ciphertext;
|
||||
var message = 'Hello, World!';
|
||||
|
||||
beforeEach(function(done) {
|
||||
pgp.importKeys({
|
||||
@ -151,7 +150,7 @@ define(function(require) {
|
||||
});
|
||||
});
|
||||
|
||||
describe('Encrypt', function() {
|
||||
describe('Encrypt and sign', function() {
|
||||
it('should fail', function(done) {
|
||||
var input = null;
|
||||
|
||||
@ -166,13 +165,23 @@ define(function(require) {
|
||||
pgp.encrypt(message, [pubkey], function(err, ct) {
|
||||
expect(err).to.not.exist;
|
||||
expect(ct).to.exist;
|
||||
ciphertext = ct;
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('Decrypt', function() {
|
||||
describe('Decrypt and verify', function() {
|
||||
var ciphertext;
|
||||
|
||||
beforeEach(function(done) {
|
||||
pgp.encrypt(message, [pubkey], function(err, ct) {
|
||||
expect(err).to.not.exist;
|
||||
expect(ct).to.exist;
|
||||
ciphertext = ct;
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should fail', function(done) {
|
||||
var input = 'asdfa\rsdf';
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user