Project

General

Profile

Download (25.6 KB) Statistics
| Branch: | Tag: | Revision:
1 64cc39d3 Matthew Grooms
<?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 1d333258 Scott Ullrich
/*
30
	pfSense_MODULE:	certificate_managaer
31
*/
32 64cc39d3 Matthew Grooms
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 742d9c2d Ermal Lu?i
require_once("certs.inc");
42 64cc39d3 Matthew Grooms
43
$ca_methods = array(
44 a37753d7 Vinicius Coque
	"existing" => gettext("Import an existing Certificate Authority"),
45 95c8cf48 Evgeny Yurchenko
	"internal" => gettext("Create an internal Certificate Authority"),
46
	"intermediate" => gettext("Create an intermediate Certificate Authority"));
47 64cc39d3 Matthew Grooms
48
$ca_keylens = array( "512", "1024", "2048", "4096");
49 84197cec jim-p
$openssl_digest_algs = array("sha1", "sha224", "sha256", "sha384", "sha512");
50 64cc39d3 Matthew Grooms
51 a37753d7 Vinicius Coque
$pgtitle = array(gettext("System"), gettext("Certificate Authority Manager"));
52 64cc39d3 Matthew Grooms
53
$id = $_GET['id'];
54
if (isset($_POST['id']))
55
	$id = $_POST['id'];
56
57 b4e6524c jim-p
if (!is_array($config['ca']))
58
	$config['ca'] = array();
59 64cc39d3 Matthew Grooms
60 b4e6524c jim-p
$a_ca =& $config['ca'];
61 64cc39d3 Matthew Grooms
62 b4e6524c jim-p
if (!is_array($config['cert']))
63
	$config['cert'] = array();
64 64cc39d3 Matthew Grooms
65 b4e6524c jim-p
$a_cert =& $config['cert'];
66 64cc39d3 Matthew Grooms
67 461aa9d0 jim-p
if (!is_array($config['crl']))
68
	$config['crl'] = array();
69
70
$a_crl =& $config['crl'];
71
72 64cc39d3 Matthew Grooms
$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 461aa9d0 jim-p
	$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 f2a86ca9 jim-p
	$name = $a_ca[$id]['descr'];
94 64cc39d3 Matthew Grooms
	unset($a_ca[$id]);
95
	write_config();
96 461aa9d0 jim-p
	$savemsg = sprintf(gettext("Certificate Authority %s and its CRLs (if any) successfully deleted"), $name) . "<br/>";
97 2f51259b jim-p
	pfSenseHeader("system_camanager.php");
98
	exit;
99 64cc39d3 Matthew Grooms
}
100
101 bfa992bc jim-p
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 64cc39d3 Matthew Grooms
if ($act == "new") {
115
	$pconfig['method'] = $_GET['method'];
116
	$pconfig['keylen'] = "2048";
117 28a20fdb jim-p
	$pconfig['digest_alg'] = "sha256";
118 cf360495 Chris Buechler
	$pconfig['lifetime'] = "3650";
119 64cc39d3 Matthew Grooms
	$pconfig['dn_commonname'] = "internal-ca";
120
}
121
122 93823b10 Matthew Grooms
if ($act == "exp") {
123
124
	if (!$a_ca[$id]) {
125
		pfSenseHeader("system_camanager.php");
126
		exit;
127
	}
128
129 f2a86ca9 jim-p
	$exp_name = urlencode("{$a_ca[$id]['descr']}.crt");
130 93823b10 Matthew Grooms
	$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 ecefc738 jim-p
if ($act == "expkey") {
141
142
	if (!$a_ca[$id]) {
143
		pfSenseHeader("system_camanager.php");
144
		exit;
145
	}
146
147 f2a86ca9 jim-p
	$exp_name = urlencode("{$a_ca[$id]['descr']}.key");
148 ecefc738 jim-p
	$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 64cc39d3 Matthew Grooms
if ($_POST) {
159
160 95c8cf48 Evgeny Yurchenko
	unset($input_errors);
161 64cc39d3 Matthew Grooms
	$pconfig = $_POST;
162
163
	/* input validation */
164
	if ($pconfig['method'] == "existing") {
165 5293bfec jim-p
		$reqdfields = explode(" ", "descr cert");
166 38fb1109 Vinicius Coque
		$reqdfieldsn = array(
167
				gettext("Descriptive name"),
168
				gettext("Certificate data"));
169 396cfe2e jim-p
		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 46698c3f jim-p
		if ($_POST['key'] && strstr($_POST['key'], "ENCRYPTED"))
172
			$input_errors[] = gettext("Encrypted private keys are not yet supported.");
173 64cc39d3 Matthew Grooms
	}
174
	if ($pconfig['method'] == "internal") {
175
		$reqdfields = explode(" ",
176 5293bfec jim-p
				"descr keylen lifetime dn_country dn_state dn_city ".
177 64cc39d3 Matthew Grooms
				"dn_organization dn_email dn_commonname");
178 38fb1109 Vinicius Coque
		$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 a37753d7 Vinicius Coque
				gettext("Distinguished name Common Name"));
188 64cc39d3 Matthew Grooms
	}
189 95c8cf48 Evgeny Yurchenko
	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 64cc39d3 Matthew Grooms
206
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
207 ca621902 jim-p
	if ($pconfig['method'] != "existing") {
208 21cc2faa Evgeny Yurchenko
		/* 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 ca621902 jim-p
		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 64cc39d3 Matthew Grooms
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 bfa992bc jim-p
		if (!isset($pconfig['refid']) || empty($pconfig['refid']))
236
			$ca['refid'] = uniqid();
237
		else
238
			$ca['refid'] = $pconfig['refid'];
239
240 64cc39d3 Matthew Grooms
		if (isset($id) && $a_ca[$id])
241
			$ca = $a_ca[$id];
242
243 bfa992bc jim-p
		$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 1b6d9fa5 Evgeny Yurchenko
			$old_err_level = error_reporting(0); /* otherwise openssl_ functions throw warings directly to a page screwing menu tab */
254 bfa992bc jim-p
			if ($pconfig['method'] == "existing")
255
				ca_import($ca, $pconfig['cert'], $pconfig['key'], $pconfig['serial']);
256
257 95c8cf48 Evgeny Yurchenko
			else if ($pconfig['method'] == "internal") {
258 bfa992bc jim-p
				$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 ca621902 jim-p
				if (!ca_create($ca, $pconfig['keylen'], $pconfig['lifetime'], $dn, $pconfig['digest_alg'])){
266 1b6d9fa5 Evgeny Yurchenko
					while($ssl_err = openssl_error_string()){
267
						$input_errors = array();
268
						array_push($input_errors, "openssl library returns: " . $ssl_err);
269
					}
270
				}
271 bfa992bc jim-p
			}
272 95c8cf48 Evgeny Yurchenko
			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 ca621902 jim-p
				if (!ca_inter_create($ca, $pconfig['keylen'], $pconfig['lifetime'], $dn, $pconfig['caref'], $pconfig['digest_alg'])){
281 95c8cf48 Evgeny Yurchenko
					while($ssl_err = openssl_error_string()){
282
						$input_errors = array();
283
						array_push($input_errors, "openssl library returns: " . $ssl_err);
284
					}
285
				}
286
			}
287 1b6d9fa5 Evgeny Yurchenko
			error_reporting($old_err_level);
288 64cc39d3 Matthew Grooms
		}
289
290
		if (isset($id) && $a_ca[$id])
291
			$a_ca[$id] = $ca;
292
		else
293
			$a_ca[] = $ca;
294
295 95c8cf48 Evgeny Yurchenko
		if (!$input_errors)
296
			write_config();
297 64cc39d3 Matthew Grooms
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 96028288 Colin Fleming
//<![CDATA[
309 64cc39d3 Matthew Grooms
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 95c8cf48 Evgeny Yurchenko
			document.getElementById("intermediate").style.display="none";
319 64cc39d3 Matthew Grooms
			break;
320
		case 1:
321
			document.getElementById("existing").style.display="none";
322
			document.getElementById("internal").style.display="";
323 95c8cf48 Evgeny Yurchenko
			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 64cc39d3 Matthew Grooms
			break;
330
	}
331
}
332
333 96028288 Colin Fleming
//]]>
334 64cc39d3 Matthew Grooms
</script>
335
<?php
336
	if ($input_errors)
337
		print_input_errors($input_errors);
338
	if ($savemsg)
339
		print_info_box($savemsg);
340 9d2d65f3 Evgeny Yurchenko
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 64cc39d3 Matthew Grooms
?>
350 96028288 Colin Fleming
<table width="100%" border="0" cellpadding="0" cellspacing="0" summary="CA manager">
351 64cc39d3 Matthew Grooms
	<tr>
352 96c7a492 Matthew Grooms
		<td>
353 64cc39d3 Matthew Grooms
		<?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 3d57d2d5 jim-p
			$tab_array[] = array(gettext("Certificate Revocation"), false, "system_crlmanager.php");
358 64cc39d3 Matthew Grooms
			display_top_tabs($tab_array);
359
		?>
360
		</td>
361
	</tr>
362
	<tr>
363 96c7a492 Matthew Grooms
		<td id="mainarea">
364
			<div class="tabcont">
365
366 bfa992bc jim-p
				<?php if ($act == "new" || $act == "edit" || $act == gettext("Save") || $input_errors): ?>
367 96c7a492 Matthew Grooms
368
				<form action="system_camanager.php" method="post" name="iform" id="iform">
369 bfa992bc jim-p
					<?php if ($act == "edit"): ?>
370 96028288 Colin Fleming
					<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 bfa992bc jim-p
					<?php endif; ?>
374 96028288 Colin Fleming
					<table width="100%" border="0" cellpadding="6" cellspacing="0" summary="main area">
375 96c7a492 Matthew Grooms
						<tr>
376
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Descriptive name");?></td>
377
							<td width="78%" class="vtable">
378 f2a86ca9 jim-p
								<input name="descr" type="text" class="formfld unknown" id="descr" size="20" value="<?=htmlspecialchars($pconfig['descr']);?>"/>
379 96c7a492 Matthew Grooms
							</td>
380
						</tr>
381 bfa992bc jim-p
						<?php if (!isset($id) || $act == "edit"): ?>
382 96c7a492 Matthew Grooms
						<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 96028288 Colin Fleming
										$selected = " selected=\"selected\"";
391 96c7a492 Matthew Grooms
								?>
392
									<option value="<?=$method;?>"<?=$selected;?>><?=$desc;?></option>
393
								<?php endforeach; ?>
394
								</select>
395
							</td>
396
						</tr>
397
						<?php endif; ?>
398
					</table>
399
400 96028288 Colin Fleming
					<table width="100%" border="0" cellpadding="6" cellspacing="0" id="existing" summary="existing">
401 96c7a492 Matthew Grooms
						<tr>
402
							<td colspan="2" class="list" height="12"></td>
403
						</tr>
404
						<tr>
405 a37753d7 Vinicius Coque
							<td colspan="2" valign="top" class="listtopic"><?=gettext("Existing Certificate Authority");?></td>
406 96c7a492 Matthew Grooms
						</tr>
407
408
						<tr>
409 a37753d7 Vinicius Coque
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Certificate data");?></td>
410 96c7a492 Matthew Grooms
							<td width="78%" class="vtable">
411 dd5bf424 Scott Ullrich
								<textarea name="cert" id="cert" cols="65" rows="7" class="formfld_cert"><?=htmlspecialchars($pconfig['cert']);?></textarea>
412 96028288 Colin Fleming
								<br/>
413 39530c89 bcyrill
								<?=gettext("Paste a certificate in X.509 PEM format here.");?>
414 96c7a492 Matthew Grooms
							</td>
415
						</tr>
416 ecefc738 jim-p
						<tr>
417
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Certificate Private Key");?><br/><?=gettext("(optional)");?></td>
418
							<td width="78%" class="vtable">
419 dd5bf424 Scott Ullrich
								<textarea name="key" id="key" cols="65" rows="7" class="formfld_cert"><?=htmlspecialchars($pconfig['key']);?></textarea>
420 96028288 Colin Fleming
								<br/>
421 39530c89 bcyrill
								<?=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 ecefc738 jim-p
							</td>
423
						</tr>
424 bfa992bc jim-p
425
					<?php if (!isset($id) || $act == "edit"): ?>
426
						<tr>
427 51c24cf6 jim-p
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Serial for next certificate");?></td>
428 bfa992bc jim-p
							<td width="78%" class="vtable">
429
								<input name="serial" type="text" class="formfld unknown" id="serial" size="20" value="<?=htmlspecialchars($pconfig['serial']);?>"/>
430 51c24cf6 jim-p
								<br/><?=gettext("Enter a decimal number to be used as the serial number for the next certificate to be created using this CA.");?>
431 bfa992bc jim-p
							</td>
432
						</tr>
433
					<?php endif; ?>
434 96c7a492 Matthew Grooms
					</table>
435
436 96028288 Colin Fleming
					<table width="100%" border="0" cellpadding="6" cellspacing="0" id="internal" summary="internal">
437 96c7a492 Matthew Grooms
						<tr>
438
							<td colspan="2" class="list" height="12"></td>
439
						</tr>
440
						<tr>
441 a37753d7 Vinicius Coque
							<td colspan="2" valign="top" class="listtopic"><?=gettext("Internal Certificate Authority");?></td>
442 96c7a492 Matthew Grooms
						</tr>
443 95c8cf48 Evgeny Yurchenko
						<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 96028288 Colin Fleming
                                                                                $selected = " selected=\"selected\"";
454 95c8cf48 Evgeny Yurchenko
                                                                ?>
455
                                                                        <option value="<?=$ca['refid'];?>"<?=$selected;?>><?=$ca['descr'];?></option>
456
                                                                <?php endforeach; ?>
457
                                                                </select>
458
							</td>
459
						</tr>
460 96c7a492 Matthew Grooms
						<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 96028288 Colin Fleming
										$selected = " selected=\"selected\"";
469 96c7a492 Matthew Grooms
								?>
470
									<option value="<?=$len;?>"<?=$selected;?>><?=$len;?></option>
471
								<?php endforeach; ?>
472
								</select>
473 ea53e38f Renato Botelho
								<?=gettext("bits");?>
474 96c7a492 Matthew Grooms
							</td>
475
						</tr>
476 ca621902 jim-p
						<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 96028288 Colin Fleming
										$selected = " selected=\"selected\"";
485 ca621902 jim-p
								?>
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 96c7a492 Matthew Grooms
						<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 ea53e38f Renato Botelho
								<?=gettext("days");?>
497 96c7a492 Matthew Grooms
							</td>
498
						</tr>
499
						<tr>
500
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Distinguished name");?></td>
501
							<td width="78%" class="vtable">
502 96028288 Colin Fleming
								<table border="0" cellspacing="0" cellpadding="2" summary="name">
503 96c7a492 Matthew Grooms
									<tr>
504 a37753d7 Vinicius Coque
										<td align="right"><?=gettext("Country Code");?> : &nbsp;</td>
505 96c7a492 Matthew Grooms
										<td align="left">
506 9d2d65f3 Evgeny Yurchenko
											<select name='dn_country' class="formselect">
507
											<?php
508
											foreach( $dn_cc as $cc){
509
												$selected = "";
510 39530c89 bcyrill
												if ($pconfig['dn_country'] == $cc)
511 96028288 Colin Fleming
													$selected = " selected=\"selected\"";
512 39530c89 bcyrill
												print "<option value=\"$cc\"$selected>$cc</option>";
513 9d2d65f3 Evgeny Yurchenko
												}
514
											?>
515
											</select>
516 96c7a492 Matthew Grooms
										</td>
517
									</tr>
518
									<tr>
519 a37753d7 Vinicius Coque
										<td align="right"><?=gettext("State or Province");?> : &nbsp;</td>
520 96c7a492 Matthew Grooms
										<td align="left">
521
											<input name="dn_state" type="text" class="formfld unknown" size="40" value="<?=htmlspecialchars($pconfig['dn_state']);?>"/>
522
											&nbsp;
523 ea53e38f Renato Botelho
											<em><?=gettext("ex:");?></em>
524 96c7a492 Matthew Grooms
											&nbsp;
525 a37753d7 Vinicius Coque
											<?=gettext("Texas");?>
526 96c7a492 Matthew Grooms
										</td>
527
									</tr>
528
									<tr>
529 a37753d7 Vinicius Coque
										<td align="right"><?=gettext("City");?> : &nbsp;</td>
530 96c7a492 Matthew Grooms
										<td align="left">
531
											<input name="dn_city" type="text" class="formfld unknown" size="40" value="<?=htmlspecialchars($pconfig['dn_city']);?>"/>
532
											&nbsp;
533 ea53e38f Renato Botelho
											<em><?=gettext("ex:");?></em>
534 96c7a492 Matthew Grooms
											&nbsp;
535 a37753d7 Vinicius Coque
											<?=gettext("Austin");?>
536 96c7a492 Matthew Grooms
										</td>
537
									</tr>
538
									<tr>
539 a37753d7 Vinicius Coque
										<td align="right"><?=gettext("Organization");?> : &nbsp;</td>
540 96c7a492 Matthew Grooms
										<td align="left">
541
											<input name="dn_organization" type="text" class="formfld unknown" size="40" value="<?=htmlspecialchars($pconfig['dn_organization']);?>"/>
542
											&nbsp;
543 ea53e38f Renato Botelho
											<em><?=gettext("ex:");?></em>
544 96c7a492 Matthew Grooms
											&nbsp;
545 a37753d7 Vinicius Coque
											<?=gettext("My Company Inc.");?>
546 96c7a492 Matthew Grooms
										</td>
547
									</tr>
548
									<tr>
549 a37753d7 Vinicius Coque
										<td align="right"><?=gettext("Email Address");?> : &nbsp;</td>
550 96c7a492 Matthew Grooms
										<td align="left">
551
											<input name="dn_email" type="text" class="formfld unknown" size="25" value="<?=htmlspecialchars($pconfig['dn_email']);?>"/>
552
											&nbsp;
553 ea53e38f Renato Botelho
											<em><?=gettext("ex:");?></em>
554 96c7a492 Matthew Grooms
											&nbsp;
555 a37753d7 Vinicius Coque
											<?=gettext("admin@mycompany.com");?>
556 96c7a492 Matthew Grooms
										</td>
557
									</tr>
558
									<tr>
559 a37753d7 Vinicius Coque
										<td align="right"><?=gettext("Common Name");?> : &nbsp;</td>
560 96c7a492 Matthew Grooms
										<td align="left">
561
											<input name="dn_commonname" type="text" class="formfld unknown" size="25" value="<?=htmlspecialchars($pconfig['dn_commonname']);?>"/>
562
											&nbsp;
563 ea53e38f Renato Botelho
											<em><?=gettext("ex:");?></em>
564 96c7a492 Matthew Grooms
											&nbsp;
565 a37753d7 Vinicius Coque
											<?=gettext("internal-ca");?>
566 96c7a492 Matthew Grooms
										</td>
567
									</tr>
568
								</table>
569
							</td>
570
						</tr>
571
					</table>
572
573 96028288 Colin Fleming
					<table width="100%" border="0" cellpadding="6" cellspacing="0" summary="save">
574 96c7a492 Matthew Grooms
						<tr>
575
							<td width="22%" valign="top">&nbsp;</td>
576
							<td width="78%">
577 443ddf6f Carlos Eduardo Ramos
								<input id="submit" name="save" type="submit" class="formbtn" value="<?=gettext("Save"); ?>" />
578 96c7a492 Matthew Grooms
								<?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 96028288 Colin Fleming
				<table width="100%" border="0" cellpadding="0" cellspacing="0" summary="">
589 64cc39d3 Matthew Grooms
					<tr>
590 a37753d7 Vinicius Coque
						<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 96c7a492 Matthew Grooms
						<td width="10%" class="list"></td>
596 64cc39d3 Matthew Grooms
					</tr>
597 96c7a492 Matthew Grooms
					<?php
598
						$i = 0;
599
						foreach($a_ca as $ca):
600 f2a86ca9 jim-p
							$name = htmlspecialchars($ca['descr']);
601 96c7a492 Matthew Grooms
							$subj = cert_get_subject($ca['crt']);
602 2cf6ddcb Nigel Graham
							$issuer = cert_get_issuer($ca['crt']);
603 2b333210 jim-p
							list($startdate, $enddate) = cert_get_dates($ca['crt']);
604 2cf6ddcb Nigel Graham
							if($subj == $issuer)
605 a37753d7 Vinicius Coque
							  $issuer_name = "<em>" . gettext("self-signed") . "</em>";
606 2cf6ddcb Nigel Graham
							else
607 a37753d7 Vinicius Coque
							  $issuer_name = "<em>" . gettext("external") . "</em>";
608 96c7a492 Matthew Grooms
							$subj = htmlspecialchars($subj);
609 2cf6ddcb Nigel Graham
							$issuer = htmlspecialchars($issuer);
610 96c7a492 Matthew Grooms
							$certcount = 0;
611
612 2cf6ddcb Nigel Graham
							$issuer_ca = lookup_ca($ca['caref']);
613
							if ($issuer_ca)
614 f2a86ca9 jim-p
								$issuer_name = $issuer_ca['descr'];
615 2cf6ddcb Nigel Graham
616 96c7a492 Matthew Grooms
							// 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 2cf6ddcb Nigel Graham
							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 96c7a492 Matthew Grooms
					?>
633 64cc39d3 Matthew Grooms
					<tr>
634 96c7a492 Matthew Grooms
						<td class="listlr">
635 96028288 Colin Fleming
							<table border="0" cellpadding="0" cellspacing="0" summary="icon">
636 64cc39d3 Matthew Grooms
								<tr>
637 96028288 Colin Fleming
									<td align="left" valign="middle">
638 96c7a492 Matthew Grooms
										<img src="<?=$caimg;?>" alt="CA" title="CA" border="0" height="16" width="16" />
639 64cc39d3 Matthew Grooms
									</td>
640 96c7a492 Matthew Grooms
									<td align="left" valign="middle">
641
										<?=$name;?>
642 64cc39d3 Matthew Grooms
									</td>
643
								</tr>
644
							</table>
645
						</td>
646 96c7a492 Matthew Grooms
						<td class="listr"><?=$internal;?>&nbsp;</td>
647 2cf6ddcb Nigel Graham
						<td class="listr"><?=$issuer_name;?>&nbsp;</td>
648 96c7a492 Matthew Grooms
						<td class="listr"><?=$certcount;?>&nbsp;</td>
649 2b333210 jim-p
						<td class="listr"><?=$subj;?><br />
650 96028288 Colin Fleming
							<table width="100%" style="font-size: 9px" summary="valid">
651 2b333210 jim-p
								<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 96c7a492 Matthew Grooms
						<td valign="middle" nowrap class="list">
664 9eac43d7 bcyrill
							<a href="system_camanager.php?act=edit&amp;id=<?=$i;?>">
665 73800013 Chris Buechler
								<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 bfa992bc jim-p
							</a>
667 9eac43d7 bcyrill
							<a href="system_camanager.php?act=exp&amp;id=<?=$i;?>">
668 73800013 Chris Buechler
								<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 96c7a492 Matthew Grooms
							</a>
670 ecefc738 jim-p
							<?php if ($ca['prv']): ?>
671 9eac43d7 bcyrill
							<a href="system_camanager.php?act=expkey&amp;id=<?=$i;?>">
672 73800013 Chris Buechler
								<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 ecefc738 jim-p
							</a>
674
							<?php endif; ?>
675 9eac43d7 bcyrill
							<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 2b33f342 Renato Botelho
								<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 96c7a492 Matthew Grooms
							</a>
678
						</td>
679
					</tr>
680
					<?php
681
							$i++;
682
						endforeach;
683
					?>
684
					<tr>
685 2cf6ddcb Nigel Graham
						<td class="list" colspan="5"></td>
686 96c7a492 Matthew Grooms
						<td class="list">
687
							<a href="system_camanager.php?act=new">
688 a37753d7 Vinicius Coque
								<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 96c7a492 Matthew Grooms
							</a>
690
						</td>
691 64cc39d3 Matthew Grooms
					</tr>
692
					<tr>
693 2cf6ddcb Nigel Graham
						<td colspan="5">
694 96c7a492 Matthew Grooms
							<p>
695 22a11a58 Larry Gilbert
								<?=gettext("Additional trusted Certificate Authorities can be added here.");?>
696 96c7a492 Matthew Grooms
							</p>
697 64cc39d3 Matthew Grooms
						</td>
698
					</tr>
699
				</table>
700
701 96c7a492 Matthew Grooms
				<?php endif; ?>
702
703
			</div>
704 64cc39d3 Matthew Grooms
		</td>
705
	</tr>
706
</table>
707
<?php include("fend.inc");?>
708
<script type="text/javascript">
709 96028288 Colin Fleming
//<![CDATA[
710 64cc39d3 Matthew Grooms
711
method_change();
712
713 96028288 Colin Fleming
//]]>
714 64cc39d3 Matthew Grooms
</script>
715
716
</body>
717 39530c89 bcyrill
</html>