{"id":1494,"date":"2016-05-25T16:13:00","date_gmt":"2016-05-25T20:13:00","guid":{"rendered":"https:\/\/risacher.org\/jfdi\/?p=1494"},"modified":"2019-02-25T21:57:55","modified_gmt":"2019-02-26T02:57:55","slug":"p11-capi","status":"publish","type":"post","link":"https:\/\/risacher.org\/jfdi\/2016\/05\/p11-capi\/","title":{"rendered":"p11-capi now supports SHA-256"},"content":{"rendered":"<p>tl;dr: I fixed <a title=\"p11-capi repo\" href=\"https:\/\/github.com\/risacher\/p11-capi\/\" target=\"_blank\" rel=\"noopener\">p11-capi<\/a> to support <a title=\"DoD CIO brief on SHA-256 Migration\" href=\"http:\/\/www.acq.osd.mil\/dpap\/ops\/docs\/Public%20Briefing%20-%20DoD%20SHA-256%20Migration%2018%20Mar%202011.pdf\" target=\"_blank\" rel=\"noopener\">SHA-256<\/a>, thus making it useful again.\u00a0 In doing so, I basically acquired custodianship of an open source project.<\/p>\n<p><!--more--><\/p>\n<p><a href=\"https:\/\/risacher.org\/jfdi\/wp-content\/uploads\/2016\/05\/p11capi-snip.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-1497 alignright\" src=\"https:\/\/risacher.org\/jfdi\/wp-content\/uploads\/2016\/05\/p11capi-snip-300x210.png\" alt=\"p11capi-snip\" width=\"300\" height=\"210\" srcset=\"https:\/\/risacher.org\/jfdi\/wp-content\/uploads\/2016\/05\/p11capi-snip-300x210.png 300w, https:\/\/risacher.org\/jfdi\/wp-content\/uploads\/2016\/05\/p11capi-snip-1024x717.png 1024w, https:\/\/risacher.org\/jfdi\/wp-content\/uploads\/2016\/05\/p11capi-snip-624x437.png 624w, https:\/\/risacher.org\/jfdi\/wp-content\/uploads\/2016\/05\/p11capi-snip.png 1083w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a>P11-capi, <a title=\"Stef Walter's original repo\" href=\"http:\/\/thewalter.net\/git\/cgit.cgi\/p11-capi\/\" target=\"_blank\" rel=\"noopener\">developed by Stef Walter in 2008<\/a>, is a very clever shim that allows Firefox-on-Windows to use the <a title=\"CAPI on Wikipedia\" href=\"https:\/\/en.wikipedia.org\/wiki\/Microsoft_CryptoAPI\" target=\"_blank\" rel=\"noopener\">Microsoft Cryptographic API (CAPI)<\/a>.\u00a0 Natively, Firefox uses the <a title=\"quasi-official PKCS#11 documentation\" href=\"http:\/\/www.emc.com\/emc-plus\/rsa-labs\/standards-initiatives\/pkcs-11-cryptographic-token-interface-standard.htm\" target=\"_blank\" rel=\"noopener\">PKCS#11 API<\/a> to interface with cryptographic tokens.\u00a0 Unfortunately, PKCS#11 is not supported by middleware vendors as well as CAPI.\u00a0 P11-capi is a PKCS#11 module that just mediates to the appropriate CAPI calls.<\/p>\n<p>I used p11-capi to access my US-government-issued smartcard from Firefox-on-Windows for years, mainly because I started using a 64-bit version of Firefox (<a title=\"Waterfox project\" href=\"https:\/\/www.waterfoxproject.org\/\" target=\"_blank\" rel=\"noopener\">Waterfox<\/a>).\u00a0 I could not find extant Windows 64-bit PKCS#11 middleware, but I compiled 64-bit p11-capi without much trouble.\u00a0 In doing so, I discovered that p11-capi had the additional benefit of not causing other applications to lock up, because CAPI was mediating access to the smartcard in ways that PKCS#11 could not.\u00a0\u00a0 In particular, I was using my smartcard with both Firefox and Outlook, and the two applications were fighting for access to the smartcard.\u00a0\u00a0\u00a0 Using p11-capi solved this problem.<\/p>\n<p>In 2012, I started <a title=\"my p11-capi binaries web page\" href=\"https:\/\/risacher.org\/p11-capi\/\" target=\"_blank\" rel=\"noopener\">publishing 32-bit and 64-bit binaries<\/a> for p11-capi as a convenience for anyone who wanted to use them, with a digitally signed assertion that I had inspected the code for back doors and compiled it myself.<\/p>\n<p>Alas, sometime around 2013, I started having trouble with Firefox not authenticating to web sites with the smartcard, reporting &#8220;SSL_ERROR_SIGN_HASHES_FAILURE&#8221;.\u00a0\u00a0 I tried to troubleshoot it, but my experience with the Microsoft Cryptographic API was virtually nonexistent, and my compile-debug-edit cycle was very slow because of factors beyond my control.\u00a0 Eventually I gave up and resigned myself to use Internet Explorer for any web sites that required PKI client authentication.<\/p>\n<p>Recently (May 2016), I picked it up again and poked a little harder.\u00a0 Ultimately, I determined that Firefox was asking p11-capi to use a <a title=\"SHA-2 on Wikipedia\" href=\"https:\/\/en.wikipedia.org\/wiki\/SHA-2\" target=\"_blank\" rel=\"noopener\">SHA-2<\/a> hash (SHA-256, in particular), but that CAPI was reporting that it couldn&#8217;t use that algorithm.\u00a0 In particular, when I ask CAPI to resolve the OID for SHA-256, <code>CertOIDToAlgId(\"2.16.840.1.101.3.4.2.1\")<\/code> (i.e. the OID for SHA-256) returns <code>CALG_OID_INFO_CNG_ONLY<\/code>.\u00a0\u00a0\u00a0 I suspect that multiple Cryptographic Service Providers are registering the SHA-256 OID, and that some of them are registering it as &#8220;CNG Only&#8221; and other CSPs implement it.\u00a0 <a title=\"CertOIDToAlgId documentation\" href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/desktop\/api\/wincrypt\/nf-wincrypt-certoidtoalgid\" target=\"_blank\" rel=\"noopener\">CertOIDtoAlgId()<\/a> is basically returning the first (or last) registration of that OID.\u00a0\u00a0 Possibly <a title=\"CryptEnumOIDInfo documentation\" href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/windows\/desktop\/aa379928%28v=vs.85%29.aspx\" target=\"_blank\" rel=\"noopener\">CryptEnumOIDInfo()<\/a> is a better approach.<\/p>\n<p>Long-story-short, I added some special cases just to handle SHA-2 algorithms, and solved the technical issue.\u00a0 Since Stef Walter has no particular interest in maintaining p11-capi, I guess I now &#8220;own&#8221; the project, for lack of someone more sensible.\u00a0 Stef was kind enough to add a note on his git repo that points to my git repo to make it &#8220;official&#8221;.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>tl;dr: I fixed p11-capi to support SHA-256, thus making it useful again.\u00a0 In doing so, I basically acquired custodianship of an open source project.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,11,21,12],"tags":[],"class_list":["post-1494","post","type-post","status-publish","format-standard","hentry","category-it","category-oss","category-pki","category-work"],"_links":{"self":[{"href":"https:\/\/risacher.org\/jfdi\/wp-json\/wp\/v2\/posts\/1494","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/risacher.org\/jfdi\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/risacher.org\/jfdi\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/risacher.org\/jfdi\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/risacher.org\/jfdi\/wp-json\/wp\/v2\/comments?post=1494"}],"version-history":[{"count":10,"href":"https:\/\/risacher.org\/jfdi\/wp-json\/wp\/v2\/posts\/1494\/revisions"}],"predecessor-version":[{"id":1604,"href":"https:\/\/risacher.org\/jfdi\/wp-json\/wp\/v2\/posts\/1494\/revisions\/1604"}],"wp:attachment":[{"href":"https:\/\/risacher.org\/jfdi\/wp-json\/wp\/v2\/media?parent=1494"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/risacher.org\/jfdi\/wp-json\/wp\/v2\/categories?post=1494"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/risacher.org\/jfdi\/wp-json\/wp\/v2\/tags?post=1494"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}