generate keypair on registration
This commit is contained in:
parent
24862f31b3
commit
086d924f06
|
@ -28,16 +28,27 @@ 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 request = {
|
cryptoService.makeKeyPair(key, function (publicKey, privateKeyEnc, errors) {
|
||||||
name: $scope.model.name,
|
if (errors) {
|
||||||
email: email,
|
validationService.addError(form, null, 'Problem generating keys.', true);
|
||||||
masterPasswordHash: cryptoService.hashPassword($scope.model.masterPassword, key),
|
return;
|
||||||
masterPasswordHint: $scope.model.masterPasswordHint
|
}
|
||||||
};
|
|
||||||
|
|
||||||
$scope.registerPromise = apiService.accounts.register(request, function () {
|
var request = {
|
||||||
$scope.success = true;
|
name: $scope.model.name,
|
||||||
$analytics.eventTrack('Registered');
|
email: email,
|
||||||
}).$promise;
|
masterPasswordHash: cryptoService.hashPassword($scope.model.masterPassword, key),
|
||||||
|
masterPasswordHint: $scope.model.masterPasswordHint,
|
||||||
|
keys: {
|
||||||
|
publicKey: publicKey,
|
||||||
|
encryptedPrivateKey: privateKeyEnc
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
$scope.registerPromise = apiService.accounts.register(request, function () {
|
||||||
|
$scope.success = true;
|
||||||
|
$analytics.eventTrack('Registered');
|
||||||
|
}).$promise;
|
||||||
|
});
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
|
@ -90,7 +90,7 @@ angular
|
||||||
return key;
|
return key;
|
||||||
};
|
};
|
||||||
|
|
||||||
_service.makeKeyPair = function (callback) {
|
_service.makeKeyPair = function (key, callback) {
|
||||||
forge.pki.rsa.generateKeyPair({ bits: 2048, workers: 2 }, function (error, keypair) {
|
forge.pki.rsa.generateKeyPair({ bits: 2048, workers: 2 }, function (error, keypair) {
|
||||||
if (error) {
|
if (error) {
|
||||||
callback(null, null, error);
|
callback(null, null, error);
|
||||||
|
@ -99,11 +99,12 @@ angular
|
||||||
|
|
||||||
var privateKey = forge.pki.privateKeyToAsn1(keypair.privateKey);
|
var privateKey = forge.pki.privateKeyToAsn1(keypair.privateKey);
|
||||||
var privateKeyBytes = forge.asn1.toDer(privateKey).getBytes();
|
var privateKeyBytes = forge.asn1.toDer(privateKey).getBytes();
|
||||||
|
var privateKeyEnc = _service.encrypt(privateKeyBytes, key, 'raw');
|
||||||
|
|
||||||
var publicKey = forge.pki.publicKeyToAsn1(keypair.publicKey);
|
var publicKey = forge.pki.publicKeyToAsn1(keypair.publicKey);
|
||||||
var publicKeyBytes = forge.asn1.toDer(publicKey).getBytes();
|
var publicKeyBytes = forge.asn1.toDer(publicKey).getBytes();
|
||||||
|
|
||||||
callback(privateKeyBytes, publicKeyBytes, null);
|
callback(forge.util.encode64(publicKeyBytes), privateKeyEnc, null);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue