alert.go 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. // Copyright 2009 The Go Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. package tls
  5. import "strconv"
  6. type alert uint8
  7. const (
  8. // alert level
  9. alertLevelWarning = 1
  10. alertLevelError = 2
  11. )
  12. const (
  13. alertCloseNotify alert = 0
  14. alertUnexpectedMessage alert = 10
  15. alertBadRecordMAC alert = 20
  16. alertDecryptionFailed alert = 21
  17. alertRecordOverflow alert = 22
  18. alertDecompressionFailure alert = 30
  19. alertHandshakeFailure alert = 40
  20. alertBadCertificate alert = 42
  21. alertUnsupportedCertificate alert = 43
  22. alertCertificateRevoked alert = 44
  23. alertCertificateExpired alert = 45
  24. alertCertificateUnknown alert = 46
  25. alertIllegalParameter alert = 47
  26. alertUnknownCA alert = 48
  27. alertAccessDenied alert = 49
  28. alertDecodeError alert = 50
  29. alertDecryptError alert = 51
  30. alertProtocolVersion alert = 70
  31. alertInsufficientSecurity alert = 71
  32. alertInternalError alert = 80
  33. alertInappropriateFallback alert = 86
  34. alertUserCanceled alert = 90
  35. alertNoRenegotiation alert = 100
  36. alertMissingExtension alert = 109
  37. alertUnsupportedExtension alert = 110
  38. alertNoApplicationProtocol alert = 120
  39. )
  40. var alertText = map[alert]string{
  41. alertCloseNotify: "close notify",
  42. alertUnexpectedMessage: "unexpected message",
  43. alertBadRecordMAC: "bad record MAC",
  44. alertDecryptionFailed: "decryption failed",
  45. alertRecordOverflow: "record overflow",
  46. alertDecompressionFailure: "decompression failure",
  47. alertHandshakeFailure: "handshake failure",
  48. alertBadCertificate: "bad certificate",
  49. alertUnsupportedCertificate: "unsupported certificate",
  50. alertCertificateRevoked: "revoked certificate",
  51. alertCertificateExpired: "expired certificate",
  52. alertCertificateUnknown: "unknown certificate",
  53. alertIllegalParameter: "illegal parameter",
  54. alertUnknownCA: "unknown certificate authority",
  55. alertAccessDenied: "access denied",
  56. alertDecodeError: "error decoding message",
  57. alertDecryptError: "error decrypting message",
  58. alertProtocolVersion: "protocol version not supported",
  59. alertInsufficientSecurity: "insufficient security level",
  60. alertInternalError: "internal error",
  61. alertInappropriateFallback: "inappropriate fallback",
  62. alertUserCanceled: "user canceled",
  63. alertNoRenegotiation: "no renegotiation",
  64. alertMissingExtension: "missing extension",
  65. alertUnsupportedExtension: "unsupported extension",
  66. alertNoApplicationProtocol: "no application protocol",
  67. }
  68. func (e alert) String() string {
  69. s, ok := alertText[e]
  70. if ok {
  71. return "tls: " + s
  72. }
  73. return "tls: alert(" + strconv.Itoa(int(e)) + ")"
  74. }
  75. func (e alert) Error() string {
  76. return e.String()
  77. }