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

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