Backup Config

This commit is contained in:
2025-02-27 14:45:27 +01:00
parent 4c62834369
commit 73542e8089
4 changed files with 61 additions and 30 deletions

View File

@@ -110,6 +110,12 @@ class ConfigLoader(QObject):
self.backupEncryptionKey.emit()
return admin
"""###################################################"""
""" """
""" TODO: Rename method and rename self.__encrypt_key """
""" """
"""###################################################"""
@Slot(str, str)
def saveRecoveryKey(self, recovery_file, recovery_password):
# print(f"In {__file__} file, saveRecoveryKey()")
@@ -131,30 +137,39 @@ class ConfigLoader(QObject):
@Slot(str, str)
def getRecoveryKey(self, recovery_file, recovery_password):
# print(f"In {__file__} file, getRecoveryKey()")
local = False
rec_file = urlparse(recovery_file)
rec_file = rec_file.path
if os.name == "nt":
rec_file = rec_file [1:]
try:
with open(rec_file, "r") as f:
rf = f.read()
rf = Vermasseln().entschluesseln(rf, local)
ek = rf[128:]
ek = ek[:-32]
password = rf[:128]
salt = rf[-32:]
ok = self.__checkRecoveryPassword(recovery_password, password, salt)
if ok:
self.__setEncryptionKey(ek)
self.configurationReady.emit()
else:
self.__invalidateEncryptionKey()
self.invalidEncryptionKey.emit()
ek = self.__parseImport(rec_file, recovery_password)
if ek:
self.__setEncryptionKey(ek)
self.configurationReady.emit()
else:
self.__invalidateEncryptionKey()
self.invalidEncryptionKey.emit()
except Exception as e:
print(str(e))
def __parseImport(self, rec_file, recovery_password):
local = False
with open(rec_file, "r") as f:
rf = f.read()
rf = Vermasseln().entschluesseln(rf, local)
ek = rf[128:]
ek = ek[:-32]
password = rf[:128]
salt = rf[-32:]
ok = self.__checkRecoveryPassword(recovery_password, password, salt)
if ok:
return ek
else:
return None
def __invalidateEncryptionKey(self):
# print(f"In {__file__} file, __invalidateEncryptionKey()")
self.__config['pyqcrm']['ENCRYPTION_KEY_VALID'] = 'No'
@@ -173,13 +188,25 @@ class ConfigLoader(QObject):
@Slot(str, str) # todo: non local encryption
def importConfig(self, confile, password):
# print(f"In {__file__} file, importConfig()")
confile = urlparse(confile)
confile = confile.path
if os.name == "nt":
confile = confile[1:]
shutil.copyfile(confile, self.config_dir+ '/pyqcrm.toml')
try:
ek = self.__parseImport(confile, password)
if ek:
self.__config = toml.loads(ek)
self.__saveConfig()
self.configurationReady.emit()
else:
self.invalidEncryptionKey.emit()
except Exception as e:
print(str(e))
def __configLoad(self):
# print(f"In {__file__} file, __configLoad()")
@@ -213,8 +240,8 @@ class ConfigLoader(QObject):
self.__config['pyqcrm']['ENCRYPTION_KEY'] = enc_key
self.__saveConfig()
@Slot(str)
def backupConfig(self, pw):
print(pw)
new_config = self.getConfig()
print(new_config)
@Slot(str, str)
def backupConfig(self, filename, password):
self.__encrypt_key = toml.dumps(self.getConfig())
self.saveRecoveryKey(filename, password)

View File

@@ -53,7 +53,6 @@ class Vermasseln:
hash_pw = (salt + password).encode("utf-8")
h_obj = SHA3_512.new(hash_pw)
password = salt + "$" + h_obj.hexdigest()
return password