Index | Thread | Search

From:
Theo Buehler <tb@theobuehler.org>
Subject:
rpki-client: hoist up cert/crl checks in cms
To:
tech@openbsd.org
Date:
Thu, 3 Sep 2026 22:43:02 +0200

Download raw body.

Thread
  • Theo Buehler:

    rpki-client: hoist up cert/crl checks in cms

This moves the retrieval of the EE cert and the check of absence of CRLs
to the earliest possible moment. The signtime check must come after we
extracted the signed attributes so it's a bit lonely right now. We can
fix this later.

Index: cms.c
===================================================================
RCS file: /cvs/src/usr.sbin/rpki-client/cms.c,v
diff -u -p -r1.64 cms.c
--- cms.c	3 Sep 2026 19:10:35 -0000	1.64
+++ cms.c	3 Sep 2026 20:31:49 -0000
@@ -225,7 +225,8 @@ cms_parse_validate(struct cert **out_cer
 
 	/*
 	 * The CMS is self-signed with a signing certificate.
-	 * Verify that the self-signage is correct.
+	 * Verify that the self-signage is correct and set up internal
+	 * structs so that the following CMS API calls work correctly.
 	 */
 	if (!CMS_verify(cms, NULL, NULL, NULL, NULL,
 	    CMS_NO_SIGNER_CERT_VERIFY)) {
@@ -233,6 +234,27 @@ cms_parse_validate(struct cert **out_cer
 		goto out;
 	}
 
+	/* Extract and parse the EE cert for later verification. */
+	certs = CMS_get0_signers(cms);
+	if (certs == NULL || sk_X509_num(certs) != 1) {
+		warnx("%s: RFC 6488 section 2.1.4: eContent: "
+		    "want 1 signer, have %d", fn, sk_X509_num(certs));
+		goto out;
+	}
+	cert = cert_parse_ee_cert(fn, talid, sk_X509_value(certs, 0));
+	if (cert == NULL)
+		goto out;
+
+	/*
+	 * Check that there are no CRLs in this CMS message.
+	 * XXX - can only error check for OpenSSL >= 3.4.
+	 */
+	crls = CMS_get1_crls(cms);
+	if (crls != NULL && sk_X509_CRL_num(crls) != 0) {
+		warnx("%s: RFC 6488: CMS has CRLs", fn);
+		goto out;
+	}
+
 	/* RFC 6488 section 3 verify the CMS */
 
 	/* Should only return NULL if cms is not of type SignedData. */
@@ -336,33 +358,6 @@ cms_parse_validate(struct cert **out_cer
 		    "OID: %s, want %s", fn, buf, obuf);
 		goto out;
 	}
-
-	/*
-	 * Check that there are no CRLs in this CMS message.
-	 * XXX - can only error check for OpenSSL >= 3.4.
-	 */
-	crls = CMS_get1_crls(cms);
-	if (crls != NULL && sk_X509_CRL_num(crls) != 0) {
-		warnx("%s: RFC 6488: CMS has CRLs", fn);
-		goto out;
-	}
-
-	/*
-	 * The self-signing certificate is further signed by the input
-	 * signing authority according to RFC 6488, 2.1.4.
-	 * We extract that certificate now for later verification.
-	 */
-
-	certs = CMS_get0_signers(cms);
-	if (certs == NULL || sk_X509_num(certs) != 1) {
-		warnx("%s: RFC 6488 section 2.1.4: eContent: "
-		    "want 1 signer, have %d", fn, sk_X509_num(certs));
-		goto out;
-	}
-
-	cert = cert_parse_ee_cert(fn, talid, sk_X509_value(certs, 0));
-	if (cert == NULL)
-		goto out;
 
 	if (*signtime > cert->notafter)
 		warnx("%s: dating issue: CMS signing-time after X.509 notAfter",