mirror of
https://github.com/Yubico/yubikey-val.git
synced 2024-12-01 15:24:16 +01:00
Fix rand# gen
This commit is contained in:
parent
3ff2d0d93d
commit
9c4b09d99c
@ -52,8 +52,8 @@ if ($ci['perm_id'] != 1 && $ci['perm_id'] != 2) {
|
|||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
$tokenId = genRandB64(6);
|
$tokenId = base64_encode(genRandRaw(6));
|
||||||
$secret = genRandB64(16);
|
$secret = base64_encode(genRandRaw(16));
|
||||||
$keyid = addNewKey($tokenId, 1, $secret, '', $client);
|
$keyid = addNewKey($tokenId, 1, $secret, '', $client);
|
||||||
|
|
||||||
if ($keyid > 0) {
|
if ($keyid > 0) {
|
||||||
@ -80,7 +80,7 @@ function reply($status, $apiKey, $client_id, $nonce, $info=null) {
|
|||||||
|
|
||||||
// Generate the signature
|
// Generate the signature
|
||||||
debug('API key: '.$apiKey); // API key of the client
|
debug('API key: '.$apiKey); // API key of the client
|
||||||
debug('Signing: '.$respParams);
|
debug('Signing response: '.$respParams);
|
||||||
// the TRUE at the end states we want the raw value, not hexadecimal form
|
// the TRUE at the end states we want the raw value, not hexadecimal form
|
||||||
$hmac = hash_hmac('sha1', utf8_encode($respParams), $apiKey, true);
|
$hmac = hash_hmac('sha1', utf8_encode($respParams), $apiKey, true);
|
||||||
//outputToFile('hmac', $hmac, "b");
|
//outputToFile('hmac', $hmac, "b");
|
||||||
|
22
common.php
22
common.php
@ -1,5 +1,4 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
define('S_OK', 'OK');
|
define('S_OK', 'OK');
|
||||||
define('S_BAD_OTP', 'BAD_OTP');
|
define('S_BAD_OTP', 'BAD_OTP');
|
||||||
define('S_BAD_CLIENT', 'BAD_CLIENT'); // New, added by paul 20080920
|
define('S_BAD_CLIENT', 'BAD_CLIENT'); // New, added by paul 20080920
|
||||||
@ -10,28 +9,33 @@ define('S_MISSING_PARAMETER', 'MISSING_PARAMETER');
|
|||||||
define('S_OPERATION_NOT_ALLOWED', 'OPERATION_NOT_ALLOWED');
|
define('S_OPERATION_NOT_ALLOWED', 'OPERATION_NOT_ALLOWED');
|
||||||
define('S_BACKEND_ERROR', 'BACKEND_ERROR');
|
define('S_BACKEND_ERROR', 'BACKEND_ERROR');
|
||||||
|
|
||||||
function debug($msg, $exit=false) {
|
function debug($msg, $exit = false) {
|
||||||
global $trace;
|
global $trace;
|
||||||
if ($trace) {
|
if ($trace) {
|
||||||
if (is_array($msg)) {
|
if (is_array($msg)) {
|
||||||
print_r($msg);
|
print_r($msg);
|
||||||
} else {
|
} else {
|
||||||
echo 'debug> '.$msg;
|
echo 'debug> ' . $msg;
|
||||||
}
|
}
|
||||||
echo "\n";
|
echo "\n";
|
||||||
}
|
}
|
||||||
if ($exit) {
|
if ($exit) {
|
||||||
die ('<font color=red><h4>Exit</h4></font>');
|
die('<font color=red><h4>Exit</h4></font>');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function genRandB64($len) {
|
function genRandRaw($len) {
|
||||||
$r = hash('sha1', rand(999,99999999));
|
$h = hash_hmac('sha1', rand(9999,9999999), 'dj*ccbcuiiurubrvnubcdluul', true);
|
||||||
$r = substr(0,$len);
|
$a = str_split($h);
|
||||||
return base64_encode($r);
|
//print_r($a);
|
||||||
|
$a = array_slice($a, 0, $len);
|
||||||
|
//print_r($a);
|
||||||
|
$s = implode($a);
|
||||||
|
//outputToFile('out', $s);
|
||||||
|
return $s;
|
||||||
}
|
}
|
||||||
|
|
||||||
function outputToFile($outFname, $content, $mode, $append=false) {
|
function outputToFile($outFname, $content, $mode, $append = false) {
|
||||||
$out = fopen($outFname, ($append ? "a" : "w"));
|
$out = fopen($outFname, ($append ? "a" : "w"));
|
||||||
fwrite($out, $content);
|
fwrite($out, $content);
|
||||||
fclose($out);
|
fclose($out);
|
||||||
|
Loading…
Reference in New Issue
Block a user