AlertDescription.cs 12 KB

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