mirror of
https://github.com/nextcloud/passman.git
synced 2025-10-10 21:46:25 +08:00
Small start of re encrypting files on share
This commit is contained in:
parent
b01afb4f3d
commit
c62a0a8d7c
2 changed files with 35 additions and 9 deletions
|
@ -9,7 +9,7 @@
|
||||||
* This file is part of passman, licensed under AGPLv3
|
* This file is part of passman, licensed under AGPLv3
|
||||||
*/
|
*/
|
||||||
angular.module('passmanApp')
|
angular.module('passmanApp')
|
||||||
.controller('ShareCtrl', ['$scope', 'VaultService', 'CredentialService', 'SettingsService', '$location', '$routeParams', 'ShareService', 'NotificationService', 'SharingACL','EncryptService',
|
.controller('ShareCtrl', ['$scope', 'VaultService', 'CredentialService', 'SettingsService', '$location', '$routeParams', 'ShareService', 'NotificationService', 'SharingACL','EncryptService', 'FileService',
|
||||||
function ($scope, VaultService, CredentialService, SettingsService, $location, $routeParams, ShareService, NotificationService, SharingACL, EncryptService) {
|
function ($scope, VaultService, CredentialService, SettingsService, $location, $routeParams, ShareService, NotificationService, SharingACL, EncryptService) {
|
||||||
$scope.active_vault = VaultService.getActiveVault();
|
$scope.active_vault = VaultService.getActiveVault();
|
||||||
|
|
||||||
|
@ -157,7 +157,6 @@ angular.module('passmanApp')
|
||||||
$scope.setPermission = function(acl, permission){
|
$scope.setPermission = function(acl, permission){
|
||||||
acl.togglePermission(permission);
|
acl.togglePermission(permission);
|
||||||
};
|
};
|
||||||
console.log($scope.storedCredential)
|
|
||||||
$scope.shareWith = function (shareWith, selectedAccessLevel) {
|
$scope.shareWith = function (shareWith, selectedAccessLevel) {
|
||||||
//@TODO Improve this so we can add, edit and remove users and permissions.
|
//@TODO Improve this so we can add, edit and remove users and permissions.
|
||||||
$scope.inputSharedWith = [];
|
$scope.inputSharedWith = [];
|
||||||
|
@ -218,8 +217,9 @@ angular.module('passmanApp')
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
$scope.sharing_complete = true;
|
||||||
$scope.applyShare = function () {
|
$scope.applyShare = function () {
|
||||||
|
$scope.sharing_complete = false;
|
||||||
$scope.share_settings.cypher_progress.percent = 0;
|
$scope.share_settings.cypher_progress.percent = 0;
|
||||||
$scope.share_settings.cypher_progress.done = 0;
|
$scope.share_settings.cypher_progress.done = 0;
|
||||||
$scope.share_settings.cypher_progress.total = 0;
|
$scope.share_settings.cypher_progress.total = 0;
|
||||||
|
@ -227,8 +227,6 @@ angular.module('passmanApp')
|
||||||
$scope.share_settings.cypher_progress.times_total = [];
|
$scope.share_settings.cypher_progress.times_total = [];
|
||||||
$scope.share_settings.upload_progress.done = 0;
|
$scope.share_settings.upload_progress.done = 0;
|
||||||
$scope.share_settings.upload_progress.total = 0;
|
$scope.share_settings.upload_progress.total = 0;
|
||||||
|
|
||||||
console.log($scope.storedCredential);
|
|
||||||
//Credential is already shared
|
//Credential is already shared
|
||||||
if($scope.storedCredential.shared_key && $scope.storedCredential.shared_key != '' && $scope.storedCredential.shared_key != null){
|
if($scope.storedCredential.shared_key && $scope.storedCredential.shared_key != '' && $scope.storedCredential.shared_key != null){
|
||||||
console.log('Shared key found');
|
console.log('Shared key found');
|
||||||
|
@ -271,11 +269,19 @@ angular.module('passmanApp')
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
ShareService.generateSharedKey(20).then(function (key) {
|
ShareService.generateSharedKey(20).then(function (key) {
|
||||||
|
|
||||||
var encryptedSharedCredential = ShareService.encryptSharedCredential($scope.storedCredential, key);
|
var encryptedSharedCredential = ShareService.encryptSharedCredential($scope.storedCredential, key);
|
||||||
CredentialService.updateCredential(encryptedSharedCredential, true).then(function(sharedCredential){
|
CredentialService.updateCredential(encryptedSharedCredential, true).then(function(sharedCredential){
|
||||||
$scope.storedCredential = ShareService.decryptSharedCredential(sharedCredential, key);
|
$scope.storedCredential = ShareService.decryptSharedCredential(sharedCredential, key);
|
||||||
});
|
});
|
||||||
|
console.log($scope.storedCredential);
|
||||||
|
|
||||||
|
//@TODO Update files with new key (async)
|
||||||
|
// Files are stored in $scope.storedCredential.files
|
||||||
|
// They need get downloaded with FileService.getFile
|
||||||
|
// Then decrypt the data obtained with var EncryptService.decryptString(result.file_data);
|
||||||
|
// To update a file you can use the FileService.updateFile
|
||||||
|
|
||||||
|
//@TODO Update revisions with new key (async)
|
||||||
|
|
||||||
var list = $scope.share_settings.credentialSharedWithUserAndGroup;
|
var list = $scope.share_settings.credentialSharedWithUserAndGroup;
|
||||||
for (var i = 0; i < list.length; i++) {
|
for (var i = 0; i < list.length; i++) {
|
||||||
|
|
|
@ -10,11 +10,11 @@
|
||||||
angular.module('passmanApp')
|
angular.module('passmanApp')
|
||||||
.service('FileService', ['$http', 'EncryptService', function ($http, EncryptService) {
|
.service('FileService', ['$http', 'EncryptService', function ($http, EncryptService) {
|
||||||
return {
|
return {
|
||||||
uploadFile: function (file) {
|
uploadFile: function (file, key) {
|
||||||
var queryUrl = OC.generateUrl('apps/passman/api/v2/file');
|
var queryUrl = OC.generateUrl('apps/passman/api/v2/file');
|
||||||
var _file = angular.copy(file);
|
var _file = angular.copy(file);
|
||||||
_file.filename = EncryptService.encryptString(_file.filename);
|
_file.filename = EncryptService.encryptString(_file.filename, key);
|
||||||
var data = EncryptService.encryptString(angular.copy(file.data));
|
var data = EncryptService.encryptString(angular.copy(file.data), key);
|
||||||
_file.data = data;
|
_file.data = data;
|
||||||
return $http.post(queryUrl, _file).then(function (response) {
|
return $http.post(queryUrl, _file).then(function (response) {
|
||||||
if (response.data) {
|
if (response.data) {
|
||||||
|
@ -50,6 +50,26 @@ angular.module('passmanApp')
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
/**
|
||||||
|
* Update a file and it's contents
|
||||||
|
* @param file
|
||||||
|
* @param key Optional encryption key to use
|
||||||
|
* @returns {*}
|
||||||
|
*/
|
||||||
|
updateFile: function(file, key){
|
||||||
|
var queryUrl = OC.generateUrl('apps/passman/api/v2/file/'+ file.file_id);
|
||||||
|
var _file = angular.copy(file);
|
||||||
|
_file.filename = EncryptService.encryptString(_file.filename, key);
|
||||||
|
var data = EncryptService.encryptString(angular.copy(file.data), key);
|
||||||
|
_file.data = data;
|
||||||
|
return $http.patch(queryUrl, _file).then(function (response) {
|
||||||
|
if (response.data) {
|
||||||
|
return response.data;
|
||||||
|
} else {
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
dataURItoBlob: function (dataURI, ftype) {
|
dataURItoBlob: function (dataURI, ftype) {
|
||||||
var byteString, mimeString, ab, ia, bb, i;
|
var byteString, mimeString, ab, ia, bb, i;
|
||||||
// convert base64 to raw binary data held in a string
|
// convert base64 to raw binary data held in a string
|
||||||
|
|
Loading…
Add table
Reference in a new issue