【问题标题】:How to solve x509: certificate has expired or is not yet valid when doing http requests如何解决x509:进行http请求时证书已过期或尚未生效
【发布时间】:2020-12-29 21:39:06
【问题描述】:

我有一个从 golang.org/x/crypto/acme/autocert 获取证书的网络服务器

我在虚拟机上运行它。

相关代码:

cache := autocert.DirCache("cert")

certManager := autocert.Manager{
    Prompt:     autocert.AcceptTOS,
    HostPolicy: autocert.HostWhitelist(common.ConfHost.GetString(), "www."+common.ConfHost.GetString()),
    Email:      common.ConfEmail.GetString(),
    Cache:      cache,
}

这是我用于 HTTP 请求的内容:resp, err := http.DefaultClient.Get(url)

当我尝试从特定 API 获取时,我收到此错误:x509: certificate has expired or is not yet valid current time 2020-12-28T17:29:37Z is after 2020-12-26T08:22:28Z

但它只发生在那个特定的 API 上。我已经尝试了其他几个,它们都有效。

该代码在 12 月 26 日证书过期之前一直有效。

另一方面,我写了一个main.go 来测试,没有我必须在我的网络服务器上使用的所有证书来测试。当我在本地机器上运行代码时,我会从 API 获得响应,没有任何问题。

这是main.go 文件:https://play.golang.org/p/-EB9DIjJYQO

我该如何解决这个问题?

【问题讨论】:

    标签: go acme autocert


    【解决方案1】:

    你是using的包的当前状态

    这个包正在开发中,没有 API 稳定性承诺。

    很难说为什么这个 API 不像其他 API 那样工作,可能是你的代码或包本身的东西。

    您可以尝试certmagic 包并针对它测试您的代码,它已经完全成熟并且已经投入生产了。

    【讨论】:

      猜你喜欢
      • 2018-06-03
      • 2016-05-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-04
      • 1970-01-01
      • 2018-01-12
      • 1970-01-01
      相关资源
      最近更新 更多