1
|
<?php
|
2
|
/*
|
3
|
system_usermanager_addcert.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_manager
|
31
|
*/
|
32
|
|
33
|
##|+PRIV
|
34
|
##|*IDENT=page-system-usermanager_addcert
|
35
|
##|*NAME=System: User Manager: Add Certificate
|
36
|
##|*DESCR=Allow access to the 'User Manager: Add Certificate' page.
|
37
|
##|*MATCH=system_usermanager_addcert.php*
|
38
|
##|-PRIV
|
39
|
|
40
|
require("guiconfig.inc");
|
41
|
require("certs.inc");
|
42
|
|
43
|
$cert_keylens = array( "512", "1024", "2048", "4096");
|
44
|
|
45
|
$pgtitle = array(gettext("System"), gettext("User Manager: Add Certificate"));
|
46
|
|
47
|
$userid = $_GET['userid'];
|
48
|
if (isset($_POST['userid']))
|
49
|
$userid = $_POST['userid'];
|
50
|
|
51
|
if (!is_array($config['system']['user']))
|
52
|
$config['system']['user'] = array();
|
53
|
|
54
|
$a_user =& $config['system']['user'];
|
55
|
|
56
|
if (!is_array($config['ca']))
|
57
|
$config['ca'] = array();
|
58
|
|
59
|
$a_ca =& $config['ca'];
|
60
|
|
61
|
$internal_ca_count = 0;
|
62
|
foreach ($a_ca as $ca)
|
63
|
if ($ca['prv'])
|
64
|
$internal_ca_count++;
|
65
|
|
66
|
if ($_GET) {
|
67
|
$pconfig['keylen'] = "2048";
|
68
|
$pconfig['lifetime'] = "3650";
|
69
|
}
|
70
|
|
71
|
if ($_POST) {
|
72
|
conf_mount_rw();
|
73
|
|
74
|
unset($input_errors);
|
75
|
$pconfig = $_POST;
|
76
|
|
77
|
/* input validation */
|
78
|
if ($pconfig['method'] == "existing") {
|
79
|
$reqdfields = explode(" ",
|
80
|
"name cert key");
|
81
|
$reqdfieldsn = array(
|
82
|
gettext("Descriptive name"),
|
83
|
gettext("Certificate data"),
|
84
|
gettext("Key data"));
|
85
|
}
|
86
|
|
87
|
if ($pconfig['method'] == "internal") {
|
88
|
$reqdfields = explode(" ",
|
89
|
"name caref keylen lifetime");
|
90
|
$reqdfieldsn = array(
|
91
|
gettext("Descriptive name"),
|
92
|
gettext("Certificate authority"),
|
93
|
gettext("Key length"),
|
94
|
gettext("Lifetime"));
|
95
|
}
|
96
|
|
97
|
do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
|
98
|
|
99
|
$ca = lookup_ca($pconfig['caref']);
|
100
|
if (!$ca)
|
101
|
$input_errors[] = sprintf(gettext("Invalid internal Certificate Authority%s"),"\n");
|
102
|
|
103
|
/* if this is an AJAX caller then handle via JSON */
|
104
|
if (isAjax() && is_array($input_errors)) {
|
105
|
input_errors2Ajax($input_errors);
|
106
|
conf_mount_ro();
|
107
|
exit;
|
108
|
}
|
109
|
|
110
|
/* save modifications */
|
111
|
if (!$input_errors) {
|
112
|
|
113
|
$cert = array();
|
114
|
$cert['refid'] = uniqid();
|
115
|
if (!is_array($a_user[$userid]['cert']))
|
116
|
$a_user[$userid]['cert'] = array();
|
117
|
|
118
|
$cert['name'] = $pconfig['name'];
|
119
|
|
120
|
$subject = cert_get_subject_array($ca['crt']);
|
121
|
|
122
|
$dn = array(
|
123
|
'countryName' => $subject[0]['v'],
|
124
|
'stateOrProvinceName' => $subject[1]['v'],
|
125
|
'localityName' => $subject[2]['v'],
|
126
|
'organizationName' => $subject[3]['v'],
|
127
|
'emailAddress' => $subject[4]['v'],
|
128
|
'commonName' => $a_user[$userid]['name']);
|
129
|
|
130
|
cert_create($cert, $pconfig['caref'], $pconfig['keylen'],
|
131
|
$pconfig['lifetime'], $dn);
|
132
|
|
133
|
if (!is_array($config['cert']))
|
134
|
$config['cert'] = array();
|
135
|
$config['cert'][] = $cert;
|
136
|
$a_user[$userid]['cert'][] = $cert['refid'];
|
137
|
|
138
|
write_config();
|
139
|
|
140
|
conf_mount_ro();
|
141
|
|
142
|
pfSenseHeader("system_usermanager.php?act=edit&id={$userid}");
|
143
|
}
|
144
|
}
|
145
|
|
146
|
include("head.inc");
|
147
|
?>
|
148
|
|
149
|
<body link="#000000" vlink="#000000" alink="#000000" onload="<?= $jsevents["body"]["onload"] ?>">
|
150
|
<?php include("fbegin.inc"); ?>
|
151
|
<script type="text/javascript">
|
152
|
<!--
|
153
|
|
154
|
<?php if ($internal_ca_count): ?>
|
155
|
function internalca_change() {
|
156
|
|
157
|
index = document.iform.caref.selectedIndex;
|
158
|
caref = document.iform.caref[index].value;
|
159
|
|
160
|
switch (caref) {
|
161
|
<?php
|
162
|
foreach ($a_ca as $ca):
|
163
|
if (!$ca['prv'])
|
164
|
continue;
|
165
|
$subject = cert_get_subject_array($ca['crt']);
|
166
|
?>
|
167
|
case "<?=$ca['refid'];?>":
|
168
|
document.iform.dn_country.value = "<?=$subject[0]['v'];?>";
|
169
|
document.iform.dn_state.value = "<?=$subject[1]['v'];?>";
|
170
|
document.iform.dn_city.value = "<?=$subject[2]['v'];?>";
|
171
|
document.iform.dn_organization.value = "<?=$subject[3]['v'];?>";
|
172
|
break;
|
173
|
<?php endforeach; ?>
|
174
|
}
|
175
|
}
|
176
|
<?php endif; ?>
|
177
|
|
178
|
//-->
|
179
|
</script>
|
180
|
<?php
|
181
|
if ($input_errors)
|
182
|
print_input_errors($input_errors);
|
183
|
if ($savemsg)
|
184
|
print_info_box($savemsg);
|
185
|
?>
|
186
|
<table width="100%" border="0" cellpadding="0" cellspacing="0">
|
187
|
<tr>
|
188
|
<td>
|
189
|
<?php
|
190
|
$tab_array = array();
|
191
|
$tab_array[] = array(gettext("Users"), true, "system_usermanager.php");
|
192
|
$tab_array[] = array(gettext("Groups"), false, "system_groupmanager.php");
|
193
|
$tab_array[] = array(gettext("Settings"), false, "system_usermanager_settings.php");
|
194
|
$tab_array[] = array(gettext("Servers"), false, "system_authservers.php");
|
195
|
display_top_tabs($tab_array);
|
196
|
?>
|
197
|
</td>
|
198
|
</tr>
|
199
|
<tr>
|
200
|
<td id="mainarea">
|
201
|
<div class="tabcont">
|
202
|
<form action="system_usermanager_addcert.php" method="post" name="iform" id="iform">
|
203
|
<table width="100%" border="0" cellpadding="6" cellspacing="0">
|
204
|
|
205
|
<?php if (!$internal_ca_count): ?>
|
206
|
|
207
|
<tr>
|
208
|
<td colspan="2" align="center" class="vtable">
|
209
|
<?=gettext("No internal Certificate Authorities have been defined. You must");?>
|
210
|
<a href="system_camanager.php?act=new&method=internal"><?=gettext("create");?></a>
|
211
|
<?=gettext("an internal CA before creating an internal certificate.");?>
|
212
|
</td>
|
213
|
</tr>
|
214
|
|
215
|
<?php else: ?>
|
216
|
|
217
|
<tr>
|
218
|
<td width="22%" valign="top" class="vncellreq"><?=gettext("Descriptive name");?></td>
|
219
|
<td width="78%" class="vtable">
|
220
|
<input name="name" type="text" class="formfld unknown" id="name" size="20" value="<?=htmlspecialchars($pconfig['name']);?>"/>
|
221
|
</td>
|
222
|
</tr>
|
223
|
<tr>
|
224
|
<td width="22%" valign="top" class="vncellreq"><?=gettext("Certificate authority");?></td>
|
225
|
<td width="78%" class="vtable">
|
226
|
<select name='caref' id='caref' class="formselect" onChange='internalca_change()'>
|
227
|
<?php
|
228
|
foreach( $a_ca as $ca):
|
229
|
if (!$ca['prv'])
|
230
|
continue;
|
231
|
$selected = "";
|
232
|
if ($pconfig['caref'] == $ca['refid'])
|
233
|
$selected = "selected";
|
234
|
?>
|
235
|
<option value="<?=$ca['refid'];?>"<?=$selected;?>><?=$ca['name'];?></option>
|
236
|
<?php endforeach; ?>
|
237
|
</select>
|
238
|
</td>
|
239
|
</tr>
|
240
|
<tr>
|
241
|
<td width="22%" valign="top" class="vncellreq"><?=gettext("Key length");?></td>
|
242
|
<td width="78%" class="vtable">
|
243
|
<select name='keylen' class="formselect">
|
244
|
<?php
|
245
|
foreach( $cert_keylens as $len):
|
246
|
$selected = "";
|
247
|
if ($pconfig['keylen'] == $len)
|
248
|
$selected = "selected";
|
249
|
?>
|
250
|
<option value="<?=$len;?>"<?=$selected;?>><?=$len;?></option>
|
251
|
<?php endforeach; ?>
|
252
|
</select>
|
253
|
<?=gettext("bits");?>
|
254
|
</td>
|
255
|
</tr>
|
256
|
<tr>
|
257
|
<td width="22%" valign="top" class="vncellreq"><?=gettext("Lifetime");?></td>
|
258
|
<td width="78%" class="vtable">
|
259
|
<input name="lifetime" type="text" class="formfld unknown" id="lifetime" size="5" value="<?=htmlspecialchars($pconfig['lifetime']);?>"/>
|
260
|
<?=gettext("days");?>
|
261
|
</td>
|
262
|
</tr>
|
263
|
|
264
|
<?php endif; ?>
|
265
|
|
266
|
<tr>
|
267
|
<td width="22%" valign="top"> </td>
|
268
|
<td width="78%">
|
269
|
<?php if ($internal_ca_count): ?>
|
270
|
<input id="submit" name="save" type="submit" class="formbtn" value="<?=gettext("Save");?>" />
|
271
|
<input id="cancelbutton" class="formbtn" type="button" value="<?=gettext("Cancel");?>" onclick="history.back()" />
|
272
|
<?php endif; ?>
|
273
|
<?php if (isset($userid) && $a_user[$userid]): ?>
|
274
|
<input name="userid" type="hidden" value="<?=$userid;?>" />
|
275
|
<?php endif;?>
|
276
|
</td>
|
277
|
</tr>
|
278
|
</table>
|
279
|
</form>
|
280
|
</div>
|
281
|
</td>
|
282
|
</tr>
|
283
|
</table>
|
284
|
<?php include("fend.inc");?>
|
285
|
<script type="text/javascript">
|
286
|
<!--
|
287
|
|
288
|
internalca_change();
|
289
|
|
290
|
//-->
|
291
|
</script>
|
292
|
|
293
|
</body>
|