Commit Graph

59 Commits

Author SHA1 Message Date
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 a7d563b657
Merge branch 'master' into recursion 2020-05-11 18:45:36 +02:00
Jakub Jelen 15b1e93b51 cac: Avoid always-true condition
Comparison is always true because pathlen >= 3.

Thanks lgtm
2020-03-04 21:27:56 +01:00
Jakub Jelen c69add3b64 cac: Correctly avoid recursion (amends 09531d72)
Closes: #1920

Thanks oss-fuzz

https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=19725
2020-03-04 21:27:56 +01:00
Jakub Jelen 09531d720a cac: Avoid stack overflow on infinite recursion in CCC chaining
Thanks oss-fuzz

Fixes: #1920

https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=19725
2020-02-04 13:57:15 +01:00
Frank Morgner ad8b9f5034 sc_*_binary: interpret SC_SUCCESS as EOF 2020-01-31 14:47:45 +01:00
Jakub Jelen 5e1bfe0acc Drop the pkcs15.h from simpletlv.h 2020-01-07 13:29:53 +01:00
Jakub Jelen 51363d3392 cac: Make sure we do not leak memory
Thanks oss-fuzz

https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=18564
2019-10-31 02:18:20 +01:00
Jakub Jelen 13429baed0 cac: Avoid signed/unsigned casting reported by coverity
src/libopensc/card-cac.c:1707: negative_returns: "val_len" is passed to a parameter that cannot be negative.
2019-04-23 14:49:45 +02:00
Frank Morgner 2ad7453718 use const qualifier for sc_simpletlv_read/put_tag 2019-01-30 21:57:59 +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
Jakub Jelen fd2343f4a2 cac: Dump the data model number, which is useful for the capabilities detection
Signed-off-by: Jakub Jelen <jjelen@redhat.com>
2018-11-25 22:07:33 +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
Jakub Jelen 55a8478ed6 cac: These functions do not have to be exposed 2018-10-15 12:14:22 +02:00
Jakub Jelen 79c0dbaa4e cac: Avoid OOB reads for inconsistent TLV structures 2018-08-14 16:13:22 +02:00
Frank Morgner 5807368ed4 fixed bad memory access 2018-08-14 16:13:22 +02:00
Jakub Jelen d5d15105dd cac: Ignore end of content errors (#7)
The CAC buffers are split to separate TL and V buffers so we need to ignore this error
2018-08-14 15:50:13 +02:00
Frank Morgner 360e95d45a fixed out of bounds writes
Thanks to Eric Sesterhenn from X41 D-SEC GmbH
for reporting the problems.
2018-08-14 15:50:13 +02:00
Frank Morgner 8fe377e93b fixed out of bounds reads
Thanks to Eric Sesterhenn from X41 D-SEC GmbH
for reporting and suggesting security fixes.
2018-08-14 15:50:13 +02:00
Jakub Jelen 2190bb927c Drop support for CAC 1
This removes code related to the old CAC 1 specification, while
preserving the CAC 2 functionality including CAC Alt token detection
for the tokens without CCC or ACA.

The detection based on SELECT APPLET APDU is improved to require also
the READ BUFFER APDU working, which should fail on misbehaving Java cards.
2018-08-03 01:51:44 +02:00
Jakub Jelen 3a7a1ba31f Do not fail if we found unknown tag or the count does not match
* The HID tokens present such undocumented tags
2018-07-11 10:48:10 +02:00
Jakub Jelen bf3382d4d9 Standardize logging and include also AID 2018-07-11 10:48:10 +02:00
Jakub Jelen 3480d9fc99 Log also information about unitialized slots with correct labels 2018-07-11 10:48:10 +02:00
Jakub Jelen 1c2a7f8dd2 HID Alt tokens have the other bunch of slots in other undocumented AID 2018-07-11 10:48:10 +02:00
Jakub Jelen 5b3da5d462 cac: Missing memory cleanup 2018-06-21 12:48:57 +02:00
Jakub Jelen 2682741293 cac: Avoid segfaults from get_challenge() 2018-06-21 12:48:57 +02:00
Jakub Jelen 40b02b2582 Namespace the function name, update comment 2018-06-11 22:31:44 +02:00
Jakub Jelen 50b5eb3b69 Allow using up to 16 certificates 2018-06-11 22:31:44 +02:00
Jakub Jelen 9dda83e48e cac: Verbose logging, avoid OOB reads 2018-06-11 22:31:44 +02:00
Jakub Jelen 930d457304 Log bad length buffers 2018-06-11 22:31:44 +02:00
Jakub Jelen 298afb072e Properly check length also of the applet entry 2018-06-11 22:31:44 +02:00
Jakub Jelen f27ee858c2 Carefully check the length of the buffers before accessing them.
The lengths are static and based on the GCS-IS 2.1 specification
2018-06-11 22:31:44 +02:00
Jakub Jelen a73b3d549b Address review comments:
* Refactor cac_properties_t structure to make its creation more readable
 * Avoid manual allocation in cac_get_acr() and clean up bogus pointers
 * Avoid bogus comments
 * Properly check lengths of retrieved values
2018-06-11 22:31:44 +02:00
Jakub Jelen d24c23ac0c Use applet properties to recognize buffer formats
Previously, the code handled all the data objects as SimpleTLV,
which caused invalid encoding when we tried to merge TL + V buffers
into single PKCS#15 buffers.

This change is using GET PROPERTIES APDU after applet selection
to explore objects, figure out encoding and check the status of
PKI objects initialization to avoid reading them.
2018-06-11 22:31:44 +02:00
Jakub Jelen 450cff470a Inspect the Alt tokens through the ACA applet
The previous solution was just guessing AIDs of the PKI objects
and trying if they answer.

This solution is inspecting card based on the Service Applet Table
(listing all the applets on the card) and using GET PROPERTIES APDU
listing all the available OIDs of the applet.

This was successfully tested with standard CAC card
(with different ACA AID) and uninitialized HID Alt tokens with empty
certificates slots.
2018-06-11 22:31:44 +02:00
Jakub Jelen ee7b6f4035 cac: Log unknown tags 2018-06-11 22:31:44 +02:00
Jakub Jelen cde06a499c Use correct AID and Object ID 2018-06-11 22:31:44 +02:00
Jakub Jelen 2138d5fe32 One more todo based on the testing with a new libcacard 2018-06-11 22:31:44 +02:00
Jakub Jelen 426914674c Unbreak encoding last tag in the data objects 2018-06-11 22:31:44 +02:00
Jakub Jelen 5b420318d4 Allocate private data outside and avoid memory leaks 2018-06-11 22:31:44 +02:00
Jakub Jelen 92df907681 Typo, clean up comments, dump more useful information from CCC 2018-06-11 22:31:44 +02:00
Jakub Jelen 52451ac438 card-cac.c: Dump also the MSCUID 2018-06-11 22:31:44 +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
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
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
Jakub Jelen ccfd4b4c35 cac: Try to read the ACA file
Some "unfriendly" cards return SW 90 00 to any instruction including
the ACA file selection and therefore they are identified as CAC card.
To avoid this, we will try to read the assumed ACA file and we will
mark the card as matched only if we will read something from that file.
We do not parse the content yet.
2018-02-07 11:13:09 +01:00
Jakub Jelen e7deb3410d cac: Fail if the read instruction does not return anything
To avoid infinite loop on "unfriendly" cards, we assume that
read data instruction always returns some data. It it does not,
we can safely assume the file is not there or it is not the card
we are looking for.
2018-02-07 11:13:09 +01:00
Jakub Jelen 07267df313 Add the ACA path to the PIN structure if we have one 2017-11-09 12:45:35 +01:00