alert.go 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. // An AlertError is a TLS alert.
  7. //
  8. // When using a QUIC transport, QUICConn methods will return an error
  9. // which wraps AlertError rather than sending a TLS alert.
  10. type AlertError uint8
  11. func (e AlertError) Error() string {
  12. return alert(e).String()
  13. }
  14. type alert uint8
  15. const (
  16. // alert level
  17. alertLevelWarning = 1
  18. alertLevelError = 2
  19. )
  20. const (
  21. alertCloseNotify alert = 0
  22. alertUnexpectedMessage alert = 10
  23. alertBadRecordMAC alert = 20
  24. alertDecryptionFailed alert = 21
  25. alertRecordOverflow alert = 22
  26. alertDecompressionFailure alert = 30
  27. alertHandshakeFailure alert = 40
  28. alertBadCertificate alert = 42
  29. alertUnsupportedCertificate alert = 43
  30. alertCertificateRevoked alert = 44
  31. alertCertificateExpired alert = 45
  32. alertCertificateUnknown alert = 46
  33. alertIllegalParameter alert = 47
  34. alertUnknownCA alert = 48
  35. alertAccessDenied alert = 49
  36. alertDecodeError alert = 50
  37. alertDecryptError alert = 51
  38. alertExportRestriction alert = 60
  39. alertProtocolVersion alert = 70
  40. alertInsufficientSecurity alert = 71
  41. alertInternalError alert = 80
  42. alertInappropriateFallback alert = 86
  43. alertUserCanceled alert = 90
  44. alertNoRenegotiation alert = 100
  45. alertMissingExtension alert = 109
  46. alertUnsupportedExtension alert = 110
  47. alertCertificateUnobtainable alert = 111
  48. alertUnrecognizedName alert = 112
  49. alertBadCertificateStatusResponse alert = 113
  50. alertBadCertificateHashValue alert = 114
  51. alertUnknownPSKIdentity alert = 115
  52. alertCertificateRequired alert = 116
  53. alertNoApplicationProtocol alert = 120
  54. )
  55. var alertText = map[alert]string{
  56. alertCloseNotify: "close notify",
  57. alertUnexpectedMessage: "unexpected message",
  58. alertBadRecordMAC: "bad record MAC",
  59. alertDecryptionFailed: "decryption failed",
  60. alertRecordOverflow: "record overflow",
  61. alertDecompressionFailure: "decompression failure",
  62. alertHandshakeFailure: "handshake failure",
  63. alertBadCertificate: "bad certificate",
  64. alertUnsupportedCertificate: "unsupported certificate",
  65. alertCertificateRevoked: "revoked certificate",
  66. alertCertificateExpired: "expired certificate",
  67. alertCertificateUnknown: "unknown certificate",
  68. alertIllegalParameter: "illegal parameter",
  69. alertUnknownCA: "unknown certificate authority",
  70. alertAccessDenied: "access denied",
  71. alertDecodeError: "error decoding message",
  72. alertDecryptError: "error decrypting message",
  73. alertExportRestriction: "export restriction",
  74. alertProtocolVersion: "protocol version not supported",
  75. alertInsufficientSecurity: "insufficient security level",
  76. alertInternalError: "internal error",
  77. alertInappropriateFallback: "inappropriate fallback",
  78. alertUserCanceled: "user canceled",
  79. alertNoRenegotiation: "no renegotiation",
  80. alertMissingExtension: "missing extension",
  81. alertUnsupportedExtension: "unsupported extension",
  82. alertCertificateUnobtainable: "certificate unobtainable",
  83. alertUnrecognizedName: "unrecognized name",
  84. alertBadCertificateStatusResponse: "bad certificate status response",
  85. alertBadCertificateHashValue: "bad certificate hash value",
  86. alertUnknownPSKIdentity: "unknown PSK identity",
  87. alertCertificateRequired: "certificate required",
  88. alertNoApplicationProtocol: "no application protocol",
  89. }
  90. func (e alert) String() string {
  91. s, ok := alertText[e]
  92. if ok {
  93. return "tls: " + s
  94. }
  95. return "tls: alert(" + strconv.Itoa(int(e)) + ")"
  96. }
  97. func (e alert) Error() string {
  98. return e.String()
  99. }