x509 certificate signed by unknown authority

2019-07-23 22:31发布

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.

标签: ssl go x509
1条回答
倾城 Initia
2楼-- · 2019-07-23 23:25

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
查看更多
登录 后发表回答