PYRO/TLSPSK : fixed typos, used appropriate ciphers (https://github.com/drbild/sslpsk/issues/3), use PYROPSK instead of unresolvable PYROLOCPSK.
authorEdouard Tisserant
Thu, 18 Oct 2018 11:01:14 +0200
changeset 2313 2eaf235270f8
parent 2312 84b3cc18893b
child 2314 e927c101ce6d
PYRO/TLSPSK : fixed typos, used appropriate ciphers (https://github.com/drbild/sslpsk/issues/3), use PYROPSK instead of unresolvable PYROLOCPSK.
connectors/PYRO/PSK_Adapter.py
connectors/PYRO/__init__.py
--- a/connectors/PYRO/PSK_Adapter.py	Mon Oct 15 16:26:59 2018 +0200
+++ b/connectors/PYRO/PSK_Adapter.py	Thu Oct 18 11:01:14 2018 +0200
@@ -1,4 +1,7 @@
+from __future__ import absolute_import
+from __future__ import print_function
 
+import socket
 import sslpsk
 import Pyro
 from Pyro.protocol import _connect_socket,TCPConnection,PYROAdapter
@@ -22,7 +25,8 @@
                 raw_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
                 _connect_socket(raw_sock, URI.address, URI.port, self.timeout)
                 sock = sslpsk.wrap_socket(
-                    raw_sock, psk=Pyro.config.PYROPSK, server_side=False)
+                    raw_sock, psk=Pyro.config.PYROPSK, server_side=False,
+                    ciphers="PSK-AES256-GCM-SHA384:PSK-AES256-CBC-SHA")
                 # all the rest is the same as in Pyro/protocol.py 
 
                 conn=TCPConnection(sock, sock.getpeername())
--- a/connectors/PYRO/__init__.py	Mon Oct 15 16:26:59 2018 +0200
+++ b/connectors/PYRO/__init__.py	Thu Oct 18 11:01:14 2018 +0200
@@ -36,7 +36,7 @@
 import Pyro.util
 from Pyro.errors import PyroError
 
-service_type = '_PYRO._tcp.local.'
+zeroconf_service_type = '_PYRO._tcp.local.'
 # this module attribute contains a list of DNS-SD (Zeroconf) service types
 # supported by this connector confnode.
 #
@@ -53,23 +53,25 @@
     servicetype, location = uri.split("://")
     if servicetype == "PYROS":
         import connectors.PYRO.PSK_Adapter
-        schemename = "PYROLOCPSK"
-        urlpath, ID = location.split('#')
+        schemename = "PYROPSK"
+        url, ID = location.split('#')
         # load PSK from project
         secpath = os.path.join(str(confnodesroot.ProjectPath), 'psk', ID+'.secret')
         if not os.path.exists(secpath):
             confnodesroot.logger.write_error(
                 'Error: Pre-Shared-Key Secret in %s is missing!\n' % secpath)
             return None
-        Pyro.config.PYROPSK = open(secpath).read()
+        Pyro.config.PYROPSK = (open(secpath).read(), ID)
+        # strip ID from URL, so that pyro can understand it.
+        location = url
     else:
         schemename = "PYROLOC"
 
-    if location.find(service_type) != -1:
+    if location.find(zeroconf_service_type) != -1:
         try:
             from zeroconf import Zeroconf
             r = Zeroconf()
-            i = r.get_service_info(service_type, location)
+            i = r.get_service_info(zeroconf_service_type, location)
             if i is None:
                 raise Exception("'%s' not found" % location)
             ip = str(socket.inet_ntoa(i.address))