diff options
author | Maximilian Hils <git@maximilianhils.com> | 2015-08-11 20:27:34 +0200 |
---|---|---|
committer | Maximilian Hils <git@maximilianhils.com> | 2015-08-11 20:32:14 +0200 |
commit | aef3b626a70de5f385c8f5496c2e49575b5c3e1c (patch) | |
tree | 868b8786906eb7bdc1a269b64494594c5831b54b /libmproxy/protocol2/root_context.py | |
parent | 026330a3b014f24f095b839b29186036854de3bc (diff) | |
download | mitmproxy-aef3b626a70de5f385c8f5496c2e49575b5c3e1c.tar.gz mitmproxy-aef3b626a70de5f385c8f5496c2e49575b5c3e1c.tar.bz2 mitmproxy-aef3b626a70de5f385c8f5496c2e49575b5c3e1c.zip |
wip commit
Diffstat (limited to 'libmproxy/protocol2/root_context.py')
-rw-r--r-- | libmproxy/protocol2/root_context.py | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/libmproxy/protocol2/root_context.py b/libmproxy/protocol2/root_context.py new file mode 100644 index 00000000..cbe596aa --- /dev/null +++ b/libmproxy/protocol2/root_context.py @@ -0,0 +1,32 @@ +from .rawtcp import TcpLayer +from .tls import TlsLayer + + +class RootContext(object): + """ + The outmost context provided to the root layer. + As a consequence, every layer has .client_conn, .channel, .next_layer() and .config. + """ + + def __init__(self, client_conn, config, channel): + self.client_conn = client_conn # Client Connection + self.channel = channel # provides .ask() method to communicate with FlowMaster + self.config = config # Proxy Configuration + + def next_layer(self, top_layer): + """ + This function determines the next layer in the protocol stack. + :param top_layer: the current top layer + :return: The next layer. + """ + + d = top_layer.client_conn.rfile.peek(1) + + 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": + layer = TlsLayer(top_layer, True, True) + else: + layer = TcpLayer(top_layer) + return layer |