【问题标题】:Unable to start Apache on CentOS Private Key Not Found无法在 CentOS 上启动 Apache 未找到私钥
【发布时间】:2018-04-28 14:45:16
【问题描述】:

我无法在装有 SELinux 的 CentOS 服务器上启动 Apache。错误日志给出。

[root@server httpd]# cat test-error_log
[Wed Nov 15 05:42:34 2017] [error] Init: Private key not found
[Wed Nov 15 05:42:34 2017] [error] SSL Library Error: 218529960 error:0D0680A8:asn1 encoding routines:ASN1_CHECK_TLEN:wrong tag
[Wed Nov 15 05:42:34 2017] [error] SSL Library Error: 218640442 error:0D08303A:asn1 encoding routines:ASN1_TEMPLATE_NOEXP_D2I:nested asn1 error
[Wed Nov 15 05:42:34 2017] [error] SSL Library Error: 218529960 error:0D0680A8:asn1 encoding routines:ASN1_CHECK_TLEN:wrong tag
[Wed Nov 15 05:42:34 2017] [error] SSL Library Error: 218595386 error:0D07803A:asn1 encoding routines:ASN1_ITEM_EX_D2I:nested asn1 error
[Wed Nov 15 05:42:34 2017] [error] SSL Library Error: 67710980 error:04093004:rsa routines:OLD_RSA_PRIV_DECODE:RSA lib
[Wed Nov 15 05:42:34 2017] [error] SSL Library Error: 218529960 error:0D0680A8:asn1 encoding routines:ASN1_CHECK_TLEN:wrong tag
[Wed Nov 15 05:42:34 2017] [error] SSL Library Error: 218595386 error:0D07803A:asn1 encoding routines:ASN1_ITEM_EX_D2I:nested asn1 error

这里也失败了

[root@server private]#  openssl rsa -in test.key -check -noout
unable to load Private Key
140598241089352:error:0D0680A8:asn1 encoding routines:ASN1_CHECK_TLEN:wrong tag:tasn_dec.c:1319:
140598241089352:error:0D07803A:asn1 encoding routines:ASN1_ITEM_EX_D2I:nested asn1 error:tasn_dec.c:381:Type=RSA
140598241089352:error:04093004:rsa routines:OLD_RSA_PRIV_DECODE:RSA lib:rsa_ameth.c:115:
140598241089352:error:0D0680A8:asn1 encoding routines:ASN1_CHECK_TLEN:wrong tag:tasn_dec.c:1319:
140598241089352:error:0D07803A:asn1 encoding routines:ASN1_ITEM_EX_D2I:nested asn1 error:tasn_dec.c:381:Type=PKCS8_PRIV_KEY_INFO
140598241089352:error:0907B00D:PEM routines:PEM_READ_BIO_PRIVATEKEY:ASN1 lib:pem_pkey.c:132:

路径在conf文件中

[root@server conf]# cat /etc/httpd/conf.d/test.conf
<VirtualHost *:443>
ServerAdmin webmaster@server.com
DocumentRoot /var/www/html/test
ServerName server.server.com

SSLEngine on
SSLProtocol all -SSLv2 -SSLv3
SSLCipherSuite ALL:!ADH:!EXPORT:!SSLv2:RC4+RSA:+HIGH:+MEDIUM:+LOW
SSLCertificateFile /etc/pki/tls/certs/test.crt
SSLCertificateKeyFile /etc/pki/tls/private/test.key


ErrorLog logs/test-error_log
CustomLog logs/test-access_log common

我还检查了私钥中没有空格。有什么其他想法会出错吗?

还有

[root@server etc]#  ls -dZ /etc/pki/tls/private/
drwxr-xr-x. root root system_u:object_r:httpd_sys_content_t:s0 /etc/pki/tls/private/
[root@server etc]#  ls -dZ /etc/pki/tls/certs/
drwxr-xr-x. root root system_u:object_r:httpd_sys_content_t:s0 /etc/pki/tls/certs/

我还检查了私钥中没有空格和适当数量的破折号。

编辑: ls -al /etc/pki/tls/private/ 和 ls -al /etc/pki/tls/certs/ 的输出

[root@server ~]# ls -al /etc/pki/tls/certs/
total 1788
drwxr-xr-x. 2 root root    4096 Nov 15 08:51 .
drwxr-xr-x. 5 root root    4096 Feb 11  2015 ..
-rw-r--r--. 1 root root  786601 Jul 14  2014 ca-bundle.crt
-rw-r--r--. 1 root root 1005005 Jul 14  2014 ca-bundle.trust.crt
-rw-------. 1 root root    1513 Feb 11  2015 localhost.crt
-rwxr-xr-x. 1 root root     610 Jan 20  2015 make-dummy-cert
-rw-r--r--. 1 root root    2242 Jan 20  2015 Makefile
-rwxr-xr-x. 1 root root     829 Jan 20  2015 renew-dummy-cert
-rw-r--r--. 1 root root    1208 Feb 11  2015 test.crt
-rw-------. 1 root root    3258 Nov 15 08:51 test_1.cert
[root@ip-10-155-16-219 ~]# ls -al /etc/pki/tls/private/
total 16
drwxr-xr-x. 2 root root 4096 Nov 18 21:15 .
drwxr-xr-x. 5 root root 4096 Feb 11  2015 ..
-rw-------. 1 root root 1679 Feb 11  2015 localhost.key
-rw-r--r--. 1 root root 1679 Nov 18 21:15 test.key
[root@server ~]#

【问题讨论】:

    标签: apache ssl centos private-key


    【解决方案1】:

    你的私钥加密了吗? 要确定您的私钥是否已加密:

    grep ENCRYPTED /etc/pki/tls/private/test.key
    

    如果是,请从私钥中删除密码:

    openssl rsa -in /etc/pki/tls/private/test.key -out /etc/pki/tls/private/test-new.key
    

    检查你的私钥的头部,应该是这样的:

    -----BEGIN RSA PRIVATE KEY-----
    

    检查页脚,应该是这样的:

    -----END RSA PRIVATE KEY-----
    

    删除页脚后的所有空格或换行符。

    希望对你有帮助

    【讨论】:

    • 它没有加密,我已经检查了开头或结尾没有空格。还有其他想法吗?
    • 能列出ls -al /etc/pki/tls/certs/ls -al /etc/pki/tls/private/的内容吗?
    • 添加在主要问题上。
    • 您是否尝试过重新生成您的私钥和公钥?
    • 我已经有证书了。重新生成私钥需要向 CA 发送 CSR 以提供证书。也许我可以使用 OpenSSL。是否有绝对 100% 的方法可以知道私钥是否不正确?
    猜你喜欢
    • 2017-07-21
    • 2016-11-12
    • 2013-12-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多