Commit Graph

268 Commits

Author SHA1 Message Date
Jakub Jelen 9a6cf6af3e configure: Add option to generate code coverage (for unit tests)
./configure --enable-code-coverage --disable-optimization
make check
make code-coverage-capture
lcov --summary OpenSC-*-coverage.info

This does not work well with Windows so on windows it should be disabled (WIP)
2020-01-07 17:07:48 +01:00
Jakub Jelen e8af4fc167 unittests: Add more coverage corner cases for BIT STRINGs 2020-01-07 14:50:48 +01:00
Jakub Jelen 3af6d7999e unittests: Add tests for non-minimal OBJECT ID encoding
Thanks @hkario for suggestions
2020-01-07 14:50:48 +01:00
Jakub Jelen 37c8c46623 unittests: Simplify the OBJECT ID tests 2020-01-07 14:50:48 +01:00
Jakub Jelen 1e2b0fe45f unittests: Restructure the BIT STRING tests 2020-01-07 14:50:48 +01:00
Jakub Jelen 71e45bb5a7 unittest: Rewrite the INTEGER unittests to use macros and avoid code duplication 2020-01-07 14:50:47 +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 4569009418 unittests: Improve test coverage mostly with negative test cases
Thanks @hkario for review
2020-01-07 14:50:47 +01:00
Jakub Jelen 611d1cea4c unittests: Verify BIT STRING parsing as integers 2020-01-07 14:50:47 +01:00
Jakub Jelen 8d49e4a305 unittests: Test encoding of OIDs and integers 2020-01-07 14:50:47 +01:00
Jakub Jelen 7971bfded3 unittests: Verify parsing of more OIDs 2020-01-07 14:50:47 +01:00
Jakub Jelen b6b9a886f9 unittests: Verify negative ASN1 integeres parsing 2020-01-07 14:50:47 +01:00
Jakub Jelen 8e6d2e251d unittests: Reproducer for undefined shift in ASN1 parser 2020-01-07 14:50:47 +01:00
Frank Morgner 31169afb72 fixed fuzzing build
wrapping/unwrapping is hopefully correctly initialized
2020-01-06 22:34:16 +01:00
Frank Morgner 45e29056cc Release 0.20.0 2019-12-29 13:42:06 +01:00
Frank Morgner fa35be5859 fixed 347857 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
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
Frank Morgner 3c87ffaa02 fuzzing: correctly consume fuzzing data 2019-11-01 15:49:10 +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
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
Frank Morgner d965156fe6 fuzz_pkcs15_decode: fixed use after free 2019-09-30 20:02:12 +02:00
Frank Morgner 2eab2bcd74 fixed out of bounds accessing array
Credit to OSS-Fuzz
2019-08-27 14:00:34 +02:00
Jakub Jelen 9b47462a51 Fix portability warning from coverity
CID 344928 (#1 of 1): Sizeof not portable (SIZEOF_MISMATCH)
suspicious_sizeof: Passing argument object_handles of type CK_OBJECT_HANDLE_PTR and argument objects_length * 8UL /* sizeof (CK_OBJECT_HANDLE_PTR) */ to function realloc is suspicious. In this case, sizeof (CK_OBJECT_HANDLE_PTR) is equal to sizeof (CK_OBJECT_HANDLE), but this is not a portable assumption.
2019-08-20 13:28:54 +02:00
Jakub Jelen 1a0a8e637b p11test: Check return values
CID undefined (#1 of 1): Unchecked return value (CHECKED_RETURN)
10. check_return: Calling RSA_set0_key without checking return value (as is done elsewhere 7 out of 8 times).
2019-08-20 13:28:54 +02:00
Jakub Jelen 818aa5b69c p11test: Avoid possible issues reported by coverity
* The fail_msg() in cmocka has a way not to fail, which confuses coverity. Adding explicit retunr/exit should address this issue
 * Reformat some code in p11test
2019-08-20 13:28:54 +02:00
Frank Morgner 8f838bc1e0 fixed passing LIB_FUZZING_ENGINE 2019-08-19 16:44:54 +02:00
Frank Morgner bf8d449795 fixed memory leak 2019-07-26 15:23:02 +02:00
Frank Morgner 755ac78a02 added fuzzing with libFuzzer and OSS-Fuzz
makes cmocka detection not required for building tests
2019-07-26 15:23:02 +02:00
Jakub Jelen b65275d6f8 p11test: Improve error reporting on unknown EC groups 2019-06-17 12:49:11 +02:00
Jakub Jelen 87770df65b p11test: Implement simple derive tests 2019-06-17 12:49:11 +02:00
Jakub Jelen 852f057ce3 p11test: Add MD5 mechanisms pretty-print 2019-06-17 12:49:11 +02:00
Frank Morgner fc9277b778 use compat_getopt_long if getopt_long is not available
uses the autoconf way for replacing getopt.h

fixes https://github.com/OpenSC/OpenSC/issues/1527
2019-03-25 14:30:09 +01:00
Frank Morgner 0af46c88b7 added tests for Microsoft CryptoAPI
imported from https://github.com/CardContact/sc-hsm-embedded
2019-01-15 07:30:13 +01:00
Jakub Jelen aa7118192a p11test: Use function compatible with OpenSSL 1.0.2 2018-12-31 21:56:45 +01:00
Jakub Jelen f0b47a51d3 p11test: Report key sizes for missing certificates 2018-12-18 14:50:08 +01:00
Jakub Jelen ed6267512c p11test: Do not report usage on incomplete keys 2018-12-18 14:50:08 +01:00
Jakub Jelen 28deeb2a00 p11test: Do not report and try pairs without private key 2018-12-18 14:50:08 +01:00
Jakub Jelen 969e29e663 p11test: Do not talk about multipart encryption 2018-12-18 14:50:08 +01:00
Jakub Jelen 8ccc39352a p11test: Do not report incomplete key pairs 2018-11-05 09:15:20 +01:00
Jakub Jelen be2cc38565 p11test: Add missing CKM_SHA224_RSA_PKCS_PSS
Signed-off-by: Jakub Jelen <jjelen@redhat.com>
2018-09-30 21:23:27 +02:00
Jakub Jelen 9d44adbc4e Missing header release tarball 2018-09-14 22:39:57 +02:00
Jakub Jelen e9314adf4b Testsuite also depends on openssl, use correct variables for linking 2018-07-11 10:48:10 +02:00
Jakub Jelen 7c8ed4dc03 Correct name in the automake 2018-07-11 10:48:10 +02:00
Jakub Jelen 155ecc11f3 Adjust the p11test readme after merge
Resolves: #1415
2018-07-04 09:46:43 +02:00
Jakub Jelen f392d7426f Utilize autoconf variables for cmocka usage 2018-06-21 12:48:57 +02:00
asc 335c242ce0 Filter certificates other than CKC_X_509 2018-06-08 08:28:37 +02:00
Jakub Jelen 9858d05589 PKCS#11 testsuite (#1224)
* Initial version of pkcs11 testsuite

* Refactor test cases to several files, clean up awful and unused stuff

* Static mechanism list based on the actual token offer

* Get rid of magic numbers

* Documentation

* License update based on the original project

* Verbose readme

* Cleanup unused code, long lines and method order

* Typo; More verbose errors

* Use fallback mechanisms

* Refactor object allocation and certificate search

* PKCS11SPY mentioned, more TODO

* add SHA mechanisms

* Do not try to Finalize already finalized cryptoki

* Add more flags and mechanisms

* Do not list table for no results

* Logical order of the tests (regression last)

* read ALWAYS_AUTHENTICATE from correct place

* ALWAYS_AUTHENTICATE for decryption

* Test EC key length signature based on the actual key length

* Shorten CKM_ list output, add keygen types detection

* Skip decrypting on non-supported mechanisms

* Fail hard if the C_Login fails

* Reorganize local FLAGS_ constants

* Test RSA Digest mechanisms

* Correct mechanisms naming, typos

* Do not attempt to do signature using empty keys

* CKM_ECDSA_SHA1 support

* Correct type cast when getting attributes

* Report failures from all mechanisms

* Standardize return values, eliminate complete fails, documentation interface

* Wait for slot event test

* Add switch to allow interaction with a card (WaitForSlotEvent)

* At least try to verify using C_Verify, if it fails, fall back to openssl

* Get rid of function_pointers

* Get rid of additional newline

* Share always_authenticate() function between the test cases

* Refactor Encrypt&decrypt test to functions

* Do not overwrite bits if they are not provided by CKA, indentation

* Cleanup and Break to more functions Sign&Verify test

* CKM_RSA_X_509 sign and verify with openssl padding

* More TODO's

* Proper abstracted padding with RSA_X_509 mechanism

* Add ongoing tasks from different TODO list

* Update instructions. Another todo

* Variables naming

* Increase mechanism list size, use different static buffers for flags and mechanism names

* nonstandard mechanism CKM_SHA224_RSA_PKCS supported by some softotkens

* Get rid of loop initial declarations

* Loop initial declaration, typos, strict warnings

* Move the p11test to the new folder to avoid problems with dynamically linked opensc.so

* Update path in README

* Possibility to validate the testsuite agains software tokens

* Add possibility to select slot ID on command-line (when there are more cards present)

* Clean up readme to reflect current options and TODOs

* Do not attempt to use keys without advertised sign&verify bits to avoid false positives

* Get and present more object attributes in readonly test; refactor table

* New test checking if the set of attributes (usage flags) is reasonable

* Test multipart signatures. There is not reasonable mechanism supporting multipart encryption

* Use PKCS#11 encryption if possible (with openssl fallback)

* Identify few more mechanisms (PSS) in the lest

* Resize table to fit new mechanisms

* Remove initial loop declaration from multipart test

* Use pkcs11-tool instead of p11tool form most of the operations (master have most of the features)

* Preparation for machine readable results

* Refactor log variables out of the main context, try to export generic data

* Do not write to non-existing FD if not logging

* Export missing data into the log file in JSON

* Store database in json

* Sanity check

* Avoid uninitialized structure fields using in state structure

* Dump always_authenticate attribute too

* Manual selection of slots with possibility to use slots without tokens

* Do not free before finalizing

* Proper cleanup of message in all cases

* Proper allocation and deallocation of messages

* Sanitize missing cases (memory leaks)

* Suppressions for testing under valgrind

* Better handling message_lengt during sign&verify (avoid invalid access)

* Suppress another PCSC error

* Do not use default PIN. Fail if none specified

* Sanitize initialization. Skip incomplete key pairs

* Add missing newline in errors

* Fix condition for certificate search

* Avoid several calls for attributes of zero length

* Handle if the private key is not present on the card

* Improve memory handling, silent GCC warning of 'unused' variable

* Fail early with missing private key, cleanup the messages

* Use correct padding for encryption

* Cache if the card supports Verify/Encrypt and avoid trying over and over again

* Loosen the condition for the Usage flags

* OpenSSL 1.1.0 compatibility

* Add missing mechanisms

* Do not require certificates on the card and pass valid data for RSA_PKCS mechanisms

* Add missing PIN argument in runtest.sh

* Add OpenSSL < 1.1 comatible bits

* Add SHA2 ECDSA mechanisms handling

* Use public key from PKCS#11 if the certificate is missing (or compare it with certificate)

* Avoid long definitions in OpenSSL compat layer

* In older OpenSSL, the header file is ecdsa.h

* Add missing config.h to apply compat OpenSSL layer

* ASN1_STRING_get0_data() is also new in 1.1.0

* Return back RSA_X_509 mechanism

* Drop bogus CKM_* in the definitions

* Drop CKM_SHA224_RSA_PKCS as it is already in pkcs11.h

* Update documentation

* Use NDEBUG as intended

* typos, cleanup

* Typos, cleanup, update copyright

* Additional check for OpenCryptoki, generate more key types on soft tokens

* Prepare for RSA-PSS and RSA-OAEP

* Use usage&result flags for the tests, gracefully ignore PSS&OAEP

* pkcs11.h: Add missing definitions for PSS

* PSS and OAEP tests

readonly: Typos, reformat

* Working version, memory leak

* Tweak message lengths for OAEP and PSS

* Skip tests that are not aplicable for tokens

* configure.ac: New switch --enable-tests

Do not attempt to build tests if cmocka is not available or
--enable-tests is provided. It makes also more lightweight release
builds out of the box (or with --disable-tests).

* travis: Install cmocka if not available

* Do not build tests on Windows and make dist pass

* Try to install cmocka from apt and from brew

* Do not require sudo (cmocka from apt and brew works)
2018-05-18 12:31:55 +02:00
Jakub Jelen 09af8714ad Avoid GCC 7 warnings with -Werror (#1196)
* Avoid GCC 7 warnings with -Werror

-Werror=implicit-fallthrough=
	libopensc/card-incrypto34.c
		not sure if this is a bug or intention
	libopensc/card-rutoken.c
		most probably intention
	libopensc/card-westcos.c
		remove bogus if so the compile is not confused
		I will fill a separate bug to gcc probably
	pkcs15init/pkcs15-iasecc.c
		Simplify the log and avoid compiler confusion
	sm/sm-common.c
		explicit fallthrough
	tools/pkcs11-tool.c
		use explicit fallthrough comment
	tools/pkcs15-init.c
		The fallthrough is obvious here

-Werror=format-truncation=
	libopensc/pkcs15-itacns.c
		use explicit string lengths
	pkcs11/framework-pkcs15.c
		calculate the truncation
	tests/pintest.c
		avoid sprintf
	tools/pkcs15-crypt.c
		avoid sprintf
	tools/pkcs15-init.c
		calculate the truncation
2017-11-17 10:47:53 +01:00
Frank Morgner f4946df4e9 fixed dead assignments 2017-11-09 12:42:29 +01:00