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/alert_message.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/alert_message.py')
-rw-r--r-- | libmproxy/contrib/tls/alert_message.py | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/libmproxy/contrib/tls/alert_message.py b/libmproxy/contrib/tls/alert_message.py new file mode 100644 index 00000000..ef02f56d --- /dev/null +++ b/libmproxy/contrib/tls/alert_message.py @@ -0,0 +1,64 @@ +# 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 + +from enum import Enum + +from characteristic import attributes + +from . import _constructs + + +class AlertLevel(Enum): + WARNING = 1 + FATAL = 2 + + +class AlertDescription(Enum): + CLOSE_NOTIFY = 0 + UNEXPECTED_MESSAGE = 10 + BAD_RECORD_MAC = 20 + DECRYPTION_FAILED_RESERVED = 21 + RECORD_OVERFLOW = 22 + DECOMPRESSION_FAILURE = 30 + HANDSHAKE_FAILURE = 40 + NO_CERTIFICATE_RESERVED = 41 + BAD_CERTIFICATE = 42 + UNSUPPORTED_CERTIFICATE = 43 + CERTIFICATE_REVOKED = 44 + CERTIFICATE_EXPIRED = 45 + CERTIFICATE_UNKNOWN = 46 + ILLEGAL_PARAMETER = 47 + UNKNOWN_CA = 48 + ACCESS_DENIED = 49 + DECODE_ERROR = 50 + DECRYPT_ERROR = 51 + EXPORT_RESTRICTION_RESERVED = 60 + PROTOCOL_VERSION = 70 + INSUFFICIENT_SECURITY = 71 + INTERNAL_ERROR = 80 + USER_CANCELED = 90 + NO_RENEGOTIATION = 100 + UNSUPPORTED_EXTENSION = 110 + + +@attributes(['level', 'description']) +class Alert(object): + """ + An object representing an Alert message. + """ + @classmethod + def from_bytes(cls, bytes): + """ + Parse an ``Alert`` struct. + + :param bytes: the bytes representing the input. + :return: Alert object. + """ + construct = _constructs.Alert.parse(bytes) + return cls( + level=AlertLevel(construct.level), + description=AlertDescription(construct.description) + ) |