diff --git a/gui/firststart.qml b/gui/firststart.qml index be202b2..f3f816f 100644 --- a/gui/firststart.qml +++ b/gui/firststart.qml @@ -68,6 +68,7 @@ Item rowSpacing: 9 anchors.fill: parent Layout.margins: 9 + property string name: "pyqcrm" Label { text: qsTr("Benutzername:") @@ -80,7 +81,7 @@ Item placeholderText: qsTr("Hier Benutzername eingeben") Layout.fillWidth: true height: 3 - property string name: "username" + property string name: "PYQCRM_ADMIN" } Label @@ -95,7 +96,7 @@ Item echoMode: TextInput.Password placeholderText: qsTr("Hier Passwort eingeben") Layout.fillWidth: true - property string name: "password" + property string name: "PYQCRM_ADMIN_PASS" } Item @@ -117,6 +118,7 @@ Item columnSpacing: 5 rowSpacing: 9 anchors.fill: parent + property string name: "database" Label @@ -131,7 +133,7 @@ Item id: dbHost placeholderText: qsTr("Hier Host eingeben") Layout.fillWidth: true - property string name: "db-host" + property string name: "DB_HOST" } Label @@ -145,7 +147,7 @@ Item id: dbPort placeholderText: qsTr("Hier DB-Port eingeben") Layout.fillWidth: true - property string name: "db-port" + property string name: "DB_PORT" } Label @@ -159,7 +161,7 @@ Item id: dbName placeholderText: qsTr("Hier DB-Name eingeben") Layout.fillWidth: true - property string name: "db-name" + property string name: "DB_NAME" } Label @@ -173,7 +175,7 @@ Item id: dbUserName placeholderText: qsTr("Hier DB-Benutzername eingeben") Layout.fillWidth: true - property string name: "db-username" + property string name: "DB_USER" } @@ -189,7 +191,7 @@ Item echoMode: TextInput.Password placeholderText: qsTr("Hier DB-Passwort eingeben") Layout.fillWidth: true - property string name: "db-password" + property string name: "DB_PASS" } Item diff --git a/js/qmldict.js b/js/qmldict.js index 67f8753..1c95926 100644 --- a/js/qmldict.js +++ b/js/qmldict.js @@ -3,25 +3,19 @@ function func(tabs) { let pyqcrm_conf = {}; - for (var j = 0; j < tabs.length; j++) { - + pyqcrm_conf[tabs[j].name] = {} for (var i = 0; i < tabs[j].children.length; i++) { - - if (tabs[j].children[i].name) { if (!tabs[j].children[i].text.trim()) return false - pyqcrm_conf[tabs[j].children[i].name] = tabs[j].children[i].text - + pyqcrm_conf[tabs[j].name] [tabs[j].children[i].name] = tabs[j].children[i].text } } - - } - + } return pyqcrm_conf } diff --git a/lib/ConfigLoader.py b/lib/ConfigLoader.py index 3fcee3a..ca682bd 100644 --- a/lib/ConfigLoader.py +++ b/lib/ConfigLoader.py @@ -3,6 +3,7 @@ import toml from platformdirs import user_config_dir from pathlib import Path from PySide6.QtCore import QObject, Slot +from .Vermasseln import Vermasseln class ConfigLoader(QObject): @@ -20,29 +21,12 @@ class ConfigLoader(QObject): @Slot(dict) def setConfig(self, app_config): - pyqcrm = '[pyqcrm]\n' - db = '[database]\n' - for k, v in app_config.items(): - if k == 'username': - pyqcrm = pyqcrm + f"PYQCRM_ADMIN = \"{v}\"\n" - elif k == 'password': - pyqcrm = pyqcrm + f"PYQCRM_ADMIN_PASS = \"{v}\"\n" - elif k == 'db-host': - db = db + f"DB_HOST = \"{v}\"\n" - elif k == 'db-name': - db = db + f"DB_PORT = \"{v}\"\n" - elif k == 'db-port': - db = db + f"DB_NAME = \"{v}\"\n" - elif k == 'db-username': - db = db + f"DB_USER = \"{v}\"\n" - elif k == 'db-password': - db = db + f"DB_PASS = \"{v}\"\n" - appconf = pyqcrm + '\n' + db + '\n' try: with open (self.config_dir + '/pyqcrm.toml', 'w') as f: - f.write(appconf) + config = Vermasseln().oscarVermasseln(toml.dumps(app_config)) + f.write(config) except FileNotFoundError: print("Konnte die Konfiguration nicht speichern.") @@ -51,11 +35,14 @@ class ConfigLoader(QObject): try: with open (self.config_dir + '/pyqcrm.toml', 'r') as f: - self.__config = toml.load(f) + config = f.read() + self.__config = toml.loads(Vermasseln().entschluesseln(config)) + print(self.__config) except FileNotFoundError: print("Konnte die Konfiguration nicht laden.") + def getConfig(self): return self.__config diff --git a/lib/Vermasseln.py b/lib/Vermasseln.py new file mode 100644 index 0000000..5628c7d --- /dev/null +++ b/lib/Vermasseln.py @@ -0,0 +1,41 @@ +# This Python file uses the following encoding: utf-8 +from Crypto import Random +from Crypto.Cipher import AES +from base64 import b64encode, b64decode +import platform +from Crypto.Hash import SHA256 + + +class Vermasseln: + def oscarVermasseln(self, data): + b_data = data.encode("utf-8") + cipher = self.__vermasslungsKobold() + + ciphertext, tag = cipher.encrypt_and_digest(b_data) + decoded_data = [b64encode(x).decode("utf-8") for x in (ciphertext, tag)] + storable_data = ".".join(decoded_data) + + return storable_data + + def entschluesseln(self, data): + data_list = data.split(".") + encoded_data = [b64decode(x) for x in data_list] + cipher = self.__vermasslungsKobold() + decrypted_data = cipher.decrypt_and_verify(encoded_data[0], encoded_data[1]) + decrypted_data = decrypted_data.decode("utf-8") + return decrypted_data + + def __vermasslungsKobold(self): + key = platform.processor().encode("utf-8") + key = key[0:31] + hash_key = SHA256.new(key) + hashed = hash_key.digest() + nonce = platform.machine().encode("utf-8") + cipher = AES.new(hashed, AES.MODE_SIV, nonce = nonce) + return cipher + +print(Vermasseln().oscarVermasseln("irgendeinenText")) + + + + diff --git a/pyqcrm.pyproject b/pyqcrm.pyproject index d16df7a..cc0c03c 100644 --- a/pyqcrm.pyproject +++ b/pyqcrm.pyproject @@ -6,6 +6,7 @@ "main.py", "gui/main.qml", "gui/start.qml", - "js/qmldict.js" + "js/qmldict.js", + "lib/Vermasseln.py" ] }