fix shared credential decryption error #737

This commit is contained in:
binsky 2023-04-22 19:10:17 +02:00
parent 70b5799c36
commit baf9a189ea

View file

@ -342,31 +342,17 @@
$scope.updateExistingListWithCredential(new_cred); $scope.updateExistingListWithCredential(new_cred);
}); });
} else { } else {
let _credential = angular.copy($scope.storedCredential);
var key, _credential; const key = CredentialService.getSharedKeyFromCredential($scope.storedCredential);
if (!$scope.storedCredential.hasOwnProperty('acl') && $scope.storedCredential.hasOwnProperty('shared_key')) {
if ($scope.storedCredential.shared_key) {
key = EncryptService.decryptString(angular.copy($scope.storedCredential.shared_key));
}
}
if ($scope.storedCredential.hasOwnProperty('acl')) {
key = EncryptService.decryptString(angular.copy($scope.storedCredential.acl.shared_key));
}
if (key) { if (key) {
_credential = ShareService.encryptSharedCredential($scope.storedCredential, key); _credential = ShareService.encryptSharedCredential($scope.storedCredential, key);
} else {
_credential = angular.copy($scope.storedCredential);
} }
delete _credential.shared_key; delete _credential.shared_key;
var _useKey = (key != null); const _useKey = (key != null);
var regex = /(<([^>]+)>)/ig; const regex = /(<([^>]+)>)/ig;
if(_credential.description && _credential.description !== "") { if(_credential.description && _credential.description !== "") {
_credential.description = _credential.description.replace(regex, ""); _credential.description = _credential.description.replace(regex, "");
} }
@ -386,17 +372,17 @@
if (!credential.shared_key) { if (!credential.shared_key) {
credential = CredentialService.decryptCredential(credential); credential = CredentialService.decryptCredential(credential);
} else { } else {
var enc_key = EncryptService.decryptString(credential.shared_key); const enc_key = CredentialService.getSharedKeyFromCredential($scope.storedCredential);
credential = ShareService.decryptSharedCredential(credential, enc_key); credential = ShareService.decryptSharedCredential(credential, enc_key);
} }
credential.tags_raw = credential.tags; credential.tags_raw = credential.tags;
var found=false; let found = false;
var credList=$rootScope.vaultCache[$scope.active_vault.guid].credentials; let credList = $rootScope.vaultCache[$scope.active_vault.guid].credentials;
for (var i = 0; i < credList.length; i++) { for (let i = 0; i < credList.length; i++) {
if (credList[i].credential_id === credential.credential_id) { if (credList[i].credential_id === credential.credential_id) {
$rootScope.vaultCache[$scope.active_vault.guid].credentials[i]=credential; $rootScope.vaultCache[$scope.active_vault.guid].credentials[i] = credential;
found=true; found = true;
} }
} }
@ -404,7 +390,6 @@
$rootScope.vaultCache[$scope.active_vault.guid].credentials.push(credential); $rootScope.vaultCache[$scope.active_vault.guid].credentials.push(credential);
} }
$rootScope.$broadcast('push_decrypted_credential_to_list', credential); $rootScope.$broadcast('push_decrypted_credential_to_list', credential);
} catch (e) { } catch (e) {
NotificationService.showNotification($translate.instant('error.decrypt'), 5000); NotificationService.showNotification($translate.instant('error.decrypt'), 5000);
console.log(e); console.log(e);