Alternative TLS implementation in Go
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

84 rader
2.8 KiB

  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. alertEndOfEarlyData alert = 1
  15. alertUnexpectedMessage alert = 10
  16. alertBadRecordMAC alert = 20
  17. alertDecryptionFailed alert = 21
  18. alertRecordOverflow alert = 22
  19. alertDecompressionFailure alert = 30
  20. alertHandshakeFailure alert = 40
  21. alertBadCertificate alert = 42
  22. alertUnsupportedCertificate alert = 43
  23. alertCertificateRevoked alert = 44
  24. alertCertificateExpired alert = 45
  25. alertCertificateUnknown alert = 46
  26. alertIllegalParameter alert = 47
  27. alertUnknownCA alert = 48
  28. alertAccessDenied alert = 49
  29. alertDecodeError alert = 50
  30. alertDecryptError alert = 51
  31. alertProtocolVersion alert = 70
  32. alertInsufficientSecurity alert = 71
  33. alertInternalError alert = 80
  34. alertInappropriateFallback alert = 86
  35. alertUserCanceled alert = 90
  36. alertNoRenegotiation alert = 100
  37. alertNoApplicationProtocol alert = 120
  38. alertSuccess alert = 255 // dummy value returned by unmarshal functions
  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. alertNoApplicationProtocol: "no application protocol",
  65. }
  66. func (e alert) String() string {
  67. s, ok := alertText[e]
  68. if ok {
  69. return "tls: " + s
  70. }
  71. return "tls: alert(" + strconv.Itoa(int(e)) + ")"
  72. }
  73. func (e alert) Error() string {
  74. return e.String()
  75. }