~ubuntu-branches/debian/sid/botan/sid

« back to all changes in this revision

Viewing changes to src/lib/tls/tls_alert.cpp

  • Committer: Package Import Robot
  • Author(s): Laszlo Boszormenyi (GCS)
  • Date: 2018-03-01 22:23:25 UTC
  • mfrom: (1.2.2)
  • Revision ID: package-import@ubuntu.com-20180301222325-7p7vc45gu3hta34d
Tags: 2.4.0-2
* Don't remove .doctrees from the manual if it doesn't exist.
* Don't specify parallel to debhelper.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
* Alert Message
 
3
* (C) 2004-2006,2011 Jack Lloyd
 
4
*
 
5
* Botan is released under the Simplified BSD License (see license.txt)
 
6
*/
 
7
 
 
8
#include <botan/tls_alert.h>
 
9
#include <botan/exceptn.h>
 
10
 
 
11
namespace Botan {
 
12
 
 
13
namespace TLS {
 
14
 
 
15
Alert::Alert(const secure_vector<uint8_t>& buf)
 
16
   {
 
17
   if(buf.size() != 2)
 
18
      throw Decoding_Error("Alert: Bad size " + std::to_string(buf.size()) +
 
19
                           " for alert message");
 
20
 
 
21
   if(buf[0] == 1)      m_fatal = false;
 
22
   else if(buf[0] == 2) m_fatal = true;
 
23
   else
 
24
      throw Decoding_Error("Alert: Bad code for alert level");
 
25
 
 
26
   const uint8_t dc = buf[1];
 
27
 
 
28
   m_type_code = static_cast<Type>(dc);
 
29
   }
 
30
 
 
31
std::vector<uint8_t> Alert::serialize() const
 
32
   {
 
33
   return std::vector<uint8_t>({
 
34
      static_cast<uint8_t>(is_fatal() ? 2 : 1),
 
35
      static_cast<uint8_t>(type())
 
36
      });
 
37
   }
 
38
 
 
39
std::string Alert::type_string() const
 
40
   {
 
41
   switch(type())
 
42
      {
 
43
      case CLOSE_NOTIFY:
 
44
         return "close_notify";
 
45
      case UNEXPECTED_MESSAGE:
 
46
         return "unexpected_message";
 
47
      case BAD_RECORD_MAC:
 
48
         return "bad_record_mac";
 
49
      case DECRYPTION_FAILED:
 
50
         return "decryption_failed";
 
51
      case RECORD_OVERFLOW:
 
52
         return "record_overflow";
 
53
      case DECOMPRESSION_FAILURE:
 
54
         return "decompression_failure";
 
55
      case HANDSHAKE_FAILURE:
 
56
         return "handshake_failure";
 
57
      case NO_CERTIFICATE:
 
58
         return "no_certificate";
 
59
      case BAD_CERTIFICATE:
 
60
         return "bad_certificate";
 
61
      case UNSUPPORTED_CERTIFICATE:
 
62
         return "unsupported_certificate";
 
63
      case CERTIFICATE_REVOKED:
 
64
         return "certificate_revoked";
 
65
      case CERTIFICATE_EXPIRED:
 
66
         return "certificate_expired";
 
67
      case CERTIFICATE_UNKNOWN:
 
68
         return "certificate_unknown";
 
69
      case ILLEGAL_PARAMETER:
 
70
         return "illegal_parameter";
 
71
      case UNKNOWN_CA:
 
72
         return "unknown_ca";
 
73
      case ACCESS_DENIED:
 
74
         return "access_denied";
 
75
      case DECODE_ERROR:
 
76
         return "decode_error";
 
77
      case DECRYPT_ERROR:
 
78
         return "decrypt_error";
 
79
      case EXPORT_RESTRICTION:
 
80
         return "export_restriction";
 
81
      case PROTOCOL_VERSION:
 
82
         return "protocol_version";
 
83
      case INSUFFICIENT_SECURITY:
 
84
         return "insufficient_security";
 
85
      case INTERNAL_ERROR:
 
86
         return "internal_error";
 
87
      case INAPPROPRIATE_FALLBACK:
 
88
         return "inappropriate_fallback";
 
89
      case USER_CANCELED:
 
90
         return "user_canceled";
 
91
      case NO_RENEGOTIATION:
 
92
         return "no_renegotiation";
 
93
 
 
94
      case UNSUPPORTED_EXTENSION:
 
95
         return "unsupported_extension";
 
96
      case CERTIFICATE_UNOBTAINABLE:
 
97
         return "certificate_unobtainable";
 
98
      case UNRECOGNIZED_NAME:
 
99
         return "unrecognized_name";
 
100
      case BAD_CERTIFICATE_STATUS_RESPONSE:
 
101
         return "bad_certificate_status_response";
 
102
      case BAD_CERTIFICATE_HASH_VALUE:
 
103
         return "bad_certificate_hash_value";
 
104
      case UNKNOWN_PSK_IDENTITY:
 
105
         return "unknown_psk_identity";
 
106
      case NO_APPLICATION_PROTOCOL:
 
107
         return "no_application_protocol";
 
108
 
 
109
      case NULL_ALERT:
 
110
         return "none";
 
111
      }
 
112
 
 
113
   /*
 
114
   * This is effectively the default case for the switch above, but we
 
115
   * leave it out so that when an alert type is added to the enum the
 
116
   * compiler can warn us that it is not included in the switch
 
117
   * statement.
 
118
   */
 
119
   return "unrecognized_alert_" + std::to_string(type());
 
120
   }
 
121
 
 
122
}
 
123
 
 
124
}