OpenVPN是一个用于创建虚拟专用网络加密通道的软件包,允许创建的VPN使用公开密钥、数字证书、或者用户名/密码来进行身份验证。OpenVPN能在Solaris、Linux、OpenBSD、FreeBSD、NetBSD、Mac OS X与Windows 2000/XP/Vista/7以及Android和iOS上运行,并包含了许多安全性的功能。
配置OpenVPN 2.0的第一步是建立一个PKI(public key infrastructure 公钥基础设施)。PKI包括:
服务端和每个客户端都有一个证书(也称做公钥)和私钥
一个认证机构(CA)的证书和私钥,用来为每一个服务端和客户端颁发证书(sign each of the server and client certificates)。
OpenVPN 支持基于证书的双向认证,也就是说客户端需认证服务端,服务端也要认证客户端,
服务端和客户端验证对方的第一步是验证对方提供的证书是由认证机构(CA)颁发的。然后测试第一步认证通过的证书的头部信息,如:证书的common name,证书的类型(客户端还是服务端)。
从VPN的观点来看,这一安全模式满足一系列要求:
服务端仅仅需要它自己的证书/私钥对 -- 它不需要知道客户端的证书。
服务端仅仅接受拥有CA颁发的证书的客户端。因为服务端检查证书是否由CA颁发时并不需要访问 CA的私钥,这样就可以将CA的私钥(整个PKI中最重要的私钥)放在另一台机子上。
如果一个私钥(is compromised),通过将它的证书加入CRL(证书吊销列表)可以禁止这一私钥。 CRL允许有选择地拒绝compromised 证书而不需要重建整个PKI。
基于嵌入的证书域比如Vommon Name,服务端能够加强客户端待定(client-specific)访问权限 (access fights)。
服务器端配置
首先,我们必须安装OpenVPN软件。在Ubuntu 15.04和其它带有‘apt’包管理器的Unix系统中,可以通过如下命令安装:
开始之前,我们需要拷贝“easy-rsa”到openvpn文件夹。
首先,我们编辑一个“vars”文件。为了简化生成过程,我们需要在里面指定数据。这里是“vars”文件的一个样例:
export KEY_COUNTRY="CN"
export KEY_PROVINCE="BJ"
export KEY_CITY="Beijing"
export KEY_ORG="Linux.CN"
export KEY_EMAIL="open@vpn.linux.cn"
export KEY_OU=server
希望这些字段名称对你而言已经很清楚,不需要进一步说明了。
其次,我们需要拷贝openssl配置。另外一个版本已经有现成的配置文件,如果你没有特定要求,你可以使用它的上一个版本。这里是1.0.0版本。
Generating a 2048 bit RSA private key
.............................................+++
...................................................................................................+++
writing new private key to 'ca.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) [BJ]:
Locality Name (eg, city) [Beijing]:
Organization Name (eg, company) [Linux.CN]:
Organizational Unit Name (eg, section) [Tech]:
Common Name (eg, your name or your server's hostname) [Linux.CN CA]:
Name [EasyRSA]:
Email Address [open@vpn.linux.cn]:
接下来,我们需要生成一个服务器密钥
Generating a 2048 bit RSA private key
........................................................................+++
............................+++
writing new private key to '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) [BJ]:
Locality Name (eg, city) [Beijing]:
Organization Name (eg, company) [Linux.CN]:
Organizational Unit Name (eg, section) [Tech]:
Common Name (eg, your name or your server's hostname) [Linux.CN server]:
Name [EasyRSA]:
Email Address [open@vpn.linux.cn]:
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:
Using configuration from /etc/openvpn/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:'BJ'
localityName :PRINTABLE:'Beijing'
organizationName :PRINTABLE:'Linux.CN'
organizationalUnitName:PRINTABLE:'Tech'