diff --git a/appinfo/routes.php b/appinfo/routes.php index 193de7a1..105ec422 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -52,7 +52,6 @@ return [ ['name' => 'share#getVaultsByUser', 'url' => '/api/v2/sharing/vaults/{user_id}', 'verb' => 'GET'], ['name' => 'share#applyIntermediateShare', 'url' => '/api/v2/sharing/share', 'verb' => 'POST'], ['name' => 'share#savePendingRequest', 'url' => '/api/v2/sharing/save', 'verb' => 'POST'], - ['name' => 'share#unshareCredential', 'url' => '/api/v2/sharing/unshare/{item_guid}', 'verb' => 'DELETE'], ['name' => 'share#getPendingRequests', 'url' => '/api/v2/sharing/pending', 'verb' => 'GET'], ['name' => 'share#deleteShareRequest', 'url' => '/api/v2/sharing/decline/{share_request_id}', 'verb' => 'DELETE'], ['name' => 'share#getVaultItems', 'url' => '/api/v2/sharing/vault/{vault_guid}/get', 'verb' => 'GET'], diff --git a/controller/credentialcontroller.php b/controller/credentialcontroller.php index 64188483..435e58b2 100644 --- a/controller/credentialcontroller.php +++ b/controller/credentialcontroller.php @@ -116,7 +116,7 @@ class CredentialController extends ApiController { 'delete_time' => $delete_time, 'hidden' => $hidden, 'otp' => $otp, - 'shared_key' => ($shared_key) ? $shared_key : null, + 'shared_key' => $shared_key, ); @@ -151,7 +151,7 @@ class CredentialController extends ApiController { } $this->credentialRevisionService->createRevision($storedCredential, $this->userId, $credential_id); - //$credential = $this->credentialService->updateCredential($credential); + $credential = $this->credentialService->updateCredential($credential); return new JSONResponse($credential); } diff --git a/controller/sharecontroller.php b/controller/sharecontroller.php index 4a3d82f9..b0ec1387 100644 --- a/controller/sharecontroller.php +++ b/controller/sharecontroller.php @@ -123,21 +123,6 @@ class ShareController extends ApiController { } - /** - * @NoAdminRequired - */ - public function unshareCredential($item_guid){ - $acl_list = $this->shareService->getCredentialAclList($item_guid); - $request_list = $this->shareService->getShareRequestsByGuid($item_guid); - foreach ($acl_list as $ACL){ - $this->shareService->deleteShareACL($ACL); - } - foreach($request_list as $request){ - $this->shareService->deleteShareRequest($request); - } - return new JSONResponse(array('result' => true)); - } - /** * @NoAdminRequired */ diff --git a/js/app/controllers/credential.js b/js/app/controllers/credential.js index c631a3b3..f2118c10 100644 --- a/js/app/controllers/credential.js +++ b/js/app/controllers/credential.js @@ -32,22 +32,19 @@ angular.module('passmanApp') var getSharedCredentials = function() { ShareService.getCredendialsSharedWithUs($scope.active_vault.guid).then(function (shared_credentials) { - console.log('Shared credentials', shared_credentials); for (var c = 0; c < shared_credentials.length; c++) { - var _shared_credential = angular.copy(shared_credentials[c]); - console.log(_shared_credential) + var _shared_credential = shared_credentials[c]; var decrypted_key = EncryptService.decryptString(_shared_credential.shared_key); - console.log(decrypted_key) try { var _shared_credential_data = ShareService.decryptSharedCredential(_shared_credential.credential_data, decrypted_key); } catch (e){ } if(_shared_credential_data){ - /*delete _shared_credential.credential_data; + delete _shared_credential.credential_data; _shared_credential_data.acl = _shared_credential; _shared_credential_data.tags_raw = _shared_credential_data.tags; - console.log(_shared_credential_data)*/ + console.log(_shared_credential_data) $scope.active_vault.credentials.push(_shared_credential_data); } } @@ -56,7 +53,6 @@ angular.module('passmanApp') var fetchCredentials = function () { VaultService.getVault($scope.active_vault).then(function (vault) { - console.log('Credentials', vault.credentials); var vaultKey = angular.copy($scope.active_vault.vaultKey); $scope.active_vault = vault; $scope.active_vault.vaultKey = vaultKey; @@ -108,7 +104,6 @@ angular.module('passmanApp') console.log('Accepted share request', share_request); var crypted_shared_key = share_request.shared_key; var private_key = EncryptService.decryptString(VaultService.getActiveVault().private_sharing_key); - console.log(private_key); private_key = ShareService.rsaPrivateKeyFromPEM(private_key); crypted_shared_key = private_key.decrypt(forge.util.decode64(crypted_shared_key)); @@ -127,6 +122,7 @@ angular.module('passmanApp') jQuery('.ui-dialog').remove(); getSharedCredentials(); } + console.log(result) }) }; diff --git a/js/app/controllers/share.js b/js/app/controllers/share.js index 4eea9a41..bc0aec32 100644 --- a/js/app/controllers/share.js +++ b/js/app/controllers/share.js @@ -9,7 +9,7 @@ * This file is part of passman, licensed under AGPLv3 */ angular.module('passmanApp') - .controller('ShareCtrl', ['$scope', 'VaultService', 'CredentialService', 'SettingsService', '$location', '$routeParams', 'ShareService', 'NotificationService', function ($scope, VaultService, CredentialService, SettingsService, $location, $routeParams, ShareService, NotificationService) { + .controller('ShareCtrl', ['$scope', 'VaultService', 'CredentialService', 'SettingsService', '$location', '$routeParams', 'ShareService', function ($scope, VaultService, CredentialService, SettingsService, $location, $routeParams, ShareService) { $scope.active_vault = VaultService.getActiveVault(); $scope.tabs = [{ @@ -116,16 +116,6 @@ angular.module('passmanApp') } }; - $scope.unshareCredential = function () { - var _credential = angular.copy($scope.storedCredential); - ShareService.unshareCredential(_credential).then(function (result) { - _credential.shared_key = null; - CredentialService.updateCredential(_credential); - NotificationService.showNotification('Credential unshared!', 5000); - - }); - }; - $scope.applyShare = function(){ $scope.share_settings.cypher_progress.percent = 0; $scope.share_settings.cypher_progress.done = 0; @@ -140,6 +130,7 @@ angular.module('passmanApp') CredentialService.updateCredential(encryptedSharedCredential, true); var list = $scope.share_settings.credentialSharedWithUserAndGroup; + console.log(list); for (var i = 0; i < list.length; i++){ var iterator = i; // Keeps it available inside the promises callback @@ -148,6 +139,7 @@ angular.module('passmanApp') $scope.share_settings.cypher_progress.total += data.length; list[iterator].vaults = data; + console.log(data); var start = new Date().getTime() / 1000; ShareService.cypherRSAStringWithPublicKeyBulkAsync(list[iterator].vaults, key) @@ -157,6 +149,8 @@ angular.module('passmanApp') $scope.$digest(); }) .then(function (result) { + console.log(result); + console.log("Took: " + ((new Date().getTime() / 1000) - start) + "s to cypher the string for user [" + data[0].user_id + "]"); $scope.share_settings.cypher_progress.times.push({ time: ((new Date().getTime() / 1000) - start), user: data[0].user_id diff --git a/js/app/services/credentialservice.js b/js/app/services/credentialservice.js index 359e87bb..f432d529 100644 --- a/js/app/services/credentialservice.js +++ b/js/app/services/credentialservice.js @@ -68,7 +68,10 @@ angular.module('passmanApp') var fieldValue = angular.copy(credential[field]); _credential[field] = EncryptService.encryptString(JSON.stringify(fieldValue)); } + } else { + console.log('Skipping encryption') } + _credential.expire_time = new Date( angular.copy(credential.expire_time) ).getTime() / 1000; var queryUrl = OC.generateUrl('apps/passman/api/v2/credentials/' + credential.credential_id); diff --git a/js/app/services/shareservice.js b/js/app/services/shareservice.js index 2e0c6698..3e3931d7 100644 --- a/js/app/services/shareservice.js +++ b/js/app/services/shareservice.js @@ -68,12 +68,6 @@ angular.module('passmanApp') return response.data; }) }, - unshareCredential: function (credential) { - var queryUrl = OC.generateUrl('apps/passman/api/v2/sharing/unshare/'+ credential.guid); - return $http.delete(queryUrl).then(function (response) { - return response.data; - }) - }, getPublicSharedCredential: function (request, crypted_shared_key) { var queryUrl = OC.generateUrl('apps/passman/api/v2/sharing/public/view'); return $http.get(queryUrl).then(function (response) { @@ -109,21 +103,19 @@ angular.module('passmanApp') for (var i = 0; i < encrypted_fields.length; i++) { var field = encrypted_fields[i]; var fieldValue = angular.copy(_credential[field]); - console.log('Field:', field) - if(fieldValue) { - try { - var field_decrypted_value = EncryptService.decryptString(fieldValue, sharedKey); - } catch (e) { - console.log(e); - throw e - } - try { - _credential[field] = JSON.parse(field_decrypted_value); - } catch (e) { - console.log('Field' + field + ' in ' + _credential.label + ' could not be parsed! Value:' + fieldValue) - throw e - } + try { + var field_decrypted_value = EncryptService.decryptString(fieldValue, sharedKey); + } catch (e){ + console.log(e); + throw e } + try{ + _credential[field] = JSON.parse(field_decrypted_value); + } catch (e){ + console.log('Field' + field + ' in '+ _credential.label +' could not be parsed! Value:'+ fieldValue) + throw e + } + } return _credential; }, diff --git a/js/templates.js b/js/templates.js index bee65a5b..b7d797d9 100644 --- a/js/templates.js +++ b/js/templates.js @@ -107,7 +107,7 @@ angular.module('views/settings.html', []).run(['$templateCache', function($templ angular.module('views/share_credential.html', []).run(['$templateCache', function($templateCache) { 'use strict'; $templateCache.put('views/share_credential.html', - '
'); + '
'); }]); angular.module('views/show_vault.html', []).run(['$templateCache', function($templateCache) { diff --git a/lib/Db/ShareRequestMapper.php b/lib/Db/ShareRequestMapper.php index dc5aa135..ec971987 100644 --- a/lib/Db/ShareRequestMapper.php +++ b/lib/Db/ShareRequestMapper.php @@ -61,9 +61,4 @@ class ShareRequestMapper extends Mapper { $q = "SELECT * FROM *PREFIX*" . self::TABLE_NAME . " WHERE id = ?"; return $this->findEntity($q, [$id]); } - - public function getShareRequestsByGuid($item_guid){ - $q = "SELECT * FROM *PREFIX*" . self::TABLE_NAME . " WHERE item_guid = ?"; - return $this->findEntities($q, [$item_guid]); - } } \ No newline at end of file diff --git a/lib/Db/SharingACLMapper.php b/lib/Db/SharingACLMapper.php index 1d4e67d9..def4ad5b 100644 --- a/lib/Db/SharingACLMapper.php +++ b/lib/Db/SharingACLMapper.php @@ -48,19 +48,4 @@ class SharingACLMapper extends Mapper { $q = "SELECT * FROM ". self::TABLE_NAME ." WHERE user_id = ? AND vault_guid = ?"; return $this->findEntities($q, [$user_id, $vault_id]); } - - /** - * Gets the currently accepted share requests from the given user for the given vault guid - * @param $user_id - * @param $vault_id - * @return SharingACL[] - */ - public function getCredentialAclList($item_guid) { - $q = "SELECT * FROM ". self::TABLE_NAME ." WHERE item_guid = ?"; - return $this->findEntities($q, [$item_guid]); - } - - public function deleteShareACL(SharingACL $ACL){ - return $this->delete($ACL); - } } \ No newline at end of file diff --git a/lib/Service/ShareService.php b/lib/Service/ShareService.php index bc55e5bf..44dd3ed2 100644 --- a/lib/Service/ShareService.php +++ b/lib/Service/ShareService.php @@ -17,116 +17,112 @@ use OCA\Passman\Db\SharingACL; use OCA\Passman\Db\SharingACLMapper; class ShareService { - private $sharingACL; - private $shareRequest; - private $credential; + private $sharingACL; + private $shareRequest; + private $credential; - public function __construct(SharingACLMapper $sharingACL, ShareRequestMapper $shareRequest, CredentialMapper $credentials) { - $this->sharingACL = $sharingACL; - $this->shareRequest = $shareRequest; - $this->credential = $credentials; - } + public function __construct(SharingACLMapper $sharingACL, ShareRequestMapper $shareRequest, CredentialMapper $credentials) { + $this->sharingACL = $sharingACL; + $this->shareRequest = $shareRequest; + $this->credential = $credentials; + } - /** - * Creates requests for all the items on the request array of objects. - * This array must follow this spec: - * user_id: The target user id - * vault_id: The id of the target vault - * guid: The guid of the target vault - * key: The shared key cyphered with the target vault RSA public key - * - * @param $target_item_id string The shared item ID - * @param $target_item_guid string The shared item GUID - * @param $request_array array - * @param $permissions integer Must be created with a bitmask from options on the ShareRequest class - * @return array Array of sharing requests - */ - public function createBulkRequests($target_item_id, $target_item_guid, $request_array, $permissions, $credential_owner) { - $created = (new \DateTime())->getTimestamp(); + /** + * Creates requests for all the items on the request array of objects. + * This array must follow this spec: + * user_id: The target user id + * vault_id: The id of the target vault + * guid: The guid of the target vault + * key: The shared key cyphered with the target vault RSA public key + * @param $target_item_id string The shared item ID + * @param $target_item_guid string The shared item GUID + * @param $request_array array + * @param $permissions integer Must be created with a bitmask from options on the ShareRequest class + * @return array Array of sharing requests + */ + public function createBulkRequests($target_item_id, $target_item_guid, $request_array, $permissions, $credential_owner) { + $created = (new \DateTime())->getTimestamp(); $requests = array(); - foreach ($request_array as $req) { - $t = new ShareRequest(); - $t->setItemId($target_item_id); - $t->setItemGuid($target_item_guid); - $t->setTargetUserId($req['user_id']); - $t->setTargetVaultId($req['vault_id']); - $t->setTargetVaultGuid($req['guid']); - $t->setSharedKey($req['key']); - $t->setPermissions($permissions); - $t->setCreated($created); + foreach ($request_array as $req){ + $t = new ShareRequest(); + $t->setItemId($target_item_id); + $t->setItemGuid($target_item_guid); + $t->setTargetUserId($req['user_id']); + $t->setTargetVaultId($req['vault_id']); + $t->setTargetVaultGuid($req['guid']); + $t->setSharedKey($req['key']); + $t->setPermissions($permissions); + $t->setCreated($created); $t->setFromUserId($credential_owner); array_push($requests, $this->shareRequest->createRequest($t)); - } - return $requests; - } + } + return $requests; + } - /** - * Applies the given share, defaults to no expire - * - * @param $item_guid - * @param $target_vault_guid - * @param $final_shared_key - */ - public function applyShare($item_guid, $target_vault_guid, $final_shared_key) { - $request = $this->shareRequest->getRequestByGuid($item_guid, $target_vault_guid); - $permissions = $request->getPermissions(); + /** + * Applies the given share, defaults to no expire + * @param $item_guid + * @param $target_vault_guid + * @param $final_shared_key + */ + public function applyShare($item_guid, $target_vault_guid, $final_shared_key){ + $request = $this->shareRequest->getRequestByGuid($item_guid, $target_vault_guid); + $permissions = $request->getPermissions(); - $acl = new SharingACL(); - $acl->setItemId($request->getItemId()); - $acl->setItemGuid($request->getItemGuid()); - $acl->setUserId($request->getTargetUserId()); - $acl->setCreated($request->getCreated()); - $acl->setExpire(0); - $acl->setPermissions($permissions); - $acl->setVaultId($request->getTargetVaultId()); - $acl->setVaultGuid($request->getTargetVaultGuid()); - $acl->setSharedKey($final_shared_key); + $acl = new SharingACL(); + $acl->setItemId($request->getItemId()); + $acl->setItemGuid($request->getItemGuid()); + $acl->setUserId($request->getTargetUserId()); + $acl->setCreated($request->getCreated()); + $acl->setExpire(0); + $acl->setPermissions($permissions); + $acl->setVaultId($request->getTargetVaultId()); + $acl->setVaultGuid($request->getTargetVaultGuid()); + $acl->setSharedKey($final_shared_key); - $this->sharingACL->createACLEntry($acl); - $this->shareRequest->cleanItemRequestsForUser($request->getItemId(), $request->getTargetUserId()); - } + $this->sharingACL->createACLEntry($acl); + $this->shareRequest->cleanItemRequestsForUser($request->getItemId(), $request->getTargetUserId()); + } - /** - * Obtains pending requests for the given user ID - * - * @param $user_id - * @return \OCA\Passman\Db\ShareRequest[] - */ - public function getUserPendingRequests($user_id) { - return $this->shareRequest->getUserPendingRequests($user_id); - } + /** + * Obtains pending requests for the given user ID + * @param $user_id + * @return \OCA\Passman\Db\ShareRequest[] + */ + public function getUserPendingRequests($user_id){ + return $this->shareRequest->getUserPendingRequests($user_id); + } - public function getSharedItems($user_id, $vault_guid) { - $entries = $this->sharingACL->getVaultEntries($user_id, $vault_guid); + public function getSharedItems($user_id, $vault_guid){ + $entries = $this->sharingACL->getVaultEntries($user_id, $vault_guid); - $return = []; - foreach ($entries as $entry) { - // Check if the user can read the credential, probably unnecesary, but just to be sure - if (!$entry->hasPermission(SharingACL::READ)) continue; + $return = []; + foreach ($entries as $entry){ + // Check if the user can read the credential, probably unnecesary, but just to be sure + if (!$entry->hasPermission(SharingACL::READ)) continue; - $tmp = $entry->jsonSerialize(); - $tmp['credential_data'] = $this->credential->getCredentialById($entry->getItemId())->jsonSerialize(); - unset($tmp['credential_data']['shared_key']); - $return[] = $tmp; - } - return $return; - } + $tmp = $entry->jsonSerialize(); + $tmp['credential_data'] = $this->credential->getCredentialById($entry->getItemId())->jsonSerialize(); + unset($tmp['credential_data']['shared_key']); + $return[] = $tmp; + } + return $return; + } /** * Deletes an share reuqest by id - * * @param ShareRequest $request * @return \OCA\Passman\Db\ShareRequest[] */ - public function cleanItemRequestsForUser(ShareRequest $request) { + public function cleanItemRequestsForUser(ShareRequest $request){ return $this->shareRequest->cleanItemRequestsForUser($request->getItemId(), $request->getTargetUserId()); } /** * Get an share request by id */ - public function getShareRequestById($id) { + public function getShareRequestById($id){ return $this->shareRequest->getShareRequestById($id); } @@ -134,47 +130,8 @@ class ShareService { * Get an share request by $item_guid and $target_vault_guid * */ - public function getRequestByGuid($item_guid, $target_vault_guid) { + public function getRequestByGuid($item_guid, $target_vault_guid){ return $this->shareRequest->getRequestByGuid($item_guid, $target_vault_guid); } - /** - * Get the access control list by item guid - * - * @param string $item_guid - * @return \OCA\Passman\Db\SharingACL[] - */ - public function getCredentialAclList($item_guid) { - return $this->sharingACL->getCredentialAclList($item_guid); - } - - /** - * Get pending share requests by guid - * - * @param string $item_guid - * @return \OCA\Passman\Db\ShareRequest[] - */ - public function getShareRequestsByGuid($item_guid) { - return $this->shareRequest->getShareRequestsByGuid($item_guid); - } - - /** - * Get pending share requests by guid - * - * @param ShareRequest $request - * @return \OCA\Passman\Db\ShareRequest[] - */ - public function deleteShareRequest(ShareRequest $request) { - return $this->shareRequest->deleteShareRequest($request); - } - - /** - * Get pending share requests by guid - * - * @param ShareRequest $request - * @return \OCA\Passman\Db\ShareRequest[] - */ - public function deleteShareACL(SharingACL $ACL) { - return $this->sharingACL->deleteShareACL($ACL); - } } \ No newline at end of file diff --git a/templates/views/share_credential.html b/templates/views/share_credential.html index caa6dffa..d8750aa1 100644 --- a/templates/views/share_credential.html +++ b/templates/views/share_credential.html @@ -25,7 +25,6 @@ -