diff options
author | Maximilian Hils <git@maximilianhils.com> | 2015-08-26 05:39:00 +0200 |
---|---|---|
committer | Maximilian Hils <git@maximilianhils.com> | 2015-08-26 05:39:00 +0200 |
commit | 3fa65c48dd2880a806985e273b3fa280103e2a7b (patch) | |
tree | 7ca2dabb2789462424ff0d0c28e3399d57540345 /libmproxy/contrib/tls/utils.py | |
parent | 8ce0de8bed5fbd2c42e7b43ee553e065e1c08a4c (diff) | |
download | mitmproxy-3fa65c48dd2880a806985e273b3fa280103e2a7b.tar.gz mitmproxy-3fa65c48dd2880a806985e273b3fa280103e2a7b.tar.bz2 mitmproxy-3fa65c48dd2880a806985e273b3fa280103e2a7b.zip |
manually read tls clienthello [wip]
Diffstat (limited to 'libmproxy/contrib/tls/utils.py')
-rw-r--r-- | libmproxy/contrib/tls/utils.py | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/libmproxy/contrib/tls/utils.py b/libmproxy/contrib/tls/utils.py new file mode 100644 index 00000000..a971af49 --- /dev/null +++ b/libmproxy/contrib/tls/utils.py @@ -0,0 +1,52 @@ +# This file is dual licensed under the terms of the Apache License, Version +# 2.0, and the BSD License. See the LICENSE file in the root of this repository +# for complete details. + +from __future__ import absolute_import, division, print_function + +import construct + +import six + + +class _UBInt24(construct.Adapter): + def _encode(self, obj, context): + return ( + six.int2byte((obj & 0xFF0000) >> 16) + + six.int2byte((obj & 0x00FF00) >> 8) + + six.int2byte(obj & 0x0000FF) + ) + + def _decode(self, obj, context): + obj = bytearray(obj) + return (obj[0] << 16 | obj[1] << 8 | obj[2]) + + +def UBInt24(name): # noqa + return _UBInt24(construct.Bytes(name, 3)) + + +def LengthPrefixedArray(subcon, length_field=construct.UBInt8("length")): + """ + An array prefixed by a byte length field. + + In contrast to construct.macros.PrefixedArray, + the length field signifies the number of bytes, not the number of elements. + """ + subcon_with_pos = construct.Struct( + subcon.name, + construct.Embed(subcon), + construct.Anchor("__current_pos") + ) + + return construct.Embed( + construct.Struct( + "", + length_field, + construct.Anchor("__start_pos"), + construct.RepeatUntil( + lambda obj, ctx: obj.__current_pos == ctx.__start_pos + getattr(ctx, length_field.name), + subcon_with_pos + ), + ) + )
\ No newline at end of file |