mirror of
https://github.com/moparisthebest/mail
synced 2024-11-25 10:22:18 -05:00
Merge pull request #254 from whiteout-io/dev/WO-852
Use realname in PGP keygen
This commit is contained in:
commit
990950bc48
@ -56,6 +56,7 @@ var LoginInitialCtrl = function($scope, $location, $routeParams, $q, newsletter,
|
|||||||
}).then(function() {
|
}).then(function() {
|
||||||
// generate key without passphrase
|
// generate key without passphrase
|
||||||
return email.unlock({
|
return email.unlock({
|
||||||
|
realname: auth.realname,
|
||||||
passphrase: undefined
|
passphrase: undefined
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -21,14 +21,15 @@ function PGP() {
|
|||||||
*/
|
*/
|
||||||
PGP.prototype.generateKeys = function(options) {
|
PGP.prototype.generateKeys = function(options) {
|
||||||
return new Promise(function(resolve) {
|
return new Promise(function(resolve) {
|
||||||
var userId, passphrase;
|
var userId, name, passphrase;
|
||||||
|
|
||||||
if (!util.emailRegEx.test(options.emailAddress) || !options.keySize) {
|
if (!util.emailRegEx.test(options.emailAddress) || !options.keySize) {
|
||||||
throw new Error('Crypto init failed. Not all options set!');
|
throw new Error('Crypto init failed. Not all options set!');
|
||||||
}
|
}
|
||||||
|
|
||||||
// generate keypair
|
// 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;
|
passphrase = (options.passphrase) ? options.passphrase : undefined;
|
||||||
|
|
||||||
resolve({
|
resolve({
|
||||||
|
@ -103,6 +103,7 @@ Email.prototype.unlock = function(options) {
|
|||||||
// no keypair for is stored for the user... generate a new one
|
// no keypair for is stored for the user... generate a new one
|
||||||
return self._pgp.generateKeys({
|
return self._pgp.generateKeys({
|
||||||
emailAddress: self._account.emailAddress,
|
emailAddress: self._account.emailAddress,
|
||||||
|
realname: options.realname,
|
||||||
keySize: self._account.asymKeySize,
|
keySize: self._account.asymKeySize,
|
||||||
passphrase: options.passphrase
|
passphrase: options.passphrase
|
||||||
}).then(function(keypair) {
|
}).then(function(keypair) {
|
||||||
|
@ -65,6 +65,10 @@ describe('Login (initial user) Controller unit test', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('generate key', function() {
|
describe('generate key', function() {
|
||||||
|
beforeEach(function() {
|
||||||
|
authMock.realname = 'Hans Dampf';
|
||||||
|
});
|
||||||
|
|
||||||
it('should not continue if terms are not accepted', function() {
|
it('should not continue if terms are not accepted', function() {
|
||||||
scope.agree = undefined;
|
scope.agree = undefined;
|
||||||
|
|
||||||
@ -79,7 +83,8 @@ describe('Login (initial user) Controller unit test', function() {
|
|||||||
scope.agree = true;
|
scope.agree = true;
|
||||||
|
|
||||||
emailMock.unlock.withArgs({
|
emailMock.unlock.withArgs({
|
||||||
passphrase: undefined
|
passphrase: undefined,
|
||||||
|
realname: authMock.realname
|
||||||
}).returns(rejects(new Error('asdf')));
|
}).returns(rejects(new Error('asdf')));
|
||||||
authMock.storeCredentials.returns(resolves());
|
authMock.storeCredentials.returns(resolves());
|
||||||
|
|
||||||
@ -95,7 +100,8 @@ describe('Login (initial user) Controller unit test', function() {
|
|||||||
scope.agree = true;
|
scope.agree = true;
|
||||||
|
|
||||||
emailMock.unlock.withArgs({
|
emailMock.unlock.withArgs({
|
||||||
passphrase: undefined
|
passphrase: undefined,
|
||||||
|
realname: authMock.realname
|
||||||
}).returns(resolves());
|
}).returns(resolves());
|
||||||
authMock.storeCredentials.returns(resolves());
|
authMock.storeCredentials.returns(resolves());
|
||||||
|
|
||||||
|
@ -65,11 +65,12 @@ describe('PGP Crypto Api unit tests', function() {
|
|||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
it('should work with passphrase', function(done) {
|
it('should work without realname', function(done) {
|
||||||
var keyObject;
|
var keyObject;
|
||||||
|
|
||||||
pgp.generateKeys({
|
pgp.generateKeys({
|
||||||
emailAddress: user,
|
emailAddress: user,
|
||||||
|
realname: undefined,
|
||||||
keySize: keySize,
|
keySize: keySize,
|
||||||
passphrase: passphrase
|
passphrase: passphrase
|
||||||
}).then(function(keys) {
|
}).then(function(keys) {
|
||||||
@ -95,11 +96,45 @@ describe('PGP Crypto Api unit tests', function() {
|
|||||||
done();
|
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) {
|
it('should work without passphrase', function(done) {
|
||||||
var keyObject;
|
var keyObject;
|
||||||
|
|
||||||
pgp.generateKeys({
|
pgp.generateKeys({
|
||||||
emailAddress: user,
|
emailAddress: user,
|
||||||
|
realname: 'Jon Doe',
|
||||||
keySize: keySize,
|
keySize: keySize,
|
||||||
passphrase: ''
|
passphrase: ''
|
||||||
}).then(function(keys) {
|
}).then(function(keys) {
|
||||||
@ -115,6 +150,8 @@ describe('PGP Crypto Api unit tests', function() {
|
|||||||
publicKeyArmored: keys.publicKeyArmored
|
publicKeyArmored: keys.publicKeyArmored
|
||||||
});
|
});
|
||||||
}).then(function() {
|
}).then(function() {
|
||||||
|
expect(pgp.getKeyParams().userIds[0].name).to.equal('Jon Doe');
|
||||||
|
|
||||||
return pgp.encrypt('secret', [keyObject.publicKeyArmored]);
|
return pgp.encrypt('secret', [keyObject.publicKeyArmored]);
|
||||||
}).then(function(ct) {
|
}).then(function(ct) {
|
||||||
expect(ct).to.exist;
|
expect(ct).to.exist;
|
||||||
|
@ -199,9 +199,11 @@ describe('Email DAO unit tests', function() {
|
|||||||
publicKeyArmored: mockKeyPair.publicKey.publicKey,
|
publicKeyArmored: mockKeyPair.publicKey.publicKey,
|
||||||
privateKeyArmored: mockKeyPair.privateKey.encryptedKey
|
privateKeyArmored: mockKeyPair.privateKey.encryptedKey
|
||||||
};
|
};
|
||||||
|
var name = 'Hans Dampf';
|
||||||
|
|
||||||
pgpStub.generateKeys.withArgs({
|
pgpStub.generateKeys.withArgs({
|
||||||
emailAddress: emailAddress,
|
emailAddress: emailAddress,
|
||||||
|
realname: name,
|
||||||
keySize: asymKeySize,
|
keySize: asymKeySize,
|
||||||
passphrase: passphrase
|
passphrase: passphrase
|
||||||
}).returns(resolves(keypair));
|
}).returns(resolves(keypair));
|
||||||
@ -214,6 +216,7 @@ describe('Email DAO unit tests', function() {
|
|||||||
keychainStub.putUserKeyPair.withArgs().returns(resolves());
|
keychainStub.putUserKeyPair.withArgs().returns(resolves());
|
||||||
|
|
||||||
dao.unlock({
|
dao.unlock({
|
||||||
|
realname: name,
|
||||||
passphrase: passphrase
|
passphrase: passphrase
|
||||||
}).then(function() {
|
}).then(function() {
|
||||||
expect(pgpStub.generateKeys.calledOnce).to.be.true;
|
expect(pgpStub.generateKeys.calledOnce).to.be.true;
|
||||||
|
Loading…
Reference in New Issue
Block a user