Make PKCS8 dependant unit tests fail gracefully
cover Make PKCS8 dependant unit tests fail gracefully
This patch is based on the failure check in unit/test-cipher, which gives mitigation instructions for known and easily correctable deficiencies in Kernel space. In the case of these three unit tests, the pkcs8_key_parser must be loaded for the unit test to pass. If not loaded the mitigation is given, and the test exits with an exit(1) rather than an assert fail.
Brian Gix (1):
unit: Add graceful fail of pem, tls and key tests
unit/test-key.c | 9 +++++++++ unit/test-pem.c | 9 +++++++++ unit/test-tls.c | 12 +++++++++++- 3 files changed, 29 insertions(+), 1 deletion(-)
Signature · 1 line
2.21.0
PATCH 1/1 unit: Add graceful fail of pem, tls and key tests
Unit tests for PEM, TLS and KEY require the pkcs8_key_parser module to be running in the kernel, however not all kernels have this running by default. This checks for this possibility and aborts these tests with exit(1) rather than an assert, and includes instruction to correct the issue.
--- unit/test-key.c | 9 +++++++++ unit/test-pem.c | 9 +++++++++ unit/test-tls.c | 12 +++++++++++- 3 files changed, 29 insertions(+), 1 deletion(-)
unit/test-key.c +9 -0
@@ -569,6 +569,15 @@ static void test_key_crypto(const void *data) privkey =l_pem_load_private_key (CERTDIR "cert-client-key-pkcs8.pem" ,NULL ,NULL ); +if (!privkey) { +l_info ("* Some kernel versions do not automatically load\n" +"* the pkcs8_key_parser module. If the system running\n" +"* test has not loaded this module, a failure here is\n" +"* likely. Running \"modprobe pkcs8_key_parser\" may\n" +"* correct this issue.\n" ); +exit (1 ); + } +assert (privkey); success =l_key_get_info (privkey, rsa, hash, &keybits, &is_public);assert (success);
unit/test-pem.c +9 -0
@@ -216,6 +216,15 @@ static void test_priv_key_from_data(const void *data) key =l_pem_load_private_key_from_data (raw_private_key,strlen (raw_private_key),"abc" , &is_encrypted); +if (!key) { +l_info ("* Some kernel versions do not automatically load\n" +"* the pkcs8_key_parser module. If the system running\n" +"* test has not loaded this module, a failure here is\n" +"* likely. Running \"modprobe pkcs8_key_parser\" may\n" +"* correct this issue.\n" ); +exit (1 ); + } +assert (key);assert (is_encrypted);
unit/test-tls.c +11 -1
@@ -562,8 +562,18 @@ static void test_tls_with_ver(const struct tls_conn_test *test,l_pem_load_private_key (test->server_key_path, test->server_key_passphrase,NULL ); -assert (server_cert); +if (!server_key) { +l_info ("* Some kernel versions do not automatically\n" +"* load the pkcs8_key_parser module. If the\n" +"* system running test has not loaded this\n" +"* module, a failure here is likely. Running\n" +"* \"modprobe pkcs8_key_parser\" may correct\n" +"* this issue.\n" ); +exit (1 ); + } +assert (server_key); +assert (server_cert);assert (l_tls_set_auth_data (s[0 ].tls, server_cert, server_key)); }
Signature · 1 line
2.21.0