您如何在Go中建立tls.Certficate链?

pht*_*ier 5 ssl go

我正在尝试配置TLS服务器以在连接时返回证书

我想创建一个带有证书tls.Config

    // Certificates contains one or more certificate chains
    // to present to the other side of the connection.
    // Server configurations must include at least one certificate
    // or else set GetCertificate.
    Certificates []Certificate
Run Code Online (Sandbox Code Playgroud)

假设我的链为root -> inter -> server,我可以独立加载每个证书,并使用一个列表,但是只有serverCert发送到SSL客户端。

我正在按照以下方式进行操作:

root, err := tls.LoadX509KeyPair("root.crt", "root.key")
inter, err := tls.LoadX509KeyPair("inter.crt", "inter.key")
server, err := tls.LoadX509KeyPair("server.crt", "server.key")

config := tls.Config{
   Certificates : []tls.Certificates{root, inter, server}
}
config.BuildNameFromCertificates()
Run Code Online (Sandbox Code Playgroud)

我是否缺少明显的东西?顺序重要吗?