Skip to contentSkip to conversation

Fixing non-standard PKCS#11 serialization format using a patched pkcs11-helper?

Openvpn-devel Samuli Seppänen 4 participants 7 messages Aug 29, 2016 – Aug 30, 2016

lore
Share & tools
lore
#0 lore raw

Hi,

Right now our Windows installers use the official pkcs11-helper release from the OpenSC project. Unfortunately this means that output of "--show-pkcs11-ids" and input of "--pkcs11-id" are non-standard, as reported here:

<https://community.openvpn.net/openvpn/ticket/491>

In Fedora this problem has been fixed with a custom patch

<https://github.com/OpenSC/pkcs11-helper/pull/4>
<http://pkgs.fedoraproject.org/cgit/rpms/pkcs11-helper.git/>

Debian and Ubuntu have _not_ are not patching this issue:

<http://http.debian.net/debian/pool/main/p/pkcs11-helper/pkcs11-helper_1.11-5.debian.tar.xz>
<http://archive.ubuntu.com/ubuntu/pool/main/p/pkcs11-helper/pkcs11-helper_1.11-5.debian.tar.xz>

Do _we_ want to move to start using a patch pkcs11-helper version?

Signature · 5 lines
Samuli Seppänen
Community Manager
OpenVPN Technologies, Inc

irc freenode net: mattock
#1 lore raw
Quoted 9 lines · Samuli Seppänen

Hi,

Right now our Windows installers use the official pkcs11-helper release from the OpenSC project. Unfortunately this means that output of "--show-pkcs11-ids" and input of "--pkcs11-id" are non-standard, as reported here:

<https://community.openvpn.net/openvpn/ticket/491>

Quoted 10 lines

In Fedora this problem has been fixed with a custom patch

<https://github.com/OpenSC/pkcs11-helper/pull/4>
<http://pkgs.fedoraproject.org/cgit/rpms/pkcs11-helper.git/>

Debian and Ubuntu have _not_ are not patching this issue:

<http://http.debian.net/debian/pool/main/p/pkcs11-helper/pkcs11-helper_1.11-5.debian.tar.xz>

<http://archive.ubuntu.com/ubuntu/pool/main/p/pkcs11-helper/pkcs11-helper_1.11-5.debian.tar.xz>

Quoted 2 lines

Do _we_ want to move to start using a patch pkcs11-helper version?

There have been some proposals to ditch pkcs11-helper and rather use a newer and more compliant library instead (p11-kit). I think this makes more sense, to be honest. There are more issues with pkcs11-helper which upstream seems less interested in resolving, among others challenges with systemd and the PIN code [1]. So as things start to pile up, I think it's better to move on to something else.

Of course, someone needs to do this job. JJK sponsored me with a PKCS#11 token at last hackathon + since that time I've gotten myself both a Yubikey Neo and a NitroKey so I believe I have what's needed to begin to dive into this rabbit hole ... I just need to get this prioritized on my TODO list. Unless someone else wants to give it a try, if so let me know and we'll see if I can help out somehow.

With that in mind, if shipping a patched pkcs11-helper in Windows makes your life easier I'd consider doing this. But step carefully, avoid getting in a situation where you suddenly have to maintain these patches yourself. Rather try to see what Fedora does and see if that can be re-used as much as possible.

Signature · 3 lines
kind regards,

David Sommerseth
#2 lore raw
Quoted 15 lines · David Sommerseth
Quoted 14 lines · Samuli Seppänen

Hi,

Right now our Windows installers use the official pkcs11-helper release from the OpenSC project. Unfortunately this means that output of "--show-pkcs11-ids" and input of "--pkcs11-id" are non-standard, as reported here:

<https://community.openvpn.net/openvpn/ticket/491>

In Fedora this problem has been fixed with a custom patch

<https://github.com/OpenSC/pkcs11-helper/pull/4>
<http://pkgs.fedoraproject.org/cgit/rpms/pkcs11-helper.git/>

Quoted 7 lines
Quoted 7 lines

Debian and Ubuntu have _not_ are not patching this issue:

<http://http.debian.net/debian/pool/main/p/pkcs11-helper/pkcs11-helper_1.11-5.debian.tar.xz>

<http://archive.ubuntu.com/ubuntu/pool/main/p/pkcs11-helper/pkcs11-helper_1.11-5.debian.tar.xz>

Quoted 20 lines
Quoted 3 lines

Do _we_ want to move to start using a patch pkcs11-helper version?

There have been some proposals to ditch pkcs11-helper and rather use a newer and more compliant library instead (p11-kit). I think this makes more sense, to be honest. There are more issues with pkcs11-helper which upstream seems less interested in resolving, among others challenges with systemd and the PIN code [1]. So as things start to pile up, I think it's better to move on to something else.

Of course, someone needs to do this job. JJK sponsored me with a PKCS#11 token at last hackathon + since that time I've gotten myself both a Yubikey Neo and a NitroKey so I believe I have what's needed to begin to dive into this rabbit hole ... I just need to get this prioritized on my TODO list. Unless someone else wants to give it a try, if so let me know and we'll see if I can help out somehow.

Quoted 5 lines

With that in mind, if shipping a patched pkcs11-helper in Windows makes your life easier I'd consider doing this. But step carefully, avoid getting in a situation where you suddenly have to maintain these patches yourself. Rather try to see what Fedora does and see if that can be re-used as much as possible.

And the missing [1] URL ...
<https://bugzilla.redhat.com/show_bug.cgi?id=1135932>

Signature · 3 lines
kind regards,

David Sommerseth
#3 lore raw
In reply to David Sommerseth
Quoted 6 lines · David Sommerseth

There have been some proposals to ditch pkcs11-helper and rather use a newer and more compliant library instead (p11-kit). I think this makes more sense, to be honest. There are more issues with pkcs11-helper which upstream seems less interested in resolving, among others challenges with systemd and the PIN code [1]. So as things start to pile up, I think it's better to move on to something else.

You fixed up the missing [1] link, but this one covers the underlying cause of the same issue, and highlights a little bit more why I *really* think we want to ditch pkcs11-helper as soon as possible:
https://github.com/OpenSC/pkcs11-helper/issues/5

Quoted 6 lines

Of course, someone needs to do this job. JJK sponsored me with a PKCS#11 token at last hackathon + since that time I've gotten myself both a Yubikey Neo and a NitroKey so I believe I have what's needed to begin to dive into this rabbit hole ... I just need to get this prioritized on my TODO list. Unless someone else wants to give it a try, if so let me know and we'll see if I can help out somehow.

Note that you don't need hardware. If you use Firefox or Chrome web browsers, you have a software PKCS#11 token. If you use the GNOME desktop, you have another one. Then there's SoftHSM and plenty of others. Anyone can test this stuff, fairly easily.

Quoted 5 lines

With that in mind, if shipping a patched pkcs11-helper in Windows makes your life easier I'd consider doing this. But step carefully, avoid getting in a situation where you suddenly have to maintain these patches yourself. Rather try to see what Fedora does and see if that can be re-used as much as possible.

The Fedora patch for adding RFC7512 support is precisely the same as in the open pull request at https://github.com/OpenSC/pkcs11-helper/pull/4

It shouldn't need much ongoing maintenance. But I do definitely think it would be good to move away from pkcs11-helper completely. I'd actually like to remove it from Fedora entirely. There are only a small handful of projects which use it, and they can all be fixed.

That said, ditching it completely and moving to something based on p11-kit and/or libp11 would make a lot of sense. I'm just not *100%* sure what that solution looks like. I know *most* of it but just not the final details.

To clarify the difference between those two a little... p11-kit gives a system-wide configuration for which PKCS#11 provider modules should be available — distribution packages of stuff like SoftHSM, OpenSC, etc. should all provide p11-kit 'module' files so I can plug in my Yubikey and this Just Works™:
dnf install opensc; openconnect -c 'pkcs11:manufacturer=piv_II;id=%01'…

The p11-kit library also offers RFC7512 URI parsing, and enumeration of the various available PKCS#11 tokens and the objects there in. Its API is at https://p11-glue.freedesktop.org/doc/p11-kit/reference.html

What p11-kit does *not* do is the actual crypto. It's completely crypto-library-agnostic. It'll give you the CK_OBJECT_HANDLE of the key in the token, but won't *use* it for you. You need a wrapper to actually make that available as an OpenSSL EVP_PKEY, or whatever the equivalent abstract key type is in mbedTLS.

Those crypto operations *are* provided for OpenSSL by libp11, and for both OpenSSL and mbedTLS by pkcs11-helper. Along with a subset of the other functionality which we don't actually *need* because p11-kit provides it these days. But libp11 and pkcs11-helper predate, and don't use, p11-kit.

So if we want to use p11-kit, we need to fill in the missing parts that actually let us *do* the crypto. Which isn't stunningly hard; we can lift those parts from pkcs11-helper for the most part. And all the token/object enumeration parts can be generic.

Also, in the long term I actually want to merge native PKCS#11 support (probably using p11-kit) into OpenSSL itself as a first-class citizen. This plan has at least been approved in principle by the OpenSSL team as a "post 1.1" goal. The basic concept was to merge something like the libp11 API, but obviously it'll be subject to review as it goes in. And it *would* make sense to base it on p11-kit as much as possible.

Signature · 1 line
dwmw2
#4 lore raw
Quoted 7 lines
Quoted 6 lines

With that in mind, if shipping a patched pkcs11-helper in Windows makes your life easier I'd consider doing this. But step carefully, avoid getting in a situation where you suddenly have to maintain these patches yourself. Rather try to see what Fedora does and see if that can be re-used as much as possible.

Quoted 7 lines

The Fedora patch for adding RFC7512 support is precisely the same as in the open pull request at https://github.com/OpenSC/pkcs11-helper/pull/4

It shouldn't need much ongoing maintenance. But I do definitely think it would be good to move away from pkcs11-helper completely. I'd actually like to remove it from Fedora entirely. There are only a small handful of projects which use it, and they can all be fixed.

Given the state of 2.4 ("almost there") I think we should, at most, apply Fedora's patch to pkcs11-helper in Windows 2.4 installers. The long-term fix should (imho) wait until 2.5.

Signature · 5 lines
Samuli Seppänen
Community Manager
OpenVPN Technologies, Inc

irc freenode net: mattock
#5 lore raw
Quoted 10 lines · Samuli Seppänen
Quoted 10 lines
Quoted 6 lines

With that in mind, if shipping a patched pkcs11-helper in Windows makes your life easier I'd consider doing this.  But step carefully, avoid getting in a situation where you suddenly have to maintain these patches yourself.  Rather try to see what Fedora does and see if that can be re-used as much as possible.

The Fedora patch for adding RFC7512 support is precisely the same as in the open pull request at https://github.com/OpenSC/pkcs11-helper/pull/4

Quoted 8 lines
Quoted 4 lines

It shouldn't need much ongoing maintenance. But I do definitely think it would be good to move away from pkcs11-helper completely. I'd actually like to remove it from Fedora entirely. There are only a small handful of projects which use it, and they can all be fixed.

Given the state of 2.4 ("almost there") I think we should, at most, apply Fedora's patch to pkcs11-helper in Windows 2.4 installers. The long-term fix should (imho) wait until 2.5.

Agreed. In the meantime I'll try to work out what the way forward should look like — for all applications, not just OpenVPN.

I've already come to the conclusion that I need to expand the Fedora certificate handling guidelines (which aren't really Fedora-specific but it's a good way to drive improvements)....

Rather than *only* specifying that applications should accept RFC7512 PKCS#11 URIs anywhere they take a filename, it looks like we also need to be a bit more prescriptive about the *files* that are accepted too.

I'm accumulating a torture test suite (which I expect OpenVPN to fail) at
http://git.infradead.org/users/dwmw2/openconnect.git/blob/HEAD:/tests/Makefile.am

I note that all crypto libraries make it bloody hard to just load a certificate from a file and do the right thing. You have to jump through various hoops in the application to work out what the file is and ask the crypto library nicely to load that specific type of file.

I'm almost tempted to make a new library 'libkeyfile' which *does* provide a simple function that does the right thing. It ends up being multiple libraries, of course. You have 'libkeyfile-openssl', 'libkeyfile-mbedtls', etc. — and it would support PKCS#11 as well as files.

The aim would be for this library to become obsolete as the crypto libraries' APIs stop sucking so hard, and they actually start to make it *easy* for applications to do the right thing. I'd do it under a BSD licence so that it can be copied — I *want* it to be merged into the crypto library upstream, and it can also copied by projects which want to do so instead of having it as an external dependency.

Signature · 1 line
dwmw2
#6 lore raw

Hi,

Quoted 2 lines · David Woodhouse

I'm accumulating a torture test suite (which I expect OpenVPN to fail) at
http://git.infradead.org/users/dwmw2/openconnect.git/blob/HEAD:/tests/Makefile.am

Torture test suites are good :-) - Steffan regularily tries to beat our crypto stuff to pulp, while I'll find new and exciting ways to blow up our packet/socket handling. Like, actually testing --inetd :-)

gert

Signature · 4 lines
USENET is *not* the non-clickable part of WWW!
                                                           //www.muc.de/~gert/
Gert Doering - Munich, Germany                             [email protected]...
fax: +49-89-35655025                        [email protected]...