Skip to content

eBPF-based security platform

testing: fuzz the certificates and CMS signatures shirudo checks

Daniel Borkmannebfb82339bf8
diff --git a/Makefile.shirudo b/Makefile.shirudo
index a356699d..1e10ae0d 100644
--- a/Makefile.shirudo
+++ b/Makefile.shirudo
@@ -733,6 +733,8 @@ testing/fuzz/fuzz-serializer: testing/fuzz/fuzz-serializer.c $(FUZZ_BASE) \
util/timefmt.c $(LIBBPF_A)
testing/fuzz/fuzz-serializer: FUZZ_CFLAGS += $(LIBELF_CFLAGS)
testing/fuzz/fuzz-serializer: FUZZ_LIBS += $(LIBBPF_A) $(LIBELF_LIBS)
+testing/fuzz/fuzz-cms: testing/fuzz/fuzz-cms.c $(FUZZ_BASE) util/keys.c \
+ util/crypto_openssl.c util/io.c util/seal.c
testing/fuzz/fuzz-otel: testing/fuzz/fuzz-otel.c $(FUZZ_BASE) \
util/upatch_maps_otel.c util/crypto_openssl.c \
util/tls_openssl.c util/io.c util/version_id.c
diff --git a/testing/fuzz/corpus/cms/cert-and-signature b/testing/fuzz/corpus/cms/cert-and-signature
new file mode 100644
index 00000000..ce6a9444
Binary files /dev/null and b/testing/fuzz/corpus/cms/cert-and-signature differ
diff --git a/testing/fuzz/fuzz-cms.c b/testing/fuzz/fuzz-cms.c
new file mode 100644
index 00000000..f45e3969
--- /dev/null
+++ b/testing/fuzz/fuzz-cms.c
@@ -0,0 +1,48 @@
+// SPDX-License-Identifier: BSD-2-Clause
+/*
+ * Copyright (c) 2026 Authors of shirudo
+ *
+ * The certificates and detached CMS signatures that come with indexes,
+ * tree publications, packages and keys: a 16-bit little-endian length, a
+ * DER certificate of that length and a signature over the certificate.
+ */
+
+#include "crypto.h"
+#include "fuzz.h"
+#include "keys.h"
+#include "malloc.h"
+
+int LLVMFuzzerTestOneInput(const __u8 *data, size_t size)
+{
+ struct shirudo_cert_pubkey pub;
+ struct shirudo_cert cert = {};
+ size_t der_len, sig_len, n;
+ const __u8 *der, *sig;
+ __u8 sha[32], fp[32];
+ __u8 *raw;
+
+ if (size < 2)
+ return 0;
+ der_len = data[0] | (size_t)data[1] << 8;
+ if (der_len > size - 2)
+ return 0;
+ der = data + 2;
+ sig = der + der_len;
+ sig_len = size - 2 - der_len;
+
+ shirudo_keys_digest_der(der, der_len, sha, fp);
+ if (!shirudo_cert_read_der(der, der_len, &cert)) {
+ shirudo_cert_pubkey(&cert, &pub);
+ shirudo_verify_detached(der, der_len, sig, sig_len, &cert);
+ shirudo_cms_signed_by(sig, sig_len, &cert);
+ shirudo_cert_free(&cert);
+ }
+
+ raw = xmalloc(sig_len + 1);
+ if (raw) {
+ shirudo_base64_decode((const char *)sig, sig_len, raw,
+ sig_len + 1, &n);
+ xfree(raw, sig_len + 1);
+ }
+ return 0;
+}