Project

General

Profile

Download (55.6 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
 * system_certmanager.php
4
 *
5
 * part of pfSense (https://www.pfsense.org)
6
 * Copyright (c) 2004-2013 BSD Perimeter
7
 * Copyright (c) 2013-2016 Electric Sheep Fencing
8
 * Copyright (c) 2014-2024 Rubicon Communications, LLC (Netgate)
9
 * Copyright (c) 2008 Shrew Soft Inc
10
 * All rights reserved.
11
 *
12
 * Licensed under the Apache License, Version 2.0 (the "License");
13
 * you may not use this file except in compliance with the License.
14
 * You may obtain a copy of the License at
15
 *
16
 * http://www.apache.org/licenses/LICENSE-2.0
17
 *
18
 * Unless required by applicable law or agreed to in writing, software
19
 * distributed under the License is distributed on an "AS IS" BASIS,
20
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21
 * See the License for the specific language governing permissions and
22
 * limitations under the License.
23
 */
24

    
25
##|+PRIV
26
##|*IDENT=page-system-certmanager
27
##|*NAME=System: Certificate Manager
28
##|*DESCR=Allow access to the 'System: Certificate Manager' page.
29
##|*MATCH=system_certmanager.php*
30
##|-PRIV
31

    
32
require_once("guiconfig.inc");
33
require_once("certs.inc");
34
require_once("pfsense-utils.inc");
35

    
36
$cert_methods = array(
37
	"internal" => gettext("Create an internal Certificate"),
38
	"import" => gettext("Import an existing Certificate"),
39
	"external" => gettext("Create a Certificate Signing Request"),
40
	"sign" => gettext("Sign a Certificate Signing Request")
41
);
42

    
43
$cert_keylens = array("1024", "2048", "3072", "4096", "6144", "7680", "8192", "15360", "16384");
44
$cert_keytypes = array("RSA", "ECDSA");
45
$cert_types = array(
46
	"server" => "Server Certificate",
47
	"user" => "User Certificate");
48

    
49
global $cert_altname_types;
50
global $openssl_digest_algs;
51
global $cert_strict_values;
52
global $p12_encryption_levels;
53

    
54
$max_lifetime = cert_get_max_lifetime();
55
$default_lifetime = min(3650, $max_lifetime);
56
$openssl_ecnames = cert_build_curve_list();
57
$class = "success";
58

    
59
if (isset($_REQUEST['userid']) && is_numericint($_REQUEST['userid'])) {
60
	$userid = $_REQUEST['userid'];
61
}
62

    
63
if (isset($userid)) {
64
	$cert_methods["existing"] = gettext("Choose an existing certificate");
65
	config_init_path('system/user');
66
}
67

    
68
config_init_path('ca');
69
config_init_path('cert');
70

    
71
$internal_ca_count = 0;
72
foreach (config_get_path('cert', []) as $ca) {
73
	if ($ca['prv']) {
74
		$internal_ca_count++;
75
	}
76
}
77

    
78
if ($_REQUEST['exportp12']) {
79
	$act = 'p12';
80
} elseif ($_REQUEST['exportpkey']) {
81
	$act = 'key';
82
} else {
83
	$act = $_REQUEST['act'];
84
}
85

    
86
if ($act == 'edit') {
87
	$cert_methods = array(
88
		'edit' => gettext("Edit an existing certificate")
89
	);
90
}
91

    
92
if (isset($_REQUEST['id']) && ctype_alnum($_REQUEST['id'])) {
93
	$id = $_REQUEST['id'];
94
}
95
if (!empty($id)) {
96
	$cert_item_config = lookup_cert($id);
97
	$thiscert = &$cert_item_config['item'];
98
}
99

    
100
/* Actions other than 'new' require an ID.
101
 * 'del' action must be submitted via POST. */
102
if ((!empty($act) &&
103
    ($act != 'new') &&
104
    !$thiscert) ||
105
    (($act == 'del') && empty($_POST))) {
106
	pfSenseHeader("system_certmanager.php");
107
	exit;
108
}
109

    
110
switch ($act) {
111
	case 'del':
112
		$name = htmlspecialchars($thiscert['descr']);
113
		if (cert_in_use($id)) {
114
			$savemsg = sprintf(gettext("Certificate %s is in use and cannot be deleted"), $name);
115
			$class = "danger";
116
		} else {
117
			foreach (config_get_path('cert', []) as $cid => $acrt) {
118
				if ($acrt['refid'] == $thiscert['refid']) {
119
					config_del_path("cert/{$cid}");
120
				}
121
			}
122
			$savemsg = sprintf(gettext("Deleted certificate %s"), $name);
123
			write_config($savemsg);
124
		}
125
		unset($act);
126
		break;
127
	case 'new':
128
		/* New certificate, so set default values */
129
		$pconfig['method'] = $_POST['method'];
130
		$pconfig['keytype'] = "RSA";
131
		$pconfig['keylen'] = "2048";
132
		$pconfig['ecname'] = "prime256v1";
133
		$pconfig['digest_alg'] = "sha256";
134
		$pconfig['csr_keytype'] = "RSA";
135
		$pconfig['csr_keylen'] = "2048";
136
		$pconfig['csr_ecname'] = "prime256v1";
137
		$pconfig['csr_digest_alg'] = "sha256";
138
		$pconfig['csrsign_digest_alg'] = "sha256";
139
		$pconfig['type'] = "user";
140
		$pconfig['lifetime'] = $default_lifetime;
141
		break;
142
	case 'edit':
143
		/* Editing a certificate, so populate values */
144
		$pconfig['descr'] = $thiscert['descr'];
145
		$pconfig['cert'] = base64_decode($thiscert['crt']);
146
		$pconfig['key'] = base64_decode($thiscert['prv']);
147
		break;
148
	case 'csr':
149
		/* Editing a CSR, so populate values */
150
		$pconfig['descr'] = $thiscert['descr'];
151
		$pconfig['csr'] = base64_decode($thiscert['csr']);
152
		break;
153
	case 'exp':
154
		/* Exporting a certificate */
155
		send_user_download('data', base64_decode($thiscert['crt']), "{$thiscert['descr']}.crt");
156
		break;
157
	case 'req':
158
		/* Exporting a certificate signing request */
159
		send_user_download('data', base64_decode($thiscert['csr']), "{$thiscert['descr']}.req");
160
		break;
161
	case 'key':
162
		/* Exporting a private key */
163
		$keyout = base64_decode($thiscert['prv']);
164
		if (isset($_POST['exportpass']) && !empty($_POST['exportpass'])) {
165
			if ((strlen($_POST['exportpass']) < 4) or (strlen($_POST['exportpass']) > 1023)) {
166
				$savemsg = gettext("Export password must be in 4 to 1023 characters.");
167
				$class = 'danger';
168
				break;
169
			} else {
170
				$res_key = openssl_pkey_get_private($keyout);
171
				if ($res_key) {
172
					$args = array('encrypt_key_cipher' => OPENSSL_CIPHER_AES_256_CBC);
173
					openssl_pkey_export($res_key, $keyout, $_POST['exportpass'], $args);
174
				} else {
175
					$savemsg = gettext("Unable to export password-protected private key.");
176
					$class = 'danger';
177
				}
178
			}
179
		}
180
		if (!empty($keyout)) {
181
			send_user_download('data', $keyout, "{$thiscert['descr']}.key");
182
		}
183
		break;
184
	case 'p12':
185
		/* Exporting a PKCS#12 file containing the certificate, key, and (if present) CA */
186
		if (isset($_POST['exportpass']) && !empty($_POST['exportpass'])) {
187
			if ((strlen($_POST['exportpass']) < 4) or (strlen($_POST['exportpass']) > 1023)) {
188
				$savemsg = gettext("Export password must be in 4 to 1023 characters.");
189
				$class = 'danger';
190
				break;
191
			} else {
192
				$password = $_POST['exportpass'];
193
			}
194
		} else {
195
			$password = null;
196
		}
197
		if (isset($_POST['p12encryption']) &&
198
		    array_key_exists($_POST['p12encryption'], $p12_encryption_levels)) {
199
			$encryption = $_POST['p12encryption'];
200
		} else {
201
			$encryption = 'high';
202
		}
203
		cert_pkcs12_export($thiscert, $encryption, $password, true, 'download');
204
		break;
205
	default:
206
		break;
207
}
208

    
209
if ($_POST['save'] == gettext("Save")) {
210
	/* Creating a new entry */
211
	$input_errors = array();
212
	$pconfig = $_POST;
213

    
214
	switch ($pconfig['method']) {
215
		case 'sign':
216
			$reqdfields = explode(" ",
217
				"descr catosignwith");
218
			$reqdfieldsn = array(
219
				gettext("Descriptive name"),
220
				gettext("CA to sign with"));
221

    
222
			if (($_POST['csrtosign'] === "new") &&
223
			    ((!strstr($_POST['csrpaste'], "BEGIN CERTIFICATE REQUEST") || !strstr($_POST['csrpaste'], "END CERTIFICATE REQUEST")) &&
224
			    (!strstr($_POST['csrpaste'], "BEGIN NEW CERTIFICATE REQUEST") || !strstr($_POST['csrpaste'], "END NEW CERTIFICATE REQUEST")))) {
225
				$input_errors[] = gettext("This signing request does not appear to be valid.");
226
			}
227

    
228
			if ( (($_POST['csrtosign'] === "new") && (strlen($_POST['keypaste']) > 0)) &&
229
			    ((!strstr($_POST['keypaste'], "BEGIN PRIVATE KEY") && !strstr($_POST['keypaste'], "BEGIN EC PRIVATE KEY")) ||
230
			    (strstr($_POST['keypaste'], "BEGIN PRIVATE KEY") && !strstr($_POST['keypaste'], "END PRIVATE KEY")) ||
231
			    (strstr($_POST['keypaste'], "BEGIN EC PRIVATE KEY") && !strstr($_POST['keypaste'], "END EC PRIVATE KEY")))) {
232
				$input_errors[] = gettext("This private does not appear to be valid.");
233
				$input_errors[] = gettext("Key data field should be blank, or a valid x509 private key");
234
			}
235

    
236
			if ($_POST['lifetime'] > $max_lifetime) {
237
				$input_errors[] = gettext("Lifetime is longer than the maximum allowed value. Use a shorter lifetime.");
238
			}
239
			break;
240
		case 'edit':
241
		case 'import':
242
			/* Make sure we do not have invalid characters in the fields for the certificate */
243
			if (preg_match("/[\?\>\<\&\/\\\"\']/", $_POST['descr'])) {
244
				$input_errors[] = gettext("The field 'Descriptive Name' contains invalid characters.");
245
			}
246
			$pkcs12_data = '';
247
			if ($_POST['import_type'] == 'x509') {
248
				$reqdfields = explode(" ",
249
					"descr cert");
250
				$reqdfieldsn = array(
251
					gettext("Descriptive name"),
252
					gettext("Certificate data"));
253
				if ($_POST['cert'] && (!strstr($_POST['cert'], "BEGIN CERTIFICATE") || !strstr($_POST['cert'], "END CERTIFICATE"))) {
254
					$input_errors[] = gettext("This certificate does not appear to be valid.");
255
				}
256

    
257
				if ($_POST['key'] && (cert_get_publickey($_POST['cert'], false) != cert_get_publickey($_POST['key'], false, 'prv'))) {
258
					$input_errors[] = gettext("The submitted private key does not match the submitted certificate data.");
259
				}
260
			} else {
261
				$reqdfields = array('descr');
262
				$reqdfieldsn = array(gettext("Descriptive name"));
263
				if (!empty($_FILES['pkcs12_cert']) && is_uploaded_file($_FILES['pkcs12_cert']['tmp_name'])) {
264
					$pkcs12_file = file_get_contents($_FILES['pkcs12_cert']['tmp_name']);
265
					if (!openssl_pkcs12_read($pkcs12_file, $pkcs12_data, $_POST['pkcs12_pass'])) {
266
						$input_errors[] = gettext("The submitted password does not unlock the submitted PKCS #12 certificate or the bundle uses unsupported encryption ciphers.");
267
					}
268
				} else {
269
					$input_errors[] = gettext("A PKCS #12 certificate store was not uploaded.");
270
				}
271
			}
272
			break;
273
		case 'internal':
274
			$reqdfields = explode(" ",
275
				"descr caref keylen ecname keytype type lifetime dn_commonname");
276
			$reqdfieldsn = array(
277
				gettext("Descriptive name"),
278
				gettext("Certificate authority"),
279
				gettext("Key length"),
280
				gettext("Elliptic Curve Name"),
281
				gettext("Key type"),
282
				gettext("Certificate Type"),
283
				gettext("Lifetime"),
284
				gettext("Common Name"));
285
			if ($_POST['lifetime'] > $max_lifetime) {
286
				$input_errors[] = gettext("Lifetime is longer than the maximum allowed value. Use a shorter lifetime.");
287
			}
288
			break;
289
		case 'external':
290
			$reqdfields = explode(" ",
291
				"descr csr_keylen csr_ecname csr_keytype csr_dn_commonname");
292
			$reqdfieldsn = array(
293
				gettext("Descriptive name"),
294
				gettext("Key length"),
295
				gettext("Elliptic Curve Name"),
296
				gettext("Key type"),
297
				gettext("Common Name"));
298
			break;
299
		case 'existing':
300
			$reqdfields = array("certref");
301
			$reqdfieldsn = array(gettext("Existing Certificate Choice"));
302
			break;
303
		default:
304
			break;
305
	}
306

    
307
	$altnames = array();
308
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
309

    
310
	if (!in_array($pconfig['method'], array('edit', 'import', 'existing'))) {
311
		/* subjectAltNames */
312
		$san_typevar = 'altname_type';
313
		$san_valuevar = 'altname_value';
314
		// This is just the blank alternate name that is added for display purposes. We don't want to validate/save it
315
		if ($_POST["{$san_valuevar}0"] == "") {
316
			unset($_POST["{$san_typevar}0"]);
317
			unset($_POST["{$san_valuevar}0"]);
318
		}
319
		foreach ($_POST as $key => $value) {
320
			$entry = '';
321
			if (!substr_compare($san_typevar, $key, 0, strlen($san_typevar))) {
322
				$entry = substr($key, strlen($san_typevar));
323
				$field = 'type';
324
			} elseif (!substr_compare($san_valuevar, $key, 0, strlen($san_valuevar))) {
325
				$entry = substr($key, strlen($san_valuevar));
326
				$field = 'value';
327
			}
328

    
329
			if (ctype_digit(strval($entry))) {
330
				$entry++;	// Pre-bootstrap code is one-indexed, but the bootstrap code is 0-indexed
331
				$altnames[$entry][$field] = $value;
332
			}
333
		}
334

    
335
		$pconfig['altnames']['item'] = $altnames;
336

    
337
		/* Input validation for subjectAltNames */
338
		foreach ($altnames as $idx => $altname) {
339
			/* Skip SAN entries with empty values
340
			 * https://redmine.pfsense.org/issues/14183
341
			 */
342
			if (empty($altname['value'])) {
343
				unset($altnames[$idx]);
344
				continue;
345
			}
346
			switch ($altname['type']) {
347
				case "DNS":
348
					if (!is_hostname($altname['value'], true) || is_ipaddr($altname['value'])) {
349
						$input_errors[] = gettext("DNS subjectAltName values must be valid hostnames, FQDNs or wildcard domains.");
350
					}
351
					break;
352
				case "IP":
353
					if (!is_ipaddr($altname['value'])) {
354
						$input_errors[] = gettext("IP subjectAltName values must be valid IP Addresses");
355
					}
356
					break;
357
				case "email":
358
					if (empty($altname['value'])) {
359
						$input_errors[] = gettext("An e-mail address must be provided for this type of subjectAltName");
360
					}
361
					if (preg_match("/[\!\#\$\%\^\(\)\~\?\>\<\&\/\\\,\"\']/", $altname['value'])) {
362
						$input_errors[] = gettext("The e-mail provided in a subjectAltName contains invalid characters.");
363
					}
364
					break;
365
				case "URI":
366
					/* Close enough? */
367
					if (!is_URL($altname['value'])) {
368
						$input_errors[] = gettext("URI subjectAltName types must be a valid URI");
369
					}
370
					break;
371
				default:
372
					$input_errors[] = gettext("Unrecognized subjectAltName type.");
373
			}
374
		}
375

    
376
		/* Make sure we do not have invalid characters in the fields for the certificate */
377
		if (preg_match("/[\?\>\<\&\/\\\"\']/", $_POST['descr'])) {
378
			$input_errors[] = gettext("The field 'Descriptive Name' contains invalid characters.");
379
		}
380
		$pattern = '/[^a-zA-Z0-9\ \'\/~`\!@#\$%\^&\*\(\)_\-\+=\{\}\[\]\|;:"\<\>,\.\?\\\]/';
381
		if (!empty($_POST['dn_commonname']) && preg_match($pattern, $_POST['dn_commonname'])) {
382
			$input_errors[] = gettext("The field 'Common Name' contains invalid characters.");
383
		}
384
		if (!empty($_POST['dn_state']) && preg_match($pattern, $_POST['dn_state'])) {
385
			$input_errors[] = gettext("The field 'State or Province' contains invalid characters.");
386
		}
387
		if (!empty($_POST['dn_city']) && preg_match($pattern, $_POST['dn_city'])) {
388
			$input_errors[] = gettext("The field 'City' contains invalid characters.");
389
		}
390
		if (!empty($_POST['dn_organization']) && preg_match($pattern, $_POST['dn_organization'])) {
391
			$input_errors[] = gettext("The field 'Organization' contains invalid characters.");
392
		}
393
		if (!empty($_POST['dn_organizationalunit']) && preg_match($pattern, $_POST['dn_organizationalunit'])) {
394
			$input_errors[] = gettext("The field 'Organizational Unit' contains invalid characters.");
395
		}
396

    
397
		switch ($pconfig['method']) {
398
			case "internal":
399
				if (isset($_POST["keytype"]) && !in_array($_POST["keytype"], $cert_keytypes)) {
400
					$input_errors[] = gettext("Please select a valid Key Type.");
401
				}
402
				if (isset($_POST["keylen"]) && !in_array($_POST["keylen"], $cert_keylens)) {
403
					$input_errors[] = gettext("Please select a valid Key Length.");
404
				}
405
				if (isset($_POST["ecname"]) && !in_array($_POST["ecname"], array_keys($openssl_ecnames))) {
406
					$input_errors[] = gettext("Please select a valid Elliptic Curve Name.");
407
				}
408
				if (!in_array($_POST["digest_alg"], $openssl_digest_algs)) {
409
					$input_errors[] = gettext("Please select a valid Digest Algorithm.");
410
				}
411
				break;
412
			case "external":
413
				if (isset($_POST["csr_keytype"]) && !in_array($_POST["csr_keytype"], $cert_keytypes)) {
414
					$input_errors[] = gettext("Please select a valid Key Type.");
415
				}
416
				if (isset($_POST["csr_keylen"]) && !in_array($_POST["csr_keylen"], $cert_keylens)) {
417
					$input_errors[] = gettext("Please select a valid Key Length.");
418
				}
419
				if (isset($_POST["csr_ecname"]) && !in_array($_POST["csr_ecname"], array_keys($openssl_ecnames))) {
420
					$input_errors[] = gettext("Please select a valid Elliptic Curve Name.");
421
				}
422
				if (!in_array($_POST["csr_digest_alg"], $openssl_digest_algs)) {
423
					$input_errors[] = gettext("Please select a valid Digest Algorithm.");
424
				}
425
				break;
426
			case "sign":
427
				if (!in_array($_POST["csrsign_digest_alg"], $openssl_digest_algs)) {
428
					$input_errors[] = gettext("Please select a valid Digest Algorithm.");
429
				}
430
				break;
431
			default:
432
				break;
433
		}
434
	}
435

    
436
	/* save modifications */
437
	if (!$input_errors) {
438
		$old_err_level = error_reporting(0); /* otherwise openssl_ functions throw warnings directly to a page breaking menu tabs */
439

    
440
		if (isset($id) && $thiscert) {
441
			$cert = $thiscert;
442
		} else {
443
			$cert = array();
444
			$cert['refid'] = uniqid();
445
		}
446

    
447
		$cert['descr'] = $pconfig['descr'];
448

    
449
		switch($pconfig['method']) {
450
			case 'existing':
451
				/* Add an existing certificate to a user */
452
				$ucert = lookup_cert($pconfig['certref']);
453
				$ucert = $ucert['item'];
454
				if ($ucert && config_get_path("system/user")) {
455
					config_set_path("system/user/{$userid}/cert/", $ucert['refid']);
456
					$savemsg = sprintf(gettext("Added certificate %s to user %s"), htmlspecialchars($ucert['descr']), config_get_path("system/user/{$userid}/name"));
457
				}
458
				unset($cert);
459
				break;
460
			case 'sign':
461
				/* Sign a CSR */
462
				$csrid = lookup_cert($pconfig['csrtosign']);
463
				$csrid = $csrid['item'];
464
				$ca_item_config = lookup_ca($pconfig['catosignwith']);
465
				$ca = &$ca_item_config['item'];
466
				// Read the CSR from config array, or if a new one, from the textarea
467
				if ($pconfig['csrtosign'] === "new") {
468
					$csr = $pconfig['csrpaste'];
469
				} else {
470
					$csr = base64_decode($csrid['csr']);
471
				}
472
				if (count($altnames)) {
473
					foreach ($altnames as $altname) {
474
						$altnames_tmp[] = "{$altname['type']}:" . $altname['value'];
475
					}
476
					$altname_str = implode(",", $altnames_tmp);
477
				}
478
				$n509 = csr_sign($csr, $ca, $pconfig['csrsign_lifetime'], $pconfig['type'], $altname_str, $pconfig['csrsign_digest_alg']);
479
				config_set_path("ca/{$ca_item_config['idx']}", $ca);
480
				if ($n509) {
481
					// Gather the details required to save the new cert
482
					$newcert = array();
483
					$newcert['refid'] = uniqid();
484
					$newcert['caref'] = $pconfig['catosignwith'];
485
					$newcert['descr'] = $pconfig['descr'];
486
					$newcert['type'] = $pconfig['type'];
487
					$newcert['crt'] = base64_encode($n509);
488
					if ($pconfig['csrtosign'] === "new") {
489
						$newcert['prv'] = base64_encode($pconfig['keypaste']);
490
					} else {
491
						$newcert['prv'] = $csrid['prv'];
492
					}
493
					// Add it to the config file
494
					config_set_path('cert/', $newcert);
495
					$savemsg = sprintf(gettext("Signed certificate %s"), htmlspecialchars($newcert['descr']));
496
					unset($act);
497
				}
498
				unset($cert);
499
				break;
500
			case 'edit':
501
				cert_import($cert, $pconfig['cert'], $pconfig['key']);
502
				$savemsg = sprintf(gettext("Edited certificate %s"), htmlspecialchars($cert['descr']));
503
				unset($act);
504
				break;
505
			case 'import':
506
				/* Import an external certificate+key */
507
				if ($pkcs12_data) {
508
					$pconfig['cert'] = $pkcs12_data['cert'];
509
					$pconfig['key'] = $pkcs12_data['pkey'];
510
					if ($_POST['pkcs12_intermediate'] && is_array($pkcs12_data['extracerts'])) {
511
						foreach ($pkcs12_data['extracerts'] as $intermediate) {
512
							$int_data = openssl_x509_parse($intermediate);
513
							if (!$int_data) continue;
514
							$cn = $int_data['subject']['CN'];
515
							$int_ca = array('descr' => $cn, 'refid' => uniqid());
516
							if (ca_import($int_ca, $intermediate)) {
517
								config_set_path('ca/', $int_ca);
518
							}
519
						}
520
					}
521
				}
522
				cert_import($cert, $pconfig['cert'], $pconfig['key']);
523
				$savemsg = sprintf(gettext("Imported certificate %s"), htmlspecialchars($cert['descr']));
524
				unset($act);
525
				break;
526
			case 'internal':
527
				/* Create an internal certificate */
528
				$dn = array('commonName' => $pconfig['dn_commonname']);
529
				if (!empty($pconfig['dn_country'])) {
530
					$dn['countryName'] = $pconfig['dn_country'];
531
				}
532
				if (!empty($pconfig['dn_state'])) {
533
					$dn['stateOrProvinceName'] = $pconfig['dn_state'];
534
				}
535
				if (!empty($pconfig['dn_city'])) {
536
					$dn['localityName'] = $pconfig['dn_city'];
537
				}
538
				if (!empty($pconfig['dn_organization'])) {
539
					$dn['organizationName'] = $pconfig['dn_organization'];
540
				}
541
				if (!empty($pconfig['dn_organizationalunit'])) {
542
					$dn['organizationalUnitName'] = $pconfig['dn_organizationalunit'];
543
				}
544
				$altnames_tmp = array();
545
				$cn_altname = cert_add_altname_type($pconfig['dn_commonname']);
546
				if (!empty($cn_altname)) {
547
					$altnames_tmp[] = $cn_altname;
548
				}
549
				if (count($altnames)) {
550
					foreach ($altnames as $altname) {
551
						// The CN is added as a SAN automatically, do not add it again.
552
						if ($altname['value'] != $pconfig['dn_commonname']) {
553
							$altnames_tmp[] = "{$altname['type']}:" . $altname['value'];
554
						}
555
					}
556
				}
557
				if (!empty($altnames_tmp)) {
558
					$dn['subjectAltName'] = implode(",", $altnames_tmp);
559
				}
560
				if (!cert_create($cert, $pconfig['caref'], $pconfig['keylen'], $pconfig['lifetime'], $dn, $pconfig['type'], $pconfig['digest_alg'], $pconfig['keytype'], $pconfig['ecname'])) {
561
					$input_errors = array();
562
					while ($ssl_err = openssl_error_string()) {
563
						if (strpos($ssl_err, 'NCONF_get_string:no value') === false) {
564
							$input_errors[] = sprintf(gettext("OpenSSL Library Error: %s"), $ssl_err);
565
						}
566
					}
567
				}
568
				$savemsg = sprintf(gettext("Created internal certificate %s"), htmlspecialchars($cert['descr']));
569
				unset($act);
570
				break;
571
			case 'external':
572
				/* Create a certificate signing request */
573
				$dn = array('commonName' => $pconfig['csr_dn_commonname']);
574
				if (!empty($pconfig['csr_dn_country'])) {
575
					$dn['countryName'] = $pconfig['csr_dn_country'];
576
				}
577
				if (!empty($pconfig['csr_dn_state'])) {
578
					$dn['stateOrProvinceName'] = $pconfig['csr_dn_state'];
579
				}
580
				if (!empty($pconfig['csr_dn_city'])) {
581
					$dn['localityName'] = $pconfig['csr_dn_city'];
582
				}
583
				if (!empty($pconfig['csr_dn_organization'])) {
584
					$dn['organizationName'] = $pconfig['csr_dn_organization'];
585
				}
586
				if (!empty($pconfig['csr_dn_organizationalunit'])) {
587
					$dn['organizationalUnitName'] = $pconfig['csr_dn_organizationalunit'];
588
				}
589
				$altnames_tmp = array();
590
				$cn_altname = cert_add_altname_type($pconfig['csr_dn_commonname']);
591
				if (!empty($cn_altname)) {
592
					$altnames_tmp[] = $cn_altname;
593
				}
594
				if (count($altnames)) {
595
					foreach ($altnames as $altname) {
596
						// The CN is added as a SAN automatically, do not add it again.
597
						if ($altname['value'] != $pconfig['csr_dn_commonname']) {
598
							$altnames_tmp[] = "{$altname['type']}:" . $altname['value'];
599
						}
600
					}
601
				}
602
				if (!empty($altnames_tmp)) {
603
					$dn['subjectAltName'] = implode(",", $altnames_tmp);
604
				}
605
				if (!csr_generate($cert, $pconfig['csr_keylen'], $dn, $pconfig['type'], $pconfig['csr_digest_alg'], $pconfig['csr_keytype'], $pconfig['csr_ecname'])) {
606
					$input_errors = array();
607
					while ($ssl_err = openssl_error_string()) {
608
						if (strpos($ssl_err, 'NCONF_get_string:no value') === false) {
609
							$input_errors[] = sprintf(gettext("OpenSSL Library Error: %s"), $ssl_err);
610
						}
611
					}
612
				}
613
				$savemsg = sprintf(gettext("Created certificate signing request %s"), htmlspecialchars($cert['descr']));
614
				unset($act);
615
				break;
616
			default:
617
				break;
618
		}
619
		error_reporting($old_err_level);
620

    
621
		if (isset($id) && $thiscert) {
622
			$thiscert = $cert;
623
			config_set_path("cert/{$cert_item_config['idx']}", $thiscert);
624
		} elseif ($cert) {
625
			config_set_path('cert/', $cert);
626
		}
627

    
628
		if (isset($userid) && (config_get_path('system/user') !== null)) {
629
			config_set_path("system/user/{$userid}/cert/", $cert['refid']);
630
		}
631

    
632
		if (!$input_errors) {
633
			write_config($savemsg);
634
		}
635

    
636
		if ((isset($userid) && is_numeric($userid)) && !$input_errors) {
637
			post_redirect("system_usermanager.php", array('act' => 'edit', 'userid' => $userid));
638
			exit;
639
		}
640
	}
641
} elseif ($_POST['save'] == gettext("Update")) {
642
	/* Updating a certificate signing request */
643
	unset($input_errors);
644
	$pconfig = $_POST;
645

    
646
	/* input validation */
647
	$reqdfields = explode(" ", "descr cert");
648
	$reqdfieldsn = array(
649
		gettext("Descriptive name"),
650
		gettext("Final Certificate data"));
651

    
652
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
653

    
654
	if (preg_match("/[\?\>\<\&\/\\\"\']/", $_POST['descr'])) {
655
		$input_errors[] = gettext("The field 'Descriptive Name' contains invalid characters.");
656
	}
657

    
658
	$mod_csr = cert_get_publickey($pconfig['csr'], false, 'csr');
659
	$mod_cert = cert_get_publickey($pconfig['cert'], false);
660

    
661
	if (strcmp($mod_csr, $mod_cert)) {
662
		// simply: if the moduli don't match, then the private key and public key won't match
663
		$input_errors[] = gettext("The certificate public key does not match the signing request public key.");
664
		$subject_mismatch = true;
665
	}
666

    
667
	/* save modifications */
668
	if (!$input_errors) {
669
		$cert = $thiscert;
670
		$cert['descr'] = $pconfig['descr'];
671
		csr_complete($cert, $pconfig['cert']);
672
		$thiscert = $cert;
673
		config_set_path("cert/{$cert_item_config['idx']}", $thiscert);
674
		$savemsg = sprintf(gettext("Updated certificate signing request %s"), htmlspecialchars($pconfig['descr']));
675
		write_config($savemsg);
676
		pfSenseHeader("system_certmanager.php");
677
	}
678
}
679

    
680
$pgtitle = array(gettext('System'), gettext('Certificates'), gettext('Certificates'));
681
$pglinks = array("", "system_camanager.php", "system_certmanager.php");
682

    
683
if (($act == "new" || ($_POST['save'] == gettext("Save") && $input_errors)) ||
684
    ($act == "csr" || ($_POST['save'] == gettext("Update") && $input_errors))) {
685
	$pgtitle[] = gettext('Edit');
686
	$pglinks[] = "@self";
687
}
688
include("head.inc");
689

    
690
if ($input_errors) {
691
	print_input_errors($input_errors);
692
}
693

    
694
if ($savemsg) {
695
	print_info_box($savemsg, $class);
696
}
697

    
698
$tab_array = array();
699
$tab_array[] = array(gettext('Authorities'), false, 'system_camanager.php');
700
$tab_array[] = array(gettext('Certificates'), true, 'system_certmanager.php');
701
$tab_array[] = array(gettext('Revocation'), false, 'system_crlmanager.php');
702
display_top_tabs($tab_array);
703

    
704
if (in_array($act, array('new', 'edit')) || (($_POST['save'] == gettext("Save")) && $input_errors)) {
705
	$form = new Form();
706
	$form->setAction('system_certmanager.php')->setMultipartEncoding();
707

    
708
	if (isset($userid) && config_get_path("system/user")) {
709
		$form->addGlobal(new Form_Input(
710
			'userid',
711
			null,
712
			'hidden',
713
			$userid
714
		));
715
	}
716

    
717
	if (isset($id) && $thiscert) {
718
		$form->addGlobal(new Form_Input(
719
			'id',
720
			null,
721
			'hidden',
722
			$id
723
		));
724
	}
725

    
726
	if ($act) {
727
		$form->addGlobal(new Form_Input(
728
			'act',
729
			null,
730
			'hidden',
731
			$act
732
		));
733
	}
734

    
735
	switch ($act) {
736
		case 'edit':
737
			$maintitle = gettext('Edit an Existing Certificate');
738
			break;
739
		case 'new':
740
		default:
741
			$maintitle = gettext('Add/Sign a New Certificate');
742
			break;
743
	}
744

    
745
	$section = new Form_Section($maintitle);
746

    
747
	if (!isset($id) || ($act == 'edit')) {
748
		$section->addInput(new Form_Select(
749
			'method',
750
			'*Method',
751
			$pconfig['method'],
752
			$cert_methods
753
		))->toggles();
754
	}
755

    
756
	$section->addInput(new Form_Input(
757
		'descr',
758
		'*Descriptive name',
759
		'text',
760
		(config_get_path('system/user') && empty($pconfig['descr'])) ? config_get_path("system/user/{$userid}/name") : $pconfig['descr']
761
	))->addClass('toggle-internal toggle-import toggle-edit toggle-external toggle-sign toggle-existing collapse')
762
	->setHelp('The name of this entry as displayed in the GUI for reference.%s' .
763
		'This name can contain spaces but it cannot contain any of the ' .
764
		'following characters: %s', '<br/>', "?, >, <, &, /, \, \", '");
765

    
766
	if (!empty($pconfig['cert'])) {
767
		$section->addInput(new Form_StaticText(
768
			"Subject",
769
			htmlspecialchars(cert_get_subject($pconfig['cert'], false))
770
		))->addClass('toggle-edit collapse');
771
	}
772

    
773
	$form->add($section);
774

    
775
	// Return an array containing the IDs od all CAs
776
	function list_cas() {
777
		$allCas = array();
778

    
779
		foreach (config_get_path('ca', []) as $ca) {
780
			if ($ca['prv']) {
781
				$allCas[$ca['refid']] = $ca['descr'];
782
			}
783
		}
784

    
785
		return $allCas;
786
	}
787

    
788
	// Return an array containing the IDs od all CSRs
789
	function list_csrs() {
790
		global $config;
791
		$allCsrs = array();
792

    
793
		foreach (config_get_path('cert', []) as $cert) {
794
			if ($cert['csr']) {
795
				$allCsrs[$cert['refid']] = $cert['descr'];
796
			}
797
		}
798

    
799
		return ['new' => gettext('New CSR (Paste below)')] + $allCsrs;
800
	}
801

    
802
	$section = new Form_Section('Sign CSR');
803
	$section->addClass('toggle-sign collapse');
804

    
805
	$section->AddInput(new Form_Select(
806
		'catosignwith',
807
		'*CA to sign with',
808
		$pconfig['catosignwith'],
809
		list_cas()
810
	));
811

    
812
	$section->AddInput(new Form_Select(
813
		'csrtosign',
814
		'*CSR to sign',
815
		isset($pconfig['csrtosign']) ? $pconfig['csrtosign'] : 'new',
816
		list_csrs()
817
	));
818

    
819
	$section->addInput(new Form_Textarea(
820
		'csrpaste',
821
		'CSR data',
822
		$pconfig['csrpaste']
823
	))->setHelp('Paste a Certificate Signing Request in X.509 PEM format here.');
824

    
825
	$section->addInput(new Form_Textarea(
826
		'keypaste',
827
		'Key data',
828
		$pconfig['keypaste']
829
	))->setHelp('Optionally paste a private key here. The key will be associated with the newly signed certificate in %1$s', g_get('product_label'));
830

    
831
	$section->addInput(new Form_Input(
832
		'csrsign_lifetime',
833
		'*Certificate Lifetime (days)',
834
		'number',
835
		$pconfig['csrsign_lifetime'] ? $pconfig['csrsign_lifetime']:$default_lifetime,
836
		['max' => $max_lifetime]
837
	))->setHelp('The length of time the signed certificate will be valid, in days. %1$s' .
838
		'Server certificates should not have a lifetime over %2$s days or some platforms ' .
839
		'may consider the certificate invalid.', '<br/>', $cert_strict_values['max_server_cert_lifetime']);
840
	$section->addInput(new Form_Select(
841
		'csrsign_digest_alg',
842
		'*Digest Algorithm',
843
		$pconfig['csrsign_digest_alg'],
844
		array_combine($openssl_digest_algs, $openssl_digest_algs)
845
	))->setHelp('The digest method used when the certificate is signed. %1$s' .
846
		'The best practice is to use SHA256 or higher. '.
847
		'Some services and platforms, such as the GUI web server and OpenVPN, consider weaker digest algorithms invalid.', '<br/>');
848

    
849
	$form->add($section);
850

    
851
	if ($act == 'edit') {
852
		$editimport = gettext("Edit Certificate");
853
	} else {
854
		$editimport = gettext("Import Certificate");
855
	}
856

    
857
	$section = new Form_Section($editimport);
858
	$section->addClass('toggle-import toggle-edit collapse');
859

    
860
	$group = new Form_Group('Certificate Type');
861

    
862
	$group->add(new Form_Checkbox(
863
		'import_type',
864
		'Certificate Type',
865
		'X.509 (PEM)',
866
		(!isset($pconfig['import_type']) || $pconfig['import_type'] == 'x509'),
867
		'x509'
868
	))->displayAsRadio()->addClass('import_type_toggle');
869

    
870
	$group->add(new Form_Checkbox(
871
		'import_type',
872
		'Certificate Type',
873
		'PKCS #12 (PFX)',
874
		(isset($pconfig['import_type']) && $pconfig['import_type'] == 'pkcs12'),
875
		'pkcs12'
876
	))->displayAsRadio()->addClass('import_type_toggle');
877

    
878
	$section->add($group);
879

    
880
	$section->addInput(new Form_Textarea(
881
		'cert',
882
		'*Certificate data',
883
		$pconfig['cert']
884
	))->setHelp('Paste a certificate in X.509 PEM format here.');
885

    
886
	$section->addInput(new Form_Textarea(
887
		'key',
888
		'Private key data',
889
		$pconfig['key']
890
	))->setHelp('Paste a private key in X.509 PEM format here. This field may remain empty in certain cases, such as when the private key is stored on a PKCS#11 token.');
891

    
892
	$section->addInput(new Form_Input(
893
		'pkcs12_cert',
894
		'PKCS #12 certificate',
895
		'file',
896
		$pconfig['pkcs12_cert']
897
	))->setHelp('Select a PKCS #12 certificate store.');
898

    
899
	$section->addInput(new Form_Input(
900
		'pkcs12_pass',
901
		'PKCS #12 certificate password',
902
		'password',
903
		$pconfig['pkcs12_pass']
904
	))->setHelp('Enter the password to unlock the PKCS #12 certificate store.');
905

    
906
	$section->addInput(new Form_Checkbox(
907
		'pkcs12_intermediate',
908
		'Intermediates',
909
		'Import intermediate CAs',
910
		isset($pconfig['pkcs12_intermediate'])
911
	))->setHelp('Import any intermediate certificate authorities found in the PKCS #12 certificate store.');
912

    
913
	if ($act == 'edit') {
914
		$section->addInput(new Form_Input(
915
			'exportpass',
916
			'Export Password',
917
			'password',
918
			null,
919
			['placeholder' => gettext('Export Password'), 'autocomplete' => 'new-password']
920
		))->setHelp('Enter the password to use when using the export buttons below (not stored)')->addClass('toggle-edit collapse');
921
		$section->addInput(new Form_Select(
922
		'p12encryption',
923
		'PKCS#12 Encryption',
924
		'high',
925
		$p12_encryption_levels
926
		))->setHelp('Select the level of encryption to use when exporting a PKCS#12 archive. ' .
927
				'Encryption support varies by Operating System and program');
928
	}
929

    
930
	$form->add($section);
931
	$section = new Form_Section('Internal Certificate');
932
	$section->addClass('toggle-internal collapse');
933

    
934
	if (!$internal_ca_count) {
935
		$section->addInput(new Form_StaticText(
936
			'*Certificate authority',
937
			gettext('No internal Certificate Authorities have been defined. ') .
938
			gettext('An internal CA must be defined in order to create an internal certificate. ') .
939
			sprintf(gettext('%1$sCreate%2$s an internal CA.'), '<a href="system_camanager.php?act=new&amp;method=internal"> ', '</a>')
940
		));
941
	} else {
942
		$allCas = array();
943
		foreach (config_get_path('ca', []) as $ca) {
944
			if (!$ca['prv']) {
945
				continue;
946
			}
947

    
948
			$allCas[ $ca['refid'] ] = $ca['descr'];
949
		}
950

    
951
		$section->addInput(new Form_Select(
952
			'caref',
953
			'*Certificate authority',
954
			$pconfig['caref'],
955
			$allCas
956
		));
957
	}
958

    
959
	$section->addInput(new Form_Select(
960
		'keytype',
961
		'*Key type',
962
		$pconfig['keytype'],
963
		array_combine($cert_keytypes, $cert_keytypes)
964
	));
965

    
966
	$group = new Form_Group($i == 0 ? '*Key length':'');
967
	$group->addClass('rsakeys');
968
	$group->add(new Form_Select(
969
		'keylen',
970
		null,
971
		$pconfig['keylen'],
972
		array_combine($cert_keylens, $cert_keylens)
973
	))->setHelp('The length to use when generating a new RSA key, in bits. %1$s' .
974
		'The Key Length should not be lower than 2048 or some platforms ' .
975
		'may consider the certificate invalid.', '<br/>');
976
	$section->add($group);
977

    
978
	$group = new Form_Group($i == 0 ? '*Elliptic Curve Name':'');
979
	$group->addClass('ecnames');
980
	$group->add(new Form_Select(
981
		'ecname',
982
		null,
983
		$pconfig['ecname'],
984
		$openssl_ecnames
985
	))->setHelp('Curves may not be compatible with all uses. Known compatible curve uses are denoted in brackets.');
986
	$section->add($group);
987

    
988
	$section->addInput(new Form_Select(
989
		'digest_alg',
990
		'*Digest Algorithm',
991
		$pconfig['digest_alg'],
992
		array_combine($openssl_digest_algs, $openssl_digest_algs)
993
	))->setHelp('The digest method used when the certificate is signed. %1$s' .
994
		'The best practice is to use SHA256 or higher. '.
995
		'Some services and platforms, such as the GUI web server and OpenVPN, consider weaker digest algorithms invalid.', '<br/>');
996

    
997
	$section->addInput(new Form_Input(
998
		'lifetime',
999
		'*Lifetime (days)',
1000
		'number',
1001
		$pconfig['lifetime'],
1002
		['max' => $max_lifetime]
1003
	))->setHelp('The length of time the signed certificate will be valid, in days. %1$s' .
1004
		'Server certificates should not have a lifetime over %2$s days or some platforms ' .
1005
		'may consider the certificate invalid.', '<br/>', $cert_strict_values['max_server_cert_lifetime']);
1006

    
1007
	$section->addInput(new Form_Input(
1008
		'dn_commonname',
1009
		'*Common Name',
1010
		'text',
1011
		$pconfig['dn_commonname'],
1012
		['placeholder' => 'e.g. www.example.com']
1013
	));
1014

    
1015
	$section->addInput(new Form_StaticText(
1016
		null,
1017
		gettext('The following certificate subject components are optional and may be left blank.')
1018
	));
1019

    
1020
	$section->addInput(new Form_Select(
1021
		'dn_country',
1022
		'Country Code',
1023
		$pconfig['dn_country'],
1024
		get_cert_country_codes()
1025
	));
1026

    
1027
	$section->addInput(new Form_Input(
1028
		'dn_state',
1029
		'State or Province',
1030
		'text',
1031
		$pconfig['dn_state'],
1032
		['placeholder' => 'e.g. Texas']
1033
	));
1034

    
1035
	$section->addInput(new Form_Input(
1036
		'dn_city',
1037
		'City',
1038
		'text',
1039
		$pconfig['dn_city'],
1040
		['placeholder' => 'e.g. Austin']
1041
	));
1042

    
1043
	$section->addInput(new Form_Input(
1044
		'dn_organization',
1045
		'Organization',
1046
		'text',
1047
		$pconfig['dn_organization'],
1048
		['placeholder' => 'e.g. My Company Inc']
1049
	));
1050

    
1051
	$section->addInput(new Form_Input(
1052
		'dn_organizationalunit',
1053
		'Organizational Unit',
1054
		'text',
1055
		$pconfig['dn_organizationalunit'],
1056
		['placeholder' => 'e.g. My Department Name (optional)']
1057
	));
1058

    
1059
	$form->add($section);
1060
	$section = new Form_Section('External Signing Request');
1061
	$section->addClass('toggle-external collapse');
1062

    
1063
	$section->addInput(new Form_Select(
1064
		'csr_keytype',
1065
		'*Key type',
1066
		$pconfig['csr_keytype'],
1067
		array_combine($cert_keytypes, $cert_keytypes)
1068
	));
1069

    
1070
	$group = new Form_Group($i == 0 ? '*Key length':'');
1071
	$group->addClass('csr_rsakeys');
1072
	$group->add(new Form_Select(
1073
		'csr_keylen',
1074
		null,
1075
		$pconfig['csr_keylen'],
1076
		array_combine($cert_keylens, $cert_keylens)
1077
	))->setHelp('The length to use when generating a new RSA key, in bits. %1$s' .
1078
		'The Key Length should not be lower than 2048 or some platforms ' .
1079
		'may consider the certificate invalid.', '<br/>');
1080
	$section->add($group);
1081

    
1082
	$group = new Form_Group($i == 0 ? '*Elliptic Curve Name':'');
1083
	$group->addClass('csr_ecnames');
1084
	$group->add(new Form_Select(
1085
		'csr_ecname',
1086
		null,
1087
		$pconfig['csr_ecname'],
1088
		$openssl_ecnames
1089
	));
1090
	$section->add($group);
1091

    
1092
	$section->addInput(new Form_Select(
1093
		'csr_digest_alg',
1094
		'*Digest Algorithm',
1095
		$pconfig['csr_digest_alg'],
1096
		array_combine($openssl_digest_algs, $openssl_digest_algs)
1097
	))->setHelp('The digest method used when the certificate is signed. %1$s' .
1098
		'The best practice is to use SHA256 or higher. '.
1099
		'Some services and platforms, such as the GUI web server and OpenVPN, consider weaker digest algorithms invalid.', '<br/>');
1100

    
1101
	$section->addInput(new Form_Input(
1102
		'csr_dn_commonname',
1103
		'*Common Name',
1104
		'text',
1105
		$pconfig['csr_dn_commonname'],
1106
		['placeholder' => 'e.g. internal-ca']
1107
	));
1108

    
1109
	$section->addInput(new Form_StaticText(
1110
		null,
1111
		gettext('The following certificate subject components are optional and may be left blank.')
1112
	));
1113

    
1114
	$section->addInput(new Form_Select(
1115
		'csr_dn_country',
1116
		'Country Code',
1117
		$pconfig['csr_dn_country'],
1118
		get_cert_country_codes()
1119
	));
1120

    
1121
	$section->addInput(new Form_Input(
1122
		'csr_dn_state',
1123
		'State or Province',
1124
		'text',
1125
		$pconfig['csr_dn_state'],
1126
		['placeholder' => 'e.g. Texas']
1127
	));
1128

    
1129
	$section->addInput(new Form_Input(
1130
		'csr_dn_city',
1131
		'City',
1132
		'text',
1133
		$pconfig['csr_dn_city'],
1134
		['placeholder' => 'e.g. Austin']
1135
	));
1136

    
1137
	$section->addInput(new Form_Input(
1138
		'csr_dn_organization',
1139
		'Organization',
1140
		'text',
1141
		$pconfig['csr_dn_organization'],
1142
		['placeholder' => 'e.g. My Company Inc']
1143
	));
1144

    
1145
	$section->addInput(new Form_Input(
1146
		'csr_dn_organizationalunit',
1147
		'Organizational Unit',
1148
		'text',
1149
		$pconfig['csr_dn_organizationalunit'],
1150
		['placeholder' => 'e.g. My Department Name (optional)']
1151
	));
1152

    
1153
	$form->add($section);
1154
	$section = new Form_Section('Choose an Existing Certificate');
1155
	$section->addClass('toggle-existing collapse');
1156

    
1157
	$existCerts = array();
1158

    
1159
	foreach (config_get_path('cert', []) as $cert) {
1160
		if (!is_array($cert) || empty($cert)) {
1161
			continue;
1162
		}
1163

    
1164
		if (isset($userid) &&
1165
		    in_array($cert['refid'], config_get_path("system/user/{$userid}/cert", []))) {
1166
			continue;
1167
		}
1168

    
1169
		$ca = lookup_ca($cert['caref']);
1170
		$ca = $ca['item'];
1171
		if ($ca) {
1172
			$cert['descr'] .= " (CA: {$ca['descr']})";
1173
		}
1174

    
1175
		if (cert_in_use($cert['refid'])) {
1176
			$cert['descr'] .= " (In Use)";
1177
		}
1178
		if (is_cert_revoked($cert)) {
1179
			$cert['descr'] .= " (Revoked)";
1180
		}
1181

    
1182
		$existCerts[ $cert['refid'] ] = $cert['descr'];
1183
	}
1184

    
1185
	$section->addInput(new Form_Select(
1186
		'certref',
1187
		'*Existing Certificates',
1188
		$pconfig['certref'],
1189
		$existCerts
1190
	));
1191

    
1192
	$form->add($section);
1193

    
1194
	$section = new Form_Section('Certificate Attributes');
1195
	$section->addClass('toggle-external toggle-internal toggle-sign collapse');
1196

    
1197
	$section->addInput(new Form_StaticText(
1198
		gettext('Attribute Notes'),
1199
		'<span class="help-block">'.
1200
		gettext('The following attributes are added to certificates and ' .
1201
		'requests when they are created or signed. These attributes behave ' .
1202
		'differently depending on the selected mode.') .
1203
		'<br/><br/>' .
1204
		'<span class="toggle-internal collapse">' . gettext('For Internal Certificates, these attributes are added directly to the certificate as shown.') . '</span>' .
1205
		'<span class="toggle-external collapse">' .
1206
		gettext('For Certificate Signing Requests, These attributes are added to the request but they may be ignored or changed by the CA that signs the request. ') .
1207
		'<br/><br/>' .
1208
		gettext('If this CSR will be signed using the Certificate Manager on this firewall, set the attributes when signing instead as they cannot be carried over.') . '</span>' .
1209
		'<span class="toggle-sign collapse">' . gettext('When Signing a Certificate Request, existing attributes in the request cannot be copied. The attributes below will be applied to the resulting certificate.') . '</span>' .
1210
		'</span>'
1211
	));
1212

    
1213
	$section->addInput(new Form_Select(
1214
		'type',
1215
		'*Certificate Type',
1216
		$pconfig['type'],
1217
		$cert_types
1218
	))->setHelp('Add type-specific usage attributes to the signed certificate.' .
1219
		' Used for placing usage restrictions on, or granting abilities to, ' .
1220
		'the signed certificate.');
1221

    
1222
	if (empty($pconfig['altnames']['item'])) {
1223
		$pconfig['altnames']['item'] = array(
1224
			array('type' => null, 'value' => null)
1225
		);
1226
	}
1227

    
1228
	$counter = 0;
1229
	$numrows = count($pconfig['altnames']['item']) - 1;
1230

    
1231
	foreach ($pconfig['altnames']['item'] as $item) {
1232

    
1233
		$group = new Form_Group($counter == 0 ? 'Alternative Names':'');
1234

    
1235
		$group->add(new Form_Select(
1236
			'altname_type' . $counter,
1237
			'Type',
1238
			$item['type'],
1239
			$cert_altname_types
1240
		))->setHelp(($counter == $numrows) ? 'Type':null);
1241

    
1242
		$group->add(new Form_Input(
1243
			'altname_value' . $counter,
1244
			null,
1245
			'text',
1246
			$item['value']
1247
		))->setHelp(($counter == $numrows) ? 'Value':null);
1248

    
1249
		$group->add(new Form_Button(
1250
			'deleterow' . $counter,
1251
			'Delete',
1252
			null,
1253
			'fa-solid fa-trash-can'
1254
		))->addClass('btn-warning');
1255

    
1256
		$group->addClass('repeatable');
1257

    
1258
		$group->setHelp('Enter additional identifiers for the certificate ' .
1259
			'in this list. The Common Name field is automatically ' .
1260
			'added to the certificate as an Alternative Name. ' .
1261
			'The signing CA may ignore or change these values.');
1262

    
1263
		$section->add($group);
1264

    
1265
		$counter++;
1266
	}
1267

    
1268
	$section->addInput(new Form_Button(
1269
		'addrow',
1270
		'Add SAN Row',
1271
		null,
1272
		'fa-solid fa-plus'
1273
	))->addClass('btn-success');
1274

    
1275
	$form->add($section);
1276

    
1277
	if (($act == 'edit') && !empty($pconfig['key'])) {
1278
		$form->addGlobal(new Form_Button(
1279
			'exportpkey',
1280
			'Export Private Key',
1281
			null,
1282
			'fa-solid fa-key'
1283
		))->addClass('btn-primary');
1284
		$form->addGlobal(new Form_Button(
1285
			'exportp12',
1286
			'Export PKCS#12',
1287
			null,
1288
			'fa-solid fa-archive'
1289
		))->addClass('btn-primary');
1290
	}
1291

    
1292
	print $form;
1293

    
1294
} elseif ($act == "csr" || (($_POST['save'] == gettext("Update")) && $input_errors)) {
1295
	$form = new Form(false);
1296
	$form->setAction('system_certmanager.php?act=csr');
1297

    
1298
	$section = new Form_Section("Complete Signing Request for " . $pconfig['descr']);
1299

    
1300
	$section->addInput(new Form_Input(
1301
		'descr',
1302
		'*Descriptive name',
1303
		'text',
1304
		$pconfig['descr']
1305
	))->setHelp('The name of this entry as displayed in the GUI for reference.%s' .
1306
		'This name can contain spaces but it cannot contain any of the ' .
1307
		'following characters: %s', '<br/>', "?, >, <, &, /, \, \", '");
1308

    
1309
	$section->addInput(new Form_Textarea(
1310
		'csr',
1311
		'Signing request data',
1312
		$pconfig['csr']
1313
	))->setReadonly()
1314
	  ->setWidth(7)
1315
	  ->setHelp('Copy the certificate signing data from here and forward it to a certificate authority for signing.');
1316

    
1317
	$section->addInput(new Form_Textarea(
1318
		'cert',
1319
		'*Final certificate data',
1320
		$pconfig['cert']
1321
	))->setWidth(7)
1322
	  ->setHelp('Paste the certificate received from the certificate authority here.');
1323

    
1324
	if (isset($id) && $thiscert) {
1325
		$form->addGlobal(new Form_Input(
1326
			'id',
1327
			null,
1328
			'hidden',
1329
			$id
1330
		));
1331

    
1332
		$form->addGlobal(new Form_Input(
1333
			'act',
1334
			null,
1335
			'hidden',
1336
			'csr'
1337
		));
1338
	}
1339

    
1340
	$form->add($section);
1341

    
1342
	$form->addGlobal(new Form_Button(
1343
		'save',
1344
		'Update',
1345
		null,
1346
		'fa-solid fa-save'
1347
	))->addClass('btn-primary');
1348

    
1349
	print($form);
1350
} else {
1351
?>
1352
<div class="panel panel-default" id="search-panel">
1353
	<div class="panel-heading">
1354
		<h2 class="panel-title">
1355
			<?=gettext('Search')?>
1356
			<span class="widget-heading-icon pull-right">
1357
				<a data-toggle="collapse" href="#search-panel_panel-body">
1358
					<i class="fa-solid fa-plus-circle"></i>
1359
				</a>
1360
			</span>
1361
		</h2>
1362
	</div>
1363
	<div id="search-panel_panel-body" class="panel-body collapse in">
1364
		<div class="form-group">
1365
			<label class="col-sm-2 control-label">
1366
				<?=gettext("Search term")?>
1367
			</label>
1368
			<div class="col-sm-5"><input class="form-control" name="searchstr" id="searchstr" type="text"/></div>
1369
			<div class="col-sm-2">
1370
				<select id="where" class="form-control">
1371
					<option value="0"><?=gettext("Name")?></option>
1372
					<option value="1"><?=gettext("Distinguished Name")?></option>
1373
					<option value="2" selected><?=gettext("Both")?></option>
1374
				</select>
1375
			</div>
1376
			<div class="col-sm-3">
1377
				<a id="btnsearch" title="<?=gettext("Search")?>" class="btn btn-primary btn-sm"><i class="fa-solid fa-search icon-embed-btn"></i><?=gettext("Search")?></a>
1378
				<a id="btnclear" title="<?=gettext("Clear")?>" class="btn btn-info btn-sm"><i class="fa-solid fa-undo icon-embed-btn"></i><?=gettext("Clear")?></a>
1379
			</div>
1380
			<div class="col-sm-10 col-sm-offset-2">
1381
				<span class="help-block"><?=gettext('Enter a search string or *nix regular expression to search certificate names and distinguished names.')?></span>
1382
			</div>
1383
		</div>
1384
	</div>
1385
</div>
1386
<div class="panel panel-default">
1387
	<div class="panel-heading"><h2 class="panel-title"><?=gettext('Certificates')?></h2></div>
1388
	<div class="panel-body">
1389
		<div class="table-responsive">
1390
		<table class="table table-striped table-hover sortable-theme-bootstrap" data-sortable>
1391
			<thead>
1392
				<tr>
1393
					<th><?=gettext("Name")?></th>
1394
					<th><?=gettext("Issuer")?></th>
1395
					<th><?=gettext("Distinguished Name")?></th>
1396
					<th><?=gettext("In Use")?></th>
1397

    
1398
					<th class="col-sm-2"><?=gettext("Actions")?></th>
1399
				</tr>
1400
			</thead>
1401
			<tbody>
1402
<?php
1403

    
1404
$pluginparams = array();
1405
$pluginparams['type'] = 'certificates';
1406
$pluginparams['event'] = 'used_certificates';
1407
$certificates_used_by_packages = pkg_call_plugins('plugin_certificates', $pluginparams);
1408
foreach (config_get_path('cert', []) as $cert):
1409
	if (!is_array($cert) || empty($cert)) {
1410
		continue;
1411
	}
1412
	$name = htmlspecialchars($cert['descr']);
1413
	if ($cert['crt']) {
1414
		$subj = cert_get_subject($cert['crt']);
1415
		$issuer = cert_get_issuer($cert['crt']);
1416
		$purpose = cert_get_purpose($cert['crt']);
1417

    
1418
		if ($subj == $issuer) {
1419
			$caname = '<i>'. gettext("self-signed") .'</i>';
1420
		} else {
1421
			$caname = '<i>'. gettext("external").'</i>';
1422
		}
1423

    
1424
		$subj = htmlspecialchars(cert_escape_x509_chars($subj, true));
1425
	} else {
1426
		$subj = "";
1427
		$issuer = "";
1428
		$purpose = "";
1429
		$startdate = "";
1430
		$enddate = "";
1431
		$caname = "<em>" . gettext("private key only") . "</em>";
1432
	}
1433

    
1434
	if ($cert['csr']) {
1435
		$subj = htmlspecialchars(cert_escape_x509_chars(csr_get_subject($cert['csr']), true));
1436
		$caname = "<em>" . gettext("external - signature pending") . "</em>";
1437
	}
1438

    
1439
	$ca = lookup_ca($cert['caref']);
1440
	$ca = $ca['item'];
1441
	if ($ca) {
1442
		$caname = htmlspecialchars($ca['descr']);
1443
	}
1444
?>
1445
				<tr>
1446
					<td>
1447
						<?=$name?><br />
1448
						<?php if ($cert['type']): ?>
1449
							<i><?=$cert_types[$cert['type']]?></i><br />
1450
						<?php endif?>
1451
						<?php if (is_array($purpose)): ?>
1452
							CA: <b><?=$purpose['ca']?></b><br/>
1453
							<?=gettext("Server")?>: <b><?=$purpose['server']?></b><br/>
1454
						<?php endif?>
1455
					</td>
1456
					<td><?=$caname?></td>
1457
					<td>
1458
						<?=$subj?>
1459
						<?= cert_print_infoblock($cert); ?>
1460
						<?php cert_print_dates($cert);?>
1461
					</td>
1462
					<td>
1463
						<?php if (is_cert_revoked($cert)): ?>
1464
							<i><?=gettext("Revoked")?></i>
1465
						<?php endif?>
1466
						<?php if (is_webgui_cert($cert['refid'])): ?>
1467
							<?=gettext("webConfigurator")?>
1468
						<?php endif?>
1469
						<?php if (is_user_cert($cert['refid'])): ?>
1470
							<?=gettext("User Cert")?>
1471
						<?php endif?>
1472
						<?php if (is_openvpn_server_cert($cert['refid'])): ?>
1473
							<?=gettext("OpenVPN Server")?>
1474
						<?php endif?>
1475
						<?php if (is_openvpn_client_cert($cert['refid'])): ?>
1476
							<?=gettext("OpenVPN Client")?>
1477
						<?php endif?>
1478
						<?php if (is_ipsec_cert($cert['refid'])): ?>
1479
							<?=gettext("IPsec Tunnel")?>
1480
						<?php endif?>
1481
						<?php if (is_captiveportal_cert($cert['refid'])): ?>
1482
							<?=gettext("Captive Portal")?>
1483
						<?php endif?>
1484
						<?php if (is_unbound_cert($cert['refid'])): ?>
1485
							<?=gettext("DNS Resolver")?>
1486
						<?php endif?>
1487
						<?php echo cert_usedby_description($cert['refid'], $certificates_used_by_packages); ?>
1488
					</td>
1489
					<td>
1490
						<?php if (!$cert['csr']): ?>
1491
							<a href="system_certmanager.php?act=edit&amp;id=<?=$cert['refid']?>" class="fa-solid fa-pencil" title="<?=gettext("Edit Certificate")?>"></a>
1492
							<a href="system_certmanager.php?act=exp&amp;id=<?=$cert['refid']?>" class="fa-solid fa-certificate" title="<?=gettext("Export Certificate")?>"></a>
1493
							<?php if ($cert['prv']): ?>
1494
								<a href="system_certmanager.php?act=key&amp;id=<?=$cert['refid']?>" class="fa-solid fa-key" title="<?=gettext("Export Key")?>"></a>
1495
								<a href="system_certmanager.php?act=p12&amp;id=<?=$cert['refid']?>" class="fa-solid fa-archive" title="<?=gettext("Export PCKS#12 Archive without Encryption")?>"></a>
1496
							<?php endif?>
1497
							<?php if (is_cert_locally_renewable($cert)): ?>
1498
								<a href="system_certmanager_renew.php?type=cert&amp;refid=<?=$cert['refid']?>" class="fa-solid fa-arrow-rotate-right" title="<?=gettext("Reissue/Renew")?>"></a>
1499
							<?php endif ?>
1500
						<?php else: ?>
1501
							<a href="system_certmanager.php?act=csr&amp;id=<?=$cert['refid']?>" class="fa-solid fa-pencil" title="<?=gettext("Update CSR")?>"></a>
1502
							<a href="system_certmanager.php?act=req&amp;id=<?=$cert['refid']?>" class="fa-solid fa-right-to-bracket" title="<?=gettext("Export Request")?>"></a>
1503
							<a href="system_certmanager.php?act=key&amp;id=<?=$cert['refid']?>" class="fa-solid fa-key" title="<?=gettext("Export Key")?>"></a>
1504
						<?php endif?>
1505
						<?php if (!cert_in_use($cert['refid'])): ?>
1506
							<a href="system_certmanager.php?act=del&amp;id=<?=$cert['refid']?>" class="fa-solid fa-trash-can" title="<?=gettext("Delete Certificate")?>" usepost></a>
1507
						<?php endif?>
1508
					</td>
1509
				</tr>
1510
<?php
1511
	endforeach; ?>
1512
			</tbody>
1513
		</table>
1514
		</div>
1515
	</div>
1516
</div>
1517

    
1518
<nav class="action-buttons">
1519
	<a href="?act=new" class="btn btn-success btn-sm">
1520
		<i class="fa-solid fa-plus icon-embed-btn"></i>
1521
		<?=gettext("Add/Sign")?>
1522
	</a>
1523
</nav>
1524
<script type="text/javascript">
1525
//<![CDATA[
1526

    
1527
events.push(function() {
1528

    
1529
	// Make these controls plain buttons
1530
	$("#btnsearch").prop('type', 'button');
1531
	$("#btnclear").prop('type', 'button');
1532

    
1533
	// Search for a term in the entry name and/or dn
1534
	$("#btnsearch").click(function() {
1535
		var searchstr = $('#searchstr').val().toLowerCase();
1536
		var table = $("table tbody");
1537
		var where = $('#where').val();
1538

    
1539
		table.find('tr').each(function (i) {
1540
			var $tds = $(this).find('td'),
1541
				shortname = $tds.eq(0).text().trim().toLowerCase(),
1542
				dn = $tds.eq(2).text().trim().toLowerCase();
1543

    
1544
			regexp = new RegExp(searchstr);
1545
			if (searchstr.length > 0) {
1546
				if (!(regexp.test(shortname) && (where != 1)) && !(regexp.test(dn) && (where != 0))) {
1547
					$(this).hide();
1548
				} else {
1549
					$(this).show();
1550
				}
1551
			} else {
1552
				$(this).show();	// A blank search string shows all
1553
			}
1554
		});
1555
	});
1556

    
1557
	// Clear the search term and unhide all rows (that were hidden during a previous search)
1558
	$("#btnclear").click(function() {
1559
		var table = $("table tbody");
1560

    
1561
		$('#searchstr').val("");
1562

    
1563
		table.find('tr').each(function (i) {
1564
			$(this).show();
1565
		});
1566
	});
1567

    
1568
	// Hitting the enter key will do the same as clicking the search button
1569
	$("#searchstr").on("keyup", function (event) {
1570
		if (event.keyCode == 13) {
1571
			$("#btnsearch").get(0).click();
1572
		}
1573
	});
1574
});
1575
//]]>
1576
</script>
1577
<?php
1578
	include("foot.inc");
1579
	exit;
1580
}
1581

    
1582

    
1583
?>
1584
<script type="text/javascript">
1585
//<![CDATA[
1586
events.push(function() {
1587

    
1588
	$('.import_type_toggle').click(function() {
1589
		var x509 = (this.value === 'x509');
1590
		hideInput('cert', !x509);
1591
		setRequired('cert', x509);
1592
		hideInput('key', !x509);
1593
		setRequired('key', x509);
1594
		hideInput('pkcs12_cert', x509);
1595
		setRequired('pkcs12_cert', !x509);
1596
		hideInput('pkcs12_pass', x509);
1597
		hideCheckbox('pkcs12_intermediate', x509);
1598
	});
1599
	if ($('input[name=import_type]:checked').val() == 'x509') {
1600
		hideInput('pkcs12_cert', true);
1601
		setRequired('pkcs12_cert', false);
1602
		hideInput('pkcs12_pass', true);
1603
		hideCheckbox('pkcs12_intermediate', true);
1604
		hideInput('cert', false);
1605
		setRequired('cert', true);
1606
		hideInput('key', false);
1607
		setRequired('key', true);
1608
	} else if ($('input[name=import_type]:checked').val() == 'pkcs12') {
1609
		hideInput('cert', true);
1610
		setRequired('cert', false);
1611
		hideInput('key', true);
1612
		setRequired('key', false);
1613
		setRequired('pkcs12_cert', false);
1614
	}
1615

    
1616
<?php if ($internal_ca_count): ?>
1617
	function internalca_change() {
1618

    
1619
		caref = $('#caref').val();
1620

    
1621
		switch (caref) {
1622
<?php
1623
			foreach (config_get_path('ca', []) as $ca):
1624
				if (!$ca['prv']) {
1625
					continue;
1626
				}
1627

    
1628
				$subject = @cert_get_subject_hash($ca['crt']);
1629
				if (!is_array($subject) || empty($subject)) {
1630
					continue;
1631
				}
1632
?>
1633
				case "<?=$ca['refid'];?>":
1634
					$('#dn_country').val(<?=json_encode(cert_escape_x509_chars($subject['C'], true));?>);
1635
					$('#dn_state').val(<?=json_encode(cert_escape_x509_chars($subject['ST'], true));?>);
1636
					$('#dn_city').val(<?=json_encode(cert_escape_x509_chars($subject['L'], true));?>);
1637
					$('#dn_organization').val(<?=json_encode(cert_escape_x509_chars($subject['O'], true));?>);
1638
					$('#dn_organizationalunit').val(<?=json_encode(cert_escape_x509_chars($subject['OU'], true));?>);
1639
					break;
1640
<?php
1641
			endforeach;
1642
?>
1643
		}
1644
	}
1645

    
1646
	function set_csr_ro() {
1647
		var newcsr = ($('#csrtosign').val() == "new");
1648

    
1649
		$('#csrpaste').attr('readonly', !newcsr);
1650
		$('#keypaste').attr('readonly', !newcsr);
1651
		setRequired('csrpaste', newcsr);
1652
	}
1653

    
1654
	function check_lifetime() {
1655
		var maxserverlife = <?= $cert_strict_values['max_server_cert_lifetime'] ?>;
1656
		var ltid = '#lifetime';
1657
		if ($('#method').val() == "sign") {
1658
			ltid = '#csrsign_lifetime';
1659
		}
1660
		if (($('#type').val() == "server") && (parseInt($(ltid).val()) > maxserverlife)) {
1661
			$(ltid).parent().parent().removeClass("text-normal").addClass("text-warning");
1662
			$(ltid).removeClass("text-normal").addClass("text-warning");
1663
		} else {
1664
			$(ltid).parent().parent().removeClass("text-warning").addClass("text-normal");
1665
			$(ltid).removeClass("text-warning").addClass("text-normal");
1666
		}
1667
	}
1668
	function check_keylen() {
1669
		var min_keylen = <?= $cert_strict_values['min_private_key_bits'] ?>;
1670
		var klid = '#keylen';
1671
		if ($('#method').val() == "external") {
1672
			klid = '#csr_keylen';
1673
		}
1674
		/* Color the Parent/Label */
1675
		if (parseInt($(klid).val()) < min_keylen) {
1676
			$(klid).parent().parent().removeClass("text-normal").addClass("text-warning");
1677
		} else {
1678
			$(klid).parent().parent().removeClass("text-warning").addClass("text-normal");
1679
		}
1680
		/* Color individual options */
1681
		$(klid + " option").filter(function() {
1682
			return parseInt($(this).val()) < min_keylen;
1683
		}).removeClass("text-normal").addClass("text-warning").siblings().removeClass("text-warning").addClass("text-normal");
1684
	}
1685

    
1686
	function check_digest() {
1687
		var weak_algs = <?= json_encode($cert_strict_values['digest_blacklist']) ?>;
1688
		var daid = '#digest_alg';
1689
		if ($('#method').val() == "external") {
1690
			daid = '#csr_digest_alg';
1691
		} else if ($('#method').val() == "sign") {
1692
			daid = '#csrsign_digest_alg';
1693
		}
1694
		/* Color the Parent/Label */
1695
		if (jQuery.inArray($(daid).val(), weak_algs) > -1) {
1696
			$(daid).parent().parent().removeClass("text-normal").addClass("text-warning");
1697
		} else {
1698
			$(daid).parent().parent().removeClass("text-warning").addClass("text-normal");
1699
		}
1700
		/* Color individual options */
1701
		$(daid + " option").filter(function() {
1702
			return (jQuery.inArray($(this).val(), weak_algs) > -1);
1703
		}).removeClass("text-normal").addClass("text-warning").siblings().removeClass("text-warning").addClass("text-normal");
1704
	}
1705

    
1706
	// ---------- Click checkbox handlers ---------------------------------------------------------
1707

    
1708
	$('#type').on('change', function() {
1709
		check_lifetime();
1710
	});
1711
	$('#method').on('change', function() {
1712
		check_lifetime();
1713
		check_keylen();
1714
		check_digest();
1715
	});
1716
	$('#lifetime').on('change', function() {
1717
		check_lifetime();
1718
	});
1719
	$('#csrsign_lifetime').on('change', function() {
1720
		check_lifetime();
1721
	});
1722

    
1723
	$('#keylen').on('change', function() {
1724
		check_keylen();
1725
	});
1726
	$('#csr_keylen').on('change', function() {
1727
		check_keylen();
1728
	});
1729

    
1730
	$('#digest_alg').on('change', function() {
1731
		check_digest();
1732
	});
1733
	$('#csr_digest_alg').on('change', function() {
1734
		check_digest();
1735
	});
1736

    
1737
	$('#caref').on('change', function() {
1738
		internalca_change();
1739
	});
1740

    
1741
	$('#csrtosign').change(function () {
1742
		set_csr_ro();
1743
	});
1744

    
1745
	function change_keytype() {
1746
		hideClass('rsakeys', ($('#keytype').val() != 'RSA'));
1747
		hideClass('ecnames', ($('#keytype').val() != 'ECDSA'));
1748
	}
1749

    
1750
	$('#keytype').change(function () {
1751
		change_keytype();
1752
	});
1753

    
1754
	function change_csrkeytype() {
1755
		hideClass('csr_rsakeys', ($('#csr_keytype').val() != 'RSA'));
1756
		hideClass('csr_ecnames', ($('#csr_keytype').val() != 'ECDSA'));
1757
	}
1758

    
1759
	$('#csr_keytype').change(function () {
1760
		change_csrkeytype();
1761
	});
1762

    
1763
	// ---------- On initial page load ------------------------------------------------------------
1764

    
1765
	internalca_change();
1766
	set_csr_ro();
1767
	change_keytype();
1768
	change_csrkeytype();
1769
	check_lifetime();
1770
	check_keylen();
1771
	check_digest();
1772

    
1773
	// Suppress "Delete row" button if there are fewer than two rows
1774
	checkLastRow();
1775

    
1776

    
1777
<?php endif; ?>
1778

    
1779

    
1780
});
1781
//]]>
1782
</script>
1783
<?php
1784
include('foot.inc');
(195-195/230)