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

Use realname in PGP keygen
master
Felix Hammerl 8 years ago
commit 990950bc48

@ -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
});

@ -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({

@ -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) {

@ -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());

@ -65,11 +65,43 @@ describe('PGP Crypto Api unit tests', function() {
done();
});
});
it('should work without realname', function(done) {
var keyObject;
pgp.generateKeys({
emailAddress: user,
realname: undefined,
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() {
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 with passphrase', function(done) {
var keyObject;
pgp.generateKeys({
emailAddress: user,
realname: 'Jon Doe <%$# ',
keySize: keySize,
passphrase: passphrase
}).then(function(keys) {
@ -85,6 +117,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;
@ -100,6 +134,7 @@ describe('PGP Crypto Api unit tests', function() {
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;

@ -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;

Loading…
Cancel
Save