1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-15 15:53:27 +00:00

promisify makekeypair and generate keys on login

This commit is contained in:
Kyle Spearrin
2017-04-13 18:18:32 -04:00
parent 2228263b9f
commit e4ffdf6815
4 changed files with 49 additions and 20 deletions

View File

@@ -1,7 +1,7 @@
angular
.module('bit.services')
.factory('cryptoService', function ($sessionStorage, constants) {
.factory('cryptoService', function ($sessionStorage, constants, $q) {
var _service = {},
_key,
_b64Key,
@@ -220,23 +220,30 @@ angular
return key;
};
_service.makeKeyPair = function (key, callback) {
_service.makeKeyPair = function (key) {
var deferred = $q.defer();
forge.pki.rsa.generateKeyPair({ bits: 2048, workers: 2 }, function (error, keypair) {
if (error) {
callback(null, null, error);
deferred.reject(error);
return;
}
var privateKeyAsn1 = forge.pki.privateKeyToAsn1(keypair.privateKey);
var privateKeyPkcs8 = forge.pki.wrapRsaPrivateKey(privateKeyAsn1);
var privateKeyBytes = forge.asn1.toDer(privateKeyPkcs8).getBytes();
var privateKeyEncBytes = _service.encrypt(privateKeyBytes, key, 'raw');
var privateKeyEncCt = _service.encrypt(privateKeyBytes, key, 'raw');
var publicKeyAsn1 = forge.pki.publicKeyToAsn1(keypair.publicKey);
var publicKeyBytes = forge.asn1.toDer(publicKeyAsn1).getBytes();
callback(forge.util.encode64(publicKeyBytes), privateKeyEncBytes, null);
deferred.resolve({
publicKey: forge.util.encode64(publicKeyBytes),
privateKeyEnc: privateKeyEncCt
});
});
return deferred.promise;
};
_service.makeShareKey = function () {