Esempio n. 1
0
 def get_server_bindaddr(k, bindaddrs):
     serverBindAddr = {}
     bindaddrs = env_has_k(k, bindaddrs).split(',')
     for bindaddr in bindaddrs:
         (transport_name, addrport) = bindaddr.split('-')
         (addr, port) = util.parse_addr_spec(addrport)
         serverBindAddr[transport_name] = (addr, port)
     return serverBindAddr
Esempio n. 2
0
 def get_server_bindaddr(k, bindaddrs):
     serverBindAddr = {}
     bindaddrs = env_has_k(k, bindaddrs).split(',')
     for bindaddr in bindaddrs:
         (transport_name, addrport) = bindaddr.split('-')
         (addr, port) = util.parse_addr_spec(addrport)
         serverBindAddr[transport_name] = (addr, port)
     return serverBindAddr
Esempio n. 3
0
    def __init__(self):
        config.Config.__init__(self)

        """
        TOR_PT_EXTENDED_SERVER_PORT is optional; tor uses the empty
        string as its value if it does not support the Extended
        ORPort.
        """
        ext_orport_tmp = self.get('TOR_PT_EXTENDED_SERVER_PORT')
        if ext_orport_tmp == '':
            self.extendedORPort = None
        else:
            self.extendedORPort = self.get_addrport('TOR_PT_EXTENDED_SERVER_PORT')

        if self.check('TOR_PT_AUTH_COOKIE_FILE'):
            self.authCookieFile = self.get('TOR_PT_AUTH_COOKIE_FILE')
        else:
            self.authCookieFile = None

        # Check that either both Extended ORPort and the Extended
        # ORPort Authentication Cookie are present, or neither.
        if self.extendedORPort and not self.authCookieFile:
            err = "Extended ORPort address provided, but no cookie file."
            self.writeEnvError(err)
            raise config.EnvError(err)
        elif self.authCookieFile and not self.extendedORPort:
            err = "Extended ORPort Authentication cookie file provided, but no Extended ORPort address."
            self.writeEnvError(err)
            raise config.EnvError(err)

        # Get ORPort.
        self.ORPort = self.get_addrport('TOR_PT_ORPORT')

        # Get bind addresses.
        self.serverBindAddr = {}
        bindaddrs = self.get('TOR_PT_SERVER_BINDADDR').split(',')
        for bindaddr in bindaddrs:
            (transport_name, addrport) = bindaddr.split('-')

            try:
                (addr, port) = util.parse_addr_spec(addrport)
            except ValueError, err:
                self.writeEnvError(err)
                raise config.EnvError(err)

            self.serverBindAddr[transport_name] = (addr, port)
Esempio n. 4
0
    def get_addrport(self, key):
        """
        Parse an environment variable holding an address:port value.

        :param str key: Environment variable key.

        :returns: tuple -- (address,port)

        :raises: :class:`pyptlib.config.EnvError` if string was not in address:port format.
        """

        string = self.get(key)
        try:
            return util.parse_addr_spec(string)
        except ValueError, err:
            self.writeEnvError(err)
            raise config.EnvError(err)
Esempio n. 5
0
def parseProxyURI(uri_str):
    try:
        uri = urlsplit(uri_str, allow_fragments=False)
    except Exception as e:
        raise ProxyError("Error parsing proxy URI (%s)" % uri_str)

    if not uri.scheme in SUPPORTED_PROXY_SCHEMES:
        raise ProxyError("Invalid scheme (%s)" % uri.scheme)
    if uri.scheme == 'socks4a' and uri.password:
        raise ProxyError("Proxy URI specified SOCKS4a and a password")
    elif uri.scheme == 'socks5':
        if uri.username and not uri.password:
            raise ProxyError(
                "Proxy URI specified SOCKS5, a username and no password")
        if uri.password and not uri.username:
            raise ProxyError(
                "Proxy URI specified SOCKS5, a password and no username")
        if uri.username and len(uri.username) > 255:
            raise ProxyError("Proxy URI specified an oversized username")
        if uri.password and len(uri.password) > 255:
            raise ProxyError("Proxy URI specified an oversized password")
    if uri.netloc == '':
        raise ProxyError("Proxy URI is missing a netloc (%s)" % uri.netloc)
    if not uri.hostname:
        raise ProxyError("Proxy URI is missing a hostname")
    if not uri.port:
        raise ProxyError("Proxy URI is missing a port")
    if uri.path != '':
        raise ProxyError("Proxy URI has a path when none expected (%s)" %
                         uri.path)
    if uri.query != '':
        raise ProxyError("Proxy URI has query when none expected (%s)" %
                         uri.query)
    try:
        addr_str = uri.hostname + ":" + str(uri.port)
        host, port = util.parse_addr_spec(addr_str)
    except:
        raise ProxyError("Proxy URI has invalid netloc (%s)" % uri.netloc)
    return uri
Esempio n. 6
0
    if uri.scheme == 'socks4a' and uri.password:
        raise ProxyError("Proxy URI specified SOCKS4a and a password")
    elif uri.scheme == 'socks5':
        if uri.username and not uri.password:
            raise ProxyError("Proxy URI specified SOCKS5, a username and no password")
        if uri.password and not uri.username:
            raise ProxyError("Proxy URI specified SOCKS5, a password and no username")
        if uri.username and len(uri.username) > 255:
            raise ProxyError("Proxy URI specified an oversized username")
        if uri.password and len(uri.password) > 255:
            raise ProxyError("Proxy URI specified an oversized password")
    if uri.netloc == '':
        raise ProxyError("Proxy URI is missing a netloc (%s)" % uri.netloc)
    if not uri.hostname:
        raise ProxyError("Proxy URI is missing a hostname")
    if not uri.port:
        raise ProxyError("Proxy URI is missing a port")
    if uri.path != '':
        raise ProxyError("Proxy URI has a path when none expected (%s)" %
                         uri.path)
    if uri.query != '':
        raise ProxyError("Proxy URI has query when none expected (%s)" %
                         uri.query)
    try:
        addr_str = uri.hostname + ":" + str(uri.port)
        host, port = util.parse_addr_spec(addr_str)
    except:
        raise ProxyError("Proxy URI has invalid netloc (%s)" %
                         uri.netloc)
    return uri
Esempio n. 7
0
        raise ProxyError("Proxy URI specified SOCKS4a and a password")
    elif uri.scheme == 'socks5':
        if uri.username and not uri.password:
            raise ProxyError(
                "Proxy URI specified SOCKS5, a username and no password")
        if uri.password and not uri.username:
            raise ProxyError(
                "Proxy URI specified SOCKS5, a password and no username")
        if uri.username and len(uri.username) > 255:
            raise ProxyError("Proxy URI specified an oversized username")
        if uri.password and len(uri.password) > 255:
            raise ProxyError("Proxy URI specified an oversized password")
    if uri.netloc == '':
        raise ProxyError("Proxy URI is missing a netloc (%s)" % uri.netloc)
    if not uri.hostname:
        raise ProxyError("Proxy URI is missing a hostname")
    if not uri.port:
        raise ProxyError("Proxy URI is missing a port")
    if uri.path != '':
        raise ProxyError("Proxy URI has a path when none expected (%s)" %
                         uri.path)
    if uri.query != '':
        raise ProxyError("Proxy URI has query when none expected (%s)" %
                         uri.query)
    try:
        addr_str = uri.hostname + ":" + str(uri.port)
        host, port = util.parse_addr_spec(addr_str)
    except:
        raise ProxyError("Proxy URI has invalid netloc (%s)" % uri.netloc)
    return uri
Esempio n. 8
0
 def empty_or_valid_addr(k, v):
     v = env_has_k(k, v)
     if v == '': return None
     return util.parse_addr_spec(v)
Esempio n. 9
0
 def empty_or_valid_addr(k, v):
     v = env_has_k(k, v)
     if v == '': return None
     return util.parse_addr_spec(v)