#openssl实现私有CA
# 1. 先生成一对密钥
# 2. 生成自签署证书
[root@localhost ~]# cd /etc/pki/CA
[root@localhost CA]# openssl genrsa -out private/cakey.pem 2048
Generating RSA private key, 2048 bit long modulus
......................................................................................................................+++
..+++
e is 65537 (0x10001)
[root@localhost CA]# ls -l private/
total 8
-rw-r--r-- 1 root root 1675 Apr 15 19:55 cakey.pem
[root@localhost CA]# chmod 600 private/cakey.pem
[root@localhost CA]# ls -l private/
total 8
-rw------- 1 root root 1675 Apr 15 19:55 cakey.pem
[root@localhost CA]# openssl req -new -x509 -key private/cakey.pem -out cacert.pem
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) [GB]:CN
State or Province Name (full name) [Berkshire]:JS
Locality Name (eg, city) [Newbury]:NJ
Organization Name (eg, company) [My Company Ltd]:bocs
Organizational Unit Name (eg, section) []:Tech
Common Name (eg, your name or your server's hostname) []:ca.bocs.com
Email Address []:ca@bocs.com
[root@localhost CA]# openssl x509 -text -in cacert.pem
[root@localhost CA]# mkdir certs newcerts crl
[root@localhost CA]# touch index.txt
[root@localhost CA]# touch serial
[root@localhost CA]# echo 01 > serial
#假设现有一台web要签证
[root@localhost ~]# mkdir /tmp/httpd
[root@localhost ~]# cd /tmp/httpd/
[root@localhost httpd]# mkdir ssl
[root@localhost httpd]# cd ssl
#生成私钥
[root@localhost ssl]# (umask 077; openssl genrsa -out httpd.key 1024)
Generating RSA private key, 1024 bit long modulus
.................++++++
..........................................................++++++
e is 65537 (0x10001)
#生成证书申请请求
[root@localhost ssl]# openssl req -new -key httpd.key -out httpd.csr
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) [GB]:CN
State or Province Name (full name) [Berkshire]:JS
Locality Name (eg, city) [Newbury]:NJ
Organization Name (eg, company) [My Company Ltd]:bocs
Organizational Unit Name (eg, section) []:Tech
Common Name (eg, your name or your server's hostname) []:www.bocs.com
Email Address []:www@bocs.com
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:
#CA服务器签证,执行命令时,先检查下/etc/pki/tls/openss.cnf 确认:dir = /etc/pki/CA
[root@localhost ssl]# openssl ca -in httpd.csr -out httpd.crt -days 365
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: Apr 15 12:23:06 2016 GMT
Not After : Apr 15 12:23:06 2017 GMT
Subject:
countryName = CN
stateOrProvinceName = JS
organizationName = bocs
organizationalUnitName = Tech
commonName = www.bocs.com
emailAddress = www@bocs.com
X509v3 extensions:
X509v3 Basic Constraints:
CA:FALSE
Netscape Comment:
OpenSSL Generated Certificate
X509v3 Subject Key Identifier:
E9:FE:1D:40:A2:42:A5:C1:80:A2:CD:94:3F:B0:D4:AB:92:45:7D:30
X509v3 Authority Key Identifier:
keyid:B2:0B:0D:C7:11:34:EF:B7:E3:AF:F7:75:D6:82:73:12:FA:A0:55:62
Certificate is to be certified until Apr 15 12:23:06 2017 GMT (365 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 Updated
[root@localhost ssl]#
#查看是否签证成功
[root@localhost CA]# cd /etc/pki/CA
[root@localhost CA]# cat index.txt
V170415122306Z01unknown/C=CN/ST=JS/O=bocs/OU=Tech/CN=www.bocs.com/emailAddress=www@bocs.com
[root@localhost CA]# cat serial
02
[root@localhost CA]#