0e3136
diff --git a/modules/ssl/ssl_engine_init.c b/modules/ssl/ssl_engine_init.c
0e3136
index 15f68f9..e67c81d 100644
0e3136
--- a/modules/ssl/ssl_engine_init.c
0e3136
+++ b/modules/ssl/ssl_engine_init.c
0e3136
@@ -1682,6 +1682,10 @@ static apr_status_t ssl_init_proxy_certs(server_rec *s,
0e3136
     STACK_OF(X509) *chain;
0e3136
     X509_STORE_CTX *sctx;
0e3136
     X509_STORE *store = SSL_CTX_get_cert_store(mctx->ssl_ctx);
0e3136
+    int addl_chain = 0; /* non-zero if additional chain certs were
0e3136
+                         * added to store */
0e3136
+
0e3136
+    ap_assert(store != NULL); /* safe to assume always non-NULL? */
0e3136
 
0e3136
 #if OPENSSL_VERSION_NUMBER >= 0x1010100fL
0e3136
     /* For OpenSSL >=1.1.1, turn on client cert support which is
0e3136
@@ -1707,20 +1711,28 @@ static apr_status_t ssl_init_proxy_certs(server_rec *s,
0e3136
         ssl_init_ca_cert_path(s, ptemp, pkp->cert_path, NULL, sk);
0e3136
     }
0e3136
 
0e3136
-    if ((ncerts = sk_X509_INFO_num(sk)) <= 0) {
0e3136
-        sk_X509_INFO_free(sk);
0e3136
-        ap_log_error(APLOG_MARK, APLOG_WARNING, 0, s, APLOGNO(02206)
0e3136
-                     "no client certs found for SSL proxy");
0e3136
-        return APR_SUCCESS;
0e3136
-    }
0e3136
-
0e3136
     /* Check that all client certs have got certificates and private
0e3136
-     * keys. */
0e3136
-    for (n = 0; n < ncerts; n++) {
0e3136
+     * keys.  Note the number of certs in the stack may decrease
0e3136
+     * during the loop. */
0e3136
+    for (n = 0; n < sk_X509_INFO_num(sk); n++) {
0e3136
         X509_INFO *inf = sk_X509_INFO_value(sk, n);
0e3136
+        int has_privkey = inf->x_pkey && inf->x_pkey->dec_pkey;
0e3136
 
0e3136
-        if (!inf->x509 || !inf->x_pkey || !inf->x_pkey->dec_pkey ||
0e3136
-            inf->enc_data) {
0e3136
+        /* For a lone certificate in the file, trust it as a
0e3136
+         * CA/intermediate certificate. */
0e3136
+        if (inf->x509 && !has_privkey && !inf->enc_data) {
0e3136
+            ssl_log_xerror(SSLLOG_MARK, APLOG_DEBUG, 0, ptemp, s, inf->x509,
0e3136
+                           APLOGNO(10261) "Trusting non-leaf certificate");
0e3136
+            X509_STORE_add_cert(store, inf->x509); /* increments inf->x509 */
0e3136
+            /* Delete from the stack and iterate again. */
0e3136
+            X509_INFO_free(inf);
0e3136
+            sk_X509_INFO_delete(sk, n);
0e3136
+            n--;
0e3136
+            addl_chain = 1;
0e3136
+            continue;
0e3136
+        }
0e3136
+
0e3136
+        if (!has_privkey || inf->enc_data) {
0e3136
             sk_X509_INFO_free(sk);
0e3136
             ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, s, APLOGNO(02252)
0e3136
                          "incomplete client cert configured for SSL proxy "
0e3136
@@ -1737,13 +1749,21 @@ static apr_status_t ssl_init_proxy_certs(server_rec *s,
0e3136
         }
0e3136
     }
0e3136
 
0e3136
+    if ((ncerts = sk_X509_INFO_num(sk)) <= 0) {
0e3136
+        sk_X509_INFO_free(sk);
0e3136
+        ap_log_error(APLOG_MARK, APLOG_WARNING, 0, s, APLOGNO(02206)
0e3136
+                     "no client certs found for SSL proxy");
0e3136
+        return APR_SUCCESS;
0e3136
+    }
0e3136
+
0e3136
     ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s, APLOGNO(02207)
0e3136
                  "loaded %d client certs for SSL proxy",
0e3136
                  ncerts);
0e3136
     pkp->certs = sk;
0e3136
 
0e3136
-
0e3136
-    if (!pkp->ca_cert_file || !store) {
0e3136
+    /* If any chain certs are configured, build the ->ca_certs chains
0e3136
+     * corresponding to the loaded keypairs. */
0e3136
+    if (!pkp->ca_cert_file && !addl_chain) {
0e3136
         return APR_SUCCESS;
0e3136
     }
0e3136