Commit Graph

7966 Commits

Author SHA1 Message Date
Charlène 2f7d0cf20f Put user supplied CFLAGS on top priority 2020-02-07 08:57:26 +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 e9308a2011 addeed zlib test data 2020-02-04 13:56:53 +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 5475dbcb3c fixed Uninitialized scalar variable
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 40b3aeb626 travis: output results of unittests on errors 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 0cd19b59e1 pkcs11-tool: add --usage-wrap (disabled by default)
fixes https://github.com/OpenSC/OpenSC/issues/1913
2020-02-01 22:29:35 +01:00
Frank Morgner 7e0465370f
Merge pull request #1914 from marschap/PGPtool-fixes
PGPtool fixes
2020-02-01 22:27:58 +01:00
Frank Morgner 8d4af9eb0b pkcs11: fixed right padding of token label with ' '
fixes https://github.com/OpenSC/OpenSC/issues/1922
2020-02-01 22:20:48 +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 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
Raul Metsma 092370f8a5 Checkout OpenSC.tokend when actually is needed
Signed-off-by: Raul Metsma <raul@metsma.ee>
2020-01-28 09:59:34 +01:00
Peter Marschall 5d576f4b31 openpgp-tool: use specialDO_size from driver in do_dump_do() 2020-01-26 13:30:28 +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 7d3e4b0878 openpgp-tool: increase buffer for private DOs
* OpenPGP v3 increased the size for private DOs. Adapt to it.
* Use the symbolic constant from the refactored OpenPGP driver
  instead of relying on magic numbers.
2020-01-26 13:15:47 +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
Peter Marschall 7ef40cdc17 openpgp-tool: update copyright 2020-01-26 13:14:37 +01:00
Peter Marschall a9873b87dd openpgp-tool: force use of 'openpgp' driver
Follow the example of other card-specific tools and explicitly force
the use of the correct driver, and fail if it cannot be set.
2020-01-26 13:13:52 +01:00
Liam Dawson 713396116d macOS: remove leftover files on uninstall
Fixes #1898
2020-01-23 12:38:43 +01:00
Frank Morgner 0ae3441949 adapt to comment 2020-01-22 13:59:33 +01:00
Frank Morgner 61c20cf83d
Merge pull request #1896 from marschap/explorer-card-drivers
opensc-explorer: make '--card-driver ?' list all available drivers
2020-01-22 09:20:29 +01:00
Jakub Jelen 4ef7ed9ffd fuzz: Fix invalid write in fuzzer
Thanks oss-fuzz

https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=20188
2020-01-21 22:35:21 +01:00
Jakub Jelen a487e9595e p11test: Generate valid json if the test is not properly finished 2020-01-21 22:35:21 +01:00
Jakub Jelen 889815629b p11test: Properly finalize the ec_sign test 2020-01-21 22:35:21 +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
Frank Morgner ee1c8073c2 pkcs11-tool: allow tests with keys that don't require PIN
... such as the 9e key of a PIV card.
2020-01-17 16:04:39 +01:00
Frank Morgner 5c55546685
Merge pull request #1830 from Jakuje/fuzz
Introduce unit tests and address more oss-fuzz issues  (mostly ASN1 parser)
2020-01-17 15:15:20 +01:00
Peter Marschall 6b295e4207 tools: correctly check return value of getopt_long()
According to the specs, getopt_long() returns -1, which is often,
but not necessarily the value of EOF.
2020-01-12 09:42:30 +01:00
Peter Marschall a0adbc9ef2 dnie-tool: cleanup
- remove command line option '--card-driver';
- instead force driver 'dnie' and fail if card is not a DNIe card
- overhaul option parsing
  - remove unused variable 'long_optind'
  - bail out with usage message on all unknown/unhandled args
  - correctly terminate option parsing (no infinite loop)
- slight refactoring
  - avoid magic constant '0x0f'
  - make variable 'tries_left' more local
  - move dependent code into if block
2020-01-12 09:42:09 +01:00
Peter Marschall 58ecb4aba2 cardos-tool: cleanup
- remove command line option '--card-driver';
- instead force driver 'cardos' and fail if card is not a CardOS card
- overhaul option parsing
      - remove unused variable 'long_optind'
      - bail out with usage message on all unknown/unhandled args
      - correctly terminate option parsing (no infinite loop)
2020-01-12 09:40:54 +01:00
Peter Marschall 04f4f589a1 piv-tool: cleanup
- remove command line option '--card-driver';
- instead force driver 'PIV-II' and fail if card is not a PIV card
- overhaul option parsing
  - remove unused variable 'long_optind'
  - make work option '--reader' ( "r:" was missing in the optstring!!!)
  - bail out with usage message on all unknown/unhandled args
  - correctly terminate option parsing (no infinite loop)
2020-01-12 09:40:53 +01:00
Peter Marschall 5514a0529f dnie-tool: rename option '--driver' to '--card-driver'
Rename option '--driver' to '--card-driver' for increased consistency.

In addition, extend it the same way opensc-explorer was extended. I.e.
treat the question mark given as argument to option '--card-driver'
special: list all available drivers instead of stupidly bailing out.

In contrast to opensc-tool and opensc-explorer, which are card-agnostic,
I am not sure whether the option '--card-driver' makes sense on this
card-specific tool.
2020-01-12 09:36:49 +01:00
Peter Marschall a10368769c cardos-tool: make '--card-driver ?' list all available drivers
Extend cardos-tool the same way opensc-explorer was extended. I.e.
treat the question mark given as argument to option '--card-driver'
special: list all available drivers instead of stupidly bailing out.

In contrast to opensc-tool and opensc-explorer, which are card-agnostic,
I am not sure whether the option '--card-driver' makes sense on this
card-specific tool.
2020-01-12 09:36:49 +01:00
Peter Marschall 30fdc7de4a piv-tool: make '--card-driver ?' list all available drivers
Extend piv-tool the same way opensc-explorer was extended. I.e.
treat the question mark given as argument to option '--card-driver'
special: list all available drivers instead of stupidly bailing out.

In contrast to opensc-tool and opensc-explorer, which are card-agnostic,
I am not sure whether the option '--card-driver' makes sense on this
card-specific tool.
2020-01-12 09:36:49 +01:00