commit 207d44712301eb3ef2387ddd057dfe9e8c2cf636
parent bfc083b421ba7e508201acacee187561ddea550d
Author: Daniel Barlow <dan@telent.net>
Date: Fri, 6 Mar 2026 18:03:45 +0000
client: parse config file instead of hardcoding key pathname
Diffstat:
2 files changed, 31 insertions(+), 7 deletions(-)
diff --git a/client.conf b/client.conf
@@ -0,0 +1,3 @@
+BlePrivateKeyFile=keys/client.key
+BlePeerKeyFile=keys/device.pub
+OtaPrivateKeyFile=privkey.bin
diff --git a/client/eculocate.py b/client/eculocate.py
@@ -13,6 +13,7 @@ import secrets
import nacl
import nacl.hash
from nacl.encoding import RawEncoder
+import configparser
from nacl.signing import SigningKey
@@ -36,12 +37,32 @@ class ZListener(ServiceListener):
self.client.host_addresses[name] = (socket.inet_ntoa(info.addresses[0]), info.port)
self.client.on_services_changed()
+class Config():
+ def __init__(self, pathname):
+ config = configparser.ConfigParser(allow_unnamed_section=True)
+ config.read(pathname)
+ self.config = config
+ self._ota_private_key = None
+
+ def ble_private_key(self):
+ pathname = self.config.get(configparser.UNNAMED_SECTION, 'BlePrivateKeyFile')
+
+ def ble_peer_key(self):
+ pathname = self.config.get(configparser.UNNAMED_SECTION, 'BlePeerKeyFile')
+
+ def ota_private_key(self):
+ if not self._ota_private_key:
+ pathname = self.config.get(configparser.UNNAMED_SECTION, 'OtaPrivateKeyFile')
+ with open(pathname, "rb") as f:
+ self._ota_private_key = SigningKey(f.read(), encoder=RawEncoder)
+
+ return self._ota_private_key
class Client():
- def __init__(self, private_key):
+ def __init__(self, config):
self.selected_service_name = None
self.bytes_recorded = 0
- self.private_key = private_key
+ self.private_key = config.ota_private_key()
self.started = False
self.host_addresses = {}
@@ -128,13 +149,12 @@ class Client():
if __name__ == '__main__':
import pprint
- with open("privkey.bin", "rb") as f:
- signing_key = SigningKey(f.read(), encoder=RawEncoder)
exists = False
- name = sys.argv[1]
- timeout = int(sys.argv[2])
+ conf_file = sys.argv[1]
+ name = sys.argv[2]
+ timeout = int(sys.argv[3])
fqname = f"{name}._keihin._udp.local."
@@ -145,7 +165,8 @@ if __name__ == '__main__':
if self.host_addresses.get(fqname, False):
print(f"found {fqname}")
- client = MyClient(signing_key)
+ config = Config(conf_file)
+ client = MyClient(config)
while not exists:
time.sleep(2)