1
0
mirror of https://github.com/opencryptoki/opencryptoki.git synced 2026-10-24 05:39:17 +03:00

26 Commits

Author SHA1 Message Date
Ingo Franzki
3f6fb6d30b TESTCASES: Add unit tests for PKCS#7 padding and unpadding
Test the PKCS#7 padding and unpadding functions to behave correctly
on various valid and invalid inputs.

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2026-10-22 12:53:13 +02:00
Ingo Franzki
238eb40a57 TESTCASES: Enhance the ASN.1 unit tests to test for PKCS#8 and SPKI compatibility
Produce a PKCS#8 and SPKI encoding using OpenSSL and test if the ASN.1 routines
can decode that key and also if the round trip produces the exact same encoded data.

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2026-10-20 14:31:37 +02:00
Ingo Franzki
9415b058cd TESTCASES: Correct the ASN.1 unit tests for Edwards and Montgomery keys
Correct the BER encoded data used for Edwards and Montgomery keys and add
tests for testing the legacy format still being accepted.

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2026-10-20 14:31:37 +02:00
Ingo Franzki
a57f9a02c3 TESTCASES: Add unit tests for invalid AlgorithmIdentifier decoding
Add tests that checks if wrong AlgorithmIdentifier are detected, i.e.
cases where the OID is too short or too long, or invalid by other means.

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2026-10-13 11:56:12 +02:00
Ingo Franzki
299ebae36b TESTCASES: Update ASN1 unit tests for common SPKI encoding function
Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2026-09-07 11:11:06 +02:00
Ingo Franzki
66de83dcc3 TESTCASES: Update ASN1 unit test for now rejected CHOICE option 0x1f
A CHOICE with an option value of 0x1f is invalid, it would indicate a
long form tag, which is not supported and is now rejected.
Change the test to check for rejection.

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2026-09-07 11:11:06 +02:00
Ingo Franzki
8cb0e36c2a COMMON: Refactor BER primitive encoding and decoding
Refactor the code to encode and decode the BER primitives. There was lots of
duplicated code in these functions. This is now refactored out into separate
helper functions.

Also the TLV encoding and decoding in these helpers have been refactored to
use a more streamlined implementation without many similar looking if cases.

With this, encoding and decoding data with more than 3 length octets (16 MB)
is now supported.

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2026-09-07 11:11:06 +02:00
Ingo Franzki
90df45fe70 COMMON: Remove dependency on liblber in common code
The use of liblber has been eliminated for most of the cases already.
The only leftover cases are in RSA, DSA, and DH public key encoding
functions for encoding BIT STRINGs.

Update these leftover places and use the already existing
ber_encode_BIT_STRING() function instead.

With this, '-lber' can be removed from the make files for most of
the tokens and tools. The ICSF token still requires liblber for its
LDAP communication.

Also adjust the configure script and example RPM spec accordingly.

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2026-09-07 11:11:06 +02:00
Ingo Franzki
c621d309e2 TESTCASES: Fix build warning with set but not used variable
Fix the following by removing the variable and its assignments entirely.
The function's actual pass/fail logic uses the global tests_failed counter.

testcases/unit/asn1fuzztest.c:846:9: warning: variable 'result' set but
                                     not used [-Wunused-but-set-variable]
  846 |     int result = 0;
      |         ^

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2026-07-27 08:16:09 +02:00
Ingo Franzki
dbd41d4a6c TESTS: Add unit and fuzzing tests for object flatten and unflatten in object.c
Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
Assisted-by: IBM Bob: 1.0.1
2026-05-28 10:41:26 +02:00
Ingo Franzki
45c14a7f76 TESTS: Add fuzzing tests for the basic BER encoding functions in asn1.c
Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
Assisted-by: IBM Bob: 1.0.1
2026-05-28 10:41:26 +02:00
Ingo Franzki
a7f2b36962 TESTS: Add unit tests for the BER encoding/decoding functions
Add unit tests for the basic BER encoding and decoding functions in asn1.c.

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
Assisted-by: IBM Bob: 1.0.1
2026-05-28 10:41:26 +02:00
Akash Kulhalli
a402a405fa aix: Add missing code that is AIX-specific
AIX does not have any of the BSD's warnx and friends functions, and neither
does it have getopt_long. Both of these are included, sourced from a pool of
permissive licenses, with their license notices intact.

In an effort to preserve nativity, this code is not used on other platforms,
instead preferring to use the native behaviours available on respective
platforms.

Additionally, this commit also includes some changes that _removes_
platform-specificity for the Linux platform, setting the _GNU_SOURCE macro
once in autoconf, instead of duplicating that in every source file.

Signed-off-by: Akash Kulhalli <akash.kulhalli@ibm.com>
2024-04-24 09:48:07 +02:00
Akash Kulhalli
d1785b5e54 testcases: miscellaneous updates
`random` returns a number within a range that includes 0; but the code does not
always handle that, leading to misleading error messages ("malloc failed" but
it was a request for a memory buffer of size 0) on test run. Those should now
be fixed.

The `ock_tests.sh.in` file has been slightly tweaked to account for some flags
that are not available on AIX. No functional differences expected across all
supported platforms.

On Linux, a null pointer is printed as "(null)", whereas on AIX nothing is
printed. Since this is only for tests, AIX now also prints the same string as
Linux when a nullptr is attempted to be printed.

Signed-off-by: Akash Kulhalli <akash.kulhalli@ibm.com>
2024-04-24 09:48:07 +02:00
Ingo Franzki
6acc08b6e7 policy: Also pass private callback data to free_attr callback function
The free_attr function might also need the private callback data, just
like the get_attr_val callback function.

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2024-02-09 14:02:18 +01:00
Ingo Franzki
278a65e660 Makefile: Fix noinst_HEADERS and EXTRA_DIST to include all headers and files
Headers not specified either in xxx_SOURCES or noinst_HEADERS will not
be included for 'make dist', and will cause compile errors during
'make distcheck'. Also include several extra files into EXTRA_DIST to
make sure they are distributed as well.

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2023-09-13 11:15:23 +02:00
Ingo Franzki
26fe51d922 POLICY: Dilithium strength and signature size depends on variant
Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2023-01-24 14:52:11 +01:00
Ingo Franzki
fc5b0da80b c99 fixes: strict prototypes and old-style definitions
The c99 standard requires strict prototypes and explicit definitions
of void functions.

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2022-11-11 10:33:15 +01:00
Holger Dengler
13f72b9295 testcases: unit: add tests for pin_prompt
Signed-off-by: Holger Dengler <dengler@linux.ibm.com>
2022-09-20 11:18:59 +02:00
Holger Dengler
1eb3f05c07 testcases: unit: add tests for buffer and uri
Add unit tests for internal library functions for p11_buffer and p11_uri.

Signed-off-by: Holger Dengler <dengler@linux.ibm.com>
2022-08-03 08:26:28 +02:00
Ingo Franzki
eb8acfc1db config: Add support for bare quoted strings
A bare quoted string can appear outside of a list or key value
pair and represents its own configuration element.

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2022-05-18 14:40:18 +02:00
Ingo Franzki
6c8f1a9734 config: Add support for number pair lists
This allows to parse the APQN_ALLOWLIST specification of an EP11 token
config file:

APQN_ALLOWLIST
   <card-no> <domain-no>
   ...
END

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2022-05-18 14:40:18 +02:00
Ingo Franzki
c06ffa0ef6 Makefile: Fix make files for building the config parser
Only reference the .y and .l files in SOURCES, but not the generated .c
files.

Building the configuration parser requires own rules for yacc and lex.
Avoid automake target override warning using Wno-override.

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2021-11-11 16:37:59 +01:00
Juergen Christ
b80631dff0 CONFIG: Add some unit tests
Signed-off-by: Juergen Christ <jchrist@linux.ibm.com>
2021-11-08 17:32:09 +01:00
Juergen Christ
3b0a198aa9 Exploit mechanism table
Make use of mechanism table to translate between string and numeric format of
mechanisms.  Remove duplicated code dealing with mechanism translations.

Signed-off-by: Juergen Christ <jchrist@linux.ibm.com>
2021-11-08 16:29:24 +01:00
Juergen Christ
c233e5b842 TEST: Policy, hashmap, and mechtable tests
Added some unit tests and a system test for manual execution.

Signed-off-by: Juergen Christ <jchrist@linux.ibm.com>
2021-11-08 16:29:24 +01:00