mirror of
https://github.com/nextcloud/passman.git
synced 2025-12-18 22:21:00 +08:00
Asynchronous key generation and status indication
This commit is contained in:
parent
60b7da4f8b
commit
be48cd77b8
4 changed files with 45 additions and 30 deletions
|
|
@ -5,24 +5,28 @@ angular.module('passmanApp')
|
||||||
.controller('SharingSettingsCtrl', ['$scope', 'VaultService', 'CredentialService', 'SettingsService', '$location', '$routeParams', 'ShareService',
|
.controller('SharingSettingsCtrl', ['$scope', 'VaultService', 'CredentialService', 'SettingsService', '$location', '$routeParams', 'ShareService',
|
||||||
function ($scope, VaultService, CredentialService, SettingsService, $location, $routeParams, ShareService) {
|
function ($scope, VaultService, CredentialService, SettingsService, $location, $routeParams, ShareService) {
|
||||||
$scope.active_vault = VaultService.getActiveVault();
|
$scope.active_vault = VaultService.getActiveVault();
|
||||||
|
$scope.progress = 1;
|
||||||
|
$scope.generating = false;
|
||||||
|
|
||||||
$scope.generateKeys = function (length) {
|
$scope.generateKeys = function (length) {
|
||||||
// var rsa = ShareService.rsaKeyPairToPEM(ShareService.generateRSAKeys(length));
|
$scope.progress = 1;
|
||||||
|
$scope.generating = true;
|
||||||
|
|
||||||
ShareService.generateRSAKeys(length, function(progress){
|
ShareService.generateRSAKeys(length, function(progress){
|
||||||
console.log(progress);
|
$scope.progress = progress > 0 ? 2:1;
|
||||||
|
$scope.$apply();
|
||||||
|
console.log($scope.progress);
|
||||||
}, function(kp){
|
}, function(kp){
|
||||||
console.log(kp);
|
$scope.generating = false;
|
||||||
|
|
||||||
var pem = ShareService.rsaKeyPairToPEM(kp)
|
var pem = ShareService.rsaKeyPairToPEM(kp)
|
||||||
|
|
||||||
$scope.active_vault.private_sharing_key = pem.privateKey;
|
$scope.active_vault.private_sharing_key = pem.privateKey;
|
||||||
$scope.active_vault.public_sharing_key = pem.publicKey;
|
$scope.active_vault.public_sharing_key = pem.publicKey;
|
||||||
|
|
||||||
VaultService.updateSharingKeys($scope.active_vault).then(function (result) {
|
VaultService.updateSharingKeys($scope.active_vault).then(function (result) {
|
||||||
console.log('done')
|
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));
|
|
||||||
}
|
}
|
||||||
}]);
|
}]);
|
||||||
|
|
@ -28,22 +28,32 @@ angular.module('passmanApp')
|
||||||
var step = function() {
|
var step = function() {
|
||||||
// run for 100 ms
|
// run for 100 ms
|
||||||
if(!forge.pki.rsa.stepKeyPairGenerationState(state, 100)) {
|
if(!forge.pki.rsa.stepKeyPairGenerationState(state, 100)) {
|
||||||
console.log(state);
|
// console.log(state);
|
||||||
console.log({
|
if (state.p !== null) {
|
||||||
// 'data_length': state.n.data.length,
|
progress(50);
|
||||||
'bits' : state.bits,
|
}
|
||||||
'pBits': state.pBits,
|
else {
|
||||||
'qBits': state.qBits
|
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);
|
setTimeout(step, 1);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// done, turn off progress indicator, use state.keys
|
|
||||||
callback(state.keys);
|
callback(state.keys);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
// turn on progress indicator, schedule generation to run
|
setTimeout(step, 100);
|
||||||
setTimeout(step);
|
|
||||||
},
|
},
|
||||||
rsaKeyPairToPEM: function(keypair){
|
rsaKeyPairToPEM: function(keypair){
|
||||||
return {
|
return {
|
||||||
|
|
|
||||||
|
|
@ -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) {
|
angular.module('views/partials/forms/settings/sharing.html', []).run(['$templateCache', function($templateCache) {
|
||||||
'use strict';
|
'use strict';
|
||||||
$templateCache.put('views/partials/forms/settings/sharing.html',
|
$templateCache.put('views/partials/forms/settings/sharing.html',
|
||||||
'<div ng-controller="SharingSettingsCtrl"><div class="row"><div class="col-md-6"><label>Private Key</label><textarea class="col-md-12">{{active_vault.private_sharing_key}}</textarea></div><div class="col-md-6"><label>Public key</label><textarea class="col-md-12">{{active_vault.public_sharing_key}}</textarea></div></div><div class="row"><div class="col-md-12"><label>Key size<select ng-model="key_size"><option value="512">512</option><option value="1024">1024</option><option value="2048">2048</option><option value="4096">4096</option></select><button ng-click="generateKeys(key_size)" class="btn btn-default">Generate sharing keys</button></label></div></div></div>');
|
'<div ng-controller="SharingSettingsCtrl"><div class="row"><div class="col-md-6"><label>Private Key</label><textarea class="col-md-12">{{active_vault.private_sharing_key}}</textarea></div><div class="col-md-6"><label>Public key</label><textarea class="col-md-12">{{active_vault.public_sharing_key}}</textarea></div></div><div class="row"><div class="col-md-12"><label>Key size<select ng-model="key_size"><option value="512">512</option><option value="1024">1024</option><option value="2048">2048</option><option value="4096">4096</option></select><button ng-if="!generating" ng-click="generateKeys(key_size)">Generate sharing keys</button> <button ng-if="generating"><i class="fa fa-spinner fa-spin"></i> Generating sharing keys step {{progress}}/2</button></label></div></div></div>');
|
||||||
}]);
|
}]);
|
||||||
|
|
||||||
angular.module('views/partials/forms/settings/tool.html', []).run(['$templateCache', function($templateCache) {
|
angular.module('views/partials/forms/settings/tool.html', []).run(['$templateCache', function($templateCache) {
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,8 @@
|
||||||
<option value="2048">2048</option>
|
<option value="2048">2048</option>
|
||||||
<option value="4096">4096</option>
|
<option value="4096">4096</option>
|
||||||
</select>
|
</select>
|
||||||
<button ng-click="generateKeys(key_size)" class="btn btn-default">Generate sharing keys</button>
|
<button ng-if="!generating" ng-click="generateKeys(key_size)">Generate sharing keys</button>
|
||||||
|
<button ng-if="generating"><i class="fa fa-spinner fa-spin"></i> Generating sharing keys step {{progress}}/2</button>
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue