Skip to content

Commit c18e0e7

Browse files
committed
mod_ssl: Fix regression in PKCS#11 handling which should work without
... SSLCryptoDevice configured Submitted By: jorton, ylavic Reviewed By: jorton, ylavic, rpluem git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/branches/2.4.x@1922083 13f79535-47bb-0310-9956-ffa450edef68
1 parent dd54417 commit c18e0e7

File tree

2 files changed

+24
-13
lines changed

2 files changed

+24
-13
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*) mod_ssl: Restore support for loading PKCS#11 keys via ENGINE
2+
without "SSLCryptoDevice" configured. [Joe Orton]

modules/ssl/ssl_engine_pphrase.c

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -839,6 +839,9 @@ static apr_status_t modssl_engine_cleanup(void *engine)
839839
return APR_SUCCESS;
840840
}
841841

842+
/* Tries to load the key and optionally certificate via the ENGINE
843+
* API. Returns APR_ENOTIMPL if an ENGINE could not be identified
844+
* loaded from the key name. */
842845
static apr_status_t modssl_load_keypair_engine(server_rec *s, apr_pool_t *pconf,
843846
apr_pool_t *ptemp,
844847
const char *vhostid,
@@ -861,19 +864,19 @@ static apr_status_t modssl_load_keypair_engine(server_rec *s, apr_pool_t *pconf,
861864

862865
c = ap_strchr_c(keyid, ':');
863866
if (!c || c == keyid) {
864-
ap_log_error(APLOG_MARK, APLOG_EMERG, 0, s, APLOGNO(10131)
867+
ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, s, APLOGNO(10131)
865868
"Init: Unrecognized private key identifier `%s'",
866869
keyid);
867-
return ssl_die(s);
870+
return APR_ENOTIMPL;
868871
}
869872

870873
scheme = apr_pstrmemdup(ptemp, keyid, c - keyid);
871874
if (!(e = ENGINE_by_id(scheme))) {
872-
ap_log_error(APLOG_MARK, APLOG_EMERG, 0, s, APLOGNO(10132)
875+
ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, s, APLOGNO(10132)
873876
"Init: Failed to load engine for private key %s",
874877
keyid);
875-
ssl_log_ssl_error(SSLLOG_MARK, APLOG_EMERG, s);
876-
return ssl_die(s);
878+
ssl_log_ssl_error(SSLLOG_MARK, APLOG_NOTICE, s);
879+
return APR_ENOTIMPL;
877880
}
878881

879882
if (!ENGINE_init(e)) {
@@ -1029,15 +1032,21 @@ apr_status_t modssl_load_engine_keypair(server_rec *s,
10291032
X509 **pubkey, EVP_PKEY **privkey)
10301033
{
10311034
#if MODSSL_HAVE_ENGINE_API
1032-
SSLModConfigRec *mc = myModConfig(s);
1035+
apr_status_t rv;
1036+
1037+
rv = modssl_load_keypair_engine(s, pconf, ptemp,
1038+
vhostid, certid, keyid,
1039+
pubkey, privkey);
1040+
if (rv == APR_SUCCESS) {
1041+
return rv;
1042+
}
1043+
/* If STORE support is not present, all errors are fatal here; if
1044+
* STORE is present and the ENGINE could not be loaded, ignore the
1045+
* error and fall through to try loading via the STORE API. */
1046+
else if (!MODSSL_HAVE_OPENSSL_STORE || rv != APR_ENOTIMPL) {
1047+
return ssl_die(s);
1048+
}
10331049

1034-
/* For OpenSSL 3.x, use the STORE-based API if either ENGINE
1035-
* support was not present compile-time, or if it's built but
1036-
* SSLCryptoDevice is not configured. */
1037-
if (mc->szCryptoDevice)
1038-
return modssl_load_keypair_engine(s, pconf, ptemp,
1039-
vhostid, certid, keyid,
1040-
pubkey, privkey);
10411050
#endif
10421051
#if MODSSL_HAVE_OPENSSL_STORE
10431052
return modssl_load_keypair_store(s, ptemp, vhostid, certid, keyid,

0 commit comments

Comments
 (0)