Log ClientHellos nicely
This commit is contained in:
parent
97d01a088c
commit
3abe65a551
12
neomi.py
12
neomi.py
|
@ -248,6 +248,8 @@ class RequestError(OneArgumentException):
|
||||||
class EmptyRequestError(OneArgumentException):
|
class EmptyRequestError(OneArgumentException):
|
||||||
text = 'Got an empty request: %s'
|
text = 'Got an empty request: %s'
|
||||||
|
|
||||||
|
class TLSClientHelloError(Exception): pass
|
||||||
|
|
||||||
class Protocol(enum.Enum):
|
class Protocol(enum.Enum):
|
||||||
gopher, gopherplus, http = range(3)
|
gopher, gopherplus, http = range(3)
|
||||||
|
|
||||||
|
@ -280,6 +282,10 @@ def get_request(sockreader, *, config):
|
||||||
if len(request) >= config.request_max_size:
|
if len(request) >= config.request_max_size:
|
||||||
raise RequestError('Request too long')
|
raise RequestError('Request too long')
|
||||||
|
|
||||||
|
# We have enough data to recognise a TLS 1.1+ ClientHello
|
||||||
|
if len(request) >= 3 and request[:3] == b'\x16\x03\x01':
|
||||||
|
raise TLSClientHelloError('Got a TLS ClientHello')
|
||||||
|
|
||||||
# We have enough data to recognise a HTTP request
|
# We have enough data to recognise a HTTP request
|
||||||
if protocol is None and len(request) >= 5:
|
if protocol is None and len(request) >= 5:
|
||||||
# Does it look like a HTTP GET request?
|
# Does it look like a HTTP GET request?
|
||||||
|
@ -354,7 +360,11 @@ def get_request(sockreader, *, config):
|
||||||
# Found the end of the path
|
# Found the end of the path
|
||||||
path_end = index
|
path_end = index
|
||||||
|
|
||||||
path = request[:path_end].decode('utf-8')
|
try:
|
||||||
|
path = request[:path_end].decode('utf-8')
|
||||||
|
except UnicodeDecodeError as err:
|
||||||
|
print(request)#debg
|
||||||
|
raise err
|
||||||
|
|
||||||
# If another field was present, check to see if it marks a Gopher+ request
|
# If another field was present, check to see if it marks a Gopher+ request
|
||||||
if chr(request[index]) == '\t':
|
if chr(request[index]) == '\t':
|
||||||
|
|
Loading…
Reference in New Issue