]> granicus.if.org Git - openssl/commitdiff
Don't allow an empty Subject when creating a Certificate
authorMatt Caswell <matt@openssl.org>
Fri, 19 Jan 2018 14:34:56 +0000 (14:34 +0000)
committerMatt Caswell <matt@openssl.org>
Mon, 22 Jan 2018 10:07:41 +0000 (10:07 +0000)
Misconfiguration (e.g. an empty policy section in the config file) can
lead to an empty Subject. Since certificates should have unique Subjects
this should not be allowed.

Reviewed-by: Rich Salz <rsalz@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/5114)

apps/ca.c

index ea2750a3f8f8c75276c48ed4bf31d00a55150a6e..551d0aa2f8c3b2d2bf3ab01caaecdff880634bd3 100644 (file)
--- a/apps/ca.c
+++ b/apps/ca.c
@@ -1403,6 +1403,10 @@ static int do_body(X509 **xret, EVP_PKEY *pkey, X509 *x509,
         BIO_printf(bio_err, "The Subject's Distinguished Name is as follows\n");
 
     name = X509_REQ_get_subject_name(req);
+    if (X509_NAME_entry_count(name) == 0) {
+        BIO_printf(bio_err, "Error: The supplied Subject is empty\n");
+        goto end;
+    }
     for (i = 0; i < X509_NAME_entry_count(name); i++) {
         ne = X509_NAME_get_entry(name, i);
         str = X509_NAME_ENTRY_get_data(ne);
@@ -1565,6 +1569,12 @@ static int do_body(X509 **xret, EVP_PKEY *pkey, X509 *x509,
             goto end;
     }
 
+    if (X509_NAME_entry_count(subject) == 0) {
+        BIO_printf(bio_err,
+                   "Error: After applying policy the Subject is empty\n");
+        goto end;
+    }
+
     if (verbose)
         BIO_printf(bio_err,
                    "The subject name appears to be ok, checking data base for clashes\n");