From 0ff6065f4b600651ef82aeea0b7078aa55cf21ae Mon Sep 17 00:00:00 2001 From: brantje Date: Fri, 30 Sep 2016 20:43:20 +0200 Subject: [PATCH 1/6] Implement a challenge password --- controller/vaultcontroller.php | 23 +++++++++++++++++++++-- js/app/controllers/vault.js | 23 ++++++++++++----------- lib/Db/CredentialMapper.php | 6 ++++++ lib/Db/Vault.php | 4 ++++ lib/Service/CredentialService.php | 4 ++++ 5 files changed, 47 insertions(+), 13 deletions(-) diff --git a/controller/vaultcontroller.php b/controller/vaultcontroller.php index d6009b18..c908f5c0 100644 --- a/controller/vaultcontroller.php +++ b/controller/vaultcontroller.php @@ -38,9 +38,28 @@ class VaultController extends ApiController { * @NoAdminRequired */ public function listVaults() { - + $result = array(); $vaults = $this->vaultService->getByUser($this->userId); - return new JSONResponse($vaults); + + $protected_credential_fields = array('getDescription','getEmail','getUsername','getPassword'); + + foreach($vaults as $vault){ + $credential = $this->credentialService->getRandomCredentialByVaultId($vault->getId(), $this->userId); + $secret_field = $protected_credential_fields[array_rand($protected_credential_fields)]; + $challenge_password = $credential->{$secret_field}(); + $vault = array( + 'vault_id' => $vault->getId(), + 'guid' => $vault->getGuid(), + 'name' => $vault->getName(), + 'created' => $vault->getCreated(), + 'public_sharing_key' => $vault->getPublicSharingKey(), + 'last_access' => $vault->getlastAccess(), + 'challenge_password' => $challenge_password + ); + array_push($result, $vault); + } + + return new JSONResponse($result); } /** diff --git a/js/app/controllers/vault.js b/js/app/controllers/vault.js index 2959ce11..be1f9cfb 100644 --- a/js/app/controllers/vault.js +++ b/js/app/controllers/vault.js @@ -101,19 +101,20 @@ angular.module('passmanApp') _vault.vaultKey = angular.copy(vault_key); VaultService.setActiveVault(_vault); - VaultService.getVault(vault).then(function (vault) { - var credential = vault.credentials[0]; - try { - var c = CredentialService.decryptCredential(credential); - if ($scope.remember_vault_password) { - SettingsService.setSetting('defaultVaultPass', vault_key); - } - _loginToVault(vault, vault_key); - } catch (e) { - $scope.error = 'Incorrect vault password!' + + var challenge_password = vault.challenge_password; + try { + var c = EncryptService.decryptString(challenge_password); + if ($scope.remember_vault_password) { + SettingsService.setSetting('defaultVaultPass', vault_key); } - }) + _loginToVault(vault, vault_key); + + } catch (e) { + $scope.error = 'Incorrect vault password!' + } + }; diff --git a/lib/Db/CredentialMapper.php b/lib/Db/CredentialMapper.php index 519e7301..f60cffdf 100644 --- a/lib/Db/CredentialMapper.php +++ b/lib/Db/CredentialMapper.php @@ -32,6 +32,12 @@ class CredentialMapper extends Mapper { return $this->findEntities($sql, [$user_id, $vault_id]); } + public function getRandomCredentialByVaultId($vault_id, $user_id) { + $sql = 'SELECT * FROM `*PREFIX*passman_credentials` ' . + 'WHERE `user_id` = ? and vault_id = ? ORDER BY RAND() LIMIT 1'; + return $this->findEntities($sql, [$user_id, $vault_id]); + } + public function getExpiredCredentials($timestamp){ $sql = 'SELECT * FROM `*PREFIX*passman_credentials` ' . 'WHERE `expire_time` > 0 AND `expire_time` < ?'; diff --git a/lib/Db/Vault.php b/lib/Db/Vault.php index c840cdea..d3ff393f 100644 --- a/lib/Db/Vault.php +++ b/lib/Db/Vault.php @@ -33,6 +33,9 @@ use \OCP\AppFramework\Db\Entity; * @method integer getSharingKeysGenerated() * @method void setVaultSettings(integer $value) * @method integer getVaultSettings() + * @method void setVaultPass(string $value) + * @method string getVaultPass() + */ @@ -49,6 +52,7 @@ class Vault extends Entity implements \JsonSerializable{ protected $privateSharingKey; protected $sharingKeysGenerated; protected $vaultSettings; + protected $vaultPass; public function __construct() { // add types in constructor diff --git a/lib/Service/CredentialService.php b/lib/Service/CredentialService.php index 56e1239b..9dbf8f33 100644 --- a/lib/Service/CredentialService.php +++ b/lib/Service/CredentialService.php @@ -44,6 +44,10 @@ class CredentialService { return $this->credentialMapper->getCredentialsByVaultId($vault_id, $user_id); } + public function getRandomCredentialByVaultId($vault_id, $user_id) { + return array_pop($this->credentialMapper->getRandomCredentialByVaultId($vault_id, $user_id)); + } + public function getExpiredCredentials($timestamp) { return $this->credentialMapper->getExpiredCredentials($timestamp); } From 9dd4a86ec4fba8e6cfc23bb6488a06ce918881a6 Mon Sep 17 00:00:00 2001 From: brantje Date: Fri, 30 Sep 2016 20:46:06 +0200 Subject: [PATCH 2/6] Remove temp var --- js/app/controllers/vault.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/js/app/controllers/vault.js b/js/app/controllers/vault.js index be1f9cfb..2f64271c 100644 --- a/js/app/controllers/vault.js +++ b/js/app/controllers/vault.js @@ -101,11 +101,8 @@ angular.module('passmanApp') _vault.vaultKey = angular.copy(vault_key); VaultService.setActiveVault(_vault); - - - var challenge_password = vault.challenge_password; try { - var c = EncryptService.decryptString(challenge_password); + var c = EncryptService.decryptString(vault.challenge_password); if ($scope.remember_vault_password) { SettingsService.setSetting('defaultVaultPass', vault_key); } From c94870e1c38317014dfb10af77e4e4e5e3aef477 Mon Sep 17 00:00:00 2001 From: brantje Date: Fri, 30 Sep 2016 20:49:35 +0200 Subject: [PATCH 3/6] Clean up code --- controller/vaultcontroller.php | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/controller/vaultcontroller.php b/controller/vaultcontroller.php index c908f5c0..191d1d9a 100644 --- a/controller/vaultcontroller.php +++ b/controller/vaultcontroller.php @@ -46,17 +46,15 @@ class VaultController extends ApiController { foreach($vaults as $vault){ $credential = $this->credentialService->getRandomCredentialByVaultId($vault->getId(), $this->userId); $secret_field = $protected_credential_fields[array_rand($protected_credential_fields)]; - $challenge_password = $credential->{$secret_field}(); - $vault = array( + array_push($result, array( 'vault_id' => $vault->getId(), 'guid' => $vault->getGuid(), 'name' => $vault->getName(), 'created' => $vault->getCreated(), 'public_sharing_key' => $vault->getPublicSharingKey(), 'last_access' => $vault->getlastAccess(), - 'challenge_password' => $challenge_password - ); - array_push($result, $vault); + 'challenge_password' => $credential->{$secret_field}() + )); } return new JSONResponse($result); From 3af9e39488b034c78ae6a7d25b1501d781ed8126 Mon Sep 17 00:00:00 2001 From: brantje Date: Fri, 30 Sep 2016 20:56:17 +0200 Subject: [PATCH 4/6] Clean up code --- lib/Db/Vault.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/lib/Db/Vault.php b/lib/Db/Vault.php index d3ff393f..61b00ae6 100644 --- a/lib/Db/Vault.php +++ b/lib/Db/Vault.php @@ -33,9 +33,6 @@ use \OCP\AppFramework\Db\Entity; * @method integer getSharingKeysGenerated() * @method void setVaultSettings(integer $value) * @method integer getVaultSettings() - * @method void setVaultPass(string $value) - * @method string getVaultPass() - */ @@ -52,8 +49,7 @@ class Vault extends Entity implements \JsonSerializable{ protected $privateSharingKey; protected $sharingKeysGenerated; protected $vaultSettings; - protected $vaultPass; - + public function __construct() { // add types in constructor $this->addType('created', 'integer'); From ae49c9e14962f20b81ba68074aa84e7c11a64e3a Mon Sep 17 00:00:00 2001 From: brantje Date: Fri, 30 Sep 2016 21:15:28 +0200 Subject: [PATCH 5/6] Implement renaming vault --- js/app/controllers/settings.js | 7 ++++++- js/app/services/vaultservice.js | 5 +++-- js/templates.js | 2 +- .../views/partials/forms/settings/general_settings.html | 6 ++++++ 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/js/app/controllers/settings.js b/js/app/controllers/settings.js index c0849854..f1533f77 100644 --- a/js/app/controllers/settings.js +++ b/js/app/controllers/settings.js @@ -11,6 +11,7 @@ angular.module('passmanApp') .controller('SettingsCtrl', ['$scope', '$rootScope', 'SettingsService', 'VaultService', 'CredentialService', '$location', '$routeParams', '$http', 'EncryptService','NotificationService', function ($scope, $rootScope, SettingsService, VaultService, CredentialService, $location, $routeParams, $http, EncryptService, NotificationService) { $scope.vault_settings = {}; + $scope.new_vault_name = ''; $scope.active_vault = VaultService.getActiveVault(); if (!SettingsService.getSetting('defaultVault') || !SettingsService.getSetting('defaultVaultPass')) { if (!$scope.active_vault) { @@ -35,17 +36,21 @@ angular.module('passmanApp') 'avoidAmbiguousCharacters': false, 'requireEveryCharType': true, 'generateOnCreate': true - }) + }); + $scope.new_vault_name = angular.copy($scope.active_vault.name); }) } } $scope.saveVaultSettings = function () { + console.log($scope.new_vault_name); var _vault = $scope.active_vault; + _vault.name = $scope.new_vault_name; _vault.vault_settings = angular.copy($scope.vault_settings); VaultService.updateVault(_vault).then(function () { VaultService.setActiveVault(_vault); + $scope.active_vault.name = angular.copy(_vault.name); NotificationService.showNotification('Settings saved', 5000); }); }; diff --git a/js/app/services/vaultservice.js b/js/app/services/vaultservice.js index aa1408b3..37e7e772 100644 --- a/js/app/services/vaultservice.js +++ b/js/app/services/vaultservice.js @@ -73,8 +73,9 @@ angular.module('passmanApp') }, updateVault: function (vault) { var _vault = angular.copy(vault); - delete vault.defaultVaultPass; - delete vault.defaultVault; + delete _vault.defaultVaultPass; + delete _vault.defaultVault; + delete _vault.vaultKey; _vault.vault_settings = window.btoa(JSON.stringify(_vault.vault_settings)) var queryUrl = OC.generateUrl('apps/passman/api/v2/vaults/' + _vault.vault_id); return $http.patch(queryUrl, _vault).then(function (response) { diff --git a/js/templates.js b/js/templates.js index 606ad011..aae95f78 100644 --- a/js/templates.js +++ b/js/templates.js @@ -51,7 +51,7 @@ angular.module('views/partials/forms/settings/export.html', []).run(['$templateC angular.module('views/partials/forms/settings/general_settings.html', []).run(['$templateCache', function($templateCache) { 'use strict'; $templateCache.put('views/partials/forms/settings/general_settings.html', - '

Change vault key

About passman

Version: {{passman_version}}
Bla bla about passman, changelog.
Donate to support development

'); + '

Rename vault

Change vault key

About passman

Version: {{passman_version}}
Bla bla about passman, changelog.
Donate to support development

'); }]); angular.module('views/partials/forms/settings/import.html', []).run(['$templateCache', function($templateCache) { diff --git a/templates/views/partials/forms/settings/general_settings.html b/templates/views/partials/forms/settings/general_settings.html index 0c3556d5..5522324d 100644 --- a/templates/views/partials/forms/settings/general_settings.html +++ b/templates/views/partials/forms/settings/general_settings.html @@ -1,5 +1,11 @@
+

Rename vault

+ + + + +

Change vault key

From 4f1dd1da882b451173797430c560f2f286f929ed Mon Sep 17 00:00:00 2001 From: brantje Date: Fri, 30 Sep 2016 21:17:34 +0200 Subject: [PATCH 6/6] Clean up --- js/app/controllers/settings.js | 1 - 1 file changed, 1 deletion(-) diff --git a/js/app/controllers/settings.js b/js/app/controllers/settings.js index f1533f77..5ceeff83 100644 --- a/js/app/controllers/settings.js +++ b/js/app/controllers/settings.js @@ -44,7 +44,6 @@ angular.module('passmanApp') $scope.saveVaultSettings = function () { - console.log($scope.new_vault_name); var _vault = $scope.active_vault; _vault.name = $scope.new_vault_name; _vault.vault_settings = angular.copy($scope.vault_settings);