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