added password encryption and metainfo file so we are 100% gnome-software compatible

This commit is contained in:
2024-11-20 14:47:40 +01:00
parent f6975cccb1
commit 85ea660c7e
7 changed files with 99 additions and 32 deletions

View File

@@ -10,6 +10,7 @@ import os
import gi
import subprocess
import json
from cryptography.fernet import Fernet
gi.require_version('Gtk', '4.0')
gi.require_version('Adw', '1')
from gi.repository import Gtk, Adw, Gdk, Gio
@@ -19,6 +20,22 @@ HOMEDIR = os.path.expanduser('~')
conn_info = {}
settings = {}
fernet = ""
def load_keys():
global fernet
cryptoKey = ""
try:
with open(HOMEDIR+"/.config/rdpconnect/.key", "r") as keyfile:
cryptoKey = str.encode(keyfile.readline())
print("Encription key loaded")
except:
cryptoKey = Fernet.generate_key()
with open(HOMEDIR+"/.config/rdpconnect/.key", "w") as keyfile:
keyfile.write(cryptoKey.decode("utf-8"))
print("Encription key generated")
fernet = Fernet(cryptoKey)
def load_config():
global conn_info, settings
@@ -29,6 +46,8 @@ def load_config():
loaded_json += line
conn_info = json.loads(loaded_json)
conn_info["passwd"] = fernet.decrypt(str.encode(conn_info["passwd"])).decode()
except:
print("[WARN] FILE: "+HOMEDIR+"/.config/rdpconnect/connection.json doesn't exist")
@@ -84,10 +103,15 @@ class MyApp(Adw.Application):
def saveConnConf(self):
if settings["save_conn"]:
password = conn_info["passwd"]
conn_info["passwd"] = fernet.encrypt(password.encode()).decode("utf-8")
print("Saving connection config to "+HOMEDIR+"/.config/rdpconnect/connection.json")
with open(HOMEDIR+"/.config/rdpconnect/connection.json", "w") as connection_file:
js = json.dumps(conn_info, sort_keys=True, indent=4, separators=(',', ': '))
connection_file.write(js)
conn_info["passwd"] = password
else:
with open(HOMEDIR+"/.config/rdpconnect/connection.json", "w") as connection_file:
connection_file.write("")
@@ -115,8 +139,8 @@ class MyApp(Adw.Application):
if not os.path.isdir(HOMEDIR+"/.config/rdpconnect"):
os.makedirs(HOMEDIR+"/.config/rdpconnect")
#subprocess.run(["ls", "-a", HOMEDIR])
load_keys()
load_config()
app = MyApp(application_id=APPID)
app.run(sys.argv)