Golang TLS 测试服务器和客户端在每次执行时协商相同的密钥以方便调试

我有一个 golang 项目的测试用例,该项目使用 crypto/tls 启动 TLS 客户端和服务器。我的测试访问客户端和服务器交换的密文以运行断言。

我正在寻找一种方法来在测试的连续执行中获得相同的密文。

协商密钥的值和服务器返回的明文与测试无关。


弑天下
浏览 131回答 1
1回答

互换的青春

tls 示例的测试示例可以帮助您,为of定义一个zeroSource已实现的Read接口。Randtls.configtype zeroSource struct{}func (zeroSource) Read(b []byte) (n int, err error) {    for i := range b {        b[i] = 0    }    // assign the same key to b    return len(b), nil}// server side    server.TLS = &tls.Config{        Rand: zeroSource{}, // for example only; don't do this.    }// client side    client := &http.Client{        Transport: &http.Transport{            TLSClientConfig: &tls.Config{                Rand:               zeroSource{}, // for reproducible output; don't do this.            },        },    }
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Go