Hello Steffan,
Sorry for the delay - I was busy doing "things" :)
On Sat, Jan 6, 2018 at 12:11 AM, Steffan Karger <stef...@karger.me> wrote:
> Hi Emmanuel,
>
> On 03-01-18 18:13, Emmanuel Deloget wrote:
> > Hello Steffan,
> >
> > On Mon, Jan 1, 2018 at 4:36 PM, Steffan Karger <stef...@karger.me
> > <mailto:stef...@karger.me>> wrote:
> >
> > Hi,
> >
> > On 01-01-18 14:57, Emmanuel Deloget wrote:
> > > I'm trying to get openvpn read my certificates from a TPM2 using a
> > > specially crafted PKCS#11 provider (the existing tpm2-pk11 is quite
> > > limited for now but I might be able to extend it).
> > >
> > > However, the PKCS#11 API is not something I'm comfortable with,
> and I'd
> > > like to know if there is some document (design or anything,
> really) that
> > > could help me to understand what openvpn wants exactly in order
> for me
> > > to provide the missing bits. I've read the documents at [1] but
> found
> > > nothing here of interest (for me).
> > >
> > > So, does someone have any pointer?
> >
> > You're right that OpenVPN's pkcs11 options lack some high-level
> > documentation. Maybe I can shed some light on the basics (probably
> > taking a step further back than you need).
> >
> > First, you need some shared object (.so, .dll) that provides the
> > interface specified by the PKCS11 standard. OpenVPN will load that
> > module, and call its functions to provide private key operations.
> That
> > shared object is usually provided by your smartcard vendor. That
> shared
> > object takes care of communication with the underlying key store
> (smart
> > card, tpm, hsm, ...). The openvpn manpage calls this a pkcs11
> > 'provider'.
> >
> > $ openvpn --show-pkcs11-ids
> > /usr/lib/x86_64-linux-gnu/pkcs11/gnome-keyring-pkcs11.so
> >
> > The following objects are available for use.
> > Each object shown below may be used as parameter to
> > --pkcs11-id option please remember to use single quote mark.
> >
> >
> >
> > I seen that while testing.
> >
> >
> >
> >
> > Certificate
> > DN: C=KG, ST=NA, O=OpenVPN-TEST, CN=Test-Client,
> > emailAddress=me@myhost.mydomain
> > Serial: 02
> > Serialized id:
> > Gnome\x20Keyring/1\x2E0/1\x3AUSER\x3ADEFAULT/Gnome2\
> x20Key\x20Storage/1A9D824585217F1BD54603E83F042F570A2EE9F2
> >
> > (I have the openvpn client testkey in my local gnome keyring, to
> easily
> > test pkcs11 without a hardware token.)
> >
> > From that list, you pick the object you want to use, and specify the
> > provider and id in your config file. In this case:
> >
> > pkcs11-providers
> > "/usr/lib/x86_64-linux-gnu/pkcs11/gnome-keyring-pkcs11.so"
> > pkcs11-id
> > "Gnome\\x20Keyring/1\\x2E0/1\\x3AUSER\\x3ADEFAULT/Gnome2\\
> x20Key\\x20Storage/1B3B2BEBF36576443D3A903AFA8997221B93FCC1"
> >
> > You specify this *instead* of the regular 'key' and 'cert' options.
> > Note that you'll need toe escape backslashes.
> >
> >
> > Good to know :)
> >
> >
> >
> > You should now be able to use pkcs11 for the private key operations.
> >
> > Since each keystore behaves differently, I did not specify how to get
> > the private key in there. But I guess your TPM vendor providers
> tooling
> > for that.
> >
> >
>
<snip>
> >
> > In my understanding, and within a context of dual authentication (server
> > identifies client, client identifies server), I should see the following
> > set of operation:
> >
> > * fetch the certificate
> > * initiate communication and so some RSA magic
> > * everything's ok? continue
> >
> > Of course, I might be wrong. What I see is (with some printf within the
> > PKCS#11 provider, you can ignore them but they give you an idea of what
> > happens)
> >
> >
> <snip>
>
> >
> >
> > Unfortunately, there is no RSA-related log, so I cannot check what
> > openvpn is doing with the certificate it found - so at this point, I'm a
> > bit confused.
>
> It does not do any RSA operations, because it does not connect:
>
> Wed Jan 3 17:53:39 2018 us=959952 Attempting to establish TCP
> connection with [AF_INET6]2a01:240:1906:1:0:1850:6118:4075:443 [nonblock]
> Wed Jan 3 17:53:40 2018 us=961428 TCP: connect to
> [AF_INET6]2a01:240:1906:1:0:1850:6118:4075:443 failed: Connection refused
>
> ... and then it tears down the instance.
>
> TLS will only do the RSA operations after a few handshake messages have
> been exchanged, and it has something to sign. If you connect to a real
> server (even with the wrong certificate), you should see more.
>
I got it a bit later. We have a particular way to connect to our openvpn
instance. Before we do it, we have to tell the server we're going to
connect. And I forgot to do that ; as a result, the client does not even
find the server.
Anyway, I did some progress in my quest to have a working
TPM2-as-PKCS#11-provider. First of all, the tpm2-pk11 provider by Iwan
Timmer (https://github.com/irtimmer/tpm2-pk11) is able to read
certificates and private keys on a TPM2. It was a bit difficult to
understand how to configure things, but studying the code of both openvpn
and libpkcs11-helper did the trick. As a result, I was probably able to
connect to my server with the keys I got. Of course, the problem was now to
have the correct certificate (i.e. signed with the correct CA). It required
me to patch both tpm2-pk11 and libp11 to be able to use openssl to create a
CSR. But that eventually worked.
So, using the latest gits of tpm2-tss (https://github.com/intel/tpm2-tss,
the TPM2 system libraries), tpm2-abrmd (https://github.com/intel/tpm2-abrmd,
the TPM2 daemon), tpm2-tools (https://github.com/intel/tpm2-tools, tools to
manipulate the TPM2 state), libp11 (https://github.com/OpenSC/libp11,
including a PKCS#11 engine for OpenSSL) and tpm2-pk11 (
https://github.com/irtimmer/tpm2-pk11, a PKCS#11 provider for TPM2), it's
now possible to
* store RSA keys within the TPM2 (that part is done using tpm2-tools).
* sign a certificate request with OpenSSL using these keys (we are then
able to sign this CSR with our CA to generate the client certificate)
* use openvpn as an authentified-by-TPM2 client to connect to a
authentified server.
For testing, one can also install IBM's software TPM2 (
http://ibmswtpm.sourceforge.net/ibmswtpm2.html). Of course, you need a
decently recent linux kernel (4.9 or 4.10).
While the number of required changes were quite small (and have no impact
on openvpn), this was quite a journey. I guess some of the merits should go
to RSA, Microsoft and Intel, for their incredible effort in building
comprehensive industry standards that are as convoluted as they are
comprehensive :) (I'm kidding ; I think I begin to enjoy PKCS#11 and I
definitely had some fun while playing with my TPM2).
Those who are interested can contact me. I will probably try to write
something about this somewhere (I don't know where yet).
You may ask 'why is this important?'. To that I should answer that TPM2 are
pervasive (you cannot sell a Windows 10 compatible PC without a TPM or
TPM2) ; now, if you factor in the Spectre vulnerability, you may understand
that being able to store your secrets (your private RSA keys) in a
protected hardware device is of interest: if it's not in the memory then it
won't leak. So why not putting them in this TPM that you're very likely to
have instead of buying another piece of hardware? (but if you want one, you
should try a Nitrokey HSM ; they work great and they are quite cheap)
>
> -Steffan
>
Best regards and thank you Steffan for your support,
-- Emmanuel Deloget
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Openvpn-devel mailing list
Openvpn-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openvpn-devel