Projet

Général

Profil

Télécharger (2,82 ko) Statistiques
| Branche: | Tag: | Révision:

univnautes / etc / inc / openvpn.tls-verify.php @ 340ce958

1
#!/usr/local/bin/php -f
2
<?php
3
/* $Id$ */
4
/*
5
	openvpn.tls-verify.php
6

    
7
	Copyright (C) 2011 Jim Pingle
8
        Copyright (C) 2013-2014 Electric Sheep Fencing, LP
9
	All rights reserved.
10

    
11
	Redistribution and use in source and binary forms, with or without
12
	modification, are permitted provided that the following conditions are met:
13

    
14
	1. Redistributions of source code must retain the above copyright notice,
15
	   this list of conditions and the following disclaimer.
16

    
17
	2. Redistributions in binary form must reproduce the above copyright
18
	   notice, this list of conditions and the following disclaimer in the
19
	   documentation and/or other materials provided with the distribution.
20

    
21
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
22
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
23
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
25
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30
	POSSIBILITY OF SUCH DAMAGE.
31

    
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
?>
(39-39/68)