dir = /etc/pki/CA # Where everything is kept
certs = $dir/certs # Where the issued certs are kept
crl_dir = $dir/crl # Where the issued crl are kept
database = $dir/index.txt # database index file.
#unique_subject = no # Set to 'no' to allow creation of
# several ctificates with same subject.
new_certs_dir = $dir/newcerts # default place for new certs.
certificate = $dir/cacert.pem # The CA certificate
serial = $dir/serial # The current serial number
crlnumber = $dir/crlnumber # the current crl number
# must be commented out to leave a V1 CRL
crl = $dir/crl.pem # The current CRL
private_key = $dir/private/cakey.pem# The private key
RANDFILE = $dir/private/.rand # private random number file
x509_extensions = usr_cert # The extentions to add to the cert
2.生成密钥对
[iyunv@localhost private]# (umask 077 ;openssl genrsa -out /etc/pki/CA/private/cakey.pem 2048)
Generating RSA private key, 2048 bit long modulus
......................................................+++
...........................+++
e is 65537 (0x10001)
[iyunv@localhost private]# ls -l
total 4
-rw------- 1 root root 1675 Sep 28 06:59 cakey.pem
3.生成自签证书
[iyunv@localhost CA]# openssl req -new -x509 -key private/cakey.pem -out cacert.pem -days 3650
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [XX]:CN
State or Province Name (full name) []:beijing
Locality Name (eg, city) [Default City]:beijing
Organization Name (eg, company) [Default Company Ltd]:magedu
Organizational Unit Name (eg, section) []:linux operation
Common Name (eg, your name or your server's hostname) []:ca.magedu.com
Email Address []:caadmin@magedu.com
[iyunv@localhost CA]# ls
cacert.pem certs crl newcerts private
[iyunv@localhost CA]# touch index.txt serial crlnumber
[iyunv@localhost CA]# echo 01 > serial
4.openssl实现证书申请
(1)在主机上生成密钥,保存至应用此证书的服务的配置文件目录下, 例如:
[iyunv@www httpd]# mkdir ssl
[iyunv@www httpd]# cd ssl/
[iyunv@www ssl]# (umask 077;openssl genrsa 1024 > http.key)
Generating RSA private key, 1024 bit long modulus
..++++++
...................................................................++++++
e is 65537 (0x10001)
(2)生成证书签署请求
[iyunv@www ssl]# openssl req -new -key http.key -out http.csrYou are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [XX]:CN
State or Province Name (full name) []:beijing
Locality Name (eg, city) [Default City]:beijing
Organization Name (eg, company) [Default Company Ltd]:magedu
Organizational Unit Name (eg, section) []:linux operation
Common Name (eg, your name or your server's hostname) []:www.magedu.com
Email Address []:webmaster@magedu.com
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:
(3)将请求文件发给CA
[iyunv@www ssl]# scp http.csr 192.168.1.103:/tmp/
The authenticity of host '192.168.1.103 (192.168.1.103)' can't be established.
RSA key fingerprint is 9b:a1:30:76:04:5c:e8:d4:72:01:b1:0a:7d:6a:03:77.
Are you sure you want to continue connecting (yes/no)? y
Please type 'yes' or 'no': ^C[iyunv@www ssl]# scp http.csr 192.168.1.103:/tmp/^C
[iyunv@www ssl]# scp http.csr 192.168.1.103:/tmp/
The authenticity of host '192.168.1.103 (192.168.1.103)' can't be established.
RSA key fingerprint is 9b:a1:30:76:04:5c:e8:d4:72:01:b1:0a:7d:6a:03:77.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.1.103' (RSA) to the list of known hosts.
Address 192.168.1.103 maps to localhost, but this does not map back to the address - POSSIBLE BREAK-IN ATTEMPT! root@192.168.1.103's password:
http.csr 100% 720 0.7KB/s 00:00
5.CA签署证书
(1)CA签署
[iyunv@localhost ~]# openssl ca -in /tmp/http.csr -out /tmp/http.crt -days 3650
Using configuration from /etc/pki/tls/openssl.cnf
Check that the request matches the signature
Signature ok
Certificate Details:
Serial Number: 1 (0x1)
Validity
Not Before: Sep 27 23:52:58 2015 GMT
Not After : Sep 24 23:52:58 2025 GMT
Subject:
countryName = CN
stateOrProvinceName = beijing
organizationName = magedu
organizationalUnitName = linux operation
commonName = www.magedu.com
emailAddress = webmaster@magedu.com
X509v3 extensions:
X509v3 Basic Constraints:
CA:FALSE
Netscape Comment:
OpenSSL Generated Certificate
X509v3 Subject Key Identifier:
25:C3:E7:05:48:D7:7F:6C:53:3F:E4:7C:70:ED:2F:B4:8C:BF:8E:73
X509v3 Authority Key Identifier:
keyid:82:EA:8D:E8:CC:6C:1D:02:A3:A6:EE:1C:D2:51:78:A6:FE:D7:89:11
Certificate is to be certified until Sep 24 23:52:58 2025 GMT (3650 days)
Sign the certificate? [y/n]:y
1 out of 1 certificate requests certified, commit? [y/n]y
Write out database with 1 new entries
Data Base Update
(2)将证书传回请求者
[iyunv@localhost CA]# scp /tmp/http.crt 192.168.1.100:/etc/httpd/ssl/
The authenticity of host '192.168.1.100 (192.168.1.100)' can't be established.
RSA key fingerprint is 03:9c:f7:7e:1e:30:4d:38:97:f6:69:bc:52:bc:3e:e8.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.1.100' (RSA) to the list of known hosts.
Address 192.168.1.100 maps to localhost, but this does not map back to the address - POSSIBLE BREAK-IN ATTEMPT! root@192.168.1.100's password:
http.crt 100% 3927 3.8KB/s 00:00
6.CA吊销证书
[iyunv@localhost tmp]# openssl ca -revoke http.crt
Using configuration from /etc/pki/tls/openssl.cnf
Revoking Certificate 01.
Data Base Updated