Apache警告我的自签名证书是CA证书 [英] Apache warns that my self-signed certificate is a CA certificate

查看:823
本文介绍了Apache警告我的自签名证书是CA证书的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于我不太清楚openssl命令的参数,因此我习惯于指代相同的 SO答案每当我需要创建自签名证书时(用于测试环境).该命令如下所示:

As I don't know the openssl command's arguments by heart, I am used to referring to the same SO answer whenever I need to create self-signed certificates (for testing environments). The command looks like:

openssl req -x509 -nodes -newkey rsa:2048 -keyout mysite.key -out mysite.crt -days 365

它通常可以工作,例如在我当前的Ubuntu 15.10上.今天,我使用的是Debian Jessie的全新安装,事实并非如此. Apache在启动时警告:

And it usually works, for instance on my current Ubuntu 15.10. Today I'm on a fresh install of Debian Jessie and it doesn't. Apache warns at startup that:

[ssl:warn] [pid 1040] AH01906: www.mysite.com:443:0 server certificate is a CA certificate (BasicConstraints: CA == TRUE !?)

我正在寻找解决问题的方法,发现在Linux论坛中的答案,指出应改为使用以下内容:

I looked for a solution to the problem and found an answer in a linux forum stating that the following should be used instead:

openssl genrsa -des3 -passout pass:x -out mysite.pass.key 2048
openssl rsa -passin pass:x -in mysite.pass.key -out mysite.key
openssl req -new -key mysite.key -out mysite.csr
openssl x509 -req -days 365 -in mysite.csr -signkey mysite.key -out mysite.crt

的确如此,Apache警告消失了.

And it's true, this way the Apache warning disappears.

据我所知,这将创建一个受密码短语保护的密钥,然后删除该密码短语,然后创建一个CSR,然后同时生成带有CSR和密钥的证书.

As far as I understand, this creates a passphrase-protected key, then removes the passphrase, then creates a CSR, then generates the certificate with both the CSR and the key.

所以问题是:这个较长的版本会做什么,而较短的版本不会做什么?为什么在某些情况下(例如今天对我而言)有必要?

So the question is: what does this longer version do that the shorter doesn't, and why is it necessary in some cases (like today for me)?

推荐答案

快捷方式(例如,使用OpenSSL 1.1.0f和Apache 2.4.37):

Short way (e.g. with OpenSSL 1.1.0f and Apache 2.4.37):

openssl genrsa -out notEncodedPk.key 3072
openssl req -new -out website.csr -sha256 -key notEncodedPk.key
openssl x509 -req -in website.csr -days 365 -signkey notEncodedPk.key -out website.cert -outform PEM

genrsa 会生成3072位的RSA密钥. (系统应该在线一段时间,以在/dev/(u)random中获得良好的数据以进行播种.)无需生成加密的PK(1),然后使用 rsa 进行删除之后输入密码. (也许早期版本的工具需要密码吗?)
req 创建证书签名请求,并使用PK进行签名.为摘要提供类似 -sha256 的内容是可选的. (3)在交互式问题区中提供您的信息.确保将您的站点域放在公用名:"中,否则Apache将抛出警告(AH01909),而浏览器将抛出无效证书"消息,因为URL/域与证书数据不匹配(2).将挑战密码:"留空.
使用 x509 创建带有 -signkey 的自签名证书(主题已复制到颁发者).通常,该命令适用于证书,但是使用 -req 时,它接受CSR作为输入.然后使用您的PK签署证书. ( -outform -days 是可选的,其中30天为后者的默认值.)

genrsa generates a 3072 bit RSA-Key. (The system should be online for some time to have good data in /dev/(u)random for seeding.) There is no need to generate an encrypted PK (1) and then use rsa to remove the password afterwards. (Maybe earlier versions of the tools required a password?)
req creates the certificate signing request and uses the PK for the signature. Providing something like -sha256 for the digest is optional. (3) Provide your infos in the interactive questionare. Ensure to put your site domain in "Common name:", otherwise the Apache will throw a warning (AH01909) and browsers will throw an "invalid certificate" message because the URL/domain does not match the certificate data (2). Leave "A challange password:" empty.
Use x509 to create a self-signed certificate with -signkey (the subject is copied to issuer). Normally the command works on certificates but with -req it accepts a CSR as an input. Then use your PK for signing the certificate. (-outform and -days are optional, with 30 days as the default value for the latter.)

问题源:

如user207421所述: req 创建CSR OR ,它将创建自签名的类似于root-CA的证书,因此通常教程技巧

As user207421 already stated: req creates a CSR OR it creates a self-signed root-CA-like certificate, therefore the typical tutorial tip

openssl req -x509 -nodes -days 365 -newkey rsa:3072 -sha256 -keyout website.key -out website.cert

很短,但通常不是您想要的.您还可以将创建的证书与

is short but normally not what you want. You can also compare created certificates with

openssl x509 -text -noout -in website.cert

在使用单行命令创建的证书中,您会看到"X509v3扩展名:"部分以及"X509v3基本约束:严重CA:TRUE".这正是Apache警告消息.
相反,如果通过三个步骤创建证书,则证书中不包括"X509v3扩展名:"部分.

In the certificate, created with the single-line command, you see a section "X509v3 extensions:" with "X509v3 Basic Constraints: critical CA:TRUE". This is exactly the Apache warning message.
Instead, if you create the certificate with the three steps, the "X509v3 extensions:" section is not included into the certificate.

附录:

(1)在大多数情况下,使用密码保护PK是一个好主意.如果存储的PK未加密,请确保限制对root的访问.如果使用密码,则必须使用 -passout/-passin 选项,但是请注意,简单的"x"不再起作用,因为某些OpenSSL工具需要至少4个字符(否则: 结果太小/密码读取错误").另外,在Apache中,您必须使用 SSLPassPhraseDialog buildin 之类的方法在Apache启动期间手动输入PK(甚至所有PK/证书)所需的密码.

(1) Securing the PK with a password is a good idea in most cases. If the PK is stored without encryption, make sure to restrict access to root. If you use a password, you have to use the -passout/-passin options, but be aware that a simple "x" does not work anymore because some OpenSSL tools require at least 4 characters (otherwise: "result too small/bad password read"). Additionally in Apache you have to use something like SSLPassPhraseDialog buildin to manually enter the required password for the PK (or even for all PKs/certs) during Apache startup.

(2)无论如何,浏览器都会显示有关自签名证书的警告.

(2) Anyway, browsers will display a warning for self-signed certificates.

(3)对于如此大的RSA密钥,使用SHA-1是不够的.通常,最好查看您的openssl.conf,例如在/etc/ssl/openssl.conf中的Debian 9中,其中包含各种默认值,例如 signer_digest = sha256 .
在Debian 9文件中,您还可以在[req]部分中找到一行 x509_extensions = v3_ca ,这就是为什么 req 命令与-x509结合使用的原因如果以单行样式用于创建自签名证书,则该选项会添加与CA相关的扩展名( basicContraints = critical,CA:true ).

(3) Using SHA-1 would be inadequate for such a large RSA-key. In general, it is a good idea to review your openssl.conf, e.g. in Debian 9 in /etc/ssl/openssl.conf, which contains various defaults, for example signer_digest = sha256.
In the Debian 9 file, you also find in the [req] section a line x509_extensions=v3_ca and this is the reason, why the req command in combination with the -x509 option adds the CA-related extension (basicContraints=critical,CA:true), if used in the single-line style to create a self-signed certificate.

此外,您可能会注意到一条注释行#req_extensions = v3_req .因为该行已被注释掉(在Debian 9中默认为openssl.cnf),所以 req 命令的简单用法不包含任何扩展名.
请注意,您可能会在修改后的文件中使用此行,将主题备用名称添加到证书中,例如因此它可以处理多个(子)域(通常比在CN中使用通配符(例如* .example.com)要好得多.)

Addidionally you might notice a comment-line # req_extensions=v3_req. Because this line is commented out (in Debian 9 default openssl.cnf), the simple usage of the req command does not include any extensions.
Note that you might use this line in a modified file to add Subject Alternative Name's to the certificate, e.g. so it can handle multiple (sub-)domains (normally a much better choice than using e wildcard in CN, e.g. *.example.com).

这篇关于Apache警告我的自签名证书是CA证书的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆