1
0
mirror of https://github.com/moparisthebest/mail synced 2024-11-25 02:12:17 -05:00

Merge pull request #254 from whiteout-io/dev/WO-852

Use realname in PGP keygen
This commit is contained in:
Felix Hammerl 2015-01-22 12:14:17 +01:00
commit 990950bc48
6 changed files with 54 additions and 5 deletions

View File

@ -56,6 +56,7 @@ var LoginInitialCtrl = function($scope, $location, $routeParams, $q, newsletter,
}).then(function() {
// generate key without passphrase
return email.unlock({
realname: auth.realname,
passphrase: undefined
});

View File

@ -21,14 +21,15 @@ function PGP() {
*/
PGP.prototype.generateKeys = function(options) {
return new Promise(function(resolve) {
var userId, passphrase;
var userId, name, passphrase;
if (!util.emailRegEx.test(options.emailAddress) || !options.keySize) {
throw new Error('Crypto init failed. Not all options set!');
}
// generate keypair
userId = 'Whiteout User <' + options.emailAddress + '>';
name = options.realname ? options.realname.replace(/[&\/\\#,+()$~%.'":*?<>{}]/g, '').trim() + ' ' : '';
userId = name + '<' + options.emailAddress + '>';
passphrase = (options.passphrase) ? options.passphrase : undefined;
resolve({

View File

@ -103,6 +103,7 @@ Email.prototype.unlock = function(options) {
// no keypair for is stored for the user... generate a new one
return self._pgp.generateKeys({
emailAddress: self._account.emailAddress,
realname: options.realname,
keySize: self._account.asymKeySize,
passphrase: options.passphrase
}).then(function(keypair) {

View File

@ -65,6 +65,10 @@ describe('Login (initial user) Controller unit test', function() {
});
describe('generate key', function() {
beforeEach(function() {
authMock.realname = 'Hans Dampf';
});
it('should not continue if terms are not accepted', function() {
scope.agree = undefined;
@ -79,7 +83,8 @@ describe('Login (initial user) Controller unit test', function() {
scope.agree = true;
emailMock.unlock.withArgs({
passphrase: undefined
passphrase: undefined,
realname: authMock.realname
}).returns(rejects(new Error('asdf')));
authMock.storeCredentials.returns(resolves());
@ -95,7 +100,8 @@ describe('Login (initial user) Controller unit test', function() {
scope.agree = true;
emailMock.unlock.withArgs({
passphrase: undefined
passphrase: undefined,
realname: authMock.realname
}).returns(resolves());
authMock.storeCredentials.returns(resolves());

View File

@ -65,11 +65,12 @@ describe('PGP Crypto Api unit tests', function() {
done();
});
});
it('should work with passphrase', function(done) {
it('should work without realname', function(done) {
var keyObject;
pgp.generateKeys({
emailAddress: user,
realname: undefined,
keySize: keySize,
passphrase: passphrase
}).then(function(keys) {
@ -95,11 +96,45 @@ describe('PGP Crypto Api unit tests', function() {
done();
});
});
it('should work with passphrase', function(done) {
var keyObject;
pgp.generateKeys({
emailAddress: user,
realname: 'Jon Doe <%$# ',
keySize: keySize,
passphrase: passphrase
}).then(function(keys) {
expect(keys.keyId).to.exist;
expect(keys.privateKeyArmored).to.exist;
expect(keys.publicKeyArmored).to.exist;
keyObject = keys;
// test encrypt/decrypt
return pgp.importKeys({
passphrase: passphrase,
privateKeyArmored: keys.privateKeyArmored,
publicKeyArmored: keys.publicKeyArmored
});
}).then(function() {
expect(pgp.getKeyParams().userIds[0].name).to.equal('Jon Doe');
return pgp.encrypt('secret', [keyObject.publicKeyArmored]);
}).then(function(ct) {
expect(ct).to.exist;
return pgp.decrypt(ct, keyObject.publicKeyArmored);
}).then(function(pt) {
expect(pt.decrypted).to.equal('secret');
expect(pt.signaturesValid).to.be.true;
done();
});
});
it('should work without passphrase', function(done) {
var keyObject;
pgp.generateKeys({
emailAddress: user,
realname: 'Jon Doe',
keySize: keySize,
passphrase: ''
}).then(function(keys) {
@ -115,6 +150,8 @@ describe('PGP Crypto Api unit tests', function() {
publicKeyArmored: keys.publicKeyArmored
});
}).then(function() {
expect(pgp.getKeyParams().userIds[0].name).to.equal('Jon Doe');
return pgp.encrypt('secret', [keyObject.publicKeyArmored]);
}).then(function(ct) {
expect(ct).to.exist;

View File

@ -199,9 +199,11 @@ describe('Email DAO unit tests', function() {
publicKeyArmored: mockKeyPair.publicKey.publicKey,
privateKeyArmored: mockKeyPair.privateKey.encryptedKey
};
var name = 'Hans Dampf';
pgpStub.generateKeys.withArgs({
emailAddress: emailAddress,
realname: name,
keySize: asymKeySize,
passphrase: passphrase
}).returns(resolves(keypair));
@ -214,6 +216,7 @@ describe('Email DAO unit tests', function() {
keychainStub.putUserKeyPair.withArgs().returns(resolves());
dao.unlock({
realname: name,
passphrase: passphrase
}).then(function() {
expect(pgpStub.generateKeys.calledOnce).to.be.true;