`

怎样用OpenSSL来签发一个中级证书

阅读更多

How to create an intermediate Certificate Authority (CA) using openssl
(怎样用OpenSSL来签发一个中级证书)


    What is an Intermediate Certificate Authority (CA) and why do I need one? An Intermediate CA is an authority that you use to create your own SSL certificates in a PKI environment. An Intermediate CA depends on a Root CA that is the origin of the chain of trust. The idea is that if your Intermediate CA gets compromised or you decide to revocate all the certificates issued by it, you can still use your Root CA without further inconvenience for your users (the users only need to have installed the certificate of the Root CA in their browsers).
    As for the second question, the sort answer is that chances are that you really do not need one  but for the shake of the experiment lets get our hands dirty!
    First of all, I need to clarify that my interest in this topic was also risen by the fact that Verisign has switched to a two-tier hierarchy of Certificate Authorities, and this has some implications specially in the configuration of web server software:
    “As of April 2006, all SSL certificates issued by VeriSign require the installation of an Intermediate CA Certificate. The SSL certificates are signed by an Intermediate CA using a two-tier hierarchy (also known as trust chain) which enhances the security of your SSL Certificate. If the proper Intermediate CA is not installed on the server, your customers will see browser errors and may choose not to proceed further and close their browser.” (boldface is mine)
    This means that while the users do not need to modify anything (if their browser already has Verisigns Root CA certificate) the server owners need to ensure that the server is able to provide the so called trust chain to the users’ browser when the SSL handshake is performed.
    Never mind, lets get back to it. In order to get your Intermediate CA working, first you need a Root CA (if you already have a CA, feel free to skip the next section). Remember that in order to get this working you need to have a copy of the openssl toolkit installed in your system.


1. Configure the Root CA


mkdir /var/ca
cd /var/ca/
mkdir certs crl newcerts private
echo "01" > serial
cp /dev/null index.txt
# beware that the location of the sample file is dependent on your environment
cp /usr/lib/ssl/openssl.cnf ./


You may want to modify some of the settings in the configuration file to save you some time in the future when creating the certificates: default_bits, countryName, stateOrProvinceName, 0.organizationName_default, organizationalUnitName and emailAddress.
Now you are ready to create the CA:

# generate a private key
openssl genrsa -des3 -out private/cakey.key 4096
# create a self-signed certificate valid for 5 years
openssl req -new -x509 -nodes -sha1 -days 1825 -key private/cakey.pem -out cacert.pem
# go for the default values if you adapted the settings in the openssl.cnf file or enter the values you desire

Now you have everything you need to run a successful CA.



2. Configure an Intermediate CA


The idea is simple, we will create a new CA following the same template that we used in the previous section, but this time instead of generating a self-signed certificate we will generate a certificate sign request that we will sign using the Root CA.

First we create the folder structure:

cd /var/ca/
mkdir ca2008
cd ca2008
cp ../openssl.cnf ./
mkdir certs crl newcerts private
echo "01" > serial
cp /dev/null index.txt


Then the Intermediate CA private key:


#generate the key
openssl genrsa -des3 -out private/cakey.pem 4096
#generate a signing request (valid for 1year)
openssl req -new -sha1 -key private/cakey.pem -out ca2008.csr
# go for the default values if you adapted the settings in the openssl.cnf file or enter the values you desire


Move the sign request to the Root CA directory and sign it:

mv ca2008.csr ../
cd ../
openssl ca -extensions v3_ca -days 365 -out ca2008.crt -in ca2008.csr -config openssl.cnf
mv ca2008.* ca2008/
cd ca2008/
mv ca2008.crt cacert.pem


    And that was it. The next thing to do is start using your Intermediate CA to sign your new certificates. But just before that, remember that to verify a certificate signed by an Intermediate CA the web browser has to verify both the certificate against the Intermediate CA and the certificate of the Intermediate CA against a Root CA.
    In order to allow the browser to do this, a certificate chain file needs to be installed in the server. A certificate chain is a plaintext file that contains all the certificates from the Authority issuing a given certificate up to the Root of the certificate tree. In this case our chain has only two levels and the chain file is created like this:-


# first the intermediate CA certificate
cat cacert.pem > chain.crt
# then the Root CA cert
cat ../cacert.pem >> chain.crt


This file is the one you need to specify in the SSLCertificateChainFile of your server.



3. Create a new server certificate

# make sure you are in the Intermediate CA folder and not in the Root CA one
cd /var/ca/ca2008/
# create the private key
openssl genrsa -des3 -out {server_name}.key 4096
# generate a certificate sign request
openssl req -new -key {server_name}.key -out {server_name}.csr
# sign the request with the Intermediate CA
openssl ca -config openssl.cnf -policy policy_anything -out {server_name}.crt -infiles {server_name}.csr
# and store the server files in the certs/ directory
mkdir certs/{server_name}
mv {server_name}.key {server_name}.csr {server_name}.crt certs/


    Then you should securely copy the .key and .crt files to the server and configure it to use them.



4. Apache server configuration


Just in case you are using Apache server and for the shake of completeness, these are the settings that you need to modify (possibly in your extra/http-ssl.conf):-

SSLCertificateFile /var/ca/ca2008/certs/{server_name}.crt
SSLCertificateKeyFile /var/ca/ca2008/certs/{server_name}.key
SSLCertificateChainFile /var/ca/ca2008/chain.crt

 

 

5. References

SSL/TLS Strong Encryption: FAQ (http://httpd.apache.org/docs/2.0/ssl/ssl_faq.html)
Creating Your Own CA (http://www.onlamp.com/pub/a/onlamp/2003/02/06/linuxhacks.html)
Be your own Certificate Authority (http://www.g-loaded.eu/2005/11/10/be-your-own-ca/)
Very brief introduction to create a CA and a CERT (http://www.sendmail.org/~ca/email/other/cagreg.html)

 

分享到:
评论

相关推荐

    CA.zip_certificates_openssl 证书_数字证书

    2. 生成证书请求:使用`openssl req`命令创建一个证书签名请求(CSR),包含公共信息和公钥。 3. 签发证书:如果作为CA,可以使用`openssl x509`命令对CSR进行签名,生成证书。 4. 非自签名:若不是CA,可以将CSR...

    openssl创建ca 公私密钥 证书

    在IT行业中,加密和安全通信是至关重要的环节,OpenSSL是一个强大的安全套接层(SSL)和传输层安全(TLS)协议实现工具包,同时也包含了用于创建数字证书、管理CA(证书颁发机构)以及处理公钥基础设施(PKI)的相关工具。...

    基于OpenSSL的PKI环境设计(CA模块)

    在本文中,我们将深入探讨如何使用OpenSSL构建一个简单的CA(Certificate Authority,证书权威机构)模块,这对于理解和实践PKI系统的基础知识非常有帮助。 1. **CA的概念与角色** CA是PKI中的核心组件,它负责...

    openssl.zip

    OpenSSL是一个强大的安全套接字层密码库,包含各种主要的密码算法、常用的密钥和证书封装管理功能以及SSL协议,并提供丰富的应用程序用于测试或其他目的。在网络安全领域,OpenSSL是构建HTTPS和其他基于SSL/TLS协议...

    OpenSSL for Windows

    在Windows环境下,OpenSSL通常以静态库和动态库的形式存在,而`OpenSSL.exe`是一个命令行工具,用于执行各种SSL/TLS相关的操作,如生成证书请求(CSR)、签发和管理自签名证书、进行加密解密等。 1. **证书生命周期...

    nginx证书手册1

    2. 创建证书链:将服务器证书、中级根证书和根证书合并成一个证书链文件,如`cat server.crt intermediate.crt root.crt > chain.pem`。 3. 修改配置文件:在Nginx配置的相应服务器块中,添加SSL相关设置,包括证书...

    证书申请 证书审核 证书制作

    在实际操作中,可能会使用工具如OpenSSL来生成CSR,或者通过Web界面在CA的平台上完成申请流程。在服务器配置中,如HTTPS,证书需要正确配置到Web服务器软件(如Apache或Nginx),以启用加密通信。 了解并掌握证书...

    Apache证书手册1

    一旦CA验证了你的信息,他们会签发一个服务器证书。下载这个证书,通常是PEM或DER格式。 3. **关于证书的格式转换** 如果证书不是Apache需要的格式,如PKCS#7或DER,可以使用OpenSSL进行转换: ``` openssl x...

    EJBCA创建证书图解

    总之,EJBCA提供了一个强大且灵活的平台来管理数字证书。通过理解EJBCA的工作原理和证书生命周期,我们可以有效地保护网络通信的安全。对于IT专业人士来说,掌握EJBCA的使用方法是提升网络安全能力的重要一步。

    Python数字证书分析

    6. **证书链**:有时证书还包括了中级CA的证书,形成一个完整的信任链。 下面是一个简单的Python代码示例,使用`ssl`库解析证书: ```python import ssl context = ssl.create_default_context() with context....

    独立根CA服务器的建立.rar

    6. **设置中级CA(可选)**:为了增强安全性和管理效率,可以创建一个或多个中级CA,这些CA由根CA签发,负责签发终端实体证书。 7. **配置证书策略和申请流程**:定义哪些用户或服务可以申请证书,以及申请和审批...

    服务器证书安装指南(Websphere)

    其次,导入证书链中的中级证书和根证书。这一步骤确保了Websphere能够识别并信任所使用的SSL证书。 - **导入命令**:使用`keytool`命令行工具来完成证书的导入工作。例如,导入根证书的命令如下: ``` keytool-...

    windows服务器ssl证书创建、安装及配置方法

    接下来,使用MMC控制台导入这些中级CA证书到本地计算机的“中级证书颁发机构”存储中。 3. **删除EV根证书**: 如果存在过期或不适用的根证书,例如"VeriSign Class 3 Public Primary Certification Authority - ...

    nginx双向认证配置proxy_ssl_verify_depth详解

    也就是说,直接尝试使用中级 CA 来验证客户端是无法通过的,openssl 会自动的去找中级 CA 的签发者一层层验证上去,直到找到根。 因此,在实际使用的时候,需要注意一下两点: CA 文件中必须同时存在 中级 CA 和 根 ...

    https配置-tomcat.zip

    如果你使用的是CA签名的证书,还需要将CA的中级证书导入到Tomcat的信任库中,以便服务器能够验证客户端证书。 对于大型企业环境,可能还会涉及到负载均衡和集群,这时候你可能需要配置多个`<Connector>`,并且需要...

    Certificate-Module

    可以使用`ssl.create_default_context()`来创建一个默认的验证上下文,并通过`load_verify_locations()`加载CA证书。 4. **自签名证书**:在开发和测试环境中,我们可能会使用自签名证书。这种证书没有经过权威CA的...

Global site tag (gtag.js) - Google Analytics