diff options
author | Maximilian Hils <git@maximilianhils.com> | 2015-08-14 10:41:11 +0200 |
---|---|---|
committer | Maximilian Hils <git@maximilianhils.com> | 2015-08-14 10:41:11 +0200 |
commit | 808218f4bc64be8de065604f6509eb75d98fde88 (patch) | |
tree | ae9320c3153761acb9924a5eb52b8a6162c43448 /libmproxy/protocol2/root_context.py | |
parent | aef3b626a70de5f385c8f5496c2e49575b5c3e1c (diff) | |
download | mitmproxy-808218f4bc64be8de065604f6509eb75d98fde88.tar.gz mitmproxy-808218f4bc64be8de065604f6509eb75d98fde88.tar.bz2 mitmproxy-808218f4bc64be8de065604f6509eb75d98fde88.zip |
more work on http layer
Diffstat (limited to 'libmproxy/protocol2/root_context.py')
-rw-r--r-- | libmproxy/protocol2/root_context.py | 29 |
1 files changed, 24 insertions, 5 deletions
diff --git a/libmproxy/protocol2/root_context.py b/libmproxy/protocol2/root_context.py index cbe596aa..3b341778 100644 --- a/libmproxy/protocol2/root_context.py +++ b/libmproxy/protocol2/root_context.py @@ -1,4 +1,6 @@ -from .rawtcp import TcpLayer +from __future__ import (absolute_import, print_function, division) + +from .rawtcp import RawTcpLayer from .tls import TlsLayer @@ -20,13 +22,30 @@ class RootContext(object): :return: The next layer. """ - d = top_layer.client_conn.rfile.peek(1) + d = top_layer.client_conn.rfile.peek(3) + + # TODO: Handle ignore and tcp passthrough + + # TLS ClientHello magic, see http://www.moserware.com/2009/06/first-few-milliseconds-of-https.html#client-hello + is_tls_client_hello = ( + len(d) == 3 and + d[0] == '\x16' and + d[1] == '\x03' and + d[2] in ('\x00', '\x01', '\x02', '\x03') + ) if not d: return - # TLS ClientHello magic, see http://www.moserware.com/2009/06/first-few-milliseconds-of-https.html#client-hello - if d[0] == "\x16": + + if is_tls_client_hello: layer = TlsLayer(top_layer, True, True) else: - layer = TcpLayer(top_layer) + layer = RawTcpLayer(top_layer) return layer + + @property + def layers(self): + return [] + + def __repr__(self): + return "RootContext" |