Project

General

Profile

Download (25.8 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
    system_camanager.php
4

    
5
    Copyright (C) 2008 Shrew Soft Inc.
6
    Copyright (C) 2013-2014 Electric Sheep Fencing, LP
7
    All rights reserved.
8

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

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

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

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

    
34
##|+PRIV
35
##|*IDENT=page-system-camanager
36
##|*NAME=System: CA Manager
37
##|*DESCR=Allow access to the 'System: CA Manager' page.
38
##|*MATCH=system_camanager.php*
39
##|-PRIV
40

    
41
require("guiconfig.inc");
42
require_once("certs.inc");
43

    
44
$ca_methods = array(
45
	"existing" => gettext("Import an existing Certificate Authority"),
46
	"internal" => gettext("Create an internal Certificate Authority"),
47
	"intermediate" => gettext("Create an intermediate Certificate Authority"));
48

    
49
$ca_keylens = array( "512", "1024", "2048", "4096");
50
$openssl_digest_algs = array("sha1", "sha224", "sha256", "sha384", "sha512");
51

    
52
$pgtitle = array(gettext("System"), gettext("Certificate Authority Manager"));
53

    
54
if (is_numericint($_GET['id']))
55
	$id = $_GET['id'];
56
if (isset($_POST['id']) && is_numericint($_POST['id']))
57
	$id = $_POST['id'];
58

    
59
if (!is_array($config['ca']))
60
	$config['ca'] = array();
61

    
62
$a_ca =& $config['ca'];
63

    
64
if (!is_array($config['cert']))
65
	$config['cert'] = array();
66

    
67
$a_cert =& $config['cert'];
68

    
69
if (!is_array($config['crl']))
70
	$config['crl'] = array();
71

    
72
$a_crl =& $config['crl'];
73

    
74
$act = $_GET['act'];
75
if ($_POST['act'])
76
	$act = $_POST['act'];
77

    
78
if ($act == "del") {
79

    
80
	if (!isset($a_ca[$id])) {
81
		pfSenseHeader("system_camanager.php");
82
		exit;
83
	}
84

    
85
	$index = count($a_cert) - 1;
86
	for (;$index >=0; $index--)
87
		if ($a_cert[$index]['caref'] == $a_ca[$id]['refid'])
88
			unset($a_cert[$index]);
89

    
90
	$index = count($a_crl) - 1;
91
	for (;$index >=0; $index--)
92
		if ($a_crl[$index]['caref'] == $a_ca[$id]['refid'])
93
			unset($a_crl[$index]);
94

    
95
	$name = $a_ca[$id]['descr'];
96
	unset($a_ca[$id]);
97
	write_config();
98
	$savemsg = sprintf(gettext("Certificate Authority %s and its CRLs (if any) successfully deleted"), $name) . "<br />";
99
	pfSenseHeader("system_camanager.php");
100
	exit;
101
}
102

    
103
if ($act == "edit") {
104
	if (!$a_ca[$id]) {
105
		pfSenseHeader("system_camanager.php");
106
		exit;
107
	}
108
	$pconfig['descr']  = $a_ca[$id]['descr'];
109
	$pconfig['refid']  = $a_ca[$id]['refid'];
110
	$pconfig['cert']   = base64_decode($a_ca[$id]['crt']);
111
	$pconfig['serial'] = $a_ca[$id]['serial'];
112
	if (!empty($a_ca[$id]['prv']))
113
		$pconfig['key'] = base64_decode($a_ca[$id]['prv']);
114
}
115

    
116
if ($act == "new") {
117
	$pconfig['method'] = $_GET['method'];
118
	$pconfig['keylen'] = "2048";
119
	$pconfig['digest_alg'] = "sha256";
120
	$pconfig['lifetime'] = "3650";
121
	$pconfig['dn_commonname'] = "internal-ca";
122
}
123

    
124
if ($act == "exp") {
125

    
126
	if (!$a_ca[$id]) {
127
		pfSenseHeader("system_camanager.php");
128
		exit;
129
	}
130

    
131
	$exp_name = urlencode("{$a_ca[$id]['descr']}.crt");
132
	$exp_data = base64_decode($a_ca[$id]['crt']);
133
	$exp_size = strlen($exp_data);
134

    
135
	header("Content-Type: application/octet-stream");
136
	header("Content-Disposition: attachment; filename={$exp_name}");
137
	header("Content-Length: $exp_size");
138
	echo $exp_data;
139
	exit;
140
}
141

    
142
if ($act == "expkey") {
143

    
144
	if (!$a_ca[$id]) {
145
		pfSenseHeader("system_camanager.php");
146
		exit;
147
	}
148

    
149
	$exp_name = urlencode("{$a_ca[$id]['descr']}.key");
150
	$exp_data = base64_decode($a_ca[$id]['prv']);
151
	$exp_size = strlen($exp_data);
152

    
153
	header("Content-Type: application/octet-stream");
154
	header("Content-Disposition: attachment; filename={$exp_name}");
155
	header("Content-Length: $exp_size");
156
	echo $exp_data;
157
	exit;
158
}
159

    
160
if ($_POST) {
161

    
162
	unset($input_errors);
163
	$input_errors = array();
164
	$pconfig = $_POST;
165

    
166
	/* input validation */
167
	if ($pconfig['method'] == "existing") {
168
		$reqdfields = explode(" ", "descr cert");
169
		$reqdfieldsn = array(
170
				gettext("Descriptive name"),
171
				gettext("Certificate data"));
172
		if ($_POST['cert'] && (!strstr($_POST['cert'], "BEGIN CERTIFICATE") || !strstr($_POST['cert'], "END CERTIFICATE")))
173
			$input_errors[] = gettext("This certificate does not appear to be valid.");
174
		if ($_POST['key'] && strstr($_POST['key'], "ENCRYPTED"))
175
			$input_errors[] = gettext("Encrypted private keys are not yet supported.");
176
	}
177
	if ($pconfig['method'] == "internal") {
178
		$reqdfields = explode(" ",
179
				"descr keylen lifetime dn_country dn_state dn_city ".
180
				"dn_organization dn_email dn_commonname");
181
		$reqdfieldsn = array(
182
				gettext("Descriptive name"),
183
				gettext("Key length"),
184
				gettext("Lifetime"),
185
				gettext("Distinguished name Country Code"),
186
				gettext("Distinguished name State or Province"),
187
				gettext("Distinguished name City"),
188
				gettext("Distinguished name Organization"),
189
				gettext("Distinguished name Email Address"),
190
				gettext("Distinguished name Common Name"));
191
	}
192
	if ($pconfig['method'] == "intermediate") {
193
		$reqdfields = explode(" ",
194
				"descr caref keylen lifetime dn_country dn_state dn_city ".
195
				"dn_organization dn_email dn_commonname");
196
		$reqdfieldsn = array(
197
				gettext("Descriptive name"),
198
				gettext("Signing Certificate Authority"),
199
				gettext("Key length"),
200
				gettext("Lifetime"),
201
				gettext("Distinguished name Country Code"),
202
				gettext("Distinguished name State or Province"),
203
				gettext("Distinguished name City"),
204
				gettext("Distinguished name Organization"),
205
				gettext("Distinguished name Email Address"),
206
				gettext("Distinguished name Common Name"));
207
	}
208

    
209
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
210
	if ($pconfig['method'] != "existing") {
211
		/* Make sure we do not have invalid characters in the fields for the certificate */
212
		for ($i = 0; $i < count($reqdfields); $i++) {
213
			if ($reqdfields[$i] == 'dn_email'){
214
				if (preg_match("/[\!\#\$\%\^\(\)\~\?\>\<\&\/\\\,\"\']/", $_POST["dn_email"]))
215
					array_push($input_errors, "The field 'Distinguished name Email Address' contains invalid characters.");
216
			}else if ($reqdfields[$i] == 'dn_commonname'){
217
				if (preg_match("/[\!\@\#\$\%\^\(\)\~\?\>\<\&\/\\\,\"\']/", $_POST["dn_commonname"]))
218
					array_push($input_errors, "The field 'Distinguished name Common Name' contains invalid characters.");
219
			}else if (($reqdfields[$i] != "descr") && preg_match("/[\!\@\#\$\%\^\(\)\~\?\>\<\&\/\\\,\.\"\']/", $_POST["$reqdfields[$i]"]))
220
				array_push($input_errors, "The field '" . $reqdfieldsn[$i] . "' contains invalid characters.");
221
		}
222
		if (!in_array($_POST["keylen"], $ca_keylens))
223
			array_push($input_errors, gettext("Please select a valid Key Length."));
224
		if (!in_array($_POST["digest_alg"], $openssl_digest_algs))
225
			array_push($input_errors, gettext("Please select a valid Digest Algorithm."));
226
	}
227

    
228
	/* if this is an AJAX caller then handle via JSON */
229
	if (isAjax() && is_array($input_errors)) {
230
		input_errors2Ajax($input_errors);
231
		exit;
232
	}
233

    
234
	/* save modifications */
235
	if (!$input_errors) {
236

    
237
		$ca = array();
238
		if (!isset($pconfig['refid']) || empty($pconfig['refid']))
239
			$ca['refid'] = uniqid();
240
		else
241
			$ca['refid'] = $pconfig['refid'];
242

    
243
		if (isset($id) && $a_ca[$id])
244
			$ca = $a_ca[$id];
245

    
246
		$ca['descr'] = $pconfig['descr'];
247

    
248
		if ($_POST['edit'] == "edit") {
249
			$ca['descr']  = $pconfig['descr'];
250
			$ca['refid']  = $pconfig['refid'];
251
			$ca['serial'] = $pconfig['serial'];
252
			$ca['crt']    = base64_encode($pconfig['cert']);
253
			if (!empty($pconfig['key']))
254
				$ca['prv']    = base64_encode($pconfig['key']);
255
		} else {
256
			$old_err_level = error_reporting(0); /* otherwise openssl_ functions throw warings directly to a page screwing menu tab */
257
			if ($pconfig['method'] == "existing")
258
				ca_import($ca, $pconfig['cert'], $pconfig['key'], $pconfig['serial']);
259

    
260
			else if ($pconfig['method'] == "internal") {
261
				$dn = array(
262
					'countryName' => $pconfig['dn_country'],
263
					'stateOrProvinceName' => $pconfig['dn_state'],
264
					'localityName' => $pconfig['dn_city'],
265
					'organizationName' => $pconfig['dn_organization'],
266
					'emailAddress' => $pconfig['dn_email'],
267
					'commonName' => $pconfig['dn_commonname']);
268
				if (!ca_create($ca, $pconfig['keylen'], $pconfig['lifetime'], $dn, $pconfig['digest_alg'])){
269
					while($ssl_err = openssl_error_string()){
270
						$input_errors = array();
271
						array_push($input_errors, "openssl library returns: " . $ssl_err);
272
					}
273
				}
274
			}
275
			else if ($pconfig['method'] == "intermediate") {
276
				$dn = array(
277
					'countryName' => $pconfig['dn_country'],
278
					'stateOrProvinceName' => $pconfig['dn_state'],
279
					'localityName' => $pconfig['dn_city'],
280
					'organizationName' => $pconfig['dn_organization'],
281
					'emailAddress' => $pconfig['dn_email'],
282
					'commonName' => $pconfig['dn_commonname']);
283
				if (!ca_inter_create($ca, $pconfig['keylen'], $pconfig['lifetime'], $dn, $pconfig['caref'], $pconfig['digest_alg'])){
284
					while($ssl_err = openssl_error_string()){
285
						$input_errors = array();
286
						array_push($input_errors, "openssl library returns: " . $ssl_err);
287
					}
288
				}
289
			}
290
			error_reporting($old_err_level);
291
		}
292

    
293
		if (isset($id) && $a_ca[$id])
294
			$a_ca[$id] = $ca;
295
		else
296
			$a_ca[] = $ca;
297

    
298
		if (!$input_errors)
299
			write_config();
300

    
301
//		pfSenseHeader("system_camanager.php");
302
	}
303
}
304

    
305
include("head.inc");
306
?>
307

    
308
<body link="#000000" vlink="#000000" alink="#000000" onload="<?= $jsevents["body"]["onload"] ?>">
309
<?php include("fbegin.inc"); ?>
310
<script type="text/javascript">
311
//<![CDATA[
312

    
313
function method_change() {
314

    
315
	method = document.iform.method.selectedIndex;
316

    
317
	switch (method) {
318
		case 0:
319
			document.getElementById("existing").style.display="";
320
			document.getElementById("internal").style.display="none";
321
			document.getElementById("intermediate").style.display="none";
322
			break;
323
		case 1:
324
			document.getElementById("existing").style.display="none";
325
			document.getElementById("internal").style.display="";
326
			document.getElementById("intermediate").style.display="none";
327
			break;
328
		case 2:
329
			document.getElementById("existing").style.display="none";
330
			document.getElementById("internal").style.display="";
331
			document.getElementById("intermediate").style.display="";
332
			break;
333
	}
334
}
335

    
336
//]]>
337
</script>
338
<?php
339
	if ($input_errors)
340
		print_input_errors($input_errors);
341
	if ($savemsg)
342
		print_info_box($savemsg);
343

    
344
	// Load valid country codes
345
	$dn_cc = array();
346
	if (file_exists("/etc/ca_countries")){
347
		$dn_cc_file=file("/etc/ca_countries");
348
		foreach($dn_cc_file as $line)
349
			if (preg_match('/^(\S*)\s(.*)$/', $line, $matches))
350
				array_push($dn_cc, $matches[1]);
351
	}
352
?>
353
<table width="100%" border="0" cellpadding="0" cellspacing="0" summary="CA manager">
354
	<tr>
355
		<td>
356
		<?php
357
			$tab_array = array();
358
			$tab_array[] = array(gettext("CAs"), true, "system_camanager.php");
359
			$tab_array[] = array(gettext("Certificates"), false, "system_certmanager.php");
360
			$tab_array[] = array(gettext("Certificate Revocation"), false, "system_crlmanager.php");
361
			display_top_tabs($tab_array);
362
		?>
363
		</td>
364
	</tr>
365
	<tr>
366
		<td id="mainarea">
367
			<div class="tabcont">
368

    
369
				<?php if ($act == "new" || $act == "edit" || $act == gettext("Save") || $input_errors): ?>
370

    
371
				<form action="system_camanager.php" method="post" name="iform" id="iform">
372
					<?php if ($act == "edit"): ?>
373
					<input type="hidden" name="edit" value="edit" id="edit" />
374
					<input type="hidden" name="id" value="<?php echo htmlspecialchars($id); ?>" id="id" />
375
					<input type="hidden" name="refid" value="<?php echo $pconfig['refid']; ?>" id="refid" />
376
					<?php endif; ?>
377
					<table width="100%" border="0" cellpadding="6" cellspacing="0" summary="main area">
378
						<tr>
379
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Descriptive name");?></td>
380
							<td width="78%" class="vtable">
381
								<input name="descr" type="text" class="formfld unknown" id="descr" size="20" value="<?=htmlspecialchars($pconfig['descr']);?>"/>
382
							</td>
383
						</tr>
384
						<?php if (!isset($id) || $act == "edit"): ?>
385
						<tr>
386
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Method");?></td>
387
							<td width="78%" class="vtable">
388
								<select name='method' id='method' class="formselect" onchange='method_change()'>
389
								<?php
390
									foreach($ca_methods as $method => $desc):
391
									$selected = "";
392
									if ($pconfig['method'] == $method)
393
										$selected = " selected=\"selected\"";
394
								?>
395
									<option value="<?=$method;?>"<?=$selected;?>><?=$desc;?></option>
396
								<?php endforeach; ?>
397
								</select>
398
							</td>
399
						</tr>
400
						<?php endif; ?>
401
					</table>
402

    
403
					<table width="100%" border="0" cellpadding="6" cellspacing="0" id="existing" summary="existing">
404
						<tr>
405
							<td colspan="2" class="list" height="12"></td>
406
						</tr>
407
						<tr>
408
							<td colspan="2" valign="top" class="listtopic"><?=gettext("Existing Certificate Authority");?></td>
409
						</tr>
410

    
411
						<tr>
412
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Certificate data");?></td>
413
							<td width="78%" class="vtable">
414
								<textarea name="cert" id="cert" cols="65" rows="7" class="formfld_cert"><?=htmlspecialchars($pconfig['cert']);?></textarea>
415
								<br />
416
								<?=gettext("Paste a certificate in X.509 PEM format here.");?>
417
							</td>
418
						</tr>
419
						<tr>
420
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Certificate Private Key");?><br /><?=gettext("(optional)");?></td>
421
							<td width="78%" class="vtable">
422
								<textarea name="key" id="key" cols="65" rows="7" class="formfld_cert"><?=htmlspecialchars($pconfig['key']);?></textarea>
423
								<br />
424
								<?=gettext("Paste the private key for the above certificate here. This is optional in most cases, but required if you need to generate a Certificate Revocation List (CRL).");?>
425
							</td>
426
						</tr>
427

    
428
					<?php if (!isset($id) || $act == "edit"): ?>
429
						<tr>
430
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Serial for next certificate");?></td>
431
							<td width="78%" class="vtable">
432
								<input name="serial" type="text" class="formfld unknown" id="serial" size="20" value="<?=htmlspecialchars($pconfig['serial']);?>"/>
433
								<br /><?=gettext("Enter a decimal number to be used as the serial number for the next certificate to be created using this CA.");?>
434
							</td>
435
						</tr>
436
					<?php endif; ?>
437
					</table>
438

    
439
					<table width="100%" border="0" cellpadding="6" cellspacing="0" id="internal" summary="internal">
440
						<tr>
441
							<td colspan="2" class="list" height="12"></td>
442
						</tr>
443
						<tr>
444
							<td colspan="2" valign="top" class="listtopic"><?=gettext("Internal Certificate Authority");?></td>
445
						</tr>
446
						<tr id='intermediate'>
447
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Signing Certificate Authority");?></td>
448
							<td width="78%" class="vtable">
449
                                                                <select name='caref' id='caref' class="formselect" onchange='internalca_change()'>
450
                                                                <?php
451
                                                                        foreach( $a_ca as $ca):
452
                                                                        if (!$ca['prv'])
453
                                                                                continue;
454
                                                                        $selected = "";
455
                                                                        if ($pconfig['caref'] == $ca['refid'])
456
                                                                                $selected = " selected=\"selected\"";
457
                                                                ?>
458
                                                                        <option value="<?=$ca['refid'];?>"<?=$selected;?>><?=$ca['descr'];?></option>
459
                                                                <?php endforeach; ?>
460
                                                                </select>
461
							</td>
462
						</tr>
463
						<tr>
464
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Key length");?></td>
465
							<td width="78%" class="vtable">
466
								<select name='keylen' id='keylen' class="formselect">
467
								<?php
468
									foreach( $ca_keylens as $len):
469
									$selected = "";
470
									if ($pconfig['keylen'] == $len)
471
										$selected = " selected=\"selected\"";
472
								?>
473
									<option value="<?=$len;?>"<?=$selected;?>><?=$len;?></option>
474
								<?php endforeach; ?>
475
								</select>
476
								<?=gettext("bits");?>
477
							</td>
478
						</tr>
479
						<tr>
480
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Digest Algorithm");?></td>
481
							<td width="78%" class="vtable">
482
								<select name='digest_alg' id='digest_alg' class="formselect">
483
								<?php
484
									foreach( $openssl_digest_algs as $digest_alg):
485
									$selected = "";
486
									if ($pconfig['digest_alg'] == $digest_alg)
487
										$selected = " selected=\"selected\"";
488
								?>
489
									<option value="<?=$digest_alg;?>"<?=$selected;?>><?=strtoupper($digest_alg);?></option>
490
								<?php endforeach; ?>
491
								</select>
492
								<br /><?= gettext("NOTE: It is recommended to use an algorithm stronger than SHA1 when possible.") ?>
493
							</td>
494
						</tr>
495
						<tr>
496
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Lifetime");?></td>
497
							<td width="78%" class="vtable">
498
								<input name="lifetime" type="text" class="formfld unknown" id="lifetime" size="5" value="<?=htmlspecialchars($pconfig['lifetime']);?>"/>
499
								<?=gettext("days");?>
500
							</td>
501
						</tr>
502
						<tr>
503
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Distinguished name");?></td>
504
							<td width="78%" class="vtable">
505
								<table border="0" cellspacing="0" cellpadding="2" summary="name">
506
									<tr>
507
										<td align="right"><?=gettext("Country Code");?> : &nbsp;</td>
508
										<td align="left">
509
											<select name='dn_country' class="formselect">
510
											<?php
511
											foreach( $dn_cc as $cc){
512
												$selected = "";
513
												if ($pconfig['dn_country'] == $cc)
514
													$selected = " selected=\"selected\"";
515
												print "<option value=\"$cc\"$selected>$cc</option>";
516
												}
517
											?>
518
											</select>
519
										</td>
520
									</tr>
521
									<tr>
522
										<td align="right"><?=gettext("State or Province");?> : &nbsp;</td>
523
										<td align="left">
524
											<input name="dn_state" type="text" class="formfld unknown" size="40" value="<?=htmlspecialchars($pconfig['dn_state']);?>"/>
525
											&nbsp;
526
											<em><?=gettext("ex:");?></em>
527
											&nbsp;
528
											<?=gettext("Texas");?>
529
										</td>
530
									</tr>
531
									<tr>
532
										<td align="right"><?=gettext("City");?> : &nbsp;</td>
533
										<td align="left">
534
											<input name="dn_city" type="text" class="formfld unknown" size="40" value="<?=htmlspecialchars($pconfig['dn_city']);?>"/>
535
											&nbsp;
536
											<em><?=gettext("ex:");?></em>
537
											&nbsp;
538
											<?=gettext("Austin");?>
539
										</td>
540
									</tr>
541
									<tr>
542
										<td align="right"><?=gettext("Organization");?> : &nbsp;</td>
543
										<td align="left">
544
											<input name="dn_organization" type="text" class="formfld unknown" size="40" value="<?=htmlspecialchars($pconfig['dn_organization']);?>"/>
545
											&nbsp;
546
											<em><?=gettext("ex:");?></em>
547
											&nbsp;
548
											<?=gettext("My Company Inc.");?>
549
										</td>
550
									</tr>
551
									<tr>
552
										<td align="right"><?=gettext("Email Address");?> : &nbsp;</td>
553
										<td align="left">
554
											<input name="dn_email" type="text" class="formfld unknown" size="25" value="<?=htmlspecialchars($pconfig['dn_email']);?>"/>
555
											&nbsp;
556
											<em><?=gettext("ex:");?></em>
557
											&nbsp;
558
											<?=gettext("admin@mycompany.com");?>
559
										</td>
560
									</tr>
561
									<tr>
562
										<td align="right"><?=gettext("Common Name");?> : &nbsp;</td>
563
										<td align="left">
564
											<input name="dn_commonname" type="text" class="formfld unknown" size="25" value="<?=htmlspecialchars($pconfig['dn_commonname']);?>"/>
565
											&nbsp;
566
											<em><?=gettext("ex:");?></em>
567
											&nbsp;
568
											<?=gettext("internal-ca");?>
569
										</td>
570
									</tr>
571
								</table>
572
							</td>
573
						</tr>
574
					</table>
575

    
576
					<table width="100%" border="0" cellpadding="6" cellspacing="0" summary="save">
577
						<tr>
578
							<td width="22%" valign="top">&nbsp;</td>
579
							<td width="78%">
580
								<input id="submit" name="save" type="submit" class="formbtn" value="<?=gettext("Save"); ?>" />
581
								<?php if (isset($id) && $a_ca[$id]): ?>
582
								<input name="id" type="hidden" value="<?=htmlspecialchars($id);?>" />
583
								<?php endif;?>
584
							</td>
585
						</tr>
586
					</table>
587
				</form>
588

    
589
				<?php else: ?>
590

    
591
				<table width="100%" border="0" cellpadding="0" cellspacing="0" summary="">
592
					<tr>
593
						<td width="20%" class="listhdrr"><?=gettext("Name");?></td>
594
						<td width="10%" class="listhdrr"><?=gettext("Internal");?></td>
595
						<td width="10%" class="listhdrr"><?=gettext("Issuer");?></td>
596
						<td width="10%" class="listhdrr"><?=gettext("Certificates");?></td>
597
						<td width="40%" class="listhdrr"><?=gettext("Distinguished Name");?></td>
598
						<td width="10%" class="list"></td>
599
					</tr>
600
					<?php
601
						$i = 0;
602
						foreach($a_ca as $ca):
603
							$name = htmlspecialchars($ca['descr']);
604
							$subj = cert_get_subject($ca['crt']);
605
							$issuer = cert_get_issuer($ca['crt']);
606
							list($startdate, $enddate) = cert_get_dates($ca['crt']);
607
							if($subj == $issuer)
608
							  $issuer_name = "<em>" . gettext("self-signed") . "</em>";
609
							else
610
							  $issuer_name = "<em>" . gettext("external") . "</em>";
611
							$subj = htmlspecialchars($subj);
612
							$issuer = htmlspecialchars($issuer);
613
							$certcount = 0;
614

    
615
							$issuer_ca = lookup_ca($ca['caref']);
616
							if ($issuer_ca)
617
								$issuer_name = $issuer_ca['descr'];
618

    
619
							// TODO : Need gray certificate icon
620

    
621
							if($ca['prv']) {
622
								$caimg = "/themes/{$g['theme']}/images/icons/icon_frmfld_cert.png";
623
								$internal = "YES";
624

    
625
							} else {
626
								$caimg = "/themes/{$g['theme']}/images/icons/icon_frmfld_cert.png";
627
								$internal = "NO";
628
							}
629
							foreach ($a_cert as $cert)
630
								if ($cert['caref'] == $ca['refid'])
631
									$certcount++;
632
  						foreach ($a_ca as $cert)
633
  							if ($cert['caref'] == $ca['refid'])
634
  								$certcount++;
635
					?>
636
					<tr>
637
						<td class="listlr">
638
							<table border="0" cellpadding="0" cellspacing="0" summary="icon">
639
								<tr>
640
									<td align="left" valign="middle">
641
										<img src="<?=$caimg;?>" alt="CA" title="CA" border="0" height="16" width="16" />
642
									</td>
643
									<td align="left" valign="middle">
644
										<?=$name;?>
645
									</td>
646
								</tr>
647
							</table>
648
						</td>
649
						<td class="listr"><?=$internal;?>&nbsp;</td>
650
						<td class="listr"><?=$issuer_name;?>&nbsp;</td>
651
						<td class="listr"><?=$certcount;?>&nbsp;</td>
652
						<td class="listr"><?=$subj;?><br />
653
							<table width="100%" style="font-size: 9px" summary="valid">
654
								<tr>
655
									<td width="10%">&nbsp;</td>
656
									<td width="20%"><?=gettext("Valid From")?>:</td>
657
									<td width="70%"><?= $startdate ?></td>
658
								</tr>
659
								<tr>
660
									<td>&nbsp;</td>
661
									<td><?=gettext("Valid Until")?>:</td>
662
									<td><?= $enddate ?></td>
663
								</tr>
664
							</table>
665
						</td>
666
						<td valign="middle" class="list nowrap">
667
							<a href="system_camanager.php?act=edit&amp;id=<?=$i;?>">
668
								<img src="/themes/<?= $g['theme'];?>/images/icons/icon_e.gif" title="<?=gettext("edit CA");?>" alt="<?=gettext("edit CA");?>" width="17" height="17" border="0" />
669
							</a>
670
							<a href="system_camanager.php?act=exp&amp;id=<?=$i;?>">
671
								<img src="/themes/<?= $g['theme'];?>/images/icons/icon_down.gif" title="<?=gettext("export CA cert");?>" alt="<?=gettext("export CA cert");?>" width="17" height="17" border="0" />
672
							</a>
673
							<?php if ($ca['prv']): ?>
674
							<a href="system_camanager.php?act=expkey&amp;id=<?=$i;?>">
675
								<img src="/themes/<?= $g['theme'];?>/images/icons/icon_down.gif" title="<?=gettext("export CA private key");?>" alt="<?=gettext("export CA private key");?>" width="17" height="17" border="0" />
676
							</a>
677
							<?php endif; ?>
678
							<a href="system_camanager.php?act=del&amp;id=<?=$i;?>" onclick="return confirm('<?=gettext("Do you really want to delete this Certificate Authority and its CRLs, and unreference any associated certificates?");?>')">
679
								<img src="/themes/<?= $g['theme'];?>/images/icons/icon_x.gif" title="<?=gettext("delete ca");?>" alt="<?=gettext("delete ca"); ?>" width="17" height="17" border="0" />
680
							</a>
681
						</td>
682
					</tr>
683
					<?php
684
							$i++;
685
						endforeach;
686
					?>
687
					<tr>
688
						<td class="list" colspan="5"></td>
689
						<td class="list">
690
							<a href="system_camanager.php?act=new">
691
								<img src="/themes/<?= $g['theme'];?>/images/icons/icon_plus.gif" title="<?=gettext("add or import ca");?>" alt="<?=gettext("add ca");?>" width="17" height="17" border="0" />
692
							</a>
693
						</td>
694
					</tr>
695
					<tr>
696
						<td colspan="5">
697
							<p>
698
								<?=gettext("Additional trusted Certificate Authorities can be added here.");?>
699
							</p>
700
						</td>
701
					</tr>
702
				</table>
703

    
704
				<?php endif; ?>
705

    
706
			</div>
707
		</td>
708
	</tr>
709
</table>
710
<?php include("fend.inc");?>
711
<script type="text/javascript">
712
//<![CDATA[
713

    
714
method_change();
715

    
716
//]]>
717
</script>
718

    
719
</body>
720
</html>
(212-212/256)