Alternative TLS implementation in Go
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

83 lignes
2.7 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. )
  39. var alertText = map[alert]string{
  40. alertCloseNotify: "close notify",
  41. alertUnexpectedMessage: "unexpected message",
  42. alertBadRecordMAC: "bad record MAC",
  43. alertDecryptionFailed: "decryption failed",
  44. alertRecordOverflow: "record overflow",
  45. alertDecompressionFailure: "decompression failure",
  46. alertHandshakeFailure: "handshake failure",
  47. alertBadCertificate: "bad certificate",
  48. alertUnsupportedCertificate: "unsupported certificate",
  49. alertCertificateRevoked: "revoked certificate",
  50. alertCertificateExpired: "expired certificate",
  51. alertCertificateUnknown: "unknown certificate",
  52. alertIllegalParameter: "illegal parameter",
  53. alertUnknownCA: "unknown certificate authority",
  54. alertAccessDenied: "access denied",
  55. alertDecodeError: "error decoding message",
  56. alertDecryptError: "error decrypting message",
  57. alertProtocolVersion: "protocol version not supported",
  58. alertInsufficientSecurity: "insufficient security level",
  59. alertInternalError: "internal error",
  60. alertInappropriateFallback: "inappropriate fallback",
  61. alertUserCanceled: "user canceled",
  62. alertNoRenegotiation: "no renegotiation",
  63. alertNoApplicationProtocol: "no application protocol",
  64. }
  65. func (e alert) String() string {
  66. s, ok := alertText[e]
  67. if ok {
  68. return "tls: " + s
  69. }
  70. return "tls: alert(" + strconv.Itoa(int(e)) + ")"
  71. }
  72. func (e alert) Error() string {
  73. return e.String()
  74. }