英文:
golang: HTTPS request yields "crypto/rsa: verification error"
问题
我在使用net/http
包访问https
链接时遇到了问题。
以下是一个出错的示例代码:
package main
import (
"fmt"
"net/http"
)
func main() {
_, err := http.Get("https://api.bitfinex.com/v1/book/ltcbtc")
if err != nil {
fmt.Println(err)
}
}
这个程序会产生以下错误:
Get https://api.bitfinex.com/v1/book/ltcbtc: crypto/rsa: verification error
net/http
的文档明确说明:
Get、Head、Post和PostForm可以发送HTTP(或HTTPS)请求
但是我找不到关于这个错误的任何文档。
crypto/rsa
的源代码只是简单地说明了这个错误:
// ErrVerification represents a failure to verify a signature.
// It is deliberately vague to avoid adaptive attacks.
var ErrVerification = errors.New("crypto/rsa: verification error")
所以我不确定接下来该怎么做。我相信这不是他们的问题,因为Chrome对他们的https证书很满意。
我还尝试过使用具有InsecureSkipVerify
设置为true
的tls.Config
的Client
,但似乎无法解决这个错误。
英文:
I'm having trouble accessing https
urls with the net/http
package.
Here's a working example of the error:
package main
import (
"fmt"
"net/http"
)
func main() {
_, err := http.Get("https://api.bitfinex.com/v1/book/ltcbtc")
if err != nil {
fmt.Println(err)
}
}
This program yields the error,
Get https://api.bitfinex.com/v1/book/ltcbtc: crypto/rsa: verification error
The docs for net/http
clearly state,
> Get, Head, Post, and PostForm make HTTP (or HTTPS) requests
but I can't find any documentation on this error.
The source for crypto/rsa
only has this to say about the error:
// ErrVerification represents a failure to verify a signature.
// It is deliberately vague to avoid adaptive attacks.
var ErrVerification = errors.New("crypto/rsa: verification error")
So I'm not sure where to go from here. I'm pretty sure it's not their fault because Chrome is happy with their https certificate.
I've also tried using a Client
with a tls.Config
that has InsecureSkipVerify
set to true
, but that didn't seem to shut this error up.
答案1
得分: 1
鉴于测试在我的Ubuntu 12.04上的Go 1.2版本上正常工作,可能有以下两种情况:
- 您正在使用非常旧的Go版本。
- 您的系统根证书已过期。
如果您想更新根证书,这里是Windows的提示。通过谷歌搜索,您可以找到其他操作系统的更多想法。
英文:
Go uses the system root SSL certificate under linux and windows.
Given that the test works fine on my ubuntu 12.04 box with go 1.2, either
- You are using a very old version of go
- Your system has out of date root certificates
If you want to update your root certificates, here is a hint for windows. Googling should find you more ideas for other OSes.
答案2
得分: 0
在我的情况下,这是因为我设置了错误的公钥来验证令牌。当我将其更改为正确的公钥时,它就像魔术般地工作了。
英文:
In my case, it happened because I set the wrong public key for verifying the token. When I changed it to the correct one, it worked like a charm.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论