Go 1.22 remote error: tls: handshake failure

Golang 1.22 remote error: tls: handshake failure

1.22之前运行下面代码是没有错误

package main

import (
	"crypto/tls"
	"fmt"
	"net/http"
)

func main() {
	http.DefaultTransport.(*http.Transport).TLSClientConfig = &tls.Config{InsecureSkipVerify: true}

	resp, err := http.Get("https://xxxxxxxxx")
	if err != nil {
		panic(err)
	}
	fmt.Println("status:", resp.Status)
}

但当golang升级1.22后就会出错,主要是crypto/tls 库已将基于 RSA 密钥交换的密码套件从默认列表中移除。这是因为基于 RSA 密钥交换的算法被认为是不够安全的,存在一些潜在的安全风险。

来源:https://pkg.go.dev/crypto/tls

// CipherSuites is a list of enabled TLS 1.0–1.2 cipher suites. The order of
// the list is ignored. Note that TLS 1.3 ciphersuites are not configurable.
//
// If CipherSuites is nil, a safe default list is used. The default cipher
// suites might change over time. In Go 1.22 RSA key exchange based cipher
// suites were removed from the default list, but can be re-added with the
// GODEBUG setting tlsrsakex=1.
CipherSuites []uint16

修复方法:设置ENV

os.Setenv("GODEBUG", "tlsrsakex=1")
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值