Project

General

Profile

Download (31.5 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
}
98

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

    
105
if ($act == "exp") {
106

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

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

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

    
123
if ($act == "key") {
124

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

    
130
	$exp_name = urlencode("{$a_cert[$id]['descr']}.key");
131
	$exp_data = base64_decode($a_cert[$id]['prv']);
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
if ($act == "csr") {
142

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

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

    
152
if ($_POST) {
153
	if ($_POST['save'] == gettext("Save")) {
154
		unset($input_errors);
155
		$pconfig = $_POST;
156

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

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

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

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

    
206
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
207

    
208
		/* if this is an AJAX caller then handle via JSON */
209
		if (isAjax() && is_array($input_errors)) {
210
			input_errors2Ajax($input_errors);
211
			exit;
212
		}
213

    
214
		/* save modifications */
215
		if (!$input_errors) {
216

    
217
			if ($pconfig['method'] == "existing") {
218
				$cert = lookup_cert($pconfig['certref']);
219
				if ($cert && $a_user)
220
					$a_user[$userid]['cert'][] = $cert['refid'];
221
			} else {
222
				$cert = array();
223
				$cert['refid'] = uniqid();
224
				if (isset($id) && $a_cert[$id])
225
					$cert = $a_cert[$id];
226

    
227
				$cert['descr'] = $pconfig['descr'];
228

    
229
				if ($pconfig['method'] == "import")
230
					cert_import($cert, $pconfig['cert'], $pconfig['key']);
231

    
232
				if ($pconfig['method'] == "internal") {
233
					$dn = array(
234
						'countryName' => $pconfig['dn_country'],
235
						'stateOrProvinceName' => $pconfig['dn_state'],
236
						'localityName' => $pconfig['dn_city'],
237
						'organizationName' => $pconfig['dn_organization'],
238
						'emailAddress' => $pconfig['dn_email'],
239
						'commonName' => $pconfig['dn_commonname']);
240
	
241
					cert_create($cert, $pconfig['caref'], $pconfig['keylen'],
242
						$pconfig['lifetime'], $dn);
243
				}
244

    
245
				if ($pconfig['method'] == "external") {
246
					$dn = array(
247
						'countryName' => $pconfig['csr_dn_country'],
248
						'stateOrProvinceName' => $pconfig['csr_dn_state'],
249
						'localityName' => $pconfig['csr_dn_city'],
250
						'organizationName' => $pconfig['csr_dn_organization'],
251
						'emailAddress' => $pconfig['csr_dn_email'],
252
						'commonName' => $pconfig['csr_dn_commonname']);
253

    
254
					csr_generate($cert, $pconfig['csr_keylen'], $dn);
255
				}
256
				if (isset($id) && $a_cert[$id])
257
					$a_cert[$id] = $cert;
258
				else
259
					$a_cert[] = $cert;
260
				if (isset($a_user) && isset($userid))
261
					$a_user[$userid]['cert'][] = $cert['refid'];
262
			}
263

    
264
			write_config();
265

    
266
			if ($userid)
267
				pfSenseHeader("system_usermanager.php?act=edit&id={$userid}");
268
		}
269
	}
270

    
271
	if ($_POST['save'] == gettext("Update")) {
272
		unset($input_errors);
273
		$pconfig = $_POST;
274

    
275
		/* input validation */
276
		$reqdfields = explode(" ", "descr cert");
277
		$reqdfieldsn = array(
278
			gettext("Descriptive name"),
279
			gettext("Final Certificate data"));
280

    
281
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
282

    
283
//		old way
284
		/* make sure this csr and certificate subjects match */
285
//		$subj_csr = csr_get_subject($pconfig['csr'], false);
286
//		$subj_cert = cert_get_subject($pconfig['cert'], false);
287
//
288
//		if ( !isset($_POST['ignoresubjectmismatch']) && !($_POST['ignoresubjectmismatch'] == "yes") ) {
289
//			if (strcmp($subj_csr,$subj_cert)) {
290
//				$input_errors[] = sprintf(gettext("The certificate subject '%s' does not match the signing request subject."),$subj_cert);
291
//				$subject_mismatch = true;
292
//			}
293
//		}
294
		$mod_csr  =  csr_get_modulus($pconfig['csr'], false);
295
		$mod_cert = cert_get_modulus($pconfig['cert'], false);
296
		
297
		if (strcmp($mod_csr,$mod_cert)) {
298
			// simply: if the moduli don't match, then the private key and public key won't match
299
			$input_errors[] = sprintf(gettext("The certificate modulus does not match the signing request modulus."),$subj_cert);
300
			$subject_mismatch = true;
301
		}
302

    
303
		/* if this is an AJAX caller then handle via JSON */
304
		if (isAjax() && is_array($input_errors)) {
305
			input_errors2Ajax($input_errors);
306
			exit;
307
		}
308

    
309
		/* save modifications */
310
		if (!$input_errors) {
311

    
312
			$cert = $a_cert[$id];
313

    
314
			$cert['descr'] = $pconfig['descr'];
315

    
316
			csr_complete($cert, $pconfig['cert']);
317

    
318
			$a_cert[$id] = $cert;
319

    
320
			write_config();
321

    
322
			pfSenseHeader("system_certmanager.php");
323
		}
324
	}
325
}
326

    
327
include("head.inc");
328
?>
329

    
330
<body link="#000000" vlink="#000000" alink="#000000" onLoad="<?= $jsevents["body"]["onload"] ?>">
331
<?php include("fbegin.inc"); ?>
332
<script type="text/javascript">
333
<!--
334

    
335
function method_change() {
336

    
337
<?php
338
	if ($internal_ca_count)
339
		$submit_style = "";
340
	else
341
		$submit_style = "none";
342
?>
343

    
344
	method = document.iform.method.selectedIndex;
345

    
346
	switch (method) {
347
		case 0:
348
			document.getElementById("import").style.display="";
349
			document.getElementById("internal").style.display="none";
350
			document.getElementById("external").style.display="none";
351
			document.getElementById("existing").style.display="none";
352
			document.getElementById("descriptivename").style.display="";
353
			document.getElementById("submit").style.display="";
354
			break;
355
		case 1:
356
			document.getElementById("import").style.display="none";
357
			document.getElementById("internal").style.display="";
358
			document.getElementById("external").style.display="none";
359
			document.getElementById("existing").style.display="none";
360
			document.getElementById("descriptivename").style.display="";
361
			document.getElementById("submit").style.display="<?=$submit_style;?>";
362
			break;
363
		case 2:
364
			document.getElementById("import").style.display="none";
365
			document.getElementById("internal").style.display="none";
366
			document.getElementById("external").style.display="";
367
			document.getElementById("existing").style.display="none";
368
			document.getElementById("descriptivename").style.display="";
369
			document.getElementById("submit").style.display="";
370
			break;
371
		case 3:
372
			document.getElementById("import").style.display="none";
373
			document.getElementById("internal").style.display="none";
374
			document.getElementById("external").style.display="none";
375
			document.getElementById("existing").style.display="";
376
			document.getElementById("descriptivename").style.display="none";
377
			document.getElementById("submit").style.display="";
378
			break;
379
	}
380
}
381

    
382
<?php if ($internal_ca_count): ?>
383
function internalca_change() {
384

    
385
	index = document.iform.caref.selectedIndex;
386
	caref = document.iform.caref[index].value;
387

    
388
	switch (caref) {
389
<?php
390
		foreach ($a_ca as $ca):
391
			if (!$ca['prv'])
392
				continue;
393
			$subject = cert_get_subject_array($ca['crt']);
394
?>
395
		case "<?=$ca['refid'];?>":
396
			document.iform.dn_country.value = "<?=$subject[0]['v'];?>";
397
			document.iform.dn_state.value = "<?=$subject[1]['v'];?>";
398
			document.iform.dn_city.value = "<?=$subject[2]['v'];?>";
399
			document.iform.dn_organization.value = "<?=$subject[3]['v'];?>";
400
			document.iform.dn_email.value = "<?=$subject[4]['v'];?>";
401
			break;
402
<?php	endforeach; ?>
403
	}
404
}
405
<?php endif; ?>
406

    
407
//-->
408
</script>
409
<?php
410
	if ($input_errors)
411
		print_input_errors($input_errors);
412
	if ($savemsg)
413
		print_info_box($savemsg);
414
?>
415
<table width="100%" border="0" cellpadding="0" cellspacing="0">
416
	<tr>
417
		<td class="tabnavtbl">
418
		<?php
419
			$tab_array = array();
420
			$tab_array[] = array(gettext("CAs"), false, "system_camanager.php");
421
			$tab_array[] = array(gettext("Certificates"), true, "system_certmanager.php");
422
			$tab_array[] = array(gettext("Certificate Revocation"), false, "system_crlmanager.php");
423
			display_top_tabs($tab_array);
424
		?>
425
		</td>
426
	</tr>
427
	<tr>
428
		<td id="mainarea">
429
			<div class="tabcont">
430

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

    
433
				<form action="system_certmanager.php" method="post" name="iform" id="iform">
434
					<table width="100%" border="0" cellpadding="6" cellspacing="0">
435
						<?php if (!isset($id)): ?>
436
						<tr>
437
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Method");?></td>
438
							<td width="78%" class="vtable">
439
								<select name='method' id='method' class="formselect" onchange='method_change()'>
440
								<?php
441
									foreach($cert_methods as $method => $desc):
442
									$selected = "";
443
									if ($pconfig['method'] == $method)
444
										$selected = "selected";
445
								?>
446
									<option value="<?=$method;?>"<?=$selected;?>><?=$desc;?></option>
447
								<?php endforeach; ?>
448
								</select>
449
							</td>
450
						</tr>
451
						<?php endif; ?>
452
						<tr id="descriptivename">
453
							<?php
454
							if ($a_user && empty($pconfig['descr']))
455
								$pconfig['descr'] = $a_user[$userid]['name'];
456
							?>
457
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Descriptive name");?></td>
458
							<td width="78%" class="vtable">
459
								<input name="descr" type="text" class="formfld unknown" id="descr" size="20" value="<?=htmlspecialchars($pconfig['descr']);?>"/>
460
							</td>
461
						</tr>
462
					</table>
463

    
464
					<table width="100%" border="0" cellpadding="6" cellspacing="0" id="import">
465
						<tr>
466
							<td colspan="2" class="list" height="12"></td>
467
						</tr>
468
						<tr>
469
							<td colspan="2" valign="top" class="listtopic"><?=gettext("Import Certificate");?></td>
470
						</tr>
471

    
472
						<tr>
473
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Certificate data");?></td>
474
							<td width="78%" class="vtable">
475
								<textarea name="cert" id="cert" cols="65" rows="7" class="formfld_cert"><?=htmlspecialchars($pconfig['cert']);?></textarea>
476
								<br>
477
									<?=gettext("Paste a certificate in X.509 PEM format here.");?></td>
478
							</td>
479
						</tr>
480
						<tr>
481
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Private key data");?></td>
482
							<td width="78%" class="vtable">
483
								<textarea name="key" id="key" cols="65" rows="7" class="formfld_cert"><?=htmlspecialchars($pconfig['key']);?></textarea>
484
								<br>
485
								<?=gettext("Paste a private key in X.509 PEM format here.");?></td>
486
							</td>
487
						</tr>
488
					</table>
489

    
490
					<table width="100%" border="0" cellpadding="6" cellspacing="0" id="internal">
491
						<tr>
492
							<td colspan="2" class="list" height="12"></td>
493
						</tr>
494
						<tr>
495
							<td colspan="2" valign="top" class="listtopic"><?=gettext("Internal Certificate");?></td>
496
						</tr>
497

    
498
						<?php if (!$internal_ca_count): ?>
499

    
500
						<tr>
501
							<td colspan="2" align="center" class="vtable">
502
								<?=gettext("No internal Certificate Authorities have been defined. You must");?>
503
								<a href="system_camanager.php?act=new&method=internal"><?=gettext("create");?></a>
504
								<?=gettext("an internal CA before creating an internal certificate.");?>
505
							</td>
506
						</tr>
507

    
508
						<?php else: ?>
509

    
510
						<tr>
511
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Certificate authority");?></td>
512
							<td width="78%" class="vtable">
513
								<select name='caref' id='caref' class="formselect" onChange='internalca_change()'>
514
								<?php
515
									foreach( $a_ca as $ca):
516
									if (!$ca['prv'])
517
										continue;
518
									$selected = "";
519
									if ($pconfig['caref'] == $ca['refid'])
520
										$selected = "selected";
521
								?>
522
									<option value="<?=$ca['refid'];?>"<?=$selected;?>><?=$ca['descr'];?></option>
523
								<?php endforeach; ?>
524
								</select>
525
							</td>
526
						</tr>
527
						<tr>
528
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Key length");?></td>
529
							<td width="78%" class="vtable">
530
								<select name='keylen' class="formselect">
531
								<?php
532
									foreach( $cert_keylens as $len):
533
									$selected = "";
534
									if ($pconfig['keylen'] == $len)
535
										$selected = "selected";
536
								?>
537
									<option value="<?=$len;?>"<?=$selected;?>><?=$len;?></option>
538
								<?php endforeach; ?>
539
								</select>
540
								<?=gettext("bits");?>
541
							</td>
542
						</tr>
543
						<tr>
544
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Lifetime");?></td>
545
							<td width="78%" class="vtable">
546
								<input name="lifetime" type="text" class="formfld unknown" id="lifetime" size="5" value="<?=htmlspecialchars($pconfig['lifetime']);?>"/>
547
								<?=gettext("days");?>
548
							</td>
549
						</tr>
550
						<tr>
551
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Distinguished name");?></td>
552
							<td width="78%" class="vtable">
553
								<table border="0" cellspacing="0" cellpadding="2">
554
									<tr>
555
										<td align="right"><?=gettext("Country Code");?> : &nbsp;</td>
556
										<td align="left">
557
											<input name="dn_country" type="text" class="formfld unknown" maxlength="2" size="2" value="<?=htmlspecialchars($pconfig['dn_country']);?>" readonly/>
558
										</td>
559
									</tr>
560
									<tr>
561
										<td align="right"><?=gettext("State or Province");?> : &nbsp;</td>
562
										<td align="left">
563
											<input name="dn_state" type="text" class="formfld unknown" size="40" value="<?=htmlspecialchars($pconfig['dn_state']);?>" readonly/>
564
										</td>
565
									</tr>
566
									<tr>
567
										<td align="right"><?=gettext("City");?> : &nbsp;</td>
568
										<td align="left">
569
											<input name="dn_city" type="text" class="formfld unknown" size="40" value="<?=htmlspecialchars($pconfig['dn_city']);?>" readonly/>
570
										</td>
571
									</tr>
572
									<tr>
573
										<td align="right"><?=gettext("Organization");?> : &nbsp;</td>
574
										<td align="left">
575
											<input name="dn_organization" type="text" class="formfld unknown" size="40" value="<?=htmlspecialchars($pconfig['dn_organization']);?>" readonly/>
576
										</td>
577
									</tr>
578
									<tr>
579
										<td align="right"><?=gettext("Email Address");?> : &nbsp;</td>
580
										<td align="left">
581
											<input name="dn_email" type="text" class="formfld unknown" size="25" value="<?=htmlspecialchars($pconfig['dn_email']);?>"/>
582
											&nbsp;
583
											<em>ex:</em>
584
											&nbsp;
585
											<?=gettext("webadmin@mycompany.com");?>
586
										</td>
587
									</tr>
588
									<tr>
589
										<td align="right"><?=gettext("Common Name");?> : &nbsp;</td>
590
										<td align="left">
591
											<?php
592
											if ($a_user && empty($pconfig['dn_commonname']))
593
												$pconfig['dn_commonname'] = $a_user[$userid]['name'];
594
											?>
595
											<input name="dn_commonname" type="text" class="formfld unknown" size="25" value="<?=htmlspecialchars($pconfig['dn_commonname']);?>"/>
596
											&nbsp;
597
											<em>ex:</em>
598
											&nbsp;
599
											<?=gettext("www.example.com");?>
600
										</td>
601
									</tr>
602
								</table>
603
							</td>
604
						</tr>
605

    
606
					<?php endif; ?>
607

    
608
					</table>
609

    
610
					<table width="100%" border="0" cellpadding="6" cellspacing="0" id="external">
611
						<tr>
612
							<td colspan="2" class="list" height="12"></td>
613
						</tr>
614
						<tr>
615
							<td colspan="2" valign="top" class="listtopic"><?=gettext("External Signing Request");?></td>
616
						</tr>
617
						<tr>
618
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Key length");?></td>
619
							<td width="78%" class="vtable">
620
								<select name='csr_keylen' class="formselect">
621
								<?php
622
									foreach( $cert_keylens as $len):
623
									$selected = "";
624
									if ($pconfig['keylen'] == $len)
625
										$selected = "selected";
626
								?>
627
									<option value="<?=$len;?>"<?=$selected;?>><?=$len;?></option>
628
								<?php endforeach; ?>
629
								</select>
630
								bits
631
							</td>
632
						</tr>
633
						<tr>
634
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Distinguished name");?></td>
635
							<td width="78%" class="vtable">
636
								<table border="0" cellspacing="0" cellpadding="2">
637
									<tr>
638
										<td align="right"><?=gettext("Country Code");?> : &nbsp;</td>
639
										<td align="left">
640
											<input name="csr_dn_country" type="text" class="formfld unknown" size="2" value="<?=htmlspecialchars($pconfig['csr_dn_country']);?>" />
641
											&nbsp;
642
											<em>ex:</em>
643
											&nbsp;
644
											US
645
											&nbsp;
646
											<em><?=gettext("( two letters )");?></em>
647
										</td>
648
									</tr>
649
									<tr>
650
										<td align="right"><?=gettext("State or Province");?> : &nbsp;</td>
651
										<td align="left">
652
											<input name="csr_dn_state" type="text" class="formfld unknown" size="40" value="<?=htmlspecialchars($pconfig['csr_dn_state']);?>" />
653
											&nbsp;
654
											<em>ex:</em>
655
											&nbsp;
656
											<?=gettext("Texas");?>
657
										</td>
658
									</tr>
659
									<tr>
660
										<td align="right"><?=gettext("City");?> : &nbsp;</td>
661
										<td align="left">
662
											<input name="csr_dn_city" type="text" class="formfld unknown" size="40" value="<?=htmlspecialchars($pconfig['csr_dn_city']);?>" />
663
											&nbsp;
664
											<em>ex:</em>
665
											&nbsp;
666
											<?=gettext("Austin");?>
667
										</td>
668
									</tr>
669
									<tr>
670
										<td align="right"><?=gettext("Organization");?> : &nbsp;</td>
671
										<td align="left">
672
											<input name="csr_dn_organization" type="text" class="formfld unknown" size="40" value="<?=htmlspecialchars($pconfig['csr_dn_organization']);?>" />
673
											&nbsp;
674
											<em>ex:</em>
675
											&nbsp;
676
											<?=gettext("My Company Inc.");?>
677
										</td>
678
									</tr>
679
									<tr>
680
										<td align="right"><?=gettext("Email Address");?> : &nbsp;</td>
681
										<td align="left">
682
											<input name="csr_dn_email" type="text" class="formfld unknown" size="25" value="<?=htmlspecialchars($pconfig['csr_dn_email']);?>"/>
683
											&nbsp;
684
											<em>ex:</em>
685
											&nbsp;
686
											<?=gettext("webadmin@mycompany.com");?>
687
										</td>
688
									</tr>
689
									<tr>
690
										<td align="right"><?=gettext("Common Name");?> : &nbsp;</td>
691
										<td align="left">
692
											<input name="csr_dn_commonname" type="text" class="formfld unknown" size="25" value="<?=htmlspecialchars($pconfig['csr_dn_commonname']);?>"/>
693
											&nbsp;
694
											<em>ex:</em>
695
											&nbsp;
696
											<?=gettext("www.example.com");?>
697
										</td>
698
									</tr>
699
								</table>
700
							</td>
701
						</tr>
702
					</table>
703

    
704
					<table width="100%" border="0" cellpadding="6" cellspacing="0" id="existing">
705
						<tr>
706
							<td colspan="2" class="list" height="12"></td>
707
						</tr>
708
						<tr>
709
							<td colspan="2" valign="top" class="listtopic"><?=gettext("Choose an Existing Certificate");?></td>
710
						</tr>
711
						<tr>
712
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Existing Certificates");?></td>
713
							<td width="78%" class="vtable">
714
								<?php if (isset($userid) && $a_user): ?>
715
								<input name="userid" type="hidden" value="<?=$userid;?>" />
716
								<?php endif;?>
717
								<select name='certref' class="formselect">
718
								<?php
719
									foreach ($config['cert'] as $cert):
720
										$selected = "";
721
										$caname = "";
722
										$inuse = "";
723
										$revoked = "";
724
										if (in_array($cert['refid'], $config['system']['user'][$userid]['cert']))
725
											continue;
726
										$ca = lookup_ca($cert['caref']);
727
										if ($ca)
728
											$caname = " (CA: {$ca['descr']})";
729
										if ($pconfig['certref'] == $cert['refid'])
730
											$selected = "selected";
731
										if (cert_in_use($cert['refid']))
732
											$inuse = " *In Use";
733
											if (is_cert_revoked($cert))
734
											$revoked = " *Revoked";
735
								?>
736
									<option value="<?=$cert['refid'];?>" <?=$selected;?>><?=$cert['descr'] . $caname . $inuse . $revoked;?></option>
737
								<?php endforeach; ?>
738
								</select>
739
							</td>
740
						</tr>
741
					</table>
742

    
743
					<table width="100%" border="0" cellpadding="6" cellspacing="0">
744
						<tr>
745
							<td width="22%" valign="top">&nbsp;</td>
746
							<td width="78%">
747
								<input id="submit" name="save" type="submit" class="formbtn" value="<?=gettext("Save");?>" />
748
								<?php if (isset($id) && $a_cert[$id]): ?>
749
								<input name="id" type="hidden" value="<?=$id;?>" />
750
								<?php endif;?>
751
							</td>
752
						</tr>
753
					</table>
754
				</form>
755

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

    
758
				<form action="system_certmanager.php" method="post" name="iform" id="iform">
759
					<table width="100%" border="0" cellpadding="6" cellspacing="0">
760
						<tr>
761
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Descriptive name");?></td>
762
							<td width="78%" class="vtable">
763
								<input name="descr" type="text" class="formfld unknown" id="descr" size="20" value="<?=htmlspecialchars($pconfig['descr']);?>"/>
764
							</td>
765
						</tr>
766
						<tr>
767
							<td colspan="2" class="list" height="12"></td>
768
						</tr>
769
						<tr>
770
							<td colspan="2" valign="top" class="listtopic"><?=gettext("Complete Signing Request");?></td>
771
						</tr>
772

    
773
						<tr>
774
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Signing Request data");?></td>
775
							<td width="78%" class="vtable">
776
								<textarea name="csr" id="csr" cols="65" rows="7" class="formfld_cert" readonly><?=htmlspecialchars($pconfig['csr']);?></textarea>
777
								<br>
778
								<?=gettext("Copy the certificate signing data from here and forward it to your certificate authority for signing.");?></td>
779
							</td>
780
						</tr>
781
						<tr>
782
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Final Certificate data");?></td>
783
							<td width="78%" class="vtable">
784
								<textarea name="cert" id="cert" cols="65" rows="7" class="formfld_cert"><?=htmlspecialchars($pconfig['cert']);?></textarea>
785
								<br>
786
								<?=gettext("Paste the certificate received from your certificate authority here.");?></td>
787
							</td>
788
						</tr>
789
						<tr>
790
							<td width="22%" valign="top">&nbsp;</td>
791
							<td width="78%">
792
								<?php /* if ( isset($subject_mismatch) && $subject_mismatch === true): ?>
793
								<input id="ignoresubjectmismatch" name="ignoresubjectmismatch" type="checkbox" class="formbtn" value="yes" />
794
								<label for="ignoresubjectmismatch"><strong><?=gettext("Ignore certificate subject mismatch"); ?></strong></label><br />
795
								<?php echo gettext("Warning: Using this option may create an " .
796
								"invalid certificate.  Check this box to disable the request -> " .
797
								"response subject verification. ");
798
								?><br/>
799
								<?php endif; */ ?>
800
								<input id="submit" name="save" type="submit" class="formbtn" value="<?=gettext("Update");?>" />
801
								<?php if (isset($id) && $a_cert[$id]): ?>
802
								<input name="id" type="hidden" value="<?=$id;?>" />
803
								<input name="act" type="hidden" value="csr" />
804
								<?php endif;?>
805
							</td>
806
						</tr>
807
					</table>
808
				</form>
809

    
810
				<?php else:?>
811

    
812
				<table width="100%" border="0" cellpadding="0" cellspacing="0">
813
					<tr>
814
						<td width="15%" class="listhdrr"><?=gettext("Name");?></td>
815
						<td width="15%" class="listhdrr"><?=gettext("Issuer");?></td>
816
						<td width="40%" class="listhdrr"><?=gettext("Distinguished Name");?></td>
817
						<td width="10%" class="listhdrr"><?=gettext("In Use");?></td>
818
						<td width="10%" class="list"></td>
819
					</tr>
820
					<?php
821
						$i = 0;
822
						foreach($a_cert as $cert):
823
							$name = htmlspecialchars($cert['descr']);
824
							
825
							if ($cert['crt']) {
826
								$subj = cert_get_subject($cert['crt']);
827
								$issuer = cert_get_issuer($cert['crt']);
828
								if($subj==$issuer)
829
								  $caname = "<em>" . gettext("self-signed") . "</em>";
830
								else
831
							    $caname = "<em>" . gettext("external"). "</em>";
832
							  $subj = htmlspecialchars($subj);
833
							}
834

    
835
							if ($cert['csr']) {
836
								$subj = htmlspecialchars(csr_get_subject($cert['csr']));
837
								$caname = "<em>" . gettext("external - signature pending") . "</em>";
838
							}
839

    
840
							$ca = lookup_ca($cert['caref']);
841
							if ($ca)
842
								$caname = $ca['descr'];
843

    
844
							if($cert['prv'])
845
								$certimg = "/themes/{$g['theme']}/images/icons/icon_frmfld_cert.png";
846
							else
847
								$certimg = "/themes/{$g['theme']}/images/icons/icon_frmfld_cert.png";
848
					?>
849
					<tr>
850
						<td class="listlr">
851
							<table border="0" cellpadding="0" cellspacing="0">
852
								<tr>
853
									<td align="left" valign="center">
854
										<img src="<?=$certimg;?>" alt="CA" title="CA" border="0" height="16" width="16" />
855
									</td>
856
									<td align="left" valign="middle">
857
										<?=$name;?>
858
									</td>
859
								</tr>
860
							</table>
861
						</td>
862
						<td class="listr"><?=$caname;?>&nbsp;</td>
863
						<td class="listr"><?=$subj;?>&nbsp;</td>
864
						<td class="listr">
865
							<?php if (is_cert_revoked($cert)): ?>
866
							<b>Revoked</b><br/>
867
							<?php endif; ?>
868
							<?php if (is_webgui_cert($cert['refid'])): ?>
869
							webConfigurator<br/>
870
							<?php endif; ?>
871
							<?php if (is_user_cert($cert['refid'])): ?>
872
							User Cert<br/>
873
							<?php endif; ?>
874
							<?php if (is_openvpn_server_cert($cert['refid'])): ?>
875
							OpenVPN Server<br/>
876
							<?php endif; ?>
877
							<?php if (is_openvpn_client_cert($cert['refid'])): ?>
878
							OpenVPN Client<br/>
879
							<?php endif; ?>
880
							<?php if (is_ipsec_cert($cert['refid'])): ?>
881
							IPsec Tunnel<br/>
882
							<?php endif; ?>
883
						</td>
884
						<td valign="middle" nowrap class="list">
885
							<a href="system_certmanager.php?act=exp&id=<?=$i;?>">
886
								<img src="/themes/<?= $g['theme'];?>/images/icons/icon_down.gif" title="<?=gettext("export cert");?>" alt="<?=gettext("export ca");?>" width="17" height="17" border="0" />
887
							</a>
888
							<a href="system_certmanager.php?act=key&id=<?=$i;?>">
889
								<img src="/themes/<?= $g['theme'];?>/images/icons/icon_down.gif" title="<?=gettext("export key");?>" alt="<?=gettext("export ca");?>" width="17" height="17" border="0" />
890
							</a>
891
							<?php	if (!cert_in_use($cert['refid'])): ?>
892
							<a href="system_certmanager.php?act=del&id=<?=$i;?>" onClick="return confirm('<?=gettext("Do you really want to delete this Certificate?");?>')">
893
								<img src="/themes/<?= $g['theme'];?>/images/icons/icon_x.gif" title="<?=gettext("delete cert");?>" alt="<?=gettext("delete cert");?>" width="17" height="17" border="0" />
894
							</a>
895
							<?php	endif; ?>
896
							<?php	if ($cert['csr']): ?>
897
							&nbsp;
898
								<a href="system_certmanager.php?act=csr&id=<?=$i;?>">
899
								<img src="/themes/<?= $g['theme'];?>/images/icons/icon_e.gif" title="<?=gettext("update csr");?>" alt="<?=gettext("update csr");?>" width="17" height="17" border="0" />
900
							</a>
901
							<?php	endif; ?>
902
						</td>
903
					</tr>
904
					<?php
905
							$i++;
906
						endforeach;
907
					?>
908
					<tr>
909
						<td class="list" colspan="4"></td>
910
						<td class="list">
911
							<a href="system_certmanager.php?act=new">
912
								<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" />
913
							</a>
914
						</td>
915
					</tr>
916
					<tr>
917
						<td>&nbsp;</td>
918
						<td colspan="3">NOTE: You can only delete a certificate if it is not currently in use.</td>
919
					</tr>
920
				</table>
921

    
922
				<?php endif; ?>
923

    
924
			</div>
925
		</td>
926
	</tr>
927
</table>
928
<?php include("fend.inc");?>
929
<script type="text/javascript">
930
<!--
931

    
932
method_change();
933
internalca_change();
934

    
935
//-->
936
</script>
937

    
938
</body>
(185-185/225)