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