github.com/hellobchain/newcryptosm@v0.0.0-20221019060107-edb949a317e9/tls/alert.go (about)

     1  /*
     2  Copyright Suzhou Tongji Fintech Research Institute 2017 All Rights Reserved.
     3  Licensed under the Apache License, Version 2.0 (the "License");
     4  you may not use this file except in compliance with the License.
     5  You may obtain a copy of the License at
     6  
     7  	http://www.apache.org/licenses/LICENSE-2.0
     8  
     9  Unless required by applicable law or agreed to in writing, software
    10  distributed under the License is distributed on an "AS IS" BASIS,
    11  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  See the License for the specific language governing permissions and
    13  limitations under the License.
    14  */
    15  
    16  package tls
    17  
    18  import "strconv"
    19  
    20  type alert uint8
    21  
    22  const (
    23  	// alert level
    24  	alertLevelWarning = 1
    25  	alertLevelError   = 2
    26  )
    27  
    28  const (
    29  	alertCloseNotify            alert = 0
    30  	alertUnexpectedMessage      alert = 10
    31  	alertBadRecordMAC           alert = 20
    32  	alertDecryptionFailed       alert = 21
    33  	alertRecordOverflow         alert = 22
    34  	alertDecompressionFailure   alert = 30
    35  	alertHandshakeFailure       alert = 40
    36  	alertBadCertificate         alert = 42
    37  	alertUnsupportedCertificate alert = 43
    38  	alertCertificateRevoked     alert = 44
    39  	alertCertificateExpired     alert = 45
    40  	alertCertificateUnknown     alert = 46
    41  	alertIllegalParameter       alert = 47
    42  	alertUnknownCA              alert = 48
    43  	alertAccessDenied           alert = 49
    44  	alertDecodeError            alert = 50
    45  	alertDecryptError           alert = 51
    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  	alertNoApplicationProtocol  alert = 120
    53  )
    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  	alertProtocolVersion:        "protocol version not supported",
    74  	alertInsufficientSecurity:   "insufficient security level",
    75  	alertInternalError:          "internal error",
    76  	alertInappropriateFallback:  "inappropriate fallback",
    77  	alertUserCanceled:           "user canceled",
    78  	alertNoRenegotiation:        "no renegotiation",
    79  	alertNoApplicationProtocol:  "no application protocol",
    80  }
    81  
    82  func (e alert) String() string {
    83  	s, ok := alertText[e]
    84  	if ok {
    85  		return "tls: " + s
    86  	}
    87  	return "tls: alert(" + strconv.Itoa(int(e)) + ")"
    88  }
    89  
    90  func (e alert) Error() string {
    91  	return e.String()
    92  }