--- a/CertManagement.py Mon Mar 24 15:13:16 2025 +0100
+++ b/CertManagement.py Fri Mar 14 14:27:23 2025 +0100
@@ -195,7 +195,6 @@
info += "Expiration date: %s\n"%cert.not_valid_after.isoformat()
info += "Error while loading certificate: %s\n"%str(e)
return "No client certificate available"
--- a/PSKManagement.py Mon Mar 24 15:13:16 2025 +0100
+++ b/PSKManagement.py Fri Mar 14 14:27:23 2025 +0100
@@ -5,14 +5,16 @@
from __future__ import absolute_import
-from os.path import join, exists
from zipfile import ZipFile
from binascii import b2a_base64
from util.paths import AppDataPath
+### Controllers Identities ### # PSK Management Data model :
# [[ID,Desc, LastKnownURI, LastConnect]]
COL_ID, COL_URI, COL_DESC, COL_LAST = range(4)
@@ -171,13 +173,20 @@
own_keystore = AppDataPath("keystore", "own")
- if not exists(own_keystore):
+ if not os.path.exists(own_keystore): os.makedirs(own_keystore)
- own_identity = join(own_keystore, "default.psk")
- if exists(own_identity):
+ return os.path.join(own_keystore, "default.psk") + own_identity = _own_psk_path() + if os.path.exists(own_identity): ID, _sep, PSK = open(own_identity).read().partition(':')
secretstring = PSK.rstrip('\n\r')
@@ -192,3 +201,17 @@
+def ExportIDEIdentity(filepath): + own_identity = _own_psk_path() + shutil.copyfile(own_identity, filepath) +def ImportIDEIdentity(filepath): + own_identity = _own_psk_path() + shutil.copyfile(filepath, own_identity) +def RemoveIDEIdentity(): + own_identity = _own_psk_path() + if os.path.exists(own_identity): + os.remove(own_identity) --- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/controls/OwnIdentityPanel.py Fri Mar 14 14:27:23 2025 +0100
@@ -0,0 +1,143 @@
+# See COPYING file for copyrights details. +import PSKManagement as PSK +from dialogs.MsgConfirmDialog import MsgConfirmDialog +class OwnIdentityPanel(wx.Panel): + def __init__(self, parent, log, **kwargs): + wx.Panel.__init__(self, parent, -1, size=(800, 600)) + main_sizer = wx.BoxSizer(wx.VERTICAL) + psk_part = wx.StaticBoxSizer(wx.VERTICAL, self, "PSK") + self.psk_text = wx.TextCtrl(self, style=wx.TE_READONLY | wx.TE_MULTILINE | wx.BORDER_NONE) + psk_part.Add(self.psk_text, 1, border=5, flag=wx.GROW | wx.ALL) + psk_btn_box = wx.BoxSizer(wx.HORIZONTAL) + exportButton = wx.Button(self, label=_("Export PSK")) + self.Bind(wx.EVT_BUTTON, self.OnPSKExportButton, exportButton) + psk_btn_box.Add(exportButton, 0, wx.LEFT | wx.RIGHT, 5) + importButton = wx.Button(self, label=_("Import PSK")) + self.Bind(wx.EVT_BUTTON, self.OnPSKImportButton, importButton) + psk_btn_box.Add(importButton, 0, wx.LEFT | wx.RIGHT, 5) + regenButton = wx.Button(self, label=_("Regen PSK")) + self.Bind(wx.EVT_BUTTON, self.OnPSKRegenButton, regenButton) + psk_btn_box.Add(regenButton, 0, wx.LEFT | wx.RIGHT, 5) + psk_part.Add(psk_btn_box, 0, border=5, flag=wx.GROW | wx.ALL) + main_sizer.Add(psk_part, 1, border=5, flag=wx.GROW | wx.ALL) + cert_part = wx.StaticBoxSizer(wx.VERTICAL, self, "Client Certificate") + self.cert_text = wx.TextCtrl(self, style=wx.TE_READONLY | wx.TE_MULTILINE | wx.BORDER_NONE) + cert_part.Add(self.cert_text, 1, border=5, flag=wx.GROW | wx.ALL) + cert_btn_box = wx.BoxSizer(wx.HORIZONTAL) + importClientCertButton = wx.Button(self, label=_("Import certificate")) + self.Bind(wx.EVT_BUTTON, self.OnImportClientCertButton, importClientCertButton) + cert_btn_box.Add(importClientCertButton, 0, wx.LEFT | wx.RIGHT, 5) + deleteClientCertButton = wx.Button(self, label=_("Delete certificate")) + self.Bind(wx.EVT_BUTTON, self.OnDeleteClientCertButton, deleteClientCertButton) + cert_btn_box.Add(deleteClientCertButton, 0, wx.LEFT | wx.RIGHT, 5) + cert_part.Add(cert_btn_box, 0, border=5, flag=wx.GROW | wx.ALL) + main_sizer.Add(cert_part, 1, border=5, flag=wx.GROW | wx.ALL) + self.SetSizer(main_sizer) + def OnPSKExportButton(self, event): + dialog = wx.FileDialog(self, _("Export IDE PSK"), + wildcard=_("PLCOpen files (*.psk)|*.psk|All files|*.*"), + style=wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT) + if dialog.ShowModal() == wx.ID_OK: + filepath = dialog.GetPath() + if os.path.isdir(os.path.dirname(filepath)): + PSK.ExportIDEIdentity(filepath) + error = _("Can't save PSK to file %s. Error: %s") % filepath + error = _("\"%s\" is not a valid folder!") % os.path.dirname(filepath) + dlg = wx.MessageDialog(self, error, _("Error"), wx.OK | wx.ICON_ERROR) + def _confirm_overwrite_identity(self): + dialog = wx.MessageDialog(self, + _("This will replace IDE Identity. Confirm ?"), + _("Warning"), wx.YES_NO | wx.CANCEL | wx.ICON_QUESTION) + answer = dialog.ShowModal() + return answer == wx.ID_YES + def OnPSKImportButton(self, event): + dialog = wx.FileDialog(self, _("Choose a file"), + wildcard=_("PSK files (*.psk)|*.psk|All files|*.*"), + style=wx.FD_OPEN | wx.FD_FILE_MUST_EXIST) + if dialog.ShowModal() == wx.ID_OK: + if self._confirm_overwrite_identity(): + PSK.ImportIDEIdentity(dialog.GetPath()) + def OnPSKRegenButton(self, event): + if self._confirm_overwrite_identity(): + PSK.RemoveIDEIdentity() + def RefreshPSKText(self): + IDE_ID, secret = PSK.GetIDEIdentity() + text = "Current ID: " + IDE_ID + text = "Failed retrieving IDE ID: " + str(e) + self.psk_text.SetValue(text) + def OnImportClientCertButton(self, event): + dialog = wx.FileDialog(self, _("Choose a file"), + wildcard=_("Certificate files (*.crt)|*.crt|All files|*.*"), + style=wx.FD_OPEN | wx.FD_FILE_MUST_EXIST) + if dialog.ShowModal() == wx.ID_OK: + if self._confirm_overwrite_identity(): + CertManagement.ImportClientCert(dialog.GetPath()) + def OnDeleteClientCertButton(self, event): + if self._confirm_overwrite_identity(): + CertManagement.RemoveClientCert() + def RefreshCertText(self): + text = CertManagement.GetClientCertificateInfo() + self.cert_text.SetValue(text) --- a/dialogs/IDManager.py Mon Mar 24 15:13:16 2025 +0100
+++ b/dialogs/IDManager.py Fri Mar 14 14:27:23 2025 +0100
@@ -3,6 +3,8 @@
from controls.IDBrowser import IDBrowser
from controls.CertBrowser import CertBrowser
+from controls.OwnIdentityPanel import OwnIdentityPanel class IDManageNB(wx.Notebook):
def __init__(self, parent, ctr):
@@ -19,7 +21,7 @@
self.id_browser = IDBrowser(self, ctr)
self.AddPage(self.id_browser, "Controllers")
- win = wx.Panel(self, -1)
+ win = OwnIdentityPanel(self, -1) self.cert_browser = CertBrowser(self, ctr.logger)