Open××× 简介

Open×××是一款开源的企业级×××,功能强大,数据全程加密。无论是电脑或手机都能轻松连接企业网络,实现远程办公。

Google Authenticator  是一款动态口令生成器,在登录×××的时候,使用密码+动态口令的方式可以进一步加强×××登录的安全系数。

Open×××有两种网络连接模式,一种为本地代理。另一种为全局代理。使用本地代理连接×××之后,只在访问企业内网资源的时候走×××的网络流量,在访问互联网时依旧与无×××连接状态一样,流量不再经过×××。 全局代理模式是将本地所有流量都发送到企业×××服务器,使用企业内部防火墙策略。

在实际的生产场景中,一般使用全局代理模式,在访问远程外网资源时,默认和在办公内网权限一致。

这两种方式的配置在服务器端只需修改一行open***配置文件即可:

本地代理模式:

push "route 192.168.20.0 255.255.255.0"

全局代理模式: 

push "redirect-gateway def1 bypass-dhcp"


Open×××部署

部署环境:一台 CentOS 7.2主机或虚拟机, 可访问外网

路由初始化配置

开启内核转发功能,在 /etc/sysctl.conf 文件中添加:
net.ipv4.ip_forward=1

清空防火墙规则,添加一条nat规则:

iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE

将此命令添加到开机启动项 /etc/rc.local 


安装Open×××

直接使用yum安装

yum install open*** -y

安装open***最新的easy-rsa,该包用来制作ca证书,服务端证书,客户端证书。最新的为easy-rsa3

wget https://github.com/Open×××/easy-rsa/archive/master.zip
unzip master.zip

重命名加压后的文件:

mv easy-rsa-master easy-rsa

然后将的到的easy-ras文件夹复制到/etc/open***/目录下

cp -R easy-rsa  /etc/open***/
cd /etc/open***/easy-rsa/easyrsa3/
cp vars.example vars

配置vars中的参数如下,可以根据自身情况进行配置:

set_var EASYRSA_REQ_COUNTRY  "CN"
set_var EASYRSA_REQ_PROVINCE  "Beijing"
set_var EASYRSA_REQ_CITY    "Beijing"
set_var EASYRSA_REQ_ORG    "Company Co"
set_var EASYRSA_REQ_EMAIL   "mail_alert@126.com"
set_var EASYRSA_REQ_OU     "My Organizational Unit"

set_var EASYRSA_CA_EXPIRE       3650  # 设置证书过期时间,默认为365或180天,到期后会出现证书过期的错误提示,从而无法认证,这里设置为10年
set_var EASYRSA_CERT_EXPIRE     3650
set_var EASYRSA_CRL_DAYS        3650

CA证书配置

进入/etc/open***/easy-rsa/easyrsa3/初始化pki, 并创建ca根证书:

./easyrsa init-pki
./easyrsa build-ca

注意:在上述部分需要输入PEM密码 PEM pass phrase,输入两次,此密码必须记住,不然以后不能为证书签名。还需要输入common name 通用名,这个你自己随便设置个独一无二的。


创建服务端证书

在每个服务器系统上,生成一个请求密钥对。通常使用“nopass”参数不加密,因为服务器通常在没有任何密码输入的情况下启动。这将生成一个未加密的密钥,因此请仔细保护其此文件,并严格控制访问权限, 

该过程中需要输入common name,随意但是不要跟之前的根证书的一样

./easyrsa gen-req UNIQUE_SERVER_SHORT_NAME nopass

eg:  ./easyrsa gen-req server nopass

对服务端证书签名,输入创建ca时的密码

./easyrsa sign server UNIQUE_SERVER_SHORT_NAME

eg: ./easyrsa sign server server

在Open×××服务器创建Diffie-Hellman,该命令将生成与连接客户端进行TLS握手期间使用的DH参数。 DH参数不是安全敏感的,仅由Open×××服务器使用。

./easyrsa gen-dh


创建客户端证书

进入root目录新建client文件夹,文件夹可随意命名,然后拷贝前面解压得到的easy-ras文件夹到client文件夹,进入下列目录

cd /root/
mkdir client && cd client
cp -R easy-rsa/ client/
cd client/easy-rsa/easyrsa3/

初始化

./easyrsa init-pki

创建客户端key及生成证书(此部输入的密码为客户端×××登录密码,客户端自定义用户名为client1)

./easyrsa gen-req UNIQUE_CLIENT_SHORT_NAME

./easyrsa gen-req client1

将的到的client1.req导入并自定义命名为client1

cd /etc/open***/easy-rsa/easyrsa3/
./easyrsa import-req /root/client/easy-rsa/easyrsa3/pki/reqs/client1.req  client1

签约证书  client1要与之前导入名字一致,需要输入CA密码

./easyrsa sign client client1

提示: 如果是多台服务器,这里可以有一台CA服务器,一台open***服务器,和一台客户端。


将服务端和客户端生成的证书和密钥文件拷贝到/etc/open***/目录

cp /etc/open***/easy-rsa/easyrsa3/pki/ca.crt /etc/open***
cp /etc/open***/easy-rsa/easyrsa3/pki/private/server.key /etc/open***
cp /etc/open***/easy-rsa/easyrsa3/pki/issued/server.crt /etc/open***
cp /etc/open***/easy-rsa/easyrsa3/pki/dh.pem /etc/open***

将下列文件放到/root/client 目录下

cp /etc/open***/easy-rsa/easyrsa3/pki/ca.crt /root/client
cp /etc/open***/easy-rsa/easyrsa3/pki/issued/client1.crt /root/client
cp /root/client/easy-rsa/easyrsa3/pki/private/client1.key /root/client

修改服务端配置文件

当你安装好了open***时候,他会提供一个server配置的文件例子,在/usr/share/doc/open***-2.4.2/sample/sample-config-files/server.conf ,复制此文件到/etc/open***/

修改配置文件:

local 192.168.20.231       # ×××服务器IP
port 1194                        # 默认监听端口
proto udp                       # 使用udp协议
dev tun
ca /etc/open***/ca.crt    # ca证书路径
cert /etc/open***/server.crt  
key /etc/open***/server.key  # This file should be kept secret
dh /etc/open***/dh.pem        # dh 文件配置路径
server 10.8.0.0 255.255.255.0    # ×××客户端虚拟IP地址段,不能和本地远程网络地址段相同
ifconfig-pool-persist ipp.txt      # 客户端登录记录
# push "route 192.168.20.0 255.255.255.0"  # 为×××客户端添加一条虚拟IP段到企业内网的静态路由
push "redirect-gateway def1"   # 全局×××
keepalive 10 120  
cipher AES-256-CBC
comp-lzo         #启用数据压缩
user nobody
group nobody
persist-key
persist-tun
status open***-status.log
log         /var/log/open***/open***.log      #日志路径
log-append  /var/log/open***/open***.log    #日志路径
verb 3
explicit-exit-notify 1

启动服务

open*** --daemon --config  /etc/open***/server.conf

查看服务和端口状态:

# netstat  -lnup
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
udp        0      0 192.168.20.231:1194     0.0.0.0:*                           26264/open***

客户端配置(Windows)

这里只介绍Windows版本配置×××客户端的方法,其他客户端可以参考官方文档。

在官网下载window版本的open***软件包 open***-install-2.4.3-I601.exe,默认安装后进入C:\Program Files\Open×××\config目录。

将open***服务器上生成的客户端文件证书(默认目录/root/client)下载到本地,三个文件:client1.crt  client1.key  ca.crt

将服务器上的/usr/share/doc/open***-2.4.2/sample/sample-config-files/client.conf 文件也下载到本地config目录。

配置客户端

对本地client.conf进行编辑:

client
dev tun
proto udp
remote 192.168.20.231 1194
resolv-retry infinite
nobind
user nobody
group nobody
persist-key
persist-tun
ca ca.crt
cert client1.crt
key client1.key
cipher AES-256-CBC
comp-lzo      # 此配置要和服务端一致
verb 3

确保与服务端的配置对应,然后将client.conf修改文件名为client.o***,右键点击client.o***,选择"Start Open××× on this config file",需要输入客户端密码。

查看输出信息,如果本地获取IP,输出正常则说明连接成功,如果出现“ ERROR: Windows route add command failed [adaptive]: returned error code 1”的报错可能本地权限不够,需要用管理员运行,

在C:\Program Files\Open×××\bin\open***-gui.exe,对此exe文件右键,以管理员身份运行即可。


测试Open×××成功后,进行下一步。


添加 ×××用户

在服务器上创建用户证书:

cd /root/client/easy-rsa/easyrsa3
./easyrsa init-pki      #输入'yes'
./easyrsa  gen-req user1    # 创建user1用户,并输入用户密码

会在pki目录生成user1的文件:

# tree pki/
pki/
├── private
│   └── user1.key
└── reqs
    └── user1.req

将的到的user1.req导入并自定义命名为user1

cd /etc/open***/easy-rsa/easyrsa3/
./easyrsa import-req /root/client/easy-rsa/easyrsa3/pki/reqs/user1.req  user1

签约证书  client1要与之前导入名字一致,需要输入CA密码

./easyrsa sign client user1

拷贝文件到指定目录:

cp /etc/open***/easy-rsa/easyrsa3/pki/issued/user1.crt  /root/client/
cp /root/client/easy-rsa/easyrsa3/pki/private/user1.key  /root/client/

下载配置文件和以上两个文件到本地配置即可。


删除×××用户

回收证书权限,生成吊销证书文件:

cd /etc/open***/easy-rsa/easyrsa3
ln -s /etc/open***/ca.crt ca.crt
./easyrsa revoke user1
./easyrsa  gen-crl
mv pki/crl.pem /etc/open***/
chown root:root /etc/open***/crl.pem

在/etc/open***/server.conf 文件中添加一行配置:

crl-verify /etc/open***/crl.pem

重启open***.

open*** --daemon --config /etc/open***/server.conf


补充说明

1、在这些文件中,扩展名为.crt 的文件表示是证书或者叫公钥,而扩展名为.key 的文件表示私钥,在这些文件中,ca.crt 比较特殊,它是一个权威认证,它将会为client.crt 和server.crt 证书签名。另外,dh1024.pem 文件是用于Diffie Hellman 密钥交换的参数。这些证书、密钥只能用于测试,绝对不要正式使用。


2、ca.key 是CA 证书的RSA 密钥(PEM 格式),它属于私钥(PRIVATE KEY),使用OpenSSL 创建CA 证书的RSA密钥(PEM 格式),方法如下:

openssl genrsa -out ca.key 1024


3、ca.crt 是CA 证书,它属于证书(CERTIFICAT)。使用OpenSSL 创建CA 证书(PEM格式),方法如下,在创建的过程中,会提示输入地域信息,也可以直接回车:

# openssl req -new -x509 -days 365 -key ca.key -out ca.crt

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) [XX]:CN
State or Province Name (full name) []:BeiJing 
Locality Name (eg, city) [Default City]:BeiJing
Organization Name (eg, company) [Default Company Ltd]:Com
Organizational Unit Name (eg, section) []:
Common Name (eg, your name or your server's hostname) []:
Email Address []:


4、server.conf配置文件中的相关难点参数


格式:port 1194

默认值:port 1194

功能:该指令用于设置Open××× 所监听的TCP/UDP 端口号。如果在同一台服务器上运行多个Open××× 实例,那么要通过本指令为每一个Open××× 实例设置一个不同的端口号,如果使用了防火墙,那么也要为它们在防火墙上打开相应的端口号。


格式:proto tcp

proto udp

默认值:proto udp

功能:该指令用于设置Open××× 服务器所使用的协议类型,可选的值有两个,即 TCP或者 UDP。


格式:dev tap

默认值:dev tun

功能:该指令用于设定通信所使用的设备。