author | Dan |
Thu, 19 Mar 2009 09:27:52 -0400 | |
changeset 15 | c479ca761d29 |
parent 8 | 032ca892b9a2 |
child 32 | b00055a88867 |
permissions | -rw-r--r-- |
0 | 1 |
<?php |
2 |
||
3
d0fe7acaf0e8
Maybe we could actually make yubikey_enable in config not ignored!
Dan
parents:
0
diff
changeset
|
3 |
if ( getConfig('yubikey_enable', '1') != '1' ) |
d0fe7acaf0e8
Maybe we could actually make yubikey_enable in config not ignored!
Dan
parents:
0
diff
changeset
|
4 |
return true; |
d0fe7acaf0e8
Maybe we could actually make yubikey_enable in config not ignored!
Dan
parents:
0
diff
changeset
|
5 |
|
0 | 6 |
$plugins->attachHook("userprefs_jbox", "yubikey_ucp_setup();"); |
7 |
$plugins->attachHook("userprefs_body", "return yubikey_user_cp(\$section);"); |
|
8 |
$plugins->attachHook("login_form_html", "yubikey_inject_html_login();"); |
|
8
032ca892b9a2
Added option to enroll Yubikey during registration + option in admin CP to require enrollment
Dan
parents:
3
diff
changeset
|
9 |
$plugins->attachHook("ucp_register_form", "yubikey_inject_registration_form();"); |
032ca892b9a2
Added option to enroll Yubikey during registration + option in admin CP to require enrollment
Dan
parents:
3
diff
changeset
|
10 |
$plugins->attachHook("ucp_register_validate", "yubikey_register_validate(\$error);"); |
032ca892b9a2
Added option to enroll Yubikey during registration + option in admin CP to require enrollment
Dan
parents:
3
diff
changeset
|
11 |
$plugins->attachHook("user_registered", "yubikey_register_insert_key(\$user_id);"); |
0 | 12 |
|
13 |
function yubikey_ucp_setup() |
|
14 |
{ |
|
15
c479ca761d29
Yubikey user CP now requires re-auth to CHPREF. Didn't win YubiKing :-(
Dan
parents:
8
diff
changeset
|
15 |
userprefs_menu_add('usercp_sec_profile', 'yubiucp_panel_title', makeUrlNS('Special', 'Preferences/Yubikey') . '" onclick="ajaxLoginNavTo(\'Special\', \'Preferences/Yubikey\', '.USER_LEVEL_CHPREF.'); return false;'); |
0 | 16 |
} |
17 |
||
18 |
function yubikey_user_cp($section) |
|
19 |
{ |
|
20 |
global $db, $session, $paths, $template, $plugins; // Common objects |
|
21 |
global $lang; |
|
22 |
||
23 |
if ( $section !== 'Yubikey' ) |
|
24 |
return false; |
|
25 |
||
15
c479ca761d29
Yubikey user CP now requires re-auth to CHPREF. Didn't win YubiKing :-(
Dan
parents:
8
diff
changeset
|
26 |
if ( $session->auth_level < USER_LEVEL_CHPREF ) |
c479ca761d29
Yubikey user CP now requires re-auth to CHPREF. Didn't win YubiKing :-(
Dan
parents:
8
diff
changeset
|
27 |
{ |
c479ca761d29
Yubikey user CP now requires re-auth to CHPREF. Didn't win YubiKing :-(
Dan
parents:
8
diff
changeset
|
28 |
redirect(makeUrlNS('Special', 'Login/' . $paths->fullpage, 'level=' . USER_LEVEL_CHPREF, true), 'Authentication required', 'You need to re-authenticate to access this page.', 0); |
c479ca761d29
Yubikey user CP now requires re-auth to CHPREF. Didn't win YubiKing :-(
Dan
parents:
8
diff
changeset
|
29 |
} |
c479ca761d29
Yubikey user CP now requires re-auth to CHPREF. Didn't win YubiKing :-(
Dan
parents:
8
diff
changeset
|
30 |
|
0 | 31 |
$count_enabled = intval(getConfig('yubikey_enroll_limit', '3')); |
32 |
||
33 |
if ( isset($_POST['submit']) ) |
|
34 |
{ |
|
35 |
csrf_request_confirm(); |
|
36 |
||
37 |
$keys = array(); |
|
38 |
if ( isset($_POST['yubikey_enable']) ) |
|
39 |
{ |
|
40 |
for ( $i = 0; $i < $count_enabled; $i++ ) |
|
41 |
{ |
|
42 |
if ( !empty($_POST["yubikey_otp_$i"]) ) |
|
43 |
{ |
|
44 |
$ckey =& $_POST["yubikey_otp_$i"]; |
|
45 |
if ( preg_match('/^[cbdefghijklnrtuv]{12,44}$/', $ckey) ) |
|
46 |
{ |
|
47 |
$ckey = substr($ckey, 0, 12); |
|
48 |
$keys[] = $ckey; |
|
49 |
} |
|
50 |
unset($ckey); |
|
51 |
} |
|
52 |
} |
|
53 |
} |
|
54 |
// Check for double enrollment |
|
55 |
$keys_check = "yubi_uid = '" . implode("' OR yubi_uid = '", $keys) . "'"; |
|
56 |
$q = $db->sql_query('SELECT yubi_uid FROM ' . table_prefix . "yubikey WHERE ( $keys_check ) AND user_id != {$session->user_id};"); |
|
57 |
if ( !$q ) |
|
58 |
$db->_die(); |
|
59 |
||
60 |
if ( $db->numrows() > 0 ) |
|
61 |
{ |
|
62 |
echo '<div class="error-box" style="margin: 0 0 10px 0;">' . $lang->get('yubiucp_err_double_enrollment') . '</div>'; |
|
63 |
while ( $row = $db->fetchrow() ) |
|
64 |
{ |
|
65 |
foreach ( $keys as $i => $key ) |
|
66 |
{ |
|
67 |
if ( $key == $row['yubi_uid'] ) |
|
68 |
{ |
|
69 |
unset($keys[$i]); |
|
70 |
} |
|
71 |
} |
|
72 |
} |
|
73 |
$keys = array_values($keys); |
|
74 |
} |
|
75 |
$db->free_result(); |
|
76 |
||
77 |
// Remove all currently registered keys |
|
78 |
$q = $db->sql_query('DELETE FROM ' . table_prefix . "yubikey WHERE user_id = {$session->user_id};"); |
|
79 |
if ( !$q ) |
|
80 |
$db->_die(); |
|
81 |
||
82 |
// Enroll any new keys |
|
83 |
if ( !empty($keys) ) |
|
84 |
{ |
|
85 |
$query = 'INSERT INTO ' . table_prefix . "yubikey(user_id, yubi_uid) VALUES\n " . |
|
86 |
"( $session->user_id, '" . implode("' ),\n ( $session->user_id, '", $keys) . "' );"; |
|
87 |
if ( !$db->sql_query($query) ) |
|
88 |
$db->_die(); |
|
89 |
} |
|
90 |
||
91 |
// Calculate flags |
|
92 |
$yubi_flags = 0; |
|
93 |
$yubi_flags |= intval($_POST['login_normal_flags']); |
|
94 |
$yubi_flags |= intval($_POST['login_elev_flags']); |
|
95 |
$yubi_flags |= ( isset($_POST['allow_no_yubikey']) ) ? YK_SEC_ALLOW_NO_OTP : 0; |
|
96 |
||
97 |
// update flags |
|
98 |
$q = $db->sql_query('UPDATE ' . table_prefix . "users SET user_yubikey_flags = $yubi_flags WHERE user_id = {$session->user_id};"); |
|
99 |
if ( !$q ) |
|
100 |
$db->_die(); |
|
101 |
} |
|
102 |
else |
|
103 |
{ |
|
104 |
// Fetch flags |
|
105 |
$q = $db->sql_query('SELECT user_yubikey_flags FROM ' . table_prefix . "users WHERE user_id = {$session->user_id};"); |
|
106 |
if ( !$q ) |
|
107 |
$db->_die(); |
|
108 |
||
109 |
list($yubi_flags) = $db->fetchrow_num(); |
|
110 |
$yubi_flags = intval($yubi_flags); |
|
111 |
// Fetch user's authorized keys from the DB |
|
112 |
$q = $db->sql_query('SELECT yubi_uid FROM ' . table_prefix . "yubikey WHERE user_id = {$session->user_id};"); |
|
113 |
if ( !$q ) |
|
114 |
$db->_die(); |
|
115 |
||
116 |
$keys = array(); |
|
117 |
while ( $row = $db->fetchrow() ) |
|
118 |
{ |
|
119 |
$keys[] = $row['yubi_uid']; |
|
120 |
} |
|
121 |
$db->free_result(); |
|
122 |
} |
|
123 |
||
124 |
while ( count($keys) < $count_enabled ) |
|
125 |
{ |
|
126 |
$keys[] = false; |
|
127 |
} |
|
128 |
||
129 |
$enable_checked = ( $keys[0] === false && !isset($_POST['yubikey_enable']) ) ? '' : 'checked="checked"'; |
|
130 |
$displaytable = ( $keys[0] === false && !isset($_POST['yubikey_enable']) ) ? 'none' : 'block'; |
|
131 |
||
132 |
$check_normal_keyonly = ( !($yubi_flags & YK_SEC_NORMAL_USERNAME) && !($yubi_flags & YK_SEC_NORMAL_PASSWORD) ) ? 'checked="checked" ' : ''; |
|
133 |
$check_normal_username = ( ($yubi_flags & YK_SEC_NORMAL_USERNAME) && !($yubi_flags & YK_SEC_NORMAL_PASSWORD) ) ? 'checked="checked" ' : ''; |
|
134 |
$check_normal_userandpw = ( ($yubi_flags & YK_SEC_NORMAL_USERNAME) && ($yubi_flags & YK_SEC_NORMAL_PASSWORD) ) ? 'checked="checked" ' : ''; |
|
135 |
||
136 |
$check_elev_keyonly = ( !($yubi_flags & YK_SEC_ELEV_USERNAME) && !($yubi_flags & YK_SEC_ELEV_PASSWORD) ) ? 'checked="checked" ' : ''; |
|
137 |
$check_elev_username = ( ($yubi_flags & YK_SEC_ELEV_USERNAME) && !($yubi_flags & YK_SEC_ELEV_PASSWORD) ) ? 'checked="checked" ' : ''; |
|
138 |
$check_elev_userandpw = ( ($yubi_flags & YK_SEC_ELEV_USERNAME) && ($yubi_flags & YK_SEC_ELEV_PASSWORD) ) ? 'checked="checked" ' : ''; |
|
139 |
||
140 |
?> |
|
141 |
<h3 style="margin-top: 0;"><?php echo $lang->get('yubiucp_panel_title'); ?></h3> |
|
142 |
||
143 |
<form action="<?php echo makeUrlNS('Special', 'Preferences/Yubikey'); ?>" method="post"> |
|
144 |
||
145 |
<div> |
|
146 |
<table border="0" cellpadding="4" width="100%"> |
|
147 |
<tr> |
|
148 |
<td style="width: 50%; text-align: right;"> |
|
149 |
<?php echo $lang->get('yubiucp_field_enable_title'); ?><br /> |
|
150 |
<small><?php echo $lang->get('yubiucp_field_enable_hint'); ?></small> |
|
151 |
</td> |
|
152 |
<td style="width: 50%;"> |
|
153 |
<label> |
|
154 |
<input type="checkbox" name="yubikey_enable" onclick="if ( $(this).attr('checked') ) $('#yk_useroptions').show('blind'); else $('#yk_useroptions').hide('blind');" <?php echo $enable_checked; ?> /> |
|
155 |
<?php echo $lang->get('yubiucp_field_enable'); ?> |
|
156 |
</label> |
|
157 |
</td> |
|
158 |
</tr> |
|
159 |
</table> |
|
160 |
<table border="0" cellpadding="4" width="100%" id="yk_useroptions" style="display: <?php echo $displaytable ?>;"> |
|
161 |
<tr class="yk_alt1"> |
|
162 |
<td style="width: 50%; text-align: right;"> |
|
163 |
<?php echo $lang->get('yubiucp_field_keys_title'); ?><br /> |
|
164 |
<small><?php |
|
165 |
echo $lang->get('yubiucp_field_keys_hint'); |
|
166 |
if ( $count_enabled > 1 ) |
|
167 |
{ |
|
168 |
echo ' '; |
|
169 |
echo $lang->get('yubiucp_field_keys_maximum', array('max' => $count_enabled)); |
|
170 |
} |
|
171 |
?></small> |
|
172 |
</td> |
|
173 |
<td style="width: 50%;"> |
|
174 |
<?php |
|
175 |
for ( $i = 0; $i < $count_enabled; $i++ ) |
|
176 |
{ |
|
177 |
echo '<p>' . generate_yubikey_field('yubikey_otp_' . $i, $keys[$i]) . '</p>'; |
|
178 |
} |
|
179 |
?> |
|
180 |
</td> |
|
181 |
</tr> |
|
182 |
<tr> |
|
183 |
<td style="width: 50%; text-align: right;"> |
|
184 |
<?php echo $lang->get('yubiucp_field_normal_flags'); ?> |
|
185 |
</td> |
|
186 |
<td> |
|
187 |
<label> |
|
188 |
<input type="radio" name="login_normal_flags" value="0" <?php echo $check_normal_keyonly; ?>/> |
|
189 |
<?php echo $lang->get('yubiucp_field_flags_keyonly'); ?> |
|
190 |
</label> |
|
191 |
||
192 |
<br /> |
|
193 |
||
194 |
<label> |
|
195 |
<input type="radio" name="login_normal_flags" value="<?php echo strval(YK_SEC_NORMAL_USERNAME); ?>" <?php echo $check_normal_username; ?>/> |
|
196 |
<?php echo $lang->get('yubiucp_field_flags_username'); ?> |
|
197 |
</label> |
|
198 |
||
199 |
<br /> |
|
200 |
||
201 |
<label> |
|
202 |
<input type="radio" name="login_normal_flags" value="<?php echo strval(YK_SEC_NORMAL_USERNAME | YK_SEC_NORMAL_PASSWORD); ?>" <?php echo $check_normal_userandpw; ?>/> |
|
203 |
<?php echo $lang->get('yubiucp_field_flags_userandpw'); ?> |
|
204 |
</label> |
|
205 |
</td> |
|
206 |
</tr> |
|
207 |
<tr class="yk_alt1"> |
|
208 |
<td style="width: 50%; text-align: right;"> |
|
209 |
<?php echo $lang->get('yubiucp_field_elev_flags'); ?> |
|
210 |
</td> |
|
211 |
<td> |
|
212 |
<label> |
|
213 |
<input type="radio" name="login_elev_flags" value="0" <?php echo $check_elev_keyonly; ?>/> |
|
214 |
<?php echo $lang->get('yubiucp_field_flags_keyonly'); ?> |
|
215 |
</label> |
|
216 |
||
217 |
<br /> |
|
218 |
||
219 |
<label> |
|
220 |
<input type="radio" name="login_elev_flags" value="<?php echo strval(YK_SEC_ELEV_USERNAME); ?>" <?php echo $check_elev_username; ?>/> |
|
221 |
<?php echo $lang->get('yubiucp_field_flags_username'); ?> |
|
222 |
</label> |
|
223 |
||
224 |
<br /> |
|
225 |
||
226 |
<label> |
|
227 |
<input type="radio" name="login_elev_flags" value="<?php echo strval(YK_SEC_ELEV_USERNAME | YK_SEC_ELEV_PASSWORD); ?>" <?php echo $check_elev_userandpw; ?>/> |
|
228 |
<?php echo $lang->get('yubiucp_field_flags_userandpw'); ?> |
|
229 |
</label> |
|
230 |
</td> |
|
231 |
</tr> |
|
232 |
<tr> |
|
233 |
<td> |
|
234 |
</td> |
|
235 |
<td> |
|
236 |
<label> |
|
237 |
<input type="checkbox" name="allow_no_yubikey" <?php if ( $yubi_flags & YK_SEC_ALLOW_NO_OTP ) echo 'checked="checked" '; ?>/> |
|
238 |
<?php echo $lang->get('yubiucp_field_allow_plain_login'); ?> |
|
239 |
</label> |
|
240 |
<br /> |
|
241 |
<small> |
|
242 |
<?php echo $lang->get('yubiucp_field_allow_plain_login_hint'); ?> |
|
243 |
</small> |
|
244 |
</td> |
|
245 |
</tr> |
|
246 |
</table> |
|
247 |
<table border="0" cellpadding="4" width="100%"> |
|
248 |
<tr class="yk_alt1"> |
|
249 |
<td colspan="2" style="text-align: center;"> |
|
250 |
<input type="submit" name="submit" value="<?php echo $lang->get('etc_save_changes'); ?>" /> |
|
251 |
</td> |
|
252 |
</tr> |
|
253 |
</table> |
|
254 |
</div> |
|
255 |
||
256 |
<input type="hidden" name="cstok" value="<?php echo $session->csrf_token; ?>" /> |
|
257 |
||
258 |
</form> |
|
259 |
<?php |
|
260 |
||
261 |
return true; |
|
262 |
} |
|
263 |
||
264 |
function yubikey_inject_html_login() |
|
265 |
{ |
|
266 |
global $lang; |
|
267 |
?> |
|
268 |
<tr> |
|
269 |
<td class="row2"> |
|
270 |
<?php echo $lang->get('yubiauth_lbl_otp_field'); ?> |
|
271 |
</td> |
|
272 |
<td class="row1" colspan="2"> |
|
273 |
<input type="text" size="40" class="yubikey_noscript" name="yubikey_otp" /> |
|
274 |
</td> |
|
275 |
</tr> |
|
276 |
<?php |
|
277 |
} |
|
278 |
||
8
032ca892b9a2
Added option to enroll Yubikey during registration + option in admin CP to require enrollment
Dan
parents:
3
diff
changeset
|
279 |
function yubikey_inject_registration_form() |
032ca892b9a2
Added option to enroll Yubikey during registration + option in admin CP to require enrollment
Dan
parents:
3
diff
changeset
|
280 |
{ |
032ca892b9a2
Added option to enroll Yubikey during registration + option in admin CP to require enrollment
Dan
parents:
3
diff
changeset
|
281 |
global $lang; |
032ca892b9a2
Added option to enroll Yubikey during registration + option in admin CP to require enrollment
Dan
parents:
3
diff
changeset
|
282 |
|
032ca892b9a2
Added option to enroll Yubikey during registration + option in admin CP to require enrollment
Dan
parents:
3
diff
changeset
|
283 |
$preset_otp = isset($_POST['yubikey_otp']) ? $_POST['yubikey_otp'] : false; |
032ca892b9a2
Added option to enroll Yubikey during registration + option in admin CP to require enrollment
Dan
parents:
3
diff
changeset
|
284 |
?> |
032ca892b9a2
Added option to enroll Yubikey during registration + option in admin CP to require enrollment
Dan
parents:
3
diff
changeset
|
285 |
<tr> |
032ca892b9a2
Added option to enroll Yubikey during registration + option in admin CP to require enrollment
Dan
parents:
3
diff
changeset
|
286 |
<td class="row1"> |
032ca892b9a2
Added option to enroll Yubikey during registration + option in admin CP to require enrollment
Dan
parents:
3
diff
changeset
|
287 |
<?php echo $lang->get('yubiucp_reg_field_otp'); ?><br /> |
032ca892b9a2
Added option to enroll Yubikey during registration + option in admin CP to require enrollment
Dan
parents:
3
diff
changeset
|
288 |
<small><?php |
032ca892b9a2
Added option to enroll Yubikey during registration + option in admin CP to require enrollment
Dan
parents:
3
diff
changeset
|
289 |
if ( getConfig('yubikey_reg_require_otp', '0') == '1' ) |
032ca892b9a2
Added option to enroll Yubikey during registration + option in admin CP to require enrollment
Dan
parents:
3
diff
changeset
|
290 |
echo $lang->get('yubiucp_reg_field_otp_hint_required'); |
032ca892b9a2
Added option to enroll Yubikey during registration + option in admin CP to require enrollment
Dan
parents:
3
diff
changeset
|
291 |
else |
032ca892b9a2
Added option to enroll Yubikey during registration + option in admin CP to require enrollment
Dan
parents:
3
diff
changeset
|
292 |
echo $lang->get('yubiucp_reg_field_otp_hint_optional'); |
032ca892b9a2
Added option to enroll Yubikey during registration + option in admin CP to require enrollment
Dan
parents:
3
diff
changeset
|
293 |
?></small> |
032ca892b9a2
Added option to enroll Yubikey during registration + option in admin CP to require enrollment
Dan
parents:
3
diff
changeset
|
294 |
</td> |
032ca892b9a2
Added option to enroll Yubikey during registration + option in admin CP to require enrollment
Dan
parents:
3
diff
changeset
|
295 |
<td class="row1"> |
032ca892b9a2
Added option to enroll Yubikey during registration + option in admin CP to require enrollment
Dan
parents:
3
diff
changeset
|
296 |
<?php |
032ca892b9a2
Added option to enroll Yubikey during registration + option in admin CP to require enrollment
Dan
parents:
3
diff
changeset
|
297 |
echo generate_yubikey_field('yubikey_otp', $preset_otp); |
032ca892b9a2
Added option to enroll Yubikey during registration + option in admin CP to require enrollment
Dan
parents:
3
diff
changeset
|
298 |
?> |
032ca892b9a2
Added option to enroll Yubikey during registration + option in admin CP to require enrollment
Dan
parents:
3
diff
changeset
|
299 |
</td> |
032ca892b9a2
Added option to enroll Yubikey during registration + option in admin CP to require enrollment
Dan
parents:
3
diff
changeset
|
300 |
<td class="row1"> |
032ca892b9a2
Added option to enroll Yubikey during registration + option in admin CP to require enrollment
Dan
parents:
3
diff
changeset
|
301 |
</td> |
032ca892b9a2
Added option to enroll Yubikey during registration + option in admin CP to require enrollment
Dan
parents:
3
diff
changeset
|
302 |
</tr> |
032ca892b9a2
Added option to enroll Yubikey during registration + option in admin CP to require enrollment
Dan
parents:
3
diff
changeset
|
303 |
<?php |
032ca892b9a2
Added option to enroll Yubikey during registration + option in admin CP to require enrollment
Dan
parents:
3
diff
changeset
|
304 |
} |
032ca892b9a2
Added option to enroll Yubikey during registration + option in admin CP to require enrollment
Dan
parents:
3
diff
changeset
|
305 |
|
032ca892b9a2
Added option to enroll Yubikey during registration + option in admin CP to require enrollment
Dan
parents:
3
diff
changeset
|
306 |
function yubikey_register_validate(&$error) |
032ca892b9a2
Added option to enroll Yubikey during registration + option in admin CP to require enrollment
Dan
parents:
3
diff
changeset
|
307 |
{ |
032ca892b9a2
Added option to enroll Yubikey during registration + option in admin CP to require enrollment
Dan
parents:
3
diff
changeset
|
308 |
global $db, $session, $paths, $template, $plugins; // Common objects |
032ca892b9a2
Added option to enroll Yubikey during registration + option in admin CP to require enrollment
Dan
parents:
3
diff
changeset
|
309 |
global $lang; |
032ca892b9a2
Added option to enroll Yubikey during registration + option in admin CP to require enrollment
Dan
parents:
3
diff
changeset
|
310 |
|
032ca892b9a2
Added option to enroll Yubikey during registration + option in admin CP to require enrollment
Dan
parents:
3
diff
changeset
|
311 |
$otp_required = getConfig('yubikey_reg_require_otp', '0') == '1'; |
032ca892b9a2
Added option to enroll Yubikey during registration + option in admin CP to require enrollment
Dan
parents:
3
diff
changeset
|
312 |
$have_otp = !empty($_POST['yubikey_otp']); |
032ca892b9a2
Added option to enroll Yubikey during registration + option in admin CP to require enrollment
Dan
parents:
3
diff
changeset
|
313 |
if ( $otp_required && !$have_otp ) |
032ca892b9a2
Added option to enroll Yubikey during registration + option in admin CP to require enrollment
Dan
parents:
3
diff
changeset
|
314 |
{ |
032ca892b9a2
Added option to enroll Yubikey during registration + option in admin CP to require enrollment
Dan
parents:
3
diff
changeset
|
315 |
$error = $lang->get('yubiucp_reg_err_otp_required'); |
032ca892b9a2
Added option to enroll Yubikey during registration + option in admin CP to require enrollment
Dan
parents:
3
diff
changeset
|
316 |
return false; |
032ca892b9a2
Added option to enroll Yubikey during registration + option in admin CP to require enrollment
Dan
parents:
3
diff
changeset
|
317 |
} |
032ca892b9a2
Added option to enroll Yubikey during registration + option in admin CP to require enrollment
Dan
parents:
3
diff
changeset
|
318 |
if ( $have_otp ) |
032ca892b9a2
Added option to enroll Yubikey during registration + option in admin CP to require enrollment
Dan
parents:
3
diff
changeset
|
319 |
{ |
032ca892b9a2
Added option to enroll Yubikey during registration + option in admin CP to require enrollment
Dan
parents:
3
diff
changeset
|
320 |
$result = yubikey_validate_otp($_POST['yubikey_otp']); |
032ca892b9a2
Added option to enroll Yubikey during registration + option in admin CP to require enrollment
Dan
parents:
3
diff
changeset
|
321 |
if ( !$result['success'] ) |
032ca892b9a2
Added option to enroll Yubikey during registration + option in admin CP to require enrollment
Dan
parents:
3
diff
changeset
|
322 |
{ |
032ca892b9a2
Added option to enroll Yubikey during registration + option in admin CP to require enrollment
Dan
parents:
3
diff
changeset
|
323 |
$error = '<b>' . $lang->get('yubiucp_reg_err_otp_invalid') . '</b><br />' . $lang->get("yubiauth_err_{$result['error']}"); |
032ca892b9a2
Added option to enroll Yubikey during registration + option in admin CP to require enrollment
Dan
parents:
3
diff
changeset
|
324 |
return false; |
032ca892b9a2
Added option to enroll Yubikey during registration + option in admin CP to require enrollment
Dan
parents:
3
diff
changeset
|
325 |
} |
032ca892b9a2
Added option to enroll Yubikey during registration + option in admin CP to require enrollment
Dan
parents:
3
diff
changeset
|
326 |
// check for double enrollment |
032ca892b9a2
Added option to enroll Yubikey during registration + option in admin CP to require enrollment
Dan
parents:
3
diff
changeset
|
327 |
$yubi_uid = substr($_POST['yubikey_otp'], 0, 12); |
032ca892b9a2
Added option to enroll Yubikey during registration + option in admin CP to require enrollment
Dan
parents:
3
diff
changeset
|
328 |
// Note on SQL injection: yubikey_validate_otp() has already ensured that this is safe |
032ca892b9a2
Added option to enroll Yubikey during registration + option in admin CP to require enrollment
Dan
parents:
3
diff
changeset
|
329 |
$q = $db->sql_query('SELECT 1 FROM ' . table_prefix . "yubikey WHERE yubi_uid = '$yubi_uid';"); |
032ca892b9a2
Added option to enroll Yubikey during registration + option in admin CP to require enrollment
Dan
parents:
3
diff
changeset
|
330 |
if ( !$q ) |
032ca892b9a2
Added option to enroll Yubikey during registration + option in admin CP to require enrollment
Dan
parents:
3
diff
changeset
|
331 |
$db->_die(); |
032ca892b9a2
Added option to enroll Yubikey during registration + option in admin CP to require enrollment
Dan
parents:
3
diff
changeset
|
332 |
if ( $db->numrows() > 0 ) |
032ca892b9a2
Added option to enroll Yubikey during registration + option in admin CP to require enrollment
Dan
parents:
3
diff
changeset
|
333 |
{ |
032ca892b9a2
Added option to enroll Yubikey during registration + option in admin CP to require enrollment
Dan
parents:
3
diff
changeset
|
334 |
$error = '<b>' . $lang->get('yubiucp_reg_err_otp_invalid') . '</b><br />' . $lang->get('yubiucp_err_double_enrollment_single'); |
032ca892b9a2
Added option to enroll Yubikey during registration + option in admin CP to require enrollment
Dan
parents:
3
diff
changeset
|
335 |
return false; |
032ca892b9a2
Added option to enroll Yubikey during registration + option in admin CP to require enrollment
Dan
parents:
3
diff
changeset
|
336 |
} |
032ca892b9a2
Added option to enroll Yubikey during registration + option in admin CP to require enrollment
Dan
parents:
3
diff
changeset
|
337 |
$db->free_result(); |
032ca892b9a2
Added option to enroll Yubikey during registration + option in admin CP to require enrollment
Dan
parents:
3
diff
changeset
|
338 |
} |
032ca892b9a2
Added option to enroll Yubikey during registration + option in admin CP to require enrollment
Dan
parents:
3
diff
changeset
|
339 |
} |
032ca892b9a2
Added option to enroll Yubikey during registration + option in admin CP to require enrollment
Dan
parents:
3
diff
changeset
|
340 |
|
032ca892b9a2
Added option to enroll Yubikey during registration + option in admin CP to require enrollment
Dan
parents:
3
diff
changeset
|
341 |
function yubikey_register_insert_key($user_id) |
032ca892b9a2
Added option to enroll Yubikey during registration + option in admin CP to require enrollment
Dan
parents:
3
diff
changeset
|
342 |
{ |
032ca892b9a2
Added option to enroll Yubikey during registration + option in admin CP to require enrollment
Dan
parents:
3
diff
changeset
|
343 |
global $db, $session, $paths, $template, $plugins; // Common objects |
032ca892b9a2
Added option to enroll Yubikey during registration + option in admin CP to require enrollment
Dan
parents:
3
diff
changeset
|
344 |
if ( !empty($_POST['yubikey_otp']) ) |
032ca892b9a2
Added option to enroll Yubikey during registration + option in admin CP to require enrollment
Dan
parents:
3
diff
changeset
|
345 |
{ |
032ca892b9a2
Added option to enroll Yubikey during registration + option in admin CP to require enrollment
Dan
parents:
3
diff
changeset
|
346 |
$yubi_uid = $db->escape(substr($_POST['yubikey_otp'], 0, 12)); |
032ca892b9a2
Added option to enroll Yubikey during registration + option in admin CP to require enrollment
Dan
parents:
3
diff
changeset
|
347 |
$q = $db->sql_query('INSERT INTO ' . table_prefix . "yubikey ( user_id, yubi_uid ) VALUES ( $user_id, '$yubi_uid' );"); |
032ca892b9a2
Added option to enroll Yubikey during registration + option in admin CP to require enrollment
Dan
parents:
3
diff
changeset
|
348 |
if ( !$q ) |
032ca892b9a2
Added option to enroll Yubikey during registration + option in admin CP to require enrollment
Dan
parents:
3
diff
changeset
|
349 |
$db->_die(); |
032ca892b9a2
Added option to enroll Yubikey during registration + option in admin CP to require enrollment
Dan
parents:
3
diff
changeset
|
350 |
} |
032ca892b9a2
Added option to enroll Yubikey during registration + option in admin CP to require enrollment
Dan
parents:
3
diff
changeset
|
351 |
} |