Project

General

Profile

Download (25.7 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 (!isset($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
	$input_errors = array();
162
	$pconfig = $_POST;
163

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
311
function method_change() {
312

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

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

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

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

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

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

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

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

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

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

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

    
587
				<?php else: ?>
588

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

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

    
617
							// TODO : Need gray certificate icon
618

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

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

    
702
				<?php endif; ?>
703

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

    
712
method_change();
713

    
714
//]]>
715
</script>
716

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