Go https客户端问题 – 远程错误:tls握手失败

huangapple go评论73阅读模式
英文:

Go https client issue - remote error: tls: handshake failure

问题

我遇到了这个错误'remote error: tls: handshake failure':

~/go/bin/aci-tls 10.0.0.201 user pass
2016/12/20 18:12:04 post error: Post https://10.0.0.201/api/aaaLogin.json: remote error: tls: handshake failure

代码是基本的HTTPS客户端:https://play.golang.org/p/cqPT0oR__q

OpenSSL对这个https服务器是正常的:

$ openssl s_client -connect 10.0.0.201:443

(省略)
SSL握手已读取1383字节并写入431字节
---
新的,TLSv1/SSLv3,密码是ECDHE-RSA-AES256-GCM-SHA384
服务器公钥为2048位
支持安全重协商
压缩:无
扩展:无
未协商ALPN
SSL会话:
    协议:TLSv1.2
    密码:ECDHE-RSA-AES256-GCM-SHA384
(省略)

测试环境:

$ go version
go version go1.7.4 linux/386

C:\>go version
go version go1.7.4 windows/amd64

gotlsscan显示:

lab@ubu:~$ go version
go version go1.8beta2 linux/386
lab@ubu:~$ ~/go/bin/gotlsscan -host 10.0.0.201 | grep -v NOT
测试SSL30(已禁用)
测试TLS1.0
测试TLS1.1
测试TLS1.2
lab@ubu:~$
lab@ubu:~$ ~/go/bin/gotlsscan -insecure -host 10.0.0.201 | grep -v NOT
测试SSL30(已禁用)
测试TLS1.0
测试TLS1.1
        TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA            [OK]
        TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA            [OK]
测试TLS1.2

我该如何进一步排查这个问题?

英文:

I am hitting this error 'remote error: tls: handshake failure':

~/go/bin/aci-tls 10.0.0.201 user pass
2016/12/20 18:12:04 post error: Post https://10.0.0.201/api/aaaLogin.json: remote error: tls: handshake failure

Code is basic HTTPS client: https://play.golang.org/p/cqPT0oR__q

OpenSSL is happy with this https server:

$ openssl s_client -connect 10.0.0.201:443

(snip)
SSL handshake has read 1383 bytes and written 431 bytes
---
New, TLSv1/SSLv3, Cipher is ECDHE-RSA-AES256-GCM-SHA384
Server public key is 2048 bit
Secure Renegotiation IS supported
Compression: NONE
Expansion: NONE
No ALPN negotiated
SSL-Session:
    Protocol  : TLSv1.2
    Cipher    : ECDHE-RSA-AES256-GCM-SHA384
(snip)

Tested on:

$ go version
go version go1.7.4 linux/386

C:\>go version
go version go1.7.4 windows/amd64

gotlsscan says:

lab@ubu:~$ go version
go version go1.8beta2 linux/386
lab@ubu:~$ ~/go/bin/gotlsscan -host 10.0.0.201 | grep -v NOT
Testing SSL30 (DISABLED)
Testing TLS1.0
Testing TLS1.1
Testing TLS1.2
lab@ubu:~$
lab@ubu:~$ ~/go/bin/gotlsscan -insecure -host 10.0.0.201 | grep -v NOT
Testing SSL30 (DISABLED)
Testing TLS1.0
Testing TLS1.1
        TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA            [OK]
        TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA            [OK]
Testing TLS1.2

How can I further troubleshoot this issue?

答案1

得分: 6

服务器由于某种原因无法接受TLS1.2握手,也无法正确回退到TLS1.1。您可以强制客户端仅使用TLS1.1和兼容的密码套件,代码如下:

cfg := &tls.Config{
    CipherSuites: []uint16{
        tls.TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
        tls.TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
    },
    PreferServerCipherSuites: true,
    InsecureSkipVerify:       true,
    MinVersion:               tls.VersionTLS11,
    MaxVersion:               tls.VersionTLS11,
}
英文:

The server for some reason doesn't accept the TLS1.2 handshake, nor does it properly fall back to TLS1.1. You can force the client to use only TLS1.1 and the compatible cipher suites with

cfg := &tls.Config{
	CipherSuites: []uint16{
		tls.TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
		tls.TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
	},
	PreferServerCipherSuites: true,
	InsecureSkipVerify:       true,
	MinVersion:               tls.VersionTLS11,
	MaxVersion:               tls.VersionTLS11,
}

huangapple
  • 本文由 发表于 2016年12月21日 04:22:36
  • 转载请务必保留本文链接:https://go.coder-hub.com/41250665.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定