openVPN-2-4-8—基于MySQL进行用户认证
# 1,环境说明
由于不同环境及软件版本命令使用略有差异,特别是 easy-rsa 的使用在 2.0 和 3.0 的差别有点大,所以在此先说明下安装环境及相关软件版本:
- 系统平台:
Centos7.4
- OpenVPN (opens new window) 版本:
2.4.8
- easy-rsa 版本:
3.0.6
尽管不同环境及软件版本命令使用略有所差异,但是整个搭建过程都是一致的,其实基于 MySQL 认证与普通认证基本上差不太多,只不过在配置过程中,多了一两个参数而已,这里依旧简单整理文档操作流程如下:
安装相关软件—> 生成相关证书:CA 根证书、服务器证书—> 配置 open VPN 服务端—> 添加防火墙规则:snat—> 启动 open VPN 服务端—> 配置基于 MySQL 认证。
# 2,安装软件
- 安装 epel 源
yum -y install epel-release
- 安装核心软件
yum -y install openvpn easy-rsa iptables-services
# 3,制作证书
使用 easy-rsa 生成需要的证书及相关文件,在这个阶段会产生一些 key 和证书:
- CA 根证书
- OpenVPN 服务器 ssl 证书
- Diffie-Hellman 算法用到的 key
# 1,移动到统一管理目录
将 easy-rsa
脚本复制到 /etc/openvpn/
,该脚本主要用来方便地生成 CA 证书和各种 key
mkdir -p /etc/openvpn/easy-rsa/
# 这下边哪个目录都行,其实都是软链的关系
cp -a /usr/share/easy-rsa/3/* /etc/openvpn/easy-rsa/
2
3
# 2,配置环境变量
跳到 easy-rsa
目录并编辑 vars
文件,添加一些生成证书时用到的变量。
$ cd /etc/openvpn/easy-rsa
$ vim vars # 没这个文件的话新建,填写如下内容(变量值根据实际情况随便填写):
export KEY_COUNTRY="CN"
export KEY_PROVINCE="ZJ"
export KEY_CITY="Hangzhou"
export KEY_ORG="ERYAJF, Inc"
export KEY_EMAIL="Linuxlql@163.com"
export KEY_CN=vpn.eryajf.net
export KEY_NAME=vpnserver
export KEY_OU=OPS
$ source ./vars # 使变量生效
2
3
4
5
6
7
8
9
10
11
KEY_COUNTRY
:定义所在的国家KEY_PROVINCE
:定义所在的省份KEY_CITY
:定义所在的城市KEY_ORG
:定义所在的组织KEY_EMAIL
:定义邮箱地址KEY_CN
:自定义 VPN 域名KEY_NAME
:自定义 VPN 名称KEY_OU
:定义所在的单位
# 3,生成 CA 根证书
初始化pki
目录,待会儿生成的证书都会放到这个目录下。
./easyrsa init-pki
Note: using Easy-RSA configuration from: ./vars
init-pki complete; you may now create a CA or requests.
Your newly created PKI dir is: /etc/openvpn/easy-rsa/pki
2
3
4
生成 CA 根证书, 输入 Common Name
,名字随便起。
./easyrsa build-ca nopass
Note: using Easy-RSA configuration from: ./vars
Using SSL: openssl OpenSSL 1.0.2k-fips 26 Jan 2017
Generating RSA private key, 2048 bit long modulus
............................................................................................................+++
...................+++
e is 65537 (0x10001)
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.
-----
Common Name (eg: your user, host, or server name) [Easy-RSA CA]:eryajf-vpn
CA creation complete and you may now import and sign cert requests.
Your new CA certificate file for publishing is at:
/etc/openvpn/easy-rsa/pki/ca.crt
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# 4,生成服务端证书
第一个参数 server 为证书名称,可以随便起,比如 ./easyrsa build-server-full openvpn nopass
./easyrsa build-server-full server nopass
Note: using Easy-RSA configuration from: ./vars
Using SSL: openssl OpenSSL 1.0.2k-fips 26 Jan 2017
Generating a 2048 bit RSA private key
......................................................................................................................................................................................................................+++
..............................+++
writing new private key to '/etc/openvpn/easy-rsa/pki/private/server.key.bF3aSjbwlQ'
-----
Using configuration from /etc/openvpn/easy-rsa/pki/safessl-easyrsa.cnf
Check that the request matches the signature
Signature ok
The Subject's Distinguished Name is as follows
commonName :ASN.1 12:'server'
Certificate is to be certified until Jan 16 09:03:45 2023 GMT (1080 days)
Write out database with 1 new entries
Data Base Updated
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# 5,生成 Diffie-Hellman 算法需要的密钥文件
创建 Diffie-Hellman,这可能得等一小会儿。
./easyrsa gen-dh
Note: using Easy-RSA configuration from: ./vars
Using SSL: openssl OpenSSL 1.0.2k-fips 26 Jan 2017
Generating DH parameters, 2048 bit long safe prime, generator 2
This is going to take a long time
..................................................................................................................................................................................................................................................................+...........................................................................................................+...........................+............................................................................................................................................................................................................+.................................+.................................................................................................................................................................................................+..........+..............................................................................................................................................+.........................................+.......+......+..................................................................+.....................................................................+..............................................................+..................................+........+..............................................................................................................+........................................+........................................................................................................................+................................................................................................................................................................................++*++*
DH parameters of size 2048 created at /etc/openvpn/easy-rsa/pki/dh.pem
2
3
4
5
6
7
# 6,生成 tls-auth key
这个 key 主要用于防止 DoS 和 TLS 攻击,这一步其实是可选的,但为了安全还是生成一下,该文件在后面配置 open VPN 时会用到。
openvpn --genkey --secret ta.key
# 7,移动到统一管理目录
将上面生成的相关证书文件整理到 /etc/openvpn/server/certs
(这一步完全是为了维护方便)
mkdir /etc/openvpn/server/certs && cd /etc/openvpn/server/certs
cp /etc/openvpn/easy-rsa/pki/dh.pem ./
cp /etc/openvpn/easy-rsa/pki/ca.crt ./
cp /etc/openvpn/easy-rsa/pki/issued/server.crt ./
cp /etc/openvpn/easy-rsa/pki/private/server.key ./
cp /etc/openvpn/easy-rsa/ta.key ./
2
3
4
5
6
# 8,创建 open VPN 日志目录
mkdir -p /var/log/openvpn/
chown openvpn:openvpn /var/log/openvpn
2
# 4,配置 OpenVPN
可以从 /usr/share/doc/openvpn-/sample/sample-config-files
复制一份 demo 到 /etc/openvpn/
(openvpn 版本号查看:yum info openvpn。)然后改改,或者从头开始创建一个新的配置文件。
我选择新建配置:
cd /etc/openvpn/
vim server.conf
2
填入如下内容(很多配置项不需要特别了解,重要的配置这里注释出来了,其他相关配置项想了解的话见 这里 (opens new window)):
# 监听的端口号
port 1194
# 服务端用的协议,udp 能快点,所以我选择 udp
proto udp
# 定义openvpn运行时使用哪一种模式,openvpn有两种运行模式一种是tap模式,一种是tun模式。
# tap模式也就是桥接模式,通过软件在系统中模拟出一个tap设备,该设备是一个二层设备,同时支持链路层协议。
# tun模式也就是路由模式,通过软件在系统中模拟出一个tun路由,tun是ip层的点对点协议。
dev tun
# 定义openvpn在使用tun路由模式时,分配给client端分配的IP地址段
server 10.106.0.0 255.255.255.0
# 这条命令可以重定向客户端的网关,在进行翻墙时会使用到
push "redirect-gateway def1 bypass-dhcp"
# 向客户端推送的路由信息,如下内容表示客户端连接之后与当前互通
push "route 10.0.0.0 255.255.0.0"
# 向客户端推送的DNS信息
push "dhcp-option DNS 223.5.5.5"
push "dhcp-option DNS 223.6.6.6"
push "dhcp-option DNS 114.114.114.114"
# 定义活动连接保时期限
keepalive 10 300
# 加密类型
cipher AES-256-CBC
# 启用允许数据压缩,客户端配置文件也需要有这项
comp-lzo
# 最多允许连接1000个客户端
max-clients 1000
# 通过keepalive检测超时后,重新启动VPN,不重新读取keys,保留第一次使用的keys
persist-key
# 通过keepalive检测超时后,重新启动VPN,一直保持tun或者tap设备是linkup的。否则网络连接,会先linkdown然后再linkup
persist-tun
# 指定日志文件的记录详细级别,可选0-9,等级越高日志内容越详细
verb 4
# 重复日志记录限额
mute 20
# 禁用TSL重协商
reneg-sec 0
# 此选项开启只能使用udp协议。否则会报错error: --explicit-exit-notify can only be used with --proto udp
explicit-exit-notify 1
# 客户端1,服务端是0
key-direction 0
# 2.4版本之前使用 tls-auth,如果高于此版本,则用tls-crypt,我用的2.4.8使用了tls-auth,结果连通之后无法访问外网了
tls-crypt /etc/openvpn/server/certs/ta.key 0
# 记录客户端和虚拟ip地址之间的关系。在openvpn重启时,再次连接的客户端将依然被分配和断开之前的IP地址
ifconfig-pool-persist /etc/openvpn/ipp.txt
# 使用客户提供的UserName作为Common Name
username-as-common-name
# 基于mysql进行认证,如不需要可注释掉,注意最后的openvpn_mysql是与后边配置文件名称相呼应的
plugin /etc/openvpn/openvpn-plugin-auth-pam.so openvpn_mysql
# CA 根证书路径
ca /etc/openvpn/server/certs/ca.crt
# open VPN 服务器证书路径
cert /etc/openvpn/server/certs/server.crt
# open VPN 服务器密钥路径
key /etc/openvpn/server/certs/server.key
# Diffie-Hellman 算法密钥文件路径
dh /etc/openvpn/server/certs/dh.pem
# 指定 log 文件位置
log /var/log/openvpn/server.log
log-append /var/log/openvpn/server.log
status /var/log/openvpn/status.log
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# 5,防火墙相关配置
# 1,防火墙
禁用 Centos7 默认的 firewalld,使用经典的 iptables 防火墙管理软件:
systemctl stop firewalld
systemctl mask firewalld
2
# 2,禁用 SELinux
马上关闭:setenforce 0
临时生效
永久关闭:sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
| 需要重启服务器生效
# 3,启用 iptables
systemctl enable iptables
systemctl start iptables
iptables -F # 清理所有防火墙规则
2
3
# 4,添加防火墙规则
将 openvpn 的网络流量转发到公网:snat 规则
# 如下网段记得与server.conf 当中定义的网段保持一致
iptables -t nat -A POSTROUTING -s 10.106.0.0/24 -o eth0 -j MASQUERADE
iptables -L -t nat
iptables-save > /etc/sysconfig/iptables # iptables 规则持久化保存
2
3
4
# 5,Linux 服务器启用地址转发
echo net.ipv4.ip_forward = 1 >> /etc/sysctl.conf
sysctl -p # 这一步一定得执行,否则不会立即生效。
2
# 6,安全组
如果是云服务器,还需要注意将当前服务器安全组的 1194 端口开放,而确实 udp 的协议。
# 6,启动 open VPN
systemctl start openvpn@server # 启动
systemctl enable openvpn@server # 开机自启动
systemctl status openvpn@server # 查看服务状态
2
3
这个时候可能启动是失败的,因为前边配置文件当中引用了 MySQL 认证的配置文件,而这个模块,我们还没有生成。所以启动失败可以暂时忽略,后边还会再次重启。
启动之后,服务端会生成一个 tun0 的网卡:
$ ifconfig tun0
tun0: flags=4305<UP,POINTOPOINT,RUNNING,NOARP,MULTICAST> mtu 1500
inet 10.8.0.1 netmask 255.255.255.255 destination 10.8.0.2
unspec 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00 txqueuelen 100 (UNSPEC)
RX packets 715 bytes 107530 (105.0 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 626 bytes 194611 (190.0 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
2
3
4
5
6
7
8
现在,就已经配置好了 openVPN 的服务端接下来的事情就是分配不同的用户供给客户端进行使用了。
# 7,配置数据库
# 1,安装数据库。
这里为了方便试验,直接在本机部署数据库程序,直接通过 rpm 方式简单快速安装一波。
$ yum -y install mariadb mariadb-server
$ systemctl enable mariadb
$ systemctl restart mariadb
# 下边是一整条命令,直接无交互方式初始化,别踩坑了。
$ mysql_secure_installation << EOF
Y
123456
123456
Y
Y
Y
Y
EOF
# 验证一下
$ mysql -u root -p123456 -e 'show databases'
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
+--------------------+
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# 2,初始化数据。
创建数据库:
MariaDB [(none)]> CREATE DATABASE IF NOT EXISTS openvpn DEFAULT CHARSET utf8;
1创建连接账号:
MariaDB [(none)]> grant all on openvpn.* to vpnadmin@'localhost' identified by 'vpn123456';
1创建用户表:
MariaDB [(none)]> use openvpn; Database changed MariaDB [openvpn]> create table vpnuser(name char(100)not null,password char(255)default null,active int(10)not null default 1,primary key(name)); # 查看 MariaDB [openvpn]> desc vpnuser; +----------+-----------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +----------+-----------+------+-----+---------+-------+ | name | char(100) | NO | PRI | NULL | | | password | char(255) | YES | | NULL | | | active | int(10) | NO | | 1 | | +----------+-----------+------+-----+---------+-------+ 3 rows in set (0.00 sec)
1
2
3
4
5
6
7
8
9
10
11
12
13创建日志表:
MariaDB [openvpn]> create table loginlog(msg char (254),user char(100),pid char(100),host char(100),rhost char(100),time char(100)); # 查看 MariaDB [openvpn]> desc loginlog; +-------+-----------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------+-----------+------+-----+---------+-------+ | msg | char(254) | YES | | NULL | | | user | char(100) | YES | | NULL | | | pid | char(100) | YES | | NULL | | | host | char(100) | YES | | NULL | | | rhost | char(100) | YES | | NULL | | | time | char(100) | YES | | NULL | | +-------+-----------+------+-----+---------+-------+ 6 rows in set (0.00 sec)
1
2
3
4
5
6
7
8
9
10
11
12
13
14插件两个测试用户:
MariaDB [openvpn]> insert into vpnuser (name,password) values ('test1',password('123456')); Query OK, 1 row affected (0.00 sec) MariaDB [openvpn]> insert into vpnuser (name,password) values ('test2',password('654321')); Query OK, 1 row affected (0.00 sec) # 查看用户 # 第一列为登录vpn的用户名,第二列为登录的密码,第三列是是否被禁用,1为启用,改为0表示不能登录。 MariaDB [openvpn]> select * from vpnuser; +-------+-------------------------------------------+--------+ | name | password | active | +-------+-------------------------------------------+--------+ | test1 | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 | 1 | | test2 | *2A032F7C5BA932872F0F045E0CF6B53CF702F2C5 | 1 | +-------+-------------------------------------------+--------+ 2 rows in set (0.00 sec)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
# 8,配置认证
# 1,安装认证软件
rpm -Uvh http://www.nosuchhost.net/~cheese/fedora/packages/epel-7/x86_64/cheese-release-7-1.noarch.rpm
yum -y install pam_mysql pam_krb5 pam pam_devel gcc gcc-c++ cyrus-sasl autoconf
systemctl enable saslauthd
systemctl restart saslauthd
ls /usr/lib64/security/pam_mysql.so
2
3
4
5
注意
此文档已过去多年,后来经过群友提醒,此处的 pam_mysql 包不能通过 yum 直接安装了。而需要通过如下方式进行安装:
rpm -ivh http://repo.iotti.biz/CentOS/7/x86_64/pam_mysql-0.8.1-0.22.el7.lux.x86_64.rpm
系统自带的版本是 0.7 的,使用这个版本的话会导致后边 OpenVPN 连接的时候认证不成功,/var/log/secure 日志中会一直报下边错误:
openvpn: PAM unable to dlopen(/usr/lib64/security/pam_mysql.so): /usr/lib64/security/pam_mysql.so: undefined symbol: pam_set_data
openvpn: PAM adding faulty module: /usr/lib64/security/pam_mysql.so
openvpn: PAM unable to dlopen(/usr/lib64/security/pam_mysql.so): /usr/lib64/security/pam_mysql.so: undefined symbol: pam_set_data
openvpn: PAM adding faulty module: /usr/lib64/security/pam_mysql.so
openvpn: PAM unable to dlopen(/usr/lib64/security/pam_mysql.so): /usr/lib64/security/pam_mysql.so: undefined symbol: pam_set_data
2
3
4
5
saslauthd 是一个利用 sasl 资料库进行明文身份验证的守护进程,等会儿配置完毕之后将通过这个工具进行命令行的简单验证。
这步操作之后,也会生成依赖库文件 /usr/lib64/security/pam_mysql.so
,后边会提到这个模块。
# 2,配置认证文件
上边了解到了一个工具叫 saslauthd,现在想要配置这个工具与 MySQL 的连接,则需要通过如下配置进行定义,配置默认路径在 /etc/pam.d
:
$ cat > /etc/pam.d/openvpn_mysql << EOF
auth sufficient pam_mysql.so user=vpnadmin passwd=vpn123456 host=localhost db=openvpn table=vpnuser usercolumn=name passwdcolumn=password [where=vpnuser.active=1] sqllog=0 crypt=2 sqllog=true logtable=loginlog logmsgcolumn=msg logusercolumn=user logpidcolumn=pid loghostcolumn=host logrhostcolumn=rhost logtimecolumn=time
account required pam_mysql.so user=vpnadmin passwd=vpn123456 host=localhost db=openvpn table=vpnuser usercolumn=name passwdcolumn=password [where=vpnuser.active=1] sqllog=0 crypt=2 sqllog=true logtable=loginlog logmsgcolumn=msg logusercolumn=user logpidcolumn=pid loghostcolumn=host logrhostcolumn=rhost logtimecolumn=time
EOF
2
3
4
注意:此处引用的 pam_mysql.so
,默认路径为 /usr/lib64/security/pam_mysql.so
,此处也可以用绝对路径引用。
# 3,命令行验证
如上配置如果都没有问题,那么就可以通过 saslauthd 来进行一下验证了。
saslauthd 的用法是 testsaslauthd -u 用户 -p 密码 -s 服务名
:
$ testsaslauthd -u test1 -p 123456 -s openvpn_mysql
0: OK "Success."
2
如果返回
0: OK "Success."
则说明认证成功。如果返回:
connect() : No such file or directory
,那么重启一下saslauthd
服务之后再进行验证。如果返回:
0: NO "authentication failed"
1,验证失败原因大概有三,其一:服务名称是否指定正确,其二:上一步配置数据库连接信息是否正确,以及引用的
pam_mysql.so
1是否正确,其三,数据库表中的测试用户名密码是否正确。如果这三步都没毛病,那么可以通过查看系统日志获取失败信息:
tail -100f /var/log/secure
tail -100f /var/log/messages
注意:服务名与上一步定义的文件名 (openvpn_mysql
) 是相呼应的。
# 4,安装 openVPN 依赖库。
事实上,基于 MySQL 认证的 openVPN 使用的服务端配置文件,比普通认证的只多了一行配置:
# 基于mysql进行认证,如不需要可注释掉,注意最后的openvpn_mysql是与后边配置文件名称相呼应的
plugin /etc/openvpn/openvpn-plugin-auth-pam.so openvpn_mysql
2
这行配置的意思是,启用插件,通过 /etc/openvpn/openvpn-plugin-auth-pam.so
这个模块儿实现,并对接 saslauthd
管理的 openvpn_mysql
。
现在还缺少 /etc/openvpn/openvpn-plugin-auth-pam.so
这个模块,此模块需要通过 openVPN 的源码编译得来。
# 下载对应版本的源码包
wget http://swupdate.openvpn.org/community/releases/openvpn-2.4.8.tar.gz
# 解压
tar xf openvpn-2.4.8.tar.gz
cd openvpn-2.4.8/
# 安装编译所需依赖
yum -y install openssl openssl-devel lzo-devel
# 在根目录进行编译
./configure
make
# 将编译生成的库文件拷贝到对应目录
cp src/plugins/auth-pam/.libs/openvpn-plugin-auth-pam.so /etc/openvpn/
2
3
4
5
6
7
8
9
10
11
12
拷贝完成之后,即可重启 openVPN。
systemctl restart openvpn@server
这里重启服务,就不应该失败了,如果启动失败,则应该通过日志来排查原因。
# 9,用户管理
基于 MySQL 进行用户管理之后就非常简便了,如果需要新增用户,只需要在 user 表新增一条数据即可,如果此用户离职了,那么只需要删除这条数据即可。
# 1,客户端配置
这次客户端配置,可以直接定义好,然后所有人通用此配置,只不过在登陆的时候,再使用自己的用户名密码进行认证即可。
cat eryajf-testvpn.ovpn
client
dev tun
proto udp
sndbuf 0
rcvbuf 0
remote myvpnserver 1194
resolv-retry infinite
nobind
persist-key
persist-tun
remote-cert-tls server
comp-lzo
verb 3
cipher AES-256-CBC
auth-user-pass
auth-nocache
script-security 3
key-direction 1
<ca>
-----BEGIN CERTIFICATE-----
MIIDMjCCAhqgAwIBAgIJAMpLxMAv8cfXMA0GCSqGSIb3DQEBCwUAMBUxEzARBgNV
BAMMCmVyeWFqZi12cG4wHhcNMjAwMjAzMDM1ODUyWhcNMzAwMTMxMDM1ODUyWjAV
MRMwEQYDVQQDDAplcnlhamYtdnBuMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIB
CgKCAQEAwvtiGrwnJkeW4cgWjV3gUEh8N1XdmXMICqHhRYfBT40W5m7FEX1UbpWJ
IpqScLSD8nrK9k3Jn3KJPzUE8Iasegn69wt9U/6CrWp0qeg//SDsQRXEf8z9yBwH
X4GpmzCqXXYiputkKgdf+LBj/foPeiXXwn7hxzKzeZSl2DTZAUOLnh+l0KwMf50T
2YW2+5jEEG0mmgX9ScKxlvFPGLv3OjAbQPZYaqtiD9GV5lA3R7jSth7+752pEPWT
FvzCWisd1/IL11MAlUrlgZ+hITc70ziNFFi50hNvBuHU74an5AtaUKdcM+ZluYLL
TpqBieuk1F3Fq2foFpdSR7m7qiFCawIDAQABo4GEMIGBMB0GA1UdDgQWBBTHJQpO
9GGbNagS3pTC2o48nm9hZzBFBgNVHSMEPjA8gBTHJQpO9GGbNagS3pTC2o48nm9h
Z6EZpBcwFTETMBEGA1UEAwwKZXJ5YWpmLXZwboIJAMpLxMAv8cfXMAwGA1UdEwQF
MAMBAf8wCwYDVR0PBAQDAgEGMA0GCSqGSIb3DQEBCwUAA4IBAQCG0cUstkZGs8fv
UpODNE/IMQfBUvhtOi5m2vOqtbDMbFDKRaZaTjELDMTrFuWlBFWTEYebOnsZMrKU
xMwUXvvc98POG0W4mk/FaerA1VKOi1ErL+BdWlY4cOpkLukYmHScr04bKJ9IVR8f
cYtQyIz6vC7lxLkqBGgD/g+jH+YbvQbFy2CAW+jng1GU91jLIL75WNzGBkQ1yKsX
QF9MAkHEiYo1qSfMIMm2yYJ7PfLvTw1iS6TslkJjv53hNN443e8ccPHW2dXIRYKW
fvwH3eNCdlT+hga6D459GPO1hlWkFzJA96rUFcHKxPrZB86BAZZ7fZd4h4l33hPP
X3hVWk9t
-----END CERTIFICATE-----
</ca>
<cert>
Certificate:
Data:
Version: 3 (0x2)
Serial Number:
d9:a0:3c:8e:3d:98:17:33:0d:68:45:69:de:85:b3:5e
Signature Algorithm: sha256WithRSAEncryption
Issuer: CN=eryajf-vpn
Validity
Not Before: Feb 3 03:58:58 2020 GMT
Not After : Jan 18 03:58:58 2023 GMT
Subject: CN=server
Subject Public Key Info:
Public Key Algorithm: rsaEncryption
Public-Key: (2048 bit)
Modulus:
00:b7:6b:4d:0f:72:58:0a:ef:8f:b3:cc:78:a8:53:
24:86:d6:6a:fa:aa:ce:e0:6b:29:0f:6b:b0:32:58:
82:ad:cb:cd:8c:4f:ce:9e:36:58:dd:ea:5c:27:bb:
d0:d8:e5:80:c2:93:99:54:c6:29:3a:64:9c:a0:04:
56:da:ff:41:e3:6c:23:36:b6:aa:d4:ff:f9:d6:46:
3b:89:62:b9:7b:71:93:e2:a8:8e:4a:d9:e7:4c:7b:
52:68:7c:b2:ba:9a:30:e7:77:8a:2d:f8:a9:20:50:
d5:86:50:5c:62:60:39:7a:62:d0:07:65:17:63:ef:
20:80:be:89:fd:c0:be:88:89:1a:82:ca:d2:a4:cb:
4c:0d:61:7b:b0:5d:54:45:9d:a5:2c:4f:5e:3d:f8:
be:d8:70:d2:c4:13:50:6f:f9:f6:a4:06:a8:34:85:
59:d6:57:b2:85:1e:7f:c9:db:3d:cc:c1:78:0d:ac:
00:33:f4:9d:2e:c6:bd:27:22:b5:2b:46:82:9c:e0:
30:70:37:8e:83:8c:f0:20:05:17:de:fb:79:5e:fb:
90:a9:b8:8b:0d:10:9a:87:99:e0:4b:8b:e2:a1:87:
c9:c2:fc:5d:3a:33:8a:71:e6:2a:bd:bc:1e:e9:d6:
b1:0d:d7:8c:14:e3:df:eb:40:1b:d7:90:7c:7c:ce:
a2:0b
Exponent: 65537 (0x10001)
X509v3 extensions:
X509v3 Basic Constraints:
CA:FALSE
X509v3 Subject Key Identifier:
F1:3C:C3:92:F6:3A:71:27:DB:3B:00:10:0D:D4:11:61:25:1F:79:86
X509v3 Authority Key Identifier:
keyid:C7:25:0A:4E:F4:61:9B:35:A8:12:DE:94:C2:DA:8E:3C:9E:6F:61:67
DirName:/CN=eryajf-vpn
serial:CA:4B:C4:C0:2F:F1:C7:D7
X509v3 Extended Key Usage:
TLS Web Server Authentication
X509v3 Key Usage:
Digital Signature, Key Encipherment
X509v3 Subject Alternative Name:
DNS:server
Signature Algorithm: sha256WithRSAEncryption
76:e5:35:0d:3d:27:66:16:d3:2c:99:b9:83:de:bd:8e:86:2b:
57:a7:fc:53:c4:7d:4b:8b:47:cc:04:99:35:62:c5:bd:58:62:
d6:f8:60:3d:ea:5f:d2:05:b1:53:24:b2:90:2f:94:5c:5e:48:
af:a3:3d:53:95:68:15:15:68:ff:4e:ad:45:eb:04:a6:7e:7d:
7c:0c:2b:5c:0e:59:b8:ae:ca:41:90:7e:91:cb:9d:e4:61:6c:
e0:c8:4d:09:1e:eb:cb:d0:0b:d2:b4:f1:70:08:c6:04:9d:ec:
bc:83:79:a0:bd:cd:ea:67:97:eb:b8:3e:c9:dd:31:1d:86:42:
2e:4e:28:e8:f6:c9:9f:24:0b:c3:0b:91:86:63:4f:d0:ec:90:
05:2b:ec:e6:be:b6:5e:1c:be:72:e5:dd:3c:0a:28:94:30:15:
49:2d:15:fd:ee:45:01:6f:c9:a6:7b:13:9f:c8:92:ba:c9:6b:
39:dd:e3:38:ab:d9:6a:84:86:a8:39:7e:40:ae:f1:94:d8:d7:
20:b2:8a:7a:37:92:74:60:c6:b9:96:0c:35:2d:5d:a1:cc:17:
60:25:d1:81:a2:7a:ca:1e:cc:95:50:75:52:b2:25:b6:5d:65:
14:bf:8e:18:bf:b8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sXy+Jfn4VTH8f1aVkU
m3qlsE07DQKmbjGZaRpplMpEIwKBgQDIMIhIKIp1poC52dtXUhxANRNxMhLzXgnd
/2LNcMaH3EOqO8eK9Nb98Nz9IwrPA1d6gIcIpb+MhKobn2s5hTF5l7pQ+QNZyZNO
Vg4wcOkfpjabaXXtJjRozUOPUnYekMx6eTuStjLc9PYQfYwsa39ouqJwms/ySyJk
hNNQRev0+QKBgCdC3ADSnoeAxLrESQx9AtxnEA+0/+a2eec+RM2EY+D3OG9YrX2B
UMu7CDpi20ZPVTKlwSk41qhuxAEv/KpDwdMKI/dL+6GYqKQvZ9AljOKdU51S7eBj
rZJrxw9QiXRbafJPxHKxJwYE+dmQasLSS7NUUXki8mCdbVv6hdtKdpj1AoGBAJYz
c81QPbLQXr0TLHNz9CZorFG+FGHtKNIcD/G8r/i31z0e5TTpR3X5BpYXeMCh7TzI
uohOdE3mLAvVrQnXWau1n+GpNE5l49Re1P6beQ56E3a/xe9NPv1zJUGfyWhdlE5A
L+aANeF7GjR9PnMFpO7bOY3rWiKdJQzua+5KyCNhAoGAPHhh1J/5uetmQQnedZ2V
mtSZo1y8t2XlnspsF0hfzCYy0+navvhP02N3uWPBH1ocTtZMbZP/9cnf1Ylm5U7z
Baxl0Ydxp+sRYzm2DG4g60sEuPWP+jBc54c44A3Men834QlKqw4NAg/6xU7tfhmO
oNzvVuDDDkVJkB9KHNu9OvY=
-----END PRIVATE KEY-----
</key>
<tls-crypt>
#
# 2048 bit OpenVPN static key
#
-----BEGIN OpenVPN Static key V1-----
d406fa21023741d539828421eb9e6171
c6eab230f034eb91942e0f4dd9390583
8a9211fa5decd4be848a2e8b6fcec9e3
0d2faf9310df7b4d5fe8b1505225af28
6cc9e8b4b899063a70f0619fafd6179b
4913eed8a1885041794c363a8b775a0c
0c25df05cfe00a7933dd19e1fd705993
2007eb53b94105b714d997a2129b8d73
92da2fa6602b046f15f5f603d85dba86
a2ca335405f759bc9bdf83e85ee611c3
965571673c2f3e12ceef4bebf9b72ec7
3e7310a0d71aca9c8ba0f2c681187ff5
53b8bd76dc2cb449ad15f05e2cb8a3e8
ebd95088a65f36dea9465ea1c5ad3a4e
3e853b7ab6e728d78ea48f482d500850
c36a341735096601c20ff27d652bfb24
-----END OpenVPN Static key V1-----
</tls-crypt>
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
# 2,客户端验证
我们上边已经有了两个测试用户,现在就用其中一个,进行验证。
要连接到 open VPN 服务端首先得需要一个客户端软件,在 Mac 下推荐使用 Tunnelblick (opens new window),下载地址:https://tunnelblick.net/。Tunnelblick 是一个开源、免费的 Mac 版 open VPN 客户端软件。
下载之后进行安装,安装方式非常简单,直接将上边生成的配置文件下载到本地,双击 eryajf-testvpn.ovpn
即可自动安装到 Tunnelblick 客户端当中,添加之后的配置可以在界面中查看,如下:
然后点击连接,会跳出让输入用户名密码的界面:
此时输入上边创建的测试用户以及密码,记得点击存储,这样以后就不用每次都输入用户名密码了。
这种管理方式更加简便,不需要给每个用户分发证书秘钥,只需要拿上这份统一的配置文件,在数据库新增一条数据即可进行登录验证了。
# 10,参考
- https://www.xiaohuait.com/2018/07/27/openvpnmysql%e5%af%86%e7%a0%81%e8%ae%a4%e8%af%81/ (opens new window)
- http://www.51niux.com/?id=73