AlertDescription.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. namespace Org.BouncyCastle.Crypto.Tls
  3. {
  4. /// <summary>
  5. /// RFC 5246 7.2
  6. /// </summary>
  7. public abstract class AlertDescription
  8. {
  9. /**
  10. * This message notifies the recipient that the sender will not send any more messages on this
  11. * connection. Note that as of TLS 1.1, failure to properly close a connection no longer
  12. * requires that a session not be resumed. This is a change from TLS 1.0 ("The session becomes
  13. * unresumable if any connection is terminated without proper close_notify messages with level
  14. * equal to warning.") to conform with widespread implementation practice.
  15. */
  16. public const byte close_notify = 0;
  17. /**
  18. * An inappropriate message was received. This alert is always fatal and should never be
  19. * observed in communication between proper implementations.
  20. */
  21. public const byte unexpected_message = 10;
  22. /**
  23. * This alert is returned if a record is received with an incorrect MAC. This alert also MUST be
  24. * returned if an alert is sent because a TLSCiphertext decrypted in an invalid way: either it
  25. * wasn't an even multiple of the block length, or its padding values, when checked, weren't
  26. * correct. This message is always fatal and should never be observed in communication between
  27. * proper implementations (except when messages were corrupted in the network).
  28. */
  29. public const byte bad_record_mac = 20;
  30. /**
  31. * This alert was used in some earlier versions of TLS, and may have permitted certain attacks
  32. * against the CBC mode [CBCATT]. It MUST NOT be sent by compliant implementations.
  33. */
  34. public const byte decryption_failed = 21;
  35. /**
  36. * A TLSCiphertext record was received that had a length more than 2^14+2048 bytes, or a record
  37. * decrypted to a TLSCompressed record with more than 2^14+1024 bytes. This message is always
  38. * fatal and should never be observed in communication between proper implementations (except
  39. * when messages were corrupted in the network).
  40. */
  41. public const byte record_overflow = 22;
  42. /**
  43. * The decompression function received improper input (e.g., data that would expand to excessive
  44. * length). This message is always fatal and should never be observed in communication between
  45. * proper implementations.
  46. */
  47. public const byte decompression_failure = 30;
  48. /**
  49. * Reception of a handshake_failure alert message indicates that the sender was unable to
  50. * negotiate an acceptable set of security parameters given the options available. This is a
  51. * fatal error.
  52. */
  53. public const byte handshake_failure = 40;
  54. /**
  55. * This alert was used in SSLv3 but not any version of TLS. It MUST NOT be sent by compliant
  56. * implementations.
  57. */
  58. public const byte no_certificate = 41;
  59. /**
  60. * A certificate was corrupt, contained signatures that did not verify correctly, etc.
  61. */
  62. public const byte bad_certificate = 42;
  63. /**
  64. * A certificate was of an unsupported type.
  65. */
  66. public const byte unsupported_certificate = 43;
  67. /**
  68. * A certificate was revoked by its signer.
  69. */
  70. public const byte certificate_revoked = 44;
  71. /**
  72. * A certificate has expired or is not currently valid.
  73. */
  74. public const byte certificate_expired = 45;
  75. /**
  76. * Some other (unspecified) issue arose in processing the certificate, rendering it
  77. * unacceptable.
  78. */
  79. public const byte certificate_unknown = 46;
  80. /**
  81. * A field in the handshake was out of range or inconsistent with other fields. This message is
  82. * always fatal.
  83. */
  84. public const byte illegal_parameter = 47;
  85. /**
  86. * A valid certificate chain or partial chain was received, but the certificate was not accepted
  87. * because the CA certificate could not be located or couldn't be matched with a known, trusted
  88. * CA. This message is always fatal.
  89. */
  90. public const byte unknown_ca = 48;
  91. /**
  92. * A valid certificate was received, but when access control was applied, the sender decided not
  93. * to proceed with negotiation. This message is always fatal.
  94. */
  95. public const byte access_denied = 49;
  96. /**
  97. * A message could not be decoded because some field was out of the specified range or the
  98. * length of the message was incorrect. This message is always fatal and should never be
  99. * observed in communication between proper implementations (except when messages were corrupted
  100. * in the network).
  101. */
  102. public const byte decode_error = 50;
  103. /**
  104. * A handshake cryptographic operation failed, including being unable to correctly verify a
  105. * signature or validate a Finished message. This message is always fatal.
  106. */
  107. public const byte decrypt_error = 51;
  108. /**
  109. * This alert was used in some earlier versions of TLS. It MUST NOT be sent by compliant
  110. * implementations.
  111. */
  112. public const byte export_restriction = 60;
  113. /**
  114. * The protocol version the client has attempted to negotiate is recognized but not supported.
  115. * (For example, old protocol versions might be avoided for security reasons.) This message is
  116. * always fatal.
  117. */
  118. public const byte protocol_version = 70;
  119. /**
  120. * Returned instead of handshake_failure when a negotiation has failed specifically because the
  121. * server requires ciphers more secure than those supported by the client. This message is
  122. * always fatal.
  123. */
  124. public const byte insufficient_security = 71;
  125. /**
  126. * An internal error unrelated to the peer or the correctness of the protocol (such as a memory
  127. * allocation failure) makes it impossible to continue. This message is always fatal.
  128. */
  129. public const byte internal_error = 80;
  130. /**
  131. * This handshake is being canceled for some reason unrelated to a protocol failure. If the user
  132. * cancels an operation after the handshake is complete, just closing the connection by sending
  133. * a close_notify is more appropriate. This alert should be followed by a close_notify. This
  134. * message is generally a warning.
  135. */
  136. public const byte user_canceled = 90;
  137. /**
  138. * Sent by the client in response to a hello request or by the server in response to a client
  139. * hello after initial handshaking. Either of these would normally lead to renegotiation; when
  140. * that is not appropriate, the recipient should respond with this alert. At that point, the
  141. * original requester can decide whether to proceed with the connection. One case where this
  142. * would be appropriate is where a server has spawned a process to satisfy a request; the
  143. * process might receive security parameters (key length, authentication, etc.) at startup, and
  144. * it might be difficult to communicate changes to these parameters after that point. This
  145. * message is always a warning.
  146. */
  147. public const byte no_renegotiation = 100;
  148. /**
  149. * Sent by clients that receive an extended server hello containing an extension that they did
  150. * not put in the corresponding client hello. This message is always fatal.
  151. */
  152. public const byte unsupported_extension = 110;
  153. /*
  154. * RFC 3546
  155. */
  156. /**
  157. * This alert is sent by servers who are unable to retrieve a certificate chain from the URL
  158. * supplied by the client (see Section 3.3). This message MAY be fatal - for example if client
  159. * authentication is required by the server for the handshake to continue and the server is
  160. * unable to retrieve the certificate chain, it may send a fatal alert.
  161. */
  162. public const byte certificate_unobtainable = 111;
  163. /**
  164. * This alert is sent by servers that receive a server_name extension request, but do not
  165. * recognize the server name. This message MAY be fatal.
  166. */
  167. public const byte unrecognized_name = 112;
  168. /**
  169. * This alert is sent by clients that receive an invalid certificate status response (see
  170. * Section 3.6). This message is always fatal.
  171. */
  172. public const byte bad_certificate_status_response = 113;
  173. /**
  174. * This alert is sent by servers when a certificate hash does not match a client provided
  175. * certificate_hash. This message is always fatal.
  176. */
  177. public const byte bad_certificate_hash_value = 114;
  178. /*
  179. * RFC 4279
  180. */
  181. /**
  182. * If the server does not recognize the PSK identity, it MAY respond with an
  183. * "unknown_psk_identity" alert message.
  184. */
  185. public const byte unknown_psk_identity = 115;
  186. /*
  187. * RFC 7507
  188. */
  189. /**
  190. * If TLS_FALLBACK_SCSV appears in ClientHello.cipher_suites and the highest protocol version
  191. * supported by the server is higher than the version indicated in ClientHello.client_version,
  192. * the server MUST respond with a fatal inappropriate_fallback alert [..].
  193. */
  194. public const byte inappropriate_fallback = 86;
  195. public static string GetName(byte alertDescription)
  196. {
  197. switch (alertDescription)
  198. {
  199. case close_notify:
  200. return "close_notify";
  201. case unexpected_message:
  202. return "unexpected_message";
  203. case bad_record_mac:
  204. return "bad_record_mac";
  205. case decryption_failed:
  206. return "decryption_failed";
  207. case record_overflow:
  208. return "record_overflow";
  209. case decompression_failure:
  210. return "decompression_failure";
  211. case handshake_failure:
  212. return "handshake_failure";
  213. case no_certificate:
  214. return "no_certificate";
  215. case bad_certificate:
  216. return "bad_certificate";
  217. case unsupported_certificate:
  218. return "unsupported_certificate";
  219. case certificate_revoked:
  220. return "certificate_revoked";
  221. case certificate_expired:
  222. return "certificate_expired";
  223. case certificate_unknown:
  224. return "certificate_unknown";
  225. case illegal_parameter:
  226. return "illegal_parameter";
  227. case unknown_ca:
  228. return "unknown_ca";
  229. case access_denied:
  230. return "access_denied";
  231. case decode_error:
  232. return "decode_error";
  233. case decrypt_error:
  234. return "decrypt_error";
  235. case export_restriction:
  236. return "export_restriction";
  237. case protocol_version:
  238. return "protocol_version";
  239. case insufficient_security:
  240. return "insufficient_security";
  241. case internal_error:
  242. return "internal_error";
  243. case user_canceled:
  244. return "user_canceled";
  245. case no_renegotiation:
  246. return "no_renegotiation";
  247. case unsupported_extension:
  248. return "unsupported_extension";
  249. case certificate_unobtainable:
  250. return "certificate_unobtainable";
  251. case unrecognized_name:
  252. return "unrecognized_name";
  253. case bad_certificate_status_response:
  254. return "bad_certificate_status_response";
  255. case bad_certificate_hash_value:
  256. return "bad_certificate_hash_value";
  257. case unknown_psk_identity:
  258. return "unknown_psk_identity";
  259. case inappropriate_fallback:
  260. return "inappropriate_fallback";
  261. default:
  262. return "UNKNOWN";
  263. }
  264. }
  265. public static string GetText(byte alertDescription)
  266. {
  267. return GetName(alertDescription) + "(" + alertDescription + ")";
  268. }
  269. }
  270. }
  271. #endif