Commit Graph

212 Commits

Author SHA1 Message Date
Jakub Jelen 613b56ee55 Add correct prefix on the clang-tidy commandline 2021-05-05 14:22:58 +02:00
Jakub Jelen 910020aeec Ignore non-useful check in clang-tidy as we have ton of memset/memcpy 2021-01-06 14:15:06 +01:00
Piotr Majkrzak d4a9405bf4
Initial support for Polish eID card (e-dowód, eDO) (#2023) 2020-05-19 14:05:13 +02:00
Frank Morgner 0dcb910289 fixed "libtool: compile: unable to infer tagged configuration" 2020-05-11 18:41:16 +02:00
Doug Engert db41cd9ab1 Various CardOS V5_* improvements
Treat CardOS V5_0 and V5_3 cards differently then older versions:

Use card->dvr_data as a pointer to cardos_data_t to store private driver
data to pass internally, especially between set security environment
and the crypto operations. Sc_get_encoding_flags sets sec_flags from
algo_info->flags in pkcs15-sec.c and it passed to decipher.

Some cards when doing a decipher may drop leading 00 byte when
returning data from RSA_RAW decipher. Add leading byte(s) as needed.

Get Cryptographic Mechanism Reference from Key Reference:

Key reference byte appears to be a 4 bit Cryptographic Mechanism Reference
and a 4 bit key reference.

This is only done if key reference & 0xF0 != 0  i.e. default Cryptographic
mechanism reference is 0. which appears to be the case for RSA RAW.
PKCS1 appears to be 0x10 and ECDSA 0x30

    See iso 7816-4 table 55 for DST:
      84 Reference of a private key
      95 Usage qualifier byte - Table 57 - 40 looks OK
      80 Cryptographic mechanism reference and referes to section 9.2

The 4 bit key reference limits card to 16 keys. In future this may not work,
but we can derive a Cryptographic Mechanism Reference from what OpenSC
thinks the card needs to do. Only know RSA RAW, PKCS1 and ECDSA.

ECDSA code has not been tested, but expected to work.

Allow setting CardOS type and flags from opensc.conf using card_atr stanza
This is a fallback if newer cards are added or older cards have problems
giving us time to make need changes in next release.

It will help in identifying what flags are needed for each card.
As user can report what combination of flags work for them. They do this by
adding to opensc.conf with something like this. (Change the ATR to your card's ATR):

        card_atr 3b:d2:18:00:81:31:fe:58:c9:03:16 {
                driver = "cardos";
                # type is decimal from cards.h:
                # SC_CARD_TYPE_CARDOS_V5_0 is 1009
                # SC_CARD_TYPE_CARDOS_V5_3 is 1010
                type = 1010;

                # flags is hex from opensc.h:
                #define SC_ALGORITHM_ONBOARD_KEY_GEN    0x80000000
                #define SC_ALGORITHM_NEED_USAGE         0x40000000

                #define SC_ALGORITHM_RSA_RAW            0x00000001 /* RSA_RAW is PAD_NONE */
                #define SC_ALGORITHM_RSA_PAD_NONE       0x00000001
                #define SC_ALGORITHM_RSA_PAD_PKCS1      0x00000002 /* PKCS#1 v1.5 padding */
                #define SC_ALGORITHM_RSA_PAD_ANSI       0x00000004
                #define SC_ALGORITHM_RSA_PAD_ISO9796    0x00000008
                #define SC_ALGORITHM_RSA_PAD_PSS        0x00000010 /* PKCS#1 v2.0 PSS */
                #define SC_ALGORITHM_RSA_PAD_OAEP       0x00000020 /* PKCS#1 v2.0 OAEP */
                #define SC_ALGORITHM_RSA_HASH_NONE      0x00000100 /* only applies to PKCS1 padding */
                # example: SC_ALGORITHM_ONBOARD_KEY_GEN | SC_ALGORITHM_RSA_HASH_NONE |  SC_ALGORITHM_RSA_RAW
                flags = 80000101;
                #example: SC_ALGORITHM_ONBOARD_KEY_GEN | SC_ALGORITHM_RSA_PAD_PKCS1
                flags = 80000002;
        }

For V5_0 and v5_3 cards, use sc_get_max_send_size and sc_get_max_recv_size
which takes care or reader sizes even on Windows where SCardControl can not get PART_10 sizes.

(commit eddea6f3c2 on Windows forces reader sizes to 255, 256
in reader-pcsc.c if not already set. It should not do this, but leave that up to card drivers.)

pkcs15-cardos.c added:

New file, pkcs15-cardos.c, added as emulation only for CardOS
V5_0 and V5_3 cards.

sc_pkcs15_bind_internal is called to get tokenInfo as CardOS
cards are substantially PKCS15 cards. But some V5_* cards have
errors in the tokenInfo, Which are corrected.

For older CardOS cards, card-cardos.c will create all the
card->algorithms.

Pkcs15-cardos.c will check for card->algorithms and if there
are none, it will do the following:

SC_CARDCTL_CARDOS_PASS_ALGO_FLAGS is called twice. First to get
the flags as set by user via opensc.conf card_atr or default
flags set by the card driver.  Then after determining from the
tokenInfo what algorithms the card can support, the new flags
are passed to card_cardos.c to create card->algorithms.

https://atos.net/wp-content/uploads/2018/11/CT_181026_LPM_CardOS_V5-3_Multifunctionality_FS_en3_web.pdf
says card supports: "“Command chaining” in accordance with ISO/IEC 7816-4"

To take advantage of this with older readers, max_send_size and max_recv_size
is now based on minimum of reader limits and  "data_field_length" from card.
This should allow card to work in older readers not capable of extended APDU.
So far current cards we have seen do no appear to support “Command chaining”.

 Changes to be committed:
	modified:   src/libopensc/Makefile.am
	modified:   src/libopensc/Makefile.mak
	modified:   src/libopensc/card-cardos.c
	modified:   src/libopensc/cardctl.h
	modified:   src/libopensc/cards.h
	new file:   src/libopensc/pkcs15-cardos.c
	modified:   src/libopensc/pkcs15-syn.c
	modified:   src/libopensc/pkcs15-syn.h
2020-05-09 23:59:51 +02:00
Frank Morgner 7e0465370f
Merge pull request #1914 from marschap/PGPtool-fixes
PGPtool fixes
2020-02-01 22:27:58 +01:00
Peter Marschall cd4dc5a9e7 OpenPGP: refactor definitions into header file
Factor out constants and structure definitions into a header file
so that they can be also used consistently in openpgp-tool.
2020-01-26 13:14:37 +01:00
Jakub Jelen f61d9b3b53 Implement new Gemalto IDPrime driver
The card is largely ISO 7816 compliant, but does not provide any
simple way of listing the content which is supported by current
PKCS#15 implementation therefore the PKCS#15 emulator had to be
used.

The certificates are compressed in a similar way as in DNIE
cards which complicates reading from the card and which I think
could be moved to the shared ISO (or some other file since I saw
that code already many times).

The card supports wide range of algorithms including
RSA-PSS and RSA-OAEP padding schemes in-card. On the other hand,
it does not allow raw RSA and SHA1 hashes on card anymore.

The card is manufactured by Gemalto so it has strict ATR which
can be used for detection.
2020-01-07 14:16:46 +01:00
Frank Morgner 94388f9538 fixed more clang-tidy warnings 2019-06-05 13:48:51 +02:00
Frank Morgner 1423c6bb90 CI: integrate clang-tidy (disabled)
files that have warnings are currently excluded
2019-05-21 19:34:46 +02:00
Martin Paljak b3d4a0d69a EstEID 2018+ driver
This adds support for a minimalistic, small and fast card profile based on IAS-ECC.

Based on information from https://installer.id.ee/media/id2019/TD-ID1-Chip-App.pdf
and proprietary driver snoops.

Thanks to @metsma and @frankmorgner.

Change-Id: I2e4b4914d8a3b991d9a639728695abf4a2362ca0
2019-05-02 11:47:31 +03:00
Raul Metsma 1e6d3df201 Remove un-lincenced header file
Signed-off-by: Raul Metsma <raul@metsma.ee>
2019-03-13 21:19:26 +01:00
Frank Morgner 106b3a28b1 acos5: removed incomplete driver
fixes https://github.com/OpenSC/OpenSC/issues/1204
2019-03-13 21:17:54 +01:00
opensignature 84f0a88edb Remove postecert and infocamere support because no longer issued (#1584)
* Remove postecert and infocamere support because no longer issued

* Remove wrong changes

* reset NEWS

* EC_POINT_set_affine_coordinates_GFp and EC_POINT_get_affine_coordinates_GFp are
deprecated, use EC_POINT_set_affine_coordinates and EC_POINT_get_affine_coordinates

* If OPENSSL API version is < 3 use old functions EC_POINT_[sg]et_affine_coordinates_GFp

* Move the OpenSSL compatibility stuff to src/libopensc/sc-ossl-compat.h
2019-01-30 22:01:24 +01:00
Jakub Jelen eaed345a76 Add missing header file to the tarball 2018-11-05 09:15:20 +01:00
Jakub Jelen e2b1fb81e0 Restore minimal CAC1 driver for legacy cards (#1502)
* Add minimal CAC1 driver for legacy cards.

It is using the same pkcs15 backend as the CAC2 cards as well as some of
the CAC2 driver methods.

The separation is made mostly for easier card matching or disabling.
2018-10-30 17:27:28 +01:00
Frank Morgner 4de0d06a93 use single quotes for passing define
makes sure that the shell doesn't evaluate parts of the define
2018-07-17 14:49:27 +02:00
Frank Morgner a0b6643fa7 Use hard coded default SM module (path)
- avoids the need to set this default in opensc.conf
- fixes loading of (unknown) local library
- removes some unused defines from config.h
2018-07-17 14:49:27 +02:00
Jakub Jelen b6e08e008e Move the Global Platform related commands to separate file and port existing code to that 2018-05-18 23:52:01 +02:00
Frank Morgner 594e125f06 Added PKCS#15 emulator for DIN 66291 profile 2017-10-27 19:48:22 +02:00
Frank Morgner 0502a839c6 unified reading of EF.GDO 2017-10-27 19:48:22 +02:00
Frank Morgner b2cde0f7fb Windows: Added support for notifications 2017-08-02 19:03:16 +02:00
Frank Morgner bf828014e5 macOS: Added support for notifications
- adds framework for user defined message strings
- automatically determine the system's language
2017-08-02 19:02:05 +02:00
Frank Morgner 74ec7b04ff sc-hsm: Add support for SoC
- eac: allow CA without EF.CardSecurity
- sc-hsm: implemented CA based on document PKI
- sc-hsm: adds receive limit for SoC card
- introduces dedicated card type for SoC card
- md: integrate card's PIN pad capabilities
- installer: added SC-HSM SoC card to registry
- pkcs15-tool: Added support for PIN entry on card
- change/unblock PIN: add support for PIN entry on card
- added OpenPACE to macOS build
- travis-ci: install gengetopt/help2man via brew
- sc-hsm: Cache EF.C_DevAut
- sc-hsm: Prevent unnecessary applet selection and state resets
- sc-hsm: added support for session pin
- sc-hsm: avoid multiple AID selection
- sc-hsm: Use the information from match_card for all subsequent selections of the applet
- sc-hsm: cache optional files as empty files (Decoding the files will reveal that they were not existing prior caching. This avoids selecting the file though we have already tried to cache the file before.)
- use dedicated directory for CVC trust anchors
- appveyor: added OpenPACE to windows build
2017-05-22 16:25:08 +02:00
Frank Morgner 013bdcb264 macOS: added support for access via CryptoTokenKit
Binaries still need to be signed with the com.apple.security.smartcard
entitlement. The command should look something like this:

codesign --force --entitlements MacOSX/pcsc.entitlements --sign "Mac Developer" target/Library/OpenSC/bin/*
codesign --force --entitlements MacOSX/pcsc.entitlements --sign "Mac Developer" target/Library/OpenSC/lib/*.dylib
codesign --force --entitlements MacOSX/pcsc.entitlements --sign "Mac Developer" --deep target/Library/OpenSC/lib/opensc-pkcs11.bundle
codesign --force --entitlements MacOSX/pcsc.entitlements --sign "Mac Developer" --deep target/Library/Security/tokend/OpenSC.tokend
2017-04-03 12:30:03 +02:00
Maciej S. Szmigiero 1b4c626d78 Make minidriver buildable again on mingw
Currently, minidriver build is broken on mingw. Let's make it work again.

For this, include adapted cardmod-mingw-compat.h with few function argument
decorations from Alon Bar-Lev's old build repository to make mingw build
almost self-contained - still requires cardmod.h from CNG, however.

Signed-off-by: Maciej S. Szmigiero <mail@maciej.szmigiero.name>
2017-03-27 10:57:21 +02:00
Frank Morgner 45a7ea9737 card-npa: moved to internal card drivers 2017-03-20 21:28:48 +01:00
Frank Morgner 40acedcc21 Added support for PIN commands via escape commands
As defined in BSI TR-03119 to issue SCardTransmit (with Uses
Pseudo-APDU) instead of SCardControl (with FEATURE_VERIFY_PIN_DIRECT).
It allows using a very basic PC/SC reader driver without special support
for PIN verification or modification (such as the default CCID driver on
Windows).

Also gets IFD vendor information via escape commands.

PC/SC's Get Uid command is now only triggered if enable_escape = true;
was set by the user to allow disabling wrapped commands on broken
readers (see https://github.com/OpenSC/OpenSC/issues/810)
2017-03-20 21:28:48 +01:00
Frank Morgner a4f64d9439 Added (external) card driver for German ID card
(Imported libcardnpa from https://github.com/frankmorgner/vsmartcard)

- Added generic SM implementation of ISO/IEC 7816-8
- Added implementation of extended access control as defined by
  - BSI TR-03110
  - ICAO Doc 9303
  - ISO/IEC 7501
- Added tool for German ID card (and other EAC tokens)
- renamed folder libsm to sm
2017-03-20 21:28:48 +01:00
Jakuje 777e2a3751 adding a CAC support into OpenSC (#841)
* Includes adding support for parsing extensions from a certificate.
* Move lebytes2ushort() to related functions in internals.h
* Adds Simple TLV related functions
2017-02-27 11:05:12 +01:00
Nuno Goncalves dc073114a0 pkcs15-pteid: new implementation
This implementation reads most of the data from the pkcs15 structure on card, so the objects list are greatly reduced.

This improves several pending issues:

* drop support for IAS card type
In accordance to [1] IAS card type is no longer issued since version
004.003.11 (2010-06-15) and as a legal requirement all documents have
been destroyed or declared lost.

[1] https://www.cartaodecidadao.pt/documentos/DOC_01-DCM-15_V3_CC_Controlo_Versao_2016-01-20.pdf

* fix pteid_cert_ids
The Signature and Authentication Sub CA certificates ids were wrong.

* add objects and fix flags
Add Root CA certificate.
Add data objects SOD and TRACe
Data object 'Citizen Notepad' doesn't require login to be read. Remove flags.

* Support PIN max tries and tries left report

* Properly report cards with 2048b keys.

Suggested-by: João Poupino <joao.poupino@gmail.com>
Suggested-by: André Guerreiro <andre.guerreiro@caixamagica.pt>
Signed-off-by: Nuno Goncalves <nunojpg@gmail.com>

-- closes #806
2016-11-08 13:02:03 +01:00
Jakub Jelen 790ed5fcd7 Add Coolkey driver
Author: Robert Relyea <rrelyea@redhat.com>

Coolkey driver improvements:
 * Remove hardcoded list and use SimCList
 * Whitespace cleanup
 * Remove bogus if
 * drop inline keywords
 * proper path to include sys/types.h
 * full name of ushort type
 * condition to use compression
 * proper include path
 * Resolve template name conflict in Tokend

Clean up the copyright headers

-- rebased into one commit by VTA
-- closes #896
2016-11-08 10:40:07 +01:00
Nikos Mavrogiannopoulos c0196b4246 src/libopensc/Makefile.am: add missing header (#895)
That ensures that sc-ossl-compat.h is included on releases.
2016-10-31 12:12:18 +01:00
HAMANO Tsukasa 33a16b4f4e New: jpki card driver
VTA: cosmetic touch and rebase to one commit
close PR #801
2016-07-17 16:36:13 +02:00
Viktor Tarasov 9ac4120594 pkcs15: 'aid' argument for emulator init
Allows to PKCS#15 emulator to bind more then one application
2016-04-08 10:48:58 +02:00
Viktor Tarasov 47eb21175c p15: auxiliary data in prkey info data type 2016-04-08 10:48:58 +02:00
LE TOUX Vincent 6a243449a0 First support for GIDS card
- minidriver included by default in Windows
- GIDS Applet is available here https://github.com/vletoux/GidsApplet
- some informative technical information is available here
  http://www.mysmartlogon.com/knowledge-base/generic-identity-device-specification-gids-kb/

closes https://github.com/OpenSC/OpenSC/pull/651
2016-02-19 00:12:16 +01:00
German Blanco 1596ca4244 DNIe user interface moved into card-dnie.c. 2015-11-10 12:10:56 +01:00
vletoux 976db5cb04 card-masktech: initial commit
card-masktech.c: fix building issues on the integration platform

card-masktech.c: fix linux compilation errors

honour HAVE_CONFIG_H

card-masktech.c: take in account Frank's remark about extended APDU in masktech_decipher

remove trailing spaces
2015-05-05 10:13:26 +02:00
Philip Wendland 48bd6b0964
Add support for the IsoApplet (Java Card applet)
The IsoApplet can be found here:
https://github.com/philipWendland/IsoApplet
Add read/write support for this applet, including RSA and
ECC support.
2015-02-20 21:55:26 +01:00
Martin Paljak 332ced5be7 Remove the bogus javacard "driver".
I had some ideas on how to improve the experience for JavaCards
but that path did not get implemented further and my approach now
is very different.

While it would be nice if OpenSC (command line) detected
somehow blank JavaCard-s and informed the user that steps a-b-c
should be taken to make use of it, it doesn't really fit in.
2014-04-21 13:44:27 +02:00
German Blanco 63ce563d76 Adding support for DNIe. 2013-06-13 17:31:56 +02:00
Viktor Tarasov 8d7c773561 SM: move SM APDU procedures to dedicated source file
new SM errors: 'session-already-opened' and 'invalid-checksum'
declare typed data for DH SM session
2013-01-06 16:40:17 +01:00
Ludovic Rousseau ea40e7fe24 Use AM_CPPFLAGS instead of INCLUDES
Fix autoreconf warnings:

$ autoreconf -vis -Wall
[...]
src/common/Makefile.am:12: warning: 'INCLUDES' is the old name for 'AM_CPPFLAGS' (or '*_CPPFLAGS')
src/libopensc/Makefile.am:19: warning: 'INCLUDES' is the old name for 'AM_CPPFLAGS' (or '*_CPPFLAGS')
src/minidriver/Makefile.am:15: warning: 'INCLUDES' is the old name for 'AM_CPPFLAGS' (or '*_CPPFLAGS')
src/pkcs11/Makefile.am:10: warning: 'INCLUDES' is the old name for 'AM_CPPFLAGS' (or '*_CPPFLAGS')
src/pkcs15init/Makefile.am:36: warning: 'INCLUDES' is the old name for 'AM_CPPFLAGS' (or '*_CPPFLAGS')
src/scconf/Makefile.am:12: warning: 'INCLUDES' is the old name for 'AM_CPPFLAGS' (or '*_CPPFLAGS')
src/sm/Makefile.am:8: warning: 'INCLUDES' is the old name for 'AM_CPPFLAGS' (or '*_CPPFLAGS')
src/tests/Makefile.am:9: warning: 'INCLUDES' is the old name for 'AM_CPPFLAGS' (or '*_CPPFLAGS')
src/tools/Makefile.am:15: warning: 'INCLUDES' is the old name for 'AM_CPPFLAGS' (or '*_CPPFLAGS')
2012-09-25 23:03:38 +02:00
Viktor Tarasov 41861e42b0 no 'pace' in common part
'PACE' is extremely card specific protocol and has not to be ostensibly
present in the common part of OpenSC:
 * currently in OpenSC there is no card driver that supports or uses this protocol;
 * amazing content of the common 'sc_perform_pace' -- beside the verbose logs
   the only substantial action is to call the card/reader specific handler.
   According to the current sources and the pull request 83
   this 'common' procedure is called by the card driver or
   card specific tool/operation.
 * currently the 'PACE' can be thouroghly tested only by one person (Frank Morgner),
   and only using the OpenSSL patched with the PACE specific patch.
   So, at least a dedicated configuration option could be introduced when comiting PACE to the common part.
 * common 'sc_perfom_pace' has the same role as the 'initialize-SM' handler of the existing SM framework
   and can be implemented as card specific SM, as the others cards do.
   This confirmed by Frank Morgner, the author of PACE commits and nPA card driver, himself.
   (https://github.com/OpenSC/OpenSC/pull/83)
2012-08-30 18:51:42 +02:00
Frank Thater 1a7ca32865 Added support for SmartCard-HSM and ECC keys
modified:   src/libopensc/Makefile.am
new file:   src/libopensc/card-sc-hsm.c
new file:   src/libopensc/card-sc-hsm.h
modified:   src/libopensc/cards.h
modified:   src/libopensc/ctx.c
modified:   src/libopensc/pkcs15-prkey.c
new file:   src/libopensc/pkcs15-sc-hsm.c
modified:   src/libopensc/pkcs15-syn.c
2012-08-20 11:22:01 +02:00
Viktor Tarasov 00b069a08e epass2003: support for ePass2003 card in read/write modes 2012-06-08 20:17:36 +02:00
Viktor Tarasov ea5a19e27e iasecc: SM add related procedures 2012-06-08 20:17:35 +02:00
Viktor Tarasov cfd5aaba7d SM: initial implementation of secure messaging framework 2012-06-08 20:17:35 +02:00
Viktor Tarasov 6c2fa7b462 pkcs15-skey: support for 'SecretKey' object type
For a while only implemented decoding of 'genericSecretKey', 'desKey', 'des2Key' and 'des3Key' keys.
2012-05-31 11:36:04 +02:00