mitmproxy/libmproxy/contrib/tls/alert_message.py

65 lines
1.6 KiB
Python
Raw Normal View History

2015-08-26 03:39:00 +00:00
# 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)
)