Project

General

Profile

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

    
5
	Copyright (C) 2008 Shrew Soft Inc.
6
	Copyright (C) 2013-2015 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_manager
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"), htmlspecialchars($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
		if (preg_match("/[\?\>\<\&\/\\\"\']/", $_POST['descr'])) {
213
			array_push($input_errors, "The field 'Descriptive Name' contains invalid characters.");
214
		}
215

    
216
		for ($i = 0; $i < count($reqdfields); $i++) {
217
			if ($reqdfields[$i] == 'dn_email'){
218
				if (preg_match("/[\!\#\$\%\^\(\)\~\?\>\<\&\/\\\,\"\']/", $_POST["dn_email"]))
219
					array_push($input_errors, "The field 'Distinguished name Email Address' contains invalid characters.");
220
			}else if ($reqdfields[$i] == 'dn_commonname'){
221
				if (preg_match("/[\!\@\#\$\%\^\(\)\~\?\>\<\&\/\\\,\"\']/", $_POST["dn_commonname"]))
222
					array_push($input_errors, "The field 'Distinguished name Common Name' contains invalid characters.");
223
			}else if (($reqdfields[$i] != "descr") && preg_match("/[\!\@\#\$\%\^\(\)\~\?\>\<\&\/\\\,\.\"\']/", $_POST["$reqdfields[$i]"]))
224
				array_push($input_errors, "The field '" . $reqdfieldsn[$i] . "' contains invalid characters.");
225
		}
226
		if (!in_array($_POST["keylen"], $ca_keylens))
227
			array_push($input_errors, gettext("Please select a valid Key Length."));
228
		if (!in_array($_POST["digest_alg"], $openssl_digest_algs))
229
			array_push($input_errors, gettext("Please select a valid Digest Algorithm."));
230
	}
231

    
232
	/* if this is an AJAX caller then handle via JSON */
233
	if (isAjax() && is_array($input_errors)) {
234
		input_errors2Ajax($input_errors);
235
		exit;
236
	}
237

    
238
	/* save modifications */
239
	if (!$input_errors) {
240

    
241
		$ca = array();
242
		if (!isset($pconfig['refid']) || empty($pconfig['refid']))
243
			$ca['refid'] = uniqid();
244
		else
245
			$ca['refid'] = $pconfig['refid'];
246

    
247
		if (isset($id) && $a_ca[$id])
248
			$ca = $a_ca[$id];
249

    
250
		$ca['descr'] = $pconfig['descr'];
251

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

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

    
297
		if (isset($id) && $a_ca[$id])
298
			$a_ca[$id] = $ca;
299
		else
300
			$a_ca[] = $ca;
301

    
302
		if (!$input_errors)
303
			write_config();
304

    
305
//		pfSenseHeader("system_camanager.php");
306
	}
307
}
308

    
309
include("head.inc");
310
?>
311

    
312
<body link="#0000CC" vlink="#0000CC" alink="#0000CC" onload="<?= $jsevents["body"]["onload"] ?>">
313
<?php include("fbegin.inc"); ?>
314
<script type="text/javascript">
315
//<![CDATA[
316

    
317
function method_change() {
318

    
319
	method = document.iform.method.selectedIndex;
320

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

    
340
//]]>
341
</script>
342
<?php
343
	if ($input_errors)
344
		print_input_errors($input_errors);
345
	if ($savemsg)
346
		print_info_box($savemsg);
347

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

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

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

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

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

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

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

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

    
593
				<?php else: ?>
594

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

    
619
							$issuer_ca = lookup_ca($ca['caref']);
620
							if ($issuer_ca)
621
								$issuer_name = htmlspecialchars($issuer_ca['descr']);
622

    
623
							// TODO : Need gray certificate icon
624

    
625
							if($ca['prv']) {
626
								$caimg = "/themes/{$g['theme']}/images/icons/icon_frmfld_cert.png";
627
								$internal = "YES";
628

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

    
708
				<?php endif; ?>
709

    
710
			</div>
711
		</td>
712
	</tr>
713
</table>
714
<?php include("fend.inc");?>
715
<script type="text/javascript">
716
//<![CDATA[
717

    
718
method_change();
719

    
720
//]]>
721
</script>
722

    
723
</body>
724
</html>
(208-208/252)