--- a/Beremiz_cli.py Tue Mar 04 14:36:27 2025 +0100
+++ b/Beremiz_cli.py Tue Mar 04 17:20:26 2025 +0100
@@ -101,6 +101,15 @@
return session.controller.stop_project()
+ return session.controller.connect_project() --- a/CLIController.py Tue Mar 04 14:36:27 2025 +0100
+++ b/CLIController.py Tue Mar 04 17:20:26 2025 +0100
@@ -152,6 +152,11 @@
return 0 if self._Stop() else 1
+ def connect_project(self): --- a/PSKManagement.py Tue Mar 04 14:36:27 2025 +0100
+++ b/PSKManagement.py Tue Mar 04 17:20:26 2025 +0100
@@ -5,9 +5,13 @@
+from os.path import join, exists from zipfile import ZipFile
+from binascii import b2a_base64 +from util.paths import AppDataPath # PSK Management Data model :
# [[ID,Desc, LastKnownURI, LastConnect]]
@@ -166,3 +170,25 @@
SaveData(project_path, data)
+ own_keystore = AppDataPath("keystore", "own") + if not exists(own_keystore): + os.makedirs(own_keystore) + own_identity = join(own_keystore, "default.psk") + if exists(own_identity): + ID, _sep, PSK = open(own_identity).read().partition(':') + secretstring = PSK.rstrip('\n\r') + ID = os.urandom(8).hex() + # secret string length is 256 + # b2a_base64 output len is 4/3 input len + secret = os.urandom(192) # int(256/1.3333) + secretstring = b2a_base64(secret).decode() + PSKstring = ID+":"+secretstring + with open(own_identity, 'w') as f: + return ID, secretstring --- a/connectors/WAMP/__init__.py Tue Mar 04 14:36:27 2025 +0100
+++ b/connectors/WAMP/__init__.py Tue Mar 04 17:20:26 2025 +0100
@@ -51,7 +51,7 @@
class WampSession(wamp.ApplicationSession):
- user = self.config.extra["ID"]
+ user = self.config.extra["IDE_ID"] self.join(self.config.realm, ["wampcra"], user)
def onChallenge(self, challenge):
@@ -76,7 +76,7 @@
- print('WAMP session joined for :', self.config.extra["ID"])
+ print('WAMP session joined for :', self.config.extra["IDE_ID"]) def onLeave(self, details):
@@ -86,17 +86,18 @@
def _WAMP_connector_factory(cls, uri, confnodesroot):
- WAMP://127.0.0.1:12345/path#realm#ID
- WAMPS://127.0.0.1:12345/path#realm#ID
+ WAMP://127.0.0.1:12345/path#realm#PLC_ID + WAMPS://127.0.0.1:12345/path#realm#PLC_ID scheme, location = uri.split("://")
- urlpath, realm, ID = location.split('#')
+ urlpath, realm, PLC_ID = location.split('#') urlprefix = {"WAMP": "ws",
url = urlprefix+"://"+urlpath
CN = urlpath.split("/")[0].split(":")[0]
- secret = PSK.GetSecret(confnodesroot.ProjectPath, ID)
+ IDE_ID, secret = PSK.GetIDEIdentity() trust_store = Cert.GetCertPath(confnodesroot.ProjectPath, CN)
confnodesroot.logger.write_error(
@@ -113,7 +114,7 @@
component_config = types.ComponentConfig(
session_factory = wamp.ApplicationSessionFactory(
@@ -169,7 +170,7 @@
def WampSessionProcMapper(self, funcname):
- wampfuncname = str('.'.join((ID, funcname)))
+ wampfuncname = str('.'.join((PLC_ID, funcname))) def catcher_func(*args, **kwargs):
if _WampSession is not None:
--- a/tests/cli_tests/wamp_test.bash Tue Mar 04 14:36:27 2025 +0100
+++ b/tests/cli_tests/wamp_test.bash Tue Mar 04 17:20:26 2025 +0100
@@ -2,7 +2,7 @@
rm -f ./CLI_OK ./PLC_OK ./PLC_CONNECTED
-# Start runtime one first time to generate PSK
+# Start runtime one first time to generate PLC PSK $BEREMIZPYTHONPATH $BEREMIZPATH/Beremiz_service.py -s psk.txt -n test_wamp_ID -x 0 &
res=110 # default to ETIMEDOUT
@@ -25,7 +25,38 @@
-IFS=':' read -r wamp_ID wamp_secret < psk.txt
+IFS=':' read -r PLC_wamp_ID PLC_wamp_secret < psk.txt +cp -a $BEREMIZPATH/tests/projects/wamp . +# Start CLI one first time to generate IDE PSK +IDE_PSK=$HOME/.local/share/beremiz/keystore/own/default.psk +$BEREMIZPYTHONPATH $BEREMIZPATH/Beremiz_cli.py -k \ + --project-home wamp connect & +res=110 # default to ETIMEDOUT + if [[ -a $IDE_PSK ]]; then + echo waiting IDE PSK.... $c +if [ "$res" != "0" ] ; then + echo timeout generating IDE PSK. +IFS=':' read -r IDE_wamp_ID IDE_wamp_secret < $IDE_PSK # Prepare crossbar server configuration
@@ -34,7 +65,6 @@
-addext "subjectAltName = DNS:localhost" \
-out ./.crossbar/server.crt
cat > .crossbar/config.json <<JsonEnd
@@ -87,8 +117,12 @@
- "secret": "${wamp_secret}",
+ "secret": "${IDE_wamp_secret}", + "role": "authenticated" + "secret": "${PLC_wamp_secret}", @@ -129,7 +163,7 @@
# Prepare runtime Wamp config
cat > wampconf.json <<JsonEnd
+ "ID": "${PLC_wamp_ID}", @@ -182,12 +216,7 @@
-cp -a $BEREMIZPATH/tests/projects/wamp .
-# place PSK so that IDE already knows runtime
-cp psk.txt wamp/psk/${wamp_ID}.secret
-# Re-use self-signed server cert for client
+# Re-use self-signed server cert for client in test project cp .crossbar/server.crt wamp/cert/localhost.crt
@@ -195,7 +224,7 @@
# used in tests instead of 127.0.0.1
# Use CLI to build transfer and start PLC
-setsid $BEREMIZPYTHONPATH $BEREMIZPATH/Beremiz_cli.py -k \
+$BEREMIZPYTHONPATH $BEREMIZPATH/Beremiz_cli.py -k \ --project-home wamp build transfer run &> >(
--- a/util/paths.py Tue Mar 04 14:36:27 2025 +0100
+++ b/util/paths.py Tue Mar 04 17:20:26 2025 +0100
@@ -61,3 +61,12 @@
Return path of files in Beremiz project
return os.path.join(AbsParentDir(__file__, 1), *names)
+def AppDataPath(*names): + Return path of files in Beremiz project + return os.path.join(os.environ["HOME"], ".local", "share", "beremiz", *names) + return os.path.join(os.environ["APPDATA"], "Beremiz", *names)