diff --git a/js/app/controllers/vault.js b/js/app/controllers/vault.js index 3ff4d45f..494ae653 100644 --- a/js/app/controllers/vault.js +++ b/js/app/controllers/vault.js @@ -8,24 +8,24 @@ * Controller of the passmanApp */ angular.module('passmanApp') - .controller('VaultCtrl', ['$scope', 'VaultService', 'SettingsService', 'CredentialService', '$location', function ($scope, VaultService, SettingsService, CredentialService, $location) { + .controller('VaultCtrl', ['$scope', 'VaultService', 'SettingsService', 'CredentialService', '$location', 'ShareService', 'EncryptService', function ($scope, VaultService, SettingsService, CredentialService, $location, ShareService, EncryptService) { VaultService.getVaults().then(function (vaults) { $scope.vaults = vaults; - if(SettingsService.getSetting('defaultVault') != null){ + if (SettingsService.getSetting('defaultVault') != null) { var default_vault = SettingsService.getSetting('defaultVault'); /** * Using a native for loop for preformance reasons. * More info see http://stackoverflow.com/questions/13843972/angular-js-break-foreach */ - for(var i = 0; i < vaults.length; i++){ + for (var i = 0; i < vaults.length; i++) { var vault = vaults[i]; - if(vault.guid == default_vault.guid){ + if (vault.guid == default_vault.guid) { $scope.default_vault = true; $scope.list_selected_vault = vault; SettingsService.setSetting('defaultVault', vault); - if(SettingsService.getSetting('defaultVaultPass') != ''){ - $location.path('/vault/'+ vault.vault_id); + if (SettingsService.getSetting('defaultVaultPass') != '') { + $location.path('/vault/' + vault.vault_id); } break; } @@ -38,22 +38,22 @@ angular.module('passmanApp') $scope.remember_vault_password = false; $scope.list_selected_vault = false; - $scope.toggleDefaultVault = function(){ + $scope.toggleDefaultVault = function () { $scope.default_vault = !$scope.default_vault; - if($scope.default_vault == true){ + if ($scope.default_vault == true) { SettingsService.setSetting('defaultVault', $scope.list_selected_vault); } else { SettingsService.setSetting('defaultVault', null); } }; - $scope.toggleRememberPassword = function(){ + $scope.toggleRememberPassword = function () { $scope.remember_vault_password = !$scope.remember_vault_password; - if($scope.remember_vault_password){ + if ($scope.remember_vault_password) { SettingsService.setSetting('defaultVault', $scope.list_selected_vault); $scope.default_vault = true; } - if($scope.remember_vault_password != true){ + if ($scope.remember_vault_password != true) { SettingsService.setSetting('defaultVault', null); } }; @@ -64,40 +64,55 @@ angular.module('passmanApp') $scope.error = false; }; - $scope.selectVault = function(vault){ + $scope.selectVault = function (vault) { $scope.list_selected_vault = vault; }; - - $scope.newVault = function(){ + $scope.sharing_keys= {}; + $scope.newVault = function () { $scope.creating_vault = true; + var _vault = { + + }; + var key_size = 1024; + ShareService.generateRSAKeys(key_size, function (progress) { + var p = progress > 0 ? 2 : 1; + $scope.$apply(); + $scope.creating_keys = 'Generating sharing keys (' + p + ' / 2)'; + }, function (kp) { + var pem = ShareService.rsaKeyPairToPEM(kp); + $scope.creating_keys = false; + $scope.sharing_keys.private_sharing_key = pem.privateKey; + $scope.sharing_keys.public_sharing_key = pem.publicKey; + }); + }; var _loginToVault = function (vault, vault_key) { - var _vault = angular.copy(vault) + var _vault = angular.copy(vault); _vault.vaultKey = angular.copy(vault_key); VaultService.setActiveVault(_vault); - $location.path('/vault/'+ vault.vault_id); - } - + $location.path('/vault/' + vault.vault_id); + }; + $scope.vaultDecryptionKey = ''; $scope.loginToVault = function (vault, vault_key) { $scope.error = false; - var _vault = angular.copy(vault) + var _vault = angular.copy(vault); _vault.vaultKey = angular.copy(vault_key); VaultService.setActiveVault(_vault); - VaultService.getVault(vault).then(function(credentials){ - for(var i = 0; i < credentials.length; i++){ + VaultService.getVault(vault).then(function (credentials) { + for (var i = 0; i < credentials.length; i++) { var credential = credentials[i]; - if(credential.hidden = true){ + if (credential.hidden = true) { try { var c = CredentialService.decryptCredential(credential); - if(c.password === 'lorum ipsum'){ - if($scope.remember_vault_password ){ + if (c.password === 'lorum ipsum') { + if ($scope.remember_vault_password) { SettingsService.setSetting('defaultVaultPass', vault_key); } _loginToVault(vault, vault_key); } - } catch (e){ + } catch (e) { $scope.error = 'Incorrect vault password!' } break; @@ -106,23 +121,30 @@ angular.module('passmanApp') }) }; - $scope.createVault = function(vault_name, vault_key, vault_key2){ - if(vault_key != vault_key2){ + + $scope.createVault = function (vault_name, vault_key, vault_key2) { + if (vault_key != vault_key2) { $scope.error = 'Passwords do not match'; return; } VaultService.createVault(vault_name).then(function (vault) { + $scope.creating_vault_msg = 'Creating vault..' $scope.vaults.push(vault); var _vault = angular.copy(vault); _vault.vaultKey = angular.copy(vault_key); VaultService.setActiveVault(_vault); var test_credential = CredentialService.newCredential(); - test_credential.label = 'Test key for vault '+ vault_name; + test_credential.label = 'Test key for vault ' + vault_name; test_credential.hidden = true; test_credential.vault_id = vault.vault_id; test_credential.password = 'lorum ipsum'; CredentialService.createCredential(test_credential).then(function (result) { - _loginToVault(vault, vault_key); + _vault.public_sharing_key = angular.copy($scope.sharing_keys.public_sharing_key); + _vault.private_sharing_key = EncryptService.encryptString(angular.copy($scope.sharing_keys.private_sharing_key)); + VaultService.updateSharingKeys(_vault).then(function (result) { + VaultService.setActiveVault(_vault); + _loginToVault(vault, vault_key); + }) }) }); }; diff --git a/js/templates.js b/js/templates.js index fbf0c61b..e0a7370e 100644 --- a/js/templates.js +++ b/js/templates.js @@ -113,5 +113,5 @@ angular.module('views/show_vault.html', []).run(['$templateCache', function($tem angular.module('views/vaults.html', []).run(['$templateCache', function($templateCache) { 'use strict'; $templateCache.put('views/vaults.html', - '
  • + Create a new vault
  • {{vault.name}}
    Created: {{vault.created * 1000 | date:\'dd-MM-yyyy @ HH:mm:ss\'}} | Last accessed: {{vault.last_access * 1000 | date:\'dd-MM-yyyy @ HH:mm:ss\'}} Never
  • No vaults found, why not create one?
  • Go back to vaults
'); + '
  • + Create a new vault
  • {{vault.name}}
    Created: {{vault.created * 1000 | date:\'dd-MM-yyyy @ HH:mm:ss\'}} | Last accessed: {{vault.last_access * 1000 | date:\'dd-MM-yyyy @ HH:mm:ss\'}} Never
  • No vaults found, why not create one?
  • Go back to vaults
'); }]); diff --git a/templates/views/vaults.html b/templates/views/vaults.html index 2bb504fc..2de1a4d3 100644 --- a/templates/views/vaults.html +++ b/templates/views/vaults.html @@ -20,7 +20,9 @@ -
  • No vaults found, why not create one?
  • +
  • No vaults found, why not create + one? +
  • @@ -47,8 +49,16 @@
    -
    - Create vault +
    + Create vault + +
    +
    + + + {{creating_keys}} +
    Cancel @@ -81,18 +91,22 @@
    -
    +
    Decrypt vault