Skip to content

eBPF-based security platform

testing: check cleanup after a malformed certificate

KP Singh0aa94e3525d1
diff --git a/testing/helper/test-keys.c b/testing/helper/test-keys.c
index f8c903b7..b2774adb 100644
--- a/testing/helper/test-keys.c
+++ b/testing/helper/test-keys.c
@@ -7,6 +7,7 @@
* signer. Subcommand on argv[1]; prints what a shell test asserts on.
*/
+#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -32,7 +33,8 @@ int main(int argc, char **argv)
int rc;
if (argc < 3) {
- fprintf(stderr, "usage: %s load|digest <keys-dir> [primary]"
+ fprintf(stderr, "usage: %s load|digest|reject <keys-dir>"
+ " [primary]"
" | signer <upatch> <cert.der>\n", argv[0]);
return 2;
}
@@ -57,6 +59,8 @@ int main(int argc, char **argv)
}
rc = shirudo_keys_load(argv[2], NULL,
argc < 4 || strcmp(argv[3], "primary"), &set);
+ if (!strcmp(argv[1], "reject"))
+ return rc == -EINVAL ? 0 : 1;
if (rc) {
printf("rc=%d\n", rc);
return 1;
diff --git a/testing/t0037-keys-set.sh b/testing/t0037-keys-set.sh
index 36a498fc..b24d3753 100755
--- a/testing/t0037-keys-set.sh
+++ b/testing/t0037-keys-set.sh
@@ -62,4 +62,15 @@ test_expect_success 'a revoked certificate is left out of the set' '
! grep -q "$fp_c" "$W/set2"
'
+test_expect_success 'malformed trusted certificates are rejected before or after valid candidates' '
+ mkdir -p "$W/malformed/trusted" &&
+ cp "$W/a/cert.der" "$W/malformed/cert.der" &&
+ cp "$W/b/cert.der" "$W/malformed/trusted/middle.der" &&
+ printf "invalid DER" >"$W/malformed/trusted/first.der" &&
+ ./$H reject "$W/malformed" &&
+ mv "$W/malformed/trusted/first.der" "$W/malformed/trusted/last.der" &&
+ mv "$W/malformed/trusted/middle.der" "$W/malformed/trusted/first.der" &&
+ ./$H reject "$W/malformed"
+'
+
test_done