【问题标题】:Intermediate certificate doesn't match private key with Go中间证书与 Go 的私钥不匹配
【发布时间】:2016-04-18 16:57:37
【问题描述】:

我正在尝试构建一个运行 https 应用程序的 Go (golang) 程序。

我在 SSL 中间证书方面确实遇到了问题,不知道问题出在哪里,是来自我的证书还是来自 Go 语言应用程序。

所以,我从我的 SSL CA 提供商那里获得了两个证书文件:服务器证书和中间证书。

所以,我正在尝试从我的 go 代码中加载这些证书,如下所示:

tlsConfig := &tls.Config{}
tlsConfig.Certificates = make([]tls.Certificate, 2)
var err error
tlsConfig.Certificates[0], err = tls.LoadX509KeyPair(serverCertificate, privateKey)
if err != nil {
    log.Fatal(err)
}
tlsConfig.Certificates[1], err = tls.LoadX509KeyPair(intermeddiateCertificate, privateKey)
if err != nil {
    log.Fatal(err)
}
tlsConfig.BuildNameToCertificate()

server := &http.Server{
    ReadTimeout:    10 * time.Second,
    WriteTimeout:   10 * time.Second,
    MaxHeaderBytes: 1 << 20,
    TLSConfig:      tlsConfig,
    Addr:           ":443,
}

   app.RunServer(server)

代码在此行第二次加载证书时失败

tls.LoadX509KeyPair(intermeddiateCertificate, privateKey)

错误是证书与私钥不匹配。

中间证书是否应该与 SSL/TLS 世界中的私钥匹配?

或者它不必。 如果不需要,那么如何在没有私钥的情况下加载证书?

我应该返回我的 CA 并告诉他们为什么中间证书与私钥不匹配?

【问题讨论】:

  • 正如@Steffen 回答的那样,如果您将证书和中间证书文件连接到一个文件中,它将起作用。

标签: ssl go ssl-certificate tls1.2


【解决方案1】:

您没有中间证书的密钥,只有服务器证书。请注意,我对 Go 了解不多,但根据 Golang SSL TCP socket certificate configuration,您只需将中间证书包含在与服务器证书相同的 PEM 文件中即可。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-07-13
    • 2011-10-16
    • 2022-07-26
    • 2021-11-06
    • 2013-09-29
    • 1970-01-01
    相关资源
    最近更新 更多