Project

General

Profile

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

    
5
    Copyright (C) 2008 Shrew Soft Inc.
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-camanager
35
##|*NAME=System: CA Manager
36
##|*DESCR=Allow access to the 'System: CA Manager' page.
37
##|*MATCH=system_camanager.php*
38
##|-PRIV
39

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

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

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

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

    
53
$id = $_GET['id'];
54
if (isset($_POST['id']))
55
	$id = $_POST['id'];
56

    
57
if (!is_array($config['ca']))
58
	$config['ca'] = array();
59

    
60
$a_ca =& $config['ca'];
61

    
62
if (!is_array($config['cert']))
63
	$config['cert'] = array();
64

    
65
$a_cert =& $config['cert'];
66

    
67
if (!is_array($config['crl']))
68
	$config['crl'] = array();
69

    
70
$a_crl =& $config['crl'];
71

    
72
$act = $_GET['act'];
73
if ($_POST['act'])
74
	$act = $_POST['act'];
75

    
76
if ($act == "del") {
77

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

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

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

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

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

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

    
122
if ($act == "exp") {
123

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

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

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

    
140
if ($act == "expkey") {
141

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

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

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

    
158
if ($_POST) {
159

    
160
	unset($input_errors);
161
	$pconfig = $_POST;
162

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

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

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

    
231
	/* save modifications */
232
	if (!$input_errors) {
233

    
234
		$ca = array();
235
		if (!isset($pconfig['refid']) || empty($pconfig['refid']))
236
			$ca['refid'] = uniqid();
237
		else
238
			$ca['refid'] = $pconfig['refid'];
239

    
240
		if (isset($id) && $a_ca[$id])
241
			$ca = $a_ca[$id];
242

    
243
		$ca['descr'] = $pconfig['descr'];
244

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

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

    
290
		if (isset($id) && $a_ca[$id])
291
			$a_ca[$id] = $ca;
292
		else
293
			$a_ca[] = $ca;
294

    
295
		if (!$input_errors)
296
			write_config();
297

    
298
//		pfSenseHeader("system_camanager.php");
299
	}
300
}
301

    
302
include("head.inc");
303
?>
304

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

    
310
function method_change() {
311

    
312
	method = document.iform.method.selectedIndex;
313

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

    
333
//-->
334
</script>
335
<?php
336
	if ($input_errors)
337
		print_input_errors($input_errors);
338
	if ($savemsg)
339
		print_info_box($savemsg);
340

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

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

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

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

    
408
						<tr>
409
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Certificate data");?></td>
410
							<td width="78%" class="vtable">
411
								<textarea name="cert" id="cert" cols="65" rows="7" class="formfld_cert"><?=htmlspecialchars($pconfig['cert']);?></textarea>
412
								<br>
413
								<?=gettext("Paste a certificate in X.509 PEM format here.");?>
414
							</td>
415
						</tr>
416
						<tr>
417
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Certificate Private Key");?><br/><?=gettext("(optional)");?></td>
418
							<td width="78%" class="vtable">
419
								<textarea name="key" id="key" cols="65" rows="7" class="formfld_cert"><?=htmlspecialchars($pconfig['key']);?></textarea>
420
								<br>
421
								<?=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).");?>
422
							</td>
423
						</tr>
424

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

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

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

    
586
				<?php else: ?>
587

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

    
612
							$issuer_ca = lookup_ca($ca['caref']);
613
							if ($issuer_ca)
614
								$issuer_name = $issuer_ca['descr'];
615

    
616
							// TODO : Need gray certificate icon
617

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

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

    
701
				<?php endif; ?>
702

    
703
			</div>
704
		</td>
705
	</tr>
706
</table>
707
<?php include("fend.inc");?>
708
<script type="text/javascript">
709
<!--
710

    
711
method_change();
712

    
713
//-->
714
</script>
715

    
716
</body>
717
</html>
(203-203/246)