1
|
<?php
|
2
|
/*
|
3
|
system_crlmanager.php
|
4
|
|
5
|
Copyright (C) 2010 Jim Pingle
|
6
|
All rights reserved.
|
7
|
|
8
|
Redistribution and use in source and binary forms, with or without
|
9
|
modification, are permitted provided that the following conditions are met:
|
10
|
|
11
|
1. Redistributions of source code must retain the above copyright notice,
|
12
|
this list of conditions and the following disclaimer.
|
13
|
|
14
|
2. Redistributions in binary form must reproduce the above copyright
|
15
|
notice, this list of conditions and the following disclaimer in the
|
16
|
documentation and/or other materials provided with the distribution.
|
17
|
|
18
|
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
19
|
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
20
|
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
21
|
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
22
|
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
23
|
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
24
|
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
25
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
26
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
27
|
POSSIBILITY OF SUCH DAMAGE.
|
28
|
*/
|
29
|
/*
|
30
|
pfSense_MODULE: certificate_managaer
|
31
|
*/
|
32
|
|
33
|
##|+PRIV
|
34
|
##|*IDENT=page-system-crlmanager
|
35
|
##|*NAME=System: CRL Manager
|
36
|
##|*DESCR=Allow access to the 'System: CRL Manager' page.
|
37
|
##|*MATCH=system_crlmanager.php*
|
38
|
##|-PRIV
|
39
|
|
40
|
require("guiconfig.inc");
|
41
|
require_once("certs.inc");
|
42
|
|
43
|
$pgtitle = array(gettext("System"), gettext("Certificate Revocation List Manager"));
|
44
|
|
45
|
$crl_methods = array(
|
46
|
"internal" => gettext("Create an internal Certificate Revocation List"),
|
47
|
"existing" => gettext("Import an existing Certificate Revocation List"));
|
48
|
|
49
|
$id = $_GET['id'];
|
50
|
if (isset($_POST['id']))
|
51
|
$id = $_POST['id'];
|
52
|
|
53
|
if (!is_array($config['ca']))
|
54
|
$config['ca'] = array();
|
55
|
|
56
|
$a_ca =& $config['ca'];
|
57
|
|
58
|
if (!is_array($config['cert']))
|
59
|
$config['cert'] = array();
|
60
|
|
61
|
$a_cert =& $config['cert'];
|
62
|
|
63
|
if (!is_array($config['crl']))
|
64
|
$config['crl'] = array();
|
65
|
|
66
|
$a_crl =& $config['crl'];
|
67
|
|
68
|
$act = $_GET['act'];
|
69
|
if ($_POST['act'])
|
70
|
$act = $_POST['act'];
|
71
|
|
72
|
if ($act == "del") {
|
73
|
|
74
|
if (!$a_crl[$id]) {
|
75
|
pfSenseHeader("system_crlmanager.php");
|
76
|
exit;
|
77
|
}
|
78
|
if (crl_in_use($a_crl[$id]['refid'])) {
|
79
|
$savemsg = sprintf(gettext("Certificate Revocation List %s is in use and cannot be deleted"), $name) . "<br/>";
|
80
|
} else {
|
81
|
$name = $a_crl[$id]['name'];
|
82
|
unset($a_crl[$id]);
|
83
|
write_config();
|
84
|
$savemsg = sprintf(gettext("Certificate Revocation List %s successfully deleted"), $name) . "<br/>";
|
85
|
}
|
86
|
}
|
87
|
|
88
|
if ($act == "new") {
|
89
|
$pconfig['method'] = $_GET['method'];
|
90
|
$pconfig['caref'] = $_GET['caref'];
|
91
|
$pconfig['lifetime'] = "9999";
|
92
|
$pconfig['serial'] = "0";
|
93
|
}
|
94
|
|
95
|
if ($act == "exp") {
|
96
|
|
97
|
if (!$a_crl[$id]) {
|
98
|
pfSenseHeader("system_crlmanager.php");
|
99
|
exit;
|
100
|
}
|
101
|
|
102
|
$exp_name = urlencode("{$a_crl[$id]['name']}.crl");
|
103
|
$exp_data = base64_decode($a_crl[$id]['text']);
|
104
|
$exp_size = strlen($exp_data);
|
105
|
|
106
|
header("Content-Type: application/octet-stream");
|
107
|
header("Content-Disposition: attachment; filename={$exp_name}");
|
108
|
header("Content-Length: $exp_size");
|
109
|
echo $exp_data;
|
110
|
exit;
|
111
|
}
|
112
|
|
113
|
if ($_POST) {
|
114
|
|
115
|
unset($input_errors);
|
116
|
$pconfig = $_POST;
|
117
|
|
118
|
/* input validation */
|
119
|
if ($pconfig['method'] == "existing") {
|
120
|
$reqdfields = explode(" ", "name crltext");
|
121
|
$reqdfieldsn = array(
|
122
|
gettext("Descriptive name"),
|
123
|
gettext("Certificate Revocation List data"));
|
124
|
}
|
125
|
if ($pconfig['method'] == "internal") {
|
126
|
$reqdfields = explode(" ",
|
127
|
"name caref");
|
128
|
$reqdfieldsn = array(
|
129
|
gettext("Descriptive name"),
|
130
|
gettext("Certificate Authority"));
|
131
|
}
|
132
|
|
133
|
do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
|
134
|
|
135
|
/* if this is an AJAX caller then handle via JSON */
|
136
|
if (isAjax() && is_array($input_errors)) {
|
137
|
input_errors2Ajax($input_errors);
|
138
|
exit;
|
139
|
}
|
140
|
|
141
|
/* save modifications */
|
142
|
if (!$input_errors) {
|
143
|
$result = false;
|
144
|
|
145
|
$crl = array();
|
146
|
$crl['refid'] = uniqid();
|
147
|
if (isset($id) && $a_crl[$id])
|
148
|
$crl = $a_crl[$id];
|
149
|
|
150
|
$crl['name'] = $pconfig['name'];
|
151
|
$crl['caref'] = $pconfig['caref'];
|
152
|
|
153
|
if ($pconfig['method'] == "existing") {
|
154
|
$crl['text'] == base64_encode($pconfig['crltext']);
|
155
|
}
|
156
|
|
157
|
if ($pconfig['method'] == "internal") {
|
158
|
$crl['serial'] = empty($pconfig['serial']) ? 9999 : $pconfig['serial'];
|
159
|
$crl['lifetime'] = empty($pconfig['lifetime']) ? 9999 : $pconfig['lifetime'];
|
160
|
$crl['cert'] = array();
|
161
|
}
|
162
|
|
163
|
if (isset($id) && $a_crl[$id])
|
164
|
$a_crl[$id] = $crl;
|
165
|
else
|
166
|
$a_crl[] = $crl;
|
167
|
|
168
|
write_config();
|
169
|
|
170
|
pfSenseHeader("system_crlmanager.php");
|
171
|
}
|
172
|
}
|
173
|
|
174
|
include("head.inc");
|
175
|
?>
|
176
|
|
177
|
<body link="#000000" vlink="#000000" alink="#000000" onload="<?= $jsevents["body"]["onload"] ?>">
|
178
|
<?php include("fbegin.inc"); ?>
|
179
|
<script type="text/javascript">
|
180
|
<!--
|
181
|
|
182
|
function method_change() {
|
183
|
|
184
|
method = document.iform.method.selectedIndex;
|
185
|
|
186
|
switch (method) {
|
187
|
case 0:
|
188
|
document.getElementById("existing").style.display="none";
|
189
|
document.getElementById("internal").style.display="";
|
190
|
break;
|
191
|
case 1:
|
192
|
document.getElementById("existing").style.display="";
|
193
|
document.getElementById("internal").style.display="none";
|
194
|
break;
|
195
|
}
|
196
|
}
|
197
|
|
198
|
//-->
|
199
|
</script>
|
200
|
<?php
|
201
|
if ($input_errors)
|
202
|
print_input_errors($input_errors);
|
203
|
if ($savemsg)
|
204
|
print_info_box($savemsg);
|
205
|
?>
|
206
|
NOTE: This page is still a work in progress and is not yet fully functional.
|
207
|
<table width="100%" border="0" cellpadding="0" cellspacing="0">
|
208
|
<tr>
|
209
|
<td>
|
210
|
<?php
|
211
|
$tab_array = array();
|
212
|
$tab_array[] = array(gettext("CAs"), false, "system_camanager.php");
|
213
|
$tab_array[] = array(gettext("Certificates"), false, "system_certmanager.php");
|
214
|
$tab_array[] = array(gettext("Certificate Revocation"), true, "system_crlmanager.php");
|
215
|
display_top_tabs($tab_array);
|
216
|
?>
|
217
|
</td>
|
218
|
</tr>
|
219
|
<tr>
|
220
|
<td id="mainarea">
|
221
|
<div class="tabcont">
|
222
|
|
223
|
<?php if ($act == "new" || $act == gettext("Save") || $input_errors): ?>
|
224
|
|
225
|
<form action="system_crlmanager.php" method="post" name="iform" id="iform">
|
226
|
<table width="100%" border="0" cellpadding="6" cellspacing="0">
|
227
|
<?php if (!isset($id)): ?>
|
228
|
<tr>
|
229
|
<td width="22%" valign="top" class="vncellreq"><?=gettext("Method");?></td>
|
230
|
<td width="78%" class="vtable">
|
231
|
<select name='method' id='method' class="formselect" onchange='method_change()'>
|
232
|
<?php
|
233
|
foreach($crl_methods as $method => $desc):
|
234
|
$selected = "";
|
235
|
if ($pconfig['method'] == $method)
|
236
|
$selected = "selected";
|
237
|
?>
|
238
|
<option value="<?=$method;?>"<?=$selected;?>><?=$desc;?></option>
|
239
|
<?php endforeach; ?>
|
240
|
</select>
|
241
|
</td>
|
242
|
</tr>
|
243
|
<?php endif; ?>
|
244
|
<tr>
|
245
|
<td width="22%" valign="top" class="vncellreq"><?=gettext("Descriptive name");?></td>
|
246
|
<td width="78%" class="vtable">
|
247
|
<input name="name" type="text" class="formfld unknown" id="name" size="20" value="<?=htmlspecialchars($pconfig['name']);?>"/>
|
248
|
</td>
|
249
|
</tr>
|
250
|
<tr>
|
251
|
<td width="22%" valign="top" class="vncellreq"><?=gettext("Certificate Authority");?></td>
|
252
|
<td width="78%" class="vtable">
|
253
|
<select name='caref' id='caref' class="formselect">
|
254
|
<?php
|
255
|
foreach($a_ca as $ca):
|
256
|
$selected = "";
|
257
|
if ($pconfig['caref'] == $ca['refid'])
|
258
|
$selected = "selected";
|
259
|
?>
|
260
|
<option value="<?=$ca['refid'];?>"<?=$selected;?>><?=$ca['name'];?></option>
|
261
|
<?php endforeach; ?>
|
262
|
</select>
|
263
|
</td>
|
264
|
</tr>
|
265
|
</table>
|
266
|
|
267
|
<table width="100%" border="0" cellpadding="6" cellspacing="0" id="existing">
|
268
|
<tr>
|
269
|
<td colspan="2" class="list" height="12"></td>
|
270
|
</tr>
|
271
|
<tr>
|
272
|
<td colspan="2" valign="top" class="listtopic"><?=gettext("Existing Certificate Revocation List");?></td>
|
273
|
</tr>
|
274
|
|
275
|
<tr>
|
276
|
<td width="22%" valign="top" class="vncellreq"><?=gettext("CRL data");?></td>
|
277
|
<td width="78%" class="vtable">
|
278
|
<textarea name="cert" id="cert" cols="65" rows="7" class="formfld_crl"><?=$pconfig['crltext'];?></textarea>
|
279
|
<br>
|
280
|
<?=gettext("Paste a Certificate Revocation List in X.509 CRL format here.");?></td>
|
281
|
</td>
|
282
|
</tr>
|
283
|
</table>
|
284
|
|
285
|
<table width="100%" border="0" cellpadding="6" cellspacing="0" id="internal">
|
286
|
<tr>
|
287
|
<td colspan="2" class="list" height="12"></td>
|
288
|
</tr>
|
289
|
<tr>
|
290
|
<td colspan="2" valign="top" class="listtopic"><?=gettext("Internal Certificate Revocation List");?></td>
|
291
|
</tr>
|
292
|
<tr>
|
293
|
<td width="22%" valign="top" class="vncellreq"><?=gettext("Lifetime");?></td>
|
294
|
<td width="78%" class="vtable">
|
295
|
<input name="lifetime" type="text" class="formfld unknown" id="lifetime" size="5" value="<?=htmlspecialchars($pconfig['lifetime']);?>"/>
|
296
|
<?=gettext("days");?><br/>
|
297
|
<?=gettext("Default: 9999");?>
|
298
|
</td>
|
299
|
</tr>
|
300
|
<tr>
|
301
|
<td width="22%" valign="top" class="vncellreq"><?=gettext("Serial");?></td>
|
302
|
<td width="78%" class="vtable">
|
303
|
<input name="lifetime" type="text" class="formfld unknown" id="lifetime" size="5" value="<?=htmlspecialchars($pconfig['serial']);?>"/>
|
304
|
<br/>
|
305
|
<?=gettext("Default: 0");?>
|
306
|
</td>
|
307
|
</tr>
|
308
|
</table>
|
309
|
|
310
|
<table width="100%" border="0" cellpadding="6" cellspacing="0">
|
311
|
<tr>
|
312
|
<td width="22%" valign="top"> </td>
|
313
|
<td width="78%">
|
314
|
<input id="submit" name="save" type="submit" class="formbtn" value="<?=gettext("Save"); ?>" />
|
315
|
<?php if (isset($id) && $a_crl[$id]): ?>
|
316
|
<input name="id" type="hidden" value="<?=$id;?>" />
|
317
|
<?php endif;?>
|
318
|
</td>
|
319
|
</tr>
|
320
|
</table>
|
321
|
</form>
|
322
|
|
323
|
<?php else: ?>
|
324
|
|
325
|
<table width="100%" border="0" cellpadding="0" cellspacing="0">
|
326
|
<thead>
|
327
|
<tr>
|
328
|
<td width="35%" class="listhdrr"><?=gettext("Name");?></td>
|
329
|
<td width="10%" class="listhdrr"><?=gettext("Internal");?></td>
|
330
|
<td width="35%" class="listhdrr"><?=gettext("Certificates");?></td>
|
331
|
<td width="10%" class="listhdrr"><?=gettext("In Use");?></td>
|
332
|
<td width="10%" class="list"></td>
|
333
|
</tr>
|
334
|
</thead>
|
335
|
<tbody>
|
336
|
<?php
|
337
|
// Map CRLs to GWs in one pass
|
338
|
$ca_crl_map = array();
|
339
|
foreach($a_crl as $crl)
|
340
|
$ca_crl_map[$crl['caref']][] = $crl['refid'];
|
341
|
|
342
|
$i = 0;
|
343
|
foreach($a_ca as $ca):
|
344
|
$name = htmlspecialchars($ca['name']);
|
345
|
|
346
|
if($ca['prv']) {
|
347
|
$caimg = "/themes/{$g['theme']}/images/icons/icon_frmfld_cert.png";
|
348
|
$internal = "YES";
|
349
|
} else
|
350
|
continue;
|
351
|
?>
|
352
|
<tr>
|
353
|
<td class="listlr" colspan="4">
|
354
|
<table border="0" cellpadding="0" cellspacing="0">
|
355
|
<tr>
|
356
|
<td align="left" valign="center">
|
357
|
<img src="<?=$caimg;?>" alt="CA" title="CA" border="0" height="16" width="16" />
|
358
|
</td>
|
359
|
<td align="left" valign="middle">
|
360
|
<?=$name;?>
|
361
|
</td>
|
362
|
</tr>
|
363
|
</table>
|
364
|
</td>
|
365
|
<td class="list">
|
366
|
<a href="system_crlmanager.php?act=new&caref=<?php echo $ca['refid']; ?>">
|
367
|
<img src="/themes/<?= $g['theme'];?>/images/icons/icon_plus.gif" title="<?=gettext("Add or Import CRL for ") . $ca['name'];?>" alt="<?=gettext("add crl");?>" width="17" height="17" border="0" />
|
368
|
</a>
|
369
|
</td>
|
370
|
</tr>
|
371
|
|
372
|
<?php
|
373
|
if (is_array($ca_crl_map[$ca['refid']])):
|
374
|
foreach($ca_crl_map[$ca['refid']] as $crl):
|
375
|
$tmpcrl = lookup_crl($crl);
|
376
|
$internal = is_crl_internal($tmpcrl);
|
377
|
$inuse = crl_in_use($tmpcrl['refid']);
|
378
|
?>
|
379
|
<tr>
|
380
|
<td class="listlr"><?php echo $tmpcrl['name']; ?></td>
|
381
|
<td class="listr"><?php echo ($internal) ? "YES" : "NO"; ?></td>
|
382
|
<td class="listr"><?php echo ($internal) ? count($tmpcrl['cert']) : "Unknown (imported)"; ?></td>
|
383
|
<td class="listr"><?php echo ($inuse) ? "YES" : "NO"; ?></td>
|
384
|
<td valign="middle" nowrap class="list">
|
385
|
<a href="system_crlmanager.php?act=exp&id=<?=$i;?>")">
|
386
|
<img src="/themes/<?= $g['theme'];?>/images/icons/icon_down.gif" title="<?=gettext("Export CRL") . " " . htmlspecialchars($tmpcrl['name']);?>" alt="<?=gettext("Export CRL") . " " . htmlspecialchars($tmpcrl['name']);?>" width="17" height="17" border="0" />
|
387
|
</a>
|
388
|
<?php if (!$inuse): ?>
|
389
|
<a href="system_crlmanager.php?act=del&id=<?=$i;?>" onclick="return confirm('<?=gettext("Do you really want to delete this Certificate Revocation List?") . ' (' . htmlspecialchars($tmpcrl['name']) . ')';?>')">
|
390
|
<img src="/themes/<?= $g['theme'];?>/images/icons/icon_x.gif" title="<?=gettext("Delete CRL") . " " . htmlspecialchars($tmpcrl['name']);?>" alt="<?=gettext("Delete CRL") . " " . htmlspecialchars($tmpcrl['name']); ?>" width="17" height="17" border="0" />
|
391
|
</a>
|
392
|
<?php endif; ?>
|
393
|
</td>
|
394
|
</tr>
|
395
|
<?php
|
396
|
$i++;
|
397
|
endforeach;
|
398
|
endif;
|
399
|
?>
|
400
|
<tr><td colspan="5"> </td></tr>
|
401
|
<?php
|
402
|
$i++;
|
403
|
endforeach;
|
404
|
?>
|
405
|
</tbody>
|
406
|
<tfoot>
|
407
|
<tr>
|
408
|
<td colspan="5">
|
409
|
<p>
|
410
|
<?=gettext("Additional Certificate Revocation Lists can be added here.");?>
|
411
|
</p>
|
412
|
</td>
|
413
|
</tr>
|
414
|
</tfoot>
|
415
|
</table>
|
416
|
|
417
|
<?php endif; ?>
|
418
|
|
419
|
</div>
|
420
|
</td>
|
421
|
</tr>
|
422
|
</table>
|
423
|
<?php include("fend.inc");?>
|
424
|
<script type="text/javascript">
|
425
|
<!--
|
426
|
|
427
|
method_change();
|
428
|
|
429
|
//-->
|
430
|
</script>
|
431
|
|
432
|
</body>
|