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