Commit Graph

3994 Commits

Author SHA1 Message Date
Zoltan Kelemen 741ee73ec9 Add generic function for PIN status retrieval, for subsequent use (among
others intended to replace iasecc_pin_is_verified).

Base it on functionality in the ISO 7816 layer to avoid code duplication.
2020-07-22 22:57:23 +02:00
Zoltan Kelemen 7ed876c816 Added ATR mask for Idemia (Oberthur) IAS-ECC card to recognize Cosmo V8 cards. 2020-07-22 22:57:23 +02:00
Zoltan Kelemen eb3e00a385 Corrected highly misleading, confusing and ambiguous use of PIN length_offset
field. Now only the PIN offset fields are used. Also added error checking for
invalid values.
2020-07-22 22:56:09 +02:00
Zoltan Kelemen 80853bda31 Only enable static frame size for PIN padding when padding length is below
maximum limits. Otherwise resort to adaptive support.
2020-07-22 22:56:09 +02:00
Zoltan Kelemen afffeccc29 Fixed problems with PIN min/max length handling:
- The wrong PIN was selected from the sc_pin_cmd_data structure.
- When the PIN max value was zero from the caller (meaning unknown max), the
  reader max value was not used.
2020-07-22 22:56:09 +02:00
Zoltan Kelemen 1dc359cb61 Fix for issue #1999:
- Reset context to undefined handle value on error since call may alter
  output parameter.
- Continue to assume -1 as undefined handle value in all PCSC
  implementations, to keep this fix as small and surgical as possible.
2020-07-22 22:55:30 +02:00
Jakub Jelen b16a5cbee0 pkcs15: Free app info when allocating new and in cleanup
Thanks oss-fuzz

https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=23746
2020-07-07 16:21:21 +02:00
Jakub Jelen c82aa92687 pkcs15: Clean memory on alocation failure 2020-07-07 16:21:21 +02:00
Jakub Jelen 2d6de2510c pkcs15: Drop bogus checks 2020-07-07 16:21:21 +02:00
Jakub Jelen 4c473fba29 authentic: Clean private data on error
Thanks oss-fuzz

https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=23786
2020-07-07 16:21:21 +02:00
Jakub Jelen 05dcde508b authentic: Use memmove as the memory can overlap (if path is > 2B)
Thanks oss-fuzz

https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=23787
2020-07-07 16:21:21 +02:00
Jakub Jelen 5098cfdb40 authentic: Do not leak memory on fail path
Thanks oss-fuzz

https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=23788
2020-07-07 16:21:21 +02:00
Jakub Jelen 7cf8087351 asepcos: Avoid heap-buffer-overflow
Thanks oss-fuzz

https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=23529
2020-07-07 16:21:21 +02:00
Jakub Jelen c4d7bb1a7b Do not crash on if private certificate is ignored (#2057) 2020-07-07 16:21:21 +02:00
Jakub Jelen 43379b3b22 coolkey: Rewrite coolkey_rsa_op() for better readability 2020-07-07 16:21:21 +02:00
Jakub Jelen 0cda376dba pkcs15-pubkey: Make sc_pkcs15_pubkey_from_spki_fields more robust against errors
Original patch from Douglas E Engert <deengert@gmail.com>
2020-07-07 16:21:21 +02:00
Jakub Jelen e759b17b66 pkcs15-pubkey: Avoid memory leaks when spki parsing fails
Thanks oss-fuzz

https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=22189
2020-07-07 16:21:21 +02:00
Jakub Jelen 56f4c6c34a piv: Free pubkey on error
Thanks oss-fuzz

https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=22297
2020-07-07 16:21:21 +02:00
Jakub Jelen 3696331d5c Remove more needless checks for NULL before free 2020-07-07 16:21:21 +02:00
Jakub Jelen fea08d749d coolkey: Avoid memory leak
Thanks oss-fuzz

https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=23251
2020-07-07 16:21:21 +02:00
Zoltan Kelemen 929717b505 Make PUK reference available to card driver from PKCS #15 layer for PIN
unblock operations. This helps some of the card drivers which otherwise
would have a hard time locating the PUK for a PIN.
2020-07-02 13:24:57 +02:00
René Liebscher 223a0949e8 Add sc_free()
For more details see https://github.com/OpenSC/OpenSC/issues/2054
2020-06-22 10:47:59 +02:00
René Liebscher 4d96fbfed4 Remove compiler warnings/errors
Recent compilers have activated some additional
checks which let the build fail. (at least with cygwin)
(Normally it would be warnings but opensc compiles
with -Werror)

GCC 9.3:
In file included from profile.c:27:
profile.c: In function '__expr_get':
profile.c:2273:18: error: array subscript has type 'char' [-Werror=char-subscripts]
 2273 |   while (isspace(*s))
      |                  ^~

clang 8.0.1:
compat_getopt_main.c:102:22: error: array subscript is of type 'char' [-Werror,-Wchar-subscripts]
                rc = toupper(rc);
                     ^~~~~~~~~~~
/usr/include/ctype.h:161:25: note: expanded from macro 'toupper'
      (void) __CTYPE_PTR[__x]; (toupper) (__x);})
                        ^~~~

Actually the code is correct as isspace and others
are used here with data type char, and are to be used
with data type int.

So either the compiler should have deactivated
this error, or the ctype.h macros have to be
written so the compiler no longer complains.

As there is also a simple workaround by casting
char to unsigned char, there is no need to wait for one
of the former options to be happen sometime.
2020-06-22 10:47:02 +02:00
Jakub Jelen 7ae74c524f piv: Avoid accessing memory after zero-length tags
Thanks oss-fuzz

https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=23215
2020-06-09 13:02:27 +02:00
Jakub Jelen 5e7d4fb8ba oberthur: Avoid memory leaks
Thanks oss-fuzz

https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=23126
2020-06-09 13:02:27 +02:00
Jakub Jelen 0a34d11cb7 oberthur: Avoid memory leaks on error paths 2020-06-09 13:02:27 +02:00
Jakub Jelen 62403eec34 tcos: Use memset instead of for cycle 2020-06-09 13:02:27 +02:00
Jakub Jelen 9dd3370673 oberthur: Fix operator precedence
Thanks oss-fuzz

https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=22665
2020-06-09 13:02:27 +02:00
Jakub Jelen a5f04188bc pteid: Do not overwrite already set information in tokeninfo
Thanks oss-fuzz

https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=22578
2020-06-09 13:02:27 +02:00
Jakub Jelen f49162af04 Avoid memory leaks when initializing tokeninfo in various drivers
Thanks oss-fuzz

https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=22578
2020-06-09 13:02:27 +02:00
Jakub Jelen 71d1f69a3a Reformat tcos_compute_signature() for better readability 2020-06-09 13:02:27 +02:00
Jakub Jelen e6848b6d88 tcos: Yet anoter buffer underflow as previous 2020-06-09 13:02:27 +02:00
Jakub Jelen fa719b301f tcos: Prevent buffer underflow
Thanks oss-fuzz

https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=22995
2020-06-09 13:02:27 +02:00
Jakub Jelen d141b35596 tcos: Rewrite assert to explicit check 2020-06-09 13:02:27 +02:00
Jakub Jelen 1819ca33d6 tcos_decipher: Reformat to improve readability 2020-06-09 13:02:27 +02:00
Jakub Jelen 53395f4075 tcos: Replace assert with explicit check
Thanks oss-fuzz

https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=22999
2020-06-09 13:02:27 +02:00
Jakub Jelen 8940ed5d85 tcos: Avoid memory leak on invalid inputs
(make sure the pointer is initialized)

Thanks oss-fuzz

https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=22765#c2
2020-06-09 13:02:27 +02:00
Frank Morgner 1c7b311289 pcsc: immediately exit on hotplug events
fixes delayed notification for removed readers

closes https://github.com/OpenSC/OpenSC/issues/2021
2020-06-09 12:07:04 +02:00
Frank Morgner 8f6e5dc2b0 Unbreak wait for events
By Jabuk Jelen

Fixes https://github.com/OpenSC/OpenSC/issues/2021
2020-06-09 12:07:04 +02:00
Frank Morgner 180c57fd15 fixed compiler warning 2020-06-05 09:43:38 +02:00
Frank Morgner 0f0e0b2e30 prevent out of bounds read
fixes https://oss-fuzz.com/testcase-detail/5769298181357568
2020-06-05 08:31:19 +02:00
Frank Morgner 9d294de90d prevent out of bounds write
fixes https://oss-fuzz.com/testcase-detail/5226571123392512
2020-06-04 10:04:10 +02:00
Frank Morgner 55fd3db2b5 prevent integer underflow and subsequent heap overflow
fixes https://oss-fuzz.com/testcase-detail/5666689944649728
2020-06-04 09:47:22 +02:00
Frank Morgner 4bc03cb55d fixed memory leak
fixes https://oss-fuzz.com/testcase-detail/5113223765557248
2020-06-04 00:13:57 +02:00
Feitian Technologies f334f3eabe
Bug fixed (#1859)
* Bug fixed

1. It solves the problem that can be signed without input PIN, and new code will check the state that the PIN value
2. The algorithm fails to verify sha256, cause signature failure
3. The format of distinguishing ECC and RSA key pair is added - after the key pair is generated successfully, ECC and RSA need to be distinguished when reading the public key. The return format of ECC is different from the RSA
4. Fix ECC information display bug - The problem is using pkcs15-tool -D to print ECC key pair information no display correctly
5. Modify the module attribute of generating ECC key pair, and add 0x04 flag according to pkcs11 standard
2020-06-03 14:54:39 +02:00
Jakub Jelen e8a2644435 Remove duplicate condition
Thanks coverity
2020-05-29 09:57:39 +02:00
Jakub Jelen 38474739b3 card-cardos: Fix NULL dereference
Thanks coverity
2020-05-29 09:57:39 +02:00
Frank Morgner 0a17188710 fixed out of bounds read
fixes https://oss-fuzz.com/testcase-detail/5769032858075136
2020-05-24 23:47:29 +02: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 ed55fcd299 fixed invalid read
fixes https://oss-fuzz.com/testcase-detail/5765246676631552
2020-05-18 17:25:32 +02:00
Frank Morgner 96a7eca99a fixed memory leak
fixes https://oss-fuzz.com/testcase-detail/5633315576217600
2020-05-18 17:13:48 +02:00
Frank Morgner 4cb9788b99 fixed invalid read
fixes https://oss-fuzz.com/testcase-detail/5726023753924608
2020-05-18 16:45:24 +02:00
Frank Morgner 7e1679b2db fixed memory leak
fixes https://oss-fuzz.com/testcase-detail/5675417580339200
2020-05-18 16:38:43 +02:00
Jakub Jelen 19791f63d5 piv: Avoid cast ignoring errors (CID 357984)
Thanks coverity
2020-05-13 21:54:16 +02:00
Jakub Jelen 787c32d195 piv: Avoid cast to unsigned ints to properly check for errors (CID 357985)
Thanks coverity scan
2020-05-13 21:54:16 +02:00
Frank Morgner d8734baf83
Merge pull request #1924 from frankmorgner/recursion
avoid calling sc_*_binary recursively
2020-05-13 00:27:42 +02:00
Doug Engert 4ebb29ce4d card-piv.c error in using sc_asn1-put-tag
In piv_general_mutual_authenticate sc_asn1_put_tag is not used correctly.

 On branch piv-sc_asn1_put_tag-error
 Changes to be committed:
	modified:   card-piv.c
2020-05-13 00:26:18 +02:00
Frank Morgner 4e9cec1a64 fixed missing includes 2020-05-11 18:58:12 +02:00
Frank Morgner a7d563b657
Merge branch 'master' into recursion 2020-05-11 18:45:36 +02:00
Frank Morgner 0dcb910289 fixed "libtool: compile: unable to infer tagged configuration" 2020-05-11 18:41:16 +02:00
Frank Morgner c1eda42099 oberthur: fixed current file state handling
fixes https://oss-fuzz.com/testcase-detail/5644083327664128
2020-05-10 01:14:00 +02:00
Frank Morgner 7add7e9ded fixed memory leak
fixes https://oss-fuzz.com/testcase-detail/5738653415636992
2020-05-10 01:01:34 +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
Doug Engert c03efeee40 sc_supported_algo_info - Put ECDSA OID as inline
Mismatch of ASN1 parsing of tokeninfo.supported_algos[n].paramters
    in one place parameter was treated as a pointer to sc_object_id
    and in another as inline structure. This caused segfaults
    in pkcs15-tool when it tried to print the OID.

 Changes to be committed:
	modified:   src/libopensc/opensc.h
	modified:   src/libopensc/pkcs15.c
2020-05-09 23:59:51 +02:00
Doug Engert 3f21dc57b7 Increase SC_MAX_SUPPORTED_ALGORITHMS from 8 to 16
CardOS cards may have more then 8 supported_algo_info entries in tokenInfo.
We may bemissing some. We have seen 8 in some pkcs15-tool -i -v output.

Simple fix is to incrase the limit. More appropriate fix is to remove the limit,
much like is done with sc_algorithm_info. and use realloc of the array.

 On branch cardos-5.3
 Changes to be committed:
	modified:   src/libopensc/pkcs15-prkey.c
	modified:   src/libopensc/pkcs15-skey.c
	modified:   src/libopensc/pkcs15.c
	modified:   src/libopensc/types.h
2020-05-09 23:59:51 +02:00
Doug Engert 52d5370c1e asn1.c don't use strict mode
see:
https://github.com/OpenSC/OpenSC/issues/1995#issuecomment-607490809

 On branch cardos-5.3
 Changes to be committed:
	modified:   asn1.c
2020-05-09 23:59:51 +02:00
Jakub Jelen d1457e9fa3 coolkey: Drop dead code (CID 351911)
default branch of the switch calls continue, preventing
going out of the loop without obj_info set.
2020-05-07 02:32:46 +02:00
Jakub Jelen 295f399304 reader-pcsc: Avoid use after free (CID 355473) 2020-05-07 02:32:46 +02:00
Jakub Jelen 71998501f2 piv: Replace internal implementation of put_tag with asn1
The asn1 implementation is simpler and has more throughout error and
buffer overflow checking.

Fixes #1394
2020-05-07 02:32:46 +02:00
Jakub Jelen 4c4237f8a3 tests: Cover asn1_put_tag() 2020-05-07 02:32:46 +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
Jakub Jelen 75be610ea0 pkcs15: Clean memory if it was not transfered to framework-pkcs15 2020-05-07 02:32:46 +02:00
Jakub Jelen 127c8d911f pkcs15-pubkey: Avoid memory leaks when ec_params are already initialized from pkcs15-algo 2020-05-07 02:32:46 +02:00
Jakub Jelen b76e08504a piv: Fix indentation 2020-05-07 02:32:46 +02:00
Jakub Jelen ed06787b5e oberthur: Avoid memory leak when the auth_init is called multiple times
Thanks oss-fuzz

https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=21678
2020-05-07 02:32:46 +02:00
alex-nitrokey 27ea7cc6ac
Merge branch 'master' of https://github.com/OpenSC/OpenSC into ecc-fixes 2020-04-09 10:25:00 +02:00
Frank Morgner 2c26b7392d opensc-notify: handle reader insertion/removal events
- If readers are attatched, the new reader is probed for a card to check
if a notification needs to be sent
- removal of readers are not notified to the user, we assume that PC/SC
sends the correct card removal event
- The list of readers to be monitored is adjusted once a reader (dis)appears
- On macOS, without PnP notification, we always check for new/removed
readers with SCardListReaders
- fixes interrupt handling in opensc-notify on Unix

fixes https://github.com/OpenSC/OpenSC/issues/1874
2020-04-06 18:08:34 +02:00
Jakub Jelen 7893d2860c idprime: Fix null-dereference
Thanks oss-fuzz

https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=21586
2020-04-06 17:56:28 +02:00
Jakub Jelen 1ddef2cd15 iasecc: Avoid memory leak on error
Thanks oss-fuzz

https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=21297
2020-04-06 17:56:28 +02:00
Marcin Cieślak 768bd1dde7 Check if we HAVE_ENDIAN_H
BSDs will have <sys/endian.h>, Linux just <endian.h>
2020-04-03 09:52:08 +02:00
alex-nitrokey 7ba89620bf
refactoring: get rid of oid_binary in ec_tables 2020-03-24 12:09:06 +01:00
Frank Morgner d5ecafc334 fixed memory leak
fixes https://oss-fuzz.com/testcase-detail/5084702283399168
2020-03-20 17:12:18 +01:00
alex-nitrokey 0ba44cbec6
Add length checking 2020-03-19 13:31:31 +01:00
Alexander Paetzelt e45712bd29
Merge branch 'master' into ecc-fixes 2020-03-19 11:54:18 +01:00
Frank Morgner dc29b0fe18 fixed memory leak
fixes https://oss-fuzz.com/testcase-detail/6237284133502976
2020-03-12 23:07:17 +01:00
Jakub Jelen 6ed3939ae5 coolkey: Avoid memory leak
Fixup previous attempt to avoid too large allocations

Thanks oss-fuzz

https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=21059
2020-03-11 12:19:43 +01:00
Peter Marschall d628022673 OpenPGP: add additional vendors
Taken from git.gnupg.org
2020-03-10 09:19:31 +01:00
Frank Morgner 267aea759c use platform dependant implementation of erasing memory
fixes potentially insecure use of memset in CWA SM implementation

fixes https://github.com/OpenSC/OpenSC/issues/1957
2020-03-06 12:23:16 +01:00
Frank Morgner d06f23e89b avoid debugging PIN commands
use a higher debug level to see it anyway
2020-03-05 22:17:09 +01:00
Jakub Jelen e429fe03c5 cardos: Avoid always-true condition
Comparison is always true because offset >= 1.

Thanks lgtm
2020-03-04 21:27:56 +01: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 44bc324864 actalis: Check return codes
CID 127776
2020-03-04 21:27:56 +01:00
Jakub Jelen e3e461aad9 coolkey: Avoid insane allocations and use correct variable type
CID 341847
2020-03-04 21:27:56 +01:00
Jakub Jelen 2a88d82cad compression: Validate inputs to decompression functions
CID 353531
CID 353530
2020-03-04 21:27:56 +01:00
Jakub Jelen 7bfca52bab iasecc: Free old driver data if the driver was initialized correctly
CID: 354007
2020-03-04 21:27:56 +01:00
Jakub Jelen 677710c72b dnie: Avoid insane memory allocations
Thanks oss-fuzz

https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=20916
2020-03-04 21:27:56 +01:00
Jakub Jelen 7d3b82c204 epass2003: Avoid memory leaks if no file_out is passed
Thanks oss-fuzz

https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=20898
2020-03-04 21:27:56 +01:00
Jakub Jelen a623226a87 Avoid memory leaks from sc_parse_ef_attr()
Thanks oss-fuzz

https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=20710
2020-03-04 21:27:56 +01:00
Jakub Jelen 9c0a7adbfc iasecc: Avoid memory leaks on error
Thanks oss-fuzz

https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=20700
2020-03-04 21:27:56 +01:00
Jakub Jelen d31ebe2fec gemsafeGPK: Fix typo in comment 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
Frank Morgner 649ee272ec reader-cryptotokenkit: fixed handling of reattached reader 2020-03-03 22:55:27 +01:00
Frank Morgner 14e396273c reader-pcsc: fixed handling of detatching events
- allows re-attatching a reader to an existing reader object by
resetting the SC_READER_REMOVED flag
- readers that are flagged with SC_READER_REMOVED are not used for
SCardGetStatusChange to avoid SCARD_E_UNKNOWN_READER

fixes https://github.com/OpenSC/OpenSC/issues/1903
2020-03-03 22:55:27 +01:00
Frank Morgner ad7eb834cf fixed indenting 2020-03-03 22:55:27 +01:00
Frank Morgner 906108bb69 dnie: fixed length checking of uncompressed data
fixes https://oss-fuzz.com/testcase-detail/5632848910614528
2020-02-27 23:12:54 +01:00
Frank Morgner dca02dd9a0 fixed 323588 Uninitialized scalar variable
accessing uninitialized data with mlock is undefined behavior
2020-02-27 23:12:54 +01: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 e0b27af205 fixed Undefined-shift
fixes https://oss-fuzz.com/testcase-detail/5644419049193472
2020-02-13 10:39:41 +01:00
Frank Morgner 6c855c561c fixed memory leak
fixes https://oss-fuzz.com/testcase-detail/5739164513599488
2020-02-12 04:48:40 +01:00
Frank Morgner a0e1bf7ae5 fixed compiler error 2020-02-10 10:17:16 +01:00
Frank Morgner ea2991ea69 fixed memory leak
also, use sc_file_free instead of free

fixes https://oss-fuzz.com/testcase-detail/4905082200260608
2020-02-10 10:17:16 +01:00
Frank Morgner 2493c5de07 fixed memory leak
fixes https://oss-fuzz.com/testcase-detail/6237284133502976
2020-02-10 10:17:16 +01:00
Frank Morgner d7e02d3bf5 fixed memory leak
Fixes https://oss-fuzz.com/testcase-detail/5151975710916608
2020-02-10 10:17:16 +01:00
Peter Marschall 8e466ad568 OpenPGP: add 3 more OpenPGP card vendors
* taken from GnuPG's git
2020-02-10 00:41:02 +01:00
Jakub Jelen 34dad7f543 idprime: Add missing terminator in ATR list
Thanks oss-fuzz

https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=20510
2020-02-04 15:44:19 +01:00
Jakub Jelen 63435adc68 coolkey: Do not return bogus error if read already failed 2020-02-04 13:57:15 +01:00
Jakub Jelen 2a0f53dd4f coolkey: Avoid heap buffer overflow
for malformend combinded objects, the ID and header were parsed before
making sure we have at least that lenght available.

Thanks oss-fuzz

https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=20131
2020-02-04 13:57:15 +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 f1044f3645 tccardos: fixed error checking 2020-02-04 13:56:53 +01:00
Frank Morgner c339136c73 tccardos: fixed freeing file object 2020-02-04 13:56:53 +01:00
Frank Morgner 723176d62f avoid calling memcpy with length 0 2020-02-04 13:56:53 +01:00
Frank Morgner 3687f71bf7 fixed 123497 Dereference after null check
Thanks to Coverity Scan
2020-02-04 13:56:53 +01:00
Frank Morgner 3dede423e6 fixed Out-of-bounds access
Thanks to Coverity scan
2020-02-04 13:56:53 +01:00
Frank Morgner 8db1cbe35f use a more explicit assignment 2020-02-04 13:56:53 +01:00
Frank Morgner d138522e33 added detection of zlib compression
... and always set outLen to 0 in case of an error in sc_decompress
2020-02-04 13:56:53 +01:00
Frank Morgner 094aa68632 fixed Explicit null dereferenced
Thanks to Coverity Scan
2020-02-04 13:56:53 +01:00
Frank Morgner 72836fa3cb Fixed Dereference before null check
As reported by coverity scan
2020-02-04 13:56:53 +01:00
Doug Engert 0fd77d642c Minidriver additionl fixes
Use __FUNCTION__ as defind in log.h so will compile with any compiler.
logprint additional handles as size_t

Add check in reader-pcsc.c pcsc_user_reader for minidriver only.

 On branch minidriver-5
 Changes to be committed:
	modified:   src/libopensc/reader-pcsc.c
	modified:   src/minidriver/minidriver.c
2020-02-01 22:42:02 +01:00
Doug Engert 111246f1d2 Better error debug messages for Minidriver
Add MD_FUNC_CALLED(pCardData, level) and  MD_FUNC_RETURN(pCardData, level, ...)
macros.

Handles are type __int3264 in VS2015 are casted as size_t when printing so
all bytes are printed. size_t on Windows are also treated as 32 or 64 bits.
SC_FORMAT_LEN_SIZE is used in the format.
 (Works with VS2105 needs to be tested on other platforms.)

 On branch minidriver-4

 Changes to be committed:
	modified:   minidriver.c

Minidriver.c and reader-pcsc.c - reuse OpenSC reader structure

Windows CNG is managing the insertion and removal of the reader and the card
and will call CardAcquireContext and CardDeleteContext as needed if
the card or reader change. But different processes or threads may establish
different PCSC connects to the same reader and card but with different handles.

Reuse the OpenSC reader when windows uses the same reader but with different
handles. Tests show the certutil -v -scinfo works the same.
Associate_card is only need when called from
CardAcquireContext and disassociate_card is only need when called from
CardDeleteContext.
No need to call reinit_card_for(pCardData, name) just because the handles changed.

This may be the fix for #1763 because calls like CardCreateContainerEx remain
in card state rather then being lost when the handles changed.

 Changes to be committed:
	modified:   src/libopensc/reader-pcsc.c
	modified:   src/minidriver/minidriver.c
2020-02-01 22:42:02 +01:00
Doug Engert 348551c920 Add EC parameters to PKCS15 public key in OpenPGP driver - Fixes #1906
The EC Parameters are the way the EC curve is presented to the outside world,
and in most cases is present in a matching certificate in the SPKI.

card-openpgp.c is modified to add the EC named_curve to the PKCS15 public key.
OpenPGP specs only provide this via the "Algorithm Attributes" for the 3 keys
via tags C1, C2 and C3 These contain the OID (not DER encoded) for the EC curve.

PKCS15 has two ways to encode a "pubkey" as it was originally written for RSA.
But other algorithms have parameters. X509 certificates encode the public key
in the SPKI and PKIX requires the parameters to be in the SPKI. PKCS15
allows for using a SPKI as source for a public key.

pgp_get_pubkey_pem will return the DER encoded RSA pubkey as before by
calling sc_pkcs15_encode_pubkey
pgp_get_pubkey_pem will return the DER encoded EC pubkey with parameters by
calling sc_pkcs15_encode_pubkey_as_spki which calls sc_pkcs15_fix_ec_parameters
internally to map DER encoded OID to named_curve.

For readability, "sc_pkcs15_pubkey_t pubkey;" definitions are changed to
"sc_pkcs15_pubkey_t p15pubkey;"

sc_pkcs15_erase_pubkey is used to avoid memory leaks.

 On branch openpgp-ec-pub-curve

 Date:      Tue Jan 21 09:43:56 2020 -0600
 Changes to be committed:
	modified:   src/libopensc/card-openpgp.c
2020-02-01 22:39:05 +01:00
Frank Morgner 7e0465370f
Merge pull request #1914 from marschap/PGPtool-fixes
PGPtool fixes
2020-02-01 22:27:58 +01:00
Lewis Porter 723129bc12 Check if card name is null in acos atrust driver
opensc-tool segfaults when trying to read a card  that doen’t populate the name field. This commit adds a null check before calling strcmp().
2020-01-31 16:15:23 +01:00
Frank Morgner 45a77ab88d
Merge pull request #1772 from Jakuje/idprime
Add support for Gemalto IDPrime smart cards
2020-01-31 15:49:29 +01: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 167c03fde4 updated documentation 2020-01-31 08:40:48 +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 230e2f9a60 documentation 2020-01-30 23:22:41 +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
Frank Morgner a501c0d185
sc_decompress_zlib_alloc: check inputs, avoid int underflow (#1907)
- turns out, you can shrink a buffer with realloc on some implementations
- realloc is never called with 0 (which would free the data)
- length checking is done in zlib, we just do the allocation

closes https://github.com/OpenSC/OpenSC/issues/1905
2020-01-30 09:45:44 +01:00
Frank Morgner b119781b02 myeid: fixed memory leak
Credits to OSS-Fuzz

Fixes https://oss-fuzz.com/testcase-detail/5671550682660864
2020-01-29 14:47:12 +01:00
Peter Marschall 471df32faa OpenPGP: correctly determine max. special DO size
In pre-v3 cards, it is hard-coded to 254 bytes.
In v3+ cards, it is stored in the "extended capabilities" DO 00C0.

Make the determined size available as a variable in the driver data.
2020-01-26 13:29:02 +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
Frank Morgner 0ae3441949 adapt to comment 2020-01-22 13:59:33 +01:00
Frank Morgner b7690a45d7 sc_decompress_zlib_alloc: check inputs, avoid int underflow
- turns out, you can shrink a buffer with realloc on some implementations
- realloc is never called with 0 (which would free the data)
- length checking is done in zlib, we just do the allocation

closes https://github.com/OpenSC/OpenSC/issues/1905
2020-01-20 10:13:27 +01:00
Jakub Jelen 23fcccecf4 reader-pcsc: Add a way to create corpus files for fuzzing 2020-01-07 17:18:05 +01:00
Jakub Jelen a1b5feea96 pkcs15-coolkey: Improve logging and formatting 2020-01-07 17:18:05 +01:00
Jakub Jelen 82ba7f311f pkcs15-syn: Improve logging 2020-01-07 17:18:05 +01:00
Jakub Jelen 900cf7aca9 coolkey: Improve logging 2020-01-07 17:18:05 +01:00
Jakub Jelen cae3b71d75 gp: Define the structure packed, as it is used directly to read data inside 2020-01-07 17:18:05 +01:00
Jakub Jelen 8fd5ffd54e simpletlv: Avoid writing before all sanity checks in sc_simpletlv_put_tag() 2020-01-07 17:07:48 +01:00
Jakub Jelen b0d3a70b91 coolkey: Improve logging of return codes 2020-01-07 17:07:48 +01:00
Jakub Jelen 8ddfafe057 asn1: Empty bit string requires empty zero-bits indicator 2020-01-07 14:50:48 +01:00
Jakub Jelen 2c913155a2 asn1: Do not accept non-minimal encoding of OBJECT IDs 2020-01-07 14:50:48 +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
Jakub Jelen fefff2e462 asn1: Simplify the OID decoding 2020-01-07 14:50:47 +01:00
Jakub Jelen 89ed273e81 cac1: Simplify the cycle definintion 2020-01-07 14:50:47 +01:00
Jakub Jelen 4faf517af4 asn1: Handle more corner cases of OBJECT ID parsing 2020-01-07 14:50:47 +01:00
Jakub Jelen c449aa4430 asn1: Reject integers with bogus zero/non-zero bytes on left 2020-01-07 14:50:47 +01:00
Jakub Jelen d3e9b55223 asn1: Distinguish error codes for invalid objects from implementation limitation (integer size) 2020-01-07 14:50:47 +01:00
Jakub Jelen 1271299955 ans1: Verify the padding in BIT STRING contains only zero bits 2020-01-07 14:50:47 +01:00
Jakub Jelen c1814571bd asn1: Avoid invalid unused bits values 2020-01-07 14:50:47 +01:00
Jakub Jelen 61af2c1d0a asn1: Add support for encoding large values in OIDs 2020-01-07 14:50:47 +01:00
Jakub Jelen 19501715d7 asn1: Correctly handle OIDs with second octet > 39 2020-01-07 14:50:47 +01:00
Jakub Jelen 8e8c3735bc idprime: Reflect the OS version in the card name 2020-01-07 14:16:46 +01:00
Jakub Jelen bebb5be6e0 idprime: Simplify applet selection and limit file size to sensible values 2020-01-07 14:16:46 +01:00
Jakub Jelen 3537cbbc78 Unbreak RSA-PSS padding 2020-01-07 14:16:46 +01:00
Jakub Jelen fe8f6297f0 idprime: Add support for longer PINs 2020-01-07 14:16:46 +01:00
Jakub Jelen 5017768e5b idprime: Detect the newer version of OS using CPLC data 2020-01-07 14:16:46 +01:00
Jakub Jelen 2c9510af1e Improve parsing of the root file and store also the object length 2020-01-07 14:16:46 +01:00
Jakub Jelen fdcc843e78 idprime: Implement a way of getting token label from special card structure 2020-01-07 14:16:46 +01:00
Jakub Jelen 48e3239857 pkcs15-cac: Use constants rather than magic numbers 2020-01-07 14:16:46 +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
Jakub Jelen 3a3a465e6b Add basic support for OEAP decryption in OpenSC internals 2020-01-07 13:30:28 +01:00
Jakub Jelen 2882c93ec1 pkcs15: Expose the map_usage() function from CAC to other pkcs15 emulators 2020-01-07 13:29:53 +01:00
Jakub Jelen 5e1bfe0acc Drop the pkcs15.h from simpletlv.h 2020-01-07 13:29:53 +01:00
Peter Marschall 4d2b860c7f OpenPGP: add ATR for Yubikey 5 2020-01-07 11:09:00 +01:00
Peter Marschall 31b8c7a404 OpenPGP: first steps at supporting OpenPGP card spec 3.4 2020-01-07 11:09:00 +01:00
alex-nitrokey 3af3d0ecee openpgp: add nistp256 and secp251k1 curves for gnuk devices 2020-01-07 11:08:25 +01:00
carblue 5dd9fcb25c Fix asn1.c:print_tags_recursive 2020-01-07 10:18:46 +01:00
carblue 4ad55997e0 sc_pkcs15_decode_skdf_entry: break all looping on oid match: on average better performance 2020-01-07 10:17:39 +01:00
Frank Morgner cfd5519b98 simplify PIV I/O 2020-01-07 10:06:23 +01:00
Priit Laes 0b4b7fbaf0 openssl: Drop all compatibility checks for <=openssl-1.0.0 2020-01-06 15:47:07 +01:00
Julian Strobl 6b84407c3d tcos: fix indentation and braces
Increase readability. No content-based changes.
2020-01-06 15:43:46 +01:00
Khem Raj 05e3f7b667 Fix misleading code indentation
Fixes
error: misleading indentation; statement is not part of the previous 'if' [-Werror,-Wmisleading-indentation]
         if(cipher)
         ^
../../../git/src/libopensc/card-entersafe.c:369:2: note: previous statement is here
        if(sbuf)
        ^
2019-12-28 18:18:06 +01:00
Julian Strobl 9eed40ea31 tcos: add encryption certificate for IDKey
Fixes https://github.com/frankmorgner/OpenSCToken/issues/21
2019-12-28 18:15:55 +01:00
Frank Morgner 1cc6087126 fix buffer length for printing DFs 2019-12-19 04:44:59 +01:00
Benjamin DELPY b59456b6e4 Update card-gids.c to support 3072 & 4096 RSA key sizes 2019-12-19 04:33:14 +01:00
Julian Strobl 187d908feb tcos: allow correct input length when signing
For 2048 bit keys the padded input is 256 bytes long.

Fixes https://github.com/frankmorgner/OpenSCToken/issues/20
2019-12-19 04:30:27 +01:00
Julian Strobl 55b7a6fefd Revert "tcos: Do not advertize non-functional RSA RAW algorithms"
This reverts commit bee5c6d639.

See https://github.com/frankmorgner/OpenSCToken/issues/20#issuecomment-566455157
2019-12-19 04:30:27 +01:00
Frank Morgner 333c41c5d5 pgp: don't write beyond oid object
fixes Stack-buffer-overflow
https://oss-fuzz.com/testcase-detail/6329203163398144
2019-12-18 14:55:46 +01:00
Jakub Jelen ee78b0b805 pkcs15-coolkey: Fix EC key type and fail on invalid key types
Thanks oss-fuzz

https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=19251
2019-12-11 09:19:45 +01:00
Jakub Jelen 708cedbdad dir: Correctly free allocated memory on error
Thanks oss-fuzz

https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=19265
2019-12-11 09:19:45 +01:00
dojo 17d9d8450c Enabled extended APDU support for StarCOS 3x cards 2019-12-05 16:48:11 +01:00
dojo a450b3427e Fix path unifying of StarCOS 3.5 cards 2019-12-05 16:48:11 +01:00
dojo 9f2c112ecb Add new ATR for StarCOS 3.5 2019-12-05 16:48:11 +01:00
dojo c99d62c04a Add PIN encoding detection for StarCOS 3x cards 2019-12-05 16:48:11 +01:00
Doug Engert 5fa633075d GIDS Decipher fix for TPM
GIDS decipher APDU fails with status '65 00' or '67 00' if
"Padding Indication" byte is present. Debug logs of Microsoft
certutil -v -scinfo  using Microsoft drivers show that for a
decipher, the "Padding Indication" is not present. It maybe
needed if Secure Messaging is added later.

Extended APDU is turned off as this may not be supported on
some cards. Chaining is used used instead, it works on all cards.

RAW RSA is turned off, it is supported.

Tested with pkcs11-tool on Windows 10 with a TPM 2.0 module.

 On branch gids-decipher
 Changes to be committed:
	modified:   src/libopensc/card-gids.c

 Date:      Tue Dec 3 18:08:32 2019 -0600
 interactive rebase in progress; onto 01678e87
 Last commands done (3 commands done):
    squash c968d0dd GIDS No Padding Indication Byte
    squash 0fa940fc Take 3
 No commands remaining.
 You are currently rebasing branch 'gids-decipher' on '01678e87'.
2019-12-05 16:33:27 +01:00
Raul Metsma e91853bda8 Simplify code and card detection
Signed-off-by: Raul Metsma <raul@metsma.ee>
2019-12-05 10:51:55 +01:00
AdriaoNeves 366adbd546 Fixing invalid signature with 3072 RSA bits in GemsafeV1 2019-12-05 10:46:21 +01:00
AdriaoNeves dbe932152d Fixing invalid signature with 3072 RSA bits in GemsafeV1 2019-12-05 10:46:21 +01:00
Jakub Jelen 642a3ee734 cardos: Use more appropriate RSA flags for CardOS 5
Fixes #1864
2019-12-05 10:45:34 +01:00
Jakub Jelen afe255c5b2 Remove never set constants and their handling in cardos driver 2019-12-05 10:45:34 +01:00
Jakub Jelen 2bab09ac03 tcos: Use unique IDs for certificates 2019-12-05 10:43:17 +01:00
Jakub Jelen 88e3c44f22 tcos: Drop undocumented tags from security environment data 2019-12-05 10:43:17 +01:00
Jakub Jelen bee5c6d639 tcos: Do not advertize non-functional RSA RAW algorithms 2019-12-05 10:43:17 +01:00
Jakub Jelen 424eca8bef tcos: Remove duplicate lines 2019-12-05 10:43:17 +01:00
Jakub Jelen 4c67bbf383 coolkey: Avoid addressing behind allocated buffers
Thanks oss-fuzz

https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=19222
2019-12-04 21:47:47 +01:00
Jakub Jelen c246f6f69a coolkey: Make sure the object ID is unique when filling list
Thanks to oss-fuzz

https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=19208
2019-12-04 21:47:47 +01:00
Andreas Schwier 32b49894c5 sc-hsm: Add ATR for faster token variant 2019-12-04 21:43:47 +01:00
Andreas Schwier 7858f3cd06 sc-hsm: Add support for SmartCard-HSM MicroSD card 2019-12-04 21:43:47 +01:00
Jakub Jelen ef61a95b31 coolkey: Make sure the matching objects have same lengths
This ensures that we do not go behind the allocated buffer if
we get wrong data.

Thanks to oss-fuzz:

https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=19031
https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=19032
https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=19038
https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=19039
https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=19040
2019-11-29 22:48:00 +01:00
Jakub Jelen aa6d3e1d36 coolkey: Fix the comparator return value 2019-11-29 22:48:00 +01:00
Jakub Jelen 249e928176 gp: Correctly check for the CPLC data length 2019-11-29 22:47:26 +01:00
Jakub Jelen 4f3d87d03c coolkey: Split the CPLC related structures and function to the generic GP file 2019-11-29 22:47:26 +01:00
Jakub Jelen 326955a147 reader-pcsc: Preserve the CARD_PRESENT flag to make sure the card is detected after reader reinsertion 2019-11-28 11:18:25 +01:00
AdriaoNeves ce71b171e2 Add support for 4K RSA keys in GemsafeV1 2019-11-23 22:13:28 +01:00
carblue 6d98f8c8d8 card-myeid.c: issue #1219 2019-11-23 21:38:14 +01:00
Jakub Jelen 2d02de4233 coolkey: Do not return uninitialized data if card does not return CPLP data
Thanks oss-fuzz

https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=18990
2019-11-18 14:02:07 +01:00
Frank Morgner bec794fbee fixed memory leak
https://crbug.com/oss-fuzz/18953
2019-11-18 14:01:50 +01:00
Jakub Jelen c4dcac5de7 pkcs15-prkey: Free allocated data on all error exit paths
Thanks oss-fuzz

https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=18790
2019-11-14 19:36:01 +01:00
Jakub Jelen 6d6d158f13 pkcs15-cert: Free data on all error exit paths
https://oss-fuzz.com/testcase-detail/5645063405436928
2019-11-14 19:36:01 +01:00
Jakub Jelen 5645fe2d16 muscle: Check length first before calling memcmp() 2019-11-14 19:36:01 +01:00
Jakub Jelen 1594b1167d muscle: Initialize variables and check return codes 2019-11-14 19:36:01 +01:00
Jakub Jelen 7360c4bf0c muscle: Avoid access uninitialized memory 2019-11-14 19:36:01 +01:00
Jakub Jelen 2c68c0662c coolkey: Avoid success from init if there are no reasonable data raturned
Thanks to oss-fuzz

https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=18918
https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=18915
2019-11-14 19:36:01 +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 f11c286bc6 coolkey: Refactor the object listing to avoid invalid memory access
Probably resolves some bad memory access from oss-fuzz such as

https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=18907
2019-11-13 15:48:33 +01:00
Jakub Jelen 07d3d8e0df compression: Free allocated data and return error if nothing was uncompressed
Also harmonizes the return codes from decompress*() functions

Fixes oss-fuzz issue

https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=18771
2019-11-13 15:48:25 +01:00
Frank Morgner 5557f34f5e Revert "pkcs15-pubkey: Avoid memory leaks"
This reverts commit 0977b5496a.
2019-11-12 11:57:43 +01:00
Jakub Jelen b79db82ae7 openpgp: Workaround non-compliant Yubikey 5 OpenPGP applets
Fixes #1850
2019-11-12 03:38:09 +01:00
Jakub Jelen 0977b5496a pkcs15-pubkey: Avoid memory leaks
Thanks oss-fuzz

https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=18758
2019-11-11 22:02:53 +01:00
Jakub Jelen cc917b541f asn1: Avoid calling malloc with 0 argument
Caused problems reported by oss-fuzz

https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=18758
2019-11-11 22:02:41 +01:00
Jakub Jelen cd51430ba7 asn1: Avoid malloc(0) also from BIT STRING and GENERALIZED TIME structures 2019-11-11 22:02:30 +01:00
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 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 2a2662fb3d fixed 348981 Resource leak 2019-11-05 21:49:30 +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