|
|
85cb4d |
diff --git a/modules/ssl/ssl_engine_init.c b/modules/ssl/ssl_engine_init.c
|
|
|
85cb4d |
index 8b6c34f..3587fb5 100644
|
|
|
85cb4d |
--- a/modules/ssl/ssl_engine_init.c
|
|
|
85cb4d |
+++ b/modules/ssl/ssl_engine_init.c
|
|
|
85cb4d |
@@ -1609,6 +1609,10 @@ static apr_status_t ssl_init_proxy_certs(server_rec *s,
|
|
|
85cb4d |
STACK_OF(X509) *chain;
|
|
|
85cb4d |
X509_STORE_CTX *sctx;
|
|
|
85cb4d |
X509_STORE *store = SSL_CTX_get_cert_store(mctx->ssl_ctx);
|
|
|
85cb4d |
+ int addl_chain = 0; /* non-zero if additional chain certs were
|
|
|
85cb4d |
+ * added to store */
|
|
|
85cb4d |
+
|
|
|
85cb4d |
+ ap_assert(store != NULL); /* safe to assume always non-NULL? */
|
|
|
85cb4d |
|
|
|
85cb4d |
#if OPENSSL_VERSION_NUMBER >= 0x1010100fL
|
|
|
85cb4d |
/* For OpenSSL >=1.1.1, turn on client cert support which is
|
|
|
85cb4d |
@@ -1653,20 +1657,28 @@ static apr_status_t ssl_init_proxy_certs(server_rec *s,
|
|
|
85cb4d |
}
|
|
|
85cb4d |
}
|
|
|
85cb4d |
|
|
|
85cb4d |
- if ((ncerts = sk_X509_INFO_num(sk)) <= 0) {
|
|
|
85cb4d |
- sk_X509_INFO_free(sk);
|
|
|
85cb4d |
- ap_log_error(APLOG_MARK, APLOG_WARNING, 0, s, APLOGNO(02206)
|
|
|
85cb4d |
- "no client certs found for SSL proxy");
|
|
|
85cb4d |
- return APR_SUCCESS;
|
|
|
85cb4d |
- }
|
|
|
85cb4d |
-
|
|
|
85cb4d |
/* Check that all client certs have got certificates and private
|
|
|
85cb4d |
- * keys. */
|
|
|
85cb4d |
- for (n = 0; n < ncerts; n++) {
|
|
|
85cb4d |
+ * keys. Note the number of certs in the stack may decrease
|
|
|
85cb4d |
+ * during the loop. */
|
|
|
85cb4d |
+ for (n = 0; n < sk_X509_INFO_num(sk); n++) {
|
|
|
85cb4d |
X509_INFO *inf = sk_X509_INFO_value(sk, n);
|
|
|
85cb4d |
+ int has_privkey = inf->x_pkey && inf->x_pkey->dec_pkey;
|
|
|
85cb4d |
+
|
|
|
85cb4d |
+ /* For a lone certificate in the file, trust it as a
|
|
|
85cb4d |
+ * CA/intermediate certificate. */
|
|
|
85cb4d |
+ if (inf->x509 && !has_privkey && !inf->enc_data) {
|
|
|
85cb4d |
+ ssl_log_xerror(SSLLOG_MARK, APLOG_DEBUG, 0, ptemp, s, inf->x509,
|
|
|
85cb4d |
+ APLOGNO(10261) "Trusting non-leaf certificate");
|
|
|
85cb4d |
+ X509_STORE_add_cert(store, inf->x509); /* increments inf->x509 */
|
|
|
85cb4d |
+ /* Delete from the stack and iterate again. */
|
|
|
85cb4d |
+ X509_INFO_free(inf);
|
|
|
85cb4d |
+ sk_X509_INFO_delete(sk, n);
|
|
|
85cb4d |
+ n--;
|
|
|
85cb4d |
+ addl_chain = 1;
|
|
|
85cb4d |
+ continue;
|
|
|
85cb4d |
+ }
|
|
|
85cb4d |
|
|
|
85cb4d |
- if (!inf->x509 || !inf->x_pkey || !inf->x_pkey->dec_pkey ||
|
|
|
85cb4d |
- inf->enc_data) {
|
|
|
85cb4d |
+ if (!has_privkey || inf->enc_data) {
|
|
|
85cb4d |
sk_X509_INFO_free(sk);
|
|
|
85cb4d |
ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, s, APLOGNO(02252)
|
|
|
85cb4d |
"incomplete client cert configured for SSL proxy "
|
|
|
85cb4d |
@@ -1683,13 +1695,21 @@ static apr_status_t ssl_init_proxy_certs(server_rec *s,
|
|
|
85cb4d |
}
|
|
|
85cb4d |
}
|
|
|
85cb4d |
|
|
|
85cb4d |
+ if ((ncerts = sk_X509_INFO_num(sk)) <= 0) {
|
|
|
85cb4d |
+ sk_X509_INFO_free(sk);
|
|
|
85cb4d |
+ ap_log_error(APLOG_MARK, APLOG_WARNING, 0, s, APLOGNO(02206)
|
|
|
85cb4d |
+ "no client certs found for SSL proxy");
|
|
|
85cb4d |
+ return APR_SUCCESS;
|
|
|
85cb4d |
+ }
|
|
|
85cb4d |
+
|
|
|
85cb4d |
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s, APLOGNO(02207)
|
|
|
85cb4d |
"loaded %d client certs for SSL proxy",
|
|
|
85cb4d |
ncerts);
|
|
|
85cb4d |
pkp->certs = sk;
|
|
|
85cb4d |
|
|
|
85cb4d |
-
|
|
|
85cb4d |
- if (!pkp->ca_cert_file || !store) {
|
|
|
85cb4d |
+ /* If any chain certs are configured, build the ->ca_certs chains
|
|
|
85cb4d |
+ * corresponding to the loaded keypairs. */
|
|
|
85cb4d |
+ if (!pkp->ca_cert_file && !addl_chain) {
|
|
|
85cb4d |
return APR_SUCCESS;
|
|
|
85cb4d |
}
|
|
|
85cb4d |
|
|
|
85cb4d |
diff --git a/modules/ssl/ssl_private.h b/modules/ssl/ssl_private.h
|
|
|
85cb4d |
index 2a08d1c..8055200 100644
|
|
|
85cb4d |
--- a/modules/ssl/ssl_private.h
|
|
|
85cb4d |
+++ b/modules/ssl/ssl_private.h
|
|
|
85cb4d |
@@ -655,10 +655,13 @@ typedef struct {
|
|
|
85cb4d |
const char *cert_file;
|
|
|
85cb4d |
const char *cert_path;
|
|
|
85cb4d |
const char *ca_cert_file;
|
|
|
85cb4d |
- STACK_OF(X509_INFO) *certs; /* Contains End Entity certs */
|
|
|
85cb4d |
- STACK_OF(X509) **ca_certs; /* Contains ONLY chain certs for
|
|
|
85cb4d |
- * each item in certs.
|
|
|
85cb4d |
- * (ptr to array of ptrs) */
|
|
|
85cb4d |
+ /* certs is a stack of configured cert, key pairs. */
|
|
|
85cb4d |
+ STACK_OF(X509_INFO) *certs;
|
|
|
85cb4d |
+ /* ca_certs contains ONLY chain certs for each item in certs.
|
|
|
85cb4d |
+ * ca_certs[n] is a pointer to the (STACK_OF(X509) *) stack which
|
|
|
85cb4d |
+ * holds the cert chain for the 'n'th cert in the certs stack, or
|
|
|
85cb4d |
+ * NULL if no chain is configured. */
|
|
|
85cb4d |
+ STACK_OF(X509) **ca_certs;
|
|
|
85cb4d |
} modssl_pk_proxy_t;
|
|
|
85cb4d |
|
|
|
85cb4d |
/** stuff related to authentication that can also be per-dir */
|