Project

General

Profile

Download (2.86 KB) Statistics
| Branch: | Tag: | Revision:
1 cb7d18d5 Renato Botelho
#!/usr/local/bin/php-cgi -f
2 98963f27 jim-p
<?php
3
/*
4
	openvpn.tls-verify.php
5
6
	Copyright (C) 2011 Jim Pingle
7 ce77a9c4 Phil Davis
	Copyright (C) 2013-2015 Electric Sheep Fencing, LP
8 98963f27 jim-p
	All rights reserved.
9
10
	Redistribution and use in source and binary forms, with or without
11
	modification, are permitted provided that the following conditions are met:
12
13
	1. Redistributions of source code must retain the above copyright notice,
14
	   this list of conditions and the following disclaimer.
15
16
	2. Redistributions in binary form must reproduce the above copyright
17
	   notice, this list of conditions and the following disclaimer in the
18
	   documentation and/or other materials provided with the distribution.
19
20
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
21
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
22
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
24
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29
	POSSIBILITY OF SUCH DAMAGE.
30
31
*/
32
/*
33 b37a2e8c Phil Davis
	pfSense_BUILDER_BINARIES:
34 98963f27 jim-p
	pfSense_MODULE:	openvpn
35
*/
36
/*
37
 * OpenVPN calls this script to validate a certificate
38
 *  This script is called ONCE per DEPTH of the certificate chain
39
 *  Normal operation would have two runs - one for the server certificate
40
 *  and one for the client certificate. Beyond that, you're dealing with
41
 *  intermediates.
42
 */
43
44
require_once("globals.inc");
45
require_once("config.inc");
46
require_once("interfaces.inc");
47
48
openlog("openvpn", LOG_ODELAY, LOG_AUTH);
49
50
/* read data from command line */
51 ed56ce5a Ermal LUÇI
if (isset($_GET['certdepth'])) {
52 b95b40a1 Ermal
	$cert_depth = $_GET['certdepth'];
53
	$cert_subject = urldecode($_GET['certsubject']);
54
	$allowed_depth = $_GET['depth'];
55
	$server_cn = $_GET['servercn'];
56
} else {
57
	$cert_depth = intval($argv[1]);
58
	$cert_subject = $argv[2];
59
}
60 98963f27 jim-p
61
/* Reserved for future use in case we decide to verify CNs and such as well
62
$subj = explode("/", $cert_subject);
63
foreach ($subj at $s) {
64
	list($n, $v) = explode("=", $s);
65 b37a2e8c Phil Davis
	if ($n == "CN") {
66 98963f27 jim-p
		$common_name = $v;
67 b37a2e8c Phil Davis
	}
68 98963f27 jim-p
}
69
*/
70
71
/* Replaced by sed with proper variables used below ( $server_cn and $allowed_depth ). */
72
//<template>
73
74
if (isset($allowed_depth) && ($cert_depth > $allowed_depth)) {
75
	syslog(LOG_WARNING, "Certificate depth {$cert_depth} exceeded max allowed depth of {$allowed_depth}.\n");
76 ed56ce5a Ermal LUÇI
	if (isset($_GET['certdepth'])) {
77 b95b40a1 Ermal
		echo "FAILED";
78
		closelog();
79
		return;
80
	} else {
81
		closelog();
82
		exit(1);
83
	}
84 98963f27 jim-p
}
85
86
// Debug
87 aa291f19 jim-p
//syslog(LOG_WARNING, "Found certificate {$argv[2]} with depth {$cert_depth}\n");
88 98963f27 jim-p
89 b95b40a1 Ermal
closelog();
90 b37a2e8c Phil Davis
if (isset($_GET['certdepth'])) {
91 b95b40a1 Ermal
	echo "OK";
92 b37a2e8c Phil Davis
} else {
93 b95b40a1 Ermal
	exit(0);
94 b37a2e8c Phil Davis
}
95 98963f27 jim-p
96
?>