// Fuzz target for the certificate bundle reader: any bytes as a PEM file.
// Whatever it accepts is a list of at most ANCHORS_MAX anchors, each with a
// name and an RSA or EC key; whatever it refuses comes with a reason and
// leaves no anchor.
#include "anchors.h"
#include "platform.h"
#include <stdint.h>
#include <string.h>
static Anchors a;
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size);
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
{
char why[200] = "";
if (!anchors_parse(&a, data, size, why, sizeof why)) {
ensure(why[0] != '\0' && a.n == 0);
return 0;
}
ensure(a.n <= ANCHORS_MAX);
for (size_t i = 0; i < a.n; i++) {
const br_x509_trust_anchor *t = &a.ta[i];
ensure(t->flags == 0 || t->flags == BR_X509_TA_CA);
if (t->pkey.key_type == BR_KEYTYPE_RSA) {
ensure(t->pkey.key.rsa.nlen > 0 && t->pkey.key.rsa.elen > 0);
} else {
ensure(t->pkey.key_type == BR_KEYTYPE_EC && t->pkey.key.ec.qlen > 0);
}
}
return 0;
}