Commit Graph

6615 Commits

Author SHA1 Message Date
Jakub Jelen e50bc29bd9 card-setcos.c: Avoid unsigned integer underflow
Thanks oss-fuzz

https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=18798
2019-11-11 22:02:18 +01:00
Jakub Jelen c173563ad2 coolkey: Accept only SW=90 00 as success to prevent interpretting invalid values 2019-11-11 22:02:08 +01:00
Jakub Jelen ef3e223917 coolkey: Do not interpret empty answers as success
Thanks to oss-fuzz

https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=18868
2019-11-11 22:01:56 +01:00
Peter Popovec e6a24b71ab MyEID: fix max_recv_size
MyEID 3.3.3 is not working with hardcoded max_recv_size=256 in
card-myeid.c. Use max_recv_size=255 if card major version < 40

Fixes #1852
2019-11-11 21:01:51 +01:00
Frank Morgner a8de0070fd fixed Null-dereference READ
https://oss-fuzz.com/testcase-detail/5644373382922240
Thanks to OSS-Fuzz
2019-11-06 23:38:37 +01:00
Frank Morgner 1a069ca71e fixed Global-buffer-overflow READ 1
https://oss-fuzz.com/testcase-detail/5685978287308800
Thanks to OSS-Fuzz
2019-11-06 23:08:43 +01:00
Frank Morgner 8fea658fe9 fixed 121888 Time of check time of use 2019-11-05 21:49:30 +01:00
Frank Morgner 3a5a90450e fixed 333715 Dereference after null check 2019-11-05 21:49:30 +01:00
Frank Morgner 7007b4a889 fixed 127766 Out-of-bounds read 2019-11-05 21:49:30 +01:00
Frank Morgner 8d7092c0cb 13598 Unchecked return value 2019-11-05 21:49:30 +01:00
Frank Morgner 192994fa13 fixed 13608 Unchecked return value 2019-11-05 21:49:30 +01:00
Frank Morgner 804cb68057 removed 339153 Logically dead code 2019-11-05 21:49:30 +01:00
Frank Morgner 8d3dfb2f6d ignore for 339158 Dereference before null check 2019-11-05 21:49:30 +01:00
Frank Morgner 07cff0e168 fixed 341844 Incorrect deallocator used 2019-11-05 21:49:30 +01:00
Frank Morgner 8b6ba40a8e fixed 341853 Resource leak 2019-11-05 21:49:30 +01:00
Frank Morgner fa35be5859 fixed 347857 Resource leak 2019-11-05 21:49:30 +01:00
Frank Morgner 2a2662fb3d fixed 348981 Resource leak 2019-11-05 21:49:30 +01:00
Frank Morgner 7a1e42e135 fixed compiler warning
fixes https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=18701
2019-11-05 10:58:32 +01:00
Frank Morgner c3f23b836e fixed UNKNOWN READ
Reported by OSS-Fuzz
https://oss-fuzz.com/testcase-detail/5681169970757632
2019-11-03 04:45:28 +01:00
Frank Morgner 6263afbe43 fixed memory leak
Reported by OSS-Fuzz
https://oss-fuzz.com/testcase-detail/5697134632632320
2019-11-03 04:38:09 +01:00
Jakub Jelen d3f60a657f pkcs15*: Fail if there is no fallback file_app 2019-11-01 15:53:40 +01:00
Jakub Jelen b75c002cfb cac1: Correctly handle the buffer limits
Found by oss-fuzz

https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=18618
and others
2019-11-01 15:53:40 +01:00
pkubaj bfa8415ea3 Fix build on ARM, PPC
Those architectures use unsigned char by default, and command variable is later compared to -1.
2019-11-01 15:51:06 +01:00
Jakub Jelen fb15a7dd86 reader-pcsc: Handle yubikey reinsertion
When the application (NSS) does not use WaitForSlotEvent and just
opportunistically tries to detect card and reader removals with
C_GetSlotInfo() and C_GetSessionInfo(), we might get errors in
various plcaes, in the sc_lock() function, when we try to transfer
other messages or when we ask for the reader status.

This is generally too late to call any disconnect functions because no
PC/SC handles are valid anymore. The reader state from PCSC
is searched by name so we can be pretty sure it is very similar
reader (with same name as the old one) and I hope we can reuse the
reader structure and just call the pcsc_connect() on that as we do
with invalid handles.

Otherwise we detect this issue in the refresh_attributes() (called
from C_GetSlotInfo()), where we can report the slot change in the
expected manner.

Fixes #1822
2019-11-01 15:50:34 +01:00
Jakub Jelen 0ea11523a3 Improve logging of exit codes 2019-11-01 15:50:34 +01:00
Frank Morgner 3c87ffaa02 fuzzing: correctly consume fuzzing data 2019-11-01 15:49:10 +01:00
Jakub Jelen 424ebf8ed1 pkcs15: Avoid insane allocations
Thanks oss-fuzz

https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=18592
2019-10-31 02:18:36 +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 829a73c941 card-npa: Remove dead code 2019-10-31 02:18:04 +01:00
Jakub Jelen 6c7b4bed37 pkcs15*: Avoid null dereference from fuzzers
Thanks oss-fuzz.

Fixes: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=18591
2019-10-31 02:17:44 +01:00
Frank Morgner 49f59d9fc9 clean up already enumerated apps 2019-10-29 17:54:40 +01:00
Nuno Goncalves 3ac47fbea9 replace SC_FUNC_CALLED(...,1) with SC_FUNC_CALLED(..., SC_LOG_DEBUG_NORMAL) (close #1698)
Signed-off-by: Nuno Goncalves <nunojpg@gmail.com>
2019-10-28 09:51:28 +01:00
Nuno Goncalves 60581ecc82 remove trailing whitespace
Signed-off-by: Nuno Goncalves <nunojpg@gmail.com>
2019-10-28 09:51:28 +01:00
Frank Morgner 026b6ab43d fuzzing: validate PIN only if it's a PIN
https://oss-fuzz.com/testcase-detail/5693809152753664
2019-10-26 23:56:19 +02:00
Frank Morgner 3c286b3cb1 fixed Null-dereference READ
https://oss-fuzz.com/testcase-detail/5734505646391296

Thanks to OSS-Fuzz
2019-10-26 23:50:11 +02:00
Jakub Jelen 61cd7fcdb2 card-mcrd: Free the allocated structures on cleanup
https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=18416
2019-10-25 20:25:06 +02:00
Jakub Jelen 6522df7587 pkcs15: Avoid null dereference in fuzzers
https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=16617
2019-10-25 20:22:40 +02:00
Jakub Jelen 532b06d07e pkcs15: Avoid insane allocations
and use single max constant accross the code

https://oss-fuzz.com/testcase-detail/6314983763214336
2019-10-25 20:22:40 +02:00
Jakub Jelen 6810eb6cf1 fuzz_pkcs15_reader: Unbreak strict builds
The error was

fuzz_pkcs15_reader.c: In function ‘fuzz_get_chunk’:
fuzz_pkcs15_reader.c:66:19: error: cast from pointer to integer of different size [-Werror=pointer-to-int-cast]
   66 |     *chunk_size = (uint16_t) data->Data;
      |                   ^
cc1: all warnings being treated as errors
2019-10-25 20:22:40 +02:00
Jakub Jelen cc466eea94 asn1: Avoid undefined shifts by adding explicit cast
The error was:
asn1.c:681:23: runtime error: left shift of 255 by 24 places cannot be represented in type 'int'
	    #0 0x5e9b11 in decode_bit_field opensc/src/libopensc/asn1.c:681:23

https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=18487
2019-10-25 20:19:50 +02:00
Jakub Jelen 0d091c8e0c asn1: Avoid integer overflow
https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=18475
2019-10-23 13:50:52 +02:00
Jakub Jelen 6ce6152284 pkcs15-prkey: Simplify cleaning memory after failure
https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=18478
2019-10-23 13:50:52 +02:00
Jakub Jelen 19f4c7e428 card-mcrd.c: Avoid null dereference
https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=18477
2019-10-23 13:50:52 +02:00
Jakub Jelen 1be013d08e asn1: Fix undefined shift in OID parser
https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=16618
2019-10-22 09:42:18 +02:00
Jakub Jelen 630d6adf32 pkcs15-prkey: Avoid memory leak
https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=16625
2019-10-22 09:41:14 +02:00
Jakub Jelen 62049ea18c Avoid memory leaks from file selection
https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=17106
2019-10-22 09:38:30 +02:00
Jakub Jelen 6ef0ac6e67 asn1: Correctly parse negative integers
The negative integers were parsed uterly wrong, resulting in undefined
shift overflows as reported by oss-fuzz.

The current implementation takes negated values (properly masked) and
calculates two's complement in the end, which results in correct values
and correct data handling.

https://oss-fuzz.com/testcase-detail/5125815506829312
2019-10-22 09:33:46 +02:00
Jakub Jelen ff893d2224 pkcs15: Remove unused code 2019-10-22 09:22:59 +02:00
Jakub Jelen 5e9e5b232c card-piv: Fix indentation 2019-10-22 09:17:24 +02:00
Jakub Jelen 459e4ecc37 piv: Avoid insane allocations in fuzzer 2019-10-22 09:17:12 +02:00
Jakub Jelen 544d576b00 asn1: Do not pass null argument to memcpy
Reported by clang analyzer:

src/libopensc/asn1.c:1080:2: note: Null pointer passed as an argument to a 'nonnull' parameter

        memcpy(p, data, datalen);
2019-10-22 09:15:49 +02:00
Jakub Jelen 889d598bcd asn1: Initialize values to avoid comparison with garbage
Reported by clang analyzer:

src/libopensc/asn1.c:2115:14: warning: The right operand of '<' is a garbage value [clang-analyzer-core.UndefinedBinaryOperatorResult]

        if (halflen < r_len || halflen < s_len)   {
2019-10-22 09:15:36 +02:00
Raul Metsma f4ac617c19 Remove unused card type
Signed-off-by: Raul Metsma <raul@metsma.ee>
2019-10-16 13:16:56 +02:00
Frank Morgner 3a1bd36e20
Use onepin-opensc-pkcs11.so for Chromium (#1828)
* pkcs11-register: Fixed detection of already registered OpenSC

Anny configuration of onepin-opensc-pkcs11.so and opensc-pkcs11.so
should be enough to skip registering the default module again.

* Use onepin module for generic NSS DB

fixes https://github.com/OpenSC/OpenSC/issues/1818

May have the disadvantage that some other programs that use NSS don't
see the signature keys. However, we currently only know for sure that
Chromium is using the generic NSS DB.
2019-10-16 13:16:22 +02:00
Jakub Jelen eac516fd41 dir: Avoid insane allocations
Resolves:
https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=17449
2019-10-03 13:57:09 +02: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
Jakub Jelen 34bd879400 openpgp: Properly free the allocated file structure
Resolves:
https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=16879
2019-10-03 13:57:09 +02:00
Jakub Jelen 79cb753921 cac: Free the certificate data on failure
Resolves:
https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=16819
2019-10-03 13:57:09 +02:00
Jakub Jelen d6435b0af4 pkcs15-din-66291: Fix indentation 2019-10-03 13:57:09 +02:00
Frank Morgner 53ff7182fb
pkcs11-tool: disable wrap/unwrap test (#1808)
... until https://github.com/OpenSC/OpenSC/issues/1796 is resolved
2019-10-01 11:52:33 +02:00
Frank Morgner e2491a7d7f
pkcs11-tool: fixed displaying secret key attributes (#1807)
fixes https://github.com/OpenSC/OpenSC/issues/1805
2019-10-01 11:51:55 +02:00
Frank Morgner d965156fe6 fuzz_pkcs15_decode: fixed use after free 2019-09-30 20:02:12 +02:00
Andreas Schwier aae529547c sc-hsm: Fix maximum APDU size to 4K version (Fixes #1794) 2019-09-20 20:35:54 +02:00
Andreas Kemnade b9810e62d6 cardos5: fix reading of serial number
The corresponding GET DATA command only returns the serial,
nothing else.
Tested with CardOS 5.0 and 5.3 cards. The serial number
is the same as shown with other tools
2019-09-16 13:09:16 +02:00
Frank Morgner 25bc8fc167 fix https://github.com/OpenSC/OpenSC/issues/1786
Thanks to Alexandre Gonzalo
2019-09-16 13:06:38 +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 28a93fdf55 fixed memory leak 2019-09-09 09:37:33 +02:00
Frank Morgner 2eaf422cb2 refactor DIN 66291 profile to avoid memory confusion 2019-09-09 09:34:37 +02:00
Frank Morgner 64d3d81036 fixed invalid free 2019-09-05 08:51:13 +02:00
Frank Morgner 769db0297b fixed memory leak
Credits to OSS-Fuzz
2019-09-02 09:43:50 +02:00
Peter Popovec 5b8095ca2c string null-termination fix
strncpy does not generate null-terminated string, fixed by memcpy.
2019-09-02 09:32:12 +02:00
Frank Morgner f621305140 fixed undefined behavior when parsing negative ASN.1 Integer 2019-08-30 23:45:40 +02:00
Frank Morgner 3e110995bc fixed undefined behavior
Credits to OSS-Fuzz
2019-08-30 23:45:40 +02:00
Frank Morgner e971ffb48e fixed memory leak
Credits to OSS-Fuzz
2019-08-30 23:45:40 +02:00
Frank Morgner 849de1d9e3 fixed memory leak when parsing malformed PKCS#15 data
Credits to OSS-Fuzz
2019-08-30 23:45:40 +02:00
Frank Morgner f5bea72637
Add support for 4K RSA keys in CardOS 5 (#1776)
fixes https://github.com/OpenSC/OpenSC/issues/1764
2019-08-29 09:43:37 +02:00
Frank Morgner a1d3e76999 openpgp: handle cards with static algorithms
fixes https://github.com/OpenSC/OpenSC/issues/1659
2019-08-28 11:06:55 +02:00
Jakub Jelen cc9020f56a pkcs15-sc-hsm: Avoid potential memory leaks 2019-08-28 11:01:50 +02:00
Jakub Jelen fb67ffdca6 pkcs15-sc-hsm: Avoid potential memory leaks 2019-08-28 11:01:50 +02:00
Jakub Jelen 14e1f3c4d3 pkcs15-tccardos: Make sure we do not overrun buffers in this wild parsing 2019-08-28 11:01:50 +02:00
Jakub Jelen 489886724f pkcs15-tccardos: Avoid negative indexing 2019-08-28 11:01:50 +02:00
Jakub Jelen cab5d3da17 iasecc-sdo: Avoid potential memory leak 2019-08-28 11:01:50 +02:00
Jakub Jelen 070a37cebd card-authentic: Avoid potential memory leaks 2019-08-28 11:01:50 +02:00
Jakub Jelen 1b32bfe4e5 card-coolkey: Avoid potential null dereference 2019-08-28 11:01:50 +02:00
Jakub Jelen 24eaa3eaa1 card-jcop: Avoid left-shift of negative values 2019-08-28 11:01:50 +02:00
Jakub Jelen 2f643948f1 ctx: Avoid potential memory leaks reported by clang 2019-08-28 11:01:50 +02:00
Frank Morgner bdca524aa8 Fixed memory leak
Credits to OSS-Fuzz
2019-08-27 15:59:46 +02:00
Frank Morgner 03ea3f719c fixed memory leak
Credits to OSS-Fuzz
2019-08-27 15:40:32 +02:00
Frank Morgner 9b4b080be7 fixed compiler warning 2019-08-27 15:27:15 +02:00
Frank Morgner a3fc7693f3 Fixed out of bounds access in ASN.1 Octet string
Credit to OSS-Fuzz
2019-08-27 15:21:46 +02:00
Frank Morgner 412a6142c2 fixed out of bounds access of ASN.1 Bitstring
Credit to OSS-Fuzz
2019-08-27 15:19:22 +02:00
Ludovic Rousseau 2bfd022180 pkcs11-spy: add support of CKM_*_PSS in C_VerifyInit()
In bdb1961dee the same code was added to
C_SignInit(). Now it is also used in C_VerifyInit().
2019-08-27 14:52:10 +02:00
Frank Morgner 2eab2bcd74 fixed out of bounds accessing array
Credit to OSS-Fuzz
2019-08-27 14:00:34 +02:00
Ludovic Rousseau 2240abcef1 spy: display -1 instead of 18446744073709551615
buf_len is a CK_ULONG (unsigned long). But if the attribute is sensitive
or is not extractable or is invalid for the object then the library set
the buffer length value to (CK_LONG)-1.

It is more friendly to see "-1" instead of "18446744073709551615" (on
64-bits CPU)
2019-08-26 10:53:09 +02:00
Ludovic Rousseau 43a8f870e5 pkcs11-spy: add support of CKA_OTP_* values 2019-08-26 10:18:04 +02:00
Ludovic Rousseau e35a7e7395 Add definition of CKA_OTP_* constants 2019-08-26 10:17:05 +02:00
Frank Morgner 9099d95c77 fixed interface change
fixes https://github.com/OpenSC/OpenSC/issues/1768
2019-08-20 14:21:44 +02:00
Peter Popovec d7a86d397f opensc-tool: do not connect card if not neccesary, fix util.c errors
opensc-tool: for options --version, --list-readers, -D, etc. we do not
need to connect card/reader. This removes unnecessary error messages
if card is not present in card reader or if reader is not available.
util.c: use symbolic error codes, pass error codes to caller without change.
2019-08-20 13:38:51 +02:00
Frank Morgner b6be87a348 make sc_format_apdu_ex agnostic to card properties 2019-08-20 13:38:20 +02:00
Frank Morgner 0c563df0c1 document sc_format_apdu_ex() 2019-08-20 13:38:20 +02:00