strongSwan smart card configuration HOWTO » History » Version 134
strongSwan Smartcard configuration HOWTO¶
- Table of contents
- strongSwan Smartcard configuration HOWTO
- Smartcard configuration
- strongSwan management
- Acknowledgements and other resources
Smartcards are a mature technology which avoid your PKIs from being stolen by a theft.
strongSwan relies on OpenSC to query the smartcard according to PKCS#11 RSA standard.
In this HOWTO, we give minimal information how to use a reader, initialize cards and use strongSwan.
You need a USB smartcard reader and a blank smart card.
Compatible card readers¶
You may refer to the matrix of supported smartcard readers published by pcsclite project.These Ominikey readers are quite popular:
- Second hand Omnikey 3121 CardMan USB smartcard readers can be found on eBay for less than 10€. These are good units for testing a setup.
- Smartcard readers with an integrated PIN pad offer an increased security level because the PIN entry cannot be sniffed on the host computer e.g. by a surrepticiously installed key logger. The Omnikey 3821 secure smartcard reader with LCD display and keypad for secure PIN entry may be a good choice.
Compatible smartcards¶You may use blank cards with support of 1024/2048 RSA to store credentials:
- Feitian PKI card. The author of this HOWTO received an evaluation kit. Feitian PKI cards work great and are fully supported by OpenSC svn version.
- Cryptoflex E-Gate 32k were the best choice (but no longer available).
- STARCOS SPK 2.4 cards are compatible, but cannot be erased, therefore any error may be fatal. You may buy developer versions which can be erased.
- Siemens Card OS 4.3 B may be a good choice, but opensc does not know how to initialize them. You have to bank them using Windows software.
- ACOS5 PKI cards are cheap, but unsupported. With a little work, OpenSC could support them.
Avoid Java cards as they may need MUSCLE framework, which is still experimental.
Read the Acknowledgements section for more information on Java cards.
A list of compatible cards is listed here.You may also use read-only, pre-personalized read-only cards:
- eID cards. Many European countries offer them and don't need to buy extra cards for VPN use.
- [fix-me] Please provide us with names of providers.
- Cryptoshop sells STARCOS SPK 2.3 and Siemens Card OS 4.3 B cards.
- Smartcardfocus sells STARCOS SPK 2.4.
Fix-me, please provide more IT shops. We are still looking for a 10€ compatible card.
To install pcsc-tools with ccid and java cards support, under Debian based distributions:
apt-get install pcsc-tools libccid
strongSwan supports PKCS#11 RSA standard using opensc libraries, which specifies how to store cryptographic information on devices.
To install opensc:
sudo apt-get install opensc
Edit this line to use only pcsc drivers:
reader_drivers = pcsc;
Do not install OpenCT package, as it is incompatible with OpenSC package. OpenSC supports OpenCT protocol using shared libraries.
We recommend using a certificate GUI to set-up your CA. One important thing to keep in mind is that, you shouldn't create private keys with a length not supported by your smart card (check the specs to be sure). Keys with a maximum length is 2048 bits are known to work.
Make a backup of your keys/certificates on a CD-ROM and store it in a safe place.
Testing the card¶
Check that the card reader is correctly recognized by OpenSC:
$ opensc-tool -l Readers known about: Nr. Driver Name 0 pcsc OmniKey CardMan 3121 00 00
At nr. 0 we have our recognized Omnikey CardMan 3121 reader. Let's insert our smart card in the reader (note that when buying the card you'll also receive the TRANSPORT KEY. Make sure that the transport key proposed by OpenSC matches the one you got in the mail. You will destroy the card by entering the wrong Key three times):
Let's double check that the card is recongized by printing its ATR:
$ opensc-tool -r0 -a 3b:95:18:40:ff:62:04:01:01:05
We can also check the name of the card with the -n switch (we can omit the -r0 since we only have one reader connected):
$ opensc-tool -n Cryptoflex 32K e-gate v4
At this point we know both the card and reader are fully recognized and functional, and we can proceed to erase the card: (You will be asked for the transport key you got in your mail)
Configuring a smartcard with pkcsc15-init¶
strongSwan's smartcard solution is based on the PKCS#15 "Cryptographic Token Information Format Standard" fully supported by OpenSC library functions. Using the command
pkcs15-init --erase-card --create-pkcs15
a fresh PKCS#15 file structure is created on a smartcard or cryptotoken. With the next command
pkcs15-init --auth-id 1 --store-pin --pin "1234" \ --puk "4321" --label "my PIN"
a secret PIN code with auth-id 1 is stored in an unretrievable location on the smart card. The PIN will protect the RSA signing operation. If the PIN is entered incorrectly more than three times then the smartcard will be locked and the PUK code can be used to unlock the card again.
Next the RSA private key is transferred to the smartcard
pkcs15-init --auth-id 1 --store-private-key myKey.pem [--id 45]
By default the PKCS#15 smartcard record will be assigned the ID 45. Using the --id option, multiple key records can be stored on a smartcard.
At last we load the matching X.509 certificate onto the smartcard
pkcs15-init --auth-id 1 --store-certificate myCert.pem [--id 45]
The pkcs15-tool can now be used to verify the contents of the smartcard.
pkcs15-tool --list-pins --list-keys --list-certificates
To enable smart card support in strongSwan, you may need to compile from sources:
./configure <add your options there> \ --enable-smartcard make sudo make install
Defining a smartcard-based connection in ipsec.conf is easy:
conn sun right=192.168.0.2 firstname.lastname@example.org left=%defaultroute leftcert=%smartcard auto=add
In most cases there is a single smartcard reader or cryptotoken and only one RSA private key safely stored on the crypto device. Thus usually the entry
which stands for the full notation
is sufficient where the first certificate/private key object enumerated by PKCS#11 module is used. If several certificate/private key objects are present then the nth object can be selected using
gives an overview over all certifcate objects made available by the PKCS#11 module. CA certificates are automatically available as trust anchors without the need to copy them into the /etc/ipsec.d/cacerts/ directory first.
As an alternative the certificate ID and/or the slot number defined by the PKCS#11 standard can be specified using the notation
leftcert=%smartcard<slot nr>:<key id in hex format>
will look in all available slots for ID 0x50 starting with the first slot (usually slot 0) whereas
will directly check slot 4 (which is usually the first slot on the second reader/token when using the OpenSC library) for a key with ID 0x50.
Entering the PIN code¶
Since the smartcard signing operation needed to sign the hash with the RSA private key during IKE Main Mode is protected by a PIN code, the secret PIN must be made available to Pluto.
For gateways that must be able to start IPsec tunnels automatically in unattended mode after a reboot, the secret PIN can be stored statically in ipsec.secrets
: PIN %smartcard "12345678"
or with the general notation
: PIN %smartcard<nr> "<PIN code>"
: PIN %smartcard<slot nr>:<key id> "<PIN code>"
On a personal notebook computer that could get stolen, you wouldn't want to store your PIN in ipsec.secrets.
Thus the alternative form
: PIN %smartcard %prompt
will prompt you for the PIN when you start up the first IPsec connection using the command
ipsec up sun
The ipsec up command calls the whack function which in turn communicates with Pluto over a socket. Since the whack function call is executed from a command window, Pluto can prompt you for the PIN over this socket connection. Unfortunately roadwarrior connections which just wait passively for peers cannot be initiated via the command window:
conn rw right=%any rightrsasigkey=%cert left=%defaultroute leftcert=%smartcard1:50 auto=add
But if there is a corresponding entry
: PIN %smartcard1:50 %prompt
in ipsec.secrets, then the standard command
or the alias
can be used to enter the PIN code for this connection interactively. The command
can be executed at any time to check the current status of the PIN code[s].
PIN-pad equipped smartcard readers¶
Smartcard readers with an integrated PIN pad offer an increased security level because the PIN entry cannot be sniffed on the host computer e.g. by a surrepticiously installed key logger. In order to tell pluto not to prompt for the PIN on the host itself, the entry
: PIN %smartcard:50 %pinpad
can be used in ipsec.secrets. Because the key pad does not cache the PIN in the smartcard reader, it must be entered for every PKCS #11 session login. By default pluto does a session logout after every RSA signature. In order to avoid the repeated entry of the PIN code during the periodic IKE main mode rekeyings, the following parameter can be set in the config setup section of ipsec.conf:
config setup pkcs11keepstate=yes
The default setting is pkcs11keepstate=no.
Acknowledgements and other resources¶
- This article was adapted by Smartcard HOWTO written by Michele Baldessari. Permission granted by Michele Baldessari to reproduce the text on strongSwan wiki. strongSwan configuration is taken from strongSwan manual.
- Bold users: some Java cards may be supported, using the Muscle experimental framework.
You may read this interesting HOWTO: How to get smartcards or crypto-tokens running on Debian Linux and Windows