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
	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
		unset($input_errors);
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

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

    
216
		/* save modifications */
217
		if (!$input_errors) {
218

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

    
229
				$cert['descr'] = $pconfig['descr'];
230

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

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

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

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

    
266
			write_config();
267

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

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

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

    
283
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
284

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

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

    
311
		/* save modifications */
312
		if (!$input_errors) {
313

    
314
			$cert = $a_cert[$id];
315

    
316
			$cert['descr'] = $pconfig['descr'];
317

    
318
			csr_complete($cert, $pconfig['cert']);
319

    
320
			$a_cert[$id] = $cert;
321

    
322
			write_config();
323

    
324
			pfSenseHeader("system_certmanager.php");
325
		}
326
	}
327
}
328

    
329
include("head.inc");
330
?>
331

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

    
337
function method_change() {
338

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

    
346
	method = document.iform.method.selectedIndex;
347

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

    
384
<?php if ($internal_ca_count): ?>
385
function internalca_change() {
386

    
387
	index = document.iform.caref.selectedIndex;
388
	caref = document.iform.caref[index].value;
389

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

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

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

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

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

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

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

    
500
						<?php if (!$internal_ca_count): ?>
501

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

    
510
						<?php else: ?>
511

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

    
608
					<?php endif; ?>
609

    
610
					</table>
611

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

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

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

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

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

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

    
812
				<?php else:?>
813

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

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

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

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

    
924
				<?php endif; ?>
925

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

    
934
method_change();
935
internalca_change();
936

    
937
//-->
938
</script>
939

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