verschlüsselung
This commit is contained in:
@@ -68,6 +68,7 @@ Item
|
|||||||
rowSpacing: 9
|
rowSpacing: 9
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
Layout.margins: 9
|
Layout.margins: 9
|
||||||
|
property string name: "pyqcrm"
|
||||||
Label
|
Label
|
||||||
{
|
{
|
||||||
text: qsTr("Benutzername:")
|
text: qsTr("Benutzername:")
|
||||||
@@ -80,7 +81,7 @@ Item
|
|||||||
placeholderText: qsTr("Hier Benutzername eingeben")
|
placeholderText: qsTr("Hier Benutzername eingeben")
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
height: 3
|
height: 3
|
||||||
property string name: "username"
|
property string name: "PYQCRM_ADMIN"
|
||||||
}
|
}
|
||||||
|
|
||||||
Label
|
Label
|
||||||
@@ -95,7 +96,7 @@ Item
|
|||||||
echoMode: TextInput.Password
|
echoMode: TextInput.Password
|
||||||
placeholderText: qsTr("Hier Passwort eingeben")
|
placeholderText: qsTr("Hier Passwort eingeben")
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
property string name: "password"
|
property string name: "PYQCRM_ADMIN_PASS"
|
||||||
}
|
}
|
||||||
|
|
||||||
Item
|
Item
|
||||||
@@ -117,6 +118,7 @@ Item
|
|||||||
columnSpacing: 5
|
columnSpacing: 5
|
||||||
rowSpacing: 9
|
rowSpacing: 9
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
|
property string name: "database"
|
||||||
|
|
||||||
|
|
||||||
Label
|
Label
|
||||||
@@ -131,7 +133,7 @@ Item
|
|||||||
id: dbHost
|
id: dbHost
|
||||||
placeholderText: qsTr("Hier Host eingeben")
|
placeholderText: qsTr("Hier Host eingeben")
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
property string name: "db-host"
|
property string name: "DB_HOST"
|
||||||
}
|
}
|
||||||
|
|
||||||
Label
|
Label
|
||||||
@@ -145,7 +147,7 @@ Item
|
|||||||
id: dbPort
|
id: dbPort
|
||||||
placeholderText: qsTr("Hier DB-Port eingeben")
|
placeholderText: qsTr("Hier DB-Port eingeben")
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
property string name: "db-port"
|
property string name: "DB_PORT"
|
||||||
}
|
}
|
||||||
|
|
||||||
Label
|
Label
|
||||||
@@ -159,7 +161,7 @@ Item
|
|||||||
id: dbName
|
id: dbName
|
||||||
placeholderText: qsTr("Hier DB-Name eingeben")
|
placeholderText: qsTr("Hier DB-Name eingeben")
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
property string name: "db-name"
|
property string name: "DB_NAME"
|
||||||
}
|
}
|
||||||
|
|
||||||
Label
|
Label
|
||||||
@@ -173,7 +175,7 @@ Item
|
|||||||
id: dbUserName
|
id: dbUserName
|
||||||
placeholderText: qsTr("Hier DB-Benutzername eingeben")
|
placeholderText: qsTr("Hier DB-Benutzername eingeben")
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
property string name: "db-username"
|
property string name: "DB_USER"
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -189,7 +191,7 @@ Item
|
|||||||
echoMode: TextInput.Password
|
echoMode: TextInput.Password
|
||||||
placeholderText: qsTr("Hier DB-Passwort eingeben")
|
placeholderText: qsTr("Hier DB-Passwort eingeben")
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
property string name: "db-password"
|
property string name: "DB_PASS"
|
||||||
}
|
}
|
||||||
|
|
||||||
Item
|
Item
|
||||||
|
|||||||
@@ -3,25 +3,19 @@
|
|||||||
function func(tabs)
|
function func(tabs)
|
||||||
{
|
{
|
||||||
let pyqcrm_conf = {};
|
let pyqcrm_conf = {};
|
||||||
|
|
||||||
for (var j = 0; j < tabs.length; j++)
|
for (var j = 0; j < tabs.length; j++)
|
||||||
{
|
{
|
||||||
|
pyqcrm_conf[tabs[j].name] = {}
|
||||||
for (var i = 0; i < tabs[j].children.length; i++)
|
for (var i = 0; i < tabs[j].children.length; i++)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
if (tabs[j].children[i].name)
|
if (tabs[j].children[i].name)
|
||||||
{
|
{
|
||||||
if (!tabs[j].children[i].text.trim())
|
if (!tabs[j].children[i].text.trim())
|
||||||
return false
|
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
|
return pyqcrm_conf
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import toml
|
|||||||
from platformdirs import user_config_dir
|
from platformdirs import user_config_dir
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from PySide6.QtCore import QObject, Slot
|
from PySide6.QtCore import QObject, Slot
|
||||||
|
from .Vermasseln import Vermasseln
|
||||||
|
|
||||||
|
|
||||||
class ConfigLoader(QObject):
|
class ConfigLoader(QObject):
|
||||||
@@ -20,29 +21,12 @@ class ConfigLoader(QObject):
|
|||||||
|
|
||||||
@Slot(dict)
|
@Slot(dict)
|
||||||
def setConfig(self, app_config):
|
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:
|
try:
|
||||||
with open (self.config_dir + '/pyqcrm.toml', 'w') as f:
|
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:
|
except FileNotFoundError:
|
||||||
print("Konnte die Konfiguration nicht speichern.")
|
print("Konnte die Konfiguration nicht speichern.")
|
||||||
|
|
||||||
@@ -51,11 +35,14 @@ class ConfigLoader(QObject):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
with open (self.config_dir + '/pyqcrm.toml', 'r') as f:
|
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:
|
except FileNotFoundError:
|
||||||
print("Konnte die Konfiguration nicht laden.")
|
print("Konnte die Konfiguration nicht laden.")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def getConfig(self):
|
def getConfig(self):
|
||||||
|
|
||||||
return self.__config
|
return self.__config
|
||||||
|
|||||||
41
lib/Vermasseln.py
Normal file
41
lib/Vermasseln.py
Normal file
@@ -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"))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -6,6 +6,7 @@
|
|||||||
"main.py",
|
"main.py",
|
||||||
"gui/main.qml",
|
"gui/main.qml",
|
||||||
"gui/start.qml",
|
"gui/start.qml",
|
||||||
"js/qmldict.js"
|
"js/qmldict.js",
|
||||||
|
"lib/Vermasseln.py"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user