Fix bug for password decrypt in auth service

This commit is contained in:
Tankred Hase 2014-12-19 11:21:57 +01:00
parent b01aa6716c
commit cddc0988b7
2 changed files with 10 additions and 3 deletions

View File

@ -76,9 +76,13 @@ Auth.prototype.getCredentials = function() {
if (self.passwordNeedsDecryption) { if (self.passwordNeedsDecryption) {
// decrypt password // decrypt password
return self._pgp.decrypt(self.password, undefined).then(function(cleartext) { return self._pgp.decrypt(self.password, undefined).then(function(pt) {
if (!pt.signaturesValid) {
throw new Error('Verifying PGP signature of encrypted password failed!');
}
self.passwordNeedsDecryption = false; self.passwordNeedsDecryption = false;
self.password = cleartext; self.password = pt.decrypted;
}).then(done); }).then(done);
} }

View File

@ -74,7 +74,10 @@ describe('Auth unit tests', function() {
storageStub.listItems.withArgs(REALNAME_DB_KEY, 0, null).returns(resolves([realname])); storageStub.listItems.withArgs(REALNAME_DB_KEY, 0, null).returns(resolves([realname]));
storageStub.listItems.withArgs(IMAP_DB_KEY, 0, null).returns(resolves([imap])); storageStub.listItems.withArgs(IMAP_DB_KEY, 0, null).returns(resolves([imap]));
storageStub.listItems.withArgs(SMTP_DB_KEY, 0, null).returns(resolves([smtp])); storageStub.listItems.withArgs(SMTP_DB_KEY, 0, null).returns(resolves([smtp]));
pgpStub.decrypt.withArgs(encryptedPassword, undefined).returns(resolves(password)); pgpStub.decrypt.withArgs(encryptedPassword, undefined).returns(resolves({
decrypted: password,
signaturesValid: true
}));
auth.getCredentials().then(function(cred) { auth.getCredentials().then(function(cred) {
expect(auth.emailAddress).to.equal(emailAddress); expect(auth.emailAddress).to.equal(emailAddress);