Skip to content

Commit

Permalink
Add AKIDs to fizz/protocol test certs
Browse files Browse the repository at this point in the history
Summary:
OpenSSL 3.0+ requires certificates to have AKIDs; certificates without AKIDs will fail verification in `X509_verify_cert`.

Prior to this diff, `CertUtil::createCert` created certificates did not have skids/akids.  This diff now adds these extensions which will fix tests running under OpenSSL 3.0+.

Reviewed By: mingtaoy

Differential Revision: D61223734

fbshipit-source-id: 280b2f92c6e4f2d766b01e780823619d9c24d061
  • Loading branch information
Nick Richardson authored and facebook-github-bot committed Aug 15, 2024
1 parent e64ec1c commit 15056ef
Showing 1 changed file with 28 additions and 10 deletions.
38 changes: 28 additions & 10 deletions fizz/protocol/test/CertUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,19 +86,37 @@ inline CertAndKey createCert(std::string cn, bool ca, CertAndKey* issuer) {
std::string("failed to set name entry: ") + entry.first);
}

X509V3_CTX ctx;
if (issuer) {
X509V3_set_ctx(&ctx, issuer->cert.get(), crt.get(), nullptr, nullptr, 0);
} else {
X509V3_set_ctx(&ctx, crt.get(), crt.get(), nullptr, nullptr, 0);
}

std::string configuration = R"(
[fizz]
subjectKeyIdentifier = hash
authorityKeyIdentifier = keyid:always, issuer
extendedKeyUsage = critical, serverAuth, clientAuth
)";
if (ca) {
X509V3_CTX ctx;
X509V3_set_ctx_nodb(&ctx);
std::array<char, 8> constraint{"CA:TRUE"};
folly::ssl::X509ExtensionUniquePtr ext(X509V3_EXT_conf_nid(
nullptr, &ctx, NID_basic_constraints, constraint.data()));
throwIfNull(ext, "failed to create extension");
throwIfNeq(
X509_EXTENSION_set_critical(ext.get(), 1), 1, "failed to set critical");
throwIfNeq(
X509_add_ext(crt.get(), ext.get(), -1), 1, "failed to add extension");
configuration.append("basicConstraints = critical, CA:TRUE\n");
configuration.append(
"keyUsage = critical, cRLSign, digitalSignature, keyCertSign\n");
} else {
configuration.append("basicConstraints = critical, CA:FALSE\n");
configuration.append("keyUsage = critical, cRLSign, digitalSignature\n");
}

folly::ssl::BioUniquePtr bio(
BIO_new_mem_buf(configuration.data(), configuration.size()));
CONF* c = NCONF_new(nullptr);
NCONF_load_bio(c, bio.get(), nullptr);
// Create X509_EXTENSIONS from each extension config specified in the "fizz"
// section then add them into the X509 `crt`
X509V3_EXT_add_nconf(c, &ctx, "fizz", crt.get());
NCONF_free(c);

if (issuer) {
throwIfNeq(
X509_set_issuer_name(
Expand Down

0 comments on commit 15056ef

Please sign in to comment.