https_server.py
def main():
    """Main method that runs and handles the HTTPs server concurrently

    Args:
        void

    Returns:
        void
    """

    parser = argparse.ArgumentParser()
    setup_arguments(parser)
    args = parser.parse_args()

    init_logger(args.debug)

    _LOGGER.debug("Initializing Socket")

    serv = socket.socket(socket.AF_INET, socket.SOCK_STREAM, 0)
    serv.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
    serv.setblocking(0)
    serv.bind((HOST, PORT))
    serv.listen(10)

    # queue for sending messages back to the clients
    message_queues = {}

    poller = select.poll()
    poller.register(serv, READ_ONLY)

    fd_to_socket = {serv.fileno(): serv,}
    sock_to_ja3 = {}

    _LOGGER.info("Launching Server on https://%s:%d", ("localhost" if HOST == "" else HOST), PORT)

    while True:
        events = poller.poll(TIMEOUT)

        for file_desc, flag in events:
            sock = fd_to_socket[file_desc]

            if flag & (select.POLLIN | select.POLLPRI):
                # server socket gets a new connection
                if sock is serv:
                    handle_new_conn(sock, fd_to_socket, poller)

                # not init connection to the server
                else:
                    # checks if this is the second event fired and need to grab the TLS handshake
                    handshake = tls_handshake(sock, message_queues, \
                            fd_to_socket, sock_to_ja3, poller)
                    # checks either error or non tls handshake
                    if handshake is not None and not handshake:
                        # check if there is an HTTP GET request because
                        # tls_handshake returned False
                        if not retrieve_http_req(sock, message_queues, sock_to_ja3, poller):
                            # we didn't get a GET, so close it
                            cleanup_connection(sock, poller, message_queues, sock_to_ja3)

            # client hangs up
            elif flag & select.POLLHUP:
                cleanup_connection(sock, poller)

            # we have output to send to the client
            elif flag & select.POLLOUT:
                try:
                    next_msg = message_queues[sock].get_nowait()
                # we've got nothing to send it
                except queue.Empty:
                    poller.modify(sock, READ_ONLY)

                else:
                    # respond with the message
                    try:
                        sock.send(next_msg)
                    except OSError as _:
                        _LOGGER.error("Client hung up before we could send back"
                                      "HTTP response")
                    # we do not keep any more connections after we use the client
                    # for the JA3 fingerprint
                    finally:
                        cleanup_connection(sock, poller, message_queues, sock_to_ja3)

            # little error happened
            elif flag & select.POLLERR:
                # close everything
                cleanup_connection(sock, poller, message_queues, sock_to_ja3)
Main method that runs and handles the HTTPs server concurrently

    Args:
        void

    Returns:
        void
    
Main method that runs and handles the HTTPs server concurrently
Args:
void

void
Main method that runs and handles the HTTPs server concurrently Args : void void
def main():
    parser = argparse.ArgumentParser()
    setup_arguments(parser)
    args = parser.parse_args()
    init_logger(args.debug)
    _LOGGER.debug("Initializing Socket")
    serv = socket.socket(socket.AF_INET, socket.SOCK_STREAM, 0)
    serv.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
    serv.setblocking(0)
    serv.bind((HOST, PORT))
    serv.listen(10)
    message_queues = {}
    poller = select.poll()
    poller.register(serv, READ_ONLY)
    fd_to_socket = {serv.fileno(): serv,}
    sock_to_ja3 = {}
    _LOGGER.info("Launching Server on https://%s:%d", ("localhost" if HOST == "" else HOST), PORT)
    while True:
        events = poller.poll(TIMEOUT)
        for file_desc, flag in events:
            sock = fd_to_socket[file_desc]
            if flag & (select.POLLIN | select.POLLPRI):
                if sock is serv:
                    handle_new_conn(sock, fd_to_socket, poller)
                else:
                    handshake = tls_handshake(sock, message_queues, \
                            fd_to_socket, sock_to_ja3, poller)
                    if handshake is not None and not handshake:
                        if not retrieve_http_req(sock, message_queues, sock_to_ja3, poller):
                            cleanup_connection(sock, poller, message_queues, sock_to_ja3)
            elif flag & select.POLLHUP:
                cleanup_connection(sock, poller)
            elif flag & select.POLLOUT:
                try:
                    next_msg = message_queues[sock].get_nowait()
                except queue.Empty:
                    poller.modify(sock, READ_ONLY)
                else:
                    try:
                        sock.send(next_msg)
                    except OSError as _:
                        _LOGGER.error("Client hung up before we could send back"
                                      "HTTP response")
                    finally:
                        cleanup_connection(sock, poller, message_queues, sock_to_ja3)
            elif flag & select.POLLERR:
                cleanup_connection(sock, poller, message_queues, sock_to_ja3)
def main ( ) : parser = argparse . ArgumentParser ( ) setup_arguments ( parser ) args = parser . parse_args ( ) init_logger ( args . debug ) _LOGGER . debug ( "Initializing Socket" ) serv = socket . socket ( socket . AF_INET , socket . SOCK_STREAM , 0 ) serv . setsockopt ( socket . SOL_SOCKET , socket . SO_REUSEADDR , 1 ) serv . setblocking ( 0 ) serv . bind ( ( HOST , PORT ) ) serv . listen ( 10 ) message_queues = { } poller = select . poll ( ) poller . register ( serv , READ_ONLY ) fd_to_socket = { serv . fileno ( ) : serv , } sock_to_ja3 = { } _LOGGER . info ( "Launching Server on https://%s:%d" , ( "localhost" if HOST == "" else HOST ) , PORT ) while True : events = poller . poll ( TIMEOUT ) for file_desc , flag in events : sock = fd_to_socket [ file_desc ] if flag & ( select . POLLIN | select . POLLPRI ) : if sock is serv : handle_new_conn ( sock , fd_to_socket , poller ) else : handshake = tls_handshake ( sock , message_queues , fd_to_socket , sock_to_ja3 , poller ) if handshake is not None and not handshake : if not retrieve_http_req ( sock , message_queues , sock_to_ja3 , poller ) : cleanup_connection ( sock , poller , message_queues , sock_to_ja3 ) elif flag & select . POLLHUP : cleanup_connection ( sock , poller ) elif flag & select . POLLOUT : try : next_msg = message_queues [ sock ] . get_nowait ( ) except queue . Empty : poller . modify ( sock , READ_ONLY ) else : try : sock . send ( next_msg ) except OSError as _ : _LOGGER . error ( "Client hung up before we could send back" "HTTP response" ) finally : cleanup_connection ( sock , poller , message_queues , sock_to_ja3 ) elif flag & select . POLLERR : cleanup_connection ( sock , poller , message_queues , sock_to_ja3 )
Main method that runs and handles the HTTPs server concurrently
Args:
void
Main method that runs and handles the HTTPs server concurrently Args : void
"""Main method that runs and handles the HTTPs server concurrently

    Args:
        void

    Returns:
        void
    """ # queue for sending messages back to the clients # server socket gets a new connection # not init connection to the server # checks if this is the second event fired and need to grab the TLS handshake # checks either error or non tls handshake # check if there is an HTTP GET request because # tls_handshake returned False # we didn't get a GET, so close it # client hangs up # we have output to send to the client # we've got nothing to send it # respond with the message # we do not keep any more connections after we use the client # for the JA3 fingerprint # little error happened # close everything