-/* $OpenBSD: x509_purp.c,v 1.25 2023/04/23 21:49:15 job Exp $ */
+/* $OpenBSD: x509_purp.c,v 1.26 2023/06/20 14:21:19 tb Exp $ */
/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
* project 2001.
*/
ASN1_BIT_STRING *ns;
EXTENDED_KEY_USAGE *extusage;
X509_EXTENSION *ex;
+ long version;
int i;
if (x->ex_flags & EXFLAG_SET)
X509_digest(x, X509_CERT_HASH_EVP, x->hash, NULL);
- /* V1 should mean no extensions ... */
- if (X509_get_version(x) == 0) {
+ version = X509_get_version(x);
+ if (version < 0 || version > 2)
+ x->ex_flags |= EXFLAG_INVALID;
+ if (version == 0) {
x->ex_flags |= EXFLAG_V1;
- if (X509_get_ext_count(x) != 0)
+ /* UIDs may only appear in v2 or v3 certs */
+ if (x->cert_info->issuerUID != NULL ||
+ x->cert_info->subjectUID != NULL)
x->ex_flags |= EXFLAG_INVALID;
}
+ if (version != 2 && X509_get_ext_count(x) != 0)
+ x->ex_flags |= EXFLAG_INVALID;
/* Handle basic constraints */
if ((bs = X509_get_ext_d2i(x, NID_basic_constraints, &i, NULL))) {