drmq16019 2016-04-18 16:57
浏览 58
已采纳

中级证书与Go的私钥不匹配

I am trying to build a Go (golang) program that will run https application.

I am really having trouble with SSL intermediate certificate and don't know where the problem, is it from my certificate or from Go language application.

So, I have from my SSL CA providers two certificate files : the server certificate, and intermediate certificate.

So, I am trying to load these certificates from my go code like this:

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)

the code fails on the second load of certificate on this line

tls.LoadX509KeyPair(intermeddiateCertificate, privateKey)

The error is the certificate doesn't match the private key.

Does the intermediate certificate should match the private key in SSL/TLS world?

or it doesn't have to. And in case doesn't have to, then how to load the certificate without a private key?

should I return back to my CA and tell them how come the intermediate certifcate doesn't match the private key?

  • 写回答

1条回答 默认 最新

  • douying6206 2016-04-18 17:09
    关注

    You don't have a key for the intermediate certificate, only for the server certificate. Note that I don't know much about Go, but according to Golang SSL TCP socket certificate configuration you simply include the intermediate certificate into the same PEM file as the server certificate.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度