github.com/hxx258456/ccgo@v0.0.5-0.20230213014102-48b35f46f66f/gmtls/alert.go (about)

     1  // Copyright 2022 s1ren@github.com/hxx258456.
     2  
     3  /*
     4  gmtls是基于`golang/go`的`tls`包实现的国密改造版本。
     5  对应版权声明: thrid_licenses/github.com/golang/go/LICENSE
     6  */
     7  
     8  package gmtls
     9  
    10  /*
    11  gmtls/alert.go 定义警告信息,添加国密对应警告信息
    12  */
    13  
    14  import "strconv"
    15  
    16  type alert uint8
    17  
    18  const (
    19  	// alert level
    20  	alertLevelWarning = 1
    21  	alertLevelError   = 2
    22  )
    23  
    24  const (
    25  	alertCloseNotify                  alert = 0
    26  	alertUnexpectedMessage            alert = 10
    27  	alertBadRecordMAC                 alert = 20
    28  	alertDecryptionFailed             alert = 21
    29  	alertRecordOverflow               alert = 22
    30  	alertDecompressionFailure         alert = 30
    31  	alertHandshakeFailure             alert = 40
    32  	alertBadCertificate               alert = 42
    33  	alertUnsupportedCertificate       alert = 43
    34  	alertCertificateRevoked           alert = 44
    35  	alertCertificateExpired           alert = 45
    36  	alertCertificateUnknown           alert = 46
    37  	alertIllegalParameter             alert = 47
    38  	alertUnknownCA                    alert = 48
    39  	alertAccessDenied                 alert = 49
    40  	alertDecodeError                  alert = 50
    41  	alertDecryptError                 alert = 51
    42  	alertExportRestriction            alert = 60
    43  	alertProtocolVersion              alert = 70
    44  	alertInsufficientSecurity         alert = 71
    45  	alertInternalError                alert = 80
    46  	alertInappropriateFallback        alert = 86
    47  	alertUserCanceled                 alert = 90
    48  	alertNoRenegotiation              alert = 100
    49  	alertMissingExtension             alert = 109
    50  	alertUnsupportedExtension         alert = 110
    51  	alertCertificateUnobtainable      alert = 111
    52  	alertUnrecognizedName             alert = 112
    53  	alertBadCertificateStatusResponse alert = 113
    54  	alertBadCertificateHashValue      alert = 114
    55  	alertUnknownPSKIdentity           alert = 115
    56  	alertCertificateRequired          alert = 116
    57  	alertNoApplicationProtocol        alert = 120
    58  	//GMT0024
    59  	alertUnspporttedSite2Site alert = 200
    60  	alertNoArea               alert = 201
    61  	alertUnspportedAreaType   alert = 202
    62  	alertBadIBCParam          alert = 203
    63  	alertUnspportedIBCParam   alert = 204
    64  	alertIdentityNeed         alert = 205
    65  )
    66  
    67  var alertText = map[alert]string{
    68  	alertCloseNotify:                  "close notify",
    69  	alertUnexpectedMessage:            "unexpected message",
    70  	alertBadRecordMAC:                 "bad record MAC",
    71  	alertDecryptionFailed:             "decryption failed",
    72  	alertRecordOverflow:               "record overflow",
    73  	alertDecompressionFailure:         "decompression failure",
    74  	alertHandshakeFailure:             "handshake failure",
    75  	alertBadCertificate:               "bad certificate",
    76  	alertUnsupportedCertificate:       "unsupported certificate",
    77  	alertCertificateRevoked:           "revoked certificate",
    78  	alertCertificateExpired:           "expired certificate",
    79  	alertCertificateUnknown:           "unknown certificate",
    80  	alertIllegalParameter:             "illegal parameter",
    81  	alertUnknownCA:                    "unknown certificate authority",
    82  	alertAccessDenied:                 "access denied",
    83  	alertDecodeError:                  "error decoding message",
    84  	alertDecryptError:                 "error decrypting message",
    85  	alertExportRestriction:            "export restriction",
    86  	alertProtocolVersion:              "protocol version not supported",
    87  	alertInsufficientSecurity:         "insufficient security level",
    88  	alertInternalError:                "internal error",
    89  	alertInappropriateFallback:        "inappropriate fallback",
    90  	alertUserCanceled:                 "user canceled",
    91  	alertNoRenegotiation:              "no renegotiation",
    92  	alertMissingExtension:             "missing extension",
    93  	alertUnsupportedExtension:         "unsupported extension",
    94  	alertCertificateUnobtainable:      "certificate unobtainable",
    95  	alertUnrecognizedName:             "unrecognized name",
    96  	alertBadCertificateStatusResponse: "bad certificate status response",
    97  	alertBadCertificateHashValue:      "bad certificate hash value",
    98  	alertUnknownPSKIdentity:           "unknown PSK identity",
    99  	alertCertificateRequired:          "certificate required",
   100  	alertNoApplicationProtocol:        "no application protocol",
   101  	//GMT0024
   102  	alertUnspporttedSite2Site: "不支持site2site",
   103  	alertNoArea:               "没有保护域",
   104  	alertUnspportedAreaType:   "不支持的保护域类型",
   105  	alertBadIBCParam:          "接收到一个无效的ibc公共参数",
   106  	alertUnspportedIBCParam:   "不支持ibc参数中定义的信息",
   107  	alertIdentityNeed:         "缺少对方的ibc标识",
   108  }
   109  
   110  func (e alert) String() string {
   111  	s, ok := alertText[e]
   112  	if ok {
   113  		return "gmtls: " + s
   114  	}
   115  	return "gmtls: alert(" + strconv.Itoa(int(e)) + ")"
   116  }
   117  
   118  func (e alert) Error() string {
   119  	return e.String()
   120  }