-/* $OpenBSD: extern.h,v 1.193 2023/10/13 12:06:49 job Exp $ */
+/* $OpenBSD: extern.h,v 1.194 2023/11/16 11:10:59 tb Exp $ */
/*
* Copyright (c) 2019 Kristaps Dzonsons <kristaps@bsd.lv>
*
struct crl {
RB_ENTRY(crl) entry;
char *aki;
+ char *number;
X509_CRL *x509_crl;
time_t lastupdate; /* do not use before */
time_t nextupdate; /* do not use after */
int x509_get_notafter(X509 *, const char *, time_t *);
int x509_get_crl(X509 *, const char *, char **);
char *x509_crl_get_aki(X509_CRL *, const char *);
+char *x509_crl_get_number(X509_CRL *, const char *);
char *x509_get_pubkey(X509 *, const char *);
enum cert_purpose x509_get_purpose(X509 *, const char *);
int x509_get_time(const ASN1_TIME *, time_t *);
-/* $OpenBSD: x509.c,v 1.74 2023/09/12 09:33:30 job Exp $ */
+/* $OpenBSD: x509.c,v 1.75 2023/11/16 11:10:59 tb Exp $ */
/*
* Copyright (c) 2022 Theo Buehler <tb@openbsd.org>
* Copyright (c) 2021 Claudio Jeker <claudio@openbsd.org>
return res;
}
+/*
+ * Retrieve CRL Number extension. Returns a printable hexadecimal representation
+ * of the number which has to be freed after use.
+ */
+char *
+x509_crl_get_number(X509_CRL *crl, const char *fn)
+{
+ ASN1_INTEGER *aint;
+ int crit;
+ char *res = NULL;
+
+ aint = X509_CRL_get_ext_d2i(crl, NID_crl_number, &crit, NULL);
+ if (aint == NULL) {
+ warnx("%s: RFC 6487 section 5: CRL Number missing", fn);
+ return NULL;
+ }
+ if (crit != 0) {
+ warnx("%s: RFC 5280, section 5.2.3: "
+ "CRL Number not non-critical", fn);
+ goto out;
+ }
+
+ /* This checks that the number is non-negative and <= 20 bytes. */
+ res = x509_convert_seqnum(fn, aint);
+
+ out:
+ ASN1_INTEGER_free(aint);
+ return res;
+}
+
/*
* Convert passed ASN1_TIME to time_t *t.
* Returns 1 on success and 0 on failure.