Opensc No Slot With A Token Was Found
[UPDATED 2020.06.29]
- Opensc No Slot With A Token Was Found Guilty
- Opensc No Slot With A Token Was Found The Most
- Opensc No Slot With A Token Was Found Dead
I already covered how baffling smart cards hardware and standards can be:
But now that you - and presumably I - are no longer in a state of utterhelplessness when confronted by smart cards mumbo jumbo, let’s see whatclever things we can do with them. Coming to mind:
For the module to simulate the opensc-onepin module behavior the following option createslotsforpins = 'user'; Environment OPENSCCONF. Filename for a user defined configuration file. If this environment variable is not found on Windows, the registry key Software OpenSC Project OpenSC ConfigFile is checked. See debug = num. $ OPENSCDRIVER=openpgp pkcs11-tool -O No slot with a token was found. $ OPENSCDRIVER=openpgp pkcs11-tool -L Available slots: Slot 0 (0x0): Yubico Yubikey NEO OTP+U2F+CCID (empty) $ pkcs11-tool -L Available slots: Slot 0 (0x0): Yubico Yubikey NEO OTP+U2F+CCID token label: xxxxxxx token manufacturer: pivII token model: PKCS#15 emulated. Available slots: Slot 0 AKS ifdh 00 00 token state: uninitialized Slot 1 (empty) Slot 2 (empty) Slot 3 (empty) If you have performed a manual installation then you can find the pkcs11-tool in the tarball for your platform (or in the opensc toolkit): FC5: Mkproxy-fc5.tar.gz; RHEL4: Mkproxy-rhel4.tar.gz. Slotnum= Slot-number to use: 1 for the first, 2 for the second and so on. The default value is 0, which means to use the first slot with an available token. Cadir= Path to the directory where the CA certificates are stored. The directory must contain an OpenSSL hash-link to each certificate. The default value is /etc/pampkcs11. Smart Card / PKCS#11 support. OpenConnect supports the use of X.509 certificates and keys from smart cards (as well as software storage such as GNOME Keyring and SoftHSM) by means of the PKCS#11 standard. Objects from PKCS#11 tokens are specified by a PKCS#11 URI according to RFC 7512. In order to use a certificate or key with OpenConnect, you must provide a PKCS#11 URI which identifies it.
Two-factor authentication: PAM, Kerberos, SSH, VPN, web, etc.
E-mail: signature and encryption
Now, each of those buzzwords may be familiar to the Linux layman. But - oh dear! -what intricacies, pitfalls, frustrations and sense of despair they entice whensmart cards come into play!
Here be dragons!
Some background
For the sake of the examples below, we’ll assume the following:
a PKI smart card from Aventra (MyEID 4.0.0)
used with two PIN codes
one for each purpose: login (authentication) and e-mail
along a card reader from HID Global (Omnikey 3x21 or 5422)
And for the sake of completeness, we’ll use:
a smart card-generated login keypair
(you loose your card, you’re out, you dumbass!)an externally-generated (and backed-up!) e-mail keypair(better still be able to decrypt those e-mails, though, huh?!)
Software versions
Although all necessary packages are readily available in Debian/Stretch, ourchosen use case and hardware requires that we use packages from Debian/Buster:
for the Aventra MyEID (4.0.0) smart card (using multiple PINs):
opensc>= 0.18.0for the HID Omnikey 5422 card reader:
libccid>= 1.4.27
PKCS#15
Opensc No Slot With A Token Was Found Guilty
The first step is to initalize the smart card and create the necessary PKCS#15structure, along the PIN codes - aka. tokens/slots - for our declared purposes.
Install the required Debian packages:
PKCS#15 initialization:
PINs/PUKs (tokens/slots) creation:
Key pairs and (X.509) certificates
Next, we need to generate/import the required PKI material in each token/slot.
Login keypair generation:
Login certificate import (after having its CSR properly signed; see the OpenSSL section further below):
E-mail key/certificate import (externally-generated and exported into aPKCS#12 bundle; see the OpenSSL section further below):
Smart card preparation finalization
Opensc No Slot With A Token Was Found The Most
Now that we’re done with the smart card itself, we can “finalize” its preparation:
The exact meaning of this step depends on the actual smart card vendor.
- on the Aventra MyEID, this switches the card from Creation State to OperationalState; PINs creation are then no longer possible and all access conditions areenforced
PKCS#11
Using smart cards for our purposes will in all cases be achieved thanks to thePKCS#11 software API/stack.
Install the required Debian packages:
Harden the default OpenSC configuration, in
/etc/opensc/opensc.conf
:And test its functioning:
WARNINGS:
- Aventra MyEID smart cards are known to raise (PKCS#11) issues with multiple PINs, unless OpenSC >= 0.18 is used(REF)
PKCS#11 URI
Some libraries and utilities may require you to provide so-called PKCS#11 URIas private key or certificate parameters. Those URIs are standardized by theRFC 7512 and look like:
LibNSS (Thunderbird/Firefox/Chromium)
PKCS#11 support is implemented in Mozilla Thunderbird, Firefox and GoogleChromium thanks to the libnss3
Network Security Services (NSS) library:
Add OpenSC driver to NSSDB:
NOTE: For Thunderbird and Firefox, you may need to specify the path to your profile instead of the home directory ~/.pki/nssdb
location. Look fora pkcs11.txt
file, where modutil
will actually have added its magic.
WARNING: For Thunderbird, make sure the emailAddress
attribute is includedin the certificate DN
(as opposed to theRFC 3850, §.3recommendation) or it will complain about not being able to find the certificateat the moment the message is sent (albeit being correctly configured in theAccount Settings
>Security
section).
OpenSSL
OpenSSL shall be required to generate the Certificate Signing Request (CSR)corresponding to our login key, as well as issuing the CA-signed X.509certificates for both login and email purposes. Generally speaking, thisimplies:
Install the required Debian packages:
Create the PKCS#11-friendly
openssl.conf
:Check the engine is properly configured
Create a CSR from a smart card private key:
Create a self-signed certificate from a smart card private key:
CA-signing a certificate, with the CA private key stored on a smart card:
OpenSSL being the horrifying piece of software that it is (at least to my simpleself), I invite you to discover OpenSSL-Easy, my humble and certainly poorattempt at making one’s OpenSSL life easier:
cURL
cURL relies on OpenSSL engine to perform its PKCS#11 magic. Once the engineinstalled (see above), it is just a matter of using the proper PKCS#11 URIsas private key and certificate arguments:
Secure Shell (SSH)
Using the smart card along SSH for RSA-based authentication is straight-forward,except for one BIG gotcha (see the WARNINGS further below).
Export the public key to your SSH authorized keys:
Login using your smart card:
Optionally temporarily storing your key in the SSH agent:
And correctly removing it from the SSH agent once done with it:
WARNINGS:
- When using multiple PINs and until the changes proposed by RedHat/Fedora areintegrated in OpenSSH:Fedora 28: Better smart card support in OpenSSH
One MUST use OpenSC’sonepin-opensc-pkcs11.so
library to prevent the SSHagent from attempting to unlock all tokens/slots with the same PIN andeventually locking those tokens/slots that do not match.This is also the reason why one MUST create the login token/slot as thefirst one on the smart card.
MIT Kerberos V
Using public key material instead of passwords for Kerberos authenticationis known as PKINIT:
Setting it up is rather straight-forward, albeit not devoid of gotchas (seethe WARNINGS further below).
Install the required Debian packages (on both servers and clients):
Generating the required servers certificates implies delving into OpenSSL;once again, one’s life may be easier thanks to OpenSSL-Easy:
OpenSSL-Easy (Authentication section)Debug the Kerberos-specific ASN.1 Subject Alternative Name (SAN) with:
Configure the Kerberos Key Distribution Center (KDC) servers;in
/etc/krb5kdc/kdc.conf
:Configure the Kerberos clients; in
/etc/krb5.conf
:
WARNINGS:
MIT Kerberos V does not allow to enforce PKINIT; if it fails, it willautomatically revert to password-based authentication
If one is willing to enforce smart card-based authentication, one shouldlook into using the PAM PKCS#11 module instead of PKINIT (see section below)
Pluggable Authentication Module (PAM)
Using the smart card for authenticating on a Linux box implies adding the PKCS#11module - pam_pkcs11
- to the PAM stack. Again, nothing particularly complicated,except a few gotchas (see the WARNINGS further below).
Install the required Debian packages:
Configure the PAM PKCS#11 module; in
/etc/pam_pkcs11/pam_pkcs11.conf
:Configure the PAM authentication stack, in
/etc/pam.d/common-auth
:
WARNINGS:
If MIT Kerberos V is configured for PKINIT (in
/etc/krb5.conf
),pam_krb5
will attempt PKINIT authentication, when password-based fails, even iftry_pkinit
is not specifiedAt the time of writing, PAM PKCS#11 module will segfault if any form ofCRL check is attempted
The smart card PIN code will be stored by
pam_pkcs11
and used as “password”by subsequent modules (e.g.pam_gnome_keyring
); this can lead to akward - ifnot unsecure - results; thus our mandating password (Kerberos/LDAP)authentication once PKCS#11’s succeeded
(see this as “two+”-factor authentication)
Apache (client) authentication
Using the smart card for (client) authentication on the Apache web server in aLDAP-centric environment is far - very far! - from trivial.
I invite you to read the article dedicated on the subject:
OpenVPN
Naively, one would think that using the smart card with OpenVPN would be assimple as:
Opensc No Slot With A Token Was Found Dead
Recovering the PKCS#11 ID(s) for use by OpenVPN:
And adding the relevant PKCS#11 stanza to OpenVPN (client) configuration:
Poor you! Nope! Not that easy! Well… Yes… That easy, provided you takeinto account the following well-(and-longime)-known bugs:
Shortly put, you will just need to:
retrieve OpenVPN and PKCS#11 helper source packages
apply the patches mentioned in the two above bug reports
make sure to disable PKCS#11 helper (multi-)threading
build the corresponding new Debian packages
and install them
… what!?!…
GNU Privacy Guard (GnuPG)
GnuPG is expected to be natively used along ad-hoc OpenPGP cards, totallydifferent beasts from the PKCS#15 and X.509-oriented smart cards we’re nowgrowing accustomed to.
Howevever, GnuPG can be made to work with those, again via the PKCS#11 interfaceand some additional trickery:
Install the required Debian package:
Configure the GnuPG Agent, in
~/.gnupg/gpg-agent.conf
:Configure the GnuPG PKCS#11 Smart Card Daemon (SCD), in
~/.gnupg/gnupg-pkcs11-scd.conf
:Where the
<login-hash>
and<email-hash>
are recovered with:Reload the GnuPG Agent and verify everything is ready:
We can therefrom coerce GnuPG into being more X.509 (and S/MIME) friendly:
Import our CA root (and intermediate) certificate(s):
Import our smart cards certificates:
And associate the corresponding (smart card) private keys:
(TODO: unravel the misteries of using the smart card with gpg
itself)
WARNINGS:
- At the time of writing, all of this will only work with RSA keys!
Python requests library
Python requests is nowadays the most ubiquitouslibrary for doing HTTP(S).
However, PKCS#11 isn’t natively supported and requires leveraging theM2Crypto library to hook the necessarygear work in, by replacing the https://
adapter (handler) by theM2HttpsAdapter
found in:
Which is as simple as it gets:
Encrypt/Decrypt data
Should you need to encrypt/decrypt data using your SmartCard:
Debugging
If you run into troubles, you can easily debug PKCS#11 interactions thanks toOpenSC’s OPENSC_DEBUG
or PKCS11SPY
environment variables:
Shortcoming: Probabilistic Signature Scheme (PSS) not supported
Probabilistic Signature Scheme (PSS),now creeps in TLS connections relying on OpenSSL 1.1.1 or above. This mayprevent you to use your credentials on websites that moved on to TLS 1.3 or withOpenVPN (which stubbornly refuses to stick to TLS 1.2 and not use PSS),unless you use:
OpenSC 0.20.0 or above
LibP11 0.4.8 or above (<-> OpenSSL engine)
PKCS#11 Helper patch (forecoming 1.26.0 release <-> OpenVPN)
Smart card?!? Easy!!!
Package: opensc-pkcs11;Maintainer for opensc-pkcs11 is Debian OpenSC Maintainers <pkg-opensc-maint@lists.alioth.debian.org>; Source for opensc-pkcs11 is src:opensc (PTS, buildd, popcon).
Reported by: E <debian@x3nsic.net>
Date: Thu, 2 Jun 2016 21:09:02 UTC
Severity: important
Found in version opensc/0.16.0~rc2-1
Reply or subscribe to this bug.
View this report as an mbox folder, status mbox, maintainer mbox
Report forwardedto debian-bugs-dist@lists.debian.org, debian@x3nsic.net, Debian OpenSC Maintainers <pkg-opensc-maint@lists.alioth.debian.org>
:Bug#826165
; Package opensc-pkcs11
. (Thu, 02 Jun 2016 21:09:06 GMT) (full text, mbox, link).
Acknowledgement sentto E <debian@x3nsic.net>
:
New Bug report received and forwarded. Copy sent to debian@x3nsic.net, Debian OpenSC Maintainers <pkg-opensc-maint@lists.alioth.debian.org>
. (Thu, 02 Jun 2016 21:09:06 GMT) (full text, mbox, link).
Message #5 received at submit@bugs.debian.org (full text, mbox, reply):
Information forwardedto debian-bugs-dist@lists.debian.org, Debian OpenSC Maintainers <pkg-opensc-maint@lists.alioth.debian.org>
:Bug#826165
; Package opensc-pkcs11
. (Tue, 12 Jul 2016 11:27:09 GMT) (full text, mbox, link).
Acknowledgement sentto Stanimir Stoyanov <stanimir@datacentrix.org>
:
Extra info received and forwarded to list. Copy sent to Debian OpenSC Maintainers <pkg-opensc-maint@lists.alioth.debian.org>
. (Tue, 12 Jul 2016 11:27:09 GMT) (full text, mbox, link).
Message #10 received at 826165@bugs.debian.org (full text, mbox, reply):
Information forwardedto debian-bugs-dist@lists.debian.org, Debian OpenSC Maintainers <pkg-opensc-maint@lists.alioth.debian.org>
:Bug#826165
; Package opensc-pkcs11
. (Sat, 15 Oct 2016 11:27:06 GMT) (full text, mbox, link).
Acknowledgement sentto gdsotirov@dir.bg
:
Extra info received and forwarded to list. Copy sent to Debian OpenSC Maintainers <pkg-opensc-maint@lists.alioth.debian.org>
. (Sat, 15 Oct 2016 11:27:06 GMT) (full text, mbox, link).
Message #15 received at 826165@bugs.debian.org (full text, mbox, reply):
Information forwardedto debian-bugs-dist@lists.debian.org, Debian OpenSC Maintainers <pkg-opensc-maint@lists.alioth.debian.org>
:Bug#826165
; Package opensc-pkcs11
. (Thu, 15 Dec 2016 23:18:07 GMT) (full text, mbox, link).
Acknowledgement sentto debian@x3nsic.net
:
Extra info received and forwarded to list. Copy sent to Debian OpenSC Maintainers <pkg-opensc-maint@lists.alioth.debian.org>
. (Thu, 15 Dec 2016 23:18:07 GMT) (full text, mbox, link).
Message #20 received at 826165@bugs.debian.org (full text, mbox, reply):
Information forwardedto debian-bugs-dist@lists.debian.org, Debian OpenSC Maintainers <pkg-opensc-maint@lists.alioth.debian.org>
:Bug#826165
; Package opensc-pkcs11
. (Sat, 14 Jan 2017 17:27:03 GMT) (full text, mbox, link).
Acknowledgement sentto 'Georgi D. Sotirov' <gdsotirov@dir.bg>
:
Extra info received and forwarded to list. Copy sent to Debian OpenSC Maintainers <pkg-opensc-maint@lists.alioth.debian.org>
. (Sat, 14 Jan 2017 17:27:03 GMT) (full text, mbox, link).
Message #25 received at 826165@bugs.debian.org (full text, mbox, reply):
Send a report that this bug log contains spam.
Debian bug tracking system administrator <owner@bugs.debian.org>.Last modified:Fri Jan 1 04:10:39 2021; Machine Name:buxtehudeDebbugs is free software and licensed under the terms of the GNU Public License version 2. The current version can be obtained from https://bugs.debian.org/debbugs-source/.
Copyright © 1999 Darren O. Benham,1997,2003 nCipher Corporation Ltd,1994-97 Ian Jackson,2005-2017 Don Armstrong, and many other contributors.