mirror of
https://github.com/kevinveenbirkenbach/splitted-secret.git
synced 2025-09-10 04:26:32 +02:00
Implemented escaping for passwords on bash level
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
import shlex
|
||||
|
||||
class AutomaticIdentificationImpossibleException(Exception):
|
||||
pass
|
||||
@@ -35,12 +36,18 @@ class Decryption():
|
||||
self.initializeNeededDecryptersAmount()
|
||||
self.initializeValidDecrypterIds()
|
||||
|
||||
def getEscapedMasterPassword(self):
|
||||
return shlex.quote(self.master_password)
|
||||
|
||||
def initializeGroupDataEncryption(self):
|
||||
self.group_name = self.getDecryptersGroupName()
|
||||
self.encrypted_group_file_path = self.paths.getGroupFilePath(self.group_name, self.paths.TYPE_DECRYPTED)
|
||||
self.decryptGroupFile()
|
||||
self.master_password = self.loadTxtFile(self.encrypted_group_file_path).strip()
|
||||
|
||||
def getMasterPassword(self):
|
||||
return self.master_password
|
||||
|
||||
def initializeNeededDecryptersAmount(self):
|
||||
self.needed_decrypters_amount = len(str(list(self.user_data['groups'].keys())[0]))
|
||||
|
||||
@@ -70,9 +77,6 @@ class Decryption():
|
||||
shared_password += str(self.password_parts[password_share_index])
|
||||
return shared_password
|
||||
|
||||
def getMasterPassword(self):
|
||||
return self.master_password
|
||||
|
||||
def addDecrypterId(self,decrypter_id):
|
||||
decrypter_id = int(decrypter_id)
|
||||
if decrypter_id not in self.valid_decrypter_ids:
|
||||
@@ -114,7 +118,7 @@ class Decryption():
|
||||
return data
|
||||
|
||||
def decryptFile(self,password,input_file_path,output_file_path):
|
||||
self.cli.executeCommand('gpg --batch --passphrase "'+ password + '" -o "' + output_file_path +'" "'+ input_file_path+'"')
|
||||
self.cli.executeCommand('gpg --batch --passphrase '+ shlex.quote(password) + ' -o "' + output_file_path +'" "'+ input_file_path+'"')
|
||||
|
||||
def decryptUserFile(self):
|
||||
input_file_path = self.paths.getUserFilePath(self.user_id,self.paths.TYPE_ENCRYPTED)
|
||||
@@ -130,4 +134,4 @@ class Decryption():
|
||||
self.decryptFile(self.user_password, input_file_path, output_file_path)
|
||||
|
||||
def decryptMainData(self):
|
||||
self.cli.executeCommand('gpg --batch --passphrase "' + self.getMasterPassword() + '" -d "' + self.paths.getEncryptedMainDataFile() + '" | tar --one-top-level="' + self.paths.getDecryptedMainDataStandartFolder() + '" -xvzf -')
|
||||
self.cli.executeCommand('gpg --batch --passphrase ' + shlex.quote(self.getMasterPassword()) + ' -d "' + self.paths.getEncryptedMainDataFile() + '" | tar --one-top-level="' + self.paths.getDecryptedMainDataStandartFolder() + '" -xvzf -')
|
@@ -5,6 +5,7 @@ import numpy
|
||||
import re
|
||||
import json
|
||||
from .Paths import Paths
|
||||
import shlex
|
||||
|
||||
class Encryption():
|
||||
|
||||
@@ -104,7 +105,7 @@ class Encryption():
|
||||
index += 1
|
||||
|
||||
def encryptStringToFile(self,text,output_file,password):
|
||||
self.cli.executeCommand('echo \'' + text + '\' | gpg --symmetric --armor --batch --passphrase "' + password + '" -o "' + output_file + '"')
|
||||
self.cli.executeCommand('echo ' + shlex.quote(text) + ' | gpg --symmetric --armor --batch --passphrase ' + shlex.quote(password) + ' -o "' + output_file + '"')
|
||||
|
||||
def encryptGroupFiles(self):
|
||||
for password_group_index_int in self.group_mapped_data:
|
||||
@@ -125,7 +126,7 @@ class Encryption():
|
||||
See: https://stackoverflow.com/questions/30650841/why-am-i-getting-errno-7-argument-list-too-long-and-oserror-errno-24-too-ma
|
||||
'''
|
||||
def encryptFileToFile(self,input_file,output_file,password):
|
||||
self.cli.executeCommand('cat \'' + input_file + '\' | gpg --symmetric --armor --batch --passphrase "' + password + '" -o "' + output_file + '"')
|
||||
self.cli.executeCommand('cat \'' + input_file + '\' | gpg --symmetric --armor --batch --passphrase ' + shlex.quote(password) + ' -o "' + output_file + '"')
|
||||
|
||||
def deleteDecryptedAccumulatedFile(self):
|
||||
self.cli.executeCommand('rm ' + self.paths.getAccumulatedFilePath(Paths.TYPE_DECRYPTED))
|
||||
@@ -144,7 +145,7 @@ class Encryption():
|
||||
self.deleteDecryptedAccumulatedFile()
|
||||
|
||||
def encryptMainData(self,input_directory):
|
||||
self.cli.executeCommand('tar -C"' + input_directory + '" -cvzf - ./ | gpg -c --batch --passphrase "' + self.master_password +'" > "' + self.paths.getEncryptedMainDataFile() + '"')
|
||||
self.cli.executeCommand('tar -C"' + input_directory + '" -cvzf - ./ | gpg -c --batch --passphrase ' + shlex.quote(self.master_password) + ' > "' + self.paths.getEncryptedMainDataFile() + '"')
|
||||
|
||||
def encryptMetaData(self):
|
||||
self.encryptUserFile()
|
||||
|
Reference in New Issue
Block a user