Project

General

Profile

Download (25.8 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 e41ec584 Renato Botelho
if (is_numericint($_GET['id']))
54
	$id = $_GET['id'];
55
if (isset($_POST['id']) && is_numericint($_POST['id']))
56 64cc39d3 Matthew Grooms
	$id = $_POST['id'];
57
58 b4e6524c jim-p
if (!is_array($config['ca']))
59
	$config['ca'] = array();
60 64cc39d3 Matthew Grooms
61 b4e6524c jim-p
$a_ca =& $config['ca'];
62 64cc39d3 Matthew Grooms
63 b4e6524c jim-p
if (!is_array($config['cert']))
64
	$config['cert'] = array();
65 64cc39d3 Matthew Grooms
66 b4e6524c jim-p
$a_cert =& $config['cert'];
67 64cc39d3 Matthew Grooms
68 461aa9d0 jim-p
if (!is_array($config['crl']))
69
	$config['crl'] = array();
70
71
$a_crl =& $config['crl'];
72
73 64cc39d3 Matthew Grooms
$act = $_GET['act'];
74
if ($_POST['act'])
75
	$act = $_POST['act'];
76
77
if ($act == "del") {
78
79 40e6086a jim-p
	if (!isset($a_ca[$id])) {
80 64cc39d3 Matthew Grooms
		pfSenseHeader("system_camanager.php");
81
		exit;
82
	}
83
84
	$index = count($a_cert) - 1;
85
	for (;$index >=0; $index--)
86
		if ($a_cert[$index]['caref'] == $a_ca[$id]['refid'])
87
			unset($a_cert[$index]);
88
89 461aa9d0 jim-p
	$index = count($a_crl) - 1;
90
	for (;$index >=0; $index--)
91
		if ($a_crl[$index]['caref'] == $a_ca[$id]['refid'])
92
			unset($a_crl[$index]);
93
94 f2a86ca9 jim-p
	$name = $a_ca[$id]['descr'];
95 64cc39d3 Matthew Grooms
	unset($a_ca[$id]);
96
	write_config();
97 8cd558b6 ayvis
	$savemsg = sprintf(gettext("Certificate Authority %s and its CRLs (if any) successfully deleted"), $name) . "<br />";
98 2f51259b jim-p
	pfSenseHeader("system_camanager.php");
99
	exit;
100 64cc39d3 Matthew Grooms
}
101
102 bfa992bc jim-p
if ($act == "edit") {
103
	if (!$a_ca[$id]) {
104
		pfSenseHeader("system_camanager.php");
105
		exit;
106
	}
107
	$pconfig['descr']  = $a_ca[$id]['descr'];
108
	$pconfig['refid']  = $a_ca[$id]['refid'];
109
	$pconfig['cert']   = base64_decode($a_ca[$id]['crt']);
110
	$pconfig['serial'] = $a_ca[$id]['serial'];
111
	if (!empty($a_ca[$id]['prv']))
112
		$pconfig['key'] = base64_decode($a_ca[$id]['prv']);
113
}
114
115 64cc39d3 Matthew Grooms
if ($act == "new") {
116
	$pconfig['method'] = $_GET['method'];
117
	$pconfig['keylen'] = "2048";
118 28a20fdb jim-p
	$pconfig['digest_alg'] = "sha256";
119 cf360495 Chris Buechler
	$pconfig['lifetime'] = "3650";
120 64cc39d3 Matthew Grooms
	$pconfig['dn_commonname'] = "internal-ca";
121
}
122
123 93823b10 Matthew Grooms
if ($act == "exp") {
124
125
	if (!$a_ca[$id]) {
126
		pfSenseHeader("system_camanager.php");
127
		exit;
128
	}
129
130 f2a86ca9 jim-p
	$exp_name = urlencode("{$a_ca[$id]['descr']}.crt");
131 93823b10 Matthew Grooms
	$exp_data = base64_decode($a_ca[$id]['crt']);
132
	$exp_size = strlen($exp_data);
133
134
	header("Content-Type: application/octet-stream");
135
	header("Content-Disposition: attachment; filename={$exp_name}");
136
	header("Content-Length: $exp_size");
137
	echo $exp_data;
138
	exit;
139
}
140
141 ecefc738 jim-p
if ($act == "expkey") {
142
143
	if (!$a_ca[$id]) {
144
		pfSenseHeader("system_camanager.php");
145
		exit;
146
	}
147
148 f2a86ca9 jim-p
	$exp_name = urlencode("{$a_ca[$id]['descr']}.key");
149 ecefc738 jim-p
	$exp_data = base64_decode($a_ca[$id]['prv']);
150
	$exp_size = strlen($exp_data);
151
152
	header("Content-Type: application/octet-stream");
153
	header("Content-Disposition: attachment; filename={$exp_name}");
154
	header("Content-Length: $exp_size");
155
	echo $exp_data;
156
	exit;
157
}
158
159 64cc39d3 Matthew Grooms
if ($_POST) {
160
161 95c8cf48 Evgeny Yurchenko
	unset($input_errors);
162 2b8bfda4 Phil Davis
	$input_errors = array();
163 64cc39d3 Matthew Grooms
	$pconfig = $_POST;
164
165
	/* input validation */
166
	if ($pconfig['method'] == "existing") {
167 5293bfec jim-p
		$reqdfields = explode(" ", "descr cert");
168 38fb1109 Vinicius Coque
		$reqdfieldsn = array(
169
				gettext("Descriptive name"),
170
				gettext("Certificate data"));
171 396cfe2e jim-p
		if ($_POST['cert'] && (!strstr($_POST['cert'], "BEGIN CERTIFICATE") || !strstr($_POST['cert'], "END CERTIFICATE")))
172
			$input_errors[] = gettext("This certificate does not appear to be valid.");
173 46698c3f jim-p
		if ($_POST['key'] && strstr($_POST['key'], "ENCRYPTED"))
174
			$input_errors[] = gettext("Encrypted private keys are not yet supported.");
175 64cc39d3 Matthew Grooms
	}
176
	if ($pconfig['method'] == "internal") {
177
		$reqdfields = explode(" ",
178 5293bfec jim-p
				"descr keylen lifetime dn_country dn_state dn_city ".
179 64cc39d3 Matthew Grooms
				"dn_organization dn_email dn_commonname");
180 38fb1109 Vinicius Coque
		$reqdfieldsn = array(
181
				gettext("Descriptive name"),
182
				gettext("Key length"),
183
				gettext("Lifetime"),
184
				gettext("Distinguished name Country Code"),
185
				gettext("Distinguished name State or Province"),
186
				gettext("Distinguished name City"),
187
				gettext("Distinguished name Organization"),
188
				gettext("Distinguished name Email Address"),
189 a37753d7 Vinicius Coque
				gettext("Distinguished name Common Name"));
190 64cc39d3 Matthew Grooms
	}
191 95c8cf48 Evgeny Yurchenko
	if ($pconfig['method'] == "intermediate") {
192
		$reqdfields = explode(" ",
193
				"descr caref keylen lifetime dn_country dn_state dn_city ".
194
				"dn_organization dn_email dn_commonname");
195
		$reqdfieldsn = array(
196
				gettext("Descriptive name"),
197
				gettext("Signing Certificate Authority"),
198
				gettext("Key length"),
199
				gettext("Lifetime"),
200
				gettext("Distinguished name Country Code"),
201
				gettext("Distinguished name State or Province"),
202
				gettext("Distinguished name City"),
203
				gettext("Distinguished name Organization"),
204
				gettext("Distinguished name Email Address"),
205
				gettext("Distinguished name Common Name"));
206
	}
207 64cc39d3 Matthew Grooms
208 1e9b4611 Renato Botelho
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
209 ca621902 jim-p
	if ($pconfig['method'] != "existing") {
210 21cc2faa Evgeny Yurchenko
		/* Make sure we do not have invalid characters in the fields for the certificate */
211
		for ($i = 0; $i < count($reqdfields); $i++) {
212
			if ($reqdfields[$i] == 'dn_email'){
213
				if (preg_match("/[\!\#\$\%\^\(\)\~\?\>\<\&\/\\\,\"\']/", $_POST["dn_email"]))
214
					array_push($input_errors, "The field 'Distinguished name Email Address' contains invalid characters.");
215
			}else if ($reqdfields[$i] == 'dn_commonname'){
216
				if (preg_match("/[\!\@\#\$\%\^\(\)\~\?\>\<\&\/\\\,\"\']/", $_POST["dn_commonname"]))
217
					array_push($input_errors, "The field 'Distinguished name Common Name' contains invalid characters.");
218 00a695c8 jim-p
			}else if (($reqdfields[$i] != "descr") && preg_match("/[\!\@\#\$\%\^\(\)\~\?\>\<\&\/\\\,\.\"\']/", $_POST["$reqdfields[$i]"]))
219 21cc2faa Evgeny Yurchenko
				array_push($input_errors, "The field '" . $reqdfieldsn[$i] . "' contains invalid characters.");
220
		}
221 ca621902 jim-p
		if (!in_array($_POST["keylen"], $ca_keylens))
222
			array_push($input_errors, gettext("Please select a valid Key Length."));
223
		if (!in_array($_POST["digest_alg"], $openssl_digest_algs))
224
			array_push($input_errors, gettext("Please select a valid Digest Algorithm."));
225
	}
226 64cc39d3 Matthew Grooms
227
	/* if this is an AJAX caller then handle via JSON */
228
	if (isAjax() && is_array($input_errors)) {
229
		input_errors2Ajax($input_errors);
230
		exit;
231
	}
232
233
	/* save modifications */
234
	if (!$input_errors) {
235
236
		$ca = array();
237 bfa992bc jim-p
		if (!isset($pconfig['refid']) || empty($pconfig['refid']))
238
			$ca['refid'] = uniqid();
239
		else
240
			$ca['refid'] = $pconfig['refid'];
241
242 64cc39d3 Matthew Grooms
		if (isset($id) && $a_ca[$id])
243
			$ca = $a_ca[$id];
244
245 bfa992bc jim-p
		$ca['descr'] = $pconfig['descr'];
246
247
		if ($_POST['edit'] == "edit") {
248
			$ca['descr']  = $pconfig['descr'];
249
			$ca['refid']  = $pconfig['refid'];
250
			$ca['serial'] = $pconfig['serial'];
251
			$ca['crt']    = base64_encode($pconfig['cert']);
252
			if (!empty($pconfig['key']))
253
				$ca['prv']    = base64_encode($pconfig['key']);
254
		} else {
255 1b6d9fa5 Evgeny Yurchenko
			$old_err_level = error_reporting(0); /* otherwise openssl_ functions throw warings directly to a page screwing menu tab */
256 bfa992bc jim-p
			if ($pconfig['method'] == "existing")
257
				ca_import($ca, $pconfig['cert'], $pconfig['key'], $pconfig['serial']);
258
259 95c8cf48 Evgeny Yurchenko
			else if ($pconfig['method'] == "internal") {
260 bfa992bc jim-p
				$dn = array(
261
					'countryName' => $pconfig['dn_country'],
262
					'stateOrProvinceName' => $pconfig['dn_state'],
263
					'localityName' => $pconfig['dn_city'],
264
					'organizationName' => $pconfig['dn_organization'],
265
					'emailAddress' => $pconfig['dn_email'],
266
					'commonName' => $pconfig['dn_commonname']);
267 ca621902 jim-p
				if (!ca_create($ca, $pconfig['keylen'], $pconfig['lifetime'], $dn, $pconfig['digest_alg'])){
268 1b6d9fa5 Evgeny Yurchenko
					while($ssl_err = openssl_error_string()){
269
						$input_errors = array();
270
						array_push($input_errors, "openssl library returns: " . $ssl_err);
271
					}
272
				}
273 bfa992bc jim-p
			}
274 95c8cf48 Evgeny Yurchenko
			else if ($pconfig['method'] == "intermediate") {
275
				$dn = array(
276
					'countryName' => $pconfig['dn_country'],
277
					'stateOrProvinceName' => $pconfig['dn_state'],
278
					'localityName' => $pconfig['dn_city'],
279
					'organizationName' => $pconfig['dn_organization'],
280
					'emailAddress' => $pconfig['dn_email'],
281
					'commonName' => $pconfig['dn_commonname']);
282 ca621902 jim-p
				if (!ca_inter_create($ca, $pconfig['keylen'], $pconfig['lifetime'], $dn, $pconfig['caref'], $pconfig['digest_alg'])){
283 95c8cf48 Evgeny Yurchenko
					while($ssl_err = openssl_error_string()){
284
						$input_errors = array();
285
						array_push($input_errors, "openssl library returns: " . $ssl_err);
286
					}
287
				}
288
			}
289 1b6d9fa5 Evgeny Yurchenko
			error_reporting($old_err_level);
290 64cc39d3 Matthew Grooms
		}
291
292
		if (isset($id) && $a_ca[$id])
293
			$a_ca[$id] = $ca;
294
		else
295
			$a_ca[] = $ca;
296
297 95c8cf48 Evgeny Yurchenko
		if (!$input_errors)
298
			write_config();
299 64cc39d3 Matthew Grooms
300
//		pfSenseHeader("system_camanager.php");
301
	}
302
}
303
304
include("head.inc");
305
?>
306
307
<body link="#000000" vlink="#000000" alink="#000000" onload="<?= $jsevents["body"]["onload"] ?>">
308
<?php include("fbegin.inc"); ?>
309
<script type="text/javascript">
310 96028288 Colin Fleming
//<![CDATA[
311 64cc39d3 Matthew Grooms
312
function method_change() {
313
314
	method = document.iform.method.selectedIndex;
315
316
	switch (method) {
317
		case 0:
318
			document.getElementById("existing").style.display="";
319
			document.getElementById("internal").style.display="none";
320 95c8cf48 Evgeny Yurchenko
			document.getElementById("intermediate").style.display="none";
321 64cc39d3 Matthew Grooms
			break;
322
		case 1:
323
			document.getElementById("existing").style.display="none";
324
			document.getElementById("internal").style.display="";
325 95c8cf48 Evgeny Yurchenko
			document.getElementById("intermediate").style.display="none";
326
			break;
327
		case 2:
328
			document.getElementById("existing").style.display="none";
329
			document.getElementById("internal").style.display="";
330
			document.getElementById("intermediate").style.display="";
331 64cc39d3 Matthew Grooms
			break;
332
	}
333
}
334
335 96028288 Colin Fleming
//]]>
336 64cc39d3 Matthew Grooms
</script>
337
<?php
338
	if ($input_errors)
339
		print_input_errors($input_errors);
340
	if ($savemsg)
341
		print_info_box($savemsg);
342 9d2d65f3 Evgeny Yurchenko
343
	// Load valid country codes
344
	$dn_cc = array();
345
	if (file_exists("/etc/ca_countries")){
346
		$dn_cc_file=file("/etc/ca_countries");
347
		foreach($dn_cc_file as $line)
348
			if (preg_match('/^(\S*)\s(.*)$/', $line, $matches))
349
				array_push($dn_cc, $matches[1]);
350
	}
351 64cc39d3 Matthew Grooms
?>
352 96028288 Colin Fleming
<table width="100%" border="0" cellpadding="0" cellspacing="0" summary="CA manager">
353 64cc39d3 Matthew Grooms
	<tr>
354 96c7a492 Matthew Grooms
		<td>
355 64cc39d3 Matthew Grooms
		<?php
356
			$tab_array = array();
357
			$tab_array[] = array(gettext("CAs"), true, "system_camanager.php");
358
			$tab_array[] = array(gettext("Certificates"), false, "system_certmanager.php");
359 3d57d2d5 jim-p
			$tab_array[] = array(gettext("Certificate Revocation"), false, "system_crlmanager.php");
360 64cc39d3 Matthew Grooms
			display_top_tabs($tab_array);
361
		?>
362
		</td>
363
	</tr>
364
	<tr>
365 96c7a492 Matthew Grooms
		<td id="mainarea">
366
			<div class="tabcont">
367
368 bfa992bc jim-p
				<?php if ($act == "new" || $act == "edit" || $act == gettext("Save") || $input_errors): ?>
369 96c7a492 Matthew Grooms
370
				<form action="system_camanager.php" method="post" name="iform" id="iform">
371 bfa992bc jim-p
					<?php if ($act == "edit"): ?>
372 96028288 Colin Fleming
					<input type="hidden" name="edit" value="edit" id="edit" />
373 e41ec584 Renato Botelho
					<input type="hidden" name="id" value="<?php echo htmlspecialchars($id); ?>" id="id" />
374 96028288 Colin Fleming
					<input type="hidden" name="refid" value="<?php echo $pconfig['refid']; ?>" id="refid" />
375 bfa992bc jim-p
					<?php endif; ?>
376 96028288 Colin Fleming
					<table width="100%" border="0" cellpadding="6" cellspacing="0" summary="main area">
377 96c7a492 Matthew Grooms
						<tr>
378
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Descriptive name");?></td>
379
							<td width="78%" class="vtable">
380 f2a86ca9 jim-p
								<input name="descr" type="text" class="formfld unknown" id="descr" size="20" value="<?=htmlspecialchars($pconfig['descr']);?>"/>
381 96c7a492 Matthew Grooms
							</td>
382
						</tr>
383 bfa992bc jim-p
						<?php if (!isset($id) || $act == "edit"): ?>
384 96c7a492 Matthew Grooms
						<tr>
385
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Method");?></td>
386
							<td width="78%" class="vtable">
387
								<select name='method' id='method' class="formselect" onchange='method_change()'>
388
								<?php
389
									foreach($ca_methods as $method => $desc):
390
									$selected = "";
391
									if ($pconfig['method'] == $method)
392 96028288 Colin Fleming
										$selected = " selected=\"selected\"";
393 96c7a492 Matthew Grooms
								?>
394
									<option value="<?=$method;?>"<?=$selected;?>><?=$desc;?></option>
395
								<?php endforeach; ?>
396
								</select>
397
							</td>
398
						</tr>
399
						<?php endif; ?>
400
					</table>
401
402 96028288 Colin Fleming
					<table width="100%" border="0" cellpadding="6" cellspacing="0" id="existing" summary="existing">
403 96c7a492 Matthew Grooms
						<tr>
404
							<td colspan="2" class="list" height="12"></td>
405
						</tr>
406
						<tr>
407 a37753d7 Vinicius Coque
							<td colspan="2" valign="top" class="listtopic"><?=gettext("Existing Certificate Authority");?></td>
408 96c7a492 Matthew Grooms
						</tr>
409
410
						<tr>
411 a37753d7 Vinicius Coque
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Certificate data");?></td>
412 96c7a492 Matthew Grooms
							<td width="78%" class="vtable">
413 dd5bf424 Scott Ullrich
								<textarea name="cert" id="cert" cols="65" rows="7" class="formfld_cert"><?=htmlspecialchars($pconfig['cert']);?></textarea>
414 8cd558b6 ayvis
								<br />
415 39530c89 bcyrill
								<?=gettext("Paste a certificate in X.509 PEM format here.");?>
416 96c7a492 Matthew Grooms
							</td>
417
						</tr>
418 ecefc738 jim-p
						<tr>
419 8cd558b6 ayvis
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Certificate Private Key");?><br /><?=gettext("(optional)");?></td>
420 ecefc738 jim-p
							<td width="78%" class="vtable">
421 dd5bf424 Scott Ullrich
								<textarea name="key" id="key" cols="65" rows="7" class="formfld_cert"><?=htmlspecialchars($pconfig['key']);?></textarea>
422 8cd558b6 ayvis
								<br />
423 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).");?>
424 ecefc738 jim-p
							</td>
425
						</tr>
426 bfa992bc jim-p
427
					<?php if (!isset($id) || $act == "edit"): ?>
428
						<tr>
429 51c24cf6 jim-p
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Serial for next certificate");?></td>
430 bfa992bc jim-p
							<td width="78%" class="vtable">
431
								<input name="serial" type="text" class="formfld unknown" id="serial" size="20" value="<?=htmlspecialchars($pconfig['serial']);?>"/>
432 8cd558b6 ayvis
								<br /><?=gettext("Enter a decimal number to be used as the serial number for the next certificate to be created using this CA.");?>
433 bfa992bc jim-p
							</td>
434
						</tr>
435
					<?php endif; ?>
436 96c7a492 Matthew Grooms
					</table>
437
438 96028288 Colin Fleming
					<table width="100%" border="0" cellpadding="6" cellspacing="0" id="internal" summary="internal">
439 96c7a492 Matthew Grooms
						<tr>
440
							<td colspan="2" class="list" height="12"></td>
441
						</tr>
442
						<tr>
443 a37753d7 Vinicius Coque
							<td colspan="2" valign="top" class="listtopic"><?=gettext("Internal Certificate Authority");?></td>
444 96c7a492 Matthew Grooms
						</tr>
445 95c8cf48 Evgeny Yurchenko
						<tr id='intermediate'>
446
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Signing Certificate Authority");?></td>
447
							<td width="78%" class="vtable">
448 4b0dbd37 Colin Fleming
                                                                <select name='caref' id='caref' class="formselect" onchange='internalca_change()'>
449 95c8cf48 Evgeny Yurchenko
                                                                <?php
450
                                                                        foreach( $a_ca as $ca):
451
                                                                        if (!$ca['prv'])
452
                                                                                continue;
453
                                                                        $selected = "";
454
                                                                        if ($pconfig['caref'] == $ca['refid'])
455 96028288 Colin Fleming
                                                                                $selected = " selected=\"selected\"";
456 95c8cf48 Evgeny Yurchenko
                                                                ?>
457
                                                                        <option value="<?=$ca['refid'];?>"<?=$selected;?>><?=$ca['descr'];?></option>
458
                                                                <?php endforeach; ?>
459
                                                                </select>
460
							</td>
461
						</tr>
462 96c7a492 Matthew Grooms
						<tr>
463
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Key length");?></td>
464
							<td width="78%" class="vtable">
465
								<select name='keylen' id='keylen' class="formselect">
466
								<?php
467
									foreach( $ca_keylens as $len):
468
									$selected = "";
469
									if ($pconfig['keylen'] == $len)
470 96028288 Colin Fleming
										$selected = " selected=\"selected\"";
471 96c7a492 Matthew Grooms
								?>
472
									<option value="<?=$len;?>"<?=$selected;?>><?=$len;?></option>
473
								<?php endforeach; ?>
474
								</select>
475 ea53e38f Renato Botelho
								<?=gettext("bits");?>
476 96c7a492 Matthew Grooms
							</td>
477
						</tr>
478 ca621902 jim-p
						<tr>
479
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Digest Algorithm");?></td>
480
							<td width="78%" class="vtable">
481
								<select name='digest_alg' id='digest_alg' class="formselect">
482
								<?php
483
									foreach( $openssl_digest_algs as $digest_alg):
484
									$selected = "";
485
									if ($pconfig['digest_alg'] == $digest_alg)
486 96028288 Colin Fleming
										$selected = " selected=\"selected\"";
487 ca621902 jim-p
								?>
488
									<option value="<?=$digest_alg;?>"<?=$selected;?>><?=strtoupper($digest_alg);?></option>
489
								<?php endforeach; ?>
490
								</select>
491 8cd558b6 ayvis
								<br /><?= gettext("NOTE: It is recommended to use an algorithm stronger than SHA1 when possible.") ?>
492 ca621902 jim-p
							</td>
493
						</tr>
494 96c7a492 Matthew Grooms
						<tr>
495
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Lifetime");?></td>
496
							<td width="78%" class="vtable">
497
								<input name="lifetime" type="text" class="formfld unknown" id="lifetime" size="5" value="<?=htmlspecialchars($pconfig['lifetime']);?>"/>
498 ea53e38f Renato Botelho
								<?=gettext("days");?>
499 96c7a492 Matthew Grooms
							</td>
500
						</tr>
501
						<tr>
502
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Distinguished name");?></td>
503
							<td width="78%" class="vtable">
504 96028288 Colin Fleming
								<table border="0" cellspacing="0" cellpadding="2" summary="name">
505 96c7a492 Matthew Grooms
									<tr>
506 a37753d7 Vinicius Coque
										<td align="right"><?=gettext("Country Code");?> : &nbsp;</td>
507 96c7a492 Matthew Grooms
										<td align="left">
508 9d2d65f3 Evgeny Yurchenko
											<select name='dn_country' class="formselect">
509
											<?php
510
											foreach( $dn_cc as $cc){
511
												$selected = "";
512 39530c89 bcyrill
												if ($pconfig['dn_country'] == $cc)
513 96028288 Colin Fleming
													$selected = " selected=\"selected\"";
514 39530c89 bcyrill
												print "<option value=\"$cc\"$selected>$cc</option>";
515 9d2d65f3 Evgeny Yurchenko
												}
516
											?>
517
											</select>
518 96c7a492 Matthew Grooms
										</td>
519
									</tr>
520
									<tr>
521 a37753d7 Vinicius Coque
										<td align="right"><?=gettext("State or Province");?> : &nbsp;</td>
522 96c7a492 Matthew Grooms
										<td align="left">
523
											<input name="dn_state" type="text" class="formfld unknown" size="40" value="<?=htmlspecialchars($pconfig['dn_state']);?>"/>
524
											&nbsp;
525 ea53e38f Renato Botelho
											<em><?=gettext("ex:");?></em>
526 96c7a492 Matthew Grooms
											&nbsp;
527 a37753d7 Vinicius Coque
											<?=gettext("Texas");?>
528 96c7a492 Matthew Grooms
										</td>
529
									</tr>
530
									<tr>
531 a37753d7 Vinicius Coque
										<td align="right"><?=gettext("City");?> : &nbsp;</td>
532 96c7a492 Matthew Grooms
										<td align="left">
533
											<input name="dn_city" type="text" class="formfld unknown" size="40" value="<?=htmlspecialchars($pconfig['dn_city']);?>"/>
534
											&nbsp;
535 ea53e38f Renato Botelho
											<em><?=gettext("ex:");?></em>
536 96c7a492 Matthew Grooms
											&nbsp;
537 a37753d7 Vinicius Coque
											<?=gettext("Austin");?>
538 96c7a492 Matthew Grooms
										</td>
539
									</tr>
540
									<tr>
541 a37753d7 Vinicius Coque
										<td align="right"><?=gettext("Organization");?> : &nbsp;</td>
542 96c7a492 Matthew Grooms
										<td align="left">
543
											<input name="dn_organization" type="text" class="formfld unknown" size="40" value="<?=htmlspecialchars($pconfig['dn_organization']);?>"/>
544
											&nbsp;
545 ea53e38f Renato Botelho
											<em><?=gettext("ex:");?></em>
546 96c7a492 Matthew Grooms
											&nbsp;
547 a37753d7 Vinicius Coque
											<?=gettext("My Company Inc.");?>
548 96c7a492 Matthew Grooms
										</td>
549
									</tr>
550
									<tr>
551 a37753d7 Vinicius Coque
										<td align="right"><?=gettext("Email Address");?> : &nbsp;</td>
552 96c7a492 Matthew Grooms
										<td align="left">
553
											<input name="dn_email" type="text" class="formfld unknown" size="25" value="<?=htmlspecialchars($pconfig['dn_email']);?>"/>
554
											&nbsp;
555 ea53e38f Renato Botelho
											<em><?=gettext("ex:");?></em>
556 96c7a492 Matthew Grooms
											&nbsp;
557 a37753d7 Vinicius Coque
											<?=gettext("admin@mycompany.com");?>
558 96c7a492 Matthew Grooms
										</td>
559
									</tr>
560
									<tr>
561 a37753d7 Vinicius Coque
										<td align="right"><?=gettext("Common Name");?> : &nbsp;</td>
562 96c7a492 Matthew Grooms
										<td align="left">
563
											<input name="dn_commonname" type="text" class="formfld unknown" size="25" value="<?=htmlspecialchars($pconfig['dn_commonname']);?>"/>
564
											&nbsp;
565 ea53e38f Renato Botelho
											<em><?=gettext("ex:");?></em>
566 96c7a492 Matthew Grooms
											&nbsp;
567 a37753d7 Vinicius Coque
											<?=gettext("internal-ca");?>
568 96c7a492 Matthew Grooms
										</td>
569
									</tr>
570
								</table>
571
							</td>
572
						</tr>
573
					</table>
574
575 96028288 Colin Fleming
					<table width="100%" border="0" cellpadding="6" cellspacing="0" summary="save">
576 96c7a492 Matthew Grooms
						<tr>
577
							<td width="22%" valign="top">&nbsp;</td>
578
							<td width="78%">
579 443ddf6f Carlos Eduardo Ramos
								<input id="submit" name="save" type="submit" class="formbtn" value="<?=gettext("Save"); ?>" />
580 96c7a492 Matthew Grooms
								<?php if (isset($id) && $a_ca[$id]): ?>
581 e41ec584 Renato Botelho
								<input name="id" type="hidden" value="<?=htmlspecialchars($id);?>" />
582 96c7a492 Matthew Grooms
								<?php endif;?>
583
							</td>
584
						</tr>
585
					</table>
586
				</form>
587
588
				<?php else: ?>
589
590 96028288 Colin Fleming
				<table width="100%" border="0" cellpadding="0" cellspacing="0" summary="">
591 64cc39d3 Matthew Grooms
					<tr>
592 a37753d7 Vinicius Coque
						<td width="20%" class="listhdrr"><?=gettext("Name");?></td>
593
						<td width="10%" class="listhdrr"><?=gettext("Internal");?></td>
594
						<td width="10%" class="listhdrr"><?=gettext("Issuer");?></td>
595
						<td width="10%" class="listhdrr"><?=gettext("Certificates");?></td>
596
						<td width="40%" class="listhdrr"><?=gettext("Distinguished Name");?></td>
597 96c7a492 Matthew Grooms
						<td width="10%" class="list"></td>
598 64cc39d3 Matthew Grooms
					</tr>
599 96c7a492 Matthew Grooms
					<?php
600
						$i = 0;
601
						foreach($a_ca as $ca):
602 f2a86ca9 jim-p
							$name = htmlspecialchars($ca['descr']);
603 96c7a492 Matthew Grooms
							$subj = cert_get_subject($ca['crt']);
604 2cf6ddcb Nigel Graham
							$issuer = cert_get_issuer($ca['crt']);
605 2b333210 jim-p
							list($startdate, $enddate) = cert_get_dates($ca['crt']);
606 2cf6ddcb Nigel Graham
							if($subj == $issuer)
607 a37753d7 Vinicius Coque
							  $issuer_name = "<em>" . gettext("self-signed") . "</em>";
608 2cf6ddcb Nigel Graham
							else
609 a37753d7 Vinicius Coque
							  $issuer_name = "<em>" . gettext("external") . "</em>";
610 96c7a492 Matthew Grooms
							$subj = htmlspecialchars($subj);
611 2cf6ddcb Nigel Graham
							$issuer = htmlspecialchars($issuer);
612 96c7a492 Matthew Grooms
							$certcount = 0;
613
614 2cf6ddcb Nigel Graham
							$issuer_ca = lookup_ca($ca['caref']);
615
							if ($issuer_ca)
616 f2a86ca9 jim-p
								$issuer_name = $issuer_ca['descr'];
617 2cf6ddcb Nigel Graham
618 96c7a492 Matthew Grooms
							// TODO : Need gray certificate icon
619
620
							if($ca['prv']) {
621
								$caimg = "/themes/{$g['theme']}/images/icons/icon_frmfld_cert.png";
622
								$internal = "YES";
623
624
							} else {
625
								$caimg = "/themes/{$g['theme']}/images/icons/icon_frmfld_cert.png";
626
								$internal = "NO";
627
							}
628 2cf6ddcb Nigel Graham
							foreach ($a_cert as $cert)
629
								if ($cert['caref'] == $ca['refid'])
630
									$certcount++;
631
  						foreach ($a_ca as $cert)
632
  							if ($cert['caref'] == $ca['refid'])
633
  								$certcount++;
634 96c7a492 Matthew Grooms
					?>
635 64cc39d3 Matthew Grooms
					<tr>
636 96c7a492 Matthew Grooms
						<td class="listlr">
637 96028288 Colin Fleming
							<table border="0" cellpadding="0" cellspacing="0" summary="icon">
638 64cc39d3 Matthew Grooms
								<tr>
639 96028288 Colin Fleming
									<td align="left" valign="middle">
640 96c7a492 Matthew Grooms
										<img src="<?=$caimg;?>" alt="CA" title="CA" border="0" height="16" width="16" />
641 64cc39d3 Matthew Grooms
									</td>
642 96c7a492 Matthew Grooms
									<td align="left" valign="middle">
643
										<?=$name;?>
644 64cc39d3 Matthew Grooms
									</td>
645
								</tr>
646
							</table>
647
						</td>
648 96c7a492 Matthew Grooms
						<td class="listr"><?=$internal;?>&nbsp;</td>
649 2cf6ddcb Nigel Graham
						<td class="listr"><?=$issuer_name;?>&nbsp;</td>
650 96c7a492 Matthew Grooms
						<td class="listr"><?=$certcount;?>&nbsp;</td>
651 2b333210 jim-p
						<td class="listr"><?=$subj;?><br />
652 96028288 Colin Fleming
							<table width="100%" style="font-size: 9px" summary="valid">
653 2b333210 jim-p
								<tr>
654
									<td width="10%">&nbsp;</td>
655
									<td width="20%"><?=gettext("Valid From")?>:</td>
656
									<td width="70%"><?= $startdate ?></td>
657
								</tr>
658
								<tr>
659
									<td>&nbsp;</td>
660
									<td><?=gettext("Valid Until")?>:</td>
661
									<td><?= $enddate ?></td>
662
								</tr>
663
							</table>
664
						</td>
665 4b0dbd37 Colin Fleming
						<td valign="middle" class="list nowrap">
666 9eac43d7 bcyrill
							<a href="system_camanager.php?act=edit&amp;id=<?=$i;?>">
667 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" />
668 bfa992bc jim-p
							</a>
669 9eac43d7 bcyrill
							<a href="system_camanager.php?act=exp&amp;id=<?=$i;?>">
670 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" />
671 96c7a492 Matthew Grooms
							</a>
672 ecefc738 jim-p
							<?php if ($ca['prv']): ?>
673 9eac43d7 bcyrill
							<a href="system_camanager.php?act=expkey&amp;id=<?=$i;?>">
674 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" />
675 ecefc738 jim-p
							</a>
676
							<?php endif; ?>
677 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?");?>')">
678 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" />
679 96c7a492 Matthew Grooms
							</a>
680
						</td>
681
					</tr>
682
					<?php
683
							$i++;
684
						endforeach;
685
					?>
686
					<tr>
687 2cf6ddcb Nigel Graham
						<td class="list" colspan="5"></td>
688 96c7a492 Matthew Grooms
						<td class="list">
689
							<a href="system_camanager.php?act=new">
690 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" />
691 96c7a492 Matthew Grooms
							</a>
692
						</td>
693 64cc39d3 Matthew Grooms
					</tr>
694
					<tr>
695 2cf6ddcb Nigel Graham
						<td colspan="5">
696 96c7a492 Matthew Grooms
							<p>
697 22a11a58 Larry Gilbert
								<?=gettext("Additional trusted Certificate Authorities can be added here.");?>
698 96c7a492 Matthew Grooms
							</p>
699 64cc39d3 Matthew Grooms
						</td>
700
					</tr>
701
				</table>
702
703 96c7a492 Matthew Grooms
				<?php endif; ?>
704
705
			</div>
706 64cc39d3 Matthew Grooms
		</td>
707
	</tr>
708
</table>
709
<?php include("fend.inc");?>
710
<script type="text/javascript">
711 96028288 Colin Fleming
//<![CDATA[
712 64cc39d3 Matthew Grooms
713
method_change();
714
715 96028288 Colin Fleming
//]]>
716 64cc39d3 Matthew Grooms
</script>
717
718
</body>
719 39530c89 bcyrill
</html>