2020-05-11 09:18:34 +03:00
|
|
|
#!/bin/bash
|
|
|
|
#
|
2022-03-21 07:10:11 +03:00
|
|
|
# Script to set up and manage IKEv2 on Ubuntu, Debian, CentOS/RHEL, Rocky Linux,
|
|
|
|
# AlmaLinux, Oracle Linux, Amazon Linux 2 and Alpine Linux
|
2021-09-20 05:51:14 +03:00
|
|
|
#
|
|
|
|
# DO NOT RUN THIS SCRIPT ON YOUR PC OR MAC!
|
2020-05-11 09:18:34 +03:00
|
|
|
#
|
2020-12-15 08:12:15 +03:00
|
|
|
# The latest version of this script is available at:
|
|
|
|
# https://github.com/hwdsl2/setup-ipsec-vpn
|
|
|
|
#
|
2023-01-05 03:58:29 +03:00
|
|
|
# Copyright (C) 2020-2023 Lin Song <linsongui@gmail.com>
|
2020-05-11 09:18:34 +03:00
|
|
|
#
|
|
|
|
# This work is licensed under the Creative Commons Attribution-ShareAlike 3.0
|
|
|
|
# Unported License: http://creativecommons.org/licenses/by-sa/3.0/
|
|
|
|
#
|
|
|
|
# Attribution required: please include my name in any derivative and let me
|
|
|
|
# know how you have improved it!
|
|
|
|
|
|
|
|
export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
|
|
|
|
|
|
|
|
exiterr() { echo "Error: $1" >&2; exit 1; }
|
2021-02-05 08:41:48 +03:00
|
|
|
bigecho() { echo "## $1"; }
|
2021-03-31 07:47:59 +03:00
|
|
|
bigecho2() { printf '\e[2K\r%s' "## $1"; }
|
2020-05-11 09:18:34 +03:00
|
|
|
|
|
|
|
check_ip() {
|
|
|
|
IP_REGEX='^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$'
|
|
|
|
printf '%s' "$1" | tr -d '\n' | grep -Eq "$IP_REGEX"
|
|
|
|
}
|
|
|
|
|
|
|
|
check_dns_name() {
|
|
|
|
FQDN_REGEX='^([a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,}$'
|
|
|
|
printf '%s' "$1" | tr -d '\n' | grep -Eq "$FQDN_REGEX"
|
|
|
|
}
|
|
|
|
|
2021-08-11 08:03:25 +03:00
|
|
|
check_root() {
|
2021-01-18 09:01:46 +03:00
|
|
|
if [ "$(id -u)" != 0 ]; then
|
|
|
|
exiterr "Script must be run as root. Try 'sudo bash $0'"
|
2021-01-15 08:21:52 +03:00
|
|
|
fi
|
2021-01-18 09:01:46 +03:00
|
|
|
}
|
2021-01-15 08:21:52 +03:00
|
|
|
|
2022-02-15 08:45:13 +03:00
|
|
|
check_container() {
|
|
|
|
in_container=0
|
|
|
|
if grep -qs "hwdsl2" /opt/src/run.sh; then
|
|
|
|
in_container=1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2021-08-11 08:03:25 +03:00
|
|
|
check_os() {
|
2021-04-20 08:09:00 +03:00
|
|
|
rh_file="/etc/redhat-release"
|
2022-08-11 06:41:55 +03:00
|
|
|
if [ -f "$rh_file" ]; then
|
|
|
|
os_type=centos
|
|
|
|
if grep -q "Red Hat" "$rh_file"; then
|
|
|
|
os_type=rhel
|
|
|
|
fi
|
|
|
|
[ -f /etc/oracle-release ] && os_type=ol
|
|
|
|
grep -qi rocky "$rh_file" && os_type=rocky
|
|
|
|
grep -qi alma "$rh_file" && os_type=alma
|
|
|
|
if grep -q "release 7" "$rh_file"; then
|
|
|
|
os_ver=7
|
|
|
|
elif grep -q "release 8" "$rh_file"; then
|
|
|
|
os_ver=8
|
|
|
|
grep -qi stream "$rh_file" && os_ver=8s
|
|
|
|
elif grep -q "release 9" "$rh_file"; then
|
|
|
|
os_ver=9
|
|
|
|
grep -qi stream "$rh_file" && os_ver=9s
|
|
|
|
else
|
|
|
|
exiterr "This script only supports CentOS/RHEL 7-9."
|
|
|
|
fi
|
2023-05-22 06:19:30 +03:00
|
|
|
elif grep -qs "Amazon Linux release 2 " /etc/system-release; then
|
2021-01-18 09:01:46 +03:00
|
|
|
os_type=amzn
|
|
|
|
os_ver=2
|
2021-01-15 08:21:52 +03:00
|
|
|
else
|
2021-01-18 09:01:46 +03:00
|
|
|
os_type=$(lsb_release -si 2>/dev/null)
|
|
|
|
[ -z "$os_type" ] && [ -f /etc/os-release ] && os_type=$(. /etc/os-release && printf '%s' "$ID")
|
|
|
|
case $os_type in
|
|
|
|
[Uu]buntu)
|
|
|
|
os_type=ubuntu
|
|
|
|
;;
|
2022-08-11 07:25:58 +03:00
|
|
|
[Dd]ebian|[Kk]ali)
|
2021-01-18 09:01:46 +03:00
|
|
|
os_type=debian
|
|
|
|
;;
|
|
|
|
[Rr]aspbian)
|
|
|
|
os_type=raspbian
|
|
|
|
;;
|
2021-07-13 07:41:33 +03:00
|
|
|
[Aa]lpine)
|
|
|
|
os_type=alpine
|
|
|
|
;;
|
2021-01-18 09:01:46 +03:00
|
|
|
*)
|
2021-09-20 05:51:14 +03:00
|
|
|
cat 1>&2 <<'EOF'
|
|
|
|
Error: This script only supports one of the following OS:
|
2022-03-21 07:10:11 +03:00
|
|
|
Ubuntu, Debian, CentOS/RHEL, Rocky Linux, AlmaLinux,
|
|
|
|
Oracle Linux, Amazon Linux 2 or Alpine Linux
|
2021-09-20 05:51:14 +03:00
|
|
|
EOF
|
2021-09-11 23:00:29 +03:00
|
|
|
exit 1
|
2021-01-18 09:01:46 +03:00
|
|
|
;;
|
|
|
|
esac
|
2021-07-13 07:41:33 +03:00
|
|
|
if [ "$os_type" = "alpine" ]; then
|
2021-09-11 23:00:29 +03:00
|
|
|
os_ver=$(. /etc/os-release && printf '%s' "$VERSION_ID" | cut -d '.' -f 1,2)
|
2023-02-12 08:08:37 +03:00
|
|
|
if [ "$os_ver" != "3.16" ] && [ "$os_ver" != "3.17" ]; then
|
|
|
|
exiterr "This script only supports Alpine Linux 3.16/3.17."
|
2021-09-11 23:00:29 +03:00
|
|
|
fi
|
2021-07-13 07:41:33 +03:00
|
|
|
else
|
|
|
|
os_ver=$(sed 's/\..*//' /etc/debian_version | tr -dc 'A-Za-z0-9')
|
|
|
|
fi
|
2021-01-15 08:21:52 +03:00
|
|
|
fi
|
2021-01-18 09:01:46 +03:00
|
|
|
}
|
2021-01-15 08:21:52 +03:00
|
|
|
|
2021-08-22 08:42:21 +03:00
|
|
|
check_libreswan() {
|
2021-07-13 07:41:33 +03:00
|
|
|
ipsec_ver=$(ipsec --version 2>/dev/null)
|
2021-01-24 22:53:55 +03:00
|
|
|
if ( ! grep -qs "hwdsl2 VPN script" /etc/sysctl.conf && ! grep -qs "hwdsl2" /opt/src/run.sh ) \
|
2022-03-08 06:29:13 +03:00
|
|
|
|| ! printf '%s' "$ipsec_ver" | grep -qi 'libreswan'; then
|
2021-01-24 22:53:55 +03:00
|
|
|
cat 1>&2 <<'EOF'
|
|
|
|
Error: Your must first set up the IPsec VPN server before setting up IKEv2.
|
2021-01-26 07:05:06 +03:00
|
|
|
See: https://github.com/hwdsl2/setup-ipsec-vpn
|
2021-01-24 22:53:55 +03:00
|
|
|
EOF
|
|
|
|
exit 1
|
|
|
|
fi
|
2022-01-29 23:12:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
check_swan_ver() {
|
2022-02-15 08:45:13 +03:00
|
|
|
swan_ver=$(printf '%s' "$ipsec_ver" | sed -e 's/.*Libreswan U\?//' -e 's/\( (\|\/K\).*//')
|
2022-01-29 23:12:50 +03:00
|
|
|
if ! printf '%s\n%s' "3.23" "$swan_ver" | sort -C -V; then
|
2021-01-24 22:53:55 +03:00
|
|
|
cat 1>&2 <<EOF
|
|
|
|
Error: Libreswan version '$swan_ver' is not supported.
|
2022-01-29 23:12:50 +03:00
|
|
|
This script requires Libreswan 3.23 or newer.
|
2021-03-20 07:58:06 +03:00
|
|
|
To update Libreswan, run:
|
2022-05-24 06:08:30 +03:00
|
|
|
wget https://get.vpnsetup.net/upg -O vpnup.sh && sudo sh vpnup.sh
|
2021-01-24 22:53:55 +03:00
|
|
|
EOF
|
2022-01-29 23:12:50 +03:00
|
|
|
exit 1
|
|
|
|
fi
|
2021-01-24 22:53:55 +03:00
|
|
|
}
|
|
|
|
|
2021-01-18 09:01:46 +03:00
|
|
|
check_utils_exist() {
|
|
|
|
command -v certutil >/dev/null 2>&1 || exiterr "'certutil' not found. Abort."
|
2021-06-01 10:30:51 +03:00
|
|
|
command -v crlutil >/dev/null 2>&1 || exiterr "'crlutil' not found. Abort."
|
2021-01-18 09:01:46 +03:00
|
|
|
command -v pk12util >/dev/null 2>&1 || exiterr "'pk12util' not found. Abort."
|
|
|
|
}
|
2021-01-15 08:21:52 +03:00
|
|
|
|
2022-02-15 08:45:13 +03:00
|
|
|
abort_and_exit() {
|
|
|
|
echo "Abort. No changes were made." >&2
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
confirm_or_abort() {
|
|
|
|
printf '%s' "$1"
|
|
|
|
read -r response
|
|
|
|
case $response in
|
|
|
|
[yY][eE][sS]|[yY])
|
|
|
|
echo
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
abort_and_exit
|
|
|
|
;;
|
|
|
|
esac
|
2021-01-15 08:21:52 +03:00
|
|
|
}
|
|
|
|
|
2021-07-30 16:47:10 +03:00
|
|
|
show_header() {
|
|
|
|
cat <<'EOF'
|
|
|
|
|
2023-02-12 08:08:37 +03:00
|
|
|
IKEv2 Script Copyright (c) 2020-2023 Lin Song 11 Feb 2023
|
2021-07-30 16:47:10 +03:00
|
|
|
|
|
|
|
EOF
|
|
|
|
}
|
|
|
|
|
2021-01-24 22:53:55 +03:00
|
|
|
show_usage() {
|
|
|
|
if [ -n "$1" ]; then
|
2022-04-27 08:05:45 +03:00
|
|
|
echo "Error: $1" >&2
|
2021-01-24 22:53:55 +03:00
|
|
|
fi
|
2021-07-30 16:47:10 +03:00
|
|
|
show_header
|
2021-01-24 22:53:55 +03:00
|
|
|
cat 1>&2 <<EOF
|
2021-01-25 05:01:40 +03:00
|
|
|
Usage: bash $0 [options]
|
2021-01-24 22:53:55 +03:00
|
|
|
|
|
|
|
Options:
|
2021-04-18 22:27:52 +03:00
|
|
|
--auto run IKEv2 setup in auto mode using default options (for initial setup only)
|
2021-08-08 00:12:26 +03:00
|
|
|
--addclient [client name] add a new client using default options
|
|
|
|
--exportclient [client name] export configuration for an existing client
|
|
|
|
--listclients list the names of existing clients
|
2022-09-11 08:17:26 +03:00
|
|
|
--revokeclient [client name] revoke an existing client
|
|
|
|
--deleteclient [client name] delete an existing client
|
2021-01-26 07:05:06 +03:00
|
|
|
--removeikev2 remove IKEv2 and delete all certificates and keys from the IPsec database
|
2021-01-24 22:53:55 +03:00
|
|
|
-h, --help show this help message and exit
|
|
|
|
|
2021-01-25 05:01:40 +03:00
|
|
|
To customize IKEv2 or client options, run this script without arguments.
|
2022-06-09 21:44:16 +03:00
|
|
|
For documentation, see: https://vpnsetup.net/ikev2
|
2021-01-24 22:53:55 +03:00
|
|
|
EOF
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
2021-04-11 00:24:49 +03:00
|
|
|
check_ikev2_exists() {
|
2022-02-15 08:45:13 +03:00
|
|
|
grep -qs "conn ikev2-cp" "$IPSEC_CONF" || [ -f "$IKEV2_CONF" ]
|
2021-04-11 00:24:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
check_client_name() {
|
2021-07-30 16:47:10 +03:00
|
|
|
! { [ "${#1}" -gt "64" ] || printf '%s' "$1" | LC_ALL=C grep -q '[^A-Za-z0-9_-]\+' \
|
2022-04-27 08:05:45 +03:00
|
|
|
|| case $1 in -*) true ;; *) false ;; esac; }
|
2021-07-30 16:47:10 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
check_cert_exists() {
|
2022-02-15 08:45:13 +03:00
|
|
|
certutil -L -d "$CERT_DB" -n "$1" >/dev/null 2>&1
|
2021-04-11 00:24:49 +03:00
|
|
|
}
|
|
|
|
|
2021-07-30 16:47:10 +03:00
|
|
|
check_cert_exists_and_exit() {
|
2022-02-15 08:45:13 +03:00
|
|
|
if certutil -L -d "$CERT_DB" -n "$1" >/dev/null 2>&1; then
|
2021-07-30 16:47:10 +03:00
|
|
|
echo "Error: Certificate '$1' already exists." >&2
|
2021-08-01 07:36:43 +03:00
|
|
|
abort_and_exit
|
2021-07-30 16:47:10 +03:00
|
|
|
fi
|
2021-04-11 00:24:49 +03:00
|
|
|
}
|
|
|
|
|
2021-07-30 16:47:10 +03:00
|
|
|
check_cert_status() {
|
2022-02-15 08:45:13 +03:00
|
|
|
cert_status=$(certutil -V -u C -d "$CERT_DB" -n "$1")
|
2021-06-01 10:30:51 +03:00
|
|
|
}
|
|
|
|
|
2021-01-24 22:53:55 +03:00
|
|
|
check_arguments() {
|
2022-09-25 02:56:27 +03:00
|
|
|
if [ "$use_defaults" = 1 ] && check_ikev2_exists; then
|
2022-03-03 06:46:15 +03:00
|
|
|
echo "Error: Invalid parameter '--auto'. IKEv2 is already set up on this server." >&2
|
|
|
|
echo " To manage VPN clients, re-run this script without '--auto'." >&2
|
2022-08-11 08:02:42 +03:00
|
|
|
echo " To change IKEv2 server address, see https://vpnsetup.net/ikev2" >&2
|
2022-03-03 06:46:15 +03:00
|
|
|
exit 1
|
2021-01-24 22:53:55 +03:00
|
|
|
fi
|
2022-04-07 06:49:20 +03:00
|
|
|
if [ "$((add_client + export_client + list_clients + revoke_client + delete_client))" -gt 1 ]; then
|
|
|
|
show_usage "Invalid parameters. Specify only one of '--addclient', '--exportclient', '--listclients', '--revokeclient' or '--deleteclient'."
|
2021-01-24 22:53:55 +03:00
|
|
|
fi
|
2022-09-25 02:56:27 +03:00
|
|
|
if [ "$remove_ikev2" = 1 ]; then
|
2022-04-07 06:49:20 +03:00
|
|
|
if [ "$((add_client + export_client + list_clients + revoke_client + delete_client + use_defaults))" -gt 0 ]; then
|
2022-02-15 08:45:13 +03:00
|
|
|
show_usage "Invalid parameters. '--removeikev2' cannot be specified with other parameters."
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
if ! check_ikev2_exists; then
|
2022-09-25 02:56:27 +03:00
|
|
|
[ "$add_client" = 1 ] && exiterr "You must first set up IKEv2 before adding a client."
|
|
|
|
[ "$export_client" = 1 ] && exiterr "You must first set up IKEv2 before exporting a client."
|
|
|
|
[ "$list_clients" = 1 ] && exiterr "You must first set up IKEv2 before listing clients."
|
|
|
|
[ "$revoke_client" = 1 ] && exiterr "You must first set up IKEv2 before revoking a client."
|
|
|
|
[ "$delete_client" = 1 ] && exiterr "You must first set up IKEv2 before deleting a client."
|
|
|
|
[ "$remove_ikev2" = 1 ] && exiterr "Cannot remove IKEv2 because it has not been set up on this server."
|
|
|
|
fi
|
|
|
|
if [ "$add_client" = 1 ]; then
|
2021-07-30 16:47:10 +03:00
|
|
|
if [ -z "$client_name" ] || ! check_client_name "$client_name"; then
|
2021-01-24 22:53:55 +03:00
|
|
|
exiterr "Invalid client name. Use one word only, no special characters except '-' and '_'."
|
2021-07-30 16:47:10 +03:00
|
|
|
elif check_cert_exists "$client_name"; then
|
2021-01-24 22:53:55 +03:00
|
|
|
exiterr "Invalid client name. Client '$client_name' already exists."
|
|
|
|
fi
|
|
|
|
fi
|
2022-09-25 02:56:27 +03:00
|
|
|
if [ "$export_client" = 1 ] || [ "$revoke_client" = 1 ] || [ "$delete_client" = 1 ]; then
|
2021-01-24 22:53:55 +03:00
|
|
|
get_server_address
|
2021-07-30 16:47:10 +03:00
|
|
|
if [ -z "$client_name" ] || ! check_client_name "$client_name" \
|
2022-02-15 08:45:13 +03:00
|
|
|
|| [ "$client_name" = "$CA_NAME" ] || [ "$client_name" = "$server_addr" ] \
|
2021-07-30 16:47:10 +03:00
|
|
|
|| ! check_cert_exists "$client_name"; then
|
2021-01-24 22:53:55 +03:00
|
|
|
exiterr "Invalid client name, or client does not exist."
|
|
|
|
fi
|
2022-09-25 02:56:27 +03:00
|
|
|
if [ "$delete_client" = 0 ] && ! check_cert_status "$client_name"; then
|
2021-06-02 07:35:19 +03:00
|
|
|
printf '%s' "Error: Certificate '$client_name' " >&2
|
|
|
|
if printf '%s' "$cert_status" | grep -q "revoked"; then
|
2022-09-25 02:56:27 +03:00
|
|
|
if [ "$revoke_client" = 1 ]; then
|
2022-02-15 08:45:13 +03:00
|
|
|
echo "has already been revoked." >&2
|
|
|
|
else
|
|
|
|
echo "has been revoked." >&2
|
|
|
|
fi
|
2021-06-01 10:30:51 +03:00
|
|
|
elif printf '%s' "$cert_status" | grep -q "expired"; then
|
2021-06-02 07:35:19 +03:00
|
|
|
echo "has expired." >&2
|
2021-06-01 10:30:51 +03:00
|
|
|
else
|
2021-06-02 07:35:19 +03:00
|
|
|
echo "is invalid." >&2
|
2021-06-01 10:30:51 +03:00
|
|
|
fi
|
2021-06-02 07:35:19 +03:00
|
|
|
exit 1
|
2021-06-01 10:30:51 +03:00
|
|
|
fi
|
|
|
|
fi
|
2021-01-24 22:53:55 +03:00
|
|
|
}
|
|
|
|
|
2021-02-10 07:32:26 +03:00
|
|
|
check_server_dns_name() {
|
2021-02-10 10:19:17 +03:00
|
|
|
if [ -n "$VPN_DNS_NAME" ]; then
|
|
|
|
check_dns_name "$VPN_DNS_NAME" || exiterr "Invalid DNS name. 'VPN_DNS_NAME' must be a fully qualified domain name (FQDN)."
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
check_custom_dns() {
|
|
|
|
if { [ -n "$VPN_DNS_SRV1" ] && ! check_ip "$VPN_DNS_SRV1"; } \
|
2022-01-29 21:36:03 +03:00
|
|
|
|| { [ -n "$VPN_DNS_SRV2" ] && ! check_ip "$VPN_DNS_SRV2"; }; then
|
2021-07-30 16:47:10 +03:00
|
|
|
exiterr "Invalid DNS server(s)."
|
2020-06-05 18:56:33 +03:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2022-10-16 08:45:45 +03:00
|
|
|
check_client_validity() {
|
|
|
|
! { printf '%s' "$1" | LC_ALL=C grep -q '[^0-9]\+' || [ "$1" -lt "1" ] \
|
|
|
|
|| [ "$1" -gt "120" ] || [ "$1" != "$((10#$1))" ]; }
|
|
|
|
}
|
|
|
|
|
2022-02-15 08:45:13 +03:00
|
|
|
check_and_set_client_name() {
|
|
|
|
if [ -n "$VPN_CLIENT_NAME" ]; then
|
|
|
|
client_name="$VPN_CLIENT_NAME"
|
|
|
|
check_client_name "$client_name" \
|
|
|
|
|| exiterr "Invalid client name. Use one word only, no special characters except '-' and '_'."
|
|
|
|
else
|
|
|
|
client_name=vpnclient
|
|
|
|
fi
|
|
|
|
check_cert_exists "$client_name" && exiterr "Client '$client_name' already exists."
|
|
|
|
}
|
|
|
|
|
2022-10-16 08:45:45 +03:00
|
|
|
check_and_set_client_validity() {
|
|
|
|
if [ -n "$VPN_CLIENT_VALIDITY" ]; then
|
|
|
|
client_validity="$VPN_CLIENT_VALIDITY"
|
|
|
|
if ! check_client_validity "$client_validity"; then
|
|
|
|
cat <<EOF
|
|
|
|
WARNING: Invalid client cert validity period. Must be an integer between 1 and 120.
|
|
|
|
Falling back to default validity (120 months).
|
|
|
|
EOF
|
|
|
|
VPN_CLIENT_VALIDITY=""
|
|
|
|
client_validity=120
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
client_validity=120
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2022-02-15 08:45:13 +03:00
|
|
|
set_server_address() {
|
|
|
|
if [ -n "$VPN_DNS_NAME" ]; then
|
|
|
|
use_dns_name=1
|
|
|
|
server_addr="$VPN_DNS_NAME"
|
|
|
|
else
|
|
|
|
use_dns_name=0
|
|
|
|
get_server_ip
|
|
|
|
check_ip "$public_ip" || exiterr "Cannot detect this server's public IP."
|
|
|
|
server_addr="$public_ip"
|
|
|
|
fi
|
|
|
|
check_cert_exists_and_exit "$server_addr"
|
|
|
|
}
|
|
|
|
|
|
|
|
set_dns_servers() {
|
|
|
|
if [ -n "$VPN_DNS_SRV1" ] && [ -n "$VPN_DNS_SRV2" ]; then
|
|
|
|
dns_server_1="$VPN_DNS_SRV1"
|
|
|
|
dns_server_2="$VPN_DNS_SRV2"
|
|
|
|
dns_servers="$VPN_DNS_SRV1 $VPN_DNS_SRV2"
|
|
|
|
elif [ -n "$VPN_DNS_SRV1" ]; then
|
|
|
|
dns_server_1="$VPN_DNS_SRV1"
|
|
|
|
dns_server_2=""
|
|
|
|
dns_servers="$VPN_DNS_SRV1"
|
|
|
|
else
|
|
|
|
dns_server_1=8.8.8.8
|
|
|
|
dns_server_2=8.8.4.4
|
|
|
|
dns_servers="8.8.8.8 8.8.4.4"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2021-04-18 22:27:52 +03:00
|
|
|
show_welcome() {
|
2021-01-18 09:01:46 +03:00
|
|
|
cat <<'EOF'
|
2022-02-18 06:36:19 +03:00
|
|
|
Welcome! Use this script to set up IKEv2 on your VPN server.
|
2022-03-19 05:52:20 +03:00
|
|
|
|
2021-01-18 09:01:46 +03:00
|
|
|
I need to ask you a few questions before starting setup.
|
|
|
|
You can use the default options and just press enter if you are OK with them.
|
2021-01-11 03:28:52 +03:00
|
|
|
|
2021-01-18 09:01:46 +03:00
|
|
|
EOF
|
|
|
|
}
|
|
|
|
|
2021-04-18 22:27:52 +03:00
|
|
|
show_start_setup() {
|
2022-02-18 06:36:19 +03:00
|
|
|
op_text=default
|
|
|
|
if [ -n "$VPN_DNS_NAME" ] || [ -n "$VPN_CLIENT_NAME" ] \
|
2022-10-16 08:45:45 +03:00
|
|
|
|| [ -n "$VPN_DNS_SRV1" ] || [ -n "$VPN_PROTECT_CONFIG" ] \
|
|
|
|
|| [ -n "$VPN_CLIENT_VALIDITY" ]; then
|
2022-02-18 06:36:19 +03:00
|
|
|
op_text=custom
|
2021-04-11 21:53:38 +03:00
|
|
|
fi
|
2022-02-18 06:36:19 +03:00
|
|
|
bigecho "Starting IKEv2 setup in auto mode, using $op_text options."
|
2021-01-18 09:01:46 +03:00
|
|
|
}
|
|
|
|
|
2021-04-18 22:27:52 +03:00
|
|
|
show_add_client() {
|
2022-10-16 08:45:45 +03:00
|
|
|
op_text=default
|
|
|
|
if [ -n "$VPN_CLIENT_VALIDITY" ]; then
|
|
|
|
op_text=custom
|
|
|
|
fi
|
|
|
|
bigecho "Adding a new IKEv2 client '$client_name', using $op_text options."
|
2021-01-24 22:53:55 +03:00
|
|
|
}
|
|
|
|
|
2021-04-18 22:27:52 +03:00
|
|
|
show_export_client() {
|
2022-02-21 06:45:11 +03:00
|
|
|
bigecho "Exporting IKEv2 client '$client_name'."
|
2021-01-24 22:53:55 +03:00
|
|
|
}
|
|
|
|
|
2021-01-30 23:24:01 +03:00
|
|
|
get_export_dir() {
|
|
|
|
export_to_home_dir=0
|
|
|
|
if grep -qs "hwdsl2" /opt/src/run.sh; then
|
|
|
|
export_dir="/etc/ipsec.d/"
|
|
|
|
else
|
|
|
|
export_dir=~/
|
|
|
|
if [ -n "$SUDO_USER" ] && getent group "$SUDO_USER" >/dev/null 2>&1; then
|
|
|
|
user_home_dir=$(getent passwd "$SUDO_USER" 2>/dev/null | cut -d: -f6)
|
|
|
|
if [ -d "$user_home_dir" ] && [ "$user_home_dir" != "/" ]; then
|
|
|
|
export_dir="$user_home_dir/"
|
|
|
|
export_to_home_dir=1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2022-09-24 08:58:16 +03:00
|
|
|
get_default_ip() {
|
|
|
|
def_ip=$(ip -4 route get 1 | sed 's/ uid .*//' | awk '{print $NF;exit}' 2>/dev/null)
|
|
|
|
if check_ip "$def_ip" \
|
|
|
|
&& ! printf '%s' "$def_ip" | grep -Eq '^(10|127|172\.(1[6-9]|2[0-9]|3[0-1])|192\.168|169\.254)\.'; then
|
|
|
|
public_ip="$def_ip"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2021-01-18 09:01:46 +03:00
|
|
|
get_server_ip() {
|
2022-09-25 02:56:27 +03:00
|
|
|
use_default_ip=0
|
2021-05-11 17:59:29 +03:00
|
|
|
public_ip=${VPN_PUBLIC_IP:-''}
|
2022-09-24 08:58:16 +03:00
|
|
|
check_ip "$public_ip" || get_default_ip
|
2022-09-25 02:56:27 +03:00
|
|
|
check_ip "$public_ip" && { use_default_ip=1; return 0; }
|
|
|
|
bigecho2 "Trying to auto discover IP of this server..."
|
2021-05-11 17:59:29 +03:00
|
|
|
check_ip "$public_ip" || public_ip=$(dig @resolver1.opendns.com -t A -4 myip.opendns.com +short)
|
2022-09-24 08:58:16 +03:00
|
|
|
check_ip "$public_ip" || public_ip=$(wget -t 2 -T 10 -qO- http://ipv4.icanhazip.com)
|
|
|
|
check_ip "$public_ip" || public_ip=$(wget -t 2 -T 10 -qO- http://ip1.dynupdate.no-ip.com)
|
2021-01-18 09:01:46 +03:00
|
|
|
}
|
|
|
|
|
2021-01-19 06:51:31 +03:00
|
|
|
get_server_address() {
|
2022-02-15 08:45:13 +03:00
|
|
|
server_addr=$(grep -s "leftcert=" "$IKEV2_CONF" | cut -f2 -d=)
|
|
|
|
[ -z "$server_addr" ] && server_addr=$(grep -s "leftcert=" "$IPSEC_CONF" | cut -f2 -d=)
|
2021-01-19 06:51:31 +03:00
|
|
|
check_ip "$server_addr" || check_dns_name "$server_addr" || exiterr "Could not get VPN server address."
|
|
|
|
}
|
|
|
|
|
2021-01-25 00:08:06 +03:00
|
|
|
list_existing_clients() {
|
|
|
|
echo "Checking for existing IKEv2 client(s)..."
|
2021-11-07 08:13:42 +03:00
|
|
|
echo
|
2022-02-15 08:45:13 +03:00
|
|
|
client_names=$(certutil -L -d "$CERT_DB" | grep -v -e '^$' -e "$CA_NAME" -e '\.' | tail -n +3 | cut -f1 -d ' ')
|
2021-11-07 08:13:42 +03:00
|
|
|
max_len=$(printf '%s\n' "$client_names" | wc -L 2>/dev/null)
|
|
|
|
[[ $max_len =~ ^[0-9]+$ ]] || max_len=64
|
|
|
|
[ "$max_len" -gt "64" ] && max_len=64
|
|
|
|
[ "$max_len" -lt "16" ] && max_len=16
|
|
|
|
printf "%-${max_len}s %s\n" 'Client Name' 'Certificate Status'
|
|
|
|
printf "%-${max_len}s %s\n" '------------' '-------------------'
|
2022-04-07 06:49:20 +03:00
|
|
|
if [ -n "$client_names" ]; then
|
2022-10-19 08:31:52 +03:00
|
|
|
client_list=$(printf '%s\n' "$client_names" | LC_ALL=C sort)
|
|
|
|
while IFS= read -r line; do
|
2022-04-07 06:49:20 +03:00
|
|
|
printf "%-${max_len}s " "$line"
|
|
|
|
client_status=$(certutil -V -u C -d "$CERT_DB" -n "$line" | grep -o -e ' valid' -e expired -e revoked | sed -e 's/^ //')
|
|
|
|
[ -z "$client_status" ] && client_status=unknown
|
|
|
|
printf '%s\n' "$client_status"
|
2022-10-19 08:31:52 +03:00
|
|
|
done <<< "$client_list"
|
2022-04-07 06:49:20 +03:00
|
|
|
fi
|
2022-04-06 07:38:43 +03:00
|
|
|
client_count=$(printf '%s\n' "$client_names" | wc -l 2>/dev/null)
|
2022-04-07 06:49:20 +03:00
|
|
|
[ -z "$client_names" ] && client_count=0
|
2022-09-25 02:56:27 +03:00
|
|
|
if [ "$client_count" = 1 ]; then
|
2022-04-06 07:38:43 +03:00
|
|
|
printf '\n%s\n' "Total: 1 client"
|
|
|
|
elif [ -n "$client_count" ]; then
|
|
|
|
printf '\n%s\n' "Total: $client_count clients"
|
|
|
|
fi
|
2021-01-25 00:08:06 +03:00
|
|
|
}
|
|
|
|
|
2021-01-18 09:01:46 +03:00
|
|
|
enter_server_address() {
|
2022-03-20 08:14:25 +03:00
|
|
|
echo "Do you want IKEv2 clients to connect to this server using a DNS name,"
|
2021-01-18 09:01:46 +03:00
|
|
|
printf "e.g. vpn.example.com, instead of its IP address? [y/N] "
|
2020-06-05 08:29:15 +03:00
|
|
|
read -r response
|
|
|
|
case $response in
|
|
|
|
[yY][eE][sS]|[yY])
|
2021-01-18 09:01:46 +03:00
|
|
|
use_dns_name=1
|
2020-06-05 08:29:15 +03:00
|
|
|
echo
|
|
|
|
;;
|
|
|
|
*)
|
2021-01-18 09:01:46 +03:00
|
|
|
use_dns_name=0
|
|
|
|
echo
|
2020-06-05 08:29:15 +03:00
|
|
|
;;
|
|
|
|
esac
|
2022-09-25 02:56:27 +03:00
|
|
|
if [ "$use_dns_name" = 1 ]; then
|
2021-01-18 09:01:46 +03:00
|
|
|
read -rp "Enter the DNS name of this VPN server: " server_addr
|
|
|
|
until check_dns_name "$server_addr"; do
|
|
|
|
echo "Invalid DNS name. You must enter a fully qualified domain name (FQDN)."
|
|
|
|
read -rp "Enter the DNS name of this VPN server: " server_addr
|
|
|
|
done
|
|
|
|
else
|
|
|
|
get_server_ip
|
2022-09-25 02:56:27 +03:00
|
|
|
[ "$use_default_ip" = 0 ] && { echo; echo; }
|
2021-01-18 09:01:46 +03:00
|
|
|
read -rp "Enter the IPv4 address of this VPN server: [$public_ip] " server_addr
|
|
|
|
[ -z "$server_addr" ] && server_addr="$public_ip"
|
|
|
|
until check_ip "$server_addr"; do
|
|
|
|
echo "Invalid IP address."
|
|
|
|
read -rp "Enter the IPv4 address of this VPN server: [$public_ip] " server_addr
|
|
|
|
[ -z "$server_addr" ] && server_addr="$public_ip"
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
enter_client_name() {
|
2021-01-19 06:51:31 +03:00
|
|
|
echo
|
2022-03-20 08:14:25 +03:00
|
|
|
echo "Provide a name for the IKEv2 client."
|
2020-06-05 18:56:33 +03:00
|
|
|
echo "Use one word only, no special characters except '-' and '_'."
|
2022-02-15 08:45:13 +03:00
|
|
|
if [ "$1" = "with_defaults" ]; then
|
|
|
|
read -rp "Client name: [vpnclient] " client_name
|
|
|
|
[ -z "$client_name" ] && client_name=vpnclient
|
|
|
|
else
|
|
|
|
read -rp "Client name: " client_name
|
|
|
|
[ -z "$client_name" ] && abort_and_exit
|
|
|
|
fi
|
2021-08-01 07:36:43 +03:00
|
|
|
while ! check_client_name "$client_name" || check_cert_exists "$client_name"; do
|
|
|
|
if ! check_client_name "$client_name"; then
|
2020-06-05 18:56:33 +03:00
|
|
|
echo "Invalid client name."
|
|
|
|
else
|
2020-12-31 07:53:19 +03:00
|
|
|
echo "Invalid client name. Client '$client_name' already exists."
|
2020-06-05 18:56:33 +03:00
|
|
|
fi
|
2022-02-15 08:45:13 +03:00
|
|
|
if [ "$1" = "with_defaults" ]; then
|
|
|
|
read -rp "Client name: [vpnclient] " client_name
|
|
|
|
[ -z "$client_name" ] && client_name=vpnclient
|
|
|
|
else
|
|
|
|
read -rp "Client name: " client_name
|
|
|
|
[ -z "$client_name" ] && abort_and_exit
|
|
|
|
fi
|
2021-01-18 09:01:46 +03:00
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2021-06-01 10:30:51 +03:00
|
|
|
enter_client_name_for() {
|
2021-01-19 06:51:31 +03:00
|
|
|
echo
|
2021-01-25 00:08:06 +03:00
|
|
|
list_existing_clients
|
2022-09-25 02:56:27 +03:00
|
|
|
if [ "$client_count" = 0 ]; then
|
2022-04-07 06:49:20 +03:00
|
|
|
echo
|
|
|
|
echo "No IKEv2 clients in the IPsec database. Nothing to $1." >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
2021-01-19 06:51:31 +03:00
|
|
|
get_server_address
|
|
|
|
echo
|
2021-06-01 10:30:51 +03:00
|
|
|
read -rp "Enter the name of the IKEv2 client to $1: " client_name
|
2021-08-01 07:36:43 +03:00
|
|
|
[ -z "$client_name" ] && abort_and_exit
|
2022-02-15 08:45:13 +03:00
|
|
|
while ! check_client_name "$client_name" || [ "$client_name" = "$CA_NAME" ] \
|
2021-08-01 07:36:43 +03:00
|
|
|
|| [ "$client_name" = "$server_addr" ] || ! check_cert_exists "$client_name" \
|
|
|
|
|| ! check_cert_status "$client_name"; do
|
2022-02-15 08:45:13 +03:00
|
|
|
if ! check_client_name "$client_name" || [ "$client_name" = "$CA_NAME" ] \
|
2021-08-01 07:36:43 +03:00
|
|
|
|| [ "$client_name" = "$server_addr" ] || ! check_cert_exists "$client_name"; then
|
2021-06-01 10:30:51 +03:00
|
|
|
echo "Invalid client name, or client does not exist."
|
|
|
|
else
|
2022-04-07 06:49:20 +03:00
|
|
|
[ "$1" = "delete" ] && break
|
2021-06-01 10:30:51 +03:00
|
|
|
printf '%s' "Error: Certificate '$client_name' "
|
|
|
|
if printf '%s' "$cert_status" | grep -q "revoked"; then
|
|
|
|
if [ "$1" = "revoke" ]; then
|
|
|
|
echo "has already been revoked."
|
|
|
|
else
|
|
|
|
echo "has been revoked."
|
|
|
|
fi
|
|
|
|
elif printf '%s' "$cert_status" | grep -q "expired"; then
|
|
|
|
echo "has expired."
|
|
|
|
else
|
|
|
|
echo "is invalid."
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
read -rp "Enter the name of the IKEv2 client to $1: " client_name
|
2021-08-01 07:36:43 +03:00
|
|
|
[ -z "$client_name" ] && abort_and_exit
|
2021-01-19 06:51:31 +03:00
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2022-02-15 08:45:13 +03:00
|
|
|
enter_client_validity() {
|
2020-07-02 19:48:35 +03:00
|
|
|
echo
|
2021-06-01 10:30:51 +03:00
|
|
|
echo "Specify the validity period (in months) for this client certificate."
|
2022-10-16 08:45:45 +03:00
|
|
|
read -rp "Enter an integer between 1 and 120: [120] " client_validity
|
2020-07-02 19:48:35 +03:00
|
|
|
[ -z "$client_validity" ] && client_validity=120
|
2022-10-16 08:45:45 +03:00
|
|
|
while ! check_client_validity "$client_validity"; do
|
2020-07-02 19:48:35 +03:00
|
|
|
echo "Invalid validity period."
|
2022-10-16 08:45:45 +03:00
|
|
|
read -rp "Enter an integer between 1 and 120: [120] " client_validity
|
2020-07-02 19:48:35 +03:00
|
|
|
[ -z "$client_validity" ] && client_validity=120
|
|
|
|
done
|
2021-01-18 09:01:46 +03:00
|
|
|
}
|
2020-07-02 19:48:35 +03:00
|
|
|
|
2021-01-18 09:01:46 +03:00
|
|
|
enter_custom_dns() {
|
|
|
|
echo
|
|
|
|
echo "By default, clients are set to use Google Public DNS when the VPN is active."
|
|
|
|
printf "Do you want to specify custom DNS servers for IKEv2? [y/N] "
|
2021-01-16 08:26:25 +03:00
|
|
|
read -r response
|
|
|
|
case $response in
|
|
|
|
[yY][eE][sS]|[yY])
|
2021-01-18 09:01:46 +03:00
|
|
|
use_custom_dns=1
|
2021-01-16 08:26:25 +03:00
|
|
|
;;
|
|
|
|
*)
|
2021-01-18 09:01:46 +03:00
|
|
|
use_custom_dns=0
|
|
|
|
dns_server_1=8.8.8.8
|
|
|
|
dns_server_2=8.8.4.4
|
|
|
|
dns_servers="8.8.8.8 8.8.4.4"
|
2021-01-16 08:26:25 +03:00
|
|
|
;;
|
|
|
|
esac
|
2022-09-25 02:56:27 +03:00
|
|
|
if [ "$use_custom_dns" = 1 ]; then
|
2021-01-18 09:01:46 +03:00
|
|
|
read -rp "Enter primary DNS server: " dns_server_1
|
|
|
|
until check_ip "$dns_server_1"; do
|
|
|
|
echo "Invalid DNS server."
|
|
|
|
read -rp "Enter primary DNS server: " dns_server_1
|
|
|
|
done
|
2022-02-18 06:36:19 +03:00
|
|
|
read -rp "Enter secondary DNS server (Enter to skip): " dns_server_2
|
2021-01-18 09:01:46 +03:00
|
|
|
until [ -z "$dns_server_2" ] || check_ip "$dns_server_2"; do
|
|
|
|
echo "Invalid DNS server."
|
2022-02-18 06:36:19 +03:00
|
|
|
read -rp "Enter secondary DNS server (Enter to skip): " dns_server_2
|
2021-01-18 09:01:46 +03:00
|
|
|
done
|
|
|
|
if [ -n "$dns_server_2" ]; then
|
|
|
|
dns_servers="$dns_server_1 $dns_server_2"
|
|
|
|
else
|
|
|
|
dns_servers="$dns_server_1"
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
echo "Using Google Public DNS (8.8.8.8, 8.8.4.4)."
|
|
|
|
fi
|
2021-02-06 06:49:35 +03:00
|
|
|
echo
|
2021-01-18 09:01:46 +03:00
|
|
|
}
|
2020-06-05 08:29:15 +03:00
|
|
|
|
2021-01-18 09:01:46 +03:00
|
|
|
check_mobike_support() {
|
2021-03-20 07:58:06 +03:00
|
|
|
mobike_support=1
|
2021-01-18 09:01:46 +03:00
|
|
|
if uname -m | grep -qi -e '^arm' -e '^aarch64'; then
|
|
|
|
modprobe -q configs
|
|
|
|
if [ -f /proc/config.gz ]; then
|
|
|
|
if ! zcat /proc/config.gz | grep -q "CONFIG_XFRM_MIGRATE=y"; then
|
|
|
|
mobike_support=0
|
|
|
|
fi
|
2021-01-24 01:02:59 +03:00
|
|
|
else
|
|
|
|
mobike_support=0
|
2021-01-18 09:01:46 +03:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
kernel_conf="/boot/config-$(uname -r)"
|
|
|
|
if [ -f "$kernel_conf" ]; then
|
|
|
|
if ! grep -qs "CONFIG_XFRM_MIGRATE=y" "$kernel_conf"; then
|
|
|
|
mobike_support=0
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
# Linux kernels on Ubuntu do not support MOBIKE
|
2022-09-25 02:56:27 +03:00
|
|
|
if [ "$in_container" = 0 ]; then
|
2021-01-18 09:01:46 +03:00
|
|
|
if [ "$os_type" = "ubuntu" ] || uname -v | grep -qi ubuntu; then
|
|
|
|
mobike_support=0
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
if uname -v | grep -qi ubuntu; then
|
|
|
|
mobike_support=0
|
|
|
|
fi
|
|
|
|
fi
|
2021-07-26 04:55:40 +03:00
|
|
|
if uname -a | grep -qi qnap; then
|
|
|
|
mobike_support=0
|
|
|
|
fi
|
2022-06-18 09:27:17 +03:00
|
|
|
if uname -a | grep -qi synology; then
|
|
|
|
mobike_support=0
|
|
|
|
fi
|
2022-09-25 02:56:27 +03:00
|
|
|
if [ "$mobike_support" = 1 ]; then
|
2021-03-31 07:47:59 +03:00
|
|
|
bigecho2 "Checking for MOBIKE support... available"
|
2021-01-18 09:01:46 +03:00
|
|
|
else
|
2021-03-31 07:47:59 +03:00
|
|
|
bigecho2 "Checking for MOBIKE support... not available"
|
2021-01-18 09:01:46 +03:00
|
|
|
fi
|
|
|
|
}
|
2021-01-15 08:21:52 +03:00
|
|
|
|
2021-01-18 09:01:46 +03:00
|
|
|
select_mobike() {
|
2021-03-31 07:47:59 +03:00
|
|
|
echo
|
2021-01-18 09:01:46 +03:00
|
|
|
mobike_enable=0
|
2022-09-25 02:56:27 +03:00
|
|
|
if [ "$mobike_support" = 1 ]; then
|
2021-09-20 05:51:14 +03:00
|
|
|
cat <<'EOF'
|
|
|
|
|
|
|
|
The MOBIKE IKEv2 extension allows VPN clients to change network attachment points,
|
|
|
|
e.g. switch between mobile data and Wi-Fi and keep the IPsec tunnel up on the new IP.
|
|
|
|
|
|
|
|
EOF
|
2022-02-12 21:12:51 +03:00
|
|
|
printf "Enable MOBIKE support? [Y/n] "
|
2021-01-18 09:01:46 +03:00
|
|
|
read -r response
|
|
|
|
case $response in
|
|
|
|
[yY][eE][sS]|[yY]|'')
|
|
|
|
mobike_enable=1
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
mobike_enable=0
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
fi
|
|
|
|
}
|
2021-01-16 08:26:25 +03:00
|
|
|
|
2022-02-14 12:46:06 +03:00
|
|
|
check_config_password() {
|
2022-02-16 06:15:08 +03:00
|
|
|
use_config_password=0
|
|
|
|
case $VPN_PROTECT_CONFIG in
|
|
|
|
[yY][eE][sS])
|
|
|
|
use_config_password=1
|
|
|
|
;;
|
|
|
|
*)
|
2022-02-16 06:17:47 +03:00
|
|
|
if grep -qs '^IKEV2_CONFIG_PASSWORD=.\+' "$CONF_FILE"; then
|
2022-02-16 06:15:08 +03:00
|
|
|
use_config_password=1
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
esac
|
2022-02-14 12:46:06 +03:00
|
|
|
}
|
|
|
|
|
2022-02-12 21:12:51 +03:00
|
|
|
select_config_password() {
|
2022-09-25 02:56:27 +03:00
|
|
|
if [ "$use_config_password" = 0 ]; then
|
2022-02-12 21:12:51 +03:00
|
|
|
cat <<'EOF'
|
|
|
|
|
2022-02-21 06:45:11 +03:00
|
|
|
IKEv2 client config files contain the client certificate, private key and CA certificate.
|
2022-02-12 21:12:51 +03:00
|
|
|
This script can optionally generate a random password to protect these files.
|
|
|
|
|
|
|
|
EOF
|
2022-02-14 12:46:06 +03:00
|
|
|
printf "Protect client config files using a password? [y/N] "
|
|
|
|
read -r response
|
|
|
|
case $response in
|
|
|
|
[yY][eE][sS]|[yY])
|
|
|
|
use_config_password=1
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
use_config_password=0
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
fi
|
2022-02-12 21:12:51 +03:00
|
|
|
}
|
|
|
|
|
2021-01-19 06:51:31 +03:00
|
|
|
select_menu_option() {
|
2021-09-20 05:51:14 +03:00
|
|
|
cat <<'EOF'
|
|
|
|
IKEv2 is already set up on this server.
|
|
|
|
|
|
|
|
Select an option:
|
|
|
|
1) Add a new client
|
2022-09-10 07:03:07 +03:00
|
|
|
2) Export config for an existing client
|
2021-09-20 05:51:14 +03:00
|
|
|
3) List existing clients
|
2022-09-10 07:03:07 +03:00
|
|
|
4) Revoke an existing client
|
|
|
|
5) Delete an existing client
|
2022-04-07 06:49:20 +03:00
|
|
|
6) Remove IKEv2
|
|
|
|
7) Exit
|
2021-09-20 05:51:14 +03:00
|
|
|
EOF
|
2021-01-19 06:51:31 +03:00
|
|
|
read -rp "Option: " selected_option
|
2022-04-07 06:49:20 +03:00
|
|
|
until [[ "$selected_option" =~ ^[1-7]$ ]]; do
|
2021-01-19 06:51:31 +03:00
|
|
|
printf '%s\n' "$selected_option: invalid selection."
|
|
|
|
read -rp "Option: " selected_option
|
|
|
|
done
|
2021-01-18 09:01:46 +03:00
|
|
|
}
|
2020-06-11 09:16:51 +03:00
|
|
|
|
2022-10-19 08:31:52 +03:00
|
|
|
print_server_info() {
|
2021-07-31 23:31:13 +03:00
|
|
|
cat <<EOF
|
|
|
|
VPN server address: $server_addr
|
|
|
|
|
|
|
|
EOF
|
|
|
|
}
|
|
|
|
|
2021-01-18 09:01:46 +03:00
|
|
|
confirm_setup_options() {
|
|
|
|
cat <<EOF
|
2021-07-14 06:09:25 +03:00
|
|
|
|
2021-03-31 07:47:59 +03:00
|
|
|
We are ready to set up IKEv2 now. Below are the setup options you selected.
|
2020-05-11 09:18:34 +03:00
|
|
|
|
2021-02-05 08:41:48 +03:00
|
|
|
======================================
|
2021-01-18 09:01:46 +03:00
|
|
|
|
2022-10-19 08:31:52 +03:00
|
|
|
Server address: $server_addr
|
|
|
|
Client name: $client_name
|
|
|
|
|
2020-05-11 09:18:34 +03:00
|
|
|
EOF
|
2022-09-25 02:56:27 +03:00
|
|
|
if [ "$client_validity" = 1 ]; then
|
2021-01-18 09:01:46 +03:00
|
|
|
echo "Client cert valid for: 1 month"
|
|
|
|
else
|
|
|
|
echo "Client cert valid for: $client_validity months"
|
|
|
|
fi
|
2022-09-25 02:56:27 +03:00
|
|
|
if [ "$mobike_support" = 1 ]; then
|
|
|
|
if [ "$mobike_enable" = 1 ]; then
|
2021-01-18 09:01:46 +03:00
|
|
|
echo "MOBIKE support: Enable"
|
2020-12-31 07:53:19 +03:00
|
|
|
else
|
2021-01-18 09:01:46 +03:00
|
|
|
echo "MOBIKE support: Disable"
|
2020-12-31 07:53:19 +03:00
|
|
|
fi
|
2020-07-13 01:14:30 +03:00
|
|
|
else
|
2021-01-18 09:01:46 +03:00
|
|
|
echo "MOBIKE support: Not available"
|
2020-05-11 09:18:34 +03:00
|
|
|
fi
|
2022-09-25 02:56:27 +03:00
|
|
|
if [ "$use_config_password" = 1 ]; then
|
2022-02-18 06:36:19 +03:00
|
|
|
echo "Protect client config: Yes"
|
|
|
|
else
|
|
|
|
echo "Protect client config: No"
|
|
|
|
fi
|
2021-01-18 09:01:46 +03:00
|
|
|
cat <<EOF
|
|
|
|
DNS server(s): $dns_servers
|
2021-01-13 10:39:41 +03:00
|
|
|
|
2021-02-05 08:41:48 +03:00
|
|
|
======================================
|
2021-01-13 10:39:41 +03:00
|
|
|
|
2021-01-18 09:01:46 +03:00
|
|
|
EOF
|
2022-02-12 21:12:51 +03:00
|
|
|
printf "Do you want to continue? [Y/n] "
|
|
|
|
read -r response
|
|
|
|
case $response in
|
|
|
|
[yY][eE][sS]|[yY]|'')
|
|
|
|
echo
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
abort_and_exit
|
|
|
|
;;
|
|
|
|
esac
|
2021-01-18 09:01:46 +03:00
|
|
|
}
|
2020-05-11 09:18:34 +03:00
|
|
|
|
2021-01-18 09:01:46 +03:00
|
|
|
create_client_cert() {
|
2021-03-31 07:47:59 +03:00
|
|
|
bigecho2 "Generating client certificate..."
|
2021-05-01 22:46:12 +03:00
|
|
|
sleep 1
|
2021-01-18 09:01:46 +03:00
|
|
|
certutil -z <(head -c 1024 /dev/urandom) \
|
2022-02-15 08:45:13 +03:00
|
|
|
-S -c "$CA_NAME" -n "$client_name" \
|
2021-01-18 09:01:46 +03:00
|
|
|
-s "O=IKEv2 VPN,CN=$client_name" \
|
2021-05-01 22:46:12 +03:00
|
|
|
-k rsa -g 3072 -v "$client_validity" \
|
2022-02-15 08:45:13 +03:00
|
|
|
-d "$CERT_DB" -t ",," \
|
2021-01-18 09:01:46 +03:00
|
|
|
--keyUsage digitalSignature,keyEncipherment \
|
2021-02-05 08:41:48 +03:00
|
|
|
--extKeyUsage serverAuth,clientAuth -8 "$client_name" >/dev/null 2>&1 || exiterr "Failed to create client certificate."
|
2021-01-18 09:01:46 +03:00
|
|
|
}
|
2021-01-16 08:26:25 +03:00
|
|
|
|
2021-07-24 23:58:48 +03:00
|
|
|
create_p12_password() {
|
2022-02-13 01:16:46 +03:00
|
|
|
p12_password=$(LC_CTYPE=C tr -dc 'A-HJ-NPR-Za-km-z2-9' </dev/urandom 2>/dev/null | head -c 18)
|
|
|
|
[ -z "$p12_password" ] && exiterr "Could not generate a random password for .p12 file."
|
|
|
|
}
|
|
|
|
|
|
|
|
get_p12_password() {
|
2022-09-25 02:56:27 +03:00
|
|
|
if [ "$use_config_password" = 0 ]; then
|
2022-02-13 01:16:46 +03:00
|
|
|
create_p12_password
|
|
|
|
else
|
2022-02-16 06:17:47 +03:00
|
|
|
p12_password=$(grep -s '^IKEV2_CONFIG_PASSWORD=.\+' "$CONF_FILE" | tail -n 1 | cut -f2- -d= | sed -e "s/^'//" -e "s/'$//")
|
2022-02-13 01:16:46 +03:00
|
|
|
if [ -z "$p12_password" ]; then
|
|
|
|
create_p12_password
|
2022-02-16 06:17:47 +03:00
|
|
|
if [ -n "$CONF_FILE" ] && [ -n "$CONF_DIR" ]; then
|
|
|
|
mkdir -p "$CONF_DIR"
|
|
|
|
printf '%s\n' "IKEV2_CONFIG_PASSWORD='$p12_password'" >> "$CONF_FILE"
|
|
|
|
chmod 600 "$CONF_FILE"
|
2022-02-15 08:45:13 +03:00
|
|
|
fi
|
2022-02-13 01:16:46 +03:00
|
|
|
fi
|
2021-07-24 23:58:48 +03:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2021-01-18 09:01:46 +03:00
|
|
|
export_p12_file() {
|
2021-03-31 07:47:59 +03:00
|
|
|
bigecho2 "Creating client configuration..."
|
2022-02-13 01:16:46 +03:00
|
|
|
get_p12_password
|
2021-02-04 06:35:56 +03:00
|
|
|
p12_file="$export_dir$client_name.p12"
|
2022-02-12 10:21:12 +03:00
|
|
|
p12_file_enc="$export_dir$client_name.enc.p12"
|
2022-02-15 08:45:13 +03:00
|
|
|
pk12util -W "$p12_password" -d "$CERT_DB" -n "$client_name" -o "$p12_file_enc" >/dev/null || exit 1
|
2022-08-11 07:25:58 +03:00
|
|
|
if [ "$os_ver" = "bookwormsid" ] || openssl version 2>/dev/null | grep -q "^OpenSSL 3"; then
|
2022-03-20 10:49:09 +03:00
|
|
|
ca_crt="$export_dir$client_name.ca.crt"
|
|
|
|
client_crt="$export_dir$client_name.client.crt"
|
|
|
|
client_key="$export_dir$client_name.client.key"
|
|
|
|
pem_file="$export_dir$client_name.temp.pem"
|
|
|
|
openssl pkcs12 -in "$p12_file_enc" -passin "pass:$p12_password" -cacerts -nokeys -out "$ca_crt" || exit 1
|
|
|
|
openssl pkcs12 -in "$p12_file_enc" -passin "pass:$p12_password" -clcerts -nokeys -out "$client_crt" || exit 1
|
2022-03-20 18:06:25 +03:00
|
|
|
openssl pkcs12 -in "$p12_file_enc" -passin "pass:$p12_password" -passout "pass:$p12_password" \
|
|
|
|
-nocerts -out "$client_key" || exit 1
|
2022-03-20 10:49:09 +03:00
|
|
|
cat "$client_key" "$client_crt" "$ca_crt" > "$pem_file"
|
2022-03-20 18:06:25 +03:00
|
|
|
/bin/rm -f "$client_key" "$client_crt" "$ca_crt"
|
2022-03-20 10:49:09 +03:00
|
|
|
openssl pkcs12 -keypbe PBE-SHA1-3DES -certpbe PBE-SHA1-3DES -export -in "$pem_file" -out "$p12_file_enc" \
|
|
|
|
-legacy -name "$client_name" -passin "pass:$p12_password" -passout "pass:$p12_password" || exit 1
|
2022-09-25 02:56:27 +03:00
|
|
|
if [ "$use_config_password" = 0 ]; then
|
2022-03-20 10:49:09 +03:00
|
|
|
openssl pkcs12 -keypbe PBE-SHA1-3DES -certpbe PBE-SHA1-3DES -export -in "$pem_file" -out "$p12_file" \
|
|
|
|
-legacy -name "$client_name" -passin "pass:$p12_password" -passout pass: || exit 1
|
2022-08-11 07:25:58 +03:00
|
|
|
fi
|
|
|
|
/bin/rm -f "$pem_file"
|
|
|
|
elif [ "$os_type" = "alpine" ] || [ "$os_ver" = "kalirolling" ] || [ "$os_type$os_ver" = "ubuntu11" ]; then
|
|
|
|
pem_file="$export_dir$client_name.temp.pem"
|
|
|
|
openssl pkcs12 -in "$p12_file_enc" -out "$pem_file" -passin "pass:$p12_password" -passout "pass:$p12_password" || exit 1
|
|
|
|
openssl pkcs12 -keypbe PBE-SHA1-3DES -certpbe PBE-SHA1-3DES -export -in "$pem_file" -out "$p12_file_enc" \
|
|
|
|
-name "$client_name" -passin "pass:$p12_password" -passout "pass:$p12_password" || exit 1
|
2022-09-25 02:56:27 +03:00
|
|
|
if [ "$use_config_password" = 0 ]; then
|
2022-08-11 07:25:58 +03:00
|
|
|
openssl pkcs12 -keypbe PBE-SHA1-3DES -certpbe PBE-SHA1-3DES -export -in "$pem_file" -out "$p12_file" \
|
|
|
|
-name "$client_name" -passin "pass:$p12_password" -passout pass: || exit 1
|
2022-03-20 10:49:09 +03:00
|
|
|
fi
|
2022-03-20 18:06:25 +03:00
|
|
|
/bin/rm -f "$pem_file"
|
2022-09-25 02:56:27 +03:00
|
|
|
elif [ "$use_config_password" = 0 ]; then
|
2022-02-15 08:45:13 +03:00
|
|
|
pk12util -W "" -d "$CERT_DB" -n "$client_name" -o "$p12_file" >/dev/null || exit 1
|
|
|
|
fi
|
2022-09-25 02:56:27 +03:00
|
|
|
if [ "$use_config_password" = 1 ]; then
|
2022-02-15 08:45:13 +03:00
|
|
|
/bin/cp -f "$p12_file_enc" "$p12_file"
|
2021-01-30 23:24:01 +03:00
|
|
|
fi
|
2022-09-25 02:56:27 +03:00
|
|
|
if [ "$export_to_home_dir" = 1 ]; then
|
2021-01-30 23:24:01 +03:00
|
|
|
chown "$SUDO_USER:$SUDO_USER" "$p12_file"
|
2021-01-18 09:01:46 +03:00
|
|
|
fi
|
2021-01-30 23:24:01 +03:00
|
|
|
chmod 600 "$p12_file"
|
2021-01-18 09:01:46 +03:00
|
|
|
}
|
2020-05-15 06:41:13 +03:00
|
|
|
|
2021-01-24 01:02:59 +03:00
|
|
|
install_base64_uuidgen() {
|
2021-01-18 09:01:46 +03:00
|
|
|
if ! command -v base64 >/dev/null 2>&1 || ! command -v uuidgen >/dev/null 2>&1; then
|
2021-03-31 07:47:59 +03:00
|
|
|
bigecho2 "Installing required packages..."
|
2021-01-18 09:01:46 +03:00
|
|
|
if [ "$os_type" = "ubuntu" ] || [ "$os_type" = "debian" ] || [ "$os_type" = "raspbian" ]; then
|
|
|
|
export DEBIAN_FRONTEND=noninteractive
|
2022-02-09 08:24:46 +03:00
|
|
|
apt-get -yqq update || apt-get -yqq update || exiterr "'apt-get update' failed."
|
2021-02-06 06:49:35 +03:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
if ! command -v base64 >/dev/null 2>&1; then
|
|
|
|
if [ "$os_type" = "ubuntu" ] || [ "$os_type" = "debian" ] || [ "$os_type" = "raspbian" ]; then
|
2021-03-31 07:47:59 +03:00
|
|
|
apt-get -yqq install coreutils >/dev/null || exiterr "'apt-get install' failed."
|
2021-01-18 09:01:46 +03:00
|
|
|
else
|
2021-03-31 07:47:59 +03:00
|
|
|
yum -y -q install coreutils >/dev/null || exiterr "'yum install' failed."
|
2021-02-06 06:49:35 +03:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
if ! command -v uuidgen >/dev/null 2>&1; then
|
|
|
|
if [ "$os_type" = "ubuntu" ] || [ "$os_type" = "debian" ] || [ "$os_type" = "raspbian" ]; then
|
2021-03-31 07:47:59 +03:00
|
|
|
apt-get -yqq install uuid-runtime >/dev/null || exiterr "'apt-get install' failed."
|
2021-02-06 06:49:35 +03:00
|
|
|
else
|
2021-03-31 07:47:59 +03:00
|
|
|
yum -y -q install util-linux >/dev/null || exiterr "'yum install' failed."
|
2021-01-18 09:01:46 +03:00
|
|
|
fi
|
|
|
|
fi
|
2021-01-24 01:02:59 +03:00
|
|
|
}
|
2020-07-02 19:48:35 +03:00
|
|
|
|
2021-09-14 08:24:27 +03:00
|
|
|
install_uuidgen() {
|
|
|
|
if ! command -v uuidgen >/dev/null 2>&1; then
|
|
|
|
bigecho2 "Installing required packages..."
|
|
|
|
apk add -U -q uuidgen || exiterr "'apk add' failed."
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2021-01-24 01:02:59 +03:00
|
|
|
create_mobileconfig() {
|
|
|
|
[ -z "$server_addr" ] && get_server_address
|
2022-02-12 10:21:12 +03:00
|
|
|
p12_file_enc="$export_dir$client_name.enc.p12"
|
|
|
|
p12_base64=$(base64 -w 52 "$p12_file_enc")
|
|
|
|
/bin/rm -f "$p12_file_enc"
|
2021-01-18 09:01:46 +03:00
|
|
|
[ -z "$p12_base64" ] && exiterr "Could not encode .p12 file."
|
2022-02-15 08:45:13 +03:00
|
|
|
ca_base64=$(certutil -L -d "$CERT_DB" -n "$CA_NAME" -a | grep -v CERTIFICATE)
|
|
|
|
[ -z "$ca_base64" ] && exiterr "Could not encode $CA_NAME certificate."
|
2021-01-18 09:01:46 +03:00
|
|
|
uuid1=$(uuidgen)
|
|
|
|
[ -z "$uuid1" ] && exiterr "Could not generate UUID value."
|
2021-02-04 06:35:56 +03:00
|
|
|
mc_file="$export_dir$client_name.mobileconfig"
|
2021-01-18 09:01:46 +03:00
|
|
|
cat > "$mc_file" <<EOF
|
|
|
|
<?xml version="1.0" encoding="UTF-8"?>
|
|
|
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
|
|
<plist version="1.0">
|
|
|
|
<dict>
|
|
|
|
<key>PayloadContent</key>
|
|
|
|
<array>
|
|
|
|
<dict>
|
|
|
|
<key>IKEv2</key>
|
|
|
|
<dict>
|
|
|
|
<key>AuthenticationMethod</key>
|
|
|
|
<string>Certificate</string>
|
|
|
|
<key>ChildSecurityAssociationParameters</key>
|
|
|
|
<dict>
|
|
|
|
<key>DiffieHellmanGroup</key>
|
|
|
|
<integer>14</integer>
|
|
|
|
<key>EncryptionAlgorithm</key>
|
2021-03-06 23:05:24 +03:00
|
|
|
<string>AES-128-GCM</string>
|
2021-01-18 09:01:46 +03:00
|
|
|
<key>LifeTimeInMinutes</key>
|
2021-01-20 10:39:07 +03:00
|
|
|
<integer>1410</integer>
|
2021-01-18 09:01:46 +03:00
|
|
|
</dict>
|
|
|
|
<key>DeadPeerDetectionRate</key>
|
|
|
|
<string>Medium</string>
|
|
|
|
<key>DisableRedirect</key>
|
|
|
|
<true/>
|
|
|
|
<key>EnableCertificateRevocationCheck</key>
|
|
|
|
<integer>0</integer>
|
|
|
|
<key>EnablePFS</key>
|
|
|
|
<integer>0</integer>
|
|
|
|
<key>IKESecurityAssociationParameters</key>
|
|
|
|
<dict>
|
|
|
|
<key>DiffieHellmanGroup</key>
|
|
|
|
<integer>14</integer>
|
|
|
|
<key>EncryptionAlgorithm</key>
|
|
|
|
<string>AES-256</string>
|
|
|
|
<key>IntegrityAlgorithm</key>
|
|
|
|
<string>SHA2-256</string>
|
|
|
|
<key>LifeTimeInMinutes</key>
|
2021-01-20 10:39:07 +03:00
|
|
|
<integer>1410</integer>
|
2021-01-18 09:01:46 +03:00
|
|
|
</dict>
|
|
|
|
<key>LocalIdentifier</key>
|
|
|
|
<string>$client_name</string>
|
|
|
|
<key>PayloadCertificateUUID</key>
|
|
|
|
<string>$uuid1</string>
|
|
|
|
<key>OnDemandEnabled</key>
|
|
|
|
<integer>0</integer>
|
|
|
|
<key>OnDemandRules</key>
|
|
|
|
<array>
|
|
|
|
<dict>
|
2022-10-30 23:45:11 +03:00
|
|
|
<key>InterfaceTypeMatch</key>
|
|
|
|
<string>WiFi</string>
|
|
|
|
<key>URLStringProbe</key>
|
|
|
|
<string>http://captive.apple.com/hotspot-detect.html</string>
|
|
|
|
<key>Action</key>
|
|
|
|
<string>Connect</string>
|
|
|
|
</dict>
|
|
|
|
<dict>
|
|
|
|
<key>InterfaceTypeMatch</key>
|
|
|
|
<string>Cellular</string>
|
|
|
|
<key>Action</key>
|
|
|
|
<string>Disconnect</string>
|
|
|
|
</dict>
|
|
|
|
<dict>
|
|
|
|
<key>Action</key>
|
|
|
|
<string>Ignore</string>
|
2021-01-18 09:01:46 +03:00
|
|
|
</dict>
|
|
|
|
</array>
|
|
|
|
<key>RemoteAddress</key>
|
|
|
|
<string>$server_addr</string>
|
|
|
|
<key>RemoteIdentifier</key>
|
|
|
|
<string>$server_addr</string>
|
|
|
|
<key>UseConfigurationAttributeInternalIPSubnet</key>
|
|
|
|
<integer>0</integer>
|
|
|
|
</dict>
|
|
|
|
<key>IPv4</key>
|
|
|
|
<dict>
|
|
|
|
<key>OverridePrimary</key>
|
|
|
|
<integer>1</integer>
|
|
|
|
</dict>
|
|
|
|
<key>PayloadDescription</key>
|
|
|
|
<string>Configures VPN settings</string>
|
|
|
|
<key>PayloadDisplayName</key>
|
|
|
|
<string>VPN</string>
|
2021-08-22 18:55:57 +03:00
|
|
|
<key>PayloadOrganization</key>
|
|
|
|
<string>IKEv2 VPN</string>
|
2021-01-18 09:01:46 +03:00
|
|
|
<key>PayloadIdentifier</key>
|
|
|
|
<string>com.apple.vpn.managed.$(uuidgen)</string>
|
|
|
|
<key>PayloadType</key>
|
|
|
|
<string>com.apple.vpn.managed</string>
|
|
|
|
<key>PayloadUUID</key>
|
|
|
|
<string>$(uuidgen)</string>
|
|
|
|
<key>PayloadVersion</key>
|
|
|
|
<integer>1</integer>
|
|
|
|
<key>Proxies</key>
|
|
|
|
<dict>
|
|
|
|
<key>HTTPEnable</key>
|
|
|
|
<integer>0</integer>
|
|
|
|
<key>HTTPSEnable</key>
|
|
|
|
<integer>0</integer>
|
|
|
|
</dict>
|
|
|
|
<key>UserDefinedName</key>
|
|
|
|
<string>$server_addr</string>
|
|
|
|
<key>VPNType</key>
|
|
|
|
<string>IKEv2</string>
|
|
|
|
</dict>
|
|
|
|
<dict>
|
2022-02-12 21:12:51 +03:00
|
|
|
EOF
|
2022-09-25 02:56:27 +03:00
|
|
|
if [ "$use_config_password" = 0 ]; then
|
2022-02-12 21:12:51 +03:00
|
|
|
cat >> "$mc_file" <<EOF
|
2022-02-12 10:21:12 +03:00
|
|
|
<key>Password</key>
|
|
|
|
<string>$p12_password</string>
|
2022-02-12 21:12:51 +03:00
|
|
|
EOF
|
|
|
|
fi
|
|
|
|
cat >> "$mc_file" <<EOF
|
2021-01-18 09:01:46 +03:00
|
|
|
<key>PayloadCertificateFileName</key>
|
|
|
|
<string>$client_name</string>
|
|
|
|
<key>PayloadContent</key>
|
|
|
|
<data>
|
|
|
|
$p12_base64
|
|
|
|
</data>
|
|
|
|
<key>PayloadDescription</key>
|
|
|
|
<string>Adds a PKCS#12-formatted certificate</string>
|
|
|
|
<key>PayloadDisplayName</key>
|
|
|
|
<string>$client_name</string>
|
|
|
|
<key>PayloadIdentifier</key>
|
|
|
|
<string>com.apple.security.pkcs12.$(uuidgen)</string>
|
|
|
|
<key>PayloadType</key>
|
|
|
|
<string>com.apple.security.pkcs12</string>
|
|
|
|
<key>PayloadUUID</key>
|
|
|
|
<string>$uuid1</string>
|
|
|
|
<key>PayloadVersion</key>
|
|
|
|
<integer>1</integer>
|
|
|
|
</dict>
|
|
|
|
<dict>
|
|
|
|
<key>PayloadContent</key>
|
|
|
|
<data>
|
|
|
|
$ca_base64
|
|
|
|
</data>
|
|
|
|
<key>PayloadCertificateFileName</key>
|
|
|
|
<string>ikev2vpnca</string>
|
|
|
|
<key>PayloadDescription</key>
|
|
|
|
<string>Adds a CA root certificate</string>
|
|
|
|
<key>PayloadDisplayName</key>
|
|
|
|
<string>Certificate Authority (CA)</string>
|
|
|
|
<key>PayloadIdentifier</key>
|
|
|
|
<string>com.apple.security.root.$(uuidgen)</string>
|
|
|
|
<key>PayloadType</key>
|
|
|
|
<string>com.apple.security.root</string>
|
|
|
|
<key>PayloadUUID</key>
|
|
|
|
<string>$(uuidgen)</string>
|
|
|
|
<key>PayloadVersion</key>
|
|
|
|
<integer>1</integer>
|
|
|
|
</dict>
|
|
|
|
</array>
|
|
|
|
<key>PayloadDisplayName</key>
|
2022-02-15 08:45:13 +03:00
|
|
|
<string>IKEv2 VPN $server_addr</string>
|
2021-01-18 09:01:46 +03:00
|
|
|
<key>PayloadIdentifier</key>
|
|
|
|
<string>com.apple.vpn.managed.$(uuidgen)</string>
|
|
|
|
<key>PayloadRemovalDisallowed</key>
|
|
|
|
<false/>
|
|
|
|
<key>PayloadType</key>
|
|
|
|
<string>Configuration</string>
|
|
|
|
<key>PayloadUUID</key>
|
|
|
|
<string>$(uuidgen)</string>
|
|
|
|
<key>PayloadVersion</key>
|
|
|
|
<integer>1</integer>
|
|
|
|
</dict>
|
|
|
|
</plist>
|
|
|
|
EOF
|
2022-09-25 02:56:27 +03:00
|
|
|
if [ "$export_to_home_dir" = 1 ]; then
|
2021-01-30 23:24:01 +03:00
|
|
|
chown "$SUDO_USER:$SUDO_USER" "$mc_file"
|
|
|
|
fi
|
2021-01-24 01:02:59 +03:00
|
|
|
chmod 600 "$mc_file"
|
|
|
|
}
|
|
|
|
|
|
|
|
create_android_profile() {
|
|
|
|
[ -z "$server_addr" ] && get_server_address
|
2021-02-04 06:35:56 +03:00
|
|
|
p12_base64_oneline=$(base64 -w 52 "$export_dir$client_name.p12" | sed 's/$/\\n/' | tr -d '\n')
|
2021-01-24 01:02:59 +03:00
|
|
|
[ -z "$p12_base64_oneline" ] && exiterr "Could not encode .p12 file."
|
|
|
|
uuid2=$(uuidgen)
|
|
|
|
[ -z "$uuid2" ] && exiterr "Could not generate UUID value."
|
2021-02-04 06:35:56 +03:00
|
|
|
sswan_file="$export_dir$client_name.sswan"
|
2021-01-24 01:02:59 +03:00
|
|
|
cat > "$sswan_file" <<EOF
|
|
|
|
{
|
|
|
|
"uuid": "$uuid2",
|
2022-02-15 08:45:13 +03:00
|
|
|
"name": "IKEv2 VPN $server_addr",
|
2021-01-24 01:02:59 +03:00
|
|
|
"type": "ikev2-cert",
|
|
|
|
"remote": {
|
|
|
|
"addr": "$server_addr"
|
|
|
|
},
|
|
|
|
"local": {
|
|
|
|
"p12": "$p12_base64_oneline",
|
|
|
|
"rsa-pss": "true"
|
|
|
|
},
|
|
|
|
"ike-proposal": "aes256-sha256-modp2048",
|
2021-03-06 23:05:24 +03:00
|
|
|
"esp-proposal": "aes128gcm16"
|
2021-01-24 01:02:59 +03:00
|
|
|
}
|
|
|
|
EOF
|
2022-09-25 02:56:27 +03:00
|
|
|
if [ "$export_to_home_dir" = 1 ]; then
|
2021-01-30 23:24:01 +03:00
|
|
|
chown "$SUDO_USER:$SUDO_USER" "$sswan_file"
|
|
|
|
fi
|
2021-01-24 03:20:49 +03:00
|
|
|
chmod 600 "$sswan_file"
|
2021-01-18 09:01:46 +03:00
|
|
|
}
|
2020-05-11 09:18:34 +03:00
|
|
|
|
2021-04-18 22:27:52 +03:00
|
|
|
export_client_config() {
|
2021-07-13 07:41:33 +03:00
|
|
|
if [ "$os_type" != "alpine" ]; then
|
|
|
|
install_base64_uuidgen
|
2021-09-14 08:24:27 +03:00
|
|
|
else
|
|
|
|
install_uuidgen
|
2021-07-13 07:41:33 +03:00
|
|
|
fi
|
2021-04-18 22:27:52 +03:00
|
|
|
export_p12_file
|
|
|
|
create_mobileconfig
|
|
|
|
create_android_profile
|
|
|
|
}
|
|
|
|
|
2021-02-14 10:10:38 +03:00
|
|
|
create_ca_server_certs() {
|
2021-03-31 07:47:59 +03:00
|
|
|
bigecho2 "Generating CA and server certificates..."
|
2021-01-18 09:01:46 +03:00
|
|
|
certutil -z <(head -c 1024 /dev/urandom) \
|
2022-02-15 08:45:13 +03:00
|
|
|
-S -x -n "$CA_NAME" \
|
|
|
|
-s "O=IKEv2 VPN,CN=$CA_NAME" \
|
2021-05-01 22:46:12 +03:00
|
|
|
-k rsa -g 3072 -v 120 \
|
2022-02-15 08:45:13 +03:00
|
|
|
-d "$CERT_DB" -t "CT,," -2 >/dev/null 2>&1 <<ANSWERS || exiterr "Failed to create CA certificate."
|
2020-06-11 09:16:51 +03:00
|
|
|
y
|
|
|
|
|
|
|
|
N
|
|
|
|
ANSWERS
|
2021-05-01 22:46:12 +03:00
|
|
|
sleep 1
|
2022-09-25 02:56:27 +03:00
|
|
|
if [ "$use_dns_name" = 1 ]; then
|
2021-01-18 09:01:46 +03:00
|
|
|
certutil -z <(head -c 1024 /dev/urandom) \
|
2022-02-15 08:45:13 +03:00
|
|
|
-S -c "$CA_NAME" -n "$server_addr" \
|
2021-01-18 09:01:46 +03:00
|
|
|
-s "O=IKEv2 VPN,CN=$server_addr" \
|
2021-05-01 22:46:12 +03:00
|
|
|
-k rsa -g 3072 -v 120 \
|
2022-02-15 08:45:13 +03:00
|
|
|
-d "$CERT_DB" -t ",," \
|
2021-01-18 09:01:46 +03:00
|
|
|
--keyUsage digitalSignature,keyEncipherment \
|
|
|
|
--extKeyUsage serverAuth \
|
2021-02-05 08:41:48 +03:00
|
|
|
--extSAN "dns:$server_addr" >/dev/null 2>&1 || exiterr "Failed to create server certificate."
|
2021-01-18 09:01:46 +03:00
|
|
|
else
|
|
|
|
certutil -z <(head -c 1024 /dev/urandom) \
|
2022-02-15 08:45:13 +03:00
|
|
|
-S -c "$CA_NAME" -n "$server_addr" \
|
2021-01-18 09:01:46 +03:00
|
|
|
-s "O=IKEv2 VPN,CN=$server_addr" \
|
2021-05-01 22:46:12 +03:00
|
|
|
-k rsa -g 3072 -v 120 \
|
2022-02-15 08:45:13 +03:00
|
|
|
-d "$CERT_DB" -t ",," \
|
2021-01-18 09:01:46 +03:00
|
|
|
--keyUsage digitalSignature,keyEncipherment \
|
|
|
|
--extKeyUsage serverAuth \
|
2021-02-05 08:41:48 +03:00
|
|
|
--extSAN "ip:$server_addr,dns:$server_addr" >/dev/null 2>&1 || exiterr "Failed to create server certificate."
|
2021-01-18 09:01:46 +03:00
|
|
|
fi
|
|
|
|
}
|
2020-06-11 09:16:51 +03:00
|
|
|
|
2022-02-26 08:25:34 +03:00
|
|
|
create_config_readme() {
|
|
|
|
readme_file="$export_dir$client_name-README.txt"
|
2022-09-25 02:56:27 +03:00
|
|
|
if [ "$in_container" = 0 ] && [ "$use_config_password" = 0 ] \
|
|
|
|
&& [ "$use_defaults" = 1 ] && [ ! -t 1 ] && [ ! -f "$readme_file" ]; then
|
2022-02-26 08:25:34 +03:00
|
|
|
cat > "$readme_file" <<'EOF'
|
|
|
|
These IKEv2 client config files were created during IPsec VPN setup.
|
2022-06-09 21:44:16 +03:00
|
|
|
To configure IKEv2 clients, see: https://vpnsetup.net/clients
|
2022-02-26 08:25:34 +03:00
|
|
|
EOF
|
2022-09-25 02:56:27 +03:00
|
|
|
if [ "$export_to_home_dir" = 1 ]; then
|
2022-02-26 08:25:34 +03:00
|
|
|
chown "$SUDO_USER:$SUDO_USER" "$readme_file"
|
|
|
|
fi
|
|
|
|
chmod 600 "$readme_file"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2021-01-18 09:01:46 +03:00
|
|
|
add_ikev2_connection() {
|
2021-03-31 07:47:59 +03:00
|
|
|
bigecho2 "Adding a new IKEv2 connection..."
|
2022-02-26 06:17:09 +03:00
|
|
|
XAUTH_POOL=${VPN_XAUTH_POOL:-'192.168.43.10-192.168.43.250'}
|
2022-02-15 08:45:13 +03:00
|
|
|
if ! grep -qs '^include /etc/ipsec\.d/\*\.conf$' "$IPSEC_CONF"; then
|
|
|
|
echo >> "$IPSEC_CONF"
|
|
|
|
echo 'include /etc/ipsec.d/*.conf' >> "$IPSEC_CONF"
|
2021-01-18 09:01:46 +03:00
|
|
|
fi
|
2022-02-15 08:45:13 +03:00
|
|
|
cat > "$IKEV2_CONF" <<EOF
|
2020-05-11 09:18:34 +03:00
|
|
|
|
|
|
|
conn ikev2-cp
|
|
|
|
left=%defaultroute
|
|
|
|
leftcert=$server_addr
|
|
|
|
leftsendcert=always
|
|
|
|
leftsubnet=0.0.0.0/0
|
|
|
|
leftrsasigkey=%cert
|
|
|
|
right=%any
|
|
|
|
rightid=%fromcert
|
2022-02-26 06:17:09 +03:00
|
|
|
rightaddresspool=$XAUTH_POOL
|
2020-05-11 09:18:34 +03:00
|
|
|
rightca=%same
|
|
|
|
rightrsasigkey=%cert
|
|
|
|
narrowing=yes
|
|
|
|
dpddelay=30
|
2022-06-15 08:28:21 +03:00
|
|
|
retransmit-timeout=300s
|
2020-05-11 09:18:34 +03:00
|
|
|
dpdaction=clear
|
|
|
|
auto=add
|
|
|
|
ikev2=insist
|
|
|
|
rekey=no
|
|
|
|
pfs=no
|
2021-04-25 06:34:48 +03:00
|
|
|
ike=aes256-sha2,aes128-sha2,aes256-sha1,aes128-sha1
|
2020-05-11 09:18:34 +03:00
|
|
|
phase2alg=aes_gcm-null,aes128-sha1,aes256-sha1,aes128-sha2,aes256-sha2
|
2021-01-20 10:39:07 +03:00
|
|
|
ikelifetime=24h
|
|
|
|
salifetime=24h
|
2020-07-13 01:14:30 +03:00
|
|
|
encapsulation=yes
|
2020-05-11 09:18:34 +03:00
|
|
|
EOF
|
2022-09-25 02:56:27 +03:00
|
|
|
if [ "$use_dns_name" = 1 ]; then
|
2022-02-15 08:45:13 +03:00
|
|
|
cat >> "$IKEV2_CONF" <<EOF
|
2021-02-02 06:31:40 +03:00
|
|
|
leftid=@$server_addr
|
|
|
|
EOF
|
|
|
|
else
|
2022-02-15 08:45:13 +03:00
|
|
|
cat >> "$IKEV2_CONF" <<EOF
|
2021-02-02 06:31:40 +03:00
|
|
|
leftid=$server_addr
|
|
|
|
EOF
|
|
|
|
fi
|
2021-03-20 07:58:06 +03:00
|
|
|
if [ -n "$dns_server_2" ]; then
|
2022-02-15 08:45:13 +03:00
|
|
|
cat >> "$IKEV2_CONF" <<EOF
|
2020-07-13 01:14:30 +03:00
|
|
|
modecfgdns="$dns_servers"
|
|
|
|
EOF
|
2021-03-20 07:58:06 +03:00
|
|
|
else
|
2022-02-15 08:45:13 +03:00
|
|
|
cat >> "$IKEV2_CONF" <<EOF
|
2020-07-13 01:14:30 +03:00
|
|
|
modecfgdns=$dns_server_1
|
2020-05-11 09:18:34 +03:00
|
|
|
EOF
|
2021-03-20 07:58:06 +03:00
|
|
|
fi
|
2022-09-25 02:56:27 +03:00
|
|
|
if [ "$mobike_enable" = 1 ]; then
|
2022-02-15 08:45:13 +03:00
|
|
|
echo " mobike=yes" >> "$IKEV2_CONF"
|
2021-03-20 07:58:06 +03:00
|
|
|
else
|
2022-02-15 08:45:13 +03:00
|
|
|
echo " mobike=no" >> "$IKEV2_CONF"
|
2021-03-20 07:58:06 +03:00
|
|
|
fi
|
2021-01-18 09:01:46 +03:00
|
|
|
}
|
|
|
|
|
2021-01-21 09:24:07 +03:00
|
|
|
apply_ubuntu1804_nss_fix() {
|
2022-08-11 06:41:55 +03:00
|
|
|
os_arch=$(uname -m | tr -dc 'A-Za-z0-9_-')
|
2022-10-22 07:37:47 +03:00
|
|
|
if [ "$os_type" = "ubuntu" ] && [ "$os_ver" = "bustersid" ] && [ "$os_arch" = "x86_64" ] \
|
|
|
|
&& ! dpkg -l libnss3-dev 2>/dev/null | grep -qF '3.49.1'; then
|
|
|
|
base_url="https://github.com/hwdsl2/vpn-extras/releases/download/v1.0.0"
|
2022-10-23 07:55:06 +03:00
|
|
|
nss_url1="https://mirrors.kernel.org/ubuntu/pool/main/n/nss"
|
|
|
|
nss_url2="https://mirrors.kernel.org/ubuntu/pool/universe/n/nss"
|
2023-03-02 06:26:04 +03:00
|
|
|
deb1="libnss3_3.49.1-1ubuntu1.9_amd64.deb"
|
|
|
|
deb2="libnss3-dev_3.49.1-1ubuntu1.9_amd64.deb"
|
|
|
|
deb3="libnss3-tools_3.49.1-1ubuntu1.9_amd64.deb"
|
2022-10-22 07:37:47 +03:00
|
|
|
bigecho2 "Applying fix for NSS bug on Ubuntu 18.04..."
|
2022-10-23 07:55:06 +03:00
|
|
|
mkdir -p /opt/src
|
|
|
|
cd /opt/src || exit 1
|
|
|
|
nss_dl=0
|
|
|
|
/bin/rm -f "$deb1" "$deb2" "$deb3"
|
|
|
|
export DEBIAN_FRONTEND=noninteractive
|
|
|
|
if wget -t 3 -T 30 -q "$base_url/$deb1" "$base_url/$deb2" "$base_url/$deb3"; then
|
|
|
|
apt-get -yqq update || apt-get -yqq update
|
|
|
|
apt-get -yqq install "./$deb1" "./$deb2" "./$deb3" >/dev/null
|
|
|
|
else
|
|
|
|
/bin/rm -f "$deb1" "$deb2" "$deb3"
|
|
|
|
if wget -t 3 -T 30 -q "$nss_url1/$deb1" "$nss_url1/$deb2" "$nss_url2/$deb3"; then
|
2022-02-09 08:24:46 +03:00
|
|
|
apt-get -yqq update || apt-get -yqq update
|
2022-10-23 07:55:06 +03:00
|
|
|
apt-get -yqq install "./$deb1" "./$deb2" "./$deb3" >/dev/null
|
2022-10-22 07:37:47 +03:00
|
|
|
else
|
|
|
|
nss_dl=1
|
|
|
|
echo "Error: Could not download NSS packages." >&2
|
2021-02-14 10:10:38 +03:00
|
|
|
fi
|
2021-01-21 09:24:07 +03:00
|
|
|
fi
|
2022-10-23 07:55:06 +03:00
|
|
|
/bin/rm -f "$deb1" "$deb2" "$deb3"
|
|
|
|
[ "$nss_dl" = 1 ] && exit 1
|
2021-01-21 09:24:07 +03:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2021-01-18 09:01:46 +03:00
|
|
|
restart_ipsec_service() {
|
2022-09-25 02:56:27 +03:00
|
|
|
if [ "$in_container" = 0 ] || { [ "$in_container" = 1 ] && service ipsec status >/dev/null 2>&1; }; then
|
2021-03-31 07:47:59 +03:00
|
|
|
bigecho2 "Restarting IPsec service..."
|
2021-02-12 10:08:49 +03:00
|
|
|
mkdir -p /run/pluto
|
|
|
|
service ipsec restart 2>/dev/null
|
|
|
|
fi
|
2021-01-18 09:01:46 +03:00
|
|
|
}
|
|
|
|
|
2022-12-02 06:45:57 +03:00
|
|
|
check_ikev2_connection() {
|
|
|
|
if grep -qs 'mobike=yes' "$IKEV2_CONF"; then
|
|
|
|
(sleep 3
|
|
|
|
if ! ipsec status | grep -q ikev2-cp; then
|
|
|
|
sed -i '/mobike=yes/s/yes/no/' "$IKEV2_CONF"
|
|
|
|
if [ "$os_type" = "alpine" ]; then
|
|
|
|
ipsec auto --add ikev2-cp >/dev/null
|
|
|
|
else
|
|
|
|
restart_ipsec_service >/dev/null
|
|
|
|
fi
|
|
|
|
fi) >/dev/null 2>&1 &
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2021-06-01 10:30:51 +03:00
|
|
|
create_crl() {
|
2022-09-10 07:03:07 +03:00
|
|
|
bigecho "Revoking client certificate..."
|
2022-02-15 08:45:13 +03:00
|
|
|
if ! crlutil -L -d "$CERT_DB" -n "$CA_NAME" >/dev/null 2>&1; then
|
|
|
|
crlutil -G -d "$CERT_DB" -n "$CA_NAME" -c /dev/null >/dev/null
|
2021-06-01 10:30:51 +03:00
|
|
|
fi
|
|
|
|
sleep 2
|
|
|
|
}
|
|
|
|
|
|
|
|
add_client_cert_to_crl() {
|
2022-02-15 08:45:13 +03:00
|
|
|
sn_txt=$(certutil -L -d "$CERT_DB" -n "$client_name" | grep -A 1 'Serial Number' | tail -n 1)
|
2021-06-01 10:30:51 +03:00
|
|
|
sn_hex=$(printf '%s' "$sn_txt" | sed -e 's/^ *//' -e 's/://g')
|
|
|
|
sn_dec=$((16#$sn_hex))
|
|
|
|
[ -z "$sn_dec" ] && exiterr "Could not find serial number of client certificate."
|
2022-02-15 08:45:13 +03:00
|
|
|
crlutil -M -d "$CERT_DB" -n "$CA_NAME" >/dev/null <<EOF || exiterr "Failed to add client certificate to CRL."
|
2021-06-01 10:30:51 +03:00
|
|
|
addcert $sn_dec $(date -u +%Y%m%d%H%M%SZ)
|
|
|
|
EOF
|
|
|
|
}
|
|
|
|
|
|
|
|
reload_crls() {
|
2021-08-11 08:03:25 +03:00
|
|
|
ipsec crls
|
2021-06-01 10:30:51 +03:00
|
|
|
}
|
|
|
|
|
2022-04-07 06:49:20 +03:00
|
|
|
delete_client_cert() {
|
2022-09-10 07:03:07 +03:00
|
|
|
bigecho "Deleting client certificate..."
|
2022-04-07 06:49:20 +03:00
|
|
|
certutil -F -d "$CERT_DB" -n "$client_name"
|
|
|
|
certutil -D -d "$CERT_DB" -n "$client_name" 2>/dev/null
|
|
|
|
}
|
|
|
|
|
2022-09-10 07:03:07 +03:00
|
|
|
remove_client_config() {
|
|
|
|
p12_file="$export_dir$client_name.p12"
|
|
|
|
mc_file="$export_dir$client_name.mobileconfig"
|
|
|
|
sswan_file="$export_dir$client_name.sswan"
|
|
|
|
if [ -f "$p12_file" ] || [ -f "$mc_file" ] || [ -f "$sswan_file" ]; then
|
|
|
|
bigecho "Removing client config files..."
|
|
|
|
if [ -f "$p12_file" ]; then
|
|
|
|
printf '%s\n' "$p12_file"
|
|
|
|
/bin/rm -f "$p12_file"
|
|
|
|
fi
|
|
|
|
if [ -f "$mc_file" ]; then
|
|
|
|
printf '%s\n' "$mc_file"
|
|
|
|
/bin/rm -f "$mc_file"
|
|
|
|
fi
|
|
|
|
if [ -f "$sswan_file" ]; then
|
|
|
|
printf '%s\n' "$sswan_file"
|
|
|
|
/bin/rm -f "$sswan_file"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2021-04-18 22:27:52 +03:00
|
|
|
print_client_added() {
|
2021-01-18 09:01:46 +03:00
|
|
|
cat <<EOF
|
|
|
|
|
2021-03-31 07:47:59 +03:00
|
|
|
|
2021-02-18 09:43:55 +03:00
|
|
|
================================================
|
2021-01-18 09:01:46 +03:00
|
|
|
|
2022-03-20 08:14:25 +03:00
|
|
|
New IKEv2 client "$client_name" added!
|
2020-05-11 09:18:34 +03:00
|
|
|
|
2021-01-18 09:01:46 +03:00
|
|
|
EOF
|
2022-10-19 08:31:52 +03:00
|
|
|
print_server_info
|
2021-01-18 09:01:46 +03:00
|
|
|
}
|
2020-05-11 09:18:34 +03:00
|
|
|
|
2021-04-18 22:27:52 +03:00
|
|
|
print_client_exported() {
|
2021-01-19 06:51:31 +03:00
|
|
|
cat <<EOF
|
|
|
|
|
2021-03-31 07:47:59 +03:00
|
|
|
|
2021-02-18 09:43:55 +03:00
|
|
|
================================================
|
2021-01-19 06:51:31 +03:00
|
|
|
|
2022-03-20 08:14:25 +03:00
|
|
|
IKEv2 client "$client_name" exported!
|
2021-01-19 06:51:31 +03:00
|
|
|
|
|
|
|
EOF
|
2022-10-19 08:31:52 +03:00
|
|
|
print_server_info
|
2021-01-19 06:51:31 +03:00
|
|
|
}
|
|
|
|
|
2021-06-01 10:30:51 +03:00
|
|
|
print_client_revoked() {
|
2022-09-10 07:03:07 +03:00
|
|
|
echo
|
|
|
|
echo "Client '$client_name' revoked!"
|
2021-06-01 10:30:51 +03:00
|
|
|
}
|
|
|
|
|
2022-04-07 06:49:20 +03:00
|
|
|
print_client_deleted() {
|
2022-09-10 07:03:07 +03:00
|
|
|
echo
|
|
|
|
echo "Client '$client_name' deleted!"
|
2022-04-07 06:49:20 +03:00
|
|
|
}
|
|
|
|
|
2021-04-18 22:27:52 +03:00
|
|
|
print_setup_complete() {
|
2022-02-18 06:36:19 +03:00
|
|
|
printf '\e[2K\e[1A\e[2K\r'
|
2022-09-25 02:56:27 +03:00
|
|
|
[ "$use_defaults" = 1 ] && printf '\e[1A\e[2K\e[1A\e[2K\e[1A\e[2K\r'
|
2020-05-11 09:18:34 +03:00
|
|
|
cat <<EOF
|
2021-02-18 09:43:55 +03:00
|
|
|
================================================
|
2020-05-11 09:18:34 +03:00
|
|
|
|
2021-03-29 07:39:04 +03:00
|
|
|
IKEv2 setup successful. Details for IKEv2 mode:
|
2020-05-11 09:18:34 +03:00
|
|
|
|
2022-10-19 08:31:52 +03:00
|
|
|
VPN server address: $server_addr
|
|
|
|
VPN client name: $client_name
|
|
|
|
|
2021-01-18 09:01:46 +03:00
|
|
|
EOF
|
|
|
|
}
|
|
|
|
|
|
|
|
print_client_info() {
|
2022-09-25 02:56:27 +03:00
|
|
|
if [ "$in_container" = 0 ]; then
|
2021-03-09 08:23:00 +03:00
|
|
|
cat <<'EOF'
|
2020-05-18 02:09:40 +03:00
|
|
|
Client configuration is available at:
|
2021-03-09 08:23:00 +03:00
|
|
|
EOF
|
|
|
|
else
|
|
|
|
cat <<'EOF'
|
|
|
|
Client configuration is available inside the
|
|
|
|
Docker container at:
|
|
|
|
EOF
|
|
|
|
fi
|
|
|
|
cat <<EOF
|
2021-03-31 07:47:59 +03:00
|
|
|
$export_dir$client_name.p12 (for Windows & Linux)
|
2021-02-04 06:35:56 +03:00
|
|
|
$export_dir$client_name.sswan (for Android)
|
|
|
|
$export_dir$client_name.mobileconfig (for iOS & macOS)
|
2021-01-16 08:26:25 +03:00
|
|
|
EOF
|
2022-09-25 02:56:27 +03:00
|
|
|
if [ "$use_config_password" = 1 ]; then
|
2022-02-12 21:12:51 +03:00
|
|
|
cat <<EOF
|
|
|
|
|
|
|
|
*IMPORTANT* Password for client config files:
|
|
|
|
$p12_password
|
|
|
|
Write this down, you'll need it for import!
|
|
|
|
EOF
|
|
|
|
fi
|
2022-10-19 08:31:52 +03:00
|
|
|
config_url="https://vpnsetup.net/clients"
|
|
|
|
if [ "$in_container" = 1 ]; then
|
|
|
|
config_url="${config_url}2"
|
|
|
|
fi
|
|
|
|
cat <<EOF
|
2020-05-11 09:18:34 +03:00
|
|
|
|
2022-03-20 08:14:25 +03:00
|
|
|
Next steps: Configure IKEv2 clients. See:
|
2022-10-19 08:31:52 +03:00
|
|
|
$config_url
|
2022-03-19 05:52:20 +03:00
|
|
|
|
2021-02-18 09:43:55 +03:00
|
|
|
================================================
|
2020-05-11 09:18:34 +03:00
|
|
|
|
|
|
|
EOF
|
2021-01-18 09:01:46 +03:00
|
|
|
}
|
|
|
|
|
2022-01-30 02:33:42 +03:00
|
|
|
check_swan_update() {
|
2022-01-29 10:30:21 +03:00
|
|
|
base_url="https://github.com/hwdsl2/vpn-extras/releases/download/v1.0.0"
|
|
|
|
swan_ver_url="$base_url/upg-$os_type-$os_ver-swanver"
|
2022-09-24 08:58:16 +03:00
|
|
|
swan_ver_latest=$(wget -t 2 -T 10 -qO- "$swan_ver_url" | head -n 1)
|
2022-01-23 09:05:44 +03:00
|
|
|
if printf '%s' "$swan_ver_latest" | grep -Eq '^([3-9]|[1-9][0-9]{1,2})(\.([0-9]|[1-9][0-9]{1,2})){1,2}$' \
|
|
|
|
&& [ -n "$swan_ver" ] && [ "$swan_ver" != "$swan_ver_latest" ] \
|
|
|
|
&& printf '%s\n%s' "$swan_ver" "$swan_ver_latest" | sort -C -V; then
|
2022-01-29 10:30:21 +03:00
|
|
|
cat <<EOF
|
|
|
|
Note: A newer version of Libreswan ($swan_ver_latest) is available.
|
|
|
|
To update, run:
|
2022-05-24 06:08:30 +03:00
|
|
|
wget https://get.vpnsetup.net/upg -O vpnup.sh && sudo sh vpnup.sh
|
2022-01-29 10:30:21 +03:00
|
|
|
|
|
|
|
EOF
|
2022-01-23 09:05:44 +03:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2021-01-19 10:05:06 +03:00
|
|
|
check_ipsec_conf() {
|
2022-02-15 08:45:13 +03:00
|
|
|
if grep -qs "conn ikev2-cp" "$IPSEC_CONF"; then
|
|
|
|
cat 1>&2 <<EOF
|
|
|
|
Error: IKEv2 configuration section found in $IPSEC_CONF.
|
2021-09-20 05:51:14 +03:00
|
|
|
This script cannot automatically remove IKEv2 from this server.
|
2022-06-09 21:44:16 +03:00
|
|
|
To manually remove IKEv2, see https://vpnsetup.net/ikev2
|
2022-05-08 10:59:28 +03:00
|
|
|
EOF
|
|
|
|
abort_and_exit
|
|
|
|
fi
|
|
|
|
if grep -qs "ikev1-policy=drop" "$IPSEC_CONF" \
|
|
|
|
|| grep -qs "ikev1-policy=reject" "$IPSEC_CONF"; then
|
|
|
|
cat 1>&2 <<EOF
|
|
|
|
Error: IKEv2-only mode is currently enabled on this VPN server.
|
|
|
|
You must first disable IKEv2-only mode before removing IKEv2.
|
|
|
|
Otherwise, you will NOT be able to connect to this VPN server.
|
2021-09-20 05:51:14 +03:00
|
|
|
EOF
|
2021-08-01 07:36:43 +03:00
|
|
|
abort_and_exit
|
2021-01-19 10:05:06 +03:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2021-06-01 10:30:51 +03:00
|
|
|
confirm_revoke_cert() {
|
2021-09-20 05:51:14 +03:00
|
|
|
cat <<EOF
|
|
|
|
WARNING: You have selected to revoke IKEv2 client certificate '$client_name'.
|
|
|
|
After revocation, this certificate *cannot* be used by VPN client(s)
|
|
|
|
to connect to this VPN server.
|
|
|
|
|
|
|
|
EOF
|
2021-07-30 16:47:10 +03:00
|
|
|
confirm_or_abort "Are you sure you want to revoke '$client_name'? [y/N] "
|
2021-06-01 10:30:51 +03:00
|
|
|
}
|
|
|
|
|
2022-04-07 06:49:20 +03:00
|
|
|
confirm_delete_cert() {
|
|
|
|
cat <<EOF
|
|
|
|
WARNING: Deleting a client certificate from the IPsec database *WILL NOT* prevent
|
|
|
|
VPN client(s) from connecting using that certificate! For this use case,
|
|
|
|
you *MUST* revoke the client certificate instead of deleting it.
|
|
|
|
This *cannot* be undone!
|
|
|
|
|
|
|
|
EOF
|
|
|
|
confirm_or_abort "Are you sure you want to delete '$client_name'? [y/N] "
|
|
|
|
}
|
|
|
|
|
2021-01-19 10:05:06 +03:00
|
|
|
confirm_remove_ikev2() {
|
2021-09-20 05:51:14 +03:00
|
|
|
cat <<'EOF'
|
|
|
|
WARNING: This option will remove IKEv2 from this VPN server, but keep the IPsec/L2TP
|
|
|
|
and IPsec/XAuth ("Cisco IPsec") modes, if installed. All IKEv2 configuration
|
|
|
|
including certificates and keys will be *permanently deleted*.
|
|
|
|
This *cannot* be undone!
|
|
|
|
|
|
|
|
EOF
|
2021-07-30 16:47:10 +03:00
|
|
|
confirm_or_abort "Are you sure you want to remove IKEv2? [y/N] "
|
2021-01-19 10:05:06 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
delete_ikev2_conf() {
|
2022-02-15 08:45:13 +03:00
|
|
|
bigecho "Deleting $IKEV2_CONF..."
|
|
|
|
/bin/rm -f "$IKEV2_CONF"
|
2021-01-19 10:05:06 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
delete_certificates() {
|
2021-03-31 07:47:59 +03:00
|
|
|
echo
|
2021-01-26 07:05:06 +03:00
|
|
|
bigecho "Deleting certificates and keys from the IPsec database..."
|
2022-10-19 08:31:52 +03:00
|
|
|
cert_list=$(certutil -L -d "$CERT_DB" | grep -v -e '^$' -e "$CA_NAME" | tail -n +3 | cut -f1 -d ' ')
|
|
|
|
while IFS= read -r line; do
|
2022-02-15 08:45:13 +03:00
|
|
|
certutil -F -d "$CERT_DB" -n "$line"
|
|
|
|
certutil -D -d "$CERT_DB" -n "$line" 2>/dev/null
|
2022-10-19 08:31:52 +03:00
|
|
|
done <<< "$cert_list"
|
2022-02-15 08:45:13 +03:00
|
|
|
crlutil -D -d "$CERT_DB" -n "$CA_NAME" 2>/dev/null
|
|
|
|
certutil -F -d "$CERT_DB" -n "$CA_NAME"
|
|
|
|
certutil -D -d "$CERT_DB" -n "$CA_NAME" 2>/dev/null
|
2022-02-16 06:17:47 +03:00
|
|
|
if grep -qs '^IKEV2_CONFIG_PASSWORD=.\+' "$CONF_FILE"; then
|
|
|
|
sed -i '/IKEV2_CONFIG_PASSWORD=/d' "$CONF_FILE"
|
2021-07-26 04:55:40 +03:00
|
|
|
fi
|
2021-01-19 10:05:06 +03:00
|
|
|
}
|
|
|
|
|
2021-04-18 22:27:52 +03:00
|
|
|
print_ikev2_removed() {
|
2021-03-31 07:47:59 +03:00
|
|
|
echo
|
2021-01-19 10:05:06 +03:00
|
|
|
echo "IKEv2 removed!"
|
|
|
|
}
|
|
|
|
|
2021-01-18 09:01:46 +03:00
|
|
|
ikev2setup() {
|
2021-08-11 08:03:25 +03:00
|
|
|
check_root
|
2021-07-13 07:41:33 +03:00
|
|
|
check_container
|
2021-08-11 08:03:25 +03:00
|
|
|
check_os
|
2021-08-22 08:42:21 +03:00
|
|
|
check_libreswan
|
2022-01-29 23:12:50 +03:00
|
|
|
check_swan_ver
|
2021-01-18 09:01:46 +03:00
|
|
|
check_utils_exist
|
|
|
|
|
2021-01-24 22:53:55 +03:00
|
|
|
use_defaults=0
|
2021-04-18 22:27:52 +03:00
|
|
|
add_client=0
|
|
|
|
export_client=0
|
2021-01-25 00:08:06 +03:00
|
|
|
list_clients=0
|
2021-06-01 10:30:51 +03:00
|
|
|
revoke_client=0
|
2022-04-07 06:49:20 +03:00
|
|
|
delete_client=0
|
2021-01-26 07:05:06 +03:00
|
|
|
remove_ikev2=0
|
2021-01-24 22:53:55 +03:00
|
|
|
while [ "$#" -gt 0 ]; do
|
|
|
|
case $1 in
|
|
|
|
--auto)
|
|
|
|
use_defaults=1
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
--addclient)
|
2021-04-18 22:27:52 +03:00
|
|
|
add_client=1
|
2021-01-24 22:53:55 +03:00
|
|
|
client_name="$2"
|
|
|
|
shift
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
--exportclient)
|
2021-04-18 22:27:52 +03:00
|
|
|
export_client=1
|
2021-01-24 22:53:55 +03:00
|
|
|
client_name="$2"
|
|
|
|
shift
|
|
|
|
shift
|
|
|
|
;;
|
2021-01-25 00:08:06 +03:00
|
|
|
--listclients)
|
|
|
|
list_clients=1
|
|
|
|
shift
|
|
|
|
;;
|
2021-06-01 10:30:51 +03:00
|
|
|
--revokeclient)
|
|
|
|
revoke_client=1
|
|
|
|
client_name="$2"
|
|
|
|
shift
|
|
|
|
shift
|
|
|
|
;;
|
2022-04-07 06:49:20 +03:00
|
|
|
--deleteclient)
|
|
|
|
delete_client=1
|
|
|
|
client_name="$2"
|
|
|
|
shift
|
|
|
|
shift
|
|
|
|
;;
|
2021-01-26 07:05:06 +03:00
|
|
|
--removeikev2)
|
|
|
|
remove_ikev2=1
|
|
|
|
shift
|
|
|
|
;;
|
2021-01-24 22:53:55 +03:00
|
|
|
-h|--help)
|
|
|
|
show_usage
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
show_usage "Unknown parameter: $1"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
2022-02-15 08:45:13 +03:00
|
|
|
CA_NAME="IKEv2 VPN CA"
|
|
|
|
CERT_DB="sql:/etc/ipsec.d"
|
2022-02-16 06:17:47 +03:00
|
|
|
CONF_DIR="/etc/ipsec.d"
|
|
|
|
CONF_FILE="/etc/ipsec.d/.vpnconfig"
|
2022-02-15 08:45:13 +03:00
|
|
|
IKEV2_CONF="/etc/ipsec.d/ikev2.conf"
|
|
|
|
IPSEC_CONF="/etc/ipsec.conf"
|
|
|
|
|
2021-01-24 22:53:55 +03:00
|
|
|
check_arguments
|
2022-02-14 12:46:06 +03:00
|
|
|
check_config_password
|
2021-01-30 23:24:01 +03:00
|
|
|
get_export_dir
|
2021-01-24 22:53:55 +03:00
|
|
|
|
2022-09-25 02:56:27 +03:00
|
|
|
if [ "$add_client" = 1 ]; then
|
2022-10-16 08:45:45 +03:00
|
|
|
check_and_set_client_validity
|
2021-07-30 16:47:10 +03:00
|
|
|
show_header
|
2021-04-18 22:27:52 +03:00
|
|
|
show_add_client
|
2021-01-24 22:53:55 +03:00
|
|
|
create_client_cert
|
2021-04-18 22:27:52 +03:00
|
|
|
export_client_config
|
|
|
|
print_client_added
|
2021-01-24 22:53:55 +03:00
|
|
|
print_client_info
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2022-09-25 02:56:27 +03:00
|
|
|
if [ "$export_client" = 1 ]; then
|
2021-07-30 16:47:10 +03:00
|
|
|
show_header
|
2021-04-18 22:27:52 +03:00
|
|
|
show_export_client
|
|
|
|
export_client_config
|
|
|
|
print_client_exported
|
2021-01-24 22:53:55 +03:00
|
|
|
print_client_info
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2022-09-25 02:56:27 +03:00
|
|
|
if [ "$list_clients" = 1 ]; then
|
2021-07-30 16:47:10 +03:00
|
|
|
show_header
|
2021-01-25 00:08:06 +03:00
|
|
|
list_existing_clients
|
2022-01-05 08:10:28 +03:00
|
|
|
echo
|
2021-01-25 00:08:06 +03:00
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2022-09-25 02:56:27 +03:00
|
|
|
if [ "$revoke_client" = 1 ]; then
|
2021-07-30 16:47:10 +03:00
|
|
|
show_header
|
2021-06-01 10:30:51 +03:00
|
|
|
confirm_revoke_cert
|
|
|
|
create_crl
|
|
|
|
add_client_cert_to_crl
|
|
|
|
reload_crls
|
2022-09-10 07:03:07 +03:00
|
|
|
remove_client_config
|
2021-06-01 10:30:51 +03:00
|
|
|
print_client_revoked
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2022-09-25 02:56:27 +03:00
|
|
|
if [ "$delete_client" = 1 ]; then
|
2022-04-07 06:49:20 +03:00
|
|
|
show_header
|
|
|
|
confirm_delete_cert
|
|
|
|
delete_client_cert
|
2022-09-10 07:03:07 +03:00
|
|
|
remove_client_config
|
2022-04-07 06:49:20 +03:00
|
|
|
print_client_deleted
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2022-09-25 02:56:27 +03:00
|
|
|
if [ "$remove_ikev2" = 1 ]; then
|
2021-01-26 07:05:06 +03:00
|
|
|
check_ipsec_conf
|
2021-07-30 16:47:10 +03:00
|
|
|
show_header
|
2021-01-26 07:05:06 +03:00
|
|
|
confirm_remove_ikev2
|
|
|
|
delete_ikev2_conf
|
2021-07-13 07:41:33 +03:00
|
|
|
if [ "$os_type" = "alpine" ]; then
|
|
|
|
ipsec auto --delete ikev2-cp
|
|
|
|
else
|
|
|
|
restart_ipsec_service
|
|
|
|
fi
|
2021-01-26 07:05:06 +03:00
|
|
|
delete_certificates
|
2021-04-18 22:27:52 +03:00
|
|
|
print_ikev2_removed
|
2021-01-26 07:05:06 +03:00
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2021-04-11 00:24:49 +03:00
|
|
|
if check_ikev2_exists; then
|
2021-07-30 16:47:10 +03:00
|
|
|
show_header
|
2021-01-19 06:51:31 +03:00
|
|
|
select_menu_option
|
|
|
|
case $selected_option in
|
|
|
|
1)
|
|
|
|
enter_client_name
|
2022-02-15 08:45:13 +03:00
|
|
|
enter_client_validity
|
2021-07-14 06:09:25 +03:00
|
|
|
echo
|
2021-01-19 06:51:31 +03:00
|
|
|
create_client_cert
|
2021-04-18 22:27:52 +03:00
|
|
|
export_client_config
|
|
|
|
print_client_added
|
2021-01-19 06:51:31 +03:00
|
|
|
print_client_info
|
|
|
|
exit 0
|
|
|
|
;;
|
|
|
|
2)
|
2021-06-01 10:30:51 +03:00
|
|
|
enter_client_name_for export
|
2021-07-14 06:09:25 +03:00
|
|
|
echo
|
2021-04-18 22:27:52 +03:00
|
|
|
export_client_config
|
|
|
|
print_client_exported
|
2021-01-19 06:51:31 +03:00
|
|
|
print_client_info
|
|
|
|
exit 0
|
|
|
|
;;
|
|
|
|
3)
|
2021-02-02 07:38:42 +03:00
|
|
|
echo
|
|
|
|
list_existing_clients
|
2022-01-05 08:10:28 +03:00
|
|
|
echo
|
2021-02-02 07:38:42 +03:00
|
|
|
exit 0
|
|
|
|
;;
|
|
|
|
4)
|
2021-06-01 10:30:51 +03:00
|
|
|
enter_client_name_for revoke
|
2021-07-30 16:47:10 +03:00
|
|
|
echo
|
2021-06-01 10:30:51 +03:00
|
|
|
confirm_revoke_cert
|
|
|
|
create_crl
|
|
|
|
add_client_cert_to_crl
|
|
|
|
reload_crls
|
2022-09-10 07:03:07 +03:00
|
|
|
remove_client_config
|
2021-06-01 10:30:51 +03:00
|
|
|
print_client_revoked
|
|
|
|
exit 0
|
|
|
|
;;
|
|
|
|
5)
|
2022-04-07 06:49:20 +03:00
|
|
|
enter_client_name_for delete
|
|
|
|
echo
|
|
|
|
confirm_delete_cert
|
|
|
|
delete_client_cert
|
2022-09-10 07:03:07 +03:00
|
|
|
remove_client_config
|
2022-04-07 06:49:20 +03:00
|
|
|
print_client_deleted
|
|
|
|
exit 0
|
|
|
|
;;
|
|
|
|
6)
|
2021-01-19 10:05:06 +03:00
|
|
|
check_ipsec_conf
|
2021-07-30 16:47:10 +03:00
|
|
|
echo
|
2021-01-19 10:05:06 +03:00
|
|
|
confirm_remove_ikev2
|
|
|
|
delete_ikev2_conf
|
2021-07-13 07:41:33 +03:00
|
|
|
if [ "$os_type" = "alpine" ]; then
|
|
|
|
ipsec auto --delete ikev2-cp
|
|
|
|
else
|
|
|
|
restart_ipsec_service
|
|
|
|
fi
|
2021-01-19 10:05:06 +03:00
|
|
|
delete_certificates
|
2021-04-18 22:27:52 +03:00
|
|
|
print_ikev2_removed
|
2021-01-19 10:05:06 +03:00
|
|
|
exit 0
|
|
|
|
;;
|
2021-02-02 07:38:42 +03:00
|
|
|
*)
|
2021-01-19 06:51:31 +03:00
|
|
|
exit 0
|
|
|
|
;;
|
|
|
|
esac
|
2021-01-18 09:01:46 +03:00
|
|
|
fi
|
|
|
|
|
2022-02-15 08:45:13 +03:00
|
|
|
check_cert_exists_and_exit "$CA_NAME"
|
2021-01-18 09:01:46 +03:00
|
|
|
|
2022-09-25 02:56:27 +03:00
|
|
|
if [ "$use_defaults" = 0 ]; then
|
2021-07-30 16:47:10 +03:00
|
|
|
show_header
|
2021-04-18 22:27:52 +03:00
|
|
|
show_welcome
|
2021-01-18 09:01:46 +03:00
|
|
|
enter_server_address
|
2021-07-30 16:47:10 +03:00
|
|
|
check_cert_exists_and_exit "$server_addr"
|
2022-02-15 08:45:13 +03:00
|
|
|
enter_client_name with_defaults
|
|
|
|
enter_client_validity
|
2021-01-18 09:01:46 +03:00
|
|
|
enter_custom_dns
|
|
|
|
check_mobike_support
|
|
|
|
select_mobike
|
2022-02-12 21:12:51 +03:00
|
|
|
select_config_password
|
2021-01-18 09:01:46 +03:00
|
|
|
confirm_setup_options
|
|
|
|
else
|
2021-02-10 10:19:17 +03:00
|
|
|
check_server_dns_name
|
|
|
|
check_custom_dns
|
2022-02-15 08:45:13 +03:00
|
|
|
check_and_set_client_name
|
2022-10-16 08:45:45 +03:00
|
|
|
check_and_set_client_validity
|
2021-07-31 23:31:13 +03:00
|
|
|
show_header
|
2021-04-18 22:27:52 +03:00
|
|
|
show_start_setup
|
2022-02-15 08:45:13 +03:00
|
|
|
set_server_address
|
|
|
|
set_dns_servers
|
2021-01-18 09:01:46 +03:00
|
|
|
check_mobike_support
|
|
|
|
mobike_enable="$mobike_support"
|
|
|
|
fi
|
|
|
|
|
2021-01-21 09:24:07 +03:00
|
|
|
apply_ubuntu1804_nss_fix
|
2021-02-14 10:10:38 +03:00
|
|
|
create_ca_server_certs
|
2021-01-18 09:01:46 +03:00
|
|
|
create_client_cert
|
2021-04-18 22:27:52 +03:00
|
|
|
export_client_config
|
2022-02-26 08:25:34 +03:00
|
|
|
create_config_readme
|
2021-01-18 09:01:46 +03:00
|
|
|
add_ikev2_connection
|
2021-07-13 07:41:33 +03:00
|
|
|
if [ "$os_type" = "alpine" ]; then
|
|
|
|
ipsec auto --add ikev2-cp >/dev/null
|
|
|
|
else
|
|
|
|
restart_ipsec_service
|
|
|
|
fi
|
2022-12-02 06:45:57 +03:00
|
|
|
check_ikev2_connection
|
2021-04-18 22:27:52 +03:00
|
|
|
print_setup_complete
|
2021-01-18 09:01:46 +03:00
|
|
|
print_client_info
|
2022-09-25 02:56:27 +03:00
|
|
|
if [ "$in_container" = 0 ]; then
|
2022-01-30 02:33:42 +03:00
|
|
|
check_swan_update
|
2022-01-29 10:30:21 +03:00
|
|
|
fi
|
2020-05-11 09:18:34 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
## Defer setup until we have the complete script
|
|
|
|
ikev2setup "$@"
|
|
|
|
|
|
|
|
exit 0
|