{"id":2539,"date":"2020-06-22T12:22:49","date_gmt":"2020-06-22T12:22:49","guid":{"rendered":"http:\/\/hauweele.net\/~gawen\/blog\/?p=2539"},"modified":"2020-06-22T12:22:49","modified_gmt":"2020-06-22T12:22:49","slug":"beid-card-reader-on-freebsd","status":"publish","type":"post","link":"https:\/\/hauweele.net\/~gawen\/blog\/?p=2539","title":{"rendered":"Beid card reader on FreeBSD"},"content":{"rendered":"<p>So I&#8217;ve got to fill in my taxes, and to do this in Belgium, we need to use our ID card. Well we can use a phone app too, but to use this app we have to register&#8230; using our ID card&#8230; \u00af\\_(\u30c4)_\/\u00af<\/p>\n<p>Last time I tested, this didn&#8217;t work well on FreeBSD, but I didn&#8217;t look too much into it and perhaps things changed since then. Also, like always, I refuse to do this on another OS where I know it works, that would be far too easy!<\/p>\n<p>So we should install the PC\/SC-Lite architecture to be able to read the cards and the beid middleware so we can use the card. Fortunately, <i>beid<\/i> is in the ports so we can just install it:<\/p>\n<pre>pkg install beid\r\n<\/pre>\n<p>This will also install pcsc-lite. The package messages tell us that we must:<\/p>\n<ul>\n<li>Install drivers for the card reader<\/li>\n<li>Hack around devd to let the PC\/SC Smart Card daemon recognize it<\/li>\n<li>Mount procfs<\/li>\n<li>Install the <i>eID Belgium<\/i> extension if you use Firefox (I&#8217;ll also explain how to install it in Chromium)<\/li>\n<li>Don&#8217;t trust your government<\/li>\n<\/ul>\n<p>Let&#8217;s do just all of that!<\/p>\n<h2>Install drivers for the card reader<\/h2>\n<p>My card reader is a DunnoWhat-Random-USB-Card-Reader, perhaps <i>devel\/libccid<\/i> should do? For some reason, this is not available in the packages but only via ports:<\/p>\n<pre>cd \/usr\/ports\/devel\/libccid\r\nmake install clean\r\n<\/pre>\n<h2>Does the card reader read cards?<\/h2>\n<p>Does it work tho? Let&#8217;s find out!<\/p>\n<pre>$ usbconfig\r\n...\r\nugen0.6: &lt;SCM Microsystems Inc. SCR35xx v2.0 USB SC Reader&gt; at usbus0, cfg=0 md=HOST spd=FULL (12Mbps) pwr=ON (100mA)\r\n...\r\n<\/pre>\n<p>So our card reader is on the USB port ugen0.6. We run <i>pcscd<\/i> to see if it&#8217;s detected properly:<\/p>\n<pre>$ pcscd --info --color --foreground\r\n...\r\n00000155 [34366794240] ccid_usb.c:660:OpenUSBByName() Found Vendor\/Product: 04E6\/5410 (SCM Microsystems Inc. SCR 355)\r\n...\r\n<\/pre>\n<p>Sweet, so it appears to be detected and working with CCID. However if I run <i>eid-viewer<\/i>, it doesn&#8217;t work. Looking at pcscd info, it looks like the power up of the card failed:<\/p>\n<pre>...\r\n00000011 [34375102464] ifdhandler.c:1221:IFDHPowerICC() PowerUp failed\r\n...\r\n<\/pre>\n<p>Searching a bit over the internet, I&#8217;ve found <a href=\"https:\/\/bugzilla.redhat.com\/show_bug.cgi?id=1033788\">this bug report<\/a> and it seems that we have to tweak the CCID driver a little.<\/p>\n<p>Edit <i>\/usr\/local\/lib\/pcsc\/drivers\/ifd-ccid.bundle\/Contents\/Info.plist<\/i> and search for <i>&lt;key&gt;ifdDriverOptions&lt;\/key&gt;<\/i>. By default it is set to <i>0x0000<\/i> which, if you read the description belows, means that it tries to power on the card at 5V, then 1.8V then 3V. But apparently this doesn&#8217;t work with my particular card reader. Instead I let the card reader decide, change the value to <i>0x0030<\/i>:<\/p>\n<pre>  &lt;key&gt;ifdDriverOptions&lt;\/key&gt;\r\n  &lt;string&gt;0x0030&lt;\/string&gt;\r\n<\/pre>\n<p>Restart pcscd (<code>pcscd --info --color --foreground<\/code>) and try the card again (<code>eid-viewer<\/code>). In my case, I can see my card details, so I believe this means that the card reader is working well.<\/p>\n<h2>Hack around devd<\/h2>\n<p>First, let&#8217;s enable pcscd at boot in <i>\/etc\/rc.conf<\/i> with <code>pcscd_enable=\"YES\"<\/code>.<\/p>\n<p>Now we need to configure <i>devd<\/i> as described by the <i>pcsc-lite<\/i> package message (<code>pkg info -D pcsc-lite<\/code>). Add this to <i>\/etc\/devd.conf<\/i>:<\/p>\n<pre>\r\nattach 100 {\r\n        device-name \"ugen[0-9]+\";\r\n        action \"\/usr\/local\/sbin\/pcscd -H\";\r\n};\r\n\r\ndetach 100 {\r\n        device-name \"ugen[0-9]+\";\r\n        action \"\/usr\/local\/sbin\/pcscd -H\";\r\n};\r\n<\/pre>\n<p>The <i>-H<\/i> option is to re-read some configuration files in case of a non-USB reader. You can probably remove them.<\/p>\n<p>Now let&#8217;s restart everything we need and check that it still works:<\/p>\n<pre>\r\n$ service devd restart\r\n$ service pcscd restart\r\n<\/pre>\n<p>Check that it works with the <i>eid-viewer<\/i>. <\/p>\n<h2>Mount procfs<\/h2>\n<p>It&#8217;s probable that you already have procfs mounted because it&#8217;s needed by a lot of other ports. But if you didn&#8217;t, just add this line to <i>\/etc\/fstab<\/i><\/p>\n<pre>\r\nproc \/proc procfs rw,late 0 0\r\n<\/pre>\n<p>and then just <code>mount procfs<\/code>.<\/p>\n<h2>Install the <i>eID Belgium<\/i> extension (for Firefox)<\/h2>\n<p>If you use Firefox, you are looking for <a href=\"https:\/\/addons.mozilla.org\/en-US\/firefox\/addon\/belgium-eid\">this extension<\/a>. It should work after you have restarted Firefox.<\/p>\n<h2>Get it to work in Chromium<\/h2>\n<p>On Chromium there is no extension, instead we work directly with NSS. For beid, the process is straightforward since they provide a script to install the necessary module in NSS. Go in your home directory and start the command <i>beid-update-nssdb<\/i>. Then restart chromium completely and it should work.<\/p>\n<p>Alternatively you can adapt <a href=\"https:\/\/help.ubuntu.com\/community\/CommonAccessCard#Google_Chrome.2FChromium_Setup\">this post<\/a> which explains how to manually update nssdb on Ubuntu. You would have to adapt this to FreeBSD and also use this library <i>\/usr\/local\/lib\/libbeidpkcs11.so.0<\/i> instead of libcac.<\/p>\n<h2>Don&#8217;t trust your government<\/h2>\n<p>You do this.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>So I&#8217;ve got to fill in my taxes, and to do this in Belgium, we need to use our ID card. Well we can use a phone app too, but to use this app we have to register&#8230; using our &hellip; <a href=\"https:\/\/hauweele.net\/~gawen\/blog\/?p=2539\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[1],"tags":[1087,1088,128,82,389,1089],"class_list":["post-2539","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-beid","tag-card-reader","tag-chromium","tag-firefox","tag-freebsd","tag-pcsc"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/hauweele.net\/~gawen\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2539","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/hauweele.net\/~gawen\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hauweele.net\/~gawen\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hauweele.net\/~gawen\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/hauweele.net\/~gawen\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2539"}],"version-history":[{"count":0,"href":"https:\/\/hauweele.net\/~gawen\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2539\/revisions"}],"wp:attachment":[{"href":"https:\/\/hauweele.net\/~gawen\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2539"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hauweele.net\/~gawen\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2539"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hauweele.net\/~gawen\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2539"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}