Blame SOURCES/Fix-certauth-built-in-module-returns.patch

963210
From 41b9111b48e53bf7864ed1f134e0433b070fa900 Mon Sep 17 00:00:00 2001
963210
From: Greg Hudson <ghudson@mit.edu>
963210
Date: Thu, 24 Aug 2017 11:11:46 -0400
963210
Subject: [PATCH] Fix certauth built-in module returns
963210
963210
The PKINIT certauth eku module should never authoritatively authorize
963210
a certificate, because an extended key usage does not establish a
963210
relationship between the certificate and any specific user; it only
963210
establishes that the certificate was created for PKINIT client
963210
authentication.  Therefore, pkinit_eku_authorize() should return
963210
KRB5_PLUGIN_NO_HANDLE on success, not 0.
963210
963210
The certauth san module should pass if it does not find any SANs of
963210
the types it can match against; the presence of other types of SANs
963210
should not cause it to explicitly deny a certificate.  Check for an
963210
empty result from crypto_retrieve_cert_sans() in verify_client_san(),
963210
instead of returning ENOENT from crypto_retrieve_cert_sans() when
963210
there are no SANs at all.
963210
963210
ticket: 8561
963210
(cherry picked from commit 07243f85a760fb37f0622d7ff0177db3f19ab025)
963210
---
167778
 .../preauth/pkinit/pkinit_crypto_openssl.c    | 39 +++++++++----------
167778
 src/plugins/preauth/pkinit/pkinit_srv.c       | 14 ++++---
963210
 2 files changed, 27 insertions(+), 26 deletions(-)
963210
963210
diff --git a/src/plugins/preauth/pkinit/pkinit_crypto_openssl.c b/src/plugins/preauth/pkinit/pkinit_crypto_openssl.c
963210
index 70e230ec2..7fa2efd21 100644
963210
--- a/src/plugins/preauth/pkinit/pkinit_crypto_openssl.c
963210
+++ b/src/plugins/preauth/pkinit/pkinit_crypto_openssl.c
963210
@@ -2137,7 +2137,6 @@ crypto_retrieve_X509_sans(krb5_context context,
963210
 
963210
     if (!(ext = X509_get_ext(cert, l)) || !(ialt = X509V3_EXT_d2i(ext))) {
963210
         pkiDebug("%s: found no subject alt name extensions\n", __FUNCTION__);
963210
-        retval = ENOENT;
963210
         goto cleanup;
963210
     }
963210
     num_sans = sk_GENERAL_NAME_num(ialt);
963210
@@ -2240,31 +2239,29 @@ crypto_retrieve_X509_sans(krb5_context context,
963210
     sk_GENERAL_NAME_pop_free(ialt, GENERAL_NAME_free);
963210
 
963210
     retval = 0;
963210
-    if (princs)
963210
+    if (princs != NULL && *princs != NULL) {
963210
         *princs_ret = princs;
963210
-    if (upns)
963210
+        princs = NULL;
963210
+    }
963210
+    if (upns != NULL && *upns != NULL) {
963210
         *upn_ret = upns;
963210
-    if (dnss)
963210
+        upns = NULL;
963210
+    }
963210
+    if (dnss != NULL && *dnss != NULL) {
963210
         *dns_ret = dnss;
963210
+        dnss = NULL;
963210
+    }
963210
 
963210
 cleanup:
963210
-    if (retval) {
963210
-        if (princs != NULL) {
963210
-            for (i = 0; princs[i] != NULL; i++)
963210
-                krb5_free_principal(context, princs[i]);
963210
-            free(princs);
963210
-        }
963210
-        if (upns != NULL) {
963210
-            for (i = 0; upns[i] != NULL; i++)
963210
-                krb5_free_principal(context, upns[i]);
963210
-            free(upns);
963210
-        }
963210
-        if (dnss != NULL) {
963210
-            for (i = 0; dnss[i] != NULL; i++)
963210
-                free(dnss[i]);
963210
-            free(dnss);
963210
-        }
963210
-    }
963210
+    for (i = 0; princs != NULL && princs[i] != NULL; i++)
963210
+        krb5_free_principal(context, princs[i]);
963210
+    free(princs);
963210
+    for (i = 0; upns != NULL && upns[i] != NULL; i++)
963210
+        krb5_free_principal(context, upns[i]);
963210
+    free(upns);
963210
+    for (i = 0; dnss != NULL && dnss[i] != NULL; i++)
963210
+        free(dnss[i]);
963210
+    free(dnss);
963210
     return retval;
963210
 }
963210
 
963210
diff --git a/src/plugins/preauth/pkinit/pkinit_srv.c b/src/plugins/preauth/pkinit/pkinit_srv.c
963210
index 9c6e96c9e..8e77606f8 100644
963210
--- a/src/plugins/preauth/pkinit/pkinit_srv.c
963210
+++ b/src/plugins/preauth/pkinit/pkinit_srv.c
963210
@@ -187,14 +187,18 @@ verify_client_san(krb5_context context,
963210
                                        &princs,
963210
                                        plgctx->opts->allow_upn ? &upns : NULL,
963210
                                        NULL);
963210
-    if (retval == ENOENT) {
963210
-        TRACE_PKINIT_SERVER_NO_SAN(context);
963210
-        goto out;
963210
-    } else if (retval) {
963210
+    if (retval) {
963210
         pkiDebug("%s: error from retrieve_certificate_sans()\n", __FUNCTION__);
963210
         retval = KRB5KDC_ERR_CLIENT_NAME_MISMATCH;
963210
         goto out;
963210
     }
963210
+
963210
+    if (princs == NULL && upns == NULL) {
963210
+        TRACE_PKINIT_SERVER_NO_SAN(context);
963210
+        retval = ENOENT;
963210
+        goto out;
963210
+    }
963210
+
963210
     /* XXX Verify this is consistent with client side XXX */
963210
 #if 0
963210
     retval = call_san_checking_plugins(context, plgctx, reqctx, princs,
963210
@@ -1495,7 +1499,7 @@ pkinit_eku_authorize(krb5_context context, krb5_certauth_moddata moddata,
963210
         return KRB5KDC_ERR_INCONSISTENT_KEY_PURPOSE;
963210
     }
963210
 
963210
-    return 0;
963210
+    return KRB5_PLUGIN_NO_HANDLE;
963210
 }
963210
 
963210
 static krb5_error_code