嵌套子域的OpenSSL和apache2通配符自签名证书

时间:2011-12-14 12:14:22

标签: apache certificate openssl subdomain wildcard

我对嵌套子域和通配符openssl证书有一些问题。也许这是因为子域类型是:site1.parisgeo.cnrs.fr,或site2.parisgeo.cnrs.fr,或者像xxxx.parisgeo这样的其他子域。 cnrs.fr

当我创建自签名证书时,我输入CN = * .parisgeo.cnrs.fr,但似乎无法使用此配置在此站点上连接例如partage.parisgeo.cnrs.fr!精氨酸。

我的虚拟主机和我的apache2 conf 工作没有通配符cerficate,所以问题不在这里我想:

port.conf

 NameVirtualHost *:443
 Listen 443

我有一个示例虚拟主机:

<VirtualHost *:443>
  ServerName partage.parisgeo.cnrs.fr
  ServerAlias www.partage.parisgeo.cnrs.Fr

  DocumentRoot /var/www/owncloud

        <Directory /var/www/owncloud>
                Options -Indexes FollowSymLinks MultiViews
                AllowOverride All
                Order allow,deny
                Allow from all
        </Directory>

   SSLEngine on

   SSLCertificateFile    /etc/ssl/parisgeo.cnrs.fr.crt
   SSLCertificateKeyFile /etc/ssl/parisgeo.cnrs.fr.key
   </VirtualHost>

我生成我的证书(CN = * .parisgeo.cnrs.fr):

openssl genrsa -des3 -out ca.key 2048
openssl req -new -x509 -days 3650 -key ca.key -out ca.crt
openssl req -newkey rsa:1024 -nodes -keyout parisgeo.cnrs.fr.key -out parisgeo.cnrs.fr.csr

openssl x509 -req -days 3650 -in parisgeo.cnrs.fr.csr -CA ca.crt -CAcreateserial  -CAkey ca.key -out parisgeo.cnrs.fr.crt

生成密钥文件的权利:

-rw-r--r-- 1 root root      1424 14 déc.  11:51 ca.crt
-rw-r--r-- 1 root root      1743 14 déc.  11:50 ca.key
-rw-r--r-- 1 root root        17 14 déc.  12:13 ca.srl
-rw-r--r-- 1 root root       981 14 déc.  12:13 parisgeo.cnrs.fr.crt
-rw-r--r-- 1 root root       627 14 déc.  12:08 parisgeo.cnrs.fr.csr
-rw-r--r-- 1 root root       891 14 déc.  12:08 parisgeo.cnrs.fr.key

当我尝试使用openssl连接并测试证书时:

root@xxxx:/etc/ssl# openssl s_client -connect partage.parisgeo.cnrs.fr:443 
CONNECTED(00000003)
depth=0 /C=FR/ST=IDF/L=PARIS/O=CNRS/CN=*.parisgeo.cnrs.fr
verify error:num=18:self signed certificate
verify return:1
depth=0 /C=FR/ST=IDF/L=PARIS/O=CNRS/CN=*.parisgeo.cnrs.fr
verify return:1
---
Certificate chain
 0 s:/C=FR/ST=IDF/L=PARIS/O=CNRS/CN=*.parisgeo.cnrs.fr
   i:/C=FR/ST=IDF/L=PARIS/O=CNRS/CN=*.parisgeo.cnrs.fr
---
Server certificate
-----BEGIN CERTIFICATE-----
..... blabla .....
-----BEGIN CERTIFICATE-----
subject=/C=FR/ST=IDF/L=PARIS/O=CNRS/CN=*.parisgeo.cnrs.fr
issuer=/C=FR/ST=IDF/L=PARIS/O=CNRS/CN=*.parisgeo.cnrs.fr
---
No client certificate CA names sent
---
SSL handshake has read 1253 bytes and written 319 bytes
---
New, TLSv1/SSLv3, Cipher is DHE-RSA-AES256-SHA
Server public key is 1024 bit
Secure Renegotiation IS supported
Compression: NONE
Expansion: NONE
SSL-Session:
    Protocol  : TLSv1
    Cipher    : DHE-RSA-AES256-SHA
    Session-ID: 7642C70A1E358CAA5901C060A26655DE3AF0BA683C9A598BA7C4B14FF108ADD7
    Session-ID-ctx: 
    Master-Key: 65184165198498498484 6516511321584831181468469431688132138498
    Key-Arg   : None
    Start Time: 1323862629
    Timeout   : 300 (sec)
    Verify return code: 18 (self signed certificate)
---
closed

尝试连接到网站时出现firefox错误:

An error occurred during a connection to partage.parisgeo.cnrs.fr.
Peer's certificate has an invalid signature.
(Error code: sec_error_bad_signature)

如果您有任何想法可以帮我解决这个问题.. 非常感谢 ! SR。

1 个答案:

答案 0 :(得分:0)

我已将说明放在gist

找到您的openssl.conf

  1. 取消注释req_extensions = v3_req
  2. req_extensions = v3_req # The extensions to add to a certificate request

    1. 将subjectAltName添加到v3_req部分
    2. [ v3_req ]
      basicConstraints = CA:FALSE keyUsage = nonRepudiation, digitalSignature, keyEncipherment subjectAltName = @alt_names

      1. 最后添加您希望此证书有效的备用名称。
      2. [alt_names] DNS.1 = yourdomain.com DNS.2 = *.yourdomain.com

        运行以下命令:

        openssl genrsa -des3 -out hostname.key 2048 openssl rsa -in hostname.key -out hostname-key.pem openssl req -new -key hostname-key.pem -out hostname-request.csr openssl x509 -req -extensions v3_req -days 365 -in hostname-request.csr -signkey hostname-key.pem -out hostname-cert.pem -extfile <path to openssl.conf>