Esempio n. 1
0
    sendResp(S_REPLAYED_REQUEST, $myLog, $apiKey, $extra);
}
/* Check the OTP counters against local db */
if ($sync->countersHigherThanOrEqual($localParams, $otpParams)) {
    $sync->log(LOG_WARNING, 'replayed OTP: Local counters higher');
    $sync->log(LOG_WARNING, 'replayed OTP: Local counters ', $localParams);
    $sync->log(LOG_WARNING, 'replayed OTP: Otp counters ', $otpParams);
    sendResp(S_REPLAYED_OTP, $myLog, $apiKey, $extra);
}
/* Valid OTP, update database. */
if (!$sync->updateDbCounters($otpParams)) {
    $myLog->log(LOG_CRIT, 'Failed to update yubikey counters in database');
    sendResp(S_BACKEND_ERROR, $myLog, $apiKey);
}
/* Queue sync requests */
if (!$sync->queue($otpParams, $localParams)) {
    $myLog->log(LOG_CRIT, 'ykval-verify:critical:failed to queue sync requests');
    sendResp(S_BACKEND_ERROR, $myLog, $apiKey);
}
$nr_servers = $sync->getNumberOfServers();
$req_answers = ceil($nr_servers * $sl / 100.0);
if ($req_answers > 0) {
    $syncres = $sync->sync($req_answers, $timeout);
    $nr_answers = $sync->getNumberOfAnswers();
    $nr_valid_answers = $sync->getNumberOfValidAnswers();
    $sl_success_rate = floor(100.0 * $nr_valid_answers / $nr_servers);
} else {
    $syncres = true;
    $nr_answers = 0;
    $nr_valid_answers = 0;
    $sl_success_rate = 0;
 public function testNullQueue()
 {
     $sl = new SyncLib();
     $sl->syncServers = array("http://localhost/wsapi/syncvalid1", "http://doesntexist/wsapi/syncvalid2", "http://localhost/wsapi/syncvalid3");
     $start_length = $sl->getQueueLength();
     $p1 = array('modified' => 1259585588 + 1000, 'otp' => "ccccccccccccfrhiutjgfnvgdurgliidceuilikvfhui", 'yk_publicname' => "cccccccccccc", 'yk_counter' => 9, 'yk_use' => 3, 'yk_high' => 100, 'yk_low' => 1000);
     $this->assertTrue($sl->queue($p1, $p1));
     $res = $sl->db->findByMultiple('queue', array("modified" => 1259585588 + 1000, "server_nonce" => $sl->server_nonce));
     $lastRes = $res[0];
     $info = $sl->otpParamsFromInfoString($lastRes['info']);
     $res = array('queued' => $lastRes['queued'], 'modified' => $lastRes['modified'], 'otp' => $lastRes['otp'], 'server' => $lastRes['server'], 'nonce' => $info['nonce'], 'yk_publicname' => $info['yk_publicname'], 'yk_counter' => $info['yk_counter'], 'yk_use' => $info['yk_use'], 'yk_high' => $info['yk_high'], 'yk_low' => $info['yk_low']);
     $this->assertNotNull($res['queued']);
     $res = $sl->sync(3);
     $this->assertEquals(1 + $start_length, $sl->getQueueLength());
     $res = $sl->db->findByMultiple('queue', array("modified" => 1259585588 + 1000, "server_nonce" => $sl->server_nonce));
     $lastRes = $res[0];
     $info = $sl->otpParamsFromInfoString($lastRes['info']);
     $res = array('queued' => $lastRes['queued'], 'modified' => $lastRes['modified'], 'otp' => $lastRes['otp'], 'server' => $lastRes['server'], 'nonce' => $info['nonce'], 'yk_publicname' => $info['yk_publicname'], 'yk_counter' => $info['yk_counter'], 'yk_use' => $info['yk_use'], 'yk_high' => $info['yk_high'], 'yk_low' => $info['yk_low']);
     $this->assertNull($res['queued']);
 }