diff -r d8fb90a2e11f -r 523559fe6352 connectors/PYRO/__init__.py --- a/connectors/PYRO/__init__.py Wed Oct 03 00:05:32 2018 +0200 +++ b/connectors/PYRO/__init__.py Thu Oct 18 18:37:01 2018 +0200 @@ -36,8 +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,43 +52,26 @@ 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" + 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 : 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(), 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)) @@ -161,3 +143,4 @@ return member return PyroProxyProxy() +