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

<title>Yubico Forum</title>
<subtitle>...visit our web-store at</subtitle>
<link href="https://forum.yubico.com/index.php" />
<updated>2015-12-11T11:31:24+01:00</updated>

<author><name><![CDATA[Yubico Forum]]></name></author>
<id>https://forum.yubico.com/feed.php?f=26&amp;t=2124</id>
<entry>
<author><name><![CDATA[hiviah]]></name></author>
<updated>2015-12-11T11:31:24+01:00</updated>
<published>2015-12-11T11:31:24+01:00</published>
<id>https://forum.yubico.com/viewtopic.php?t=2124&amp;p=8070#p8070</id>
<link href="https://forum.yubico.com/viewtopic.php?t=2124&amp;p=8070#p8070"/>
<title type="html"><![CDATA[[HOW TO] OpenVPN with PIV PKCS#11 on Linux]]></title>

<content type="html" xml:base="https://forum.yubico.com/viewtopic.php?t=2124&amp;p=8070#p8070"><![CDATA[
This HOWTO describes how to import your existing OpenVPN RSA key and certificate into slot 9c of PIV applet.<br /><br />Some people have been using it before, but I have encountered a few rough edges that might be documented somewhere.<br /><br />You'll need these packages installed:<br /><br /><ul><li> openvpn</li><li> opensc</li><li> yubico-piv-tool <em>or</em> yubikey-piv-manager</li></ul><br /><strong>Warning</strong>: some OpenVPN packages don't work with this, e.g. recent OpenVPN on Fedora 23 breaks. Ubuntu 14.04 works.<br /><br />Assumption: you have files client.key, client.crt and ca.crt representing your existing key, client certificate and CA certificate respectively, all in PEM format.<br /><br />First, convert them to pkcs12 (you may encounter this <a href="https://github.com/Yubico/yubikey-piv-manager/issues/6#issuecomment-163880085" class="postlink">bug</a> when importing from PEM directly), set empty passphrase when asked for PKCS#12 passphrase:<br /><br /><div class="codetitle"><b>Code:</b></div><div class="codecontent">openssl pkcs12 -export -out cert_key.p12 -inkey client.key -in client.crt -certfile ca.crt -nodes</div><br /><br />Now, import the cert_key.p12 in one of following ways (the GUI way is probably simpler):<br /><br /><ul><li>import the newly generated cert_key.p12 either in the GUI PIV Manager</li><li>or use yubico-piv-tool to do the same (change -k to -P if you didn't set management key): <div class="codetitle"><b>Code:</b></div><div class="codecontent">yubico-piv-tool -s 9c -i cert_key.p12 -K PKCS12 -a import-key -a import-cert -k</div></li></ul><br />Let's see under what name the OpenVPN application sees your certificate. To do this, locate opensc-pkcs11.so library. On most distros you'll find it as openvpn /usr/lib/x86_64-linux-gnu/opensc-pkcs11.so or openvpn --show-pkcs11-ids /usr/lib64/opensc-pkcs11.so (for 64-bit platforms). Run as root with the correct location of opensc-pkcs11.so library:<br /><br /><div class="codetitle"><b>Code:</b></div><div class="codecontent"># openvpn --show-pkcs11-ids /usr/lib/x86_64-linux-gnu/opensc-pkcs11.so<br />Certificate<br />       DN:             C=CZ, ...<br />       Serial:         02<br />       Serialized id:  piv_II/PKCS\x2315\x20emulated/0575ebacfe300911/PIV_II\x20\x28PIV\x20Card\x20Holder\x20pin\x29/02<br /></div><br /><br />In your openvpn.conf, locate &quot;cert&quot; and &quot;key&quot; clausules, we will replace them with:<br /><br /><div class="codetitle"><b>Code:</b></div><div class="codecontent">pkcs11-id piv_II/PKCS\\x2315\\x20emulated/0575ebacfe300911/PIV_II\\x20\\x28PIV\\x20Card\\x20Holder\\x20pin\\x29/02<br />pkcs11-providers /usr/lib/x86_64-linux-gnu/opensc-pkcs11.so<br /></div><br /><br />We just copied the PKCS#11 Serialized id from previous step - but <strong>make sure to escape backslashes by adding another backslash</strong>. (The serialized ID is somehow wrong in Fedora 23 and therefore OpenVPN there does not work with PIV applet.) <br /><br />Now try the openvpn to run again with your Yubikey inserted, it should ask for your PIN:<br /><br /><div class="codetitle"><b>Code:</b></div><div class="codecontent">openvpn --config openvpn.conf<br />Fri Dec 11 11:19:06 2015 OpenVPN 2.3.2 x86_64-pc-linux-gnu &#91;SSL (OpenSSL)&#93; &#91;LZO&#93; &#91;EPOLL&#93; &#91;PKCS11&#93; &#91;eurephia&#93; &#91;MH&#93; &#91;IPv6&#93; built on Dec  1 2014<br />Fri Dec 11 11:19:06 2015 PKCS#11: Adding PKCS#11 provider '/usr/lib/x86_64-linux-gnu/opensc-pkcs11.so'<br />Fri Dec 11 11:19:06 2015 WARNING: No server certificate verification method has been enabled.  See http://openvpn.net/howto.html#mitm for more info.<br />Fri Dec 11 11:19:06 2015 Control Channel Authentication: using 'tls_auth.key' as a OpenVPN static key file<br />Fri Dec 11 11:19:06 2015 Outgoing Control Channel Authentication: Using 160 bit message hash 'SHA1' for HMAC authentication<br />Fri Dec 11 11:19:06 2015 Incoming Control Channel Authentication: Using 160 bit message hash 'SHA1' for HMAC authentication<br />Fri Dec 11 11:19:06 2015 Socket Buffers: R=&#91;212992-&gt;131072&#93; S=&#91;212992-&gt;131072&#93;<br />Fri Dec 11 11:19:06 2015 UDPv4 link local: &#91;undef&#93;<br />Fri Dec 11 11:19:06 2015 UDPv4 link remote: &#91;AF_INET&#93;1.2.6.5:1194<br />Fri Dec 11 11:19:06 2015 TLS: Initial packet from &#91;AF_INET&#93;1.2.6.5:1194, sid=b14bf3bf 4f16ba93<br />Fri Dec 11 11:19:06 2015 VERIFY OK: depth=1, C=CZ, ...<br />Fri Dec 11 11:19:06 2015 VERIFY OK: depth=0, C=CZ, ...<br />Enter PIV_II (PIV Card Holder pin) token Password:<br /></div><br /><br />The VPN should work as it did before, but now PIV applet on your Yubikey authenthicates you.<br /><br /><strong>Warning</strong>: The hex part in serialized id will change when you add new certificates/keys later, you'll have to edit openvpn.conf again!<p>Statistics: Posted by <a href="https://forum.yubico.com/memberlist.php?mode=viewprofile&amp;u=2457">hiviah</a> — Fri Dec 11, 2015 11:31 am</p><hr />
]]></content>
</entry>
</feed>