Project

General

Profile

Download (1.75 KB) Statistics
| Branch: | Tag: | Revision:
1
#!/bin/sh
2
#
3
# ovpn_auth_verify
4
#
5
# part of pfSense (https://www.pfsense.org)
6
# Copyright (c) 2004-2013 BSD Perimeter
7
# Copyright (c) 2013-2016 Electric Sheep Fencing
8
# Copyright (c) 2014-2025 Rubicon Communications, LLC (Netgate)
9
# All rights reserved.
10
#
11
# Licensed under the Apache License, Version 2.0 (the "License");
12
# you may not use this file except in compliance with the License.
13
# You may obtain a copy of the License at
14
#
15
# http://www.apache.org/licenses/LICENSE-2.0
16
#
17
# Unless required by applicable law or agreed to in writing, software
18
# distributed under the License is distributed on an "AS IS" BASIS,
19
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20
# See the License for the specific language governing permissions and
21
# limitations under the License.
22

    
23
if [ "$1" = "tls" ]; then
24
	for check_depth in $(/usr/bin/seq ${3} -1 0)
25
	do
26
		eval serial="\$tls_serial_${check_depth}"
27
		if [ -n "$serial" ]; then
28
			# $config contains the path, e.g. '/var/etc/openvpn/server1/config.ovpn'
29
			RESULT=$(/usr/local/sbin/fcgicli -f /etc/inc/openvpn.tls-verify.php -d "servercn=$2&depth=$3&certdepth=$4&certsubject=$5&serial=$serial&config=$config")
30
			if [ "${RESULT}" = "FAILED" ]; then
31
				exit 1
32
			fi
33
		fi
34
	done
35
else
36
	# Single quoting $password breaks getting the value from the variable.
37
	# Base64 and urlEncode usernames and passwords
38
	password=$(echo -n "${password}" | openssl enc -base64 | sed -e 's_=_%3D_g;s_+_%2B_g;s_/_%2F_g')
39
	username=$(echo -n "${username}" | openssl enc -base64 | sed -e 's_=_%3D_g;s_+_%2B_g;s_/_%2F_g')
40
	RESULT=$(/usr/local/sbin/fcgicli -f /etc/inc/openvpn.auth-user.php -d "username=$username&password=$password&cn=$common_name&strictcn=$3&authcfg=$2&modeid=$4&nas_port=$5")
41
fi
42

    
43
if [ "${RESULT}" = "OK" ]; then
44
	exit 0
45
fi
46

    
47
exit 1
(16-16/38)