CA创建

创建私有CA: openssl的配置文件:/etc/pki/tls/openssl.cnf ,该文件规定了CA证书夫人存放目录,工作目录,证书编号、策略信息等,搭建CA需要以此 配置文件作为参看。

配置文件中需要注意的参数:

                         [ policy_match ]

                        countryName         = match   # 国家名是否匹配,match为匹配

                        stateOrProvinceName = match  # 州或省名是否需要匹配

                        organizationName    = match  # 组织名是否需要匹配

                        organizationalUnitName  = optional # 组织的部门名字是否需要匹配

                        commonName          = supplied # 注释

                        emailAddress        = optional # 邮箱地址


                        dir             = /etc/pki/CA           # Where everything is kept (dir变量)

                        certs           = $dir/certs            # Where the issued certs are kept(认证证书目录)

                        database        = $dir/index.txt        # database index file.(数据库索引文件)

                        new_certs_dir   = $dir/newcerts         # default place for new certs.(新证书的默认位置)c

                        ertificate     = $dir/cacert.pem       # The CA certificate(CA机构证书)

                        serial          = $dir/serial           # The current serial number(当前序号,默认为空,可以指定从01开始)

                        private_key     = $dir/private/cakey.pem# The private key(CA机构的私钥)


三种策略:匹配、支持和可选 匹配指要求申请填写的信息跟CA设置信息必须一致,支持指必须填写这 项申请信息,可选指可有可无 

CA自签证书 生成私钥 cd /etc/pki/CA/ (umask 066; openssl genrsa -out /etc/pki/CA/private/cakey.pem 2048)

生成自签名证书 openssl req -new -x509 –key 

                /etc/pki/CA/private/cakey.pem -days  7300  -out    

                /etc/pki/CA/cacert.pem

                -new: 生成新证书签署请求

                 -x509: 专用于CA生成自签证书 (根证书)

                -key: 生成请求时用到的私钥文件

                 -days n:证书的有效期限 

                -out /PATH/TO/SOMECERTFILE: 证书的保存路径

实验:建立CA,并使用另一个主机申请证书,用CA签名


根CA

1、touch /etc/pki/CA/index.text     生成证书索引数据库文件

2、echo 00 > serial 指定第一个颁发的序列号

3、创建私钥(umask 066;openssl genrsa -out private/cakey.pem -des3 2048)

genrsa代表RSA算法,CA的私钥存放目录是配置文件中规定的(private目录),2048代表指定私钥位数。

image.png

4、生成自签名颁发证书:openssl req -new -x509 -key private/cakey.pem -out cacert.pem -days 7300

[root@localhost CA]#openssl req -new -x509 -key private/cakey.pem -out cacert.pem -days 7300

Enter pass phrase for private/cakey.pem:

You are about to be asked to enter information that will be incorporated

。。。。。。。。。。。。。。。。。。。。。。。。。。。。

-----

Country Name (2 letter code) [XX]:CN

State or Province Name (full name) []:HENAN  

Locality Name (eg, city) [Default City]:ZhengZhou  

Organization Name (eg, company) [Default Company Ltd]:shushu.com

Organizational Unit Name (eg, section) []:opt

Common Name (eg, your name or your server's hostname) []:ca.shushu.com

Email Address []:

注意:默认国家,省,公司名称三项必须和CA一致 根CA与子CA的Common Name一定要不一样。

以上就是自制CA证书的主要步骤,创建成功后从虚拟系统sz丢到实体机中安装进行测试。

image.png

安装到证书的存储时选择‘将所有的证书都放入下列存储’浏览选中‘受信任的根证书颁发机构’下一步完成。在浏览器设置‘高级选项卡选’

image.png

5、查看证书中的信息

openssl x509 -in /PATH/FROM/CERT_FILE -noout -text|issuer|subject|serial|dates

                   text代表全部信息,issuer代表颁发者,subject代表主题,dates代表有效期

image.png

openssl ca -status SERIAL 查看指定编号的证书状态 

6、创建搭建子CA,与创建根CA基本相同

  (1)在/etc/pki/CA下创建数据库索引文件

image.png

  (2)指定第一个颁发证书的序列号

image.png

(3)给web服务器生成私钥

image.png

(4)生成证书请求

[root@centos CA]#openssl req -new -key private/cakey.pem -out subca.csr

Enter pass phrase for private/cakey.pem:

140185183258440:error:28069065:lib(40):UI_set_result:result too small:ui_lib.c:869:You must type in 4 to 8191 characters

...........................................................

If you enter '.', the field will be left blank.

-----

Country Name (2 letter code) [XX]:CN

State or Province Name (full name) []:HENAN  

Locality Name (eg, city) [Default City]:LuoHe  

Organization Name (eg, company) [Default Company Ltd]:shushu.com

Organizational Unit Name (eg, section) []:Rou

Common Name (eg, your name or your server's hostname) []:app.shushu.com

Email Address []:


Please enter the following 'extra' attributes

to be sent with your certificate request

A challenge password []:centos

An optional company name []:centos

注意:根据默认策略,所填写的国家,省,公司必须与根CA一致

(5)将子CA中生成的公钥发送给根CA:scp subca.csr [email protected]:/etc/pki/CA

image.png

7、颁发证书,在根CA中进行操作,根CA进行签名。

[root@localhost CA]#openssl ca -in subca.csr -out certs/subca.crt -days 3650

Using configuration from /etc/pki/tls/openssl.cnf

...............................

        Subject:

            countryName                   = CN

            stateOrProvinceName      = HENAN

            organizationName            = shushu.com

            organizationalUnitName    = opt

            commonName                 = ca.shu.com

     

Certificate is to be certified until Aug 29 02:56:28 2028 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 Updated

操作完成后可以查子CA的数据库索引,序列号等信息,子CA是否创建成功

X1`J%9PFX9403]A_(@20}QR.png

8、最后再把生成的证书文件发送给请求者子CA。最后安装证书与上述安装根证书的步骤类似。





猜你喜欢

转载自blog.51cto.com/13869577/2168364
CA
今日推荐