如何将各种证书组合成单个 .pem

qui*_*tin 55 consolidation ssl-certificate apache-2.2

我刚刚读完了这个解释不同 SSL 格式的好线程

现在我基本上正在寻找与如何拆分 PEM 文件相反的方法

我想合并 4 个文件,最初是为 Apache 创建的,我正在查看由

  • SSL证书文件
  • SSL证书密钥文件
  • SSL证书链文件
  • SSLCAC证书文件

我最好奇的是合并衍生品中文件的顺序,这很重要吗?例如。如果我cat按照上面出现的顺序将它们放在一起,放入.pem,它是否有效,还是应该以特定方式订购?

仅供参考,我这样做是使用这些证书作为组合单一的缘故。质子交换膜SimpleSAMLphp

Dan*_* t. 66

根据RFC 4346,顺序确实很重要。

这是直接取自 RFC 的引用:

  certificate_list
    This is a sequence (chain) of X.509v3 certificates.  The sender's
    certificate must come first in the list.  Each following
    certificate must directly certify the one preceding it.  Because
    certificate validation requires that root keys be distributed
    independently, the self-signed certificate that specifies the root
    certificate authority may optionally be omitted from the chain,
    under the assumption that the remote end must already possess it
    in order to validate it in any case.
Run Code Online (Sandbox Code Playgroud)

根据此信息,服务器证书应该排在第一位,然后是任何中间证书,最后是根可信机构证书(如果是自签名)。我找不到有关私钥的任何信息,但我认为这无关紧要,因为 pem 中的私钥很容易识别,因为它以下面的文本开头和结尾,其中包含关键字PRIVATE

 -----BEGIN RSA PRIVATE KEY-----
 -----END RSA PRIVATE KEY-----
Run Code Online (Sandbox Code Playgroud)

  • cat site.crt root.crt site.key > site.pem (8认同)

小智 13

这是组合使用的命令 cat

cat first_cert.pem second_cert.pem > combined_cert.pem
Run Code Online (Sandbox Code Playgroud)

  • 您的回答并未指明文件应该以什么顺序* 连接(您只有“first_cert.pem”和“second_cert.pem”)。正确答案是`cat my_site.pem ca_chain.pem my_site.key > combine_cert.pem` (9认同)
  • 这是如何连接任何两个证书的答案,但不是如何为 Apache 合并/连接证书。 (7认同)