From 3ff2d0d93d1b4a21ffea072510d7b132520f49ed Mon Sep 17 00:00:00 2001 From: Paul Chen Date: Fri, 26 Sep 2008 03:21:11 +0000 Subject: [PATCH] add key --- add_key.php | 101 ++++++++++++++++++++++++++++++++++++++++++++++++++ common.php | 39 +++++++++++++++++++ verifyOTP.php | 33 +---------------- 3 files changed, 142 insertions(+), 31 deletions(-) create mode 100644 add_key.php create mode 100644 common.php diff --git a/add_key.php b/add_key.php new file mode 100644 index 0000000..e535f96 --- /dev/null +++ b/add_key.php @@ -0,0 +1,101 @@ + 0) { + debug('Key '.$keyid.' added'); + reply(S_OK, $ci['secret'], $client, $nonce); +} else { + reply(S_BACKEND_ERROR, $ci['secret'], $client, $nonce); + exit; +} + +function reply($status, $apiKey, $client_id, $nonce, $info=null) { + global $tokenId; + + if ($status == null) { + $status = S_BACKEND_ERROR; + } + + date_default_timezone_set('UTC'); + $timestamp = date('Y-m-d\TH:i:s\ZZ', time()); + + //// Prepare the response to the user + // + $respParams = 'status='.$status.'&t='.$timestamp; + + // Generate the signature + debug('API key: '.$apiKey); // API key of the client + debug('Signing: '.$respParams); + // the TRUE at the end states we want the raw value, not hexadecimal form + $hmac = hash_hmac('sha1', utf8_encode($respParams), $apiKey, true); + //outputToFile('hmac', $hmac, "b"); + // now take that byte value and base64 encode it + $hmac = base64_encode($hmac); + + echo 'h='.$hmac.PHP_EOL; + if ($info != null) { + echo 'info='.$info.PHP_EOL; + } + echo 'nonce='.$nonce.PHP_EOL; + echo 'status='.$status.PHP_EOL; + echo 't='.$timestamp.PHP_EOL; + echo PHP_EOL; + +} // End reply + +?> diff --git a/common.php b/common.php new file mode 100644 index 0000000..f982ca6 --- /dev/null +++ b/common.php @@ -0,0 +1,39 @@ + '.$msg; + } + echo "\n"; + } + if ($exit) { + die ('

Exit

'); + } +} + +function genRandB64($len) { + $r = hash('sha1', rand(999,99999999)); + $r = substr(0,$len); + return base64_encode($r); +} + +function outputToFile($outFname, $content, $mode, $append=false) { + $out = fopen($outFname, ($append ? "a" : "w")); + fwrite($out, $content); + fclose($out); +} +?> diff --git a/verifyOTP.php b/verifyOTP.php index fbb00d6..d574660 100644 --- a/verifyOTP.php +++ b/verifyOTP.php @@ -1,16 +1,7 @@ '.$msg; - } - echo "\n"; - } - if ($exit) { - die ('

Exit

'); - } -} - function updDB($keyid, $new) { $stmt = 'UPDATE yubikeys SET '. 'accessed=NOW(),'. @@ -237,9 +213,4 @@ function updDB($keyid, $new) { return true; } -function outputToFile($outFname, $content, $mode, $append=false) { - $out = fopen($outFname, ($append ? "a" : "w")); - fwrite($out, $content); - fclose($out); -} ?>