Commit Graph

36 Commits

Author SHA1 Message Date
AdriaoNeves 366adbd546 Fixing invalid signature with 3072 RSA bits in GemsafeV1 2019-12-05 10:46:21 +01:00
AdriaoNeves dbe932152d Fixing invalid signature with 3072 RSA bits in GemsafeV1 2019-12-05 10:46:21 +01:00
AdriaoNeves ce71b171e2 Add support for 4K RSA keys in GemsafeV1 2019-11-23 22:13:28 +01:00
Nuno Goncalves 0322401aae gemsafeV1: remove redundant match card call to allow for opensc.conf match
At the point when gemsafe_match_card is called, the card type is already known,
either because of a previous match at card.c, or because it is forced at opensc.conf.

With this redundant match it's not possible to force selection on opensc.conf.

Signed-off-by: Nuno Goncalves <nunojpg@gmail.com>
2019-06-05 13:43:52 +02:00
Nuno Goncalves e3ff3be4fe pteid: add new ATRs
One ATR have been confirmed on my personal card and also added to the official middleware:

https://svn.gov.pt/projects/ccidadao/changeset/321/middleware-offline/trunk/_src/eidmw/minidriver/makemsi/pteidmdrv.inf

There is another ATR I am adding blind from the official middleware:

https://svn.gov.pt/projects/ccidadao/changeset/321/middleware-offline/trunk/_src/eidmw/minidriver/makemsi/pteidmdrv.inf

Signed-off-by: Nuno Goncalves <nunojpg@gmail.com>
2019-05-31 14:12:12 +02:00
Frank Morgner a899a46b09 replaced SC_TEST_RET with LOG_TEST_RET 2018-12-06 09:26:42 +01:00
Frank Morgner 24b50a4277 replace sc_debug with sc_log 2018-12-06 09:26:42 +01:00
Priit Laes 45f407c021 Mark driver-specific global sc_atr_table structures as const
As most of the drivers do not modify these, we can mark them as const.
Two drivers that we cannot convert are dnie and masktech.

section                 size
.data                  35232 ->   25472
.data.rel.ro           36928 ->   46688
2018-08-22 22:50:30 +02:00
Frank Morgner 439a95f2d2
If card initialization fails, return SC_ERROR_INVALID_CARD (#1251)
fixes https://github.com/OpenSC/OpenSC/issues/946
2018-05-18 23:49:29 +02:00
Frank Morgner d719977d14 Reselect PKI-Applets after card reset
PKI-Applets may not be active if the card has been reset or unpowered.
The SELECT command used to activate the applet, is identical to the one
used during card matching or initialization.
2018-02-07 11:57:48 +01:00
Frank Morgner 6bfb39454b Fix missing error handling of memory allocation (#1020)
* libopensc: handle allocation errors
* handle more faults during memory allocation

fixes several situations that cause segmentation fault
2017-04-20 21:08:49 +02:00
Maciej S. Szmigiero 62cbda6cd9 Fix log messages format and parameter issues flagged by GCC
Since "Add GCC format checking attributes to log functions" commit GCC
warns us about problems with format strings and their arguments provided
to OpenSC message logging functions.

This commit fixes all cases where GCC warned about incorrect format on
64-bit Linux, 32-bit and 64-bit mingw builds (with SM and OpenSSL enabled).
Well, almost all since on mingw GCC does not recognize "ll" size specifier
(present at least since Visual Studio 2005, also in mingw own CRT) so these
(few) warnings about it remain.

In most cases format size specifier for size_t type was missing (usually
size was left at default int level, with is different on 64-bit x86).
Some formats had too few / too many arguments.
In some cases pointers were printed as integers.
Some long variables were missing "l" prefix (especially with regard to %x
format).

Signed-off-by: Maciej S. Szmigiero <mail@maciej.szmigiero.name>
2017-03-27 11:05:16 +02:00
Nuno Goncalves b2f6abded3 card-gemsafeV1: use iso7816 pin_cmd implementation
GemsafeV1 is compatible with iso7816 pin commands, including
SC_PIN_CMD_GET_INFO so it doesn't need to customize it.

Acked-by: João Poupino <joao.poupino@gmail.com>
Tested-by: Lukas Wunner <lukas@wunner.de>
Signed-off-by: Nuno Goncalves <nunojpg@gmail.com>
2016-11-08 10:52:37 +01:00
Nuno Goncalves 68cbc288de card-gemsafeV1: fix driver name
Acked-by: João Poupino <joao.poupino@gmail.com>
Signed-off-by: Nuno Goncalves <nunojpg@gmail.com>
2016-11-08 10:52:37 +01:00
Lukas Wunner c8fbcdd076 card-gemsafeV1: Add ATR for European Patent Office smart card
The EPO hands this card out to attorneys and inventors to authenticate
with their online services. The applet on the card seems to be identical
to the one on Swedish eID cards.

Ludovic Rousseau's list identifies the card as Gemalto IDClassic 340.
Gemalto Classic Client identifies the card as GemSAFE V3.

Previously the EPO was using a GemSAFE V1 card, its ATR was added with
81bbddfc24 ("card-gemsafeV1: Add a GemSafe V1 ATR").
2016-02-20 14:27:27 +01:00
Lukas Wunner 4734721180 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.
2015-12-14 20:54:56 +01:00
Frank Morgner bcb5fc15e5 honour HAVE_CONFIG_H 2015-04-22 23:55:33 +02:00
Frank Morgner 734cb67924 fixed algo ref 2015-01-28 07:23:34 +01:00
Jonathan Süssemilch Poulain ab814380cf Adds support for a Swedish eID card 2014-01-01 20:22:17 +01:00
Ludovic Rousseau 81bbddfc24 card-gemsafeV1: Add a GemSafe V1 ATR
Thanks to Lukas Wunner for the patch
2012-11-20 19:11:23 +01:00
joao 36f1fbb655 Add new ATR for the Portuguese eID card.
git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@4790 c6295689-39f2-0310-b995-f0e70906c6a9
2010-10-05 16:10:35 +00:00
aj 6545b42c02 cleanup of the debug code:
* reduce to a few, supported functions.
* change all functions to take the debug level as parameter.
* use symbolic names for the debug levels.
* fix tools to pass "verbose"/"opt_debug" as ctx->debug.


git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@4118 c6295689-39f2-0310-b995-f0e70906c6a9
2010-03-15 12:17:13 +00:00
aj d22a2483c0 Header file cleanup.
git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@4081 c6295689-39f2-0310-b995-f0e70906c6a9
2010-03-04 08:14:36 +00:00
martin d006b1845e libopensc:
- Remove slot abstraction from internal API and all reader drivers. CT-API (from where it all comes from) readers with multiple slots (if still found) can be presented as separate readers, OpenCT should remove the slot abstraction, PC/SC never knew about it. None of the tools knew how to use slots.
 - Add sc_cancel (translates to SCardCancel)
 - Re-implement sc_wait_for_event; support a blocking call.
 - Replace the "int reader" API with "* sc_reader_t" style; add "Get reader by name" functionality.
 - Remove "action" parameter from sc_disconnect_card() (was not used)


git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@3931 c6295689-39f2-0310-b995-f0e70906c6a9
2010-01-24 15:25:08 +00:00
martin d5200b3bbe Add GemSafeXpresso 32K ATR.
The card is available from http://www.smartcardfocus.com/shop/ilp/id~246/p/index.shtml



git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@3918 c6295689-39f2-0310-b995-f0e70906c6a9
2010-01-19 13:11:21 +00:00
martin e931fdfd06 Fix C coding style
git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@3853 c6295689-39f2-0310-b995-f0e70906c6a9
2009-11-16 20:35:15 +00:00
martin 9c7eb8122a Add support for Portugese eID on IAS and Gemsafe cards, by João Poupino.
git-svn-id: https://www.opensc-project.org/svnp/opensc/branches/martin/0.12@3755 c6295689-39f2-0310-b995-f0e70906c6a9
2009-10-03 14:41:14 +00:00
martin 64f9578202 apdu.sensitive is not in use since [2868]
git-svn-id: https://www.opensc-project.org/svnp/opensc/branches/martin/0.12@3751 c6295689-39f2-0310-b995-f0e70906c6a9
2009-10-03 09:31:07 +00:00
martin d672fde449 Remove sc_error and sc_ctx_suppress_errors_* in favor of sc_debug/fprintf
git-svn-id: https://www.opensc-project.org/svnp/opensc/branches/martin/0.12@3721 c6295689-39f2-0310-b995-f0e70906c6a9
2009-09-14 08:46:59 +00:00
aj a2032f5e83 Aktiv Co. / Aleksey Samsonov:
use generic set_security_env code, remove duplicate code.


git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@3705 c6295689-39f2-0310-b995-f0e70906c6a9
2009-06-28 07:25:47 +00:00
alonbl ff4d6dd101 Fix for two apparent C code bugs
By Stanislav Brabec

entersafe_init_pin_info() was declared as int, but defined and used as
void, resulting in a function returning an unused pseudo-random value.

card-gemsafeV1.c uses comparison 'type == "DF"', which is always false,
as it compares pointer to a string with pointer to the string "DF" in
the code.



git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@3563 c6295689-39f2-0310-b995-f0e70906c6a9
2008-09-10 12:44:40 +00:00
ludovic.rousseau a05564447a add ATR for the GemSafeXpresso 16k R3.2
git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@3426 c6295689-39f2-0310-b995-f0e70906c6a9
2008-03-17 15:03:51 +00:00
ludovic.rousseau d2bec293d2 gemsafe_init(): the applet supports also SC_ALGORITHM_RSA_HASH_NONE
thanks to Douglas E. Engert for the patch


git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@3302 c6295689-39f2-0310-b995-f0e70906c6a9
2007-11-15 15:52:46 +00:00
ludovic.rousseau 44b2d51385 gemsafe_flags2algref(): return 0x12 instead of 0x13 for
SC_ALGORITHM_RSA_PAD_PKCS1

thanks to Douglas E. Engert for the patch


git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@3301 c6295689-39f2-0310-b995-f0e70906c6a9
2007-11-15 14:07:13 +00:00
ludovic.rousseau 83cef7bfc0 remove spaces and tabs at end of lines
git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@3298 c6295689-39f2-0310-b995-f0e70906c6a9
2007-11-13 07:52:43 +00:00
ludovic.rousseau 07e6b23a26 add initial support of Gemsafe applet V1 cards
Thanks to David Mattes for the patch
http://www.opensc-project.org/pipermail/opensc-devel/2007-November/010558.html


git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@3296 c6295689-39f2-0310-b995-f0e70906c6a9
2007-11-12 10:18:54 +00:00