本文主要说说 openvpn 提供的 easy-rsa 这套RSA证书管理工具如何来用
openvpn的下载:
下载页面 http://openvpn.net/release/,提供有 Linux版和Windows版
具体的使用方法可参考下面几篇文章:
官方的使用说明 http://openvpn.net/index.php/open-source/documentation/miscellaneous/77-rsa-key-management.html
OpenVPN 2.0 HOWTO-安全证书篇 http://blog.5ilinux.com/archives/2006/08/openvpn_20_howt_1.html
下面就以archlinux openvpn 2.1.1为例说说一些简单的操作
#安装openvpn
[root@vkill'host ~]# pacman -S openvpn
#查看openvpn easy-rsa 工具包的位置
[root@vkill'host ~]# pacman -Ql openvpn
openvpn /usr/share/openvpn/easy-rsa/
[root@vkill'host ~]# cd /usr/share/openvpn/easy-rsa/
#修改vars文件中的下面那几个变量,这些都会显示到证书里面的,建议还是修改下
[root@vkill'host easy-rsa]# vi vars
export KEY_COUNTRY="CN"
export KEY_PROVINCE="Gansu"
export KEY_CITY="Linze"
export KEY_ORG="vkill.net"
export KEY_EMAIL="vkill.net@gmail.com"
#初始化变量
[root@vkill'host easy-rsa]# . vars
#清空keys目录
[root@vkill'host easy-rsa]# ./clean-all
#制作CA证书
[root@vkill'host easy-rsa]# ./build-ca
//一路默认
//最后会在keys目录下生成 ca.crt(根证书文件) 和 ca.key(根证书私钥文件)
#制作服务器端证书
[root@vkill'host easy-rsa]# ./build-key-server server
//一路默认
//最后会在keys目录下生成 server.crt(证书文件) 和 server.key(私钥文件)、server.csr(证书请求文件)
#制作客户端证书
[root@vkill'host easy-rsa]# ./build-key client1
//一路默认
//最后会在keys目录下生成 server.crt(证书文件) 和 server.key(私钥文件)、server.csr(证书请求文件)
#注销客户端证书
[root@vkill'host easy-rsa]# ./revoke-full client1
//2.0.9版本下的 revoke-full 有问题,建议使用2.1.1版本下的 revoke-full
//如果提示下列错误
// Using configuration from /usr/share/openvpn/easy-rsa/openssl.cnf
// error on line 288 of config file '/usr/share/openvpn/easy-rsa/openssl.cnf'
// 2471:error:0E065068:configuration file routines:STR_COPY:variable has no value:conf_def.c:629:line 288
// Using configuration from /usr/share/openvpn/easy-rsa/openssl.cnf
// error on line 288 of config file '/usr/share/openvpn/easy-rsa/openssl.cnf'
// 2472:error:0E065068:configuration file routines:STR_COPY:variable has no value:conf_def.c:629:line 288
// cat: crl.pem: No such file or directory
// client1.crt: /C=CN/ST=Gansu/L=Linze/O=vkill.net/CN=client1/emailAddress=vkill.net@gmail.com
// error 3 at 0 depth lookup:unable to get certificate CRL
//那就打开openssl.cnf文件,注释掉下面这几行
// 285 #[ pkcs11_section ]
// 286 #engine_id = pkcs11
// 287 #dynamic_path = /usr/lib/engines/engine_pkcs11.so
// 288 #MODULE_PATH = $ENV::PKCS11_MODULE_PATH
// 289 #PIN = $ENV::PKCS11_PIN
// 290 #init = 0
//再执行注销证书命令,看到下面这提示就证明已经注销了
// Using configuration from /usr/share/openvpn/easy-rsa/openssl.cnf
// Revoking Certificate 02.
// Data Base Updated
// Using configuration from /usr/share/openvpn/easy-rsa/openssl.cnf
// client1.crt: /C=CN/ST=Gansu/L=Linze/O=vkill.net/CN=client1/emailAddress=vkill.net@gmail.com
// error 23 at 0 depth lookup:certificate revoked
//解决这个错误的详细方法参见这篇文章 http://hi.baidu.com/chenshake/blog/item/98e78a0a41457c1695ca6b8c.html
//最后会在keys目录下生成 crl.pem,这个文件里面包含了吊销证书的名单
//成功注销某个证书之后,可以打开 keys/index.txt 文件,可以看到被注销的证书前面,已标记为R
#创建Diffie Hellman参数,openvpn是必须要dh参数的,不过我在nginx上这个可有可无
[root@vkill'host easy-rsa]# ./build-dh
好了,这样制作出来的证书就基本上可以用了
一般像openvpn、nginx这些服务器端需要 ca.crt server.crt server.key dh1024.pem 这四个文件,客户端需要 client1.crt client1.key
还有最关键的一点就是,以后要生成新客户端证书的话,每次都要先执行下 . vars 命令
后记:
#制作受保护的客户端密钥,这样制作出来的证书才可以转为 p12格式的证书,供IE、firefox使用
[root@vkill'host easy-rsa]# ./build-key-pass client8
Generating a 1024 bit RSA private key
.................................++++++
...............++++++
writing new private key to 'client8.key'
Enter PEM pass phrase:
Verifying - Enter PEM pass phrase:
//这里输入两遍证书的保护密码,假设输入aabbcc,后一路默认
#转换证书为 p12 格式,供IE、firefox使用,执行完后将在keys目录下生成 client8.p12 文件
[root@vkill'host easy-rsa]# openssl pkcs12 -export -clcerts -in keys/client8.crt -inkey keys/client8.key -out keys/client8.p12
Enter pass phrase for keys/client8.key:
//先输入刚刚设置的密码 aabbcc
Enter Export Password:
Verifying - Enter Export Password:
//再输入两遍导出密码,假设输入1234567,那么我们在IE上导入证书的时候就得输入密码1234567
Last modified by vkill on2010/04/30 00:23
openvpn的下载:
下载页面 http://openvpn.net/release/,提供有 Linux版和Windows版
具体的使用方法可参考下面几篇文章:
官方的使用说明 http://openvpn.net/index.php/open-source/documentation/miscellaneous/77-rsa-key-management.html
OpenVPN 2.0 HOWTO-安全证书篇 http://blog.5ilinux.com/archives/2006/08/openvpn_20_howt_1.html
下面就以archlinux openvpn 2.1.1为例说说一些简单的操作
#安装openvpn
[root@vkill'host ~]# pacman -S openvpn
#查看openvpn easy-rsa 工具包的位置
[root@vkill'host ~]# pacman -Ql openvpn
openvpn /usr/share/openvpn/easy-rsa/
[root@vkill'host ~]# cd /usr/share/openvpn/easy-rsa/
#修改vars文件中的下面那几个变量,这些都会显示到证书里面的,建议还是修改下
[root@vkill'host easy-rsa]# vi vars
export KEY_COUNTRY="CN"
export KEY_PROVINCE="Gansu"
export KEY_CITY="Linze"
export KEY_ORG="vkill.net"
export KEY_EMAIL="vkill.net@gmail.com"
#初始化变量
[root@vkill'host easy-rsa]# . vars
#清空keys目录
[root@vkill'host easy-rsa]# ./clean-all
#制作CA证书
[root@vkill'host easy-rsa]# ./build-ca
//一路默认
//最后会在keys目录下生成 ca.crt(根证书文件) 和 ca.key(根证书私钥文件)
#制作服务器端证书
[root@vkill'host easy-rsa]# ./build-key-server server
//一路默认
//最后会在keys目录下生成 server.crt(证书文件) 和 server.key(私钥文件)、server.csr(证书请求文件)
#制作客户端证书
[root@vkill'host easy-rsa]# ./build-key client1
//一路默认
//最后会在keys目录下生成 server.crt(证书文件) 和 server.key(私钥文件)、server.csr(证书请求文件)
#注销客户端证书
[root@vkill'host easy-rsa]# ./revoke-full client1
//2.0.9版本下的 revoke-full 有问题,建议使用2.1.1版本下的 revoke-full
//如果提示下列错误
// Using configuration from /usr/share/openvpn/easy-rsa/openssl.cnf
// error on line 288 of config file '/usr/share/openvpn/easy-rsa/openssl.cnf'
// 2471:error:0E065068:configuration file routines:STR_COPY:variable has no value:conf_def.c:629:line 288
// Using configuration from /usr/share/openvpn/easy-rsa/openssl.cnf
// error on line 288 of config file '/usr/share/openvpn/easy-rsa/openssl.cnf'
// 2472:error:0E065068:configuration file routines:STR_COPY:variable has no value:conf_def.c:629:line 288
// cat: crl.pem: No such file or directory
// client1.crt: /C=CN/ST=Gansu/L=Linze/O=vkill.net/CN=client1/emailAddress=vkill.net@gmail.com
// error 3 at 0 depth lookup:unable to get certificate CRL
//那就打开openssl.cnf文件,注释掉下面这几行
// 285 #[ pkcs11_section ]
// 286 #engine_id = pkcs11
// 287 #dynamic_path = /usr/lib/engines/engine_pkcs11.so
// 288 #MODULE_PATH = $ENV::PKCS11_MODULE_PATH
// 289 #PIN = $ENV::PKCS11_PIN
// 290 #init = 0
//再执行注销证书命令,看到下面这提示就证明已经注销了
// Using configuration from /usr/share/openvpn/easy-rsa/openssl.cnf
// Revoking Certificate 02.
// Data Base Updated
// Using configuration from /usr/share/openvpn/easy-rsa/openssl.cnf
// client1.crt: /C=CN/ST=Gansu/L=Linze/O=vkill.net/CN=client1/emailAddress=vkill.net@gmail.com
// error 23 at 0 depth lookup:certificate revoked
//解决这个错误的详细方法参见这篇文章 http://hi.baidu.com/chenshake/blog/item/98e78a0a41457c1695ca6b8c.html
//最后会在keys目录下生成 crl.pem,这个文件里面包含了吊销证书的名单
//成功注销某个证书之后,可以打开 keys/index.txt 文件,可以看到被注销的证书前面,已标记为R
#创建Diffie Hellman参数,openvpn是必须要dh参数的,不过我在nginx上这个可有可无
[root@vkill'host easy-rsa]# ./build-dh
好了,这样制作出来的证书就基本上可以用了
一般像openvpn、nginx这些服务器端需要 ca.crt server.crt server.key dh1024.pem 这四个文件,客户端需要 client1.crt client1.key
还有最关键的一点就是,以后要生成新客户端证书的话,每次都要先执行下 . vars 命令
后记:
#制作受保护的客户端密钥,这样制作出来的证书才可以转为 p12格式的证书,供IE、firefox使用
[root@vkill'host easy-rsa]# ./build-key-pass client8
Generating a 1024 bit RSA private key
.................................++++++
...............++++++
writing new private key to 'client8.key'
Enter PEM pass phrase:
Verifying - Enter PEM pass phrase:
//这里输入两遍证书的保护密码,假设输入aabbcc,后一路默认
#转换证书为 p12 格式,供IE、firefox使用,执行完后将在keys目录下生成 client8.p12 文件
[root@vkill'host easy-rsa]# openssl pkcs12 -export -clcerts -in keys/client8.crt -inkey keys/client8.key -out keys/client8.p12
Enter pass phrase for keys/client8.key:
//先输入刚刚设置的密码 aabbcc
Enter Export Password:
Verifying - Enter Export Password:
//再输入两遍导出密码,假设输入1234567,那么我们在IE上导入证书的时候就得输入密码1234567
Last modified by vkill on2010/04/30 00:23
网友评论(0):


