Project

General

Profile

Download (25.7 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 40e6086a jim-p
	if (!isset($a_ca[$id])) {
79 64cc39d3 Matthew Grooms
		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 2b8bfda4 Phil Davis
	$input_errors = array();
162 64cc39d3 Matthew Grooms
	$pconfig = $_POST;
163
164
	/* input validation */
165
	if ($pconfig['method'] == "existing") {
166 5293bfec jim-p
		$reqdfields = explode(" ", "descr cert");
167 38fb1109 Vinicius Coque
		$reqdfieldsn = array(
168
				gettext("Descriptive name"),
169
				gettext("Certificate data"));
170 396cfe2e jim-p
		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 46698c3f jim-p
		if ($_POST['key'] && strstr($_POST['key'], "ENCRYPTED"))
173
			$input_errors[] = gettext("Encrypted private keys are not yet supported.");
174 64cc39d3 Matthew Grooms
	}
175
	if ($pconfig['method'] == "internal") {
176
		$reqdfields = explode(" ",
177 5293bfec jim-p
				"descr keylen lifetime dn_country dn_state dn_city ".
178 64cc39d3 Matthew Grooms
				"dn_organization dn_email dn_commonname");
179 38fb1109 Vinicius Coque
		$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 a37753d7 Vinicius Coque
				gettext("Distinguished name Common Name"));
189 64cc39d3 Matthew Grooms
	}
190 95c8cf48 Evgeny Yurchenko
	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 64cc39d3 Matthew Grooms
207 1e9b4611 Renato Botelho
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
208 ca621902 jim-p
	if ($pconfig['method'] != "existing") {
209 21cc2faa Evgeny Yurchenko
		/* 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 00a695c8 jim-p
			}else if (($reqdfields[$i] != "descr") && preg_match("/[\!\@\#\$\%\^\(\)\~\?\>\<\&\/\\\,\.\"\']/", $_POST["$reqdfields[$i]"]))
218 21cc2faa Evgeny Yurchenko
				array_push($input_errors, "The field '" . $reqdfieldsn[$i] . "' contains invalid characters.");
219
		}
220 ca621902 jim-p
		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 64cc39d3 Matthew Grooms
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 bfa992bc jim-p
		if (!isset($pconfig['refid']) || empty($pconfig['refid']))
237
			$ca['refid'] = uniqid();
238
		else
239
			$ca['refid'] = $pconfig['refid'];
240
241 64cc39d3 Matthew Grooms
		if (isset($id) && $a_ca[$id])
242
			$ca = $a_ca[$id];
243
244 bfa992bc jim-p
		$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 1b6d9fa5 Evgeny Yurchenko
			$old_err_level = error_reporting(0); /* otherwise openssl_ functions throw warings directly to a page screwing menu tab */
255 bfa992bc jim-p
			if ($pconfig['method'] == "existing")
256
				ca_import($ca, $pconfig['cert'], $pconfig['key'], $pconfig['serial']);
257
258 95c8cf48 Evgeny Yurchenko
			else if ($pconfig['method'] == "internal") {
259 bfa992bc jim-p
				$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 ca621902 jim-p
				if (!ca_create($ca, $pconfig['keylen'], $pconfig['lifetime'], $dn, $pconfig['digest_alg'])){
267 1b6d9fa5 Evgeny Yurchenko
					while($ssl_err = openssl_error_string()){
268
						$input_errors = array();
269
						array_push($input_errors, "openssl library returns: " . $ssl_err);
270
					}
271
				}
272 bfa992bc jim-p
			}
273 95c8cf48 Evgeny Yurchenko
			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 ca621902 jim-p
				if (!ca_inter_create($ca, $pconfig['keylen'], $pconfig['lifetime'], $dn, $pconfig['caref'], $pconfig['digest_alg'])){
282 95c8cf48 Evgeny Yurchenko
					while($ssl_err = openssl_error_string()){
283
						$input_errors = array();
284
						array_push($input_errors, "openssl library returns: " . $ssl_err);
285
					}
286
				}
287
			}
288 1b6d9fa5 Evgeny Yurchenko
			error_reporting($old_err_level);
289 64cc39d3 Matthew Grooms
		}
290
291
		if (isset($id) && $a_ca[$id])
292
			$a_ca[$id] = $ca;
293
		else
294
			$a_ca[] = $ca;
295
296 95c8cf48 Evgeny Yurchenko
		if (!$input_errors)
297
			write_config();
298 64cc39d3 Matthew Grooms
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 96028288 Colin Fleming
//<![CDATA[
310 64cc39d3 Matthew Grooms
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 95c8cf48 Evgeny Yurchenko
			document.getElementById("intermediate").style.display="none";
320 64cc39d3 Matthew Grooms
			break;
321
		case 1:
322
			document.getElementById("existing").style.display="none";
323
			document.getElementById("internal").style.display="";
324 95c8cf48 Evgeny Yurchenko
			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 64cc39d3 Matthew Grooms
			break;
331
	}
332
}
333
334 96028288 Colin Fleming
//]]>
335 64cc39d3 Matthew Grooms
</script>
336
<?php
337
	if ($input_errors)
338
		print_input_errors($input_errors);
339
	if ($savemsg)
340
		print_info_box($savemsg);
341 9d2d65f3 Evgeny Yurchenko
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 64cc39d3 Matthew Grooms
?>
351 96028288 Colin Fleming
<table width="100%" border="0" cellpadding="0" cellspacing="0" summary="CA manager">
352 64cc39d3 Matthew Grooms
	<tr>
353 96c7a492 Matthew Grooms
		<td>
354 64cc39d3 Matthew Grooms
		<?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 3d57d2d5 jim-p
			$tab_array[] = array(gettext("Certificate Revocation"), false, "system_crlmanager.php");
359 64cc39d3 Matthew Grooms
			display_top_tabs($tab_array);
360
		?>
361
		</td>
362
	</tr>
363
	<tr>
364 96c7a492 Matthew Grooms
		<td id="mainarea">
365
			<div class="tabcont">
366
367 bfa992bc jim-p
				<?php if ($act == "new" || $act == "edit" || $act == gettext("Save") || $input_errors): ?>
368 96c7a492 Matthew Grooms
369
				<form action="system_camanager.php" method="post" name="iform" id="iform">
370 bfa992bc jim-p
					<?php if ($act == "edit"): ?>
371 96028288 Colin Fleming
					<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 bfa992bc jim-p
					<?php endif; ?>
375 96028288 Colin Fleming
					<table width="100%" border="0" cellpadding="6" cellspacing="0" summary="main area">
376 96c7a492 Matthew Grooms
						<tr>
377
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Descriptive name");?></td>
378
							<td width="78%" class="vtable">
379 f2a86ca9 jim-p
								<input name="descr" type="text" class="formfld unknown" id="descr" size="20" value="<?=htmlspecialchars($pconfig['descr']);?>"/>
380 96c7a492 Matthew Grooms
							</td>
381
						</tr>
382 bfa992bc jim-p
						<?php if (!isset($id) || $act == "edit"): ?>
383 96c7a492 Matthew Grooms
						<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 96028288 Colin Fleming
										$selected = " selected=\"selected\"";
392 96c7a492 Matthew Grooms
								?>
393
									<option value="<?=$method;?>"<?=$selected;?>><?=$desc;?></option>
394
								<?php endforeach; ?>
395
								</select>
396
							</td>
397
						</tr>
398
						<?php endif; ?>
399
					</table>
400
401 96028288 Colin Fleming
					<table width="100%" border="0" cellpadding="6" cellspacing="0" id="existing" summary="existing">
402 96c7a492 Matthew Grooms
						<tr>
403
							<td colspan="2" class="list" height="12"></td>
404
						</tr>
405
						<tr>
406 a37753d7 Vinicius Coque
							<td colspan="2" valign="top" class="listtopic"><?=gettext("Existing Certificate Authority");?></td>
407 96c7a492 Matthew Grooms
						</tr>
408
409
						<tr>
410 a37753d7 Vinicius Coque
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Certificate data");?></td>
411 96c7a492 Matthew Grooms
							<td width="78%" class="vtable">
412 dd5bf424 Scott Ullrich
								<textarea name="cert" id="cert" cols="65" rows="7" class="formfld_cert"><?=htmlspecialchars($pconfig['cert']);?></textarea>
413 96028288 Colin Fleming
								<br/>
414 39530c89 bcyrill
								<?=gettext("Paste a certificate in X.509 PEM format here.");?>
415 96c7a492 Matthew Grooms
							</td>
416
						</tr>
417 ecefc738 jim-p
						<tr>
418
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Certificate Private Key");?><br/><?=gettext("(optional)");?></td>
419
							<td width="78%" class="vtable">
420 dd5bf424 Scott Ullrich
								<textarea name="key" id="key" cols="65" rows="7" class="formfld_cert"><?=htmlspecialchars($pconfig['key']);?></textarea>
421 96028288 Colin Fleming
								<br/>
422 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).");?>
423 ecefc738 jim-p
							</td>
424
						</tr>
425 bfa992bc jim-p
426
					<?php if (!isset($id) || $act == "edit"): ?>
427
						<tr>
428 51c24cf6 jim-p
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Serial for next certificate");?></td>
429 bfa992bc jim-p
							<td width="78%" class="vtable">
430
								<input name="serial" type="text" class="formfld unknown" id="serial" size="20" value="<?=htmlspecialchars($pconfig['serial']);?>"/>
431 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.");?>
432 bfa992bc jim-p
							</td>
433
						</tr>
434
					<?php endif; ?>
435 96c7a492 Matthew Grooms
					</table>
436
437 96028288 Colin Fleming
					<table width="100%" border="0" cellpadding="6" cellspacing="0" id="internal" summary="internal">
438 96c7a492 Matthew Grooms
						<tr>
439
							<td colspan="2" class="list" height="12"></td>
440
						</tr>
441
						<tr>
442 a37753d7 Vinicius Coque
							<td colspan="2" valign="top" class="listtopic"><?=gettext("Internal Certificate Authority");?></td>
443 96c7a492 Matthew Grooms
						</tr>
444 95c8cf48 Evgeny Yurchenko
						<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 96028288 Colin Fleming
                                                                                $selected = " selected=\"selected\"";
455 95c8cf48 Evgeny Yurchenko
                                                                ?>
456
                                                                        <option value="<?=$ca['refid'];?>"<?=$selected;?>><?=$ca['descr'];?></option>
457
                                                                <?php endforeach; ?>
458
                                                                </select>
459
							</td>
460
						</tr>
461 96c7a492 Matthew Grooms
						<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 96028288 Colin Fleming
										$selected = " selected=\"selected\"";
470 96c7a492 Matthew Grooms
								?>
471
									<option value="<?=$len;?>"<?=$selected;?>><?=$len;?></option>
472
								<?php endforeach; ?>
473
								</select>
474 ea53e38f Renato Botelho
								<?=gettext("bits");?>
475 96c7a492 Matthew Grooms
							</td>
476
						</tr>
477 ca621902 jim-p
						<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 96028288 Colin Fleming
										$selected = " selected=\"selected\"";
486 ca621902 jim-p
								?>
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 96c7a492 Matthew Grooms
						<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 ea53e38f Renato Botelho
								<?=gettext("days");?>
498 96c7a492 Matthew Grooms
							</td>
499
						</tr>
500
						<tr>
501
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Distinguished name");?></td>
502
							<td width="78%" class="vtable">
503 96028288 Colin Fleming
								<table border="0" cellspacing="0" cellpadding="2" summary="name">
504 96c7a492 Matthew Grooms
									<tr>
505 a37753d7 Vinicius Coque
										<td align="right"><?=gettext("Country Code");?> : &nbsp;</td>
506 96c7a492 Matthew Grooms
										<td align="left">
507 9d2d65f3 Evgeny Yurchenko
											<select name='dn_country' class="formselect">
508
											<?php
509
											foreach( $dn_cc as $cc){
510
												$selected = "";
511 39530c89 bcyrill
												if ($pconfig['dn_country'] == $cc)
512 96028288 Colin Fleming
													$selected = " selected=\"selected\"";
513 39530c89 bcyrill
												print "<option value=\"$cc\"$selected>$cc</option>";
514 9d2d65f3 Evgeny Yurchenko
												}
515
											?>
516
											</select>
517 96c7a492 Matthew Grooms
										</td>
518
									</tr>
519
									<tr>
520 a37753d7 Vinicius Coque
										<td align="right"><?=gettext("State or Province");?> : &nbsp;</td>
521 96c7a492 Matthew Grooms
										<td align="left">
522
											<input name="dn_state" type="text" class="formfld unknown" size="40" value="<?=htmlspecialchars($pconfig['dn_state']);?>"/>
523
											&nbsp;
524 ea53e38f Renato Botelho
											<em><?=gettext("ex:");?></em>
525 96c7a492 Matthew Grooms
											&nbsp;
526 a37753d7 Vinicius Coque
											<?=gettext("Texas");?>
527 96c7a492 Matthew Grooms
										</td>
528
									</tr>
529
									<tr>
530 a37753d7 Vinicius Coque
										<td align="right"><?=gettext("City");?> : &nbsp;</td>
531 96c7a492 Matthew Grooms
										<td align="left">
532
											<input name="dn_city" type="text" class="formfld unknown" size="40" value="<?=htmlspecialchars($pconfig['dn_city']);?>"/>
533
											&nbsp;
534 ea53e38f Renato Botelho
											<em><?=gettext("ex:");?></em>
535 96c7a492 Matthew Grooms
											&nbsp;
536 a37753d7 Vinicius Coque
											<?=gettext("Austin");?>
537 96c7a492 Matthew Grooms
										</td>
538
									</tr>
539
									<tr>
540 a37753d7 Vinicius Coque
										<td align="right"><?=gettext("Organization");?> : &nbsp;</td>
541 96c7a492 Matthew Grooms
										<td align="left">
542
											<input name="dn_organization" type="text" class="formfld unknown" size="40" value="<?=htmlspecialchars($pconfig['dn_organization']);?>"/>
543
											&nbsp;
544 ea53e38f Renato Botelho
											<em><?=gettext("ex:");?></em>
545 96c7a492 Matthew Grooms
											&nbsp;
546 a37753d7 Vinicius Coque
											<?=gettext("My Company Inc.");?>
547 96c7a492 Matthew Grooms
										</td>
548
									</tr>
549
									<tr>
550 a37753d7 Vinicius Coque
										<td align="right"><?=gettext("Email Address");?> : &nbsp;</td>
551 96c7a492 Matthew Grooms
										<td align="left">
552
											<input name="dn_email" type="text" class="formfld unknown" size="25" value="<?=htmlspecialchars($pconfig['dn_email']);?>"/>
553
											&nbsp;
554 ea53e38f Renato Botelho
											<em><?=gettext("ex:");?></em>
555 96c7a492 Matthew Grooms
											&nbsp;
556 a37753d7 Vinicius Coque
											<?=gettext("admin@mycompany.com");?>
557 96c7a492 Matthew Grooms
										</td>
558
									</tr>
559
									<tr>
560 a37753d7 Vinicius Coque
										<td align="right"><?=gettext("Common Name");?> : &nbsp;</td>
561 96c7a492 Matthew Grooms
										<td align="left">
562
											<input name="dn_commonname" type="text" class="formfld unknown" size="25" value="<?=htmlspecialchars($pconfig['dn_commonname']);?>"/>
563
											&nbsp;
564 ea53e38f Renato Botelho
											<em><?=gettext("ex:");?></em>
565 96c7a492 Matthew Grooms
											&nbsp;
566 a37753d7 Vinicius Coque
											<?=gettext("internal-ca");?>
567 96c7a492 Matthew Grooms
										</td>
568
									</tr>
569
								</table>
570
							</td>
571
						</tr>
572
					</table>
573
574 96028288 Colin Fleming
					<table width="100%" border="0" cellpadding="6" cellspacing="0" summary="save">
575 96c7a492 Matthew Grooms
						<tr>
576
							<td width="22%" valign="top">&nbsp;</td>
577
							<td width="78%">
578 443ddf6f Carlos Eduardo Ramos
								<input id="submit" name="save" type="submit" class="formbtn" value="<?=gettext("Save"); ?>" />
579 96c7a492 Matthew Grooms
								<?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 96028288 Colin Fleming
				<table width="100%" border="0" cellpadding="0" cellspacing="0" summary="">
590 64cc39d3 Matthew Grooms
					<tr>
591 a37753d7 Vinicius Coque
						<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 96c7a492 Matthew Grooms
						<td width="10%" class="list"></td>
597 64cc39d3 Matthew Grooms
					</tr>
598 96c7a492 Matthew Grooms
					<?php
599
						$i = 0;
600
						foreach($a_ca as $ca):
601 f2a86ca9 jim-p
							$name = htmlspecialchars($ca['descr']);
602 96c7a492 Matthew Grooms
							$subj = cert_get_subject($ca['crt']);
603 2cf6ddcb Nigel Graham
							$issuer = cert_get_issuer($ca['crt']);
604 2b333210 jim-p
							list($startdate, $enddate) = cert_get_dates($ca['crt']);
605 2cf6ddcb Nigel Graham
							if($subj == $issuer)
606 a37753d7 Vinicius Coque
							  $issuer_name = "<em>" . gettext("self-signed") . "</em>";
607 2cf6ddcb Nigel Graham
							else
608 a37753d7 Vinicius Coque
							  $issuer_name = "<em>" . gettext("external") . "</em>";
609 96c7a492 Matthew Grooms
							$subj = htmlspecialchars($subj);
610 2cf6ddcb Nigel Graham
							$issuer = htmlspecialchars($issuer);
611 96c7a492 Matthew Grooms
							$certcount = 0;
612
613 2cf6ddcb Nigel Graham
							$issuer_ca = lookup_ca($ca['caref']);
614
							if ($issuer_ca)
615 f2a86ca9 jim-p
								$issuer_name = $issuer_ca['descr'];
616 2cf6ddcb Nigel Graham
617 96c7a492 Matthew Grooms
							// 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 2cf6ddcb Nigel Graham
							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 96c7a492 Matthew Grooms
					?>
634 64cc39d3 Matthew Grooms
					<tr>
635 96c7a492 Matthew Grooms
						<td class="listlr">
636 96028288 Colin Fleming
							<table border="0" cellpadding="0" cellspacing="0" summary="icon">
637 64cc39d3 Matthew Grooms
								<tr>
638 96028288 Colin Fleming
									<td align="left" valign="middle">
639 96c7a492 Matthew Grooms
										<img src="<?=$caimg;?>" alt="CA" title="CA" border="0" height="16" width="16" />
640 64cc39d3 Matthew Grooms
									</td>
641 96c7a492 Matthew Grooms
									<td align="left" valign="middle">
642
										<?=$name;?>
643 64cc39d3 Matthew Grooms
									</td>
644
								</tr>
645
							</table>
646
						</td>
647 96c7a492 Matthew Grooms
						<td class="listr"><?=$internal;?>&nbsp;</td>
648 2cf6ddcb Nigel Graham
						<td class="listr"><?=$issuer_name;?>&nbsp;</td>
649 96c7a492 Matthew Grooms
						<td class="listr"><?=$certcount;?>&nbsp;</td>
650 2b333210 jim-p
						<td class="listr"><?=$subj;?><br />
651 96028288 Colin Fleming
							<table width="100%" style="font-size: 9px" summary="valid">
652 2b333210 jim-p
								<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 96c7a492 Matthew Grooms
						<td valign="middle" nowrap class="list">
665 9eac43d7 bcyrill
							<a href="system_camanager.php?act=edit&amp;id=<?=$i;?>">
666 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" />
667 bfa992bc jim-p
							</a>
668 9eac43d7 bcyrill
							<a href="system_camanager.php?act=exp&amp;id=<?=$i;?>">
669 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" />
670 96c7a492 Matthew Grooms
							</a>
671 ecefc738 jim-p
							<?php if ($ca['prv']): ?>
672 9eac43d7 bcyrill
							<a href="system_camanager.php?act=expkey&amp;id=<?=$i;?>">
673 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" />
674 ecefc738 jim-p
							</a>
675
							<?php endif; ?>
676 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?");?>')">
677 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" />
678 96c7a492 Matthew Grooms
							</a>
679
						</td>
680
					</tr>
681
					<?php
682
							$i++;
683
						endforeach;
684
					?>
685
					<tr>
686 2cf6ddcb Nigel Graham
						<td class="list" colspan="5"></td>
687 96c7a492 Matthew Grooms
						<td class="list">
688
							<a href="system_camanager.php?act=new">
689 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" />
690 96c7a492 Matthew Grooms
							</a>
691
						</td>
692 64cc39d3 Matthew Grooms
					</tr>
693
					<tr>
694 2cf6ddcb Nigel Graham
						<td colspan="5">
695 96c7a492 Matthew Grooms
							<p>
696 22a11a58 Larry Gilbert
								<?=gettext("Additional trusted Certificate Authorities can be added here.");?>
697 96c7a492 Matthew Grooms
							</p>
698 64cc39d3 Matthew Grooms
						</td>
699
					</tr>
700
				</table>
701
702 96c7a492 Matthew Grooms
				<?php endif; ?>
703
704
			</div>
705 64cc39d3 Matthew Grooms
		</td>
706
	</tr>
707
</table>
708
<?php include("fend.inc");?>
709
<script type="text/javascript">
710 96028288 Colin Fleming
//<![CDATA[
711 64cc39d3 Matthew Grooms
712
method_change();
713
714 96028288 Colin Fleming
//]]>
715 64cc39d3 Matthew Grooms
</script>
716
717
</body>
718 39530c89 bcyrill
</html>