Project

General

Profile

Download (33.4 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
    system_certmanager.php
4

    
5
    Copyright (C) 2008 Shrew Soft Inc.
6
    All rights reserved.
7

    
8
    Redistribution and use in source and binary forms, with or without
9
    modification, are permitted provided that the following conditions are met:
10

    
11
    1. Redistributions of source code must retain the above copyright notice,
12
       this list of conditions and the following disclaimer.
13

    
14
    2. Redistributions in binary form must reproduce the above copyright
15
       notice, this list of conditions and the following disclaimer in the
16
       documentation and/or other materials provided with the distribution.
17

    
18
    THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
19
    INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
20
    AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
21
    AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
22
    OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23
    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24
    INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25
    CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26
    ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27
    POSSIBILITY OF SUCH DAMAGE.
28
*/
29
/*
30
	pfSense_MODULE:	certificate_managaer
31
*/
32

    
33
##|+PRIV
34
##|*IDENT=page-system-certmanager
35
##|*NAME=System: Certificate Manager
36
##|*DESCR=Allow access to the 'System: Certificate Manager' page.
37
##|*MATCH=system_certmanager.php*
38
##|-PRIV
39

    
40
require("guiconfig.inc");
41
require_once("certs.inc");
42

    
43
$cert_methods = array(
44
	"import" => gettext("Import an existing Certificate"),
45
	"internal" => gettext("Create an internal Certificate"),
46
	"external" => gettext("Create a Certificate Signing Request"),
47
);
48

    
49
$cert_keylens = array( "512", "1024", "2048", "4096");
50

    
51
$pgtitle = array(gettext("System"), gettext("Certificate Manager"));
52

    
53
$userid = $_GET['userid'];
54
if (isset($_POST['userid']))
55
	$userid = $_POST['userid'];
56
if ($userid) {
57
	$cert_methods["existing"] = gettext("Choose an existing certificate");
58
	if (!is_array($config['system']['user']))
59
		$config['system']['user'] = array();
60
	$a_user =& $config['system']['user'];
61
}
62

    
63
$id = $_GET['id'];
64
if (isset($_POST['id']))
65
	$id = $_POST['id'];
66

    
67
if (!is_array($config['ca']))
68
	$config['ca'] = array();
69

    
70
$a_ca =& $config['ca'];
71

    
72
if (!is_array($config['cert']))
73
	$config['cert'] = array();
74

    
75
$a_cert =& $config['cert'];
76

    
77
$internal_ca_count = 0;
78
foreach ($a_ca as $ca)
79
	if ($ca['prv'])	
80
		$internal_ca_count++;
81

    
82
$act = $_GET['act'];
83
if ($_POST['act'])
84
	$act = $_POST['act'];
85

    
86
if ($act == "del") {
87

    
88
	if (!$a_cert[$id]) {
89
		pfSenseHeader("system_certmanager.php");
90
		exit;
91
	}
92

    
93
	$name = $a_cert[$id]['descr'];
94
	unset($a_cert[$id]);
95
	write_config();
96
	$savemsg = sprintf(gettext("Certificate %s successfully deleted"), $name) . "<br/>";
97
	pfSenseHeader("system_certmanager.php");
98
	exit;
99
}
100

    
101
if ($act == "new") {
102
	$pconfig['method'] = $_GET['method'];
103
	$pconfig['keylen'] = "2048";
104
	$pconfig['lifetime'] = "3650";
105
}
106

    
107
if ($act == "exp") {
108

    
109
	if (!$a_cert[$id]) {
110
		pfSenseHeader("system_certmanager.php");
111
		exit;
112
	}
113

    
114
	$exp_name = urlencode("{$a_cert[$id]['descr']}.crt");
115
	$exp_data = base64_decode($a_cert[$id]['crt']);
116
	$exp_size = strlen($exp_data);
117

    
118
	header("Content-Type: application/octet-stream");
119
	header("Content-Disposition: attachment; filename={$exp_name}");
120
	header("Content-Length: $exp_size");
121
	echo $exp_data;
122
	exit;
123
}
124

    
125
if ($act == "key") {
126

    
127
	if (!$a_cert[$id]) {
128
		pfSenseHeader("system_certmanager.php");
129
		exit;
130
	}
131

    
132
	$exp_name = urlencode("{$a_cert[$id]['descr']}.key");
133
	$exp_data = base64_decode($a_cert[$id]['prv']);
134
	$exp_size = strlen($exp_data);
135

    
136
	header("Content-Type: application/octet-stream");
137
	header("Content-Disposition: attachment; filename={$exp_name}");
138
	header("Content-Length: $exp_size");
139
	echo $exp_data;
140
	exit;
141
}
142

    
143
if ($act == "csr") {
144

    
145
	if (!$a_cert[$id]) {
146
		pfSenseHeader("system_certmanager.php");
147
		exit;
148
	}
149

    
150
	$pconfig['descr'] = $a_cert[$id]['descr'];
151
	$pconfig['csr'] = base64_decode($a_cert[$id]['csr']);
152
}
153

    
154
if ($_POST) {
155
	if ($_POST['save'] == gettext("Save")) {
156
		$input_errors = array();
157
		$pconfig = $_POST;
158

    
159
		/* input validation */
160
		if ($pconfig['method'] == "import") {
161
			$reqdfields = explode(" ",
162
					"descr cert key");
163
			$reqdfieldsn = array(
164
					gettext("Descriptive name"),
165
					gettext("Certificate data"),
166
					gettext("Key data"));
167
			if ($_POST['cert'] && (!strstr($_POST['cert'], "BEGIN CERTIFICATE") || !strstr($_POST['cert'], "END CERTIFICATE")))
168
				$input_errors[] = gettext("This certificate does not appear to be valid.");
169
		}
170

    
171
		if ($pconfig['method'] == "internal") {
172
			$reqdfields = explode(" ",
173
					"descr caref keylen lifetime dn_country dn_state dn_city ".
174
					"dn_organization dn_email dn_commonname");
175
			$reqdfieldsn = array(
176
					gettext("Descriptive name"),
177
					gettext("Certificate authority"),
178
					gettext("Key length"),
179
					gettext("Lifetime"),
180
					gettext("Distinguished name Country Code"),
181
					gettext("Distinguished name State or Province"),
182
					gettext("Distinguished name City"),
183
					gettext("Distinguished name Organization"),
184
					gettext("Distinguished name Email Address"),
185
					gettext("Distinguished name Common Name"));
186
		}
187

    
188
		if ($pconfig['method'] == "external") {
189
			$reqdfields = explode(" ",
190
					"descr csr_keylen csr_dn_country csr_dn_state csr_dn_city ".
191
					"csr_dn_organization csr_dn_email csr_dn_commonname");
192
			$reqdfieldsn = array(
193
					gettext("Descriptive name"),
194
					gettext("Key length"),
195
					gettext("Distinguished name Country Code"),
196
					gettext("Distinguished name State or Province"),
197
					gettext("Distinguished name City"),
198
					gettext("Distinguished name Organization"),
199
					gettext("Distinguished name Email Address"),
200
					gettext("Distinguished name Common Name"));
201
		}
202

    
203
		if ($pconfig['method'] == "existing") {
204
			$reqdfields = array("certref");
205
			$reqdfieldsn = array(gettext("Existing Certificate Choice"));
206
		}
207

    
208
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
209
		if ($pconfig['method'] != "import")
210
			/* Make sure we do not have invalid characters in the fields for the certificate */
211
			for ($i = 0; $i < count($reqdfields); $i++) {
212
				if (preg_match('/email/', $reqdfields[$i])){ /* dn_email or csr_dn_name */
213
				 	if (preg_match("/[\!\#\$\%\^\(\)\~\?\>\<\&\/\\\,\"\']/", $_POST["$reqdfields[$i]"]))
214
						array_push($input_errors, "The field 'Distinguished name Email Address' contains invalid characters.");
215
				}else if (preg_match('/commonname/', $reqdfields[$i])){ /* dn_commonname or csr_dn_commonname */
216
					if (preg_match("/[\!\@\#\$\%\^\(\)\~\?\>\<\&\/\\\,\"\']/", $_POST["$reqdfields[$i]"]))
217
						array_push($input_errors, "The field 'Distinguished name Common Name' contains invalid characters.");
218
				}else if (preg_match("/[\!\@\#\$\%\^\(\)\~\?\>\<\&\/\\\,\.\"\']/", $_POST["$reqdfields[$i]"]))
219
					array_push($input_errors, "The field '" . $reqdfieldsn[$i] . "' contains invalid characters.");
220
			}
221

    
222
		/* if this is an AJAX caller then handle via JSON */
223
		if (isAjax() && is_array($input_errors)) {
224
			input_errors2Ajax($input_errors);
225
			exit;
226
		}
227

    
228
		/* save modifications */
229
		if (!$input_errors) {
230

    
231
			if ($pconfig['method'] == "existing") {
232
				$cert = lookup_cert($pconfig['certref']);
233
				if ($cert && $a_user)
234
					$a_user[$userid]['cert'][] = $cert['refid'];
235
			} else {
236
				$cert = array();
237
				$cert['refid'] = uniqid();
238
				if (isset($id) && $a_cert[$id])
239
					$cert = $a_cert[$id];
240

    
241
				$cert['descr'] = $pconfig['descr'];
242

    
243
				$old_err_level = error_reporting(0); /* otherwise openssl_ functions throw warings directly to a page screwing menu tab */
244

    
245
				if ($pconfig['method'] == "import")
246
					cert_import($cert, $pconfig['cert'], $pconfig['key']);
247

    
248
				if ($pconfig['method'] == "internal") {
249
					$dn = array(
250
						'countryName' => $pconfig['dn_country'],
251
						'stateOrProvinceName' => $pconfig['dn_state'],
252
						'localityName' => $pconfig['dn_city'],
253
						'organizationName' => $pconfig['dn_organization'],
254
						'emailAddress' => $pconfig['dn_email'],
255
						'commonName' => $pconfig['dn_commonname']);
256
	
257
					if (!cert_create($cert, $pconfig['caref'], $pconfig['keylen'],
258
						$pconfig['lifetime'], $dn)){
259
						while($ssl_err = openssl_error_string()){
260
							$input_errors = array();
261
							array_push($input_errors, "openssl library returns: " . $ssl_err);
262
						}
263
					}
264
				}
265

    
266
				if ($pconfig['method'] == "external") {
267
					$dn = array(
268
						'countryName' => $pconfig['csr_dn_country'],
269
						'stateOrProvinceName' => $pconfig['csr_dn_state'],
270
						'localityName' => $pconfig['csr_dn_city'],
271
						'organizationName' => $pconfig['csr_dn_organization'],
272
						'emailAddress' => $pconfig['csr_dn_email'],
273
						'commonName' => $pconfig['csr_dn_commonname']);
274

    
275
					if(!csr_generate($cert, $pconfig['csr_keylen'], $dn)){
276
						while($ssl_err = openssl_error_string()){
277
							$input_errors = array();
278
							array_push($input_errors, "openssl library returns: " . $ssl_err);
279
						}
280
					}
281
				}
282
				error_reporting($old_err_level);
283

    
284
				if (isset($id) && $a_cert[$id])
285
					$a_cert[$id] = $cert;
286
				else
287
					$a_cert[] = $cert;
288
				if (isset($a_user) && isset($userid))
289
					$a_user[$userid]['cert'][] = $cert['refid'];
290
			}
291

    
292
			if (!$input_errors)
293
				write_config();
294

    
295
			if ($userid)
296
				pfSenseHeader("system_usermanager.php?act=edit&id={$userid}");
297
		}
298
	}
299

    
300
	if ($_POST['save'] == gettext("Update")) {
301
		unset($input_errors);
302
		$pconfig = $_POST;
303

    
304
		/* input validation */
305
		$reqdfields = explode(" ", "descr cert");
306
		$reqdfieldsn = array(
307
			gettext("Descriptive name"),
308
			gettext("Final Certificate data"));
309

    
310
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
311

    
312
//		old way
313
		/* make sure this csr and certificate subjects match */
314
//		$subj_csr = csr_get_subject($pconfig['csr'], false);
315
//		$subj_cert = cert_get_subject($pconfig['cert'], false);
316
//
317
//		if ( !isset($_POST['ignoresubjectmismatch']) && !($_POST['ignoresubjectmismatch'] == "yes") ) {
318
//			if (strcmp($subj_csr,$subj_cert)) {
319
//				$input_errors[] = sprintf(gettext("The certificate subject '%s' does not match the signing request subject."),$subj_cert);
320
//				$subject_mismatch = true;
321
//			}
322
//		}
323
		$mod_csr  =  csr_get_modulus($pconfig['csr'], false);
324
		$mod_cert = cert_get_modulus($pconfig['cert'], false);
325
		
326
		if (strcmp($mod_csr,$mod_cert)) {
327
			// simply: if the moduli don't match, then the private key and public key won't match
328
			$input_errors[] = sprintf(gettext("The certificate modulus does not match the signing request modulus."),$subj_cert);
329
			$subject_mismatch = true;
330
		}
331

    
332
		/* if this is an AJAX caller then handle via JSON */
333
		if (isAjax() && is_array($input_errors)) {
334
			input_errors2Ajax($input_errors);
335
			exit;
336
		}
337

    
338
		/* save modifications */
339
		if (!$input_errors) {
340

    
341
			$cert = $a_cert[$id];
342

    
343
			$cert['descr'] = $pconfig['descr'];
344

    
345
			csr_complete($cert, $pconfig['cert']);
346

    
347
			$a_cert[$id] = $cert;
348

    
349
			write_config();
350

    
351
			pfSenseHeader("system_certmanager.php");
352
		}
353
	}
354
}
355

    
356
include("head.inc");
357
?>
358

    
359
<body link="#000000" vlink="#000000" alink="#000000" onLoad="<?= $jsevents["body"]["onload"] ?>">
360
<?php include("fbegin.inc"); ?>
361
<script type="text/javascript">
362
<!--
363

    
364
function method_change() {
365

    
366
<?php
367
	if ($internal_ca_count)
368
		$submit_style = "";
369
	else
370
		$submit_style = "none";
371
?>
372

    
373
	method = document.iform.method.selectedIndex;
374

    
375
	switch (method) {
376
		case 0:
377
			document.getElementById("import").style.display="";
378
			document.getElementById("internal").style.display="none";
379
			document.getElementById("external").style.display="none";
380
			document.getElementById("existing").style.display="none";
381
			document.getElementById("descriptivename").style.display="";
382
			document.getElementById("submit").style.display="";
383
			break;
384
		case 1:
385
			document.getElementById("import").style.display="none";
386
			document.getElementById("internal").style.display="";
387
			document.getElementById("external").style.display="none";
388
			document.getElementById("existing").style.display="none";
389
			document.getElementById("descriptivename").style.display="";
390
			document.getElementById("submit").style.display="<?=$submit_style;?>";
391
			break;
392
		case 2:
393
			document.getElementById("import").style.display="none";
394
			document.getElementById("internal").style.display="none";
395
			document.getElementById("external").style.display="";
396
			document.getElementById("existing").style.display="none";
397
			document.getElementById("descriptivename").style.display="";
398
			document.getElementById("submit").style.display="";
399
			break;
400
		case 3:
401
			document.getElementById("import").style.display="none";
402
			document.getElementById("internal").style.display="none";
403
			document.getElementById("external").style.display="none";
404
			document.getElementById("existing").style.display="";
405
			document.getElementById("descriptivename").style.display="none";
406
			document.getElementById("submit").style.display="";
407
			break;
408
	}
409
}
410

    
411
<?php if ($internal_ca_count): ?>
412
function internalca_change() {
413

    
414
	index = document.iform.caref.selectedIndex;
415
	caref = document.iform.caref[index].value;
416

    
417
	switch (caref) {
418
<?php
419
		foreach ($a_ca as $ca):
420
			if (!$ca['prv'])
421
				continue;
422
			$subject = cert_get_subject_array($ca['crt']);
423
?>
424
		case "<?=$ca['refid'];?>":
425
			document.iform.dn_country.value = "<?=$subject[0]['v'];?>";
426
			document.iform.dn_state.value = "<?=$subject[1]['v'];?>";
427
			document.iform.dn_city.value = "<?=$subject[2]['v'];?>";
428
			document.iform.dn_organization.value = "<?=$subject[3]['v'];?>";
429
			document.iform.dn_email.value = "<?=$subject[4]['v'];?>";
430
			break;
431
<?php	endforeach; ?>
432
	}
433
}
434
<?php endif; ?>
435

    
436
//-->
437
</script>
438
<?php
439
	if ($input_errors)
440
		print_input_errors($input_errors);
441
	if ($savemsg)
442
		print_info_box($savemsg);
443

    
444
        // Load valid country codes
445
        $dn_cc = array();
446
        if (file_exists("/etc/ca_countries")){
447
                $dn_cc_file=file("/etc/ca_countries");
448
                foreach($dn_cc_file as $line)
449
                        if (preg_match('/^(\S*)\s(.*)$/', $line, $matches))
450
                                array_push($dn_cc, $matches[1]);
451
        }
452
?>
453
<table width="100%" border="0" cellpadding="0" cellspacing="0">
454
	<tr>
455
		<td class="tabnavtbl">
456
		<?php
457
			$tab_array = array();
458
			$tab_array[] = array(gettext("CAs"), false, "system_camanager.php");
459
			$tab_array[] = array(gettext("Certificates"), true, "system_certmanager.php");
460
			$tab_array[] = array(gettext("Certificate Revocation"), false, "system_crlmanager.php");
461
			display_top_tabs($tab_array);
462
		?>
463
		</td>
464
	</tr>
465
	<tr>
466
		<td id="mainarea">
467
			<div class="tabcont">
468

    
469
				<?php if ($act == "new" || (($_POST['save'] == gettext("Save")) && $input_errors)): ?>
470

    
471
				<form action="system_certmanager.php" method="post" name="iform" id="iform">
472
					<table width="100%" border="0" cellpadding="6" cellspacing="0">
473
						<?php if (!isset($id)): ?>
474
						<tr>
475
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Method");?></td>
476
							<td width="78%" class="vtable">
477
								<select name='method' id='method' class="formselect" onchange='method_change()'>
478
								<?php
479
									foreach($cert_methods as $method => $desc):
480
									$selected = "";
481
									if ($pconfig['method'] == $method)
482
										$selected = "selected";
483
								?>
484
									<option value="<?=$method;?>"<?=$selected;?>><?=$desc;?></option>
485
								<?php endforeach; ?>
486
								</select>
487
							</td>
488
						</tr>
489
						<?php endif; ?>
490
						<tr id="descriptivename">
491
							<?php
492
							if ($a_user && empty($pconfig['descr']))
493
								$pconfig['descr'] = $a_user[$userid]['name'];
494
							?>
495
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Descriptive name");?></td>
496
							<td width="78%" class="vtable">
497
								<input name="descr" type="text" class="formfld unknown" id="descr" size="20" value="<?=htmlspecialchars($pconfig['descr']);?>"/>
498
							</td>
499
						</tr>
500
					</table>
501

    
502
					<table width="100%" border="0" cellpadding="6" cellspacing="0" id="import">
503
						<tr>
504
							<td colspan="2" class="list" height="12"></td>
505
						</tr>
506
						<tr>
507
							<td colspan="2" valign="top" class="listtopic"><?=gettext("Import Certificate");?></td>
508
						</tr>
509

    
510
						<tr>
511
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Certificate data");?></td>
512
							<td width="78%" class="vtable">
513
								<textarea name="cert" id="cert" cols="65" rows="7" class="formfld_cert"><?=htmlspecialchars($pconfig['cert']);?></textarea>
514
								<br>
515
									<?=gettext("Paste a certificate in X.509 PEM format here.");?></td>
516
							</td>
517
						</tr>
518
						<tr>
519
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Private key data");?></td>
520
							<td width="78%" class="vtable">
521
								<textarea name="key" id="key" cols="65" rows="7" class="formfld_cert"><?=htmlspecialchars($pconfig['key']);?></textarea>
522
								<br>
523
								<?=gettext("Paste a private key in X.509 PEM format here.");?></td>
524
							</td>
525
						</tr>
526
					</table>
527

    
528
					<table width="100%" border="0" cellpadding="6" cellspacing="0" id="internal">
529
						<tr>
530
							<td colspan="2" class="list" height="12"></td>
531
						</tr>
532
						<tr>
533
							<td colspan="2" valign="top" class="listtopic"><?=gettext("Internal Certificate");?></td>
534
						</tr>
535

    
536
						<?php if (!$internal_ca_count): ?>
537

    
538
						<tr>
539
							<td colspan="2" align="center" class="vtable">
540
								<?=gettext("No internal Certificate Authorities have been defined. You must");?>
541
								<a href="system_camanager.php?act=new&method=internal"><?=gettext("create");?></a>
542
								<?=gettext("an internal CA before creating an internal certificate.");?>
543
							</td>
544
						</tr>
545

    
546
						<?php else: ?>
547

    
548
						<tr>
549
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Certificate authority");?></td>
550
							<td width="78%" class="vtable">
551
								<select name='caref' id='caref' class="formselect" onChange='internalca_change()'>
552
								<?php
553
									foreach( $a_ca as $ca):
554
									if (!$ca['prv'])
555
										continue;
556
									$selected = "";
557
									if ($pconfig['caref'] == $ca['refid'])
558
										$selected = "selected";
559
								?>
560
									<option value="<?=$ca['refid'];?>"<?=$selected;?>><?=$ca['descr'];?></option>
561
								<?php endforeach; ?>
562
								</select>
563
							</td>
564
						</tr>
565
						<tr>
566
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Key length");?></td>
567
							<td width="78%" class="vtable">
568
								<select name='keylen' class="formselect">
569
								<?php
570
									foreach( $cert_keylens as $len):
571
									$selected = "";
572
									if ($pconfig['keylen'] == $len)
573
										$selected = "selected";
574
								?>
575
									<option value="<?=$len;?>"<?=$selected;?>><?=$len;?></option>
576
								<?php endforeach; ?>
577
								</select>
578
								<?=gettext("bits");?>
579
							</td>
580
						</tr>
581
						<tr>
582
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Lifetime");?></td>
583
							<td width="78%" class="vtable">
584
								<input name="lifetime" type="text" class="formfld unknown" id="lifetime" size="5" value="<?=htmlspecialchars($pconfig['lifetime']);?>"/>
585
								<?=gettext("days");?>
586
							</td>
587
						</tr>
588
						<tr>
589
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Distinguished name");?></td>
590
							<td width="78%" class="vtable">
591
								<table border="0" cellspacing="0" cellpadding="2">
592
									<tr>
593
										<td align="right"><?=gettext("Country Code");?> : &nbsp;</td>
594
										<td align="left">
595
											<input name="dn_country" type="text" class="formfld unknown" maxlength="2" size="2" value="<?=htmlspecialchars($pconfig['dn_country']);?>"/>
596
										</td>
597
									</tr>
598
									<tr>
599
										<td align="right"><?=gettext("State or Province");?> : &nbsp;</td>
600
										<td align="left">
601
											<input name="dn_state" type="text" class="formfld unknown" size="40" value="<?=htmlspecialchars($pconfig['dn_state']);?>"/>
602
										</td>
603
									</tr>
604
									<tr>
605
										<td align="right"><?=gettext("City");?> : &nbsp;</td>
606
										<td align="left">
607
											<input name="dn_city" type="text" class="formfld unknown" size="40" value="<?=htmlspecialchars($pconfig['dn_city']);?>"/>
608
										</td>
609
									</tr>
610
									<tr>
611
										<td align="right"><?=gettext("Organization");?> : &nbsp;</td>
612
										<td align="left">
613
											<input name="dn_organization" type="text" class="formfld unknown" size="40" value="<?=htmlspecialchars($pconfig['dn_organization']);?>"/>
614
										</td>
615
									</tr>
616
									<tr>
617
										<td align="right"><?=gettext("Email Address");?> : &nbsp;</td>
618
										<td align="left">
619
											<input name="dn_email" type="text" class="formfld unknown" size="25" value="<?=htmlspecialchars($pconfig['dn_email']);?>"/>
620
											&nbsp;
621
											<em>ex:</em>
622
											&nbsp;
623
											<?=gettext("webadmin@mycompany.com");?>
624
										</td>
625
									</tr>
626
									<tr>
627
										<td align="right"><?=gettext("Common Name");?> : &nbsp;</td>
628
										<td align="left">
629
											<?php
630
											if ($a_user && empty($pconfig['dn_commonname']))
631
												$pconfig['dn_commonname'] = $a_user[$userid]['name'];
632
											?>
633
											<input name="dn_commonname" type="text" class="formfld unknown" size="25" value="<?=htmlspecialchars($pconfig['dn_commonname']);?>"/>
634
											&nbsp;
635
											<em>ex:</em>
636
											&nbsp;
637
											<?=gettext("www.example.com");?>
638
										</td>
639
									</tr>
640
								</table>
641
							</td>
642
						</tr>
643

    
644
					<?php endif; ?>
645

    
646
					</table>
647

    
648
					<table width="100%" border="0" cellpadding="6" cellspacing="0" id="external">
649
						<tr>
650
							<td colspan="2" class="list" height="12"></td>
651
						</tr>
652
						<tr>
653
							<td colspan="2" valign="top" class="listtopic"><?=gettext("External Signing Request");?></td>
654
						</tr>
655
						<tr>
656
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Key length");?></td>
657
							<td width="78%" class="vtable">
658
								<select name='csr_keylen' class="formselect">
659
								<?php
660
									foreach( $cert_keylens as $len):
661
									$selected = "";
662
									if ($pconfig['keylen'] == $len)
663
										$selected = "selected";
664
								?>
665
									<option value="<?=$len;?>"<?=$selected;?>><?=$len;?></option>
666
								<?php endforeach; ?>
667
								</select>
668
								bits
669
							</td>
670
						</tr>
671
						<tr>
672
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Distinguished name");?></td>
673
							<td width="78%" class="vtable">
674
								<table border="0" cellspacing="0" cellpadding="2">
675
									<tr>
676
										<td align="right"><?=gettext("Country Code");?> : &nbsp;</td>
677
										<td align="left">
678
											<select name='csr_dn_country' class="formselect">
679
											<?php
680
											foreach( $dn_cc as $cc){
681
												$selected = "";
682
												if ($pconfig['csr_dn_country'] == $cc) $selected = "selected";
683
												print "<option value=\"$cc\" $selected>$cc</option>";
684
												}
685
											?>
686
											</select>
687
										</td>
688
									</tr>
689
									<tr>
690
										<td align="right"><?=gettext("State or Province");?> : &nbsp;</td>
691
										<td align="left">
692
											<input name="csr_dn_state" type="text" class="formfld unknown" size="40" value="<?=htmlspecialchars($pconfig['csr_dn_state']);?>" />
693
											&nbsp;
694
											<em>ex:</em>
695
											&nbsp;
696
											<?=gettext("Texas");?>
697
										</td>
698
									</tr>
699
									<tr>
700
										<td align="right"><?=gettext("City");?> : &nbsp;</td>
701
										<td align="left">
702
											<input name="csr_dn_city" type="text" class="formfld unknown" size="40" value="<?=htmlspecialchars($pconfig['csr_dn_city']);?>" />
703
											&nbsp;
704
											<em>ex:</em>
705
											&nbsp;
706
											<?=gettext("Austin");?>
707
										</td>
708
									</tr>
709
									<tr>
710
										<td align="right"><?=gettext("Organization");?> : &nbsp;</td>
711
										<td align="left">
712
											<input name="csr_dn_organization" type="text" class="formfld unknown" size="40" value="<?=htmlspecialchars($pconfig['csr_dn_organization']);?>" />
713
											&nbsp;
714
											<em>ex:</em>
715
											&nbsp;
716
											<?=gettext("My Company Inc.");?>
717
										</td>
718
									</tr>
719
									<tr>
720
										<td align="right"><?=gettext("Email Address");?> : &nbsp;</td>
721
										<td align="left">
722
											<input name="csr_dn_email" type="text" class="formfld unknown" size="25" value="<?=htmlspecialchars($pconfig['csr_dn_email']);?>"/>
723
											&nbsp;
724
											<em>ex:</em>
725
											&nbsp;
726
											<?=gettext("webadmin@mycompany.com");?>
727
										</td>
728
									</tr>
729
									<tr>
730
										<td align="right"><?=gettext("Common Name");?> : &nbsp;</td>
731
										<td align="left">
732
											<input name="csr_dn_commonname" type="text" class="formfld unknown" size="25" value="<?=htmlspecialchars($pconfig['csr_dn_commonname']);?>"/>
733
											&nbsp;
734
											<em>ex:</em>
735
											&nbsp;
736
											<?=gettext("www.example.com");?>
737
										</td>
738
									</tr>
739
								</table>
740
							</td>
741
						</tr>
742
					</table>
743

    
744
					<table width="100%" border="0" cellpadding="6" cellspacing="0" id="existing">
745
						<tr>
746
							<td colspan="2" class="list" height="12"></td>
747
						</tr>
748
						<tr>
749
							<td colspan="2" valign="top" class="listtopic"><?=gettext("Choose an Existing Certificate");?></td>
750
						</tr>
751
						<tr>
752
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Existing Certificates");?></td>
753
							<td width="78%" class="vtable">
754
								<?php if (isset($userid) && $a_user): ?>
755
								<input name="userid" type="hidden" value="<?=$userid;?>" />
756
								<?php endif;?>
757
								<select name='certref' class="formselect">
758
								<?php
759
									foreach ($config['cert'] as $cert):
760
										$selected = "";
761
										$caname = "";
762
										$inuse = "";
763
										$revoked = "";
764
										if (in_array($cert['refid'], $config['system']['user'][$userid]['cert']))
765
											continue;
766
										$ca = lookup_ca($cert['caref']);
767
										if ($ca)
768
											$caname = " (CA: {$ca['descr']})";
769
										if ($pconfig['certref'] == $cert['refid'])
770
											$selected = "selected";
771
										if (cert_in_use($cert['refid']))
772
											$inuse = " *In Use";
773
											if (is_cert_revoked($cert))
774
											$revoked = " *Revoked";
775
								?>
776
									<option value="<?=$cert['refid'];?>" <?=$selected;?>><?=$cert['descr'] . $caname . $inuse . $revoked;?></option>
777
								<?php endforeach; ?>
778
								</select>
779
							</td>
780
						</tr>
781
					</table>
782

    
783
					<table width="100%" border="0" cellpadding="6" cellspacing="0">
784
						<tr>
785
							<td width="22%" valign="top">&nbsp;</td>
786
							<td width="78%">
787
								<input id="submit" name="save" type="submit" class="formbtn" value="<?=gettext("Save");?>" />
788
								<?php if (isset($id) && $a_cert[$id]): ?>
789
								<input name="id" type="hidden" value="<?=$id;?>" />
790
								<?php endif;?>
791
							</td>
792
						</tr>
793
					</table>
794
				</form>
795

    
796
				<?php elseif ($act == "csr" || (($_POST['save'] == gettext("Update")) && $input_errors)):?>
797

    
798
				<form action="system_certmanager.php" method="post" name="iform" id="iform">
799
					<table width="100%" border="0" cellpadding="6" cellspacing="0">
800
						<tr>
801
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Descriptive name");?></td>
802
							<td width="78%" class="vtable">
803
								<input name="descr" type="text" class="formfld unknown" id="descr" size="20" value="<?=htmlspecialchars($pconfig['descr']);?>"/>
804
							</td>
805
						</tr>
806
						<tr>
807
							<td colspan="2" class="list" height="12"></td>
808
						</tr>
809
						<tr>
810
							<td colspan="2" valign="top" class="listtopic"><?=gettext("Complete Signing Request");?></td>
811
						</tr>
812

    
813
						<tr>
814
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Signing Request data");?></td>
815
							<td width="78%" class="vtable">
816
								<textarea name="csr" id="csr" cols="65" rows="7" class="formfld_cert" readonly><?=htmlspecialchars($pconfig['csr']);?></textarea>
817
								<br>
818
								<?=gettext("Copy the certificate signing data from here and forward it to your certificate authority for signing.");?></td>
819
							</td>
820
						</tr>
821
						<tr>
822
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Final Certificate data");?></td>
823
							<td width="78%" class="vtable">
824
								<textarea name="cert" id="cert" cols="65" rows="7" class="formfld_cert"><?=htmlspecialchars($pconfig['cert']);?></textarea>
825
								<br>
826
								<?=gettext("Paste the certificate received from your certificate authority here.");?></td>
827
							</td>
828
						</tr>
829
						<tr>
830
							<td width="22%" valign="top">&nbsp;</td>
831
							<td width="78%">
832
								<?php /* if ( isset($subject_mismatch) && $subject_mismatch === true): ?>
833
								<input id="ignoresubjectmismatch" name="ignoresubjectmismatch" type="checkbox" class="formbtn" value="yes" />
834
								<label for="ignoresubjectmismatch"><strong><?=gettext("Ignore certificate subject mismatch"); ?></strong></label><br />
835
								<?php echo gettext("Warning: Using this option may create an " .
836
								"invalid certificate.  Check this box to disable the request -> " .
837
								"response subject verification. ");
838
								?><br/>
839
								<?php endif; */ ?>
840
								<input id="submit" name="save" type="submit" class="formbtn" value="<?=gettext("Update");?>" />
841
								<?php if (isset($id) && $a_cert[$id]): ?>
842
								<input name="id" type="hidden" value="<?=$id;?>" />
843
								<input name="act" type="hidden" value="csr" />
844
								<?php endif;?>
845
							</td>
846
						</tr>
847
					</table>
848
				</form>
849

    
850
				<?php else:?>
851

    
852
				<table width="100%" border="0" cellpadding="0" cellspacing="0">
853
					<tr>
854
						<td width="15%" class="listhdrr"><?=gettext("Name");?></td>
855
						<td width="15%" class="listhdrr"><?=gettext("Issuer");?></td>
856
						<td width="40%" class="listhdrr"><?=gettext("Distinguished Name");?></td>
857
						<td width="10%" class="listhdrr"><?=gettext("In Use");?></td>
858
						<td width="10%" class="list"></td>
859
					</tr>
860
					<?php
861
						$i = 0;
862
						foreach($a_cert as $cert):
863
							$name = htmlspecialchars($cert['descr']);
864
							
865
							if ($cert['crt']) {
866
								$subj = cert_get_subject($cert['crt']);
867
								$issuer = cert_get_issuer($cert['crt']);
868
								if($subj==$issuer)
869
								  $caname = "<em>" . gettext("self-signed") . "</em>";
870
								else
871
							    $caname = "<em>" . gettext("external"). "</em>";
872
							  $subj = htmlspecialchars($subj);
873
							}
874

    
875
							if ($cert['csr']) {
876
								$subj = htmlspecialchars(csr_get_subject($cert['csr']));
877
								$caname = "<em>" . gettext("external - signature pending") . "</em>";
878
							}
879

    
880
							$ca = lookup_ca($cert['caref']);
881
							if ($ca)
882
								$caname = $ca['descr'];
883

    
884
							if($cert['prv'])
885
								$certimg = "/themes/{$g['theme']}/images/icons/icon_frmfld_cert.png";
886
							else
887
								$certimg = "/themes/{$g['theme']}/images/icons/icon_frmfld_cert.png";
888
					?>
889
					<tr>
890
						<td class="listlr">
891
							<table border="0" cellpadding="0" cellspacing="0">
892
								<tr>
893
									<td align="left" valign="center">
894
										<img src="<?=$certimg;?>" alt="CA" title="CA" border="0" height="16" width="16" />
895
									</td>
896
									<td align="left" valign="middle">
897
										<?=$name;?>
898
									</td>
899
								</tr>
900
							</table>
901
						</td>
902
						<td class="listr"><?=$caname;?>&nbsp;</td>
903
						<td class="listr"><?=$subj;?>&nbsp;</td>
904
						<td class="listr">
905
							<?php if (is_cert_revoked($cert)): ?>
906
							<b>Revoked</b><br/>
907
							<?php endif; ?>
908
							<?php if (is_webgui_cert($cert['refid'])): ?>
909
							webConfigurator<br/>
910
							<?php endif; ?>
911
							<?php if (is_user_cert($cert['refid'])): ?>
912
							User Cert<br/>
913
							<?php endif; ?>
914
							<?php if (is_openvpn_server_cert($cert['refid'])): ?>
915
							OpenVPN Server<br/>
916
							<?php endif; ?>
917
							<?php if (is_openvpn_client_cert($cert['refid'])): ?>
918
							OpenVPN Client<br/>
919
							<?php endif; ?>
920
							<?php if (is_ipsec_cert($cert['refid'])): ?>
921
							IPsec Tunnel<br/>
922
							<?php endif; ?>
923
						</td>
924
						<td valign="middle" nowrap class="list">
925
							<a href="system_certmanager.php?act=exp&id=<?=$i;?>">
926
								<img src="/themes/<?= $g['theme'];?>/images/icons/icon_down.gif" title="<?=gettext("export cert");?>" alt="<?=gettext("export ca");?>" width="17" height="17" border="0" />
927
							</a>
928
							<a href="system_certmanager.php?act=key&id=<?=$i;?>">
929
								<img src="/themes/<?= $g['theme'];?>/images/icons/icon_down.gif" title="<?=gettext("export key");?>" alt="<?=gettext("export ca");?>" width="17" height="17" border="0" />
930
							</a>
931
							<?php	if (!cert_in_use($cert['refid'])): ?>
932
							<a href="system_certmanager.php?act=del&id=<?=$i;?>" onClick="return confirm('<?=gettext("Do you really want to delete this Certificate?");?>')">
933
								<img src="/themes/<?= $g['theme'];?>/images/icons/icon_x.gif" title="<?=gettext("delete cert");?>" alt="<?=gettext("delete cert");?>" width="17" height="17" border="0" />
934
							</a>
935
							<?php	endif; ?>
936
							<?php	if ($cert['csr']): ?>
937
							&nbsp;
938
								<a href="system_certmanager.php?act=csr&id=<?=$i;?>">
939
								<img src="/themes/<?= $g['theme'];?>/images/icons/icon_e.gif" title="<?=gettext("update csr");?>" alt="<?=gettext("update csr");?>" width="17" height="17" border="0" />
940
							</a>
941
							<?php	endif; ?>
942
						</td>
943
					</tr>
944
					<?php
945
							$i++;
946
						endforeach;
947
					?>
948
					<tr>
949
						<td class="list" colspan="4"></td>
950
						<td class="list">
951
							<a href="system_certmanager.php?act=new">
952
								<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" />
953
							</a>
954
						</td>
955
					</tr>
956
					<tr>
957
						<td>&nbsp;</td>
958
						<td colspan="3"><?=gettext("Note: You can only delete a certificate if it is not currently in use.");?></td>
959
					</tr>
960
				</table>
961

    
962
				<?php endif; ?>
963

    
964
			</div>
965
		</td>
966
	</tr>
967
</table>
968
<?php include("fend.inc");?>
969
<script type="text/javascript">
970
<!--
971

    
972
method_change();
973
internalca_change();
974

    
975
//-->
976
</script>
977

    
978
</body>
(191-191/232)