Revert "Unshare item. Reading shared credential broke?"

This reverts commit 86d9910f74.
This commit is contained in:
brantje 2016-10-03 15:47:00 +02:00
Родитель 167ffd4644
Коммит ab7b2f7a4d
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 5FF1D117F918687F
12 изменённых файлов: 109 добавлений и 204 удалений

Просмотреть файл

@ -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'],

Просмотреть файл

@ -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);
}

Просмотреть файл

@ -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
*/

Просмотреть файл

@ -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)
})
};

Просмотреть файл

@ -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

Просмотреть файл

@ -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);

Просмотреть файл

@ -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;
},

Просмотреть файл

@ -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',
'<div id="controls"><div class="actions creatable"><div class="breadcrumb"><div class="crumb svg ui-droppable" data-dir="/"><a ng-click="logout()"><i class="fa fa-home"></i></a></div><div class="crumb svg" data-dir="/Test"><a ng-click="cancel()">{{active_vault.name}}</a></div><div class="crumb svg last" data-dir="/Test"><a ng-if="storedCredential.credential_id">Share credential "{{storedCredential.label}}"</a></div></div></div></div><ul class="tab_header"><li ng-repeat="tab in tabs track by $index" class="tab" ng-class="{active:isActiveTab(tab)}" ng-click="onClickTab(tab)" use-theme>{{tab.title}}</li></ul><div class="tab_container edit_credential"><div ng-include="currentTab.url"></div><button ng-click="applyShare()">Share</button> <button ng-click="cancel()">Cancel</button> <button class="btn btn-danger" ng-click="unshareCredential()">Unshare</button></div>');
'<div id="controls"><div class="actions creatable"><div class="breadcrumb"><div class="crumb svg ui-droppable" data-dir="/"><a ng-click="logout()"><i class="fa fa-home"></i></a></div><div class="crumb svg" data-dir="/Test"><a ng-click="cancel()">{{active_vault.name}}</a></div><div class="crumb svg last" data-dir="/Test"><a ng-if="storedCredential.credential_id">Share credential "{{storedCredential.label}}"</a></div></div></div></div><ul class="tab_header"><li ng-repeat="tab in tabs track by $index" class="tab" ng-class="{active:isActiveTab(tab)}" ng-click="onClickTab(tab)" use-theme>{{tab.title}}</li></ul><div class="tab_container edit_credential"><div ng-include="currentTab.url"></div><button ng-click="applyShare()">Share</button> <button ng-click="cancel()">Cancel</button></div>');
}]);
angular.module('views/show_vault.html', []).run(['$templateCache', function($templateCache) {

Просмотреть файл

@ -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]);
}
}

Просмотреть файл

@ -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);
}
}

Просмотреть файл

@ -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);
}
}

Просмотреть файл

@ -25,7 +25,6 @@
<button ng-click="applyShare()">Share</button>
<button ng-click="cancel()">Cancel</button>
<button class="btn btn-danger" ng-click="unshareCredential()">Unshare</button>
</div>