<?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=2610" />

<title>Yubico Forum</title>
<subtitle>...visit our web-store at</subtitle>
<link href="https://forum.yubico.com/index.php" />
<updated>2017-03-23T17:28:59+01:00</updated>

<author><name><![CDATA[Yubico Forum]]></name></author>
<id>https://forum.yubico.com/feed.php?f=5&amp;t=2610</id>
<entry>
<author><name><![CDATA[bmahf]]></name></author>
<updated>2017-03-23T17:28:59+01:00</updated>
<published>2017-03-23T17:28:59+01:00</published>
<id>https://forum.yubico.com/viewtopic.php?t=2610&amp;p=9494#p9494</id>
<link href="https://forum.yubico.com/viewtopic.php?t=2610&amp;p=9494#p9494"/>
<title type="html"><![CDATA[[Q] Variable response from OTP challenge w fixed config]]></title>

<content type="html" xml:base="https://forum.yubico.com/viewtopic.php?t=2610&amp;p=9494#p9494"><![CDATA[
I'm working on a Qt5 with Win32 project on Win7 using VS2010. I need to implement a simple OTP configuration on our YubiKeys such that they all have a fixed secret key that identifies the YubiKey as a known key.  I have gotten to the point where after importing the YubiClientAPI.dll library, I am able to detect if a key is inserted, get the key's serial#, perform an OTP challenge/response, and get current buffer.  The results seem to complement the results I get when I run the &quot;Sample YubiClientAPI MFC test container&quot; application compiled from the Samples folder.<br /><br />I have a couple things that I need to figure out about using the API in order to complete my project.  But the most important question I have is that, since my secret 16 byte key is constant on the YubiKey, and I keep getting back different byte strings every time I do a challenge, what do I do on the client end to get a constant expected string back that I can use for recognition.  I am assuming that there is something I'm doing wrong.  In the code below, you will see that I am randomizing the challenge string (see comment starting with &quot;NOTE:&quot;).  I have also commented the randomization out so that the challenge string is all zeroes.  Doesn't make a difference in the variability of the response string.<br /><br />I am also not sure how the &quot;Private Identity 6 byte Hex&quot; field is used in the authentication process?  Read the documentation, and I see when I run the &quot;YubiKey Personalization Tool&quot; that I can set that, but don't know how that affects the resulting response I get, and what it has to do with my client-side authentication process.<br /><br />If anyone can just give me an indication of what I should be looking at to figure this out, I would be very grateful.<br /><br /><div class="codetitle"><b>Code:</b></div><div class="codecontent">#include &lt;iomanip&gt;<br />#include &lt;sstream&gt;<br /><br />// NOTE: import done in header file<br />//#import &lt;YubiClientAPI.dll&gt; no_namespace, named_guids<br /><br />#define RESPONSE_LENGTH 16<br />#define CHALLENGE_LENGTH 6<br />#define CONFIG1 0<br />#define CONFIG2 1<br /><br />TestingYubikeyAPI::TestingYubikeyAPI(QWidget *parent)<br />    : QMainWindow(parent)<br />{<br />    ui.setupUi(this);<br /><br />   HRESULT hr = CoCreateInstance(CLSID_YubiClient, 0, CLSCTX_ALL, IID_IYubiClient, reinterpret_cast&lt;void **&gt;(&amp;m_yubiClient));<br /><br />   if (FAILED(hr))<br />    {<br />      _com_error er(hr);<br />        setValid(false);<br />   }<br />    else<br />        setValid(true);<br />    <br />    QObject::connect(ui.m_getOtpConf1PushButton, &amp;QPushButton::clicked, this, &amp;TestingYubikeyAPI::onGetOtpConfig1Clicked);<br />}<br /><br />void TestingYubikeyAPI::onGetOtpConfig1Clicked()<br />{<br />    BYTE challenge&#91;CHALLENGE_LENGTH&#93;;<br />    BYTE response&#91;RESPONSE_LENGTH&#93;;<br />    memset(challenge, 0, sizeof(challenge));<br />    memset(response, 0, sizeof(response));<br />    <br />    // NOTE: randomizing challenge<br />    BCryptGenRandom(NULL, challenge, CHALLENGE_LENGTH, BCRYPT_USE_SYSTEM_PREFERRED_RNG);<br /><br />    variant_t va;<br />    std::ostringstream os;<br />    std::stringstream os2;<br />    os &lt;&lt; std::hex &lt;&lt; std::setfill('0');<br />    for (DWORD i = 0; i &lt; CHALLENGE_LENGTH; i++)<br />    {<br />        os &lt;&lt; std::setw(2) &lt;&lt; (int)challenge&#91;i&#93;;<br />    }<br />    _bstr_t bstr(os.str().c_str());<br /><br />    TCHAR buf&#91;1024&#93;;<br />    va.bstrVal = bstr;<br />    va.vt = VT_BSTR;<br />    m_yubiClient-&gt;PutdataEncoding(ycENCODING_BYTE_ARRAY);<br />    m_yubiClient-&gt;PutdataBuffer(va);<br />    ycRETCODE ret = m_yubiClient-&gt;GetotpChallenge(CONFIG1, ycCALL_BLOCKING);<br />   <br />    if (ret == ycRETCODE_OK)<br />    {<br />        getCurrentBuffer(challenge, 64);<br />    }<br />    else<br />    {<br />        ui.m_outputTextEdit-&gt;append(QString(&quot;Got No Data: retcode = %1&quot;).arg(translateRetCode(ret)));<br />    }<br />}<br /><br />void TestingYubikeyAPI::getCurrentBuffer(BYTE* pChallenge, int len)<br />{<br />    BYTE HUGEP *pb;<br />    long lbound, hbound;<br />    QString outstr;<br />    <br />    SafeArrayGetLBound(m_yubiClient-&gt;dataBuffer.parray, 1, &amp;lbound);<br />    SafeArrayGetUBound(m_yubiClient-&gt;dataBuffer.parray, 1, &amp;hbound);<br />    SafeArrayAccessData(m_yubiClient-&gt;dataBuffer.parray, (void **)&amp;pb);<br /><br />    for (; lbound &lt;= hbound; lbound++)<br />    {<br />        outstr = QString(&quot;%1%2 &quot;).arg(outstr).arg((uint)pb&#91;lbound&#93;, 2, 16, QLatin1Char('0'));<br />    }<br />    <br />    SafeArrayUnaccessData(m_yubiClient-&gt;dataBuffer.parray);<br />    ui.m_outputTextEdit-&gt;append(QString(&quot;Got Data: %1&quot;).arg(outstr));<br />}<br /></div><p>Statistics: Posted by <a href="https://forum.yubico.com/memberlist.php?mode=viewprofile&amp;u=4623">bmahf</a> — Thu Mar 23, 2017 5:28 pm</p><hr />
]]></content>
</entry>
</feed>