<?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=5&amp;t=2393" />

<title>Yubico Forum</title>
<subtitle>...visit our web-store at</subtitle>
<link href="https://forum.yubico.com/index.php" />
<updated>2016-08-11T20:07:25+01:00</updated>

<author><name><![CDATA[Yubico Forum]]></name></author>
<id>https://forum.yubico.com/feed.php?f=5&amp;t=2393</id>
<entry>
<author><name><![CDATA[evile]]></name></author>
<updated>2016-08-11T20:07:00+01:00</updated>
<published>2016-08-11T20:07:00+01:00</published>
<id>https://forum.yubico.com/viewtopic.php?t=2393&amp;p=8873#p8873</id>
<link href="https://forum.yubico.com/viewtopic.php?t=2393&amp;p=8873#p8873"/>
<title type="html"><![CDATA[Re: [QUESTION] - GethmacSha1 API returning ycRETCODE_FAILED]]></title>

<content type="html" xml:base="https://forum.yubico.com/viewtopic.php?t=2393&amp;p=8873#p8873"><![CDATA[
Solved.  The YubiKey I was using was not personalized for hmac-sha1 using the yubikey-personalization-gui.<p>Statistics: Posted by <a href="https://forum.yubico.com/memberlist.php?mode=viewprofile&amp;u=4434">evile</a> — Thu Aug 11, 2016 8:07 pm</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[evile]]></name></author>
<updated>2016-08-11T20:07:25+01:00</updated>
<published>2016-08-11T17:30:10+01:00</published>
<id>https://forum.yubico.com/viewtopic.php?t=2393&amp;p=8872#p8872</id>
<link href="https://forum.yubico.com/viewtopic.php?t=2393&amp;p=8872#p8872"/>
<title type="html"><![CDATA[[SOLVED] - GethmacSha1 API returning ycRETCODE_FAILED]]></title>

<content type="html" xml:base="https://forum.yubico.com/viewtopic.php?t=2393&amp;p=8872#p8872"><![CDATA[
All, <br /><br />I'm working with the Windows COM library and trying to use the GethmacSha1 API function.  I'm receiving the ycRETCODE_FAILED error code.<br /><br />I've copy and pasted the DoChallengeResponse from <!-- m --><a class="postlink" href="https://github.com/Yubico/yubico-windows-auth/blob/master/yubiprovider/YubiKeyMsvsubauth/SubAuth.cpp">https://github.com/Yubico/yubico-window ... ubAuth.cpp</a><!-- m --> into my my project and when I call it, it consistently returns false.  The false return code is due to the call to GethmacSha1 failing with ycRETCODE_FAILED.  The Windows COM library does not appear to be on github, so thats why I posting this message here.  <br /><br />I'm using Windows 10 64bit<br />I've tried both 32 and 64bit version of the COM library.<br />yubikey-client-API_x64-4.1.0.msi<br />yubikey-client-API_x86-4.1.0.msi<br /><br />My code which is below checks to see if a device is present, gets the serial number, and then attempts to call the GethmacSha1 function.  <br /><br />Output:<br />Found YubiKey Serial#: 004bXXXX<br />Do challenge failed<br /><br />Can anyone tell me what I'm doing wrong.<br /><br />Thanks.<br /><br /><div class="codetitle"><b>Code:</b></div><div class="codecontent">#include &lt;Windows.h&gt;<br />#include &lt;iostream&gt;<br />#include &lt;sstream&gt;<br />#include &lt;string&gt;<br />#include &lt;iomanip&gt;<br />#include &quot;ykdef.h&quot;<br /><br />#import &lt;YubiClientAPI.dll&gt; no_namespace, named_guids<br /><br />using namespace std;<br /><br />IYubiClient* api;<br /><br />bool DoChallengeResponse(__in BYTE* challenge, __out BYTE* response, __in DWORD len)<br />{<br />   bool res = true;<br />   variant_t va;<br />   ostringstream os;<br />   os &lt;&lt; hex &lt;&lt; setfill('0');<br />   for (DWORD i = 0; i &lt; len; i++) {<br />      os &lt;&lt; setw(2) &lt;&lt; int(challenge&#91;i&#93;);<br />   }<br />   _bstr_t bstr(os.str().c_str());<br /><br />   va.bstrVal = bstr;<br />   va.vt = VT_BSTR;<br />   api-&gt;PutdataEncoding(ycENCODING_BYTE_ARRAY);<br />   api-&gt;PutdataBuffer(va);<br />   ycRETCODE ret = api-&gt;GethmacSha1(2, ycCALL_BLOCKING);<br />   if (ret == ycRETCODE_OK) {<br />      BYTE HUGEP *pb;<br />      long lbound, hbound;<br />      SafeArrayGetLBound(api-&gt;dataBuffer.parray, 1, &amp;lbound);<br />      SafeArrayGetUBound(api-&gt;dataBuffer.parray, 1, &amp;hbound);<br />      SafeArrayAccessData(api-&gt;dataBuffer.parray, (void **)&amp;pb);<br />      for (; lbound &lt;= hbound; lbound++) {<br />         *response++ = *pb++;<br />      }<br />      SafeArrayUnaccessData(api-&gt;dataBuffer.parray);<br />      res = true;<br />   }<br />   else {<br />      res = false;<br />   }<br /><br />   return res;<br />}<br /><br />int main()<br />{<br />   CoInitializeEx(NULL, COINIT_MULTITHREADED);<br />   HRESULT h = CoCreateInstance(CLSID_YubiClient, 0, CLSCTX_ALL, IID_IYubiClient, reinterpret_cast&lt;void **&gt;(&amp;api));<br />   if (FAILED(h)) {<br />      CoUninitialize();<br />   }<br /><br />   ycRETCODE ret = api-&gt;GetisInserted();<br />   if (ret == ycRETCODE_NO_DEVICE)<br />   {<br />      cout &lt;&lt; &quot;No yubikey device found&quot; &lt;&lt; endl;<br />      CoUninitialize();<br />      return -1;<br />   }<br /><br />   api-&gt;dataEncoding = ycENCODING::ycENCODING_UINT32;<br />   ret = api-&gt;GetreadSerial(ycCALL_MODE::ycCALL_BLOCKING);<br />   cout &lt;&lt; &quot;Found YubiKey Serial#: &quot; &lt;&lt; setw(8) &lt;&lt; setfill('0') &lt;&lt; hex &lt;&lt; api-&gt;dataBuffer.intVal &lt;&lt; endl;<br /><br />   DWORD len = 64;<br />   BYTE challenge&#91;128&#93;;<br />   BYTE response&#91;128&#93;;<br />   memset(challenge, 0, sizeof(challenge));<br />   memset(response, 0, sizeof(response));<br />   BCryptGenRandom(NULL, challenge, len, BCRYPT_USE_SYSTEM_PREFERRED_RNG);<br />   <br />   if (DoChallengeResponse(challenge, response, 63))<br />   {<br />      cout &lt;&lt; &quot;Do challange worked&quot; &lt;&lt; endl;<br />   }<br />   else<br />   {<br />      cout &lt;&lt; &quot;Do challenge failed&quot; &lt;&lt; endl;<br />   }<br />   <br />   return 0;<br />}<br /></div><p>Statistics: Posted by <a href="https://forum.yubico.com/memberlist.php?mode=viewprofile&amp;u=4434">evile</a> — Thu Aug 11, 2016 5:30 pm</p><hr />
]]></content>
</entry>
</feed>