golang: HTTPS请求返回“crypto/rsa: 验证错误”

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

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设置为truetls.ConfigClient,但似乎无法解决这个错误。

英文:

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

Go在LinuxWindows下使用系统根SSL证书。

鉴于测试在我的Ubuntu 12.04上的Go 1.2版本上正常工作,可能有以下两种情况:

  1. 您正在使用非常旧的Go版本。
  2. 您的系统根证书已过期。

如果您想更新根证书,这里是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

  1. You are using a very old version of go
  2. 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.

huangapple
  • 本文由 发表于 2014年3月14日 21:55:54
  • 转载请务必保留本文链接:https://go.coder-hub.com/22407042.html
匿名

发表评论

匿名网友

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

确定