1
|
#!/usr/local/bin/php -f
|
2
|
<?php
|
3
|
/* $Id$ */
|
4
|
/*
|
5
|
openvpn.tls-verify.php
|
6
|
|
7
|
Copyright (C) 2011 Jim Pingle
|
8
|
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
|
DISABLE_PHP_LINT_CHECKING
|
32
|
*/
|
33
|
/*
|
34
|
pfSense_BUILDER_BINARIES:
|
35
|
pfSense_MODULE: openvpn
|
36
|
*/
|
37
|
/*
|
38
|
* OpenVPN calls this script to validate a certificate
|
39
|
* This script is called ONCE per DEPTH of the certificate chain
|
40
|
* Normal operation would have two runs - one for the server certificate
|
41
|
* and one for the client certificate. Beyond that, you're dealing with
|
42
|
* intermediates.
|
43
|
*/
|
44
|
|
45
|
require_once("globals.inc");
|
46
|
require_once("config.inc");
|
47
|
require_once("interfaces.inc");
|
48
|
|
49
|
openlog("openvpn", LOG_ODELAY, LOG_AUTH);
|
50
|
|
51
|
/* read data from command line */
|
52
|
if (isset($_GET)) {
|
53
|
$cert_depth = $_GET['certdepth'];
|
54
|
$cert_subject = urldecode($_GET['certsubject']);
|
55
|
$allowed_depth = $_GET['depth'];
|
56
|
$server_cn = $_GET['servercn'];
|
57
|
} else {
|
58
|
$cert_depth = intval($argv[1]);
|
59
|
$cert_subject = $argv[2];
|
60
|
}
|
61
|
|
62
|
/* Reserved for future use in case we decide to verify CNs and such as well
|
63
|
$subj = explode("/", $cert_subject);
|
64
|
foreach ($subj at $s) {
|
65
|
list($n, $v) = explode("=", $s);
|
66
|
if ($n == "CN")
|
67
|
$common_name = $v;
|
68
|
}
|
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
|
if (isset($_GET)) {
|
77
|
echo "FAILED";
|
78
|
closelog();
|
79
|
return;
|
80
|
} else {
|
81
|
closelog();
|
82
|
exit(1);
|
83
|
}
|
84
|
}
|
85
|
|
86
|
// Debug
|
87
|
//syslog(LOG_WARNING, "Found certificate {$argv[2]} with depth {$cert_depth}\n");
|
88
|
|
89
|
closelog();
|
90
|
if (isset($_GET))
|
91
|
echo "OK";
|
92
|
else
|
93
|
exit(0);
|
94
|
|
95
|
?>
|