04
2019
12
14:54:58

Ocserv证书登录如何屏蔽/吊销证书



推荐点击下面图片,通过本站淘宝优惠价购买:

image.png

https://www.jianshu.com/p/686e5915a502


ocserv本身提供多种认证方式,比较常用的方式是账号密码和证书。

现在的问题是,如果开启了证书认证,已经发出去的证书,如何吊销/屏蔽,亦即,禁止此证书通过登录认证。

有两种方式,一种是常规的吊销证书,一种是通过登录脚本控制。
对于吊销证书的方式,转载一下:

吊销证书

进入证书所在目录
cd /etc/ocserv/certs
创建吊销模板 crl.tmpl
crl_next_update = 9999
crl_number = 1
把用户证书重定向到一个文件
cat user1-cert.pem >> revoked.pem
执行吊销操作, 最终成生一个 crl.pem 吊销列表
certtool --generate-crl --load-ca-privkey ca-key.pem --load-ca-certificate ca-cert.pem --load-certificate revoked.pem --template crl.tmpl --outfile crl.pem
最后, 需要重启 ocserv 服务才可以使 crl.pem 生效


以上内容来自:https://bijizhan.com/post/ocserv-install-conf
同时为需要上下文的同学存档一下:http://web.archive.org/web/20180818003101/https://bijizhan.com/post/ocserv-install-conf
上述方式要求你保留了生成用户证书时的pem文件,而不是p12文件,并且操作起来也比较麻烦。

下面介绍一种相对方便的方式:

在ocserv的配置文件(默认是/etc/ocserv/ocserv.conf)中,有一个选项是connect-script,给它填上值,比如

connect-script=/home/yourname/connectscript

然后创建该文件,开始写脚本:

#!/bin/sh
case $USERNAME in
    testa|testb|testc)
        exit 1
        ;;
        
    *)  
        ;;
esac
exit 0

上述testa, testb, testc即为要吊销的证书的名称,就是生成证书那步,填名称和密码那步填写的名称,如果不确定有哪些证书名称,可以利用这个脚本,log所有登录操作的证书名称。

在这个脚本中可以用的变量有:

$USERNAME

$REASON,其中,此变量的取值可能为disconnect, connect。(当然disconnect在你配置了ocserv配置中的disconnect-script时才会取到)

更多可用变量,引述一下ocserv.conf中的注释:

# Script to call when a client connects and obtains an IP.
# The following parameters are passed on the environment.
# REASON, USERNAME, GROUPNAME, HOSTNAME (the hostname selected by client), 
# DEVICE, IP_REAL (the real IP of the client), IP_REAL_LOCAL (the local
# interface IP the client connected), IP_LOCAL (the local IP
# in the P-t-P connection), IP_REMOTE (the VPN IP of the client),
# IPV6_LOCAL (the IPv6 local address if there are both IPv4 and IPv6
# assigned), IPV6_REMOTE (the IPv6 remote address), IPV6_PREFIX, and
# ID (a unique numeric ID); REASON may be "connect" or "disconnect".
# In addition the following variables OCSERV_ROUTES (the applied routes for this
# client), OCSERV_NO_ROUTES, OCSERV_DNS (the DNS servers for this client),
# will contain a space separated list of routes or DNS servers. A version
# of these variables with the 4 or 6 suffix will contain only the IPv4 or
# IPv6 values.

# The disconnect script will receive the additional values: STATS_BYTES_IN,
# STATS_BYTES_OUT, STATS_DURATION that contain a 64-bit counter of the bytes 
# output from the tun device, and the duration of the session in seconds.

当使用被名称放到上面脚本中的证书连接时,会失败。

ocserv配置文件生效需要重启;如果已经在ocserv的配置文件中配置了脚本路径并已生效,脚本本身的修改时实时的,因为每次有登录操作时,会执行此脚本。

只要退出值不为0,连接就会失败,至此,我们的目标已经达成。



作者:stuazt
链接:https://www.jianshu.com/p/686e5915a502
来源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。


本文链接:https://hqyman.cn/post/1096.html 非本站原创文章欢迎转载,原创文章需保留本站地址!

分享到:





休息一下,本站随机推荐观看栏目:


« 上一篇 下一篇 »

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

您的IP地址是: