1
0
mirror of https://github.com/Yubico/yubikey-val.git synced 2025-03-04 03:29:18 +01:00

Added full resync by sending yk=all.

This commit is contained in:
Dain Nilsson 2013-02-12 14:56:22 +01:00
parent d1858b9020
commit 088bcb4799

View File

@ -47,7 +47,7 @@ $yk = $_REQUEST["yk"];
if (!$yk) { if (!$yk) {
logdie($myLog, "ERROR Missing parameter"); logdie($myLog, "ERROR Missing parameter");
} }
if (!preg_match("/^([cbdefghijklnrtuv]{0,16})$/", $yk)) { if (!($yk == "all" || preg_match("/^([cbdefghijklnrtuv]{0,16})$/", $yk))) {
logdie($myLog, "ERROR Unknown yk value: $yk"); logdie($myLog, "ERROR Unknown yk value: $yk");
} }
$myLog->addField('yk', $yk); $myLog->addField('yk', $yk);
@ -58,10 +58,20 @@ if (!$db->connect()) {
logdie($myLog, 'ERROR Database connect error (1)'); logdie($myLog, 'ERROR Database connect error (1)');
} }
# Check if key exists if($yk == "all") {
$r = $db->findBy('yubikeys', 'yk_publicname', $yk, 1); # Get all keys
if (!$r) { $res = $db->customQuery("SELECT yk_publicname FROM yubikeys WHERE active = true");
while($r = $db->fetchArray($res)) {
$yubikeys[] = $r['yk_publicname'];
}
$db->closeCursor($res);
} else {
# Check if key exists
$r = $db->findBy('yubikeys', 'yk_publicname', $yk, 1);
if (!$r) {
logdie($myLog, "ERROR Unknown yubikey: $yk"); logdie($myLog, "ERROR Unknown yubikey: $yk");
}
$yubikeys = array($yk);
} }
/* Initialize the sync library. */ /* Initialize the sync library. */
@ -73,17 +83,19 @@ if (! $sync->isConnected()) {
logdie($myLog, 'ERROR Database connect error (2)'); logdie($myLog, 'ERROR Database connect error (2)');
} }
$localParams = $sync->getLocalParams($yk); foreach($yubikeys as $key) {
if (!$localParams) { $localParams = $sync->getLocalParams($key);
logdie($myLog, 'ERROR Invalid Yubikey ' . $yk); if (!$localParams) {
} logdie($myLog, 'ERROR Invalid Yubikey ' . $key);
}
$localParams['otp'] = $yk . str_repeat('c', 32); // Fake an OTP, only used for logging. $localParams['otp'] = $key . str_repeat('c', 32); // Fake an OTP, only used for logging.
$myLog->log(LOG_DEBUG, "Auth data:", $localParams); $myLog->log(LOG_DEBUG, "Auth data:", $localParams);
/* Queue sync requests */ /* Queue sync request */
if (!$sync->queue($localParams, $localParams)) { if (!$sync->queue($localParams, $localParams)) {
logdie($myLog, 'ERROR Failed resync'); logdie($myLog, 'ERROR Failed resync');
}
} }
# We are done # We are done