我正在开发一个肥皂服务器,它将为一些具有旧版肥皂协议的旧嵌入式计算机提供服务。
我用go编写它,到目前为止只使用 plain http,但在生产中它必须使用ssl加密。所以我刚刚创建了一个密钥和一个证书(来自此站点)并使用了该http.ListenAndServeTLS功能。
但现在计算机无法连接,服务器只是打印握手错误:
server.go:2848: http: TLS handshake error from [::1]:38790: tls: no cipher suite supported by both client and server
在文档中,对于计算机,不是支持的 ssl 版本或密码。所以我想知道,如何找出客户端的 ssl 版本,以及客户端支持的可用密码套件。
然后我如何配置 golang http 服务器以支持所选的密码。
这里似乎有两个问题,所以我们分两部分来说:
为此,您需要设置tls.ConfigGetConfigForClient对象的字段。
该字段采用带有签名的方法:
func(*ClientHelloInfo) (*Config, error)
Run Code Online (Sandbox Code Playgroud)
Client Hello它在收到带有ClientHelloInfo结构的消息时调用。该结构包含您感兴趣的以下字段:
// 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
Run Code Online (Sandbox Code Playgroud)
请阅读周围的评论GetConfigForClient,ClientHelloInfo了解具体的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
Run Code Online (Sandbox Code Playgroud)
例如,您可以使用以下字段设置 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,
Run Code Online (Sandbox Code Playgroud)
支持的密码套件的完整列表位于tls 文档中。
| 归档时间: |
|
| 查看次数: |
4172 次 |
| 最近记录: |