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

<title>Yubico Forum</title>
<subtitle>...visit our web-store at</subtitle>
<link href="https://forum.yubico.com/index.php" />
<updated>2015-03-13T08:07:40+01:00</updated>

<author><name><![CDATA[Yubico Forum]]></name></author>
<id>https://forum.yubico.com/feed.php?f=33&amp;t=1778</id>
<entry>
<author><name><![CDATA[henrik]]></name></author>
<updated>2015-03-13T08:07:40+01:00</updated>
<published>2015-03-13T08:07:40+01:00</published>
<id>https://forum.yubico.com/viewtopic.php?t=1778&amp;p=7019#p7019</id>
<link href="https://forum.yubico.com/viewtopic.php?t=1778&amp;p=7019#p7019"/>
<title type="html"><![CDATA[Re: [Solved] U2F Signing algorithm with .NET lib]]></title>

<content type="html" xml:base="https://forum.yubico.com/viewtopic.php?t=1778&amp;p=7019#p7019"><![CDATA[
Great! Glad I could help <img src="https://forum.yubico.com/images/smilies/icon_e_smile.gif" alt=":)" title="Smile" /><p>Statistics: Posted by <a href="https://forum.yubico.com/memberlist.php?mode=viewprofile&amp;u=2968">henrik</a> — Fri Mar 13, 2015 8:07 am</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[bbartlett]]></name></author>
<updated>2015-03-12T19:40:26+01:00</updated>
<published>2015-03-12T19:40:26+01:00</published>
<id>https://forum.yubico.com/viewtopic.php?t=1778&amp;p=7015#p7015</id>
<link href="https://forum.yubico.com/viewtopic.php?t=1778&amp;p=7015#p7015"/>
<title type="html"><![CDATA[Re: U2F Signing algorithm with .NET lib]]></title>

<content type="html" xml:base="https://forum.yubico.com/viewtopic.php?t=1778&amp;p=7015#p7015"><![CDATA[
This code returned the correct results in VerifySignature!!!  I applied the same changes to both the Register and Sign pages and both return the correct responses.  I also checked that a false value is returned for VerifySignature() if the Signature array is reversed. Thank you so much for your help.<br /><br />            byte[] appIdHash = Encoding.ASCII.GetBytes(appId);<br />            byte[] clientHash = Encoding.ASCII.GetBytes(clientData);<br /><br />            byte[] signedBytes = PackBytesToSign(<br />                U2F.Crypto.Hash(appIdHash),<br />                U2F.Crypto.Hash(clientHash),<br />                KeyHandle,<br />                UserPublicKey<br />                );<p>Statistics: Posted by <a href="https://forum.yubico.com/memberlist.php?mode=viewprofile&amp;u=3155">bbartlett</a> — Thu Mar 12, 2015 7:40 pm</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[bbartlett]]></name></author>
<updated>2015-03-12T19:11:08+01:00</updated>
<published>2015-03-12T19:11:08+01:00</published>
<id>https://forum.yubico.com/viewtopic.php?t=1778&amp;p=7014#p7014</id>
<link href="https://forum.yubico.com/viewtopic.php?t=1778&amp;p=7014#p7014"/>
<title type="html"><![CDATA[Re: U2F Signing algorithm with .NET lib]]></title>

<content type="html" xml:base="https://forum.yubico.com/viewtopic.php?t=1778&amp;p=7014#p7014"><![CDATA[
?appId<br />&quot;http://localhost:52701&quot;<br /><br />?Utils.ByteArrayToBase64String(U2F.Crypto.Hash(appId))<br />&quot;ENIbQIWZ9ZHrY48rknvb_PjHS6RGN-wkcKM_n0gjCHw&quot;<br /><br /><br />The results of Crypto.Hash are different between Java and .NET code.  Here is the .NET code.<br /><br />       private readonly SHA256Managed _sha256Managed = new SHA256Managed();<br /><br />       public byte[] Hash(byte[] bytes)<br />        {<br />            try<br />            {<br />                return _sha256Managed.ComputeHash(bytes);<br />            }<br />            catch (Exception e)<br />            {<br />                throw new UnsupportedOperationException(&quot;Error when computing SHA-256&quot;, e);<br />            }<br />        }<br /><br />        public byte[] Hash(string str)<br />        {<br />            byte[] bytes = new byte[str.Length*sizeof (char)];<br />            Buffer.BlockCopy(str.ToCharArray(), 0, bytes, 0, bytes.Length);<br /><br />            return Hash(bytes);<br />        }<p>Statistics: Posted by <a href="https://forum.yubico.com/memberlist.php?mode=viewprofile&amp;u=3155">bbartlett</a> — Thu Mar 12, 2015 7:11 pm</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[henrik]]></name></author>
<updated>2015-03-12T13:39:51+01:00</updated>
<published>2015-03-12T13:39:51+01:00</published>
<id>https://forum.yubico.com/viewtopic.php?t=1778&amp;p=7012#p7012</id>
<link href="https://forum.yubico.com/viewtopic.php?t=1778&amp;p=7012#p7012"/>
<title type="html"><![CDATA[Re: U2F Signing algorithm with .NET lib]]></title>

<content type="html" xml:base="https://forum.yubico.com/viewtopic.php?t=1778&amp;p=7012#p7012"><![CDATA[
<div class="quotetitle">bbartlett wrote:</div><div class="quotecontent"><br />32 bytes hash(appId)<br /><!-- m --><a class="postlink" href="http://localhost:52701">http://localhost:52701</a><!-- m --><br /><br />32 bytes hash(clientdata):<br />{\&quot;typ\&quot;:\&quot;navigator.id.finishEnrollment\&quot;,\&quot;challenge\&quot;:\&quot;2ScxHgONm6HWi-69dl-u8MHJStWczxjyqVYc1Jywnyc\&quot;,\&quot;origin\&quot;:\&quot;http://localhost:52701\&quot;,\&quot;cid_pubkey\&quot;:\&quot;\&quot;}<br /></div><br />Are you not hashing these values (you have to)? Please give me the hash of them. Judging from where the difference occurs in bytesToSign, I suspect that these two values are the problem. Maybe brucedog/u2flib's BouncyCastleCrypto.Hash(string) does not output the same as yubico/java-u2flib-server's BouncyCastleCrypto.hash(String).<br /><br />The correct hashes of the strings you posted are:<br /><div class="codetitle"><b>Code:</b></div><div class="codecontent">appIdHash: 1nUt4iGiZ2xQwcNThBvg9jgGnISM-w3K3se9csoSn7s<br />clientDataHash: LBQ8iUMFH6ZfAucUwHa0rwO23Uwnzcdp5bWNQ3T57Xc</div><p>Statistics: Posted by <a href="https://forum.yubico.com/memberlist.php?mode=viewprofile&amp;u=2968">henrik</a> — Thu Mar 12, 2015 1:39 pm</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[henrik]]></name></author>
<updated>2015-03-12T13:33:28+01:00</updated>
<published>2015-03-12T13:33:28+01:00</published>
<id>https://forum.yubico.com/viewtopic.php?t=1778&amp;p=7011#p7011</id>
<link href="https://forum.yubico.com/viewtopic.php?t=1778&amp;p=7011#p7011"/>
<title type="html"><![CDATA[Re: U2F Signing algorithm with .NET lib]]></title>

<content type="html" xml:base="https://forum.yubico.com/viewtopic.php?t=1778&amp;p=7011#p7011"><![CDATA[
I fed the Java library with the data you posted above. It verifies the signature successfully. KeyHandle and publicKey are the same but not <em>bytesToSign</em>:<br /><br /><div class="codetitle"><b>Code:</b></div><div class="codecontent">// bytesToSign from the .NET library:<br />ABDSG0CFmfWR62OPK5J72_z4x0ukRjfsJHCjP59IIwh8zGCun1fxQS1HuBc1lXcbueGEoLZ2ToBbDJUUnzvCbwC<br />KnUFv5Te81rlgybzl64ukOCFbqd0JALAODVfXNU7k6X3PVXshB8oWg0zm7mruZ5cfXh6RhWohd6gRKfm3N0zVBLg3U0ZhQ6vOIv4UkQGIHguVvNegGt_gj2T6W1Syk45is0PBG1i89FzLFzGsK5YO8A4raeC-O4QmCnaKnieT0fA<br /><br />// bytesToSign from the Java library:<br />ANZ1LeIhomdsUMHDU4Qb4PY4BpyEjPsNyt7HvXLKEp-7LBQ8iUMFH6ZfAucUwHa0rwO23Uwnzcdp5bWNQ3T57Xe<br />KnUFv5Te81rlgybzl64ukOCFbqd0JALAODVfXNU7k6X3PVXshB8oWg0zm7mruZ5cfXh6RhWohd6gRKfm3N0zVBLg3U0ZhQ6vOIv4UkQGIHguVvNegGt_gj2T6W1Syk45is0PBG1i89FzLFzGsK5YO8A4raeC-O4QmCnaKnieT0fA</div><br />I added line breaks to highlight which parts that differs.<p>Statistics: Posted by <a href="https://forum.yubico.com/memberlist.php?mode=viewprofile&amp;u=2968">henrik</a> — Thu Mar 12, 2015 1:33 pm</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[bbartlett]]></name></author>
<updated>2015-03-12T02:31:54+01:00</updated>
<published>2015-03-12T02:31:54+01:00</published>
<id>https://forum.yubico.com/viewtopic.php?t=1778&amp;p=7008#p7008</id>
<link href="https://forum.yubico.com/viewtopic.php?t=1778&amp;p=7008#p7008"/>
<title type="html"><![CDATA[Re: U2F Signing algorithm with .NET lib]]></title>

<content type="html" xml:base="https://forum.yubico.com/viewtopic.php?t=1778&amp;p=7008#p7008"><![CDATA[
Here are some values from a registration.<br /><br />RegistrationData (745 bytes):<br />BQS4N1NGYUOrziL-FJEBiB4LlbzXoBrf4I9k-ltUspOOYrNDwRtYvPRcyxcxrCuWDvAOK2ngvjuEJgp2ip4nk9HwQIqdQW_lN7zWuWDJvOXri6Q4IVup3QkAsA4NV9c1TuTpfc9VeyEHyhaDTObuau5nlx9eHpGFaiF3qBEp-bc3TNUwggIcMIIBBqADAgECAgQ4Zt91MAsGCSqGSIb3DQEBCzAuMSwwKgYDVQQDEyNZdWJpY28gVTJGIFJvb3QgQ0EgU2VyaWFsIDQ1NzIwMDYzMTAgFw0xNDA4MDEwMDAwMDBaGA8yMDUwMDkwNDAwMDAwMFowKzEpMCcGA1UEAwwgWXViaWNvIFUyRiBFRSBTZXJpYWwgMTM4MzExNjc4NjEwWTATBgcqhkjOPQIBBggqhkjOPQMBBwNCAAQ3jfx0DHOblHJO09Ujubh2gQZWwT3ob6-uzzjZD1XiyAob_gsw3FOzXefQRblty48r-U-o4LkDFjx_btwuSHtxoxIwEDAOBgorBgEEAYLECgEBBAAwCwYJKoZIhvcNAQELA4IBAQIaR2TKAInPkq24f6hIU45yzD79uzR5KUMEe4IWqTm69METVio0W2FHWXlpeUe85nGqanwGeW7U67G4_WAnGbcd6zz2QumNsdlmb_AebbdPRa95Z8BG1ub_S04JoxQYNLaa8WRlzN7POgqAnAqkmnsZQ_W9Tj2uO9zP3mpxOkkmnqz7P5zt4Lp5xrv7p15hGOIPD5V-ph7tUmiCJsq0LfeRA36X7aXi32Ap0rt_wyfnRef59YYr7SmwaMuXKjbIZSLesscZZTMzXd-uuLb6DbUCasqEVBkGGqTRfAcOmPov1nHUrNDCkOR0obR4PsJG4PiamIfApNeoXGYpGbok6nucMEQCIHA2eDMSEyuCBPKfBD5PkZROH_qvk8_57WNIV3rzdMupAiA8f3mPVHvO-DWh5xwl-6zZrTHBtadEBlxdogCvkWCiQw<br /><br /><br />Header (1 byte): 0x05<br /><br />Public Key  (65 bytes):<br />BLg3U0ZhQ6vOIv4UkQGIHguVvNegGt_gj2T6W1Syk45is0PBG1i89FzLFzGsK5YO8A4raeC-O4QmCnaKnieT0fA<br /><br />Key handle length (1 byte): 0x40 (64)<br /><br />Key handle (64 bytes):<br />ip1Bb-U3vNa5YMm85euLpDghW6ndCQCwDg1X1zVO5Ol9z1V7IQfKFoNM5u5q7meXH14ekYVqIXeoESn5tzdM1Q<br /><br />X509 certificate (544 bytes):<br /><br />Signature (70 bytes):<br />MEQCIHA2eDMSEyuCBPKfBD5PkZROH_qvk8_57WNIV3rzdMupAiA8f3mPVHvO-DWh5xwl-6zZrTHBtadEBlxdogCvkWCiQw<br /><br />1+65+1+64+544+70 = 745<br /><br />Verify Register Signature <br /><br />BytesToSign (194 bytes):<br />1 byte 0x00<br /><br />32 bytes hash(appId)<br /><!-- m --><a class="postlink" href="http://localhost:52701">http://localhost:52701</a><!-- m --><br /><br />32 bytes hash(clientdata):<br />{\&quot;typ\&quot;:\&quot;navigator.id.finishEnrollment\&quot;,\&quot;challenge\&quot;:\&quot;2ScxHgONm6HWi-69dl-u8MHJStWczxjyqVYc1Jywnyc\&quot;,\&quot;origin\&quot;:\&quot;http://localhost:52701\&quot;,\&quot;cid_pubkey\&quot;:\&quot;\&quot;}<br /><br />64 bytes key handle:<br />ip1Bb-U3vNa5YMm85euLpDghW6ndCQCwDg1X1zVO5Ol9z1V7IQfKFoNM5u5q7meXH14ekYVqIXeoESn5tzdM1Q<br /><br />65 bytes public key:<br />BLg3U0ZhQ6vOIv4UkQGIHguVvNegGt_gj2T6W1Syk45is0PBG1i89FzLFzGsK5YO8A4raeC-O4QmCnaKnieT0fA<br /><br />BytesToSign (194 bytes):<br />ABDSG0CFmfWR62OPK5J72_z4x0ukRjfsJHCjP59IIwh8zGCun1fxQS1HuBc1lXcbueGEoLZ2ToBbDJUUnzvCbwCKnUFv5Te81rlgybzl64ukOCFbqd0JALAODVfXNU7k6X3PVXshB8oWg0zm7mruZ5cfXh6RhWohd6gRKfm3N0zVBLg3U0ZhQ6vOIv4UkQGIHguVvNegGt_gj2T6W1Syk45is0PBG1i89FzLFzGsK5YO8A4raeC-O4QmCnaKnieT0fA<br /><br /><br />VerifySignature fails!!<p>Statistics: Posted by <a href="https://forum.yubico.com/memberlist.php?mode=viewprofile&amp;u=3155">bbartlett</a> — Thu Mar 12, 2015 2:31 am</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[bbartlett]]></name></author>
<updated>2015-03-12T01:18:03+01:00</updated>
<published>2015-03-12T01:18:03+01:00</published>
<id>https://forum.yubico.com/viewtopic.php?t=1778&amp;p=7007#p7007</id>
<link href="https://forum.yubico.com/viewtopic.php?t=1778&amp;p=7007#p7007"/>
<title type="html"><![CDATA[Re: U2F Signing algorithm with .NET lib]]></title>

<content type="html" xml:base="https://forum.yubico.com/viewtopic.php?t=1778&amp;p=7007#p7007"><![CDATA[
The FIDO specification for RawMessages Registration section 4.3 states &quot;The signature is to be verified by the relying party using the public key certified in the attestation certificate.&quot;  Shouldn't the public key in the attestation certificate match the public key returned in the device response?  <br /><br />The following code checks the signature during Registration.   pKey1 is the public key from the device RegistrationData bytes 1-65 and pKey2 is the AttestationCertificate public key value.  They are not equal (pKeyVerify is false).  I try to verify the signature with pKey1 and pKey2 and both results are false.  pKey1 is the value that is persisted in the database for the user device and later retrieved for authentication.<br /><br />        public bool CheckSignature(String appId, String clientData)<br />        {<br />            byte[] signedBytes = PackBytesToSign(<br />                U2F.Crypto.Hash(appId), <br />                U2F.Crypto.Hash(clientData),<br />                KeyHandle,<br />                UserPublicKey<br />                );<br /><br />            ICipherParameters pKey1 = U2F.Crypto.DecodePublicKey(UserPublicKey);<br />            ICipherParameters pKey2 = AttestationCertificate.GetPublicKey();<br />            bool pKeyVerify = (pKey1 == pKey2);<br /><br />            bool check1 = U2F.Crypto.CheckSignature(<br />                pKey1,<br />                signedBytes,<br />                Signature<br />                );<br /><br />            bool check2 = U2F.Crypto.CheckSignature(<br />                pKey2,<br />                signedBytes,<br />                Signature<br />                );<br /><br />            return (check1 || check2);<br />        }<p>Statistics: Posted by <a href="https://forum.yubico.com/memberlist.php?mode=viewprofile&amp;u=3155">bbartlett</a> — Thu Mar 12, 2015 1:18 am</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[bbartlett]]></name></author>
<updated>2015-03-11T23:17:35+01:00</updated>
<published>2015-03-11T23:17:35+01:00</published>
<id>https://forum.yubico.com/viewtopic.php?t=1778&amp;p=7005#p7005</id>
<link href="https://forum.yubico.com/viewtopic.php?t=1778&amp;p=7005#p7005"/>
<title type="html"><![CDATA[Re: U2F Signing algorithm with .NET lib]]></title>

<content type="html" xml:base="https://forum.yubico.com/viewtopic.php?t=1778&amp;p=7005#p7005"><![CDATA[
Yes, these values return a true result and if I reverse the signature it returns a false result (Check2 is true and Check3 is false).  I also checked the public key x and y values and they matched your values.  This indicates the Bouncy Castle code is working properly.  We must marshaling the values incorrectly in our code.  I also noticed that the  signedBytes[33-36] stored the counter in big endian as we expected.  Thank you.<br /><br />            Signature = Utils.Base64StringToByteArray(&quot;MEUCIQCHR7QtUrcPfPY3UEF_IxmxECKc2Ody8b-M3I1LAahuTgIgWz0Oc_3SovRj1kLflA2wjvox3pb1n1UuhcPD1YDH1FU=&quot;);<br />            publicKey = Utils.Base64StringToByteArray(&quot;BAARhpOKSZZ4RBs_uPUq79rttBCjJMPsmK9Guquc2_ugfZPz60TBqKRLl-2FSYKN-HEEGf7AfMtYGeaMWIDO3jA=&quot;);<br />            signedBytes = Utils.Base64StringToByteArray(&quot;TJp1zKcX77aMhW8muoJQc39E5pgNMxk8lPoLjpzXYYwBAAAAAepBdB9rg8Ena3vY5hyD09-N3vva-7yGE8LvydFuPTkM&quot;);<br /><br />            bool Check2 = U2F.Crypto.CheckSignature(<br />                U2F.Crypto.DecodePublicKey(publicKey),<br />                signedBytes,<br />                Signature<br />                );<br /><br />            Array.Reverse(Signature);<br /><br />            bool Check3 = U2F.Crypto.CheckSignature(<br />                U2F.Crypto.DecodePublicKey(publicKey),<br />                signedBytes,<br />                Signature<br />                );<p>Statistics: Posted by <a href="https://forum.yubico.com/memberlist.php?mode=viewprofile&amp;u=3155">bbartlett</a> — Wed Mar 11, 2015 11:17 pm</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[henrik]]></name></author>
<updated>2015-03-11T08:27:11+01:00</updated>
<published>2015-03-11T08:27:11+01:00</published>
<id>https://forum.yubico.com/viewtopic.php?t=1778&amp;p=7000#p7000</id>
<link href="https://forum.yubico.com/viewtopic.php?t=1778&amp;p=7000#p7000"/>
<title type="html"><![CDATA[Re: U2F Signing algorithm with .NET lib]]></title>

<content type="html" xml:base="https://forum.yubico.com/viewtopic.php?t=1778&amp;p=7000#p7000"><![CDATA[
Ok, now I understand the background <img src="https://forum.yubico.com/images/smilies/icon_e_smile.gif" alt=":)" title="Smile" /><br /><br />A few thoughts:<br /><br /><ul><li>Have you seen <a href="https://github.com/hanswolff/fido-u2f-net" class="postlink">this new .NET U2F library</a>? Not sure how complete it is, but it might be useful to have a look at the code.<br /></li><li>In U2F registrations, the data returned from the U2F device is signed by the attestation certificate. In U2F authentications, the data returned from the U2F device is signed by the public key (this public key is <br />completely unrelated to the attestation certificate).<br /></li><li>I extracted some data from <em>SoftKeyTest.shouldAuthenticate()</em> in the Java implementation. Let me know if the data below signs successfully for you as well.</li></ul><div class="codetitle"><b>Code:</b></div><div class="codecontent">signedBytes: TJp1zKcX77aMhW8muoJQc39E5pgNMxk8lPoLjpzXYYwBAAAAAepBdB9rg8Ena3vY5hyD09-N3vva-7yGE8LvydFuPTkM<br />signature: MEUCIQCHR7QtUrcPfPY3UEF_IxmxECKc2Ody8b-M3I1LAahuTgIgWz0Oc_3SovRj1kLflA2wjvox3pb1n1UuhcPD1YDH1FU=<br />publicKey: BAARhpOKSZZ4RBs_uPUq79rttBCjJMPsmK9Guquc2_ugfZPz60TBqKRLl-2FSYKN-HEEGf7AfMtYGeaMWIDO3jA=<br />publicKey decoded: EC Public Key<br />            X: 1186938a499678441b3fb8f52aefdaedb410a324c3ec98af46baab9cdbfba0<br />            Y: 7d93f3eb44c1a8a44b97ed8549828df8710419fec07ccb5819e68c5880cede30</div><br /><br />This is how this data was used:<br /><div class="codetitle"><b>Code:</b></div><div class="codecontent">System.out.println(&quot;signedBytes: &quot; + BaseEncoding.base64Url().encode(signedBytes));<br />System.out.println(&quot;signature: &quot; + BaseEncoding.base64Url().encode(signature));<br />System.out.println(&quot;publicKey: &quot; + BaseEncoding.base64Url().encode(publicKey));<br />System.out.println(&quot;publicKey decoded: &quot; + crypto.decodePublicKey(publicKey));<br /><br />crypto.checkSignature(<br />        crypto.decodePublicKey(publicKey),<br />        signedBytes,<br />        signature<br />);</div><p>Statistics: Posted by <a href="https://forum.yubico.com/memberlist.php?mode=viewprofile&amp;u=2968">henrik</a> — Wed Mar 11, 2015 8:27 am</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[bbartlett]]></name></author>
<updated>2015-03-10T18:12:50+01:00</updated>
<published>2015-03-10T18:12:50+01:00</published>
<id>https://forum.yubico.com/viewtopic.php?t=1778&amp;p=6996#p6996</id>
<link href="https://forum.yubico.com/viewtopic.php?t=1778&amp;p=6996#p6996"/>
<title type="html"><![CDATA[Re: U2F Signing algorithm with .NET lib]]></title>

<content type="html" xml:base="https://forum.yubico.com/viewtopic.php?t=1778&amp;p=6996#p6996"><![CDATA[
Thank you for the prompt and thorough reply.  I understand the .NET code is not Yubico code.  I have been working directly with the .NET developer for several weeks to troubleshoot the calls into the Bouncy Castle library to verify the signature returned from the Yubikey.  The .NET code has been ported from your Java solution.  We have tried two methods to load the public key, directly and from the attestation certificate.  Both attempts fail to produce expected results.  We just wanted to make sure that we are using the correct algorithm selection in Bouncy Castle.  <br /><br />There is a bug somewhere in the .NET implementation and we are trying to determine if is the signing algorithm, the public key, the bytes to be signed, or the signature.<br /><br />The signing algorithm is defined here.  <br />private readonly ISigner _signer = SignerUtilities.GetSigner(&quot;SHA-256withECDSA&quot;);<br /><br />The signature comes right out of Yubikey device response JSON object.<br /><br />The public key is retrieved from the device registration information, and decoded from the byte array encodedPublicKey[].  The DecodePublicKey method is not throwing errors, so we are confident that the public key is loading properly.<br />                    private readonly DerObjectIdentifier _curve = SecObjectIdentifiers.SecP256r1;<br />                    X9ECParameters curve = SecNamedCurves.GetByOid(_curve);<br />                    ECPoint point = curve.Curve.DecodePoint(encodedPublicKey);<br />                    ECDomainParameters ecP = new ECDomainParameters(curve.Curve, curve.G, curve.N, curve.H);<br />                    return new ECPublicKeyParameters(point, ecP);<br /><br />The bytes to be signed are assembled as follows.  We have read the FIDO specification and believe this is correct.  32 bytes the hash of the appid.  1 byte indicating UserPresence 0x01 (binary 1).  4 bytes indicating the counter in big endian format such as 0x0009 (binary 9).  32 bytes the hash of the clientData.  This results in 69 bytes.  Since this pattern has to match exactly what takes place on the Yubikey to generate the signature, it is most likely where the problem occurs.<br />            byte[] signedBytes = PackBytesToSign(<br />                U2F.Crypto.Hash(Encoding.ASCII.GetBytes(appId)),<br />                UserPresence,<br />                Counter,<br />                U2F.Crypto.Hash(Encoding.ASCII.GetBytes(clientData)));<br /><br />Let me describe what I perceive the expected results to be.  If the 4 values (algorithm, public key, bytes to sign, signature) are correctly assembled, the verification should be true.  Changing 1 or more bytes in the signature byte array should return false.  We have not been able to achieve these results.  If we load the public key directly, the result is always false.  If we load the load the X509 certificate, the result is always true.  <br /><br />The fact that the results change depending on how we load the public key with the other 3 values unchanged, indicates that the public key is not being loaded correctly in one of the two methods, but we can't determine which one is incorrect.  In the case where the signature verifies true, when we reverse the entire signature array, the result is still true.  That is clearly not valid.<br /><br />I know it is not Yubico's responsibility to fix this, but I am hoping there is another .NET programmer who I might get in contact with through the forum.<p>Statistics: Posted by <a href="https://forum.yubico.com/memberlist.php?mode=viewprofile&amp;u=3155">bbartlett</a> — Tue Mar 10, 2015 6:12 pm</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[henrik]]></name></author>
<updated>2015-03-10T11:17:59+01:00</updated>
<published>2015-03-10T11:17:59+01:00</published>
<id>https://forum.yubico.com/viewtopic.php?t=1778&amp;p=6990#p6990</id>
<link href="https://forum.yubico.com/viewtopic.php?t=1778&amp;p=6990#p6990"/>
<title type="html"><![CDATA[Re: U2F Signing algorithm]]></title>

<content type="html" xml:base="https://forum.yubico.com/viewtopic.php?t=1778&amp;p=6990#p6990"><![CDATA[
<div class="quotetitle">bbartlett wrote:</div><div class="quotecontent"><br />I am using the .NET library published on your developer pages.<br /></div><br />Just to be clear: We are linking to the .NET library from developers.yubico.com. Yubico is not the publisher of that library.<br /><br /><div class="quotetitle">bbartlett wrote:</div><div class="quotecontent"><br />(2) A correct implementation of U2F by a relying party to authenticate users would require the following, (a) persistence of the key handle, public key and attestation certificate created during registration (from window.u2f.register)<br /></div><br />They key handle and the public key has to be persisted, but usually a U2F library will collect this data in an object (called <em>DeviceRegistration</em> or similar). As a user of a library, you should only have to persist this object. See code example <a href="https://developers.yubico.com/U2F/Libraries/Using_a_library.html#_server_side" class="postlink">here</a>.<br /><br />The attestation certificate can, but does not have to, be persisted.<br /><br /><div class="quotetitle">bbartlett wrote:</div><div class="quotecontent"><br />(b) no error code returned during authentication (from window.u2f.sign)<br /></div><br />Well... If an error code is returned by the browser, there will be no signature and thus the next step will fail.<br /><br /><div class="quotetitle">bbartlett wrote:</div><div class="quotecontent"><br />(c) verify the digital signature returned from the Yubikey sign operation using a crypto library such as Bouncy Castle.<br /></div><br />Once again, this should be handled by the U2F library. You should not have to deal with crypto libraries yourself. The only thing you should have to do is something like this:<br /><div class="codetitle"><b>Code:</b></div><div class="codecontent">u2f_lib.finish_authentication(challenge, device_response, registered_devices)</div><br />This will code will throw an exception if the signature was invalid.<br /><br />I'm not familiar with the .NET library, but it <a href="https://github.com/brucedog/u2flib/blob/master/DemoU2FSite/Controllers/HomeController.cs#L87" class="postlink">seems like</a> this is the way the demo server of that libarary does it:<br /><div class="codetitle"><b>Code:</b></div><div class="codecontent">memberShipService.AuthenticateUser(model.UserName.Trim(), model.DeviceResponse.Trim());</div><br />(this line returns a boolean instead of throwing an exception)<p>Statistics: Posted by <a href="https://forum.yubico.com/memberlist.php?mode=viewprofile&amp;u=2968">henrik</a> — Tue Mar 10, 2015 11:17 am</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[henrik]]></name></author>
<updated>2015-03-10T10:50:55+01:00</updated>
<published>2015-03-10T10:50:55+01:00</published>
<id>https://forum.yubico.com/viewtopic.php?t=1778&amp;p=6989#p6989</id>
<link href="https://forum.yubico.com/viewtopic.php?t=1778&amp;p=6989#p6989"/>
<title type="html"><![CDATA[Re: U2F Signing algorithm]]></title>

<content type="html" xml:base="https://forum.yubico.com/viewtopic.php?t=1778&amp;p=6989#p6989"><![CDATA[
<div class="quotetitle">bbartlett wrote:</div><div class="quotecontent"><br />(1) I have decoded the attestation certificate returned during registration of a Yubikey NEO and found sha256RSA listed as the SignatureAlgorithm.  I was expecting ECDSA not RSA.  Please confirm which digital signature algorithm is implemented on the Yubikey.<br /></div><br />All U2F attestation certificates are ECDSA (in accordance with the spec), but they are signed by our CA, which is RSA.<p>Statistics: Posted by <a href="https://forum.yubico.com/memberlist.php?mode=viewprofile&amp;u=2968">henrik</a> — Tue Mar 10, 2015 10:50 am</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[bbartlett]]></name></author>
<updated>2015-03-12T22:57:15+01:00</updated>
<published>2015-03-09T20:35:47+01:00</published>
<id>https://forum.yubico.com/viewtopic.php?t=1778&amp;p=6984#p6984</id>
<link href="https://forum.yubico.com/viewtopic.php?t=1778&amp;p=6984#p6984"/>
<title type="html"><![CDATA[[Solved] U2F Signing algorithm with .NET lib]]></title>

<content type="html" xml:base="https://forum.yubico.com/viewtopic.php?t=1778&amp;p=6984#p6984"><![CDATA[
A couple of sanity check questions regarding implementation of U2F by a replying party.  <br /><br />(1) I have decoded the attestation certificate returned during registration of a Yubikey NEO and found sha256RSA listed as the SignatureAlgorithm.  I was expecting ECDSA not RSA.  Please confirm which digital signature algorithm is implemented on the Yubikey.  <br /><br />(2) A correct implementation of U2F by a relying party to authenticate users would require the following, (a) persistence of the key handle, public key and attestation certificate created during registration (from window.u2f.register), (b) no error code returned during authentication (from window.u2f.sign), and (c) verify the digital signature returned from the Yubikey sign operation using a crypto library such as Bouncy Castle. <br /><br />Step (2)(c) is where I am having difficulty.  I cannot get _signer.VerifySignature(signature) to return expected boolean results.  It should return true if the inputs (public key, bytes to sign, signer algorithm, signature from Yubikey) are correct, otherwise false.  <br /><br />I am using the .NET library published on your developer pages.<br /><br />Thank you.<p>Statistics: Posted by <a href="https://forum.yubico.com/memberlist.php?mode=viewprofile&amp;u=3155">bbartlett</a> — Mon Mar 09, 2015 8:35 pm</p><hr />
]]></content>
</entry>
</feed>