公司如果有一些其他需求,比如员工离职或者其他需求,可能需要对原来签发的客户端证书进行吊销,以免出现信息泄露等安全问题。
如果config目录下有多个客户端配置,在OpenVPN GUI客户端右键就会有多个用户配置,可以根据需要使用任一客户端证书连接VPN Server。
这是OpenVPN GUI for Windows客户端安装目录下的config目录中的客户端配置文件,每个文件都以用户名作为名字,以便区分。下面以jack为例,显示如何对jack用户的客户端证书进行吊销。
[[email protected] 2.0]# source vars NOTE: If you run ./clean-all, I will be doing a rm -rf on /opt/tools/openvpn-2.0.9/easy-rsa/2.0/keys [[email protected] 2.0]# ./revoke-full jack Using configuration from /opt/tools/openvpn-2.0.9/easy-rsa/2.0/openssl.cnf error on line 282 of config file ‘/opt/tools/openvpn-2.0.9/easy-rsa/2.0/openssl.cnf‘ 140124214830920:error:0E065068:configuration file routines:STR_COPY:variable has no value:conf_def.c:618:line 282 Using configuration from /opt/tools/openvpn-2.0.9/easy-rsa/2.0/openssl.cnf error on line 282 of config file ‘/opt/tools/openvpn-2.0.9/easy-rsa/2.0/openssl.cnf‘ 140213574821704:error:0E065068:configuration file routines:STR_COPY:variable has no value:conf_def.c:618:line 282 cat: crl.pem: No such file or directory jack.crt: C = CN, ST = GD, L = Shenzhen, O = contoso.com, OU = HR, CN = jack, emailAddress = [email protected] error 3 at 0 depth lookup:unable to get certificate CRL
执行上面的命令,结果报错,对于该错误,解决的方法是:
[[email protected] 2.0]# tail -8 openssl.cnf [ pkcs11_section ] #engine_id = pkcs11 #dynamic_path = /usr/lib/engines/engine_pkcs11.so #MODULE_PATH = $ENV::PKCS11_MODULE_PATH #PIN = $ENV::PKCS11_PIN #init = 0
将/easy-rsa/2.0/目录下openssl.cnf中的最后几行注释掉,如下图:
再次执行吊销命令
[[email protected] 2.0]# source vars NOTE: If you run ./clean-all, I will be doing a rm -rf on /opt/tools/openvpn-2.0.9/easy-rsa/2.0/keys [[email protected] 2.0]# ./revoke-full jack Using configuration from /opt/tools/openvpn-2.0.9/easy-rsa/2.0/openssl.cnf Revoking Certificate 04. Data Base Updated Using configuration from /opt/tools/openvpn-2.0.9/easy-rsa/2.0/openssl.cnf jack.crt: C = CN, ST = GD, L = Shenzhen, O = contoso.com, OU = HR, CN = jack, emailAddress = [email protected] error 23 at 0 depth lookup:certificate revoked
这时,虽然结果中有error 23字样,但是这却是表明注销已经成功了。需要注意的是,一定要保证OpenVPN的服务端是运行状态,不能在服务关闭的情况下执行该命令,不然是无法成功的。此时,命令虽然成功,但是还是可以使用jack的证书进行登录。这是因为上面的操作在keys目录下生成了crl.pem,里面就是注销掉的证书,也就是说证书此时并没有完全注销掉。
[[email protected] 2.0]# ll keys/crl.pem -rw-r--r-- 1 root root 544 Sep 4 21:59 keys/crl.pem [[email protected] 2.0]# cat keys/crl.pem -----BEGIN X509 CRL----- MIIBaTCB0zANBgkqhkiG9w0BAQQFADCBjTELMAkGA1UEBhMCQ04xCzAJBgNVBAgT AkdEMREwDwYDVQQHEwhTaGVuemhlbjEUMBIGA1UEChMLY29udG9zby5jb20xDTAL BgNVBAsTBFRlY2gxFzAVBgNVBAMTDmNvbnRvc28uY29tIENBMSAwHgYJKoZIhvcN AQkBFhFhZG1pbkBjb250b3NvLmNvbRcNMTYwOTA0MTM1OTAzWhcNMTYxMDA0MTM1 OTAzWjAUMBICAQQXDTE2MDkwNDEzNTkwM1owDQYJKoZIhvcNAQEEBQADgYEAsclj rF/BIoYR/U4G4K6I3ee1Mq3M9jL1zsPWta+NANURzdBt+2ELv/12SO2XITXKw5hS CM+A16KU+h+eF6LN2s1e9GIKZAdjGZpUszH3v0Wrb6zwAVIROYzUI2Ka+yFNU3C4 i8GSyKEoJoRWUMMk3yDL3ZXK5UnsOpPq2FachpY= -----END X509 CRL----- [[email protected] keys]# cat index.txt V260901065439Z01unknown/C=CN/ST=GD/L=Shenzhen/O=contoso.com/OU=Tech/CN=server/[email protected] V260901070330Z02unknown/C=CN/ST=GD/L=Shenzhen/O=contoso.com/OU=Tech/CN=tom/[email protected] V260901070740Z03unknown/C=CN/ST=GD/L=Shenzhen/O=contoso.com/OU=Tech/CN=jerry/[email protected] R260902094321Z160904135903Z04unknown/C=CN/ST=GD/L=Shenzhen/O=contoso.com/OU=HR/CN=jack/[email protected] # 其中R的意思就是吊销的状态 [[email protected] keys]# cat serial.old 04 # 已经颁发的最后一个证书编号 [[email protected] keys]# cat serial 05 # 下一个颁发的证书编号
好吧,为了能彻底吊销证书,需要添加如下操作:
[[email protected] keys]# echo "crl-verify /opt/tools/openvpn-2.0.9/easy-rsa/2.0/keys/crl.pem" >>/etc/server.conf [[email protected] keys]# tail -1 /etc/server.conf crl-verify /opt/tools/openvpn-2.0.9/easy-rsa/2.0/keys/crl.pem [[email protected] keys]# ps -ef|grep openvpn root 1002 984 0 21:49 pts/0 00:00:00 /usr/local/sbin/openvpn --config /etc/server.conf root 1100 1012 0 22:23 pts/1 00:00:00 grep openvpn [[email protected] keys]# kill -9 1002 [[email protected] keys]# ps -ef|grep openvpn root 1105 1012 0 22:23 pts/1 00:00:00 grep openvpn [[email protected] keys]# /usr/local/sbin/openvpn --config /etc/server.conf &
OpenVPN服务器端重启以后,jack已经无法连接上vpn了,证明吊销操作成功。
下面测试一下批量证书吊销,网上有人说可以在/etc/server.conf中添加多行,比如
crl-verify /opt/tools/openvpn-2.0.9/easy-rsa/2.0/keys/jack.pem
crl-verify /opt/tools/openvpn-2.0.9/easy-rsa/2.0/keys/jerry.pem
crl-verify /opt/tools/openvpn-2.0.9/easy-rsa/2.0/keys/charles.pem
....
所以,下面继续吊销另一个用户jerry,然后测试。
[[email protected] 2.0]# ./revoke-full jerry Using configuration from /opt/tools/openvpn-2.0.9/easy-rsa/2.0/openssl.cnf Revoking Certificate 03. Data Base Updated Using configuration from /opt/tools/openvpn-2.0.9/easy-rsa/2.0/openssl.cnf jerry.crt: C = CN, ST = GD, L = Shenzhen, O = contoso.com, OU = Tech, CN = jerry, emailAddress = [email protected] error 23 at 0 depth lookup:certificate revoked [[email protected] 2.0]# ll keys/crl.pem -rw-r--r-- 1 root root 573 Sep 4 22:29 keys/crl.pem [[email protected] 2.0]# cat keys/crl.pem -----BEGIN X509 CRL----- MIIBfTCB5zANBgkqhkiG9w0BAQQFADCBjTELMAkGA1UEBhMCQ04xCzAJBgNVBAgT AkdEMREwDwYDVQQHEwhTaGVuemhlbjEUMBIGA1UEChMLY29udG9zby5jb20xDTAL BgNVBAsTBFRlY2gxFzAVBgNVBAMTDmNvbnRvc28uY29tIENBMSAwHgYJKoZIhvcN AQkBFhFhZG1pbkBjb250b3NvLmNvbRcNMTYwOTA0MTQyOTQ3WhcNMTYxMDA0MTQy OTQ3WjAoMBICAQMXDTE2MDkwNDE0Mjk0N1owEgIBBBcNMTYwOTA0MTM1OTAzWjAN BgkqhkiG9w0BAQQFAAOBgQCC6eOVkGmVDCSjX+UsZJJB+rzVWE4mj5JWo3Mm4o0M lXUORVCl7lFqbQblW2Sq2po76Owzs6OK//WSnifA0FS18vD1H4/1w2cdsHZpGgS3 pqrjDG6ueywc5wQuR+AzbTJufIlKlEAJmaFPdTPjz+LD9bmCek7++sqM+VBgppae rQ== -----END X509 CRL-----
原有的crl.pem文件已经备份成crl.pem.bak,里面是jack的注销证书,因为在/etc/server.conf中的配置刚好是该生成文件的位置,所以无需重启OpenVPN,吊销即可生效。
可以看到,jerry已经无法连接了,我并没有重启OpenVPN服务,但是吊销就已生效,因为之前的配置刚好是新生成的文件位置,但如果你在/etc/server.conf中添加的是crl-verify /etc/openvpn/crl.pem那么你可能需要重新启动OpenVPN才能使吊销生效,我建议不要把配置写到/etc/openvpn.crl.pem,因为一个用户的吊销就重启OpenVPN服务,我觉得这个在生产中不可取,还是建议配置到安装目录为好,批量吊销也无须重启服务。
再使用jack进行拨号,虽然新生成的crl.pem已经覆盖了原有的crl.pem文件(当然我有备份),但是发现此时jack也无法连接,所以说明之前吊销的不会因为吊销新用户生成新的crl.pem而失效,因此,结论是批量吊销无须写多个crl.pem文件,只需要执行吊销操作即可。
[[email protected] 2.0]# cat keys/index.txt V260901065439Z01unknown/C=CN/ST=GD/L=Shenzhen/O=contoso.com/OU=Tech/CN=server/[email protected] V260901070330Z02unknown/C=CN/ST=GD/L=Shenzhen/O=contoso.com/OU=Tech/CN=tom/[email protected] R260901070740Z160904142947Z03unknown/C=CN/ST=GD/L=Shenzhen/O=contoso.com/OU=Tech/CN=jerry/[email protected] R260902094321Z160904135903Z04unknown/C=CN/ST=GD/L=Shenzhen/O=contoso.com/OU=HR/CN=jack/[email protected]
再说一下用户密码的修改,之前创建用户key的时候,可以选择生成带密码的key和不带密码的key,但是如果用户想要修改密码,该怎么做呢?
当然,如果是不带密码的key也可以通过上面的方法进行密码的设置,以tom为例说明:
关于证书的有效期限,我们在创建证书的时候发现,默认情况下创建的证书有效期是10年,这个时间无疑太长了,所以如果需要我们最好缩短该有效期,设置有效期的可以通过修改build-key文件实现,这是一个shell脚本,我们可以查看一下里面的内容:
#!/bin/sh # # Make a certificate/private key pair using a locally generated # root certificate. # if test $# -ne 1; then echo "usage: build-key <name>"; exit 1 fi if test $KEY_DIR; then cd $KEY_DIR && openssl req -days 3650 -nodes -new -keyout $1.key -out $1.csr -config $KEY_CONFIG && openssl ca -days 3650 -out $1.crt -in $1.csr -config $KEY_CONFIG && chmod 0600 $1.key else echo you must define KEY_DIR fi
所以只需要把其中的3650修改为你需要设置的时间即可,注意默认单位是天。
最后,补充一下OpenVPN的安全问题,如果环境允许,最好把OpenVPN服务器和要共享资源的服务器放到DMZ区域,跟办公网络隔离开,这样万一被黑客攻破,也可以使损失降低到最小。
=================补上安装openvpn的shell脚本==================
#!/bin/bash ############################################ #This script is used to install openvpn. #created by Jerry12356 on Sep 4th, 2016 ############################################ LzoVersion=2.03 VpnVersion=2.0.9 yum -y install openssl openssl-devel gcc >/dev/null 2>&1 rpm -qa openssl openssl-devel gcc >/dev/null 2>&1 [ $? -ne 0 ] && echo "Please install openssl,openssl-devel and gcc first." && exit 1 [ ! -d /opt/tools ] && mkdir -p /opt/tools cd /opt/tools # Download packages wget http://www.oberhumer.com/opensource/lzo/download/lzo-${LzoVersion}.tar.gz >/dev/null 2>&1 [ $? -ne 0 ] && echo "Download package lzo failed." && exit 1 ||echo "Download package lzo successful." wget https://openvpn.net/release/openvpn-${VpnVersion}.tar.gz --no-check-certificate >/dev/null 2>&1 [ $? -ne 0 ] && echo "Download package openvpn failed." && exit 1 ||echo "Download package openvpn successful." # install lzo [ ! -d /usr/local/lzo ] && mkdir -p /usr/local/lzo tar -zxf lzo-${LzoVersion}.tar.gz cd lzo-${LzoVersion} ./configure --prefix=/usr/local/lzo/ >/dev/null [ $? -ne 0 ] && echo "config lzo error, please fix it and try again." && exit 1 make && make install >/dev/null 1>/tmp/lzo.log [ $? -ne 0 ] && echo "make install error, please fix it and try again." && exit 1||echo "Lzo installed successful." # install openvpn cd /opt/tools tar -zxf openvpn-${VpnVersion}.tar.gz cd openvpn-${VpnVersion} ./configure --with-lzo-headers=/usr/local/lzo/include --with-lzo-lib=/usr/local/lzo/lib >/dev/null [ $? -ne 0 ] && echo "config openvpn error,please fix it and try again." && exit1 make && make install >/dev/null 1>/tmp/openvpn.log [ $? -ne 0 ] && echo "make install error,please fix it and try again." && exit 1 || echo "OpenVPN installed successful." cd ~ exit 0