Set X509_V_ERR_INVALID_EXTENSION error for invalid basic constraints
authorTomas Mraz <tmraz@fedoraproject.org>
Thu, 2 Apr 2020 15:31:21 +0000 (17:31 +0200)
committerTomas Mraz <tmraz@fedoraproject.org>
Mon, 6 Apr 2020 08:26:13 +0000 (10:26 +0200)
If we encounter certificate with basic constraints CA:false,
pathlen present and X509_V_FLAG_X509_STRICT is set we set
X509_V_ERR_INVALID_EXTENSION error.

Reviewed-by: Bernd Edlinger <bernd.edlinger@hotmail.de>
Reviewed-by: Viktor Dukhovni <viktor@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/11463)

crypto/x509/x509_vfy.c

index b338b635316e584f7aff18c4c176e2c94f7bcf85..510b4f1109caa96c8be0040d00a8233c1b501622 100644 (file)
@@ -509,6 +509,12 @@ static int check_chain_extensions(X509_STORE_CTX *ctx)
                 ret = 1;
             break;
         }
+        if ((x->ex_flags & EXFLAG_CA) == 0
+            && x->ex_pathlen != -1
+            && (ctx->param->flags & X509_V_FLAG_X509_STRICT)) {
+            ctx->error = X509_V_ERR_INVALID_EXTENSION;
+            ret = 0;
+        }
         if (ret == 0 && !verify_cb_cert(ctx, x, i, X509_V_OK))
             return 0;
         /* check_purpose() makes the callback as needed */