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 |
38809d47
|
Renato Botelho do Couto
|
* Copyright (c) 2011-2013 BSD Perimeter
|
8 |
|
|
* Copyright (c) 2013-2016 Electric Sheep Fencing
|
9 |
|
|
* Copyright (c) 2014-2019 Rubicon Communications, LLC (Netgate)
|
10 |
ac24dc24
|
Renato Botelho
|
* All rights reserved.
|
11 |
|
|
*
|
12 |
b12ea3fb
|
Renato Botelho
|
* 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 |
ac24dc24
|
Renato Botelho
|
*
|
16 |
b12ea3fb
|
Renato Botelho
|
* http://www.apache.org/licenses/LICENSE-2.0
|
17 |
ac24dc24
|
Renato Botelho
|
*
|
18 |
b12ea3fb
|
Renato Botelho
|
* 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 |
ac24dc24
|
Renato Botelho
|
*/
|
24 |
09221bc3
|
Renato Botelho
|
|
25 |
98963f27
|
jim-p
|
/*
|
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 |
ed56ce5a
|
Ermal LUÇI
|
if (isset($_GET['certdepth'])) {
|
41 |
b95b40a1
|
Ermal
|
$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 |
98963f27
|
jim-p
|
|
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 |
b37a2e8c
|
Phil Davis
|
if ($n == "CN") {
|
55 |
98963f27
|
jim-p
|
$common_name = $v;
|
56 |
b37a2e8c
|
Phil Davis
|
}
|
57 |
98963f27
|
jim-p
|
}
|
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 |
882af7b4
|
jim-p
|
syslog(LOG_WARNING, "Certificate depth {$cert_depth} exceeded max allowed depth of {$allowed_depth}.");
|
65 |
ed56ce5a
|
Ermal LUÇI
|
if (isset($_GET['certdepth'])) {
|
66 |
b95b40a1
|
Ermal
|
echo "FAILED";
|
67 |
|
|
closelog();
|
68 |
|
|
return;
|
69 |
|
|
} else {
|
70 |
|
|
closelog();
|
71 |
|
|
exit(1);
|
72 |
|
|
}
|
73 |
98963f27
|
jim-p
|
}
|
74 |
|
|
|
75 |
|
|
// Debug
|
76 |
882af7b4
|
jim-p
|
//syslog(LOG_WARNING, "Found certificate {$argv[2]} with depth {$cert_depth}");
|
77 |
98963f27
|
jim-p
|
|
78 |
b95b40a1
|
Ermal
|
closelog();
|
79 |
b37a2e8c
|
Phil Davis
|
if (isset($_GET['certdepth'])) {
|
80 |
b95b40a1
|
Ermal
|
echo "OK";
|
81 |
b37a2e8c
|
Phil Davis
|
} else {
|
82 |
b95b40a1
|
Ermal
|
exit(0);
|
83 |
b37a2e8c
|
Phil Davis
|
}
|
84 |
98963f27
|
jim-p
|
|
85 |
|
|
?>
|