Project

General

Profile

Download (2.21 KB) Statistics
| Branch: | Tag: | Revision:
1 cb7d18d5 Renato Botelho
#!/usr/local/bin/php-cgi -f
2 98963f27 jim-p
<?php
3
/*
4 ac24dc24 Renato Botelho
 * openvpn.tls-verify.php
5
 *
6
 * part of pfSense (https://www.pfsense.org)
7 81299b5c Renato Botelho
 * Copyright (c) 2011-2016 Rubicon Communications, LLC (Netgate)
8 ac24dc24 Renato Botelho
 * All rights reserved.
9
 *
10 b12ea3fb Renato Botelho
 * Licensed under the Apache License, Version 2.0 (the "License");
11
 * you may not use this file except in compliance with the License.
12
 * You may obtain a copy of the License at
13 ac24dc24 Renato Botelho
 *
14 b12ea3fb Renato Botelho
 * http://www.apache.org/licenses/LICENSE-2.0
15 ac24dc24 Renato Botelho
 *
16 b12ea3fb Renato Botelho
 * Unless required by applicable law or agreed to in writing, software
17
 * distributed under the License is distributed on an "AS IS" BASIS,
18
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19
 * See the License for the specific language governing permissions and
20
 * limitations under the License.
21 ac24dc24 Renato Botelho
 */
22 09221bc3 Renato Botelho
23 98963f27 jim-p
/*
24
 * OpenVPN calls this script to validate a certificate
25
 *  This script is called ONCE per DEPTH of the certificate chain
26
 *  Normal operation would have two runs - one for the server certificate
27
 *  and one for the client certificate. Beyond that, you're dealing with
28
 *  intermediates.
29
 */
30
31
require_once("globals.inc");
32
require_once("config.inc");
33
require_once("interfaces.inc");
34
35
openlog("openvpn", LOG_ODELAY, LOG_AUTH);
36
37
/* read data from command line */
38 ed56ce5a Ermal LUÇI
if (isset($_GET['certdepth'])) {
39 b95b40a1 Ermal
	$cert_depth = $_GET['certdepth'];
40
	$cert_subject = urldecode($_GET['certsubject']);
41
	$allowed_depth = $_GET['depth'];
42
	$server_cn = $_GET['servercn'];
43
} else {
44
	$cert_depth = intval($argv[1]);
45
	$cert_subject = $argv[2];
46
}
47 98963f27 jim-p
48
/* Reserved for future use in case we decide to verify CNs and such as well
49
$subj = explode("/", $cert_subject);
50
foreach ($subj at $s) {
51
	list($n, $v) = explode("=", $s);
52 b37a2e8c Phil Davis
	if ($n == "CN") {
53 98963f27 jim-p
		$common_name = $v;
54 b37a2e8c Phil Davis
	}
55 98963f27 jim-p
}
56
*/
57
58
/* Replaced by sed with proper variables used below ( $server_cn and $allowed_depth ). */
59
//<template>
60
61
if (isset($allowed_depth) && ($cert_depth > $allowed_depth)) {
62
	syslog(LOG_WARNING, "Certificate depth {$cert_depth} exceeded max allowed depth of {$allowed_depth}.\n");
63 ed56ce5a Ermal LUÇI
	if (isset($_GET['certdepth'])) {
64 b95b40a1 Ermal
		echo "FAILED";
65
		closelog();
66
		return;
67
	} else {
68
		closelog();
69
		exit(1);
70
	}
71 98963f27 jim-p
}
72
73
// Debug
74 aa291f19 jim-p
//syslog(LOG_WARNING, "Found certificate {$argv[2]} with depth {$cert_depth}\n");
75 98963f27 jim-p
76 b95b40a1 Ermal
closelog();
77 b37a2e8c Phil Davis
if (isset($_GET['certdepth'])) {
78 b95b40a1 Ermal
	echo "OK";
79 b37a2e8c Phil Davis
} else {
80 b95b40a1 Ermal
	exit(0);
81 b37a2e8c Phil Davis
}
82 98963f27 jim-p
83
?>