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-2020 Rubicon Communications, LLC (Netgate)
|
8
|
* All rights reserved.
|
9
|
*
|
10
|
* 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
|
*
|
14
|
* http://www.apache.org/licenses/LICENSE-2.0
|
15
|
*
|
16
|
* 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
|
*/
|
22
|
|
23
|
/*
|
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
|
if (isset($_GET['certdepth'])) {
|
39
|
$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
|
|
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
|
if ($n == "CN") {
|
53
|
$common_name = $v;
|
54
|
}
|
55
|
}
|
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
|
if (isset($_GET['certdepth'])) {
|
64
|
echo "FAILED";
|
65
|
closelog();
|
66
|
return;
|
67
|
} else {
|
68
|
closelog();
|
69
|
exit(1);
|
70
|
}
|
71
|
}
|
72
|
|
73
|
// Debug
|
74
|
//syslog(LOG_WARNING, "Found certificate {$argv[2]} with depth {$cert_depth}\n");
|
75
|
|
76
|
closelog();
|
77
|
if (isset($_GET['certdepth'])) {
|
78
|
echo "OK";
|
79
|
} else {
|
80
|
exit(0);
|
81
|
}
|
82
|
|
83
|
?>
|