aboutsummaryrefslogtreecommitdiffstats
path: root/libmproxy/contrib/tls/alert_message.py
diff options
context:
space:
mode:
Diffstat (limited to 'libmproxy/contrib/tls/alert_message.py')
-rw-r--r--libmproxy/contrib/tls/alert_message.py64
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)
+ )