mirror of
https://github.com/Yubico/yubikey-val.git
synced 2025-01-20 10:52:15 +01:00
sign example
This commit is contained in:
parent
2ebaaaeb1f
commit
b18af416f8
15
common.php
15
common.php
@ -13,9 +13,9 @@ function debug($msg, $exit = false) {
|
||||
global $trace;
|
||||
if ($trace) {
|
||||
if (is_array($msg)) {
|
||||
print_r($msg);
|
||||
//print_r($msg);
|
||||
} else {
|
||||
echo 'debug> ' . $msg;
|
||||
echo '<p>Debug> ' . $msg;
|
||||
}
|
||||
echo "\n";
|
||||
}
|
||||
@ -42,7 +42,7 @@ function getUTCTimeStamp() {
|
||||
|
||||
// Sign a http query string in the array of key-value pairs
|
||||
// return b64 encoded hmac hash
|
||||
function sign($a, $apiKey) {
|
||||
function sign($a, $apiKey, $debug=false) {
|
||||
ksort($a);
|
||||
$qs = '';
|
||||
$n = count($a);
|
||||
@ -56,15 +56,18 @@ function sign($a, $apiKey) {
|
||||
|
||||
// Generate the signature
|
||||
//debug('API key: '.$apiKey); // API key of the client
|
||||
debug('Signing: '.$qs);
|
||||
debug('SIGN: '.$qs);
|
||||
|
||||
// the TRUE at the end states we want the raw value, not hexadecimal form
|
||||
$hmac = hash_hmac('sha1', utf8_encode($qs), $apiKey, true);
|
||||
$hmac = base64_encode($hmac);
|
||||
|
||||
if ($debug) {
|
||||
debug('h='.$hmac);
|
||||
debug('<a href=verify_debug.php?'.$qs.'&h='.urlencode($hmac).'>Submit the request >> </a>');
|
||||
}
|
||||
return $hmac;
|
||||
|
||||
} // SignWithTime
|
||||
} // sign an array of query string
|
||||
|
||||
function outputToFile($outFname, $content, $mode, $append = false) {
|
||||
$out = fopen($outFname, ($append ? "a" : "w"));
|
||||
|
37
sign_demo.php
Normal file
37
sign_demo.php
Normal file
@ -0,0 +1,37 @@
|
||||
<h3>Generate a signature</h3>
|
||||
|
||||
<?php require_once '../yubiphpbase/appinclude.php';
|
||||
require_once '../yubiphpbase/yubi_lib.php';
|
||||
require_once 'common.php';
|
||||
|
||||
$trace = true;
|
||||
|
||||
$act = getHttpVal('act', '');
|
||||
|
||||
if ($act == '') {
|
||||
echo '<form action=sign_demo.php method=post>'.
|
||||
'<input name=act value=sign type=hidden>'.
|
||||
'api key: (use your api key issued to you by Yubico in b64 format): ' .
|
||||
'<input name=apikey size=45 maxlength=100 value="kNapft02c1a81N4MEMDcC/mgcGc="><p>'.
|
||||
'id (your client id): <input name=id size=5 maxlength=10><p>'.
|
||||
'otp: <input name=otp size=45 maxlength=100><p>'.
|
||||
'<input type=submit value=Sign>'.
|
||||
'</form>';
|
||||
exit;
|
||||
}
|
||||
|
||||
$id = getHttpVal('id', '');
|
||||
$otp = getHttpVal('otp', '');
|
||||
$t = getHttpVal('t', '');
|
||||
$apiKey = base64_decode(getHttpVal('apikey', ''));
|
||||
|
||||
$a['id']=$id;
|
||||
$a['otp']=$otp;
|
||||
|
||||
if ($t != '') {
|
||||
$a['t']=$t;
|
||||
}
|
||||
|
||||
$hmac = sign($a, $apiKey, true);
|
||||
|
||||
?>
|
@ -24,7 +24,6 @@ if ($otp == '') {
|
||||
//
|
||||
$devId = substr($otp, 0, 12);
|
||||
$ad = getAuthData($devId);
|
||||
debug('Auth Data from DB:');
|
||||
|
||||
if ($ad == null) {
|
||||
debug('Invalid Yubikey '.$devId);
|
||||
|
Loading…
x
Reference in New Issue
Block a user