gitee.com/ks-custle/core-gm@v0.0.0-20230922171213-b83bdd97b62c/gmtls/alert.go (about) 1 // Copyright (c) 2022 zhaochun 2 // core-gm is licensed under Mulan PSL v2. 3 // You can use this software according to the terms and conditions of the Mulan PSL v2. 4 // You may obtain a copy of Mulan PSL v2 at: 5 // http://license.coscl.org.cn/MulanPSL2 6 // THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. 7 // See the Mulan PSL v2 for more details. 8 9 /* 10 gmtls是基于`golang/go`的`tls`包实现的国密改造版本。 11 对应版权声明: thrid_licenses/github.com/golang/go/LICENSE 12 */ 13 14 package gmtls 15 16 /* 17 gmtls/alert.go 定义警告信息,添加国密对应警告信息 18 */ 19 20 import "strconv" 21 22 type alert uint8 23 24 const ( 25 // alert level 26 alertLevelWarning = 1 27 alertLevelError = 2 28 ) 29 30 const ( 31 alertCloseNotify alert = 0 32 alertUnexpectedMessage alert = 10 33 alertBadRecordMAC alert = 20 34 alertDecryptionFailed alert = 21 35 alertRecordOverflow alert = 22 36 alertDecompressionFailure alert = 30 37 alertHandshakeFailure alert = 40 38 alertBadCertificate alert = 42 39 alertUnsupportedCertificate alert = 43 40 alertCertificateRevoked alert = 44 41 alertCertificateExpired alert = 45 42 alertCertificateUnknown alert = 46 43 alertIllegalParameter alert = 47 44 alertUnknownCA alert = 48 45 alertAccessDenied alert = 49 46 alertDecodeError alert = 50 47 alertDecryptError alert = 51 48 alertExportRestriction alert = 60 49 alertProtocolVersion alert = 70 50 alertInsufficientSecurity alert = 71 51 alertInternalError alert = 80 52 alertInappropriateFallback alert = 86 53 alertUserCanceled alert = 90 54 alertNoRenegotiation alert = 100 55 alertMissingExtension alert = 109 56 alertUnsupportedExtension alert = 110 57 alertCertificateUnobtainable alert = 111 58 alertUnrecognizedName alert = 112 59 alertBadCertificateStatusResponse alert = 113 60 alertBadCertificateHashValue alert = 114 61 alertUnknownPSKIdentity alert = 115 62 alertCertificateRequired alert = 116 63 alertNoApplicationProtocol alert = 120 64 //GMT0024 65 alertUnspporttedSite2Site alert = 200 66 alertNoArea alert = 201 67 alertUnspportedAreaType alert = 202 68 alertBadIBCParam alert = 203 69 alertUnspportedIBCParam alert = 204 70 alertIdentityNeed alert = 205 71 ) 72 73 var alertText = map[alert]string{ 74 alertCloseNotify: "close notify", 75 alertUnexpectedMessage: "unexpected message", 76 alertBadRecordMAC: "bad record MAC", 77 alertDecryptionFailed: "decryption failed", 78 alertRecordOverflow: "record overflow", 79 alertDecompressionFailure: "decompression failure", 80 alertHandshakeFailure: "handshake failure", 81 alertBadCertificate: "bad certificate", 82 alertUnsupportedCertificate: "unsupported certificate", 83 alertCertificateRevoked: "revoked certificate", 84 alertCertificateExpired: "expired certificate", 85 alertCertificateUnknown: "unknown certificate", 86 alertIllegalParameter: "illegal parameter", 87 alertUnknownCA: "unknown certificate authority", 88 alertAccessDenied: "access denied", 89 alertDecodeError: "error decoding message", 90 alertDecryptError: "error decrypting message", 91 alertExportRestriction: "export restriction", 92 alertProtocolVersion: "protocol version not supported", 93 alertInsufficientSecurity: "insufficient security level", 94 alertInternalError: "internal error", 95 alertInappropriateFallback: "inappropriate fallback", 96 alertUserCanceled: "user canceled", 97 alertNoRenegotiation: "no renegotiation", 98 alertMissingExtension: "missing extension", 99 alertUnsupportedExtension: "unsupported extension", 100 alertCertificateUnobtainable: "certificate unobtainable", 101 alertUnrecognizedName: "unrecognized name", 102 alertBadCertificateStatusResponse: "bad certificate status response", 103 alertBadCertificateHashValue: "bad certificate hash value", 104 alertUnknownPSKIdentity: "unknown PSK identity", 105 alertCertificateRequired: "certificate required", 106 alertNoApplicationProtocol: "no application protocol", 107 //GMT0024 108 alertUnspporttedSite2Site: "不支持site2site", 109 alertNoArea: "没有保护域", 110 alertUnspportedAreaType: "不支持的保护域类型", 111 alertBadIBCParam: "接收到一个无效的ibc公共参数", 112 alertUnspportedIBCParam: "不支持ibc参数中定义的信息", 113 alertIdentityNeed: "缺少对方的ibc标识", 114 } 115 116 func (e alert) String() string { 117 s, ok := alertText[e] 118 if ok { 119 return "gmtls: " + s 120 } 121 return "gmtls: alert(" + strconv.Itoa(int(e)) + ")" 122 } 123 124 func (e alert) Error() string { 125 return e.String() 126 }