OpenSC fork, with some Italian healthcare smart card utils
Go to file
Lukas Wunner d7559f1546 card-gemsafeV1: Support signing SHA256
GemSAFE V1 cards support signing 36 bytes of free form data.
When signing a hash, the hash must be prepended by the DigestInfo
header. The PKCS#1 padding is done on the card. The 36 bytes limit
is sufficient for MD5 (16 + 18 bytes for the header), SHA1 and
RIPEMD160 (both use 20 + 15 bytes for the header) and MD5_SHA1
(16 + 20 bytes, no header). The algorithm reference ("cryptographic
mechanism reference" in ISO 7816 parlance) for signing free form data
is 0x12.

GemSAFE V3 cards changed the algorithm reference for signing free
form data to 0x02. In addition, they gained the ability to sign SHA256.
Since SHA256 exceeds the 36 bytes limit (32 + 19 bytes for the header),
it must be sent to the card *without* DigestInfo header. The header
will be prepended by the card and it is instructed to do so by sending
algorithm reference 0x42.

This scheme is also supported for SHA1, the algorithm reference is
0x12 in this case. However using this is not necessary as SHA1 fits
within the 36 bytes limit, including the header.

Supporting SHA256 is straightforward, we just add it to the flags
before adding the RSA algorithms. When sc_pkcs15_compute_signature()
calls sc_get_encoding_flags(), the input will be "iFlags 0x202, card
capabilities 0x8000021A" and the output will be "pad flags 0x0, secure
algorithm flags 0x202". I.e. the hash is neither prepended by the
DigestInfo header nor PKCS#1 padded and the hash algorithm is passed
to gemsafe_set_security_env() which can send the appropriate algorithm
reference 0x42 to the card.

However there's a catch: Once we add SHA256 to the flags, PKCS#11
applications will be unable to use the other hashes like SHA1 or
RIPEMD160. That's because register_mechanisms() checks if the card
supports no hashes, and if so, adds all of them:

		if (!(rsa_flags & SC_ALGORITHM_RSA_HASHES)) {
			rsa_flags |= SC_ALGORITHM_RSA_HASHES;
		}

We cannot add these missing hashes to the flags like we did with SHA256
because like SHA256, they would be sent to the card *without* DigestInfo
header. What we want is to send all hashes *with* DigestInfo header,
*except* for SHA256.

We can achieve that by registering a fake RSA algorithm which includes
the missing hashes in its flags. This fake algorithm is never used
because sc_card_find_rsa_alg() searches the algorithm list in-order
and we register the fake algorithm *after* the real algorithms.

The fake algorithm persuades register_mechanisms() to register the
missing hashes because it ORs the flags of all RSA algorithms together:

	num = card->algorithm_count;
	while (num--) {
		switch (alg_info->algorithm) {
			case SC_ALGORITHM_RSA:
				rsa_flags |= alg_info->flags;
				break;
		}
	}

So when signing e.g. a RIPEMD160 hash and sc_pkcs15_compute_signature()
calls sc_get_encoding_flags(), the input will be "iFlags 0x102, card
capabilities 0x8000021A" and the output will be "pad flags 0x100, secure
algorithm flags 0x2". This will result in the hash being prepended by
the DigestInfo header, which is what we want.
2016-01-14 04:55:23 +01:00
MacOSX Added minimum version of OS X to pkg 2015-11-03 00:03:17 +01:00
doc piv: fix typos in usage & man page 2015-10-15 12:51:19 +02:00
etc Implemented atomic PKCS#11 transactions 2015-12-06 10:42:45 +01:00
m4 Use AX_PTHREAD instead of ACX_PTHREAD 2012-09-25 23:03:38 +02:00
packaging/debian.templates fix LGPL version 2013-09-29 20:55:41 +02:00
solaris Thomas Uhle: modify Makefile so configure finds the include files 2009-12-03 07:05:15 +00:00
src card-gemsafeV1: Support signing SHA256 2016-01-14 04:55:23 +01:00
win32 add zlib compilation into the appveyor built process 2015-12-26 18:44:57 +01:00
.gitignore Issue 395. Avoiding a couple of memory leaks. 2015-04-12 11:35:09 +02:00
.travis.yml Uses container based travis and caching 2015-09-16 03:52:00 +02:00
CONTRIBUTING.md Create CONTRIBUTING.md 2015-02-13 16:52:10 +02:00
COPYING - changed license to LGPL 2001-11-06 18:34:19 +00:00
Makefile.am build: bootstrap script has expected content 2014-05-11 09:15:27 +02:00
Makefile.mak build: 'auto-config' parameters 2012-06-08 20:17:36 +02:00
NEWS revision: 0.15.0 2015-05-16 21:45:40 +02:00
README link README to README.md 2015-11-02 23:54:36 +01:00
README.md use shield.io for badge images 2015-11-02 22:48:52 +01:00
appveyor.yml cache the zlib.zip when building from Appveyor 2015-12-27 13:13:24 +01:00
bootstrap build: bootstrap script has expected content 2014-05-11 09:15:27 +02:00
bootstrap.ci build: put PACKAGE_VERSION_REVISION into version.m4 2014-05-12 07:27:04 +02:00
configure.ac configurable OS thread locking 2015-12-01 09:19:03 +01:00
version.m4 build: put PACKAGE_VERSION_REVISION into version.m4 2014-05-12 07:27:04 +02:00

README.md

OpenSC documentation wiki is available online at https://github.com/OpenSC/OpenSC/wiki

Please take a look at the documentation before trying to use OpenSC.

![Jenkins Build Status](https://img.shields.io/jenkins/s/https/opensc.fr/jenkins/OpenSC-master.svg?label=Jenkins build) Travis CI Build Status AppVeyor CI Build Status Coverity Scan Status