8 Star 31 Fork 13

Cliven / gotlcp

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

Go TLCP

Github CI Documentation GitHub go.mod Go version GitHub tag (latest SemVer)

Information security technology Transport Layer Cryptography Protocol (TLCP)

GoTLCP采用Go语言实现的传输层密码协议(TLCP,也称GMSSL) ,其协议遵循《GB/T 38636-2020 信息安全技术 传输层密码协议》。

GoTLCP实现了TLCP协议中的记录层协议、握手协议族以及密钥计算,支持完整TLCP握手、会话重用、传输保护、单向身份认证(认证服务端)双向身份认证。

密码套件支持以及优先级如下:

  1. ECC_SM4_GCM_SM3
  2. ECC_SM4_CBC_SM3
  3. ECDHE_SM4_GCM_SM3
  4. ECDHE_SM4_CBC_SM3

在使用GOTLCP前,请务必悉知 《Go TLCP 免责声明》

若clone和文档预览存在困难,请移步 https://gitee.com/Trisia/gotlcp

致谢:

  • 项目中的SM系列算法由 emmansun/gmsm 项目实现,其项目中通过CPU指令集优化了算法效率。
  • 项目TLCP协议代码裁剪自 go 1.19版本 golang/src/crypto/tls 模块。

安装

为了安装使用GoTLCP,您需要首先安装 Go 并且设置您的Go环境,GoTLCP至少需要您的Go版本在 1.18及以上

通过下面命令就可以安装 GoTLCP:

go get -u gitee.com/Trisia/gotlcp

GoTLCP 将持续保证API的向下兼容,您可以放心的升级GoTLCP库至最新版本。

快速开始

客户端

package main

import (
	"fmt"
	"gitee.com/Trisia/gotlcp/tlcp"
)

func main() {
	conn, err := tlcp.Dial("tcp", "127.0.0.1:8443", &tlcp.Config{InsecureSkipVerify: true})
	if err != nil {
		panic(err)
	}
	defer conn.Close()

	buff := make([]byte, 516)
	n, err := conn.Read(buff)
	if err != nil {
		panic(err)
	}
	fmt.Printf(">> %s\n", buff[:n])
}

上述代码实现了客户端向服务端建立TLCP连接并读取数据,注客户端配置InsecureSkipVerify表示跳过服务端证书校验。

服务端

package main

import (
	"gitee.com/Trisia/gotlcp/tlcp"
	"net"
)


func main() {
	// 证书解析以详见下方完整代码。
	config := &tlcp.Config{
		Certificates: []tlcp.Certificate{sigCert, encCert},
	}

	listen, err := tlcp.Listen("tcp", ":8443", config)
	if err != nil {
		panic(err)
	}
	var conn net.Conn
	for {
		conn, err = listen.Accept()
		if err != nil {
			panic(err)
		}
		_, _ = conn.Write([]byte("Hello Go TLCP!"))
		_ = conn.Close()
	}
}

若您需要同时支持TLCP/TLS协议,请参考《GoTLCP 协议适配器》相关内容。

文档

进展

>> 项目进展

MIT License Copyright (c) 2022 Quan Guanyu Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

Go语言实现的传输层密码协议(TLCP GMSSL),TLCP协议遵循 GB/T 38636-2020 Information security technology Transport Layer Cryptography Protocol (TLCP) 展开 收起
Go
MIT
取消

发行版 (29)

全部

贡献者

全部

近期动态

加载更多
不能加载更多了
Go
1
https://gitee.com/Trisia/gotlcp.git
git@gitee.com:Trisia/gotlcp.git
Trisia
gotlcp
gotlcp
main

搜索帮助