这里似乎有两个问题,所以我们分两部分来做:
查找客户端的 TLS 版本和支持的密码套件:
为此,您需要设置tls.Config 对象的GetConfigForClient 字段。
该字段采用带签名的方法:
func(*ClientHelloInfo) (*Config, error)
在收到带有ClientHelloInfo 结构的Client Hello 消息时调用它。此结构包含您感兴趣的以下字段:
// CipherSuites lists the CipherSuites supported by the client (e.g.
// TLS_RSA_WITH_RC4_128_SHA).
CipherSuites []uint16
// SupportedVersions lists the TLS versions supported by the client.
// For TLS versions less than 1.3, this is extrapolated from the max
// version advertised by the client, so values other than the greatest
// might be rejected if used.
SupportedVersions []uint16
请阅读 GetConfigForClient 和 ClientHelloInfo 周围的 cmets,了解 GetConfigForClient 的确切行为方式以及字段详细信息。
指定服务器支持的版本和密码套件:
这也可以通过tls.Config 对象使用以下字段来完成:
// CipherSuites is a list of supported cipher suites. If CipherSuites
// is nil, TLS uses a list of suites supported by the implementation.
CipherSuites []uint16
// MinVersion contains the minimum SSL/TLS version that is acceptable.
// If zero, then TLS 1.0 is taken as the minimum.
MinVersion uint16
// MaxVersion contains the maximum SSL/TLS version that is acceptable.
// If zero, then the maximum version supported by this package is used,
// which is currently TLS 1.2.
MaxVersion uint16
例如,您可以使用以下字段设置 tls.Config:
CipherSuites: []uint16{
tls.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
tls.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
tls.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
etc...
tls.TLS_RSA_WITH_AES_256_CBC_SHA,
},
MinVersion: tls.VersionTLS12,
支持的密码套件的完整列表位于tls docs。