generate enc key on registration

This commit is contained in:
Kyle Spearrin 2017-05-31 11:05:52 -04:00
parent 9aa2014e85
commit 3845c55155
3 changed files with 20 additions and 5 deletions

View File

@ -42,13 +42,15 @@ angular
var email = $scope.model.email.toLowerCase(); var email = $scope.model.email.toLowerCase();
var key = cryptoService.makeKey($scope.model.masterPassword, email); var key = cryptoService.makeKey($scope.model.masterPassword, email);
var encKey = cryptoService.makeEncKey(key);
$scope.registerPromise = cryptoService.makeKeyPair(key).then(function (result) { $scope.registerPromise = cryptoService.makeKeyPair(encKey.encKey).then(function (result) {
var request = { var request = {
name: $scope.model.name, name: $scope.model.name,
email: email, email: email,
masterPasswordHash: cryptoService.hashPassword($scope.model.masterPassword, key), masterPasswordHash: cryptoService.hashPassword($scope.model.masterPassword, key),
masterPasswordHint: $scope.model.masterPasswordHint, masterPasswordHint: $scope.model.masterPasswordHint,
key: encKey.encKeyEnc,
keys: { keys: {
publicKey: result.publicKey, publicKey: result.publicKey,
encryptedPrivateKey: result.privateKeyEnc encryptedPrivateKey: result.privateKeyEnc

View File

@ -40,18 +40,18 @@ angular
} }
if (response.PrivateKey) { if (response.PrivateKey) {
cryptoService.setPrivateKey(response.PrivateKey, key); cryptoService.setPrivateKey(response.PrivateKey);
return true; return true;
} }
else { else {
return cryptoService.makeKeyPair(key); return cryptoService.makeKeyPair();
} }
}).then(function (keyResults) { }).then(function (keyResults) {
if (keyResults === true) { if (keyResults === true) {
return; return;
} }
cryptoService.setPrivateKey(keyResults.privateKeyEnc, key); cryptoService.setPrivateKey(keyResults.privateKeyEnc);
return apiService.accounts.putKeys({ return apiService.accounts.putKeys({
publicKey: keyResults.publicKey, publicKey: keyResults.publicKey,
encryptedPrivateKey: keyResults.privateKeyEnc encryptedPrivateKey: keyResults.privateKeyEnc

View File

@ -57,7 +57,7 @@ angular
setKey = true; setKey = true;
} }
catch (e) { catch (e) {
console.log('Cannot set org key ' + i + '. Decryption failed.'); console.log('Cannot set org key for ' + orgId + '. Decryption failed.');
} }
} }
} }
@ -236,6 +236,19 @@ angular
return new SymmetricCryptoKey(keyBytes); return new SymmetricCryptoKey(keyBytes);
}; };
_service.makeEncKey = function (key) {
if (!key) {
throw 'Invalid parameters.';
}
var encKey = forge.random.getBytesSync(512 / 8);
var encKeyEnc = _service.encrypt(encKey, key, 'raw');
return {
encKey: new SymmetricCryptoKey(encKey),
encKeyEnc: encKeyEnc
};
};
_service.makeKeyPair = function (key) { _service.makeKeyPair = function (key) {
var deferred = $q.defer(); var deferred = $q.defer();