mirror of
https://github.com/Yubico/yubikey-val.git
synced 2025-02-08 03:54:20 +01:00
Auto-discover yubikeys known by the ykksm.
This commit is contained in:
parent
84f381ba96
commit
52720a57ba
11
common.php
11
common.php
@ -127,9 +127,9 @@ function decryptOTP($otp, $base_url) {
|
|||||||
function getAuthData($conn, $devId) {
|
function getAuthData($conn, $devId) {
|
||||||
$tokenId = modhex2b64($devId);
|
$tokenId = modhex2b64($devId);
|
||||||
$stmt =
|
$stmt =
|
||||||
'SELECT id, client_id, counter, sessionUse, low, high, accessed '.
|
'SELECT id, active, client_id, counter, sessionUse, low, high, accessed '.
|
||||||
'FROM yubikeys '.
|
'FROM yubikeys '.
|
||||||
'WHERE active AND tokenId='.mysql_quote($tokenId);
|
'WHERE tokenId='.mysql_quote($tokenId);
|
||||||
$r = query($conn, $stmt);
|
$r = query($conn, $stmt);
|
||||||
if (mysql_num_rows($r) > 0) {
|
if (mysql_num_rows($r) > 0) {
|
||||||
$row = mysql_fetch_assoc($r);
|
$row = mysql_fetch_assoc($r);
|
||||||
@ -139,6 +139,13 @@ function getAuthData($conn, $devId) {
|
|||||||
return null;
|
return null;
|
||||||
} // End getAuthData
|
} // End getAuthData
|
||||||
|
|
||||||
|
function addNewKey($conn, $devId) {
|
||||||
|
$tokenId = modhex2b64($devId);
|
||||||
|
$stmt = 'INSERT INTO yubikeys (client_id, active, created, tokenId, counter) '.
|
||||||
|
'VALUES (1, true, NOW(), ' . mysql_quote($tokenId) . ', 0)';
|
||||||
|
$r = query($conn, $stmt);
|
||||||
|
}
|
||||||
|
|
||||||
// $clientId: The decimal client identity
|
// $clientId: The decimal client identity
|
||||||
function getClientData($conn, $clientId) {
|
function getClientData($conn, $clientId) {
|
||||||
$stmt =
|
$stmt =
|
||||||
|
10
verify.php
10
verify.php
@ -82,12 +82,22 @@ debug($otpinfo);
|
|||||||
//
|
//
|
||||||
$devId = substr($otp, 0, strlen ($otp) - TOKEN_LEN);
|
$devId = substr($otp, 0, strlen ($otp) - TOKEN_LEN);
|
||||||
$ad = getAuthData($conn, $devId);
|
$ad = getAuthData($conn, $devId);
|
||||||
|
if (!is_array($ad)) {
|
||||||
|
debug('Discovered Yubikey ' . $devId);
|
||||||
|
addNewKey($conn, $devId);
|
||||||
|
}
|
||||||
|
$ad = getAuthData($conn, $devId);
|
||||||
if (!is_array($ad)) {
|
if (!is_array($ad)) {
|
||||||
debug('Invalid Yubikey ' . $devId);
|
debug('Invalid Yubikey ' . $devId);
|
||||||
sendResp(S_BAD_OTP);
|
sendResp(S_BAD_OTP);
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
debug($ad);
|
debug($ad);
|
||||||
|
if ($ad['active'] != 1) {
|
||||||
|
debug('De-activated Yubikey ' . $devId);
|
||||||
|
sendResp(S_BAD_OTP);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
//// Check the session counter
|
//// Check the session counter
|
||||||
//
|
//
|
||||||
|
Loading…
x
Reference in New Issue
Block a user