Commit Graph

218 Commits

Author SHA1 Message Date
Doug Engert 0380142482 Fix obtaining key_length i.e. field_length pkcs15-openpgp
card-opennpgp.c and pkcs15-openpgp.c have a strang way of
using sc_object_id_t to store what they call a binary_oid
or oid_binary.  It is used to convert the EC curve asn1
returned in the cxdata.

This code uses asn1_decode_object_id to use sc_object_id_t
as used in the rest of the code.

The code and ec_curve tabes in card-openpgp.c where not changed.

pkcs15-openpgp.c was channge si to can use:
algorithm_info = sc_card_find_ec_alg(card, 0, &oid);
to retried the key_length to add to the pubkey and prkey entries.
The EC and EDDSA needs (i.e. field_length)  to run.

 On branch eddsa
 Your branch is up to date with 'Jakuje/eddsa'.

 Changes to be committed:
	modified:   card.c
	modified:   pkcs15-openpgp.c
2021-03-01 15:43:28 +01:00
Jakub Jelen caae75758c Add internal support for (X)EdDSA keys 2021-03-01 15:42:26 +01:00
Jakub Jelen 61eb4e487e card: Correctly free pointers durint cache invalidation
As the whole structure is memset(0) on the following line,
we need to clean the pointers before doing so.

Thanks oss-fuzz

Related to:
https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=27797
2020-12-04 09:30:10 +01:00
Peter Marschall 16c889cf7d spelling fixes
Fix various spelling errors, mostly in comments but also in texts displayed.

Errors found & interactively fixed using 'codespell', with additional manual
checks after the fixes.
2020-08-30 10:35:14 +02:00
Frank Morgner 70baccbe95 iso7816_*_sfid: return the number of bytes processed 2020-01-31 15:04:31 +01:00
Frank Morgner ad8b9f5034 sc_*_binary: interpret SC_SUCCESS as EOF 2020-01-31 14:47:45 +01:00
Frank Morgner 1f9b3f3538 sc_*_record: return the number of bytes processed 2020-01-30 23:54:45 +01:00
Frank Morgner 91af2c7513 repeat sc_erase_binary if needed
return the number of bytes processed
2020-01-30 23:49:36 +01:00
Frank Morgner 14aaa64d3e avoid calling sc_*_binary recursively
- lock the card early to avoid deselection of the file
- check on integer overflows of indices

fixes https://github.com/OpenSC/OpenSC/issues/1919
2020-01-30 22:27:10 +01:00
Jakub Jelen 75847f4e93 Make ef_dir variable local
Thanks oss-fuzz

https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=18821
2019-11-13 15:48:40 +01:00
Jakub Jelen 5490d73f31 card: Avoid integer overflows
Resolves:
https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=17007
2019-10-03 13:57:09 +02:00
Doug Engert 3b632e64a1 Fix #1731 sc_format_apdu_cse_lc_le fails to set Le correctly
Changed four places where "<" should be "<=" so Le will be set correctly
Previous for 65K (extended) or 256 (short) Le is left set to 0.
This then caused Le to be to be not added to APDU as Le==0
Code later converts actual Le in APDU to be set to 0 to mean 256 or 65K.

SC_APDU_CASE_*_EXT are changed to SC_APDU_CASE_* so sc_detect_apdu_cse
to set the cse based on card capabilities as well as data chaining.

This commit is not well tested and neds review.

 On branch fix-1731
 Changes to be committed:
	modified:   src/libopensc/card.c
2019-09-09 12:49:56 +02:00
Frank Morgner b6be87a348 make sc_format_apdu_ex agnostic to card properties 2019-08-20 13:38:20 +02:00
Raul Metsma 9ba8f56037 Change u8 *data to const because sc_apdu unsigned char *data is const
Name sc_format_apdu parameters for IDE help hints

Signed-off-by: Raul Metsma <raul@metsma.ee>
2019-04-03 22:15:54 +02:00
Frank Morgner 27526de021 implemented sc_format_apdu_ex 2019-03-05 13:54:13 +01:00
Frank Morgner 7a7ff50422 fixed memory leaks during card initialization 2019-01-30 21:57:59 +01:00
Frank Morgner f2145eca79 don't debug pointers 2018-12-06 09:26:42 +01:00
Frank Morgner a899a46b09 replaced SC_TEST_RET with LOG_TEST_RET 2018-12-06 09:26:42 +01:00
Frank Morgner 00a150f74c replaced SC_FUNC_RETURN with LOG_FUNC_RETURN 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
Frank Morgner cf55cdc637 replace SC_FUNC_CALLED with LOG_FUNC_CALLED 2018-12-06 09:26:42 +01:00
Frank Morgner ad83c2c5a9 use proper debug level for card matching 2018-11-20 12:48:58 +01:00
Hannu Honkanen aa814fd8e8 Implemented C_Wrap into PKCS#11 interface. Added support for wrapping and unwrapping with secret keys into framework-pkcs15.c and all the way to the card driver level. 2018-10-31 10:24:19 +02:00
Priit Laes 2eae5e70f5 Mark atr table argument as const in match_atr_table and _sc_match_atr functions
This allows us to mark driver-specific atr tables as constants.
2018-08-22 22:50:30 +02:00
Frank Morgner ff8ec86f26 avoid looping forever in GET CHALLENGE
fixes https://github.com/OpenSC/OpenSC/issues/1440
2018-08-20 14:37:20 +02:00
Frank Morgner 9294058d5c fixed requesting DWORD with sc_ctx_win32_get_config_value
the length of the value is not determined by strlen()
2018-08-05 11:35:12 +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
Frank Morgner 2c0d1b9ab0 reset sc_card_t during card detection
fixes https://github.com/OpenSC/OpenSC/issues/1417
2018-07-11 10:12:42 +02:00
Frank Morgner 410cdf0dcc refactored sc_get_challenge
Let sc_get_challenge() do sc_lock() and loop through the card driver's
get_challenge() until enough bytes were collected. The card driver's
get_challenge() now returns the number of bytes collected (less or equal
than requested) or an error code.

- Allow more code re-use.
- PIV driver now uses ASN.1 parser for reading the random bytes
2018-05-23 14:20:28 +02:00
Peter Marschall 5abe99d228 fix typos
Mass-typo fixing, almost exclusively in comments and text strings.

While at it also fixed a few (very few) grammar errors.
2018-04-15 09:34:45 +02:00
Frank Morgner fc64c87c5c with keep_alive, use cache only within the transaction
fixes https://github.com/OpenSC/OpenSC/issues/1159
2018-04-06 12:20:32 +02:00
Timo Teräs 0576ccce0c Add _sc_card_add_generic for registering secret key algorithms 2017-06-13 10:40:36 +02: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
Frank Morgner e7915ec198 replace assert with error handling 2017-04-04 09:11:35 +02:00
Frank Morgner 70313512ad recognize T=0 limitation of sending 255 bytes
fixes https://github.com/OpenSC/OpenSC/issues/1009
2017-04-03 09:08:40 +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
Maciej S. Szmigiero 7f778ccff8 Fix most of warnings shown when building on Linux and mingw
This commit fixes most of warnings shown by GCC on 64-bit Linux, 32-bit and
64-bit mingw builds (with SM and OpenSSL enabled).

These warnings were mostly caused by missing casts.

In minidriver there was also a bit of unused variables and dead code.

Remaining warnings on mingw are mostly caused by GCC not recognizing on
this platform "ll" size specifier (present at least since
Visual Studio 2005, also in mingw own CRT) and "z" size specifier (this one
will be fixed in next commits).

There is also a warning about pointer truncation on Win64 when making
PKCS#11 object handle from pointer to this object.
This is a legitimate warning, since it could result in the same handles
being generated from different pointers and so from different objects.

Signed-off-by: Maciej S. Szmigiero <mail@maciej.szmigiero.name>
2017-03-27 10:58:26 +02: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
Michał Trojnara 645780e6d4 NULL parameter check moved to sc_file_free()
This fixes numerous issues where the check is *not* performed,
and also simplifies the code.
2017-01-10 12:46:44 +01:00
Doug Engert 84a69ce2ba libopensc: introduce 'reader_lock_obtained' card operation
Add card_reader_lock_obtained function to sc_card_operations

During sc_lock, if card->reader->ops->lock is called, card->ops->card_reader_lock_obtained will be called.
If PCSC is being used as the reader driver, this occures just after pcsc_lock  has done a SCardBeginTransaction
and our process has exclusive control over the card. The card driver can then determine if the state of the
card has changed, and take action to get the card into an acceptable state.

If card->reader->ops->lock returns SC_ERROR_CARD_RESET, indicating some other process has interefered
with the state of the card. was_reset=1 is passed to card->ops->card_reader_lock_obtained.

Some examples of actions that could be done by the card driver is to select the AID and reset logged_in.

Currently the card driver is not notified. So no default card_reader_lock_obtained is defined in iso7816.c
2016-08-15 13:31:08 +02:00
Doug Engert 1e82dbe5c7 libopensc: fix reopen SM after reader reconnect
After card reset detected, run SM open under new transaction

Before trying to reestablish SM session or onte code that may
need to use a transaction,  get the transaction that will be
used by the caller od sc_lock.

closes #837
2016-07-29 17:29:38 +02:00
Frank Morgner 60f2d06308 libopensc: fetch card's UID
Fetch card's UID.
For file caching, use UID if SN is not available.
2016-07-24 17:16:29 +02:00
Viktor Tarasov 66515989d8 win32: method to get config option from registers 2016-04-17 12:43:18 +02:00
Viktor Tarasov 2173450664 log: print file-id in 'create-file' 2016-03-06 19:28:59 +01:00
Frank Morgner e1073c09ea handle checking of file output in sc_select_file
fixes https://github.com/OpenSC/OpenSC/issues/576
2015-10-14 23:25:13 +02:00
Frank Morgner 2d9802308f reactivate handling of `0` for max_recv/send_size
The special value still needs to be handled for commands that are issued
during card initialization. This especially concerns T=0 cards that need
to use iso_get_response.

fixes #533
regression of 85b79a3332
2015-08-26 02:55:35 +02:00
Frank Morgner 85b79a3332 don't always overwrite max_send_size/max_recv_size
If the reader announces extended length support, but the card driver
leaves max_send_size/max_recv_size at `0`, max_send_size/max_recv_size
previously would have been overwritten with the reader's size though the
card might not have set SC_CARD_CAP_APDU_EXT. This commit fixes this
behavior.

Additionally card->max_send_size/max_recv_size is always initialized to
a value different from 0 after the card initialization. This removes the
need to check for this special value in all subsequent calls.
2015-08-11 23:08:41 +02:00
Frank Morgner d7d64ee8d4 Merge pull request #494 from frankmorgner/fork
After a fork do not release resources shared with parent
2015-08-04 10:32:01 +02:00
Frank Morgner c92e3b4f98 honour PC/SC pt 10 dwMaxAPDUDataSize
closes #306
2015-07-28 09:49:44 +02:00
Frank Morgner 7cec500e54 added flags to sc_context_t
- is initialized in sc_context_create with parm->flags
- removes members paranoid_memory and enable_default_driver
2015-07-22 17:30:21 +02:00