Security Considerations

For most users and uses, OpenSC should work reasonably securely out of the box, with the assumption that the software and physical environment of the user has not been already compromised. While smart cards are designed to protect sensitive key material in hostile environments, there are many attacks that can be launched against a system utilizing OpenSC software. If you're serious about security or have healthy paranoia, this page contains tips and notes to push the limits even further.

The basics

To keep your private keys secret and to prevent unauthorized use of them:

Relevant opensc.conf entries

NB! OpenSC will use the file in OPENSC_CONF environment variable if present!

debug / debug_file

profile_dir

connect_exclusive

transaction_reset

enable_pinpad

provider_library

use_pin_caching

use_file_caching

lock_login

soft_keygen_allowed

Generic issues

Publicly readable information

Multiuser implications

Command line arguments

The OpenSC tools allow you to specify PINs and keys on the command line. This is only suitable for testing or when you are the only user of the machine. If there are multiple users, other users usually are able to run things like 'ps' or 'top', and probably are able to see the arguments given to some process, too. Also, the arguments probably get logged to some shell history file like ~/.bash_history.

The solution is to use a script or, in the case of the pkcs15-init tool to put PINS and keys into a file and used through the --options-file options.

Access to the card

Some other problems if multiple users have access to the reader(s):

If the user forgets a card to the reader while the session isn't locked, a malicious other user could run PIN verify commands to the card and probably lock the PIN, or even lock the card for good. If a user is logged in to the card but the session isn't locked, a malicious user could use the previleged functionality (e.g. doing a signature, writing data to the card).

A solution is to add the user to a specific "scard" group after they've logged in through xdm. pcsc-lite's pcscd runs as pseudouser/group scard/scard, and limit the access to the server socket (pcscd.comm) as 770 scard:scard. This way, other possible users that may have logged in through ssh won't have any access to the local card readers. Not a perfect solution, but works for single-reader workstations well enough.

By default OpenSC allows multiple applications to access smart cards via the PKCS#11 module. If you don't want that, you can set lock_login = true; in opensc.conf file and the card will be locked as soon as application calls C_Login() until C_Logout is called. Several applications (like Firefox, Thunderbird) won't call C_Login before the application is closed, so you can only use a single application at a time.

Protection of cards made with the pkcs15-init tool

Most cards have a default transport key that is used to create a pkcs15 directory on the card. Within the pkcs15 directory, files and keys are protected by PINs so the transport key has no power there.

This means that your keys and sensitive data are safe against others (who know the default transport key), in the sense that they can't be read or used.

However, depending on the smartcard os and the card profile anyone who knows the transport key and has access to your card can erase the card.

On itself, that may be a good thing if you lost your card, but there's another problem: If your card contains trusted certificates, and an adversary steals your card, puts another pkcs15 dir with other certs on the card and puts it back without you knowing, you may not find out until you put trust in those untrusted certs. Bottomline: be very carefull when using the card as a tamper-resistant storage -- make them PIN-protected for example. (Note: this if often not the case: the trusted certificates are usually stored in the applications using them.)

Root access

From the above, it follows that you can't protect your card, nor use your card to protect something against someone with root access or who can change the config/profile files, binaries or sniff/modify the communication with the card.