Commit Graph

8144 Commits

Author SHA1 Message Date
Jakub Jelen 741091b3c6 travis-ci: Add clang linux target 2020-05-26 10:03:23 +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
Torin Carey 93bed892a8 tests: Fix card present check
Check SC_READER_CARD_PRESENT flag rather than == 1.
Having no card present on the first loop and then inserting a card will
return rc = CARD_PRESENT | CARD_CHANGED (= 3). SEGFAULT ensures when we mistake
the unset opt_reader as having a present card.
2020-05-18 16:30:15 +02:00
Jakub Jelen 57f538810e travis-ci: Do not pass sign arguments if we do not have the secret params in PRs 2020-05-18 16:28:59 +02:00
Jakub Jelen 8175df0e47 Make sure pcscd is started when using emulation
Running from systemd has --auto-exit, which does not guaranee us that
the process is running when we start emulators
2020-05-18 16:28:59 +02:00
Jakub Jelen e1830ea6d2 Install OpenJDK 8 to build jcardsim (it does not work with Java 11) 2020-05-18 16:28:59 +02:00
Jakub Jelen 47a36efa7c travis: Update to something with sensible openssl version to make yubico-piv-tool build 2020-05-18 16:28:59 +02:00
Jakub Jelen 66bcce8a8d travis-ci: Use newer JavaCard SDK to unbreak PivApplet build to enable ECDSA support 2020-05-18 16:28:59 +02:00
Jakub Jelen 687f52233e travis-ci: Fail if any applet or tool needed for tests fails to build
(in our case, it was yubico-piv-tool and PivApplet for some time)
2020-05-18 16:28:59 +02:00
Jakub Jelen 3b3aecbf8c travis: Kill particular pid instead of killall to avoid killing unrelated processes 2020-05-18 16:28:59 +02:00
Jakub Jelen 27a819baa7 framework-pkcs15: Do not leak memory (CID 139147) 2020-05-13 21:54:16 +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 2495bbecf7 macOS: pass installation if we could not start the background services 2020-05-11 18:41:16 +02:00
Frank Morgner e864aa6d76 macOS: cover minor versions of xcode
uses subshell for getting xcode version
2020-05-11 18:41:16 +02:00
Frank Morgner b08d33ceb6 Travis: seperate installer packages not needed anymore 2020-05-11 18:41:16 +02:00
Frank Morgner 0dcb910289 fixed "libtool: compile: unable to infer tagged configuration" 2020-05-11 18:41:16 +02:00
Frank Morgner 178c4a9eaa fixed checking for strlcat/strlcpy
newer clang uses a definition rather than a function
2020-05-11 18:41:16 +02:00
Frank Morgner e71b85867f macOS: added basic installer signing 2020-05-11 18:41:16 +02:00
Jakub Jelen 3af52cd1c6 tests: Temporarily exclude goid-tool from manpage tests 2020-05-11 08:06:26 +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
Michael Weiser a49a64ec79 unittests: Fix out-of-source build
Commit 4fd34e28ea unintentionally replaced top_builddir with
top_srcdir when refactoring flags variables in Makefile.am. This causes
out-of-source builds to fail.

Restore top_builddir in LDADD.

Also, remove a superfluous -L flag also referencing top_srcdir from
AM_CFLAGS while at it.

Signed-off-by: Michael Weiser <michael.weiser@gmx.de>

Closes #2027.
2020-05-10 00:01:27 +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 8a5a1435f1 pkcs15-tool.c - print Supported_algorithms from tokenInfo
Some cards can provide supported algorithms in tokenInfo
which contain ECDSA OID, and PKCS11 mechanism

Don't know how many Algo_refs were actually read,
and a ref of 0 may be valid. print at least one Algo_refs.

Print the mechanism from PKCS11, and print operations
Use the $(top_srcdir)/src/pkcs11/pkcs11-display.c  on Unix
Use the $(TOPDIR)\src\pkcs11\pkcs11-display.obj on Windows

pkcs15.tool.c treat ECDSA OID as inline

pkcs15-tool prints PKCS11 mechanisms using pkcs11-display.c
Automake now warns that the default will change, in the future
so "[subdir-objects]" is added to configure.ac

 Changes to be committed:
	modified:   configure.ac
	modified:   src/tools/Makefile.am
	modified:   src/tools/Makefile.mak
	modified:   src/tools/pkcs15-tool.c
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 f5fe292ae1 pkcs11-tool - use valid data for decription tests
In tests, make sute test data is either padded, or "zero" padded
so size if data <=  modlen - 11. The smallest pad in 11 bytes,
00 | NN | PS | 00. PS is at least 8 bytes.
"zero" padding has N = 00, PS >= 8 byte of 00.

 On branch cardos-5.3
 Changes to be committed:
	modified:   tools/pkcs11-tool.c
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 797414be05 Create missing man pages (goid needs some work) 2020-05-07 02:34:12 +02:00
Jakub Jelen b091165595 doc: Drop trailing comma 2020-05-07 02:34:12 +02:00
Jakub Jelen 0a057a976d Fix typo arguement -> argument in documentation 2020-05-07 02:34:12 +02:00
Jakub Jelen a1d53aa217 tests: Temporarily whitelist example binaries in tools/ 2020-05-07 02:34:12 +02:00
Jakub Jelen 3c7823d1f0 tests: Verify every tool has a manual page 2020-05-07 02:34:12 +02:00
Jakub Jelen ddc049e37b Remove bogus file from tools directory 2020-05-07 02:34:12 +02:00
Jakub Jelen ce659b2f7a test: Fix typo in comment 2020-05-07 02:34:12 +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