Project

General

Profile

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