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 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 = {
name: $scope.model.name,
email: email,
masterPasswordHash: cryptoService.hashPassword($scope.model.masterPassword, key),
masterPasswordHint: $scope.model.masterPasswordHint,
key: encKey.encKeyEnc,
keys: {
publicKey: result.publicKey,
encryptedPrivateKey: result.privateKeyEnc

View File

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

View File

@ -57,7 +57,7 @@ angular
setKey = true;
}
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);
};
_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) {
var deferred = $q.defer();