<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-gb">
<link rel="self" type="application/atom+xml" href="https://forum.yubico.com/feed.php?f=8&amp;t=130" />

<title>Yubico Forum</title>
<subtitle>...visit our web-store at</subtitle>
<link href="https://forum.yubico.com/index.php" />
<updated>2008-07-08T21:17:44+01:00</updated>

<author><name><![CDATA[Yubico Forum]]></name></author>
<id>https://forum.yubico.com/feed.php?f=8&amp;t=130</id>
<entry>
<author><name><![CDATA[gorkab]]></name></author>
<updated>2008-07-08T21:17:44+01:00</updated>
<published>2008-07-08T21:17:44+01:00</published>
<id>https://forum.yubico.com/viewtopic.php?t=130&amp;p=421#p421</id>
<link href="https://forum.yubico.com/viewtopic.php?t=130&amp;p=421#p421"/>
<title type="html"><![CDATA[Re: hmac verification in perl (RESOLVED)]]></title>

<content type="html" xml:base="https://forum.yubico.com/viewtopic.php?t=130&amp;p=421#p421"><![CDATA[
working code - <br /><br /><div class="codetitle"><b>Code:</b></div><div class="codecontent">#!/usr/bin/perl<br /><br /># {{{ Includes<br /><br />use strict;<br />use warnings;<br /><br />use Digest::SHA qw(hmac_sha1);<br />use File::Basename;<br />use MIME::Base64;<br />use URI::Escape;<br />use WWW::Mechanize;<br /><br /># }}}<br /># {{{ Constants<br /><br />use constant YUBICOAUTHSRVURLPREFIX =&gt; 'http://api.yubico.com/wsapi/verify?';<br />use constant MYYUBICOAPIKEY         =&gt; '';<br /><br /># }}}<br /># {{{ Globals<br /><br />my $MyDecodedYubicoAPIKey = decode_base64(MYYUBICOAPIKEY);<br /><br /># }}}<br /># {{{ usage()<br /><br />sub usage(;$) {<br />    print &quot;\n\n!!!  @_\n\n&quot; if @_;<br />    my $prog = basename $0;<br /><br />    print &lt;&lt;_USAGE_END;<br /><br />Usage:<br />    $prog  clientID  oneTimePasscode<br /><br />_USAGE_END<br />}<br /><br /># }}}<br /># {{{ main<br /><br />if ( @ARGV != 2 ) {<br />    usage and exit 2;<br />}<br /><br />my $YubicoAuthString = &quot;id=&quot; . $ARGV&#91;0&#93; . &quot;&amp;otp=&quot; . $ARGV&#91;1&#93;;<br /><br />my $YubicoAuthHash = &quot;&amp;h=&quot;<br />    . uri_escape(<br />    encode_base64( hmac_sha1( $YubicoAuthString, $MyDecodedYubicoAPIKey ) ),<br />    '+' );<br /><br />my $YubicoAuthSrvURL<br />    = YUBICOAUTHSRVURLPREFIX . $YubicoAuthString . $YubicoAuthHash;<br /><br />print &quot;\nAuth Request = $YubicoAuthSrvURL\n&quot;;<br /><br />my $mech = WWW::Mechanize-&gt;new();<br /><br />$mech-&gt;get($YubicoAuthSrvURL);<br /><br />my $YubicoAuthSrvResponse = $mech-&gt;response()-&gt;content();<br /><br />my ( $YubiHMAC, $YubiTime, $YubiStat )<br />    = split( /\n/, $YubicoAuthSrvResponse );<br /><br />chop( $YubiHMAC, $YubiTime, $YubiStat );<br /><br />my $YubiCheckString = $YubiStat . &quot;&amp;&quot; . $YubiTime;<br /><br />my $YubiCheckHash = &quot;h=&quot;<br />    . encode_base64( hmac_sha1( $YubiCheckString, $MyDecodedYubicoAPIKey ) );<br /><br />chomp($YubiCheckHash);<br /><br />if ( $YubiStat =~ /status=OK/ ) {<br />    print &quot; OTP verification ok\n&quot;;<br />}<br />else {<br />    print &quot; OTP verification failed\n&quot;;<br />}<br /><br />if ( $YubiCheckHash eq $YubiHMAC ) {<br />    print &quot;HMAC verification ok\n&quot;;<br />}<br />else {<br />    print &quot;HMAC verification failed\n&quot;;<br />}<br /><br />print &quot;\n&quot;;<br />print &quot;VMAC = $YubiCheckHash\n&quot;;<br />print &quot;HMAC = $YubiHMAC\n&quot;;<br />print &quot;TIME = $YubiTime\n&quot;;<br />print &quot;STAT = $YubiStat\n\n&quot;;<br /><br /># }}}<br /></div><p>Statistics: Posted by <a href="https://forum.yubico.com/memberlist.php?mode=viewprofile&amp;u=194">gorkab</a> — Tue Jul 08, 2008 9:17 pm</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[gorkab]]></name></author>
<updated>2008-07-08T14:59:45+01:00</updated>
<published>2008-07-08T14:59:45+01:00</published>
<id>https://forum.yubico.com/viewtopic.php?t=130&amp;p=419#p419</id>
<link href="https://forum.yubico.com/viewtopic.php?t=130&amp;p=419#p419"/>
<title type="html"><![CDATA[Re: hmac verification in perl]]></title>

<content type="html" xml:base="https://forum.yubico.com/viewtopic.php?t=130&amp;p=419#p419"><![CDATA[
and the answer is... I'm missing something, and the API documentation is very unclear.  I've got it working now thanks to the work of the PHP team.     (the api documentation i am referring to is here <!-- m --><a class="postlink" href="http://www.yubico.com/developers/intro/">http://www.yubico.com/developers/intro/</a><!-- m --> , if there are better docs elsewhere I didn't find them)<br /><br />End problems in a nutshell were:<br /><br />1) the API key is base64 encoded when given to you, but you need to operate with it in non-base64 format.  this is not in the API documentation on the web page that I could find.<br /><br />2) what you are actually hashing on the return is not clear from the API documentation.   i've figured it out (again thanks to the PHP folks here), but the API documentation was again very unclear.<br /><br />My only remaining problem is that when there is a + symbol in the outgoing HMAC it returns a bad signature.   I've seen people allude to URL encoding that string, but the perl url_escape functions<br />seem to still end up with a bad signature return.  I'm working on this.  Once it's done, I will publish updated code here.<p>Statistics: Posted by <a href="https://forum.yubico.com/memberlist.php?mode=viewprofile&amp;u=194">gorkab</a> — Tue Jul 08, 2008 2:59 pm</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[gorkab]]></name></author>
<updated>2008-07-08T15:00:35+01:00</updated>
<published>2008-07-07T19:26:21+01:00</published>
<id>https://forum.yubico.com/viewtopic.php?t=130&amp;p=414#p414</id>
<link href="https://forum.yubico.com/viewtopic.php?t=130&amp;p=414#p414"/>
<title type="html"><![CDATA[hmac verification in perl (RESOLVED)]]></title>

<content type="html" xml:base="https://forum.yubico.com/viewtopic.php?t=130&amp;p=414#p414"><![CDATA[
I'm trying to add HMAC verification in to the simple perl client.   While I think i have it right, I can't seem to generate a response that matches the h= part from the Yubico servers.<br /><br />I've taken the sample code, and added a few bits:<br /><br /><div class="codetitle"><b>Code:</b></div><div class="codecontent">use Digest::SHA qw(hmac_sha1);<br />use MIME::Base64;<br /><br />my $MyYubicoAPIKey = &quot;myAPIkey&quot;;<br />.<br />. snip<br />.<br />my $YubicoAuthString = &quot;&amp;id=&quot;. $ARGV&#91;0&#93; . &quot;&amp;otp=&quot; . $ARGV&#91;1&#93;;<br />my $YubicoAuthSrvURL = YubicoAuthSrvURLprefix . $YubicoAuthString;<br /><br />my $mech = WWW::Mechanize-&gt;new();<br />$mech-&gt;get($YubicoAuthSrvURL);<br />my $YubicoAuthSrvResponse = $mech-&gt;response()-&gt;content();<br /><br />if ($YubicoAuthSrvResponse =~ /status=OK/) {<br />  print &quot;\nOTP verification ok\n&quot;;<br />  print &quot;$YubicoAuthSrvResponse&quot;;<br />  print &quot;v=&quot; . encode_base64(hmac_sha1($YubicoAuthString, $MyYubicoAPIKey));<br />} else {<br />  print &quot;\nOTP verification failed\n&quot;;<br />  print &quot;$YubicoAuthSrvResponse&quot;;<br />  print &quot;v=&quot; . encode_base64(hmac_sha1($YubicoAuthString, $MyYubicoAPIKey));<br />}<br /></div><br /><br />when i run it, it doesn't generate the proper verification (v=):<br />(mID is my numeric ID from Yubico when i generated an API key)<br /><br /><div class="codetitle"><b>Code:</b></div><div class="codecontent">perl YubicoAuthClient.pl myID fghbibnivrtkrvdetdhcrfrklgcrkrkrvrchiriitdkt<br /><br />OTP verification ok<br />h=di+/stO00nh4oDaqA+7sJ24TI0Y=<br />t=2008-07-09T02:33:19Z0762<br />status=OK<br /><br />v=JsUPm4RnBwwOIDodGYEf2MDYFFI=<br /></div><br /><br />i guess my question is, am i passing the right info to the hash and base64 functions?  am i missing something here?<p>Statistics: Posted by <a href="https://forum.yubico.com/memberlist.php?mode=viewprofile&amp;u=194">gorkab</a> — Mon Jul 07, 2008 7:26 pm</p><hr />
]]></content>
</entry>
</feed>