x509证书由未知机构签名

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

x509 certificate signed by unknown authority

问题

我正在尝试一些基本示例来请求网络数据,但是对不同主机的所有请求都会导致 SSL 错误:x509: certificate signed by unknown authority。注意:我没有使用代理,也没有发生任何形式的证书拦截,因为使用 curl 或浏览器没有任何问题。

我目前正在使用的代码示例是:

package main

import (
    "fmt"
    "net/http"
    "io/ioutil"
    "os"
)

func main() {
    response, err := http.Get("https://google.com")
    if err != nil {
        fmt.Printf("%s\n", err)
        os.Exit(1)
    } else {
        defer response.Body.Close()
        contents, err := ioutil.ReadAll(response.Body)
        if err != nil {
            fmt.Printf("%s", err)
            os.Exit(1)
        }
        fmt.Printf("%s\n", string(contents))
    }
}

编辑:代码在 Arch Linux 内核 4.9.37-1-lts 上运行。

编辑 2:显然 /etc/ssl/certs/ca-certificates.crt 在我的系统上与版本有差异,通过(重新)移除证书并手动重新安装 ca-certificates-utils 包,问题得到解决。

英文:

I'm trying some basic examples to request data from the web, however all requests to different hosts result in an SSL error: x509: certificate signed by unknown authority. Note: I'm not behind a proxy and no forms of certificate interception is happening, as using curl or the browser works without problems.

The code sample I'm currently working with is:

package main

import (
    "fmt"
    "net/http"
    "io/ioutil"
    "os"
    )

func main() {
    response, err := http.Get("https://google.com")
    if err != nil {
        fmt.Printf("%s\n", err)
        os.Exit(1)
    } else {
        defer response.Body.Close()
        contents, err := ioutil.ReadAll(response.Body)
        if err != nil {
            fmt.Printf("%s", err)
            os.Exit(1)
        }
        fmt.Printf("%s\n", string(contents))
    }
}

Edit: Code is run on Arch linux kernel 4.9.37-1-lts.

Edit 2: Apparently /etc/ssl/certs/ca-certificates.crt had a difference between the version on my system, by (re)moving the certificate and re-installing the ca-certificates-utils package manually, the issue was solved.

答案1

得分: 9

根据你的错误信息,我猜测你正在使用Linux操作系统?

很可能你需要在运行程序的机器上安装ca-certificates。

在Ubuntu上,你可以执行以下命令:

sudo apt-get install ca-certificates
英文:

Based on your error, I'm assuming you are using Linux?

It's likely that you will have to install ca-certificates on the machine your program is running on.

On Ubuntu, you would execute something like this:

sudo apt-get install ca-certificates

huangapple
  • 本文由 发表于 2017年7月18日 19:41:49
  • 转载请务必保留本文链接:https://go.coder-hub.com/45165813.html
匿名

发表评论

匿名网友

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

确定