Is it possible using a Python twisted web server to access the raw bytes of TLS Handshake packets for further processing, such as counting ja3 for client-hello?
I tried use call dataReceived method but its impossible by web server.
I think need redefine custom class for TLSMemoryBIOProtocol, but I can't call constructor for it.
class CustomTLSMemoryBIOProtocol(tls.TLSMemoryBIOProtocol):
def __init__(self, factory, wrappedProtocol, _connectWrapped=True, client_hello = b""):
super().__init__(factory, wrappedProtocol, _connectWrapped=True)
self.client_hello = client_hello
def dataReceived(self, bytes):
if len(bytes) > 5 and bytes[:3] == b'\x16\x03\x01' and bytes[5] == 1:
print("CustomTLSMemoryBIOProtocol dataReceived")
self.client_hello = bytes
super().dataReceived(bytes)
It's my current code:
def get_https_endpoint():
ssl_context = ssl.DefaultOpenSSLContextFactory(
"services/web/certs/key.pem", "services/web/certs/cert.pem"
)
https_factory = server.Site(IndexResource())
return reactor.listenSSL(
config["service"]["port"]["https"], https_factory, ssl_context
)