Commit Graph

198 Commits

Author SHA1 Message Date
Peter Popovec ba85ae75e3 opensc-explorer, command "info" - added information about LCS
Information about "Life cycle status byte" is now available in listing.
Also src/libopensc/types.h update - added more LCSB definitions.
iso7816_process_fci () update: improved tag 0x8A parsing.

Fixes in card-flex.c and card-miocos.c - SC_FILE_STATUS_xxx is not
bitfield.
2021-01-22 19:04:22 +01:00
Frank Morgner 480da424a5
fix possible infinite recursion (#2151)
fixes https://github.com/OpenSC/OpenSC/issues/2149
2020-11-25 09:27:28 +01:00
Jakub Jelen 88f3d19479 opensc: Expose iso7816_build_pin_apdu function to support different pin APDUs 2020-10-24 21:01:18 +02:00
Peter Marschall 376cc2d910 iso7816: set record_length for any record-oriented EF 2020-08-19 09:58:12 +02:00
Frank Morgner a7d563b657
Merge branch 'master' into recursion 2020-05-11 18:45:36 +02:00
Jakub Jelen 508f8a9fce iso7816: Do not recurse if no data was returned
Thanks oss-fuzz

https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=20399
2020-05-07 02:32:46 +02:00
Peter Marschall cd5c91b8ef iso7816: extend iso7816_process_fci()
* define file type SC_FILE_TYPE_UNKNOWN
* explicitly set file->type to SC_FILE_TYPE_UNKNOWN for unkown files
* store full-length file type attributes via sc_file_set_type_attr()
* parse # of records for record-oriented EFs
* parse record length for for EFs with fixed-size records
  Note: I am not sure, parsing the record length only for EFs with fixed-
        size records is the correct approach.
        My interpretation of the norm is slightly different, but it seems
        to be in-line what's currently in opensc:
        - there's a comment hinting at that interpretation
        - otherwise variable size records fail to be read in opensc-explorer
        So I leave it this way for now.
2020-02-18 20:47:26 +01:00
Frank Morgner 70baccbe95 iso7816_*_sfid: return the number of bytes processed 2020-01-31 15:04:31 +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 aaa302ca35 asn1: Allow non-strict INTEGER parsing for other code paths (FCI parsing) 2020-01-07 14:50:47 +01:00
Frank Morgner 0e97ef2ce3 don't use sc_format_apdu_ex in default driver
fixes https://github.com/OpenSC/OpenSC/issues/1731
closes https://github.com/OpenSC/OpenSC/pull/1734
2019-08-20 13:38:20 +02:00
Martin Paljak ea74308512 iso7816_read_binary: do not assume that 6282 is returned with data
Instead of a double check_sw call in case there is no data, assume
that a SW is properly sent by the card and do not expose
SC_ERROR_FILE_END_REACHED outside of the function
(like sc_pkcs15_read_file)

This is to facilitate Estonian eID 2018+ that instead of properly returning
6282 with trunkated data, 9000 is returned and next READ BINARY returns
6b00 (invalid p1/p2). The change should be generally harmless for well-behaving
cards.

Change-Id: I7511ab4841d3bcdf8d6f4a37a9315ea4ac569b10
2019-04-01 12:51:00 +02:00
Frank Morgner 27526de021 implemented sc_format_apdu_ex 2019-03-05 13:54:13 +01:00
Frank Morgner 141ec6ab23 added shortcut to update binary via sfid 2019-01-15 07:31:20 +01:00
Frank Morgner a899a46b09 replaced SC_TEST_RET with LOG_TEST_RET 2018-12-06 09:26:42 +01:00
Frank Morgner 907c9479e2 replace sc_debug_hex with sc_log_hex 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
Hannu Honkanen 5f51d5d315 Added implementation of C_UnwrapKey all the way from PKCS#11 interface to the card driver level.
Not yet complete, but can be run with CKA_TOKEN=FALSE set in the target object. Currently unwrapping emulated
with a decrypt operation in card-myeid.c. To be improved.
2018-10-31 10:22:16 +02:00
Jakub Jelen e5da6b66b9 iso7816: Replace asserts with explicit length checks to make coverity happy 2018-10-01 23:07:34 +02:00
Peter Marschall 0603c3b7fc iso7816: fix typo in previous commit 2018-06-24 10:34:49 +03:00
Peter Marschall 2818e0f703 iso7816: update & extend error codes
While at it, do some space policing.
2018-06-24 10:34:49 +03: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
Frank Morgner ae31408f81 fixed checking SW in iso7816_read_binary_sfid
fixes https://github.com/OpenSC/OpenSC/issues/1360
2018-05-18 23:39:16 +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 45ad44e311 fixed handling SC_ASN1_TAG_EOC from sc_asn1_read_tag
We can't check for `tag == SC_ASN1_TAG_EOC` directly, because this
would also be true for a tag of 0x80 (with `class ==
SC_ASN1_CLASS_CONSTRUCTED`). So what we do is we check for the output
buffer to be NULL!

fixes https://github.com/OpenSC/OpenSC/issues/1273
2018-03-30 08:28:51 +02:00
Frank Morgner 7ca16a7531
Merge pull request #1256 from dengert/piv-aid-discovery
PIV detection of AID using Discovery Object before doing select AID - Partial 
 #1243
2018-03-16 22:06:16 +01:00
Frank Morgner c3ffdecd0b rename SC_SEC_ENV_KEY_REF_ASYMMETRIC to SC_SEC_ENV_KEY_REF_SYMMETRIC
This reflects the actual use of the identifier by the card drivers.
2018-03-09 14:36:55 +01:00
Doug Engert 27add2ee3c Inform pkcs15 and card drivers of PKCS#11 C_Login(CKU_CONTEXT_SPECIFIC)"
Framework-pkcs15.c will now set pin_info->auth_method to SC_AC_CONTEXT_SPECIFIC

iso7816.c iso7816_build_pin_apdu treats this the same as SC_AC_CHV

card-piv.c piv_pin_cmd sets priv->xcontext_specific=1 and calls sc_lock before
the verify command. If the verify fails sc_unlock is called.
Later after the next card command returns, if priv->context_specific==1 piv_check_sw
will call sc_unlock as the application may not have requested the crypto but
some other command.

Some additional calls to sc_lock and sc_unlock have been added to make sure
PIV internal command sequences including the crypto command ('87') and any get
responses are always protected by a lock.

This guarantees the card is locked for verify and the next command
which should be the crypto operation. The PIV card also inforces this restriction
on the card.

This is based on suggestions in:
://github.com/OpenSC/OpenSC/pull/1256#issuecomment-361975751

 On branch piv-aid-discovery

 Changes to be committed:
	modified:   src/libopensc/card-piv.c
	modified:   src/libopensc/iso7816.c
	modified:   src/libopensc/types.h
	modified:   src/pkcs11/framework-pkcs15.c
2018-02-22 09:37:46 -06:00
Frank Morgner 449f6c2b94 OpenPGP: Added support for PIN logout and status 2018-01-22 15:26:44 +01:00
Frank Morgner ddeb01ddc1 ISO7816: allow nested CP DOs 2018-01-22 15:26:44 +01:00
Frank Morgner 5ca99febe3 ISO 7816-4 doesn't force a maximum for GET CHALLENGE 2017-12-04 21:09:26 +01:00
Frank Morgner 8de544653c dump data with sc_debug_hex and sc_log_hex 2017-11-17 10:03:54 +01:00
Frank Morgner 04a7075290 fixed compiler warnings 2017-11-09 12:42:29 +01:00
Frank Morgner bc075d6639 iso7816: don't show error for PIN status on 63C3 2017-10-27 19:48:22 +02:00
Frank Morgner 32aa51a0f6 avoid logically dead code 2017-06-09 10:33:46 +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 74f11a32a5 removed obsolete comment 2017-04-20 10:58:54 +02:00
Frank Morgner 9d15326de1 fixed more coverity issues 2017-04-20 10:58:54 +02:00
Frank Morgner e7915ec198 replace assert with error handling 2017-04-04 09:11:35 +02:00
Frank Morgner c5e40127d0 Coverity fixes (#1012)
card-cac.c
 * CLANG_WARNING: The left operand of '<' is a garbage value
card-coolkey.c
 * CLANG_WARNING: overwriting variable
 * CPPCHECK_WARNING: memory leak / overwrite variable
 * CLANG_WARNING: null pointer dereference
 * UNUSED_VALUE: unused return value
card-gids.c
 * CLANG_WARNING: Branch condition evaluates to a garbage value
 * SIZEOF_MISMATCH: suspicious_sizeof
card-myeid.c
 * RESOURCE_LEAK: Variable "buf" going out of scope leaks the storage it points to.
 * CLANG_WARNING: overwriting variable
 * (rewrite not to confuse coverity)
pkcs15-cac.c
 * RESOURCE_LEAK: Variable "cert_out" going out of scope leaks the storage it points to.
pkcs15-coolkey.c
 * UNUSED_VALUE: unused return value
pkcs15-piv.c
 * RESOURCE_LEAK: Variable "cert_out" going out of scope leaks the storage it points to.
pkcs15-sc-hsm.c
 * DEADCODE
pkcs11/framework-pkcs15.c
 * RESOURCE_LEAK: Variable "p15_cert" going out of scope leaks the storage it points to.
pkcs15init/pkcs15-lib.c
 * CLANG_WARNING: Assigned value is garbage or undefined
pkcs15init/pkcs15-myeid.c
 * UNREACHABLE: Probably wrong placement of code block
tests/p15dump.c
 * IDENTICAL_BRANCHES
pkcs15-init.c
 * CLANG_WARNING: Potential leak of memory pointed to by 'args.der_encoded.value'
pkcs15-tool.c
 * RESOURCE_LEAK: Variable "cert" going out of scope leaks the storage it points to.
 * MISSING_BREAK: The above case falls through to this one.
sc-hsm-tool.c
 * CLANG_WARNING: Potential leak of memory pointed to by 'sp'
westcos-tool.c
 * FORWARD_NULL: Passing null pointer "pin" to "unlock_pin", which dereferences it.
 * (rewrite not to confuse coverity)
card-cac.c
* Avoid malloc with 0 argument
gids-tool.c
* FORWARD_NULL -- copy&paste error
scconf.c
* CLANG_WARNING: Call to 'malloc' has an allocation size of 0 bytes

closes #982
2017-04-03 13:43:30 +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
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
Jakub Jelen 92765f612e iso7816: Parse TL using ASN1 parser to avoid (possibly) wrong assumptions about length of both parts 2017-01-28 01:11:54 +01:00
Frank Morgner 81d16fcc27 iso7816: propagate the PIN status on verify/change 2017-01-10 13:00:26 +01:00
Peter Popovec 539c89e581 opensc-explorer: show tag 0x82 for unknown files
For reserved/unknown file type print value of 0x82 tag, instead of "???" string.

closes #918
2016-12-18 12:50:11 +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
Frank Morgner 2f10de4f5c use sc_pkcs15_get_pin_info in C_GetTokenInfo
introduced paramter to signal back the login state
- used for the pin command SC_PIN_CMD_GET_INFO
- implemented in accordance to ISO 7816-4; all other implementations
  are currently set to an unknown login state

implemented and exporeted sc_pkcs15_get_pin_info

use sc_pkcs15_get_pin_info in C_GetTokenInfo

C_GetSessionInfo: Check whether a logout was done

Closes https://github.com/OpenSC/OpenSC/pull/624

rebased by @viktorTarasov
2016-07-17 14:07:43 +02:00
Viktor Tarasov 1da49757cb fix NEWS, few debug messages more 2016-05-26 10:59:58 +02:00
Frank Morgner b96ba14aae added fall through comment 2015-10-30 12:15:06 +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