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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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
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>
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>
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>