added keyring auth, so we don't have to save credentials in file

This commit is contained in:
2025-09-16 13:47:28 +02:00
parent d38aeda6c0
commit eea479b3df
3 changed files with 60 additions and 30 deletions

View File

@@ -67,6 +67,12 @@
<p>Updated to newest FreeRDP which seems to fix issues with hanging / freezing</p> <p>Updated to newest FreeRDP which seems to fix issues with hanging / freezing</p>
</description> </description>
</release> </release>
<release version="1.3.0" date="2025-02-19">
<url type="details">https://gitea.farmdash.org/angoosh/Flatpaks/src/tag/1.3.0</url>
<description>
<p>Changed pasword storage from file to system keyring. Still using file for compatibility. Also added menu for credential selection.</p>
</description>
</release>
</releases> </releases>
<screenshots> <screenshots>

View File

@@ -31,6 +31,7 @@ finish-args:
- --filesystem=xdg-download - --filesystem=xdg-download
- --socket=pcsc - --socket=pcsc
# - --socket=system-bus # - --socket=system-bus
- --socket=session-bus
# - --talk-name=org.freedesktop.Flatpak # - --talk-name=org.freedesktop.Flatpak
add-build-extensions: add-build-extensions:
@@ -68,7 +69,7 @@ modules:
build-args: build-args:
- --share=network - --share=network
build-commands: build-commands:
- pip3 install PyGObject cryptography - pip3 install PyGObject cryptography keyring
- name: rdpconnect - name: rdpconnect
buildsystem: simple buildsystem: simple

View File

@@ -18,13 +18,15 @@ from cryptography.fernet import Fernet
gi.require_version('Gtk', '4.0') gi.require_version('Gtk', '4.0')
gi.require_version('Adw', '1') gi.require_version('Adw', '1')
from gi.repository import Gtk, Adw, Gdk, Gio from gi.repository import Gtk, Adw, Gdk, Gio
import keyring
APPID = "com.angoosh.RDPConnect" APPID = "com.angoosh.RDPConnect"
HOMEDIR = os.path.expanduser('~') HOMEDIR = os.path.expanduser('~')
VERSION = "1.2.0" VERSION = "1.3.0"
conn_info = {} conn_info = {}
hist_info = {}
settings = {} settings = {}
settings["extra_params"] = {} settings["extra_params"] = {}
fernet = "" fernet = ""
@@ -48,15 +50,27 @@ def load_config():
global conn_info, settings global conn_info, settings
loaded_json = "" loaded_json = ""
try: try:
with open(HOMEDIR+"/.config/rdpconnect/connection.json", "r") as connection_file: with open(HOMEDIR+"/.config/rdpconnect/history.json", "r") as history_file:
for line in connection_file: for line in connection_file:
loaded_json += line loaded_json += line
conn_info = json.loads(loaded_json) hist_info = json.loads(loaded_json)
last_conn = conn_info[max(hist_info)]
conn_info["user"] = last_conn.split('@')[0]
conn_info["ip"] = last_conn.split('@')[1]
conn_info["passwd"] = keyring.get_password("rdpconnect", last_conn)
conn_info["passwd"] = fernet.decrypt(str.encode(conn_info["passwd"])).decode()
except: except:
print("[WARN] FILE: "+HOMEDIR+"/.config/rdpconnect/connection.json doesn't exist") try:
with open(HOMEDIR+"/.config/rdpconnect/connection.json", "r") as connection_file:
for line in connection_file:
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")
loaded_json = "" loaded_json = ""
try: try:
@@ -261,14 +275,23 @@ class MyApp(Adw.Application):
def saveConnConf(self): def saveConnConf(self):
if settings["save_conn"]: if settings["save_conn"]:
password = conn_info["passwd"] password = conn_info["passwd"]
conn_info["passwd"] = fernet.encrypt(password.encode()).decode("utf-8") useratip = conn_info["user"] + "@" + conn_info["ip"]
with open(HOMEDIR+"/.config/rdpconnect/history.json", "a") as hist_file:
hist_id = str(int(max(hist_info)) + 1)
hist_info[hist_id] = useratip
js = json.dumps(hist_info, sort_keys=True, indent=4, separators=(',', ': '))
hist_file.write(js)
try:
keyring.set_password("rdpconnect", useratip, password)
except:
conn_info["passwd"] = fernet.encrypt(password.encode()).decode("utf-8")
print("Saving connection config to "+HOMEDIR+"/.config/rdpconnect/connection.json") print("Saving connection config to "+HOMEDIR+"/.config/rdpconnect/connection.json")
with open(HOMEDIR+"/.config/rdpconnect/connection.json", "w") as connection_file: with open(HOMEDIR+"/.config/rdpconnect/connection.json", "w") as connection_file:
js = json.dumps(conn_info, sort_keys=True, indent=4, separators=(',', ': ')) js = json.dumps(conn_info, sort_keys=True, indent=4, separators=(',', ': '))
connection_file.write(js) connection_file.write(js)
conn_info["passwd"] = password conn_info["passwd"] = password
else: else:
with open(HOMEDIR+"/.config/rdpconnect/connection.json", "w") as connection_file: with open(HOMEDIR+"/.config/rdpconnect/connection.json", "w") as connection_file:
connection_file.write("") connection_file.write("")