From 085e4cc7f33f5013f2ab501a16efb7b8f92f4b32 Mon Sep 17 00:00:00 2001 From: Marcos Zuriaga Date: Sun, 25 Sep 2016 20:19:58 +0200 Subject: [PATCH 1/2] Asynchronous key generation and status indication --- js/app/controllers/share_settings.js | 40 ++++++++++--------- js/app/services/shareservice.js | 30 +++++++++----- js/templates.js | 2 +- .../partials/forms/settings/sharing.html | 3 +- 4 files changed, 45 insertions(+), 30 deletions(-) diff --git a/js/app/controllers/share_settings.js b/js/app/controllers/share_settings.js index b0b016be..689df1ce 100644 --- a/js/app/controllers/share_settings.js +++ b/js/app/controllers/share_settings.js @@ -5,24 +5,28 @@ angular.module('passmanApp') .controller('SharingSettingsCtrl', ['$scope', 'VaultService', 'CredentialService', 'SettingsService', '$location', '$routeParams', 'ShareService', function ($scope, VaultService, CredentialService, SettingsService, $location, $routeParams, ShareService) { $scope.active_vault = VaultService.getActiveVault(); + $scope.progress = 1; + $scope.generating = false; $scope.generateKeys = function (length) { - // var rsa = ShareService.rsaKeyPairToPEM(ShareService.generateRSAKeys(length)); - ShareService.generateRSAKeys(length, function(progress){ - console.log(progress); - }, function(kp){ - console.log(kp); - var pem = ShareService.rsaKeyPairToPEM(kp) - $scope.active_vault.private_sharing_key = pem.privateKey; - $scope.active_vault.public_sharing_key = pem.publicKey; - VaultService.updateSharingKeys($scope.active_vault).then(function (result) { - console.log('done') - }) - }); - // console.log(rsa); - // $scope.active_vault.private_sharing_key = rsa.privateKey; - // $scope.active_vault.public_sharing_key = rsa.publicKey; - // console.log(ShareService.rsaPublicKeyFromPEM(rsa.publicKey)); - // console.log(ShareService.rsaPrivateKeyFromPEM(rsa.privateKey)); - } + $scope.progress = 1; + $scope.generating = true; + + ShareService.generateRSAKeys(length, function(progress){ + $scope.progress = progress > 0 ? 2:1; + $scope.$apply(); + console.log($scope.progress); + }, function(kp){ + $scope.generating = false; + + var pem = ShareService.rsaKeyPairToPEM(kp) + + $scope.active_vault.private_sharing_key = pem.privateKey; + $scope.active_vault.public_sharing_key = pem.publicKey; + + VaultService.updateSharingKeys($scope.active_vault).then(function (result) { + console.log('done') + }) + }); + } }]); \ No newline at end of file diff --git a/js/app/services/shareservice.js b/js/app/services/shareservice.js index c62822d5..6fb1f73a 100644 --- a/js/app/services/shareservice.js +++ b/js/app/services/shareservice.js @@ -28,22 +28,32 @@ angular.module('passmanApp') var step = function() { // run for 100 ms if(!forge.pki.rsa.stepKeyPairGenerationState(state, 100)) { - console.log(state); - console.log({ - // 'data_length': state.n.data.length, - 'bits' : state.bits, - 'pBits': state.pBits, - 'qBits': state.qBits - }); + // console.log(state); + if (state.p !== null) { + progress(50); + } + else { + progress(0); + } + + // console.log({ + // // 'data_length': state.n.data.length, + // 'bits' : state.bits, + // 'num' : state.num, + // 'numBitLength' : state.num !== null ? state.num.bitLength() : null, + // 'pBitLength' : state.p !== null ? state.p.bitLength() : null, + // 'qBitLength' : state.q !== null ? state.q.bitLength() : null, + // 'pqState' : state.pqState, + // 'pBits': state.pBits, + // 'qBits': state.qBits + // }); setTimeout(step, 1); } else { - // done, turn off progress indicator, use state.keys callback(state.keys); } }; - // turn on progress indicator, schedule generation to run - setTimeout(step); + setTimeout(step, 100); }, rsaKeyPairToPEM: function(keypair){ return { diff --git a/js/templates.js b/js/templates.js index 1b1e5b6e..ac0a8f17 100644 --- a/js/templates.js +++ b/js/templates.js @@ -63,7 +63,7 @@ angular.module('views/partials/forms/settings/import.html', []).run(['$templateC angular.module('views/partials/forms/settings/sharing.html', []).run(['$templateCache', function($templateCache) { 'use strict'; $templateCache.put('views/partials/forms/settings/sharing.html', - '
'); + '
'); }]); angular.module('views/partials/forms/settings/tool.html', []).run(['$templateCache', function($templateCache) { diff --git a/templates/views/partials/forms/settings/sharing.html b/templates/views/partials/forms/settings/sharing.html index be747c6a..88728811 100644 --- a/templates/views/partials/forms/settings/sharing.html +++ b/templates/views/partials/forms/settings/sharing.html @@ -19,7 +19,8 @@ - + + From c52cf5ee7537e28ea5d1b9c4ada641691faa8d86 Mon Sep 17 00:00:00 2001 From: Marcos Zuriaga Date: Sun, 25 Sep 2016 20:31:01 +0200 Subject: [PATCH 2/2] Code cleanup --- js/app/services/shareservice.js | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/js/app/services/shareservice.js b/js/app/services/shareservice.js index 6fb1f73a..73b22737 100644 --- a/js/app/services/shareservice.js +++ b/js/app/services/shareservice.js @@ -22,8 +22,6 @@ angular.module('passmanApp') }); }, generateRSAKeys: function(key_length, progress, callback){ - // return forge.pki.rsa.generateKeyPair(key_length); - var state = forge.pki.rsa.createKeyPairGenerationState(key_length, 0x10001); var step = function() { // run for 100 ms @@ -35,18 +33,6 @@ angular.module('passmanApp') else { progress(0); } - - // console.log({ - // // 'data_length': state.n.data.length, - // 'bits' : state.bits, - // 'num' : state.num, - // 'numBitLength' : state.num !== null ? state.num.bitLength() : null, - // 'pBitLength' : state.p !== null ? state.p.bitLength() : null, - // 'qBitLength' : state.q !== null ? state.q.bitLength() : null, - // 'pqState' : state.pqState, - // 'pBits': state.pBits, - // 'qBits': state.qBits - // }); setTimeout(step, 1); } else {