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

684 Commits

Author SHA1 Message Date
Ingo Franzki
1cf361530d TESTCASES: Add tests for CKR_BUFFER_TOO_SMALL on encrypt and decrypt
Check that an encrypt or decrypt call with a too small buffer correctly
returns CKR_BUFFER_TOO_SMALL, update the output buffer length to the
required size, and does not write to the output buffer beyond the
provided output buffer length. Furthermore, the operation must stay
active and a retry must be possible.

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2026-10-22 12:53:13 +02:00
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
Alexandre Laroche
e8cadb2484 TESTCASES: Check unwrapped DH, ML-DSA and ML-KEM private keys too
Run check_unwrap_sensitive_extractable() after the private key unwrap in
the ML-DSA and ML-KEM key transfer tests, for every test vector, and add
do_WrapUnwrapDHKey(), which wraps a generated DH private key under an AES
key with CKM_AES_CBC_PAD and runs the same check.

DSA is not covered: the soft token is built with -DNODSA, so no DSA test
runs there.

Signed-off-by: Alexandre Laroche <larochealexandre@hotmail.com>
Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2026-10-19 13:52:53 +02:00
Alexandre Laroche
7131685d35 TESTCASES: Check CKA_SENSITIVE and CKA_EXTRACTABLE of unwrapped keys
Add check_unwrap_sensitive_extractable() to the common test code. It
unwraps the same data with each combination of CKA_SENSITIVE and
CKA_EXTRACTABLE, and with neither, and checks every new key: the
attributes match the template (any value is accepted when the template
does not set them, since the defaults are token specific);
CKA_ALWAYS_SENSITIVE and CKA_NEVER_EXTRACTABLE are FALSE; and the key
value cannot be read from a sensitive key. When the unwrapping key's
CKA_UNWRAP_TEMPLATE sets one of the attributes, a key unwrapped without
it gets that value, and a template asking for the other value must fail
with CKR_TEMPLATE_INCONSISTENT.

CKA_ALWAYS_SENSITIVE and CKA_NEVER_EXTRACTABLE are not checked on the
ICSF token, which unwraps on the ICSF server and takes these attributes
from it.

Run it from do_WrapUnwrapAES() for secret keys, from do_WrapUnwrapRSA()
for RSA private keys, and from both EC key transfer tests for EC private
keys, whose transport key's CKA_UNWRAP_TEMPLATE sets CKA_EXTRACTABLE =
FALSE. Add do_UnwrapTemplateAES(), which unwraps under a wrapping key
whose CKA_UNWRAP_TEMPLATE sets CKA_SENSITIVE = TRUE and CKA_EXTRACTABLE =
FALSE, for every AES wrap mechanism.

Signed-off-by: Alexandre Laroche <larochealexandre@hotmail.com>
Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2026-10-19 13:52:53 +02:00
Ingo Franzki
1ae575b090 CI: Stop an already running ICSF mock server before starting it again
Trying to start the ICS mock server when another instance is already running
leads to 'Address already in use'. Stop an already running ICSF mock server
before starting it again.

Also remove the token directory of a previous ICSF token before creating a
new one at the same location. THis is the same as addslot() does for the
other tokens.

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2026-10-14 11:09:31 +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
0e0a8c807f CI: 'make ci-cleanup' should also remove the testcase log files
Running 'make ci-installcheck' (or 'make installcheck') produces several
log files that contain the detail testcase output. Let 'make ci-cleanup'
also remove these log files.

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2026-10-13 09:33:43 +02:00
Ingo Franzki
da1daeaaab TESTCASES: Use a DH key that is complaint per NIST SP 800-56A R3 5.6.2.1.2
ICSF enforces NIST SP 800-56A compliance for private key validation during
key agreement. The key DH_PRIVATE_B does not pass this validation.

Update the testcase to use a valid private DH key that is complaint per
NIST SP 800-56A R3 5.6.2.1.2.

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2026-10-08 12:37:09 +02:00
Ingo Franzki
a3d297c30e TESTCASES: Don't set CKF_INTERFACE_FORK_SAFE to get interfaces
With the change of the previous commit, we must not set the
CKF_INTERFACE_FORK_SAFE flag when retrieving interfaces.

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2026-10-05 08:35:13 +02:00
Ingo Franzki
612cb84e23 TESTCASES: Remove temporary files produced by pkcstok_migrate_test.sh
Remove the .out files when the test has finished.

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2026-10-05 08:35:13 +02:00
Ingo Franzki
b0769d6332 CI: Let ock_tests.sh only spawn a certain number of concurrent processes
Spawn only up to MAX_JOBS concurrent jobs. Defer the remaining job until
others have finished. MAX_JOBS defaults to 16, but can be configured at
runtime.

While at it, make the jobs limit for tok2toktest.sh also configurable, with
a default of 16 concurrent jobs. Also use 'wait -n' instead of polling
for jobs to complete.

When configured with the address sanitizer active, limit the number of jobs
to 4 because with ASAN it needs more memory and might run into out-of-memory
situations with too many concurrent jobs.

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2026-09-25 08:49:36 +02:00
Ingo Franzki
943924e4e6 CI: Backup the existing opencryptoki.conf before overwriting
The ciconfig.sh script creates a new opencryptoki.conf. Backup the existing
one as '.opencryptoki.conf.ci-backup' before overwriting it. If the backup
file already exists, don't overwrite it.

During 'make ci-cleanup' restore the original opencryptoki.conf, if the
backup file '.opencryptoki.conf.ci-backup' exists.

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2026-09-25 08:49:36 +02:00
Ingo Franzki
a1d6b8c375 CI: Remove the CI tokens during 'make ci-cleanup'
Remove all tokens added during ci-prepare.

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2026-09-25 08:49:36 +02:00
Ingo Franzki
71f197707e CI: Add an ICSF token using the ICSF mock server for 'make ci-installcheck'
Add one ICSF token at slot 50 that uses the ICSF mock server as back end.

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2026-09-25 08:49:36 +02:00
Ingo Franzki
f0df2b4023 TESTCASES: Skip object mgmt testcases for ICSF token
The ICSF token does not support all attributes used in the object mgmt tests.
Skip the entire test if running against the ICSF token.

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2026-09-23 13:25:13 +02:00
Ingo Franzki
6d90d94500 TESTCASES: Adjust PKCS#11 testcases for ICSF token
The ICSF token does not support all attributes used in the PKCS11 tests.
Adjust the test logic and skip the unsupported test conditions.

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2026-09-23 13:25:13 +02:00
Ingo Franzki
2ba0a19469 TESTCASES: Adjust p11sak_test.sh for the ICSF token
The ICSF token does not support public sessions. Communicating to an ICSF
server always requires a login (SO or USER). Skip the --no-logon tests.

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2026-09-23 13:25:13 +02:00
Ingo Franzki
afb7209dd0 TESTCASE: Let run_DeriveECDHKeyKAT() continue with next vector on error
In case run_DeriveECDHKeyKAT() finds an error with one test vector, continue
with the next one.

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2026-09-23 13:25:13 +02:00
Ingo Franzki
6d329a4549 TESTCASES: Skip unsupported curves and KDFs for the ICSF token
Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2026-09-23 13:25:13 +02:00
Ingo Franzki
d3b97c59c3 TESTCASES: tok2tok: Skip if an EC key with an unsupported curve is generated
Don't treat CKR_CURVE_NOT_SUPPORTED as error, skip instead.

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2026-09-11 13:53:23 +02:00
Ingo Franzki
ce11cba0bb CI: Run tok2tok_transport on all slot combination in the CI
Discovers all available, initialized tokens and runs tok2tok_transport
for every combination of slots (including same-slot). When multiple
slots carry tokens of the same type/model, only the first one is used
to avoid redundant runs.

Each run is spawned as a background process. Its combined stdout and
stderr are redirected to log-tok2tok-slots_X_Y.txt where X and Y are
the two slot numbers used. Run only up to 4 concurrent jobs to not run
into out-of-memory situations.

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2026-09-09 08:14:11 +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
83d8e3ce97 TESTCASES: Add a token migration test to 'make ci-installcheck'
In case the token format is the pre-FIPS format (every other day) then
migrate the token data of the Soft token 'sw0' to the new FIPS format
using the pkcstok_migrate tool after all tests have been run.
Verify that all objects have been migrated successfully.

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2026-08-31 08:15:46 +02:00
Ingo Franzki
356c144b9e TESTCASES: Detect if the fork child was killed by a signal
Print the signal that killed the fork child to the test output.

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2026-08-19 08:28:00 +02:00
Ingo Franzki
3720edf4fd TESTCASES: Recognize the ICSF token in ock_tests.sh
Let the script recognize the ICSF token, based on the model containing 'HCR'.

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2026-08-19 08:27:59 +02:00
Ingo Franzki
dba13f348f TESTCASES: Better error checking in p11kmip_test.sh
Make sure to capture failing commands and report them through the scripts
exit code.

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2026-08-19 08:27:58 +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
ab96be64ec TESTCASES: Fix resource leak in run_DeriveBTC
Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2026-07-22 13:17:14 +02:00
Ingo Franzki
26e3591e02 TESTCASES: Add tests for the CKM_IBM_ETH_DERIVE mechanism
Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2026-07-22 13:17:14 +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
Ingo Franzki
583d0128bb Bumping up to version-3.27
Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2026-05-13 13:19:05 +02:00
Ingo Franzki
e5314ff05f TESTCASES: Skip if CKR_FUNCTION_CANCELED with ML-KEM with ECDH
CKR_FUNCTION_CANCELED usually indicates that a control point prohibits
an operation, or that the operation is not allowed due to some other
policy. Skip the test in that case.

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2026-05-13 13:18:08 +02:00
Ingo Franzki
67f2819789 TESTCASES: Skip if CKR_KEY_SIZE_RANGE at C_DeriveKey
C_DeriveKey may return CKR_KEY_SIZE_RANGE when CCA enforces the NIST
security strength requirements regarding ECC curve type (input) and
derived key-length.

Skip the test in such cases.

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2026-05-13 13:18:08 +02:00
Ingo Franzki
ba2550b01f TESTCASES: Fix memory leak in run_EncapsDecapsECDH
Fixes: c2ab1d9b8c

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2026-04-28 13:31:01 +02:00
Ingo Franzki
5847880151 TESTCASES: Fix memory leak in do_EnDecapsulateDHKey
Fixes: 6acd311005

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2026-04-28 13:31:01 +02:00
Ingo Franzki
41294a08a8 TESTCASES: Add the new ECDH_*_AES_KEY_WRAP mechanisms to tok2tok test
Test the new ECDH_*_AES_KEY_WRAP mechanisms.

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2026-04-22 13:07:43 +02:00
Ingo Franzki
4abd6fa0d1 TESTCASES: Allow additional public exponent values for CCA
Update the list of valid RSA public exponents for CCA.

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2026-04-17 11:20:24 +02:00
Ingo Franzki
f2ff1dcf2b TESTCASES: Fix ECDH en-/decapsulation tests for older EP11 cards
Older EP11 firmware does not support ECDH with KDFs other than CKD_NULL, or
with non-empty shared data. This fails with CKR_MECHANISM_PARAM_INVALID
and must be skipped as unsupported properly. This error might only be
reported for the non-size-query call to C_EncapsulateKey.

Add a test vector with CKD_NULL and empty shared data to have at least one
supported test for such older EP11 cards.

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2026-04-14 15:34:31 +02:00
Ingo Franzki
6b73e1ba57 TESTCASES: Add tests for ML-KEM of PKCS#11 v3.2 to cca_ep11_export_import_test
Test exporting and importing ML-KEM keys via its opaque key blob.

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2026-04-13 14:39:43 +02:00
Ingo Franzki
214dedf268 TESTCASES: Add tests for ML-DSA of PKCS#11 v3.2 to cca_ep11_export_import_test
Test exporting and importing ML-DSA keys via its opaque key blob.

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2026-04-13 14:39:43 +02:00
Ingo Franzki
ea341db322 TESTCASES: Add PKCS#11 v3.2 ML-DSA and ML-KEM tests for p11sak
Test working with ML-DSA and ML-KEM key types of PKCS#11 v3.2 with p11sak.

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2026-04-13 14:39:43 +02:00
Ingo Franzki
9b56859008 TESTCASES: Add tests for ML-DSA and ML-KEM of PKCS#11 v3.2 for tok2tok_transport
Test key wrapping of ML-DSA and ML-KEM keys of PKCS#11 v3.2.

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2026-04-13 14:39:43 +02:00
Ingo Franzki
f38928daff TESTCASES: Add tests for ML-KEM of PKCS#11 v3.2
Test ML-KEM of PKCS#11 v3.2.

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2026-04-13 14:39:43 +02:00