OpenVPN server disable and reenable clients
I'm running OpenVPN 2.3.2 (still a newbie at this) in an Ubuntu 14.04 Server machine. I want to be able to disable/reenable clients that connect to my OpenVPN server.
I followed this guide for revoking a client's certificate, but it seems that this move is irreversible. Also, if I revoke a client's certificate, and the client is already connected, the connection does not seem to stop. I want the connection to stop immediately.
Is there any easy way to disable and reenable clients?
My server.conf file:
# OpenVPN server configuration file
dev tun
proto udp
port 1194
server 10.8.0.0 255.255.255.0
ca /usr/share/easy-rsa/keys/ca.crt
cert /usr/share/easy-rsa/keys/vpnserver.crt
key /usr/share/easy-rsa/keys/vpnserver.key
dh /usr/share/easy-rsa/keys/dh2048.pem
push "dhcp-option DNS 8.8.8.8"
push "redirect-gateway def1"
comp-lzo
keepalive 10 60
persist-tun
persist-key
user panos
group panos
log-append /var/log/openvpn.log
verb 3
# crl-verify keys/crl.pem
The last line is for the guide above.
Thank you.
Solution 1:
I implemented a solution similar to davidgo's. Unfortunately I faced an openssl error similar to this bug, and it took me a lot of time to find a workaround for this.
I wrote finally two scripts for revoking and unrevoking client certificates:
revoke.sh:
#!/bin/bash
keys_index_file=/usr/share/easy-rsa/keys/index.txt
fileline="$(grep "/CN=$1/" $keys_index_file)"
columns_number="$(echo $fileline | awk -F' ' '{print NF;}')"
if [[ $columns_number -eq 5 ]] && [[ $fileline == V* ]]; then
source /usr/share/easy-rsa/vars
/usr/share/easy-rsa/revoke-full $1
{
sleep 3
echo kill $1
sleep 3
echo exit
} | telnet localhost 7505
echo "Client certificate revoked successfully."
exit 0;
elif [[ $columns_number -eq 6 ]] && [[ $fileline == R* ]]; then
echo "Client certificate is already revoked."
exit 0;
else
echo "Error; key index file may be corrupted."
exit 1;
fi
unrevoke.sh:
#!/bin/bash
keys_index_file=/usr/share/easy-rsa/keys/index.txt
linenumber="$(grep -n "/CN=$1/" $keys_index_file | cut -f1 -d:)"
fileline="$(grep -n "/CN=$1/" $keys_index_file)"
line="$(grep "/CN=$1/" $keys_index_file)"
columns_number="$(echo $line | awk -F' ' '{print NF;}')"
echo $columns_number
if [[ $columns_number -eq 6 ]] && [[ $line == R* ]]; then
column2="$(echo $fileline | awk '{print $2}')"
column4="$(echo $fileline | awk '{print $4}')"
column5="$(echo $fileline | awk '{print $5}')"
column6="$(echo $fileline | awk '{print $6}')"
echo -e "V\t$column2\t\t$column4\t$column5\t$column6" >> $keys_index_file
sed -i "${linenumber}d" $keys_index_file
cd /usr/share/easy-rsa; source ./vars; openssl ca -gencrl -out "keys/crl.pem" -config "$KEY_CONFIG"
echo "Certificate unrevoked successfully."
exit 0;
elif [[ $columns_number -eq 5 ]] && [[ $fileline == V* ]]; then
echo "Certificate is already unrevoked and active"
exit 0;
else
echo "Error; Key index file may be corrupted."
exit 1;
fi
Note that revoke.sh
script also opens a telnet connection with openVPN and kicks out the client to be revoked.