AlertDescription.cs 15 KB

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