connectors/PYRO/__init__.py
changeset 2312 84b3cc18893b
parent 2010 bb9c28bd204f
child 2313 2eaf235270f8
--- a/connectors/PYRO/__init__.py	Mon Oct 15 15:27:47 2018 +0200
+++ b/connectors/PYRO/__init__.py	Mon Oct 15 16:26:59 2018 +0200
@@ -36,7 +36,6 @@
 import Pyro.util
 from Pyro.errors import PyroError
 
-
 service_type = '_PYRO._tcp.local.'
 # this module attribute contains a list of DNS-SD (Zeroconf) service types
 # supported by this connector confnode.
@@ -53,38 +52,19 @@
 
     servicetype, location = uri.split("://")
     if servicetype == "PYROS":
-        schemename = "PYROLOCSSL"
-        # Protect against name->IP substitution in Pyro3
-        Pyro.config.PYRO_DNS_URI = True
-        # Beware Pyro lib need str path, not unicode
-        # don't rely on PYRO_STORAGE ! see documentation
-        Pyro.config.PYROSSL_CERTDIR = os.path.abspath(str(confnodesroot.ProjectPath) + '/certs')
-        if not os.path.exists(Pyro.config.PYROSSL_CERTDIR):
+        import connectors.PYRO.PSK_Adapter
+        schemename = "PYROLOCPSK"
+        urlpath, 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 : the directory %s is missing for SSL certificates (certs_dir).'
-                'Please fix it in your project.\n' % Pyro.config.PYROSSL_CERTDIR)
+                'Error: Pre-Shared-Key Secret in %s is missing!\n' % secpath)
             return None
-        else:
-            confnodesroot.logger.write(_("PYRO using certificates in '%s' \n")
-                                       % (Pyro.config.PYROSSL_CERTDIR))
-        Pyro.config.PYROSSL_CERT = "client.crt"
-        Pyro.config.PYROSSL_KEY = "client.key"
-
-        # Ugly Monkey Patching
-        def _gettimeout(self):
-            return self.timeout
-
-        def _settimeout(self, timeout):
-            self.timeout = timeout
-        from M2Crypto.SSL import Connection  # pylint: disable=import-error
-        Connection.timeout = None
-        Connection.gettimeout = _gettimeout
-        Connection.settimeout = _settimeout
-        # M2Crypto.SSL.Checker.WrongHost: Peer certificate commonName does not
-        # match host, expected 127.0.0.1, got server
-        Connection.clientPostConnectionCheck = None
+        Pyro.config.PYROPSK = open(secpath).read()
     else:
         schemename = "PYROLOC"
+
     if location.find(service_type) != -1:
         try:
             from zeroconf import Zeroconf
@@ -161,3 +141,4 @@
             return member
 
     return PyroProxyProxy()
+