Ocserv整合Radius认证

目前社区主流SSL VPN有两个分支:openvpn和ocserv,通过官网和检索到的资料对比前者服务端比较强大,后者客户端和移动端支持更好,二者并不兼容;
另外前者商业化封装更好,偏向商业化,后者对开发者更友好。
最近在学习vpn时对移动端要求高(主要是有国密算法相关积累),因此选择了后者;
虽然社区文档已经比较全面,但使用过程中还是遇到不少曲折。
学习过程中使用软件相关版本如下:

  1. ocserv:ocserv-1.1.6
  2. radius:freeradius-server-3.2.3
  3. radius客户端:radcli-1.3.0
  4. 数据库:mysql-5.7.24

首先是按照文档安装、配置好ocserv和freeradius之后单独测试都正常通过,但是Ocserv配置了Radius认证之后启动报错,服务启动失败,错误如下:
error: vhost:default: unknown or unsupported auth method: radius[config=/usr/local/ocserv/conf/radiusclient.conf,groupconfig=true]
从字面看就是不支持radius认证方法,翻看官方文档确实有这么一段描述:
NOTE: radcli (or libradius-client) need to be installed before ocserv. If ocserv is compiled before radius libraries, it will build without radius support. Even if radius libraries are compiled/installed afterwards, it will not work, and ocserv will return errors when you try to start the service with RADIUS authentication enabled.
大意是radclient必须先于ocserv安装,回忆安装过程好像是把顺序搞反了,于是又重新安装了一次ocserv,再次启动,错误没啥变化~
翻看config.log,发现了错误:

Package radcli was not found in the pkg-config search path.
Perhaps you should add the directory containing radcli.pc
to the PKG_CONFIG_PATH environment variable
No package 'radcli' found
configure:13172: $? = 1
configure:13186: result: no
No package 'radcli' found
configure:13218: checking for freeradius client library
configure:13236: gcc -o conftest -g -O2 -Wall -Wno-strict-aliasing -Wextra -Wno-unused-parameter -Wno-sign-compare -Wno-missing-field-initializers -Wno-implicit-fallthrough -Wno-stringop-truncation conftest.c -lfreeradius-client >&5
conftest.c:46:15: fatal error: freeradius-client.h: No such file or directory
46 | #include <freeradius-client.h>
| ^~~~~~~~~~~~~~~~~~~~~
compilation terminated.
原来radclient通过源码编译安装,pkg-config找不到库文件;
其实源码中是包含了.pc文件的,只要放到PKG_CONFIG_PATH相关目录下就好了:

cp ./radcli-1.3.0/lib/radcli.pc /usr/lib64/pkgconfig/
通过命令行测试,ocserv服务端和radius控制台显示认证成功
openconnect -v -l --dump-http-traffic --cafile=/opt/keys/ca.crt 192.168.9.118:1194

(2) sql: SQL query returned: success
(2) sql: 1 record(s) updated
rlm_sql (sql): Released connection (5)
(2) [sql] = ok
(2) [exec] = noop
(2) policy remove_reply_message_if_eap {
(2) ......
(2) } # post-auth = ok
(2) Sent Access-Accept Id 12 from 127.0.0.1:1812 to 127.0.0.1:33997 length 20

编译安装过程中可能遇到其他类似依赖缺失问题,configure阶段大部分是通过pkg-config寻找已安装依赖包,如果确认本地已经存在依赖库,通过配置PKG_CONFIG_PATH指向.pc文件存储目录即可解决,如果本地找不到依赖库则需安装;另外不排除安装后还报依赖缺失,有两种情况:

  • 安装过程中没有生成.pc包配置文件,需要参考wiki文档手写.pc文件拷贝至相应目录下。
  • 提示缺少.h文件或者.so文件,如果提示缺少.so文件,可以尝试扩展LD_LIBRARY_PATH,也可手动将已安装.h或者.so/.la文件拷贝到系统默认目录例如/usr/include或者/usr/lib目录或者建立软连接。
    官网地址:(openvpn站点需要过墙才能访问)
    [1]https://ocserv.gitlab.io/www/manual.html
    [2]https://openvpn.net/
posted @ 2023-08-03 19:06  七彩代码  阅读(674)  评论(0)    收藏  举报