Botan  1.11.15
src/lib/tls/tls_alert.h
Go to the documentation of this file.
00001 /*
00002 * Alert Message
00003 * (C) 2004-2006,2011,2012 Jack Lloyd
00004 *
00005 * Botan is released under the Simplified BSD License (see license.txt)
00006 */
00007 
00008 #ifndef BOTAN_TLS_ALERT_H__
00009 #define BOTAN_TLS_ALERT_H__
00010 
00011 #include <botan/secmem.h>
00012 #include <string>
00013 
00014 namespace Botan {
00015 
00016 namespace TLS {
00017 
00018 /**
00019 * SSL/TLS Alert Message
00020 */
00021 class BOTAN_DLL Alert
00022    {
00023    public:
00024       /**
00025       * Type codes for TLS alerts
00026       */
00027       enum Type {
00028          CLOSE_NOTIFY                    = 0,
00029          UNEXPECTED_MESSAGE              = 10,
00030          BAD_RECORD_MAC                  = 20,
00031          DECRYPTION_FAILED               = 21,
00032          RECORD_OVERFLOW                 = 22,
00033          DECOMPRESSION_FAILURE           = 30,
00034          HANDSHAKE_FAILURE               = 40,
00035          NO_CERTIFICATE                  = 41, // SSLv3 only
00036          BAD_CERTIFICATE                 = 42,
00037          UNSUPPORTED_CERTIFICATE         = 43,
00038          CERTIFICATE_REVOKED             = 44,
00039          CERTIFICATE_EXPIRED             = 45,
00040          CERTIFICATE_UNKNOWN             = 46,
00041          ILLEGAL_PARAMETER               = 47,
00042          UNKNOWN_CA                      = 48,
00043          ACCESS_DENIED                   = 49,
00044          DECODE_ERROR                    = 50,
00045          DECRYPT_ERROR                   = 51,
00046          EXPORT_RESTRICTION              = 60,
00047          PROTOCOL_VERSION                = 70,
00048          INSUFFICIENT_SECURITY           = 71,
00049          INTERNAL_ERROR                  = 80,
00050          INAPPROPRIATE_FALLBACK          = 86,
00051          USER_CANCELED                   = 90,
00052          NO_RENEGOTIATION                = 100,
00053          UNSUPPORTED_EXTENSION           = 110,
00054          CERTIFICATE_UNOBTAINABLE        = 111,
00055          UNRECOGNIZED_NAME               = 112,
00056          BAD_CERTIFICATE_STATUS_RESPONSE = 113,
00057          BAD_CERTIFICATE_HASH_VALUE      = 114,
00058          UNKNOWN_PSK_IDENTITY            = 115,
00059 
00060          // pseudo alert values
00061          NULL_ALERT                      = 256,
00062          HEARTBEAT_PAYLOAD               = 257
00063       };
00064 
00065       /**
00066       * @return true iff this alert is non-empty
00067       */
00068       bool is_valid() const { return (m_type_code != NULL_ALERT); }
00069 
00070       /**
00071       * @return if this alert is a fatal one or not
00072       */
00073       bool is_fatal() const { return m_fatal; }
00074 
00075       /**
00076       * @return type of alert
00077       */
00078       Type type() const { return m_type_code; }
00079 
00080       /**
00081       * @return type of alert
00082       */
00083       std::string type_string() const;
00084 
00085       /**
00086       * Serialize an alert
00087       */
00088       std::vector<byte> serialize() const;
00089 
00090       /**
00091       * Deserialize an Alert message
00092       * @param buf the serialized alert
00093       */
00094       Alert(const secure_vector<byte>& buf);
00095 
00096       /**
00097       * Create a new Alert
00098       * @param type_code the type of alert
00099       * @param fatal specifies if this is a fatal alert
00100       */
00101       Alert(Type type_code, bool fatal = false) :
00102          m_fatal(fatal), m_type_code(type_code) {}
00103 
00104       Alert() : m_fatal(false), m_type_code(NULL_ALERT) {}
00105    private:
00106       bool m_fatal;
00107       Type m_type_code;
00108    };
00109 
00110 }
00111 
00112 }
00113 
00114 #endif