dpmopn8542 2014-08-30 03:01
浏览 66

golang SSL认证

So, here I am trying to have a socket listen on an SSL connection. However, it isn't able to make the handshake. Upon running

 sudo openssl s_client -CApath /etc/ssl/certs/ -connect localhost:8080

It is unable to verify the first cert.

I have very little experience with these SSL. Can anyone help?

  cert, err := tls.LoadX509KeyPair("positivessl.crt", "key.pem")
  Error.CheckError(err)                                                         

  rootCert, err := ioutil.ReadFile("AddTrustExternalCARoot.crt")   
  checkError(err)                                                         
  trustCert, err := ioutil.ReadFile("COMODORSAAddTrustCA.crt")        
  checkError(err)                                                         
  validationCert, err := ioutil.ReadFile("COMODORSADomainValidationSecureServerCA.crt")
  checkError(err)                                                         

  certs := x509.NewCertPool()                                                   
  certs.AppendCertsFromPEM(validationCert)                                      
  certs.AppendCertsFromPEM(trustCert)                                           
  certs.AppendCertsFromPEM(rootCert)                                            

  sslConfig := tls.Config{RootCAs: certs,Certificates: []tls.Certificate{cert}} 
  sslConfig.Rand = rand.Reader                                                                                                       

  listener, err := tls.Listen("tcp", service, &sslConfig)   
  • 写回答

1条回答 默认 最新

  • duanjia7912 2014-08-30 05:15
    关注

    I'm not familiar with go itself, but from the documentation at http://golang.org/pkg/crypto/tls/ they look similar to other SSL stacks:

    • The rootCert should not be included in the chain. The root cert is the actual trust anchor used for verification at the certificate chain at the client and thus the client must already know it and trust it.
    • RootCA are the trusted certificates which are used to verify the certificate. These are not send to the peer but used instead as the trust anchors when verifying the received certificates. Thus this setting is relevant for the client side to verify the servers certificate and maybe for the server side when the client send certificates too.
    • Instead all the certificates you want to send to the peer have to be included in Certificates. That is, not only the leaf certificates cert, but also the chain certificates validationCert and trustCert. You have to include them in the correct order so that they build a chain which the client then can finish with the trusted root certificate.
    评论

报告相同问题?

悬赏问题

  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计