我正在使用肥皂服务器,它将使用旧的肥皂协议(protocol)为某些旧的嵌入式计算机服务。
我用go编写了它,到目前为止只使用了http
,但是在生产中必须使用ssl
加密。因此,我刚刚创建了一个 key 和一个证书(来自this site),并使用了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版本和受支持的密码套件:
为此,您需要设置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
的注释,以了解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中。关于ssl - 客户端的ssl版本和密码套件,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/48498038/