Exemplo n.º 1
0
    def _tls_connect(self, tls_server):

        Log.dprint(
            f'[{tls_server}/{self._protocol.name}] Opening secure socket.')  # pylint: disable=no-member
        sock = socket(AF_INET, SOCK_STREAM)
        sock.settimeout(RELAY_TIMEOUT)

        dns_sock = self._tls_context.wrap_socket(sock,
                                                 server_hostname=tls_server)
        try:
            dns_sock.connect((tls_server, PROTO.DNS_TLS))
        except OSError:
            Log.error(
                f'[{tls_server}/{self._protocol.name}] Failed to connect to server: {E}'
            )  # pylint: disable=no-member

        except Exception as E:
            Log.console(
                f'[{tls_server}/{self._protocol.name}] TLS context error while attemping to connect to server: {E}'
            )  # pylint: disable=no-member
            Log.debug(
                f'[{tls_server}/{self._protocol.name}] TLS context error while attemping to connect to server: {E}'
            )  # pylint: disable=no-member

        else:
            self._relay_conn = RELAY_CONN(tls_server, dns_sock, dns_sock.send,
                                          dns_sock.recv, dns_sock.version())

            return True

        return None
Exemplo n.º 2
0
    def _register_new_socket(self):  #, client_query=None):
        for tls_server in self._DNSServer.dns_servers:

            # skipping over known down server
            if (not tls_server[self._protocol]): continue

            # attempting to connect via tls. if successful will return True, otherwise mark server as
            # down and try next server.
            if self._tls_connect(tls_server['ip']): return True

            self.mark_server_down(remote_server=tls_server['ip'])

        else:
            self._DNSServer.tls_up = False

            Log.error(f'[{self._protocol}] No DNS servers available.')