2016-09-25 23:46:55 +08:00
|
|
|
/**
|
|
|
|
* Created by wolfi on 25/09/16.
|
|
|
|
*/
|
|
|
|
angular.module('passmanApp')
|
2016-09-26 03:33:04 +08:00
|
|
|
.controller('SharingSettingsCtrl', ['$scope', 'VaultService', 'CredentialService', 'SettingsService', '$location', '$routeParams', 'ShareService', 'EncryptService',
|
|
|
|
function ($scope, VaultService, CredentialService, SettingsService, $location, $routeParams, ShareService, EncryptService) {
|
2016-09-26 20:29:36 +08:00
|
|
|
$scope.active_vault = VaultService.getActiveVault();
|
2016-09-26 20:23:31 +08:00
|
|
|
$scope.sharing_keys = ShareService.getSharingKeys();
|
|
|
|
|
2016-09-26 02:19:58 +08:00
|
|
|
$scope.progress = 1;
|
|
|
|
$scope.generating = false;
|
2016-09-25 23:46:55 +08:00
|
|
|
|
2016-10-02 01:04:05 +08:00
|
|
|
|
|
|
|
|
|
|
|
$scope.available_sizes = [
|
|
|
|
{
|
|
|
|
size: 1024,
|
|
|
|
name: 1024
|
|
|
|
},
|
|
|
|
{
|
|
|
|
size: 2048,
|
|
|
|
name: 2048
|
|
|
|
},
|
|
|
|
{
|
|
|
|
size: 4096,
|
|
|
|
name: 4096
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
$scope.setKeySize = function (size) {
|
|
|
|
for (var i = 0; i < $scope.available_sizes.length; i++) {
|
|
|
|
if ($scope.available_sizes[i].size == size) {
|
|
|
|
$scope.key_size = $scope.available_sizes[i];
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.setKeySize(2048);
|
|
|
|
|
2016-09-26 00:34:33 +08:00
|
|
|
$scope.generateKeys = function (length) {
|
2016-09-26 02:19:58 +08:00
|
|
|
$scope.progress = 1;
|
|
|
|
$scope.generating = true;
|
|
|
|
|
2016-09-26 20:23:31 +08:00
|
|
|
ShareService.generateRSAKeys(length).progress(function(progress){
|
2016-09-26 02:19:58 +08:00
|
|
|
$scope.progress = progress > 0 ? 2:1;
|
2016-10-01 03:51:38 +08:00
|
|
|
$scope.$digest();
|
2016-09-26 20:23:31 +08:00
|
|
|
}).then(function(kp){
|
|
|
|
console.log('stuff done');
|
2016-09-26 02:19:58 +08:00
|
|
|
$scope.generating = false;
|
|
|
|
|
|
|
|
var pem = ShareService.rsaKeyPairToPEM(kp)
|
|
|
|
|
2016-09-26 20:29:36 +08:00
|
|
|
$scope.active_vault.private_sharing_key = EncryptService.encryptString(pem.privateKey);
|
|
|
|
$scope.active_vault.public_sharing_key = pem.publicKey;
|
2016-09-26 03:33:04 +08:00
|
|
|
|
2016-09-26 20:29:36 +08:00
|
|
|
VaultService.updateSharingKeys($scope.active_vault).then(function (result) {
|
2016-09-26 20:23:31 +08:00
|
|
|
$scope.sharing_keys = ShareService.getSharingKeys();
|
2016-09-26 02:19:58 +08:00
|
|
|
})
|
|
|
|
});
|
|
|
|
}
|
2016-09-26 00:34:33 +08:00
|
|
|
}]);
|