【问题标题】:mod24_ssl won't read certificate that validates against opensslmod24_ssl 不会读取针对 openssl 进行验证的证书
【发布时间】:2016-09-14 04:20:18
【问题描述】:

所以我在尝试在 EC2 服务器上启动 apache 时遇到了问题。

规格:

OS: Amazon Linux AMI r2016.03
httpd24.x86_  64 2.4.18-1.64.amzn1
mod24_ssl.x86_64 2.4.18-1.64.amzn1

Apache 配置:

<VirtualHost *:443>
    DocumentRoot            /var/www/zxurian.com/html/
    ServerAdmin             root@localhost.com
    ServerName              zxurian.com

    DirectoryIndex          index.php

    SSLEngine               on
    SSLProtocol             all -SSLv2 -SSLv3 -TLSv1
    SSLCipherSuite          "AES256+EECDH:AES256+EDH"
    SSLHonorCipherOrder     on
    SSLCertificateFile      /etc/httpd/ssl/certificate.crt
    SSLCertificateChainFile /etc/httpd/ssl/certificate.cc-bundle
    SSLCertificateKeyFile   /etc/httpd/ssl/certificate.key

    Header always set Strict-Transport-Security "max-age=31536000; includeSubDomains"
    Header always append X-Frame-Options SAMEORIGIN

    <Directory "/var/www/zxurian.com">
            Require all granted
            AllowOverride All
    </Directory>
    <FilesMatch "^\.">
            Order Allow,Deny
            Deny from All
    </FilesMatch>
    <DirectoryMatch "^\.|\/\.">
            Order Deny,Allow
            Deny from All
    </DirectoryMatch>
</VirtualHost>

我将私钥和购买的证书复制到服务器以供使用。运行 openssl x509 -noout -text -in certificate.crt 会显示证书信息。运行openssl rsa -in certificate.key -check 会给我一个RSA key ok。但是,当尝试启动 apache 时,出现以下错误:

[Tue May 17 21:07:12.592129 2016] [ssl:emerg] [pid 8896] AH02572: Failed to configure at least one certificate and key for hub.tantor.com:443
[Tue May 17 21:07:12.592145 2016] [ssl:emerg] [pid 8896] SSL Library Error: error:0906D06C:PEM routines:PEM_read_bio:no start line (Expecting: DH PARAMETERS) -- Bad file contents or format - or even just a forgotten SSLCertificateKeyFile?
[Tue May 17 21:07:12.592151 2016] [ssl:emerg] [pid 8896] SSL Library Error: error:0906D06C:PEM routines:PEM_read_bio:no start line (Expecting: EC PARAMETERS) -- Bad file contents or format - or even just a forgotten SSLCertificateKeyFile?
[Tue May 17 21:07:12.592158 2016] [ssl:emerg] [pid 8896] SSL Library Error: error:140A80B1:SSL routines:SSL_CTX_check_private_key:no certificate assigned

在这一点上,我没有想法。我已经验证该文件没有额外的行尾。文件上的vi -b 不显示文件中的额外信息(即,没有^M 或windows 行结尾)。它的设置与我的其他运行良好的 EC2 服务器相同。

还有什么我可以查的吗?

根据请求添加:

[zxurian@ip-10-0-200-22 ssl]$ egrep 'BEGIN|END' certificate.crt
-----BEGIN CERTIFICATE-----
-----END CERTIFICATE-----
[zxurian@ip-10-0-200-22 ssl]$ egrep 'BEGIN|END' certificate.key
-----BEGIN PRIVATE KEY-----
-----END PRIVATE KEY-----

【问题讨论】:

  • 这可能不是什么安慰,但我怀疑错误消息是在谎报真正的问题。您可以编辑帖子以包含 egrep 'BEGIN|END' /etc/httpd/ssl/certificate.crt 的输出以及其他文件的相同内容,以进行完整性检查。
  • 添加到原帖
  • 如果我把你送进黑洞,我提前道歉,因为我尽量避免使用 apache...但是那个私钥不应该说 -----BEGIN RSA PRIVATE KEY----- 吗?转换它:openssl rsa -in certificate,key -out certificate.rsakey 然后更改您的配置以使用新创建的文件。
  • 我在另一台 EC2 服务器上的密钥文件(相同的 Amazon Linux/Apache/mod24_ssl 设置)也有 -----BEGIN PRIVATE KEY-----,但为了论证,我尝试将密钥转换为 rsa,切换密钥文件apache 配置,还是一样的错误。

标签: apache ssl amazon-ec2


【解决方案1】:

首先是线索:你不能再依赖你的VirtualHost 定义了。您必须像这样从 conf.d/ssl.conf 引用有效的证书/密钥对(位置是我的 Fedora 系统):

SSLCertificateFile /etc/pki/tls/certs/localhost.crt

SSLCertificateKeyFile /etc/pki/tls/private/localhost.pem

我的是自签名证书,从 httpd-2.2/openssl-1.0.2h 继承。证书采用 ascii PEM 格式。密钥已转换为 RSA 明文副本,因此 httpd 启动时不需要密码。 (在你这样做之前仔细评估你的环境)。为它制作的证书看起来并不重要,因为它仍然是在将呈现给客户端的 VirtualHost 部分中定义的证书。对我来说,这些证书(从 httpd-2.2 继承)采用 PEM 短格式,而相应的密钥再次采用 RSA 清晰副本形式。当然,您必须加载 mod_ssl.so,但如果您在 httpd-2.2 中有工作,那么您已经这样做了。作为记录:我的系统上的任何地方都没有 dhparams.pem 文件(在我的案例中只是另一个错误的线索)。

【讨论】:

    猜你喜欢
    • 2020-06-26
    • 2019-01-29
    • 2012-09-26
    • 1970-01-01
    • 1970-01-01
    • 2012-11-27
    • 2015-01-12
    • 1970-01-01
    • 2015-05-05
    相关资源
    最近更新 更多