使用easyrsa来制做证书

1、基于easy_rsa 2.x制做证书:linux

    连接:http://www.javashuo.com/article/p-cymxddnp-go.html  最后附录部分。git

下载密钥制做工具easy_rsa 2github

         wget https://github.com/Open×××/easy-rsa/archive/release/2.x.zipweb

解压easy_rsa并拷贝到/etc/open***vim

         unzip 2.x.zipapi

         mv easy-rsa-release-2.x/ /etc/open***/服务器

编辑easy-rsavars文件,设定相关变量信息:app

         cd /etc/open***/easy-rsa-release-2.x/easy-rsa/2.0dom

         vim varside

export KEY_COUNTRY="CN"

export KEY_PROVINCE="Beijing"

export KEY_CITY="Beijing"

export KEY_ORG="APICloud"

export KEY_EMAIL="ADMIN@APICloud.COM"

export KEY_OU="***.apicloud.com"

         编辑完以后,保存退出。

将刚才编辑的vars文件,执行以下命令:

         source vars 

         ./clean-all

         ./build-ca

建立服务器的证书和密钥:

       ./build-key-server Open×××_Server

[root@cloud 2.0]# ./build-key-server Open×××_Server

Generating a 2048 bit RSA private key

.................................+++

............+++

writing new private key to 'Open×××_Server.key'

-----

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) [CN]:

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

Locality Name (eg, city) [BEIJING]:

Organization Name (eg, company) [XIAOCUI]:

Organizational Unit Name (eg, section) [MyOpen×××]:

Common Name (eg, your name or your server's hostname) [Open×××_Server]:

Name [EasyRSA]:

Email Address [ADMIN@ XIAOCUI.COM]:

 

Please enter the following 'extra' attributes

to be sent with your certificate request

A challenge password []:

An optional company name []:

Using configuration from /etc/open***/easy-rsa-release-2.x/easy-rsa/2.0/openssl-1.0.0.cnf

Check that the request matches the signature

Signature ok

The Subject's Distinguished Name is as follows

countryName           :PRINTABLE:'CN'

stateOrProvinceName   :PRINTABLE:'BEIJING'

localityName          :PRINTABLE:'BEIJING'

organizationName      :PRINTABLE:' XIAOCUI '

organizationalUnitName:PRINTABLE:'MyOpen×××'

commonName            :T61STRING:'Open×××_Server'

name                  :PRINTABLE:'EasyRSA'

emailAddress          :IA5STRING:'ADMIN@ XIAOCUI.COM'

Certificate is to be certified until May  2 07:49:13 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 Updated

 

建立客户端的证书和密钥:

       ./build-key client-user-test1

 

[root@cloud 2.0]# ./build-key client-user-test1

Generating a 2048 bit RSA private key

....................+++

...............................................................................+++

writing new private key to 'client-user-cuiyuanrong.key'

-----

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) [CN]:

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

Locality Name (eg, city) [BEIJING]:

Organization Name (eg, company) [XIAOCUI]:

Organizational Unit Name (eg, section) [MyOpen×××]:

Common Name (eg, your name or your server's hostname) [client-user-test1]:

Name [EasyRSA]:

Email Address [ADMIN@XIAOCUI.COM]:

 

Please enter the following 'extra' attributes

to be sent with your certificate request

A challenge password []:

An optional company name []:

Using configuration from /etc/open***/easy-rsa-release-2.x/easy-rsa/2.0/openssl-1.0.0.cnf

Check that the request matches the signature

Signature ok

The Subject's Distinguished Name is as follows

countryName           :PRINTABLE:'CN'

stateOrProvinceName   :PRINTABLE:'BEIJING'

localityName          :PRINTABLE:'BEIJING'

organizationName      :PRINTABLE:'XIAOCUI'

organizationalUnitName:PRINTABLE:'MyOpen×××'

commonName            :PRINTABLE:'client-user-test1'

name                  :PRINTABLE:'EasyRSA'

emailAddress          :IA5STRING:'ADMIN@XIAOCUI.COM'

Certificate is to be certified until May  2 07:53:17 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 Updated

 

建立Diffie Hellman 参数:

       ./build-dh


2、基于easy_rsa 3.x制做证书:

    连接:http://openwrt.iteye.com/blog/2305318 

最近研究如何在路由器上面实现open***的功能,其中便涉及到使用easyrsa来制做证书的问题,针对最新的open***-2.3.11源码包,easyrsa已经不包含在里面,须要单独下载,下载网址为https://github.com/Open×××/easy-rsa,下载下来是一个easy-rsa-master.zip压缩包,已上传为附件,在linux上面将其解压获得easy-rsa-master,进入easyrsa3,将vars.example复制一份命名为vars,此文件为制做证书时所使用到的配置文件,根据个人须要,我只打开了以下选项: 

set_var EASYRSA_DN  "org" 

set_var EASYRSA_REQ_COUNTRY "CN" 

set_var EASYRSA_REQ_PROVINCE    "Guangdong" 

set_var EASYRSA_REQ_CITY    "Shenzhen" 

set_var EASYRSA_REQ_ORG "XXX" 

set_var EASYRSA_REQ_EMAIL   "me@myhost.mydomain" 

/*************************************/ 

若是open*** client的配置文件中使用了ns-cert-type server则要打开此选项,制做server证书时会将一些信息写入证书,如不打开此选项,则open*** client会提示server certificate verify fail 

set_var EASYRSA_NS_SUPPORT  "yes" 

/*************************************/  

下面就能够制做证书了,每条命令执行以后都有些信息输出,如出错,会提示相关错误信息 

1 ./easyrsa init-pki 

初始化,会在当前目录建立PKI目录,用于存储一些中间变量及最终生成的证书 


2 ./easyrsa build-ca 

建立根证书,首先会提示设置密码,用于ca对以后生成的server和client证书签名时使用,而后会提示设置Country Name,State or Province Name,Locality Name,Organization Name,Organizational Unit Name,Common Name,Email Address,能够键入回车使用默认的,也能够手动更改 


3 ./easyrsa gen-req server nopass 

建立server端证书和private key,nopass表示不加密private key,而后会提示设置Country Name,State or Province Name,Locality Name,Organization Name,Organizational Unit Name,Common Name,Email Address,能够键入回车使用默认的,也能够手动更改 


4 ./easyrsa sign server server 

给server端证书作签名,首先是对一些信息的确认,能够输入yes,而后输入build-ca时设置的那个密码 


5 ./easyrsa gen-dh 

建立Diffie-Hellman,时间会有点长,耐心等待 


6 建立client端证书,须要单独把easyrsa3文件夹拷贝出来一份,删除里面的PKI目录,而后进入到此目录 

./easyrsa init-pki 

初始化,会在当前目录建立PKI目录,用于存储一些中间变量及最终生成的证书 


7 ./easyrsa gen-req client nopass 

建立client端证书和private key,nopass表示不加密private key,而后会提示设置Country Name,State or Province Name,Locality Name,Organization Name,Organizational Unit Name,Common Name,Email Address,能够键入回车使用默认的,也能够手动更改 


8 回到制做server证书时的那个easyrsa3目录,导入client端证书,准备签名 

./easyrsa import-req client.req所在路径 client 

client.req应该在刚才制做client端证书的easyrsa3/pki/reqs/下面 


9 ./easyrsa sign client client 

给client端证书作签名,首先是对一些信息的确认,能够输入yes,而后输入build-ca时设置的那个密码 


注意:ca、server和client的Common Name最好不要设置为同样,我没有验证,不过网上有人说设置同样后,open***链接时会有问题 


至此,server和client端证书已制做完毕 

open*** server端须要的是 

easyrsa3/pki/ca.crt   <制做server证书的文件夹> 

easyrsa3/pki/private/server.key <制做server证书的文件夹> 

easyrsa3/pki/issued/server.crt <制做server证书的文件夹> 

easyrsa3/pki/dh.pem 


open*** client端须要的是 

easy-rsa/easyrsa3/pki/ca.crt <制做server证书的文件夹> 

easy-rsa/easyrsa3/pki/issued/client.crt <制做server证书的文件夹> 

easy-rsa/easyrsa3/pki/private/client.key <制做client证书的文件夹>

相关文章
相关标签/搜索