-/* $OpenBSD: cert.c,v 1.131 2024/05/20 15:51:43 claudio Exp $ */
+/* $OpenBSD: cert.c,v 1.132 2024/05/31 02:45:15 tb Exp $ */
/*
* Copyright (c) 2022 Theo Buehler <tb@openbsd.org>
* Copyright (c) 2021 Job Snijders <job@openbsd.org>
return rc;
}
+static int
+cert_check_subject_and_issuer(const char *fn, const X509 *x)
+{
+ const X509_NAME *name;
+
+ if ((name = X509_get_subject_name(x)) == NULL) {
+ warnx("%s: X509_get_subject_name", fn);
+ return 0;
+ }
+ if (!x509_valid_name(fn, "subject", name))
+ return 0;
+
+ if ((name = X509_get_issuer_name(x)) == NULL) {
+ warnx("%s: X509_get_issuer_name", fn);
+ return 0;
+ }
+ if (!x509_valid_name(fn, "issuer", name))
+ return 0;
+
+ return 1;
+}
+
/*
* Lightweight version of cert_parse_pre() for EE certs.
* Parses the two RFC 3779 extensions, and performs some sanity checks.
goto out;
}
- if (!x509_valid_subject(fn, x))
+ if (!cert_check_subject_and_issuer(fn, x))
goto out;
if (X509_get_key_usage(x) != KU_DIGITAL_SIGNATURE) {
goto out;
}
- if (!x509_valid_subject(fn, x))
+ if (!cert_check_subject_and_issuer(fn, x))
goto out;
/* Look for X509v3 extensions. */
-/* $OpenBSD: crl.c,v 1.35 2024/05/29 13:26:24 tb Exp $ */
+/* $OpenBSD: crl.c,v 1.36 2024/05/31 02:45:15 tb Exp $ */
/*
* Copyright (c) 2019 Kristaps Dzonsons <kristaps@bsd.lv>
*
const unsigned char *oder;
struct crl *crl;
const X509_ALGOR *palg;
+ const X509_NAME *name;
const ASN1_OBJECT *cobj;
const ASN1_TIME *at;
int count, nid, rc = 0;
goto out;
}
+ if ((name = X509_CRL_get_issuer(crl->x509_crl)) == NULL) {
+ warnx("%s: X509_CRL_get_issuer", fn);
+ goto out;
+ }
+ if (!x509_valid_name(fn, "issuer", name))
+ goto out;
+
X509_CRL_get0_signature(crl->x509_crl, NULL, &palg);
if (palg == NULL) {
warnx("%s: X509_CRL_get0_signature", fn);
-/* $OpenBSD: extern.h,v 1.219 2024/05/29 13:26:24 tb Exp $ */
+/* $OpenBSD: extern.h,v 1.220 2024/05/31 02:45:15 tb Exp $ */
/*
* Copyright (c) 2019 Kristaps Dzonsons <kristaps@bsd.lv>
*
GENERAL_NAME *, char **);
int x509_inherits(X509 *);
int x509_any_inherits(X509 *);
-int x509_valid_subject(const char *, const X509 *);
+int x509_valid_name(const char *, const char *, const X509_NAME *);
time_t x509_find_expires(time_t, struct auth *, struct crl_tree *);
/* printers */
-/* $OpenBSD: x509.c,v 1.88 2024/05/29 13:26:24 tb Exp $ */
+/* $OpenBSD: x509.c,v 1.89 2024/05/31 02:45:15 tb Exp $ */
/*
* Copyright (c) 2022 Theo Buehler <tb@openbsd.org>
* Copyright (c) 2021 Claudio Jeker <claudio@openbsd.org>
}
/*
- * Check that the subject only contains commonName and serialNumber.
+ * Check that subject or issuer only contain commonName and serialNumber.
* Return 0 on failure.
*/
int
-x509_valid_subject(const char *fn, const X509 *x)
+x509_valid_name(const char *fn, const char *descr, const X509_NAME *xn)
{
- const X509_NAME *xn;
const X509_NAME_ENTRY *ne;
const ASN1_OBJECT *ao;
const ASN1_STRING *as;
int cn = 0, sn = 0;
int i, nid;
- if ((xn = X509_get_subject_name(x)) == NULL) {
- warnx("%s: X509_get_subject_name", fn);
- return 0;
- }
-
for (i = 0; i < X509_NAME_entry_count(xn); i++) {
if ((ne = X509_NAME_get_entry(xn, i)) == NULL) {
warnx("%s: X509_NAME_get_entry", fn);
switch (nid) {
case NID_commonName:
if (cn++ > 0) {
- warnx("%s: duplicate commonName in subject",
- fn);
+ warnx("%s: duplicate commonName in %s",
+ fn, descr);
return 0;
}
if ((as = X509_NAME_ENTRY_get_data(ne)) == NULL) {
break;
case NID_serialNumber:
if (sn++ > 0) {
- warnx("%s: duplicate serialNumber in subject",
- fn);
+ warnx("%s: duplicate serialNumber in %s",
+ fn, descr);
return 0;
}
break;
return 0;
default:
warnx("%s: RFC 6487 section 4.5: unexpected attribute"
- " %s", fn, nid2str(nid));
+ " %s in %s", fn, nid2str(nid), descr);
return 0;
}
}
if (cn == 0) {
- warnx("%s: RFC 6487 section 4.5: subject missing commonName",
- fn);
+ warnx("%s: RFC 6487 section 4.5: %s missing commonName",
+ fn, descr);
return 0;
}