Merge ~sergiodj/ubuntu/+source/apache2:openssl-3-support into ubuntu/+source/apache2:ubuntu/devel

Proposed by Sergio Durigan Junior
Status: Merged
Merge reported by: Sergio Durigan Junior
Merged at revision: 7564cdd51e8656e7c8559291298c94e758bbc4f3
Proposed branch: ~sergiodj/ubuntu/+source/apache2:openssl-3-support
Merge into: ubuntu/+source/apache2:ubuntu/devel
Diff against target: 976 lines (+900/-0)
12 files modified
debian/changelog (+8/-0)
debian/patches/series (+10/-0)
debian/patches/support-openssl3-001.patch (+88/-0)
debian/patches/support-openssl3-002.patch (+345/-0)
debian/patches/support-openssl3-003.patch (+48/-0)
debian/patches/support-openssl3-004.patch (+56/-0)
debian/patches/support-openssl3-005.patch (+121/-0)
debian/patches/support-openssl3-006.patch (+33/-0)
debian/patches/support-openssl3-007.patch (+72/-0)
debian/patches/support-openssl3-008.patch (+29/-0)
debian/patches/support-openssl3-009.patch (+36/-0)
debian/patches/support-openssl3-010.patch (+54/-0)
Reviewer Review Type Date Requested Status
Bryce Harrington (community) Approve
Canonical Server packageset reviewers Pending
Review via email: mp+412548@code.launchpad.net

Description of the change

This MP is an attempt to fix apache2's mod-ssl's failures that happen when one starts apache2 with OpenSSL 3 installed.

As I said during our standup a few times, these patches are part of an upstream PR that is still open, so I was monitoring the situation to see what upstream would decide. There is a possible regression/user-visible change that was detected during the tests performed by upstream (in Fedora):

===
With r1890067 (9eb262f) enabling the OpenSSL auto-DH-parameter selection overrides user-supplied DH parameters which are now ignored. This is not necessary for OpenSSL 1.1 (which that patch affects) and is only removing a "deprecated" function so not strictly necessary for 3.0 either. Need to ponder this one.
===

There was also a problem with one of the functions exported by OpenSSL 3's and used by mod_ssl, which has been reported and fixed by OpenSSL upstream:

https://github.com/openssl/openssl/issues/15946

I checked and the fix is present in our copy of OpenSSL, so we're fine in this regard.

Either way, I think it should be safe enough for us to backport the patches from the upstream PR so that we have an apache2 that builds and works fine with mod_ssl + OpenSSL 3. I'm also subscribed to the PR, so if there are any changes there it should be pretty quick to bring them to Ubuntu.

For this change, I created a bileto ticket here:

https://bileto.ubuntu.com/#/ticket/4726

with a corresponding PPA here:

https://launchpad.net/~ci-train-ppa-service/+archive/ubuntu/4726/+packages

autopkgtest is back to normal:

autopkgtest [17:08:19]: @@@@@@@@@@@@@@@@@@@@ summary
run-test-suite PASS
duplicate-module-load PASS
htcacheclean PASS
default-mods PASS
ssl-passphrase PASS
check-http2 PASS
chroot PASS

It's important to mention that bileto also ran autopkgtest against apache2 and its dependencies; you will see a bunch of results here:

https://autopkgtest.ubuntu.com/results/autopkgtest-jammy-ci-train-ppa-service-4726/?format=plain

The problem is that -proposed wasn't enabled when running the tests, which means that they will be listed as failures. I didn't know how to retrigger them automatically with '&all-proposed=1', so I didn't.

All in all, I think the pros outweigh the cons here and I believe it's worth backporting these patches in order to unblock OpenSSL 3, squid and possibly other dependencies in -proposed.

To post a comment you must log in.
Revision history for this message
Bryce Harrington (bryce) wrote :

Thanks for tackling this, looks like you've researched the situation quite thoroughly. I've verified the builds all look good in the PPA, and it builds fine for me locally as well. The autopkgtest failures (https://bileto.ubuntu.com/excuses/4726/jammy.html) surprised me, but I can believe that it just needs -proposed enabled.

I am planning on tackling the merge for apache2 at some point here, so it would be great to get this MP landed, and thus agree the pros outweigh the cons. When I do get to the merge, that will be an additional checkpoint where we can see where things sit upstream and to make any necessary corrections, and in the immediate term this will help with the openssl 3.0 transition.

LGTM, +1

review: Approve
Revision history for this message
Bryce Harrington (bryce) wrote :

(Sorry, seems Launchpad auto-added me to the canonical-server slot; if possible please re-add that as I seem to not be able to do that.)

Revision history for this message
Sergio Durigan Junior (sergiodj) wrote :

On Tuesday, November 30 2021, Bryce Harrington wrote:

> Thanks for tackling this, looks like you've researched the situation
> quite thoroughly. I've verified the builds all look good in the PPA,
> and it builds fine for me locally as well. The autopkgtest failures
> (https://bileto.ubuntu.com/excuses/4726/jammy.html) surprised me, but
> I can believe that it just needs -proposed enabled.

Thanks for the review, Bryce.

Yeah, the autopkgtest failures are happening because they're not running
against -proposed, which triggers a failure when trying to install
openssl3 into the testbed. I'm not expecting these tests to fail when
we run them with the right openssl trigger.

> I am planning on tackling the merge for apache2 at some point here, so
> it would be great to get this MP landed, and thus agree the pros
> outweigh the cons. When I do get to the merge, that will be an
> additional checkpoint where we can see where things sit upstream and
> to make any necessary corrections, and in the immediate term this will
> help with the openssl 3.0 transition.

Yeah. I don't know when upstream plans to merge that PR, nor when they
intend to release a new 2.4.x version with the fix included, so I'm not
expecting us to be able to get this change through upstream and drop the
delta. We may need to revisit these patches when we merge apache2 and
check if upstream has fixed/changed something in them; I will leave a
message in the apache2 merge bug as a reminder.

Uploaded:

$ dput apache2_2.4.48-3.1ubuntu4_source.changes
Trying to upload package to ubuntu
Checking signature on .changes
gpg: /home/sergio/work/apache2/apache2_2.4.48-3.1ubuntu4_source.changes: Valid signature from 106DA1C8C3CBBF14
Checking signature on .dsc
gpg: /home/sergio/work/apache2/apache2_2.4.48-3.1ubuntu4.dsc: Valid signature from 106DA1C8C3CBBF14
Uploading to ubuntu (via ftp to upload.ubuntu.com):
  Uploading apache2_2.4.48-3.1ubuntu4.dsc: done.
  Uploading apache2_2.4.48-3.1ubuntu4.debian.tar.xz: done.
  Uploading apache2_2.4.48-3.1ubuntu4_source.buildinfo: done.
  Uploading apache2_2.4.48-3.1ubuntu4_source.changes: done.
Successfully uploaded packages.

Thanks,

--
Sergio
GPG key ID: E92F D0B3 6B14 F1F4 D8E0 EB2F 106D A1C8 C3CB BF14

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/debian/changelog b/debian/changelog
2index 0dbb7c5..1aefacb 100644
3--- a/debian/changelog
4+++ b/debian/changelog
5@@ -1,3 +1,11 @@
6+apache2 (2.4.48-3.1ubuntu4) jammy; urgency=medium
7+
8+ * d/p/support-openssl3-*.patch: Backport various patches from
9+ https://github.com/apache/httpd/pull/258 in order to fix mod_ssl's
10+ failure to load when using OpenSSL 3. (LP: #1951476)
11+
12+ -- Sergio Durigan Junior <sergio.durigan@canonical.com> Fri, 26 Nov 2021 16:07:56 -0500
13+
14 apache2 (2.4.48-3.1ubuntu3) impish; urgency=medium
15
16 * SECURITY REGRESSION: Issues in UDS URIs (LP: #1945311)
17diff --git a/debian/patches/series b/debian/patches/series
18index 149e28d..0b07ccb 100644
19--- a/debian/patches/series
20+++ b/debian/patches/series
21@@ -19,3 +19,13 @@ CVE-2021-40438.patch
22 CVE-2021-33193.patch
23 CVE-2021-40438-2.patch
24 CVE-2021-40438-3.patch
25+support-openssl3-001.patch
26+support-openssl3-002.patch
27+support-openssl3-003.patch
28+support-openssl3-004.patch
29+support-openssl3-005.patch
30+support-openssl3-006.patch
31+support-openssl3-007.patch
32+support-openssl3-008.patch
33+support-openssl3-009.patch
34+support-openssl3-010.patch
35diff --git a/debian/patches/support-openssl3-001.patch b/debian/patches/support-openssl3-001.patch
36new file mode 100644
37index 0000000..d7d386d
38--- /dev/null
39+++ b/debian/patches/support-openssl3-001.patch
40@@ -0,0 +1,88 @@
41+From: Joe Orton <jorton@redhat.com>
42+Date: Mon, 26 Jul 2021 12:23:24 +0100
43+Subject: add some log messages and AP_DEBUG_ASSERTs for functions that should
44+ never be called
45+
46+Submitted by: sf
47+
48+
49+Forwarded: yes, https://github.com/apache/httpd/pull/258
50+Bug-Ubuntu: https://bugs.launchpad.net/ubuntu/+source/apache2/+bug/1951476
51+---
52+ modules/ssl/ssl_engine_io.c | 28 ++++++++++++++++++++++++++++
53+ 1 file changed, 28 insertions(+)
54+
55+diff --git a/modules/ssl/ssl_engine_io.c b/modules/ssl/ssl_engine_io.c
56+index cabf753..ed9db54 100644
57+--- a/modules/ssl/ssl_engine_io.c
58++++ b/modules/ssl/ssl_engine_io.c
59+@@ -194,6 +194,10 @@ static int bio_filter_destroy(BIO *bio)
60+ static int bio_filter_out_read(BIO *bio, char *out, int outl)
61+ {
62+ /* this is never called */
63++ bio_filter_out_ctx_t *outctx = (bio_filter_out_ctx_t *)(bio->ptr);
64++ ap_log_cerror(APLOG_MARK, APLOG_TRACE1, 0, outctx->c,
65++ "BUG: %s() should not be called", "bio_filter_out_read");
66++ AP_DEBUG_ASSERT(0);
67+ return -1;
68+ }
69+
70+@@ -293,12 +297,20 @@ static long bio_filter_out_ctrl(BIO *bio, int cmd, long num, void *ptr)
71+ static int bio_filter_out_gets(BIO *bio, char *buf, int size)
72+ {
73+ /* this is never called */
74++ bio_filter_out_ctx_t *outctx = (bio_filter_out_ctx_t *)(bio->ptr);
75++ ap_log_cerror(APLOG_MARK, APLOG_TRACE1, 0, outctx->c,
76++ "BUG: %s() should not be called", "bio_filter_out_gets");
77++ AP_DEBUG_ASSERT(0);
78+ return -1;
79+ }
80+
81+ static int bio_filter_out_puts(BIO *bio, const char *str)
82+ {
83+ /* this is never called */
84++ bio_filter_out_ctx_t *outctx = (bio_filter_out_ctx_t *)(bio->ptr);
85++ ap_log_cerror(APLOG_MARK, APLOG_TRACE1, 0, outctx->c,
86++ "BUG: %s() should not be called", "bio_filter_out_puts");
87++ AP_DEBUG_ASSERT(0);
88+ return -1;
89+ }
90+
91+@@ -533,21 +545,37 @@ static int bio_filter_in_read(BIO *bio, char *in, int inlen)
92+
93+ static int bio_filter_in_write(BIO *bio, const char *in, int inl)
94+ {
95++ bio_filter_in_ctx_t *inctx = (bio_filter_in_ctx_t *)(bio->ptr);
96++ ap_log_cerror(APLOG_MARK, APLOG_TRACE1, 0, inctx->f->c,
97++ "BUG: %s() should not be called", "bio_filter_in_write");
98++ AP_DEBUG_ASSERT(0);
99+ return -1;
100+ }
101+
102+ static int bio_filter_in_puts(BIO *bio, const char *str)
103+ {
104++ bio_filter_in_ctx_t *inctx = (bio_filter_in_ctx_t *)(bio->ptr);
105++ ap_log_cerror(APLOG_MARK, APLOG_TRACE1, 0, inctx->f->c,
106++ "BUG: %s() should not be called", "bio_filter_in_puts");
107++ AP_DEBUG_ASSERT(0);
108+ return -1;
109+ }
110+
111+ static int bio_filter_in_gets(BIO *bio, char *buf, int size)
112+ {
113++ bio_filter_in_ctx_t *inctx = (bio_filter_in_ctx_t *)(bio->ptr);
114++ ap_log_cerror(APLOG_MARK, APLOG_TRACE1, 0, inctx->f->c,
115++ "BUG: %s() should not be called", "bio_filter_in_gets");
116++ AP_DEBUG_ASSERT(0);
117+ return -1;
118+ }
119+
120+ static long bio_filter_in_ctrl(BIO *bio, int cmd, long num, void *ptr)
121+ {
122++ bio_filter_in_ctx_t *inctx = (bio_filter_in_ctx_t *)(bio->ptr);
123++ ap_log_cerror(APLOG_MARK, APLOG_TRACE1, 0, inctx->f->c,
124++ "BUG: %s() should not be called", "bio_filter_in_ctrl");
125++ AP_DEBUG_ASSERT(0);
126+ return -1;
127+ }
128+
129diff --git a/debian/patches/support-openssl3-002.patch b/debian/patches/support-openssl3-002.patch
130new file mode 100644
131index 0000000..3a56106
132--- /dev/null
133+++ b/debian/patches/support-openssl3-002.patch
134@@ -0,0 +1,345 @@
135+From: Joe Orton <jorton@redhat.com>
136+Date: Mon, 26 Jul 2021 12:24:24 +0100
137+Subject: mod_ssl: add compatibility with OpenSSL 3.0.0
138+
139+Wrappers around deprecated API:
140+* X509_STORE_load_locations() => modssl_X509_STORE_load_locations(),
141+* CTX_load_verify_locations() => modssl_CTX_load_verify_locations(),
142+* ERR_peek_error_line_data() => modssl_ERR_peek_error_data(),
143+* DH_bits(dh) => BN_num_bits(DH_get0_p(dh)).
144+
145+Provide a compatible version of ssl_callback_SessionTicket() which does not
146+use the deprecated HMAC_CTX and HMAC_Init_ex(), replaced by EVP_MAC_CTX and
147+EVP_MAC_CTX_set_params() respectively. This requires adapting struct
148+modssl_ticket_key_t to replace hmac_secret[] with OSSL_PARAM mac_params[],
149+created once at load time still.
150+The callback is registered by SSL_CTX_set_tlsext_ticket_key_evp_cb() instead
151+of SSL_CTX_set_tlsext_ticket_key_cb().
152+
153+Since BIO_eof() may now be called openssl-3 state machine, the never-called
154+assertion in bio_filter_in_ctrl() does not hold anymore, and we have to
155+handle BIO_CTRL_EOF. For any other cmd, we continue to AP_DEBUG_ASSERT(0) and
156+log an error, yet the return value is changed from -1 to 0 which is the usual
157+unhandled value.
158+
159+Note that OpenSSL 3.0.0 is still in alpha stage as of now, the API shouldn't
160+change though, neither breakage to 1.x.x API.
161+
162+Submitted by: ylavic
163+
164+
165+Forwarded: yes, https://github.com/apache/httpd/pull/258
166+Bug-Ubuntu: https://bugs.launchpad.net/ubuntu/+source/apache2/+bug/1951476
167+---
168+ modules/ssl/ssl_engine_init.c | 76 ++++++++++++++++++++++++++++++++---------
169+ modules/ssl/ssl_engine_io.c | 17 ++++++---
170+ modules/ssl/ssl_engine_kernel.c | 22 ++++++++++--
171+ modules/ssl/ssl_engine_log.c | 12 ++++++-
172+ modules/ssl/ssl_private.h | 19 +++++++++--
173+ 5 files changed, 120 insertions(+), 26 deletions(-)
174+
175+diff --git a/modules/ssl/ssl_engine_init.c b/modules/ssl/ssl_engine_init.c
176+index 4da24ed..eb41e7f 100644
177+--- a/modules/ssl/ssl_engine_init.c
178++++ b/modules/ssl/ssl_engine_init.c
179+@@ -843,6 +843,23 @@ static void ssl_init_ctx_callbacks(server_rec *s,
180+ #endif
181+ }
182+
183++static APR_INLINE
184++int modssl_CTX_load_verify_locations(SSL_CTX *ctx,
185++ const char *file,
186++ const char *path)
187++{
188++#if OPENSSL_VERSION_NUMBER < 0x30000000L
189++ if (!SSL_CTX_load_verify_locations(ctx, file, path))
190++ return 0;
191++#else
192++ if (file && !SSL_CTX_load_verify_file(ctx, file))
193++ return 0;
194++ if (path && !SSL_CTX_load_verify_dir(ctx, path))
195++ return 0;
196++#endif
197++ return 1;
198++}
199++
200+ static apr_status_t ssl_init_ctx_verify(server_rec *s,
201+ apr_pool_t *p,
202+ apr_pool_t *ptemp,
203+@@ -883,10 +900,8 @@ static apr_status_t ssl_init_ctx_verify(server_rec *s,
204+ ap_log_error(APLOG_MARK, APLOG_TRACE1, 0, s,
205+ "Configuring client authentication");
206+
207+- if (!SSL_CTX_load_verify_locations(ctx,
208+- mctx->auth.ca_cert_file,
209+- mctx->auth.ca_cert_path))
210+- {
211++ if (!modssl_CTX_load_verify_locations(ctx, mctx->auth.ca_cert_file,
212++ mctx->auth.ca_cert_path)) {
213+ ap_log_error(APLOG_MARK, APLOG_EMERG, 0, s, APLOGNO(01895)
214+ "Unable to configure verify locations "
215+ "for client authentication");
216+@@ -971,6 +986,23 @@ static apr_status_t ssl_init_ctx_cipher_suite(server_rec *s,
217+ return APR_SUCCESS;
218+ }
219+
220++static APR_INLINE
221++int modssl_X509_STORE_load_locations(X509_STORE *store,
222++ const char *file,
223++ const char *path)
224++{
225++#if OPENSSL_VERSION_NUMBER < 0x30000000L
226++ if (!X509_STORE_load_locations(store, file, path))
227++ return 0;
228++#else
229++ if (file && !X509_STORE_load_file(store, file))
230++ return 0;
231++ if (path && !X509_STORE_load_path(store, path))
232++ return 0;
233++#endif
234++ return 1;
235++}
236++
237+ static apr_status_t ssl_init_ctx_crl(server_rec *s,
238+ apr_pool_t *p,
239+ apr_pool_t *ptemp,
240+@@ -1009,8 +1041,8 @@ static apr_status_t ssl_init_ctx_crl(server_rec *s,
241+ ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s, APLOGNO(01900)
242+ "Configuring certificate revocation facility");
243+
244+- if (!store || !X509_STORE_load_locations(store, mctx->crl_file,
245+- mctx->crl_path)) {
246++ if (!store || modssl_X509_STORE_load_locations(store, mctx->crl_file,
247++ mctx->crl_path)) {
248+ ap_log_error(APLOG_MARK, APLOG_EMERG, 0, s, APLOGNO(01901)
249+ "Host %s: unable to configure X.509 CRL storage "
250+ "for certificate revocation", mctx->sc->vhost_id);
251+@@ -1249,7 +1281,7 @@ static apr_status_t ssl_init_server_certs(server_rec *s,
252+ const char *vhost_id = mctx->sc->vhost_id, *key_id, *certfile, *keyfile;
253+ int i;
254+ X509 *cert;
255+- DH *dhparams;
256++ DH *dh;
257+ #ifdef HAVE_ECC
258+ EC_GROUP *ecparams = NULL;
259+ int nid;
260+@@ -1434,12 +1466,12 @@ static apr_status_t ssl_init_server_certs(server_rec *s,
261+ */
262+ certfile = APR_ARRAY_IDX(mctx->pks->cert_files, 0, const char *);
263+ if (certfile && !modssl_is_engine_id(certfile)
264+- && (dhparams = ssl_dh_GetParamFromFile(certfile))) {
265+- SSL_CTX_set_tmp_dh(mctx->ssl_ctx, dhparams);
266++ && (dh = ssl_dh_GetParamFromFile(certfile))) {
267++ SSL_CTX_set_tmp_dh(mctx->ssl_ctx, dh);
268+ ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s, APLOGNO(02540)
269+ "Custom DH parameters (%d bits) for %s loaded from %s",
270+- DH_bits(dhparams), vhost_id, certfile);
271+- DH_free(dhparams);
272++ BN_num_bits(DH_get0_p(dh)), vhost_id, certfile);
273++ DH_free(dh);
274+ }
275+
276+ #ifdef HAVE_ECC
277+@@ -1490,6 +1522,7 @@ static apr_status_t ssl_init_ticket_key(server_rec *s,
278+ char buf[TLSEXT_TICKET_KEY_LEN];
279+ char *path;
280+ modssl_ticket_key_t *ticket_key = mctx->ticket_key;
281++ int res;
282+
283+ if (!ticket_key->file_path) {
284+ return APR_SUCCESS;
285+@@ -1517,11 +1550,22 @@ static apr_status_t ssl_init_ticket_key(server_rec *s,
286+ }
287+
288+ memcpy(ticket_key->key_name, buf, 16);
289+- memcpy(ticket_key->hmac_secret, buf + 16, 16);
290+ memcpy(ticket_key->aes_key, buf + 32, 16);
291+-
292+- if (!SSL_CTX_set_tlsext_ticket_key_cb(mctx->ssl_ctx,
293+- ssl_callback_SessionTicket)) {
294++#if OPENSSL_VERSION_NUMBER < 0x30000000L
295++ memcpy(ticket_key->hmac_secret, buf + 16, 16);
296++ res = SSL_CTX_set_tlsext_ticket_key_cb(mctx->ssl_ctx,
297++ ssl_callback_SessionTicket);
298++#else
299++ ticket_key->mac_params[0] =
300++ OSSL_PARAM_construct_octet_string(OSSL_MAC_PARAM_KEY, buf + 16, 16);
301++ ticket_key->mac_params[1] =
302++ OSSL_PARAM_construct_utf8_string(OSSL_MAC_PARAM_DIGEST, "sha256", 0);
303++ ticket_key->mac_params[2] =
304++ OSSL_PARAM_construct_end();
305++ res = SSL_CTX_set_tlsext_ticket_key_evp_cb(mctx->ssl_ctx,
306++ ssl_callback_SessionTicket);
307++#endif
308++ if (!res) {
309+ ap_log_error(APLOG_MARK, APLOG_EMERG, 0, s, APLOGNO(01913)
310+ "Unable to initialize TLS session ticket key callback "
311+ "(incompatible OpenSSL version?)");
312+@@ -1652,7 +1696,7 @@ static apr_status_t ssl_init_proxy_certs(server_rec *s,
313+ return ssl_die(s);
314+ }
315+
316+- X509_STORE_load_locations(store, pkp->ca_cert_file, NULL);
317++ modssl_X509_STORE_load_locations(store, pkp->ca_cert_file, NULL);
318+
319+ for (n = 0; n < ncerts; n++) {
320+ int i;
321+diff --git a/modules/ssl/ssl_engine_io.c b/modules/ssl/ssl_engine_io.c
322+index ed9db54..f7e5cfc 100644
323+--- a/modules/ssl/ssl_engine_io.c
324++++ b/modules/ssl/ssl_engine_io.c
325+@@ -572,11 +572,20 @@ static int bio_filter_in_gets(BIO *bio, char *buf, int size)
326+
327+ static long bio_filter_in_ctrl(BIO *bio, int cmd, long num, void *ptr)
328+ {
329+- bio_filter_in_ctx_t *inctx = (bio_filter_in_ctx_t *)(bio->ptr);
330++ bio_filter_in_ctx_t *inctx = (bio_filter_in_ctx_t *)BIO_get_data(bio);
331++ switch (cmd) {
332++#ifdef BIO_CTRL_EOF
333++ case BIO_CTRL_EOF:
334++ return inctx->rc == APR_EOF;
335++#endif
336++ default:
337++ break;
338++ }
339+ ap_log_cerror(APLOG_MARK, APLOG_TRACE1, 0, inctx->f->c,
340+- "BUG: %s() should not be called", "bio_filter_in_ctrl");
341++ "BUG: bio_filter_in_ctrl() should not be called with cmd=%i",
342++ cmd);
343+ AP_DEBUG_ASSERT(0);
344+- return -1;
345++ return 0;
346+ }
347+
348+ #if MODSSL_USE_OPENSSL_PRE_1_1_API
349+@@ -601,7 +610,7 @@ static BIO_METHOD bio_filter_in_method = {
350+ bio_filter_in_read,
351+ bio_filter_in_puts, /* puts is never called */
352+ bio_filter_in_gets, /* gets is never called */
353+- bio_filter_in_ctrl, /* ctrl is never called */
354++ bio_filter_in_ctrl, /* ctrl is called for EOF check */
355+ bio_filter_create,
356+ bio_filter_destroy,
357+ NULL
358+diff --git a/modules/ssl/ssl_engine_kernel.c b/modules/ssl/ssl_engine_kernel.c
359+index b99dcf1..f2d49ad 100644
360+--- a/modules/ssl/ssl_engine_kernel.c
361++++ b/modules/ssl/ssl_engine_kernel.c
362+@@ -2614,7 +2614,11 @@ int ssl_callback_SessionTicket(SSL *ssl,
363+ unsigned char *keyname,
364+ unsigned char *iv,
365+ EVP_CIPHER_CTX *cipher_ctx,
366+- HMAC_CTX *hctx,
367++#if OPENSSL_VERSION_NUMBER < 0x30000000L
368++ HMAC_CTX *hmac_ctx,
369++#else
370++ EVP_MAC_CTX *mac_ctx,
371++#endif
372+ int mode)
373+ {
374+ conn_rec *c = (conn_rec *)SSL_get_app_data(ssl);
375+@@ -2641,7 +2645,13 @@ int ssl_callback_SessionTicket(SSL *ssl,
376+ }
377+ EVP_EncryptInit_ex(cipher_ctx, EVP_aes_128_cbc(), NULL,
378+ ticket_key->aes_key, iv);
379+- HMAC_Init_ex(hctx, ticket_key->hmac_secret, 16, tlsext_tick_md(), NULL);
380++
381++#if OPENSSL_VERSION_NUMBER < 0x30000000L
382++ HMAC_Init_ex(hmac_ctx, ticket_key->hmac_secret, 16,
383++ tlsext_tick_md(), NULL);
384++#else
385++ EVP_MAC_CTX_set_params(mac_ctx, ticket_key->mac_params);
386++#endif
387+
388+ ap_log_cerror(APLOG_MARK, APLOG_DEBUG, 0, c, APLOGNO(02289)
389+ "TLS session ticket key for %s successfully set, "
390+@@ -2662,7 +2672,13 @@ int ssl_callback_SessionTicket(SSL *ssl,
391+
392+ EVP_DecryptInit_ex(cipher_ctx, EVP_aes_128_cbc(), NULL,
393+ ticket_key->aes_key, iv);
394+- HMAC_Init_ex(hctx, ticket_key->hmac_secret, 16, tlsext_tick_md(), NULL);
395++
396++#if OPENSSL_VERSION_NUMBER < 0x30000000L
397++ HMAC_Init_ex(hmac_ctx, ticket_key->hmac_secret, 16,
398++ tlsext_tick_md(), NULL);
399++#else
400++ EVP_MAC_CTX_set_params(mac_ctx, ticket_key->mac_params);
401++#endif
402+
403+ ap_log_cerror(APLOG_MARK, APLOG_DEBUG, 0, c, APLOGNO(02290)
404+ "TLS session ticket key for %s successfully set, "
405+diff --git a/modules/ssl/ssl_engine_log.c b/modules/ssl/ssl_engine_log.c
406+index 7dbbbdb..3b3ceac 100644
407+--- a/modules/ssl/ssl_engine_log.c
408++++ b/modules/ssl/ssl_engine_log.c
409+@@ -78,6 +78,16 @@ apr_status_t ssl_die(server_rec *s)
410+ return APR_EGENERAL;
411+ }
412+
413++static APR_INLINE
414++unsigned long modssl_ERR_peek_error_data(const char **data, int *flags)
415++{
416++#if OPENSSL_VERSION_NUMBER < 0x30000000L
417++ return ERR_peek_error_line_data(NULL, NULL, data, flags);
418++#else
419++ return ERR_peek_error_data(data, flags);
420++#endif
421++}
422++
423+ /*
424+ * Prints the SSL library error information.
425+ */
426+@@ -87,7 +97,7 @@ void ssl_log_ssl_error(const char *file, int line, int level, server_rec *s)
427+ const char *data;
428+ int flags;
429+
430+- while ((e = ERR_peek_error_line_data(NULL, NULL, &data, &flags))) {
431++ while ((e = modssl_ERR_peek_error_data(&data, &flags))) {
432+ const char *annotation;
433+ char err[256];
434+
435+diff --git a/modules/ssl/ssl_private.h b/modules/ssl/ssl_private.h
436+index a6fc751..71d658c 100644
437+--- a/modules/ssl/ssl_private.h
438++++ b/modules/ssl/ssl_private.h
439+@@ -89,6 +89,9 @@
440+ /* must be defined before including ssl.h */
441+ #define OPENSSL_NO_SSL_INTERN
442+ #endif
443++#if OPENSSL_VERSION_NUMBER >= 0x30000000
444++#include <openssl/core_names.h>
445++#endif
446+ #include <openssl/ssl.h>
447+ #include <openssl/err.h>
448+ #include <openssl/x509.h>
449+@@ -674,7 +677,11 @@ typedef struct {
450+ typedef struct {
451+ const char *file_path;
452+ unsigned char key_name[16];
453++#if OPENSSL_VERSION_NUMBER < 0x30000000L
454+ unsigned char hmac_secret[16];
455++#else
456++ OSSL_PARAM mac_params[3];
457++#endif
458+ unsigned char aes_key[16];
459+ } modssl_ticket_key_t;
460+ #endif
461+@@ -938,8 +945,16 @@ int ssl_callback_ServerNameIndication(SSL *, int *, modssl_ctx_t *);
462+ int ssl_callback_ClientHello(SSL *, int *, void *);
463+ #endif
464+ #ifdef HAVE_TLS_SESSION_TICKETS
465+-int ssl_callback_SessionTicket(SSL *, unsigned char *, unsigned char *,
466+- EVP_CIPHER_CTX *, HMAC_CTX *, int);
467++int ssl_callback_SessionTicket(SSL *ssl,
468++ unsigned char *keyname,
469++ unsigned char *iv,
470++ EVP_CIPHER_CTX *cipher_ctx,
471++#if OPENSSL_VERSION_NUMBER < 0x30000000L
472++ HMAC_CTX *hmac_ctx,
473++#else
474++ EVP_MAC_CTX *mac_ctx,
475++#endif
476++ int mode);
477+ #endif
478+
479+ #ifdef HAVE_TLS_ALPN
480diff --git a/debian/patches/support-openssl3-003.patch b/debian/patches/support-openssl3-003.patch
481new file mode 100644
482index 0000000..06906a9
483--- /dev/null
484+++ b/debian/patches/support-openssl3-003.patch
485@@ -0,0 +1,48 @@
486+From: Joe Orton <jorton@redhat.com>
487+Date: Mon, 26 Jul 2021 12:24:27 +0100
488+Subject: mod_ssl: follow up to r1876934: wrap DH_bits()
489+
490+DH_get0_p() seems to be undefined for some openssl versions, so it can't
491+be used to implement DH_bits() generically.
492+
493+Add new a modssl_DH_bits() wrapper to call DH_bits() for openssl < 3,
494+and BN_num_bits(DH_get0_p(dh)) otherwise.
495+
496+Submitted by: ylavic
497+
498+
499+Forwarded: yes, https://github.com/apache/httpd/pull/258
500+Bug-Ubuntu: https://bugs.launchpad.net/ubuntu/+source/apache2/+bug/1951476
501+---
502+ modules/ssl/ssl_engine_init.c | 11 ++++++++++-
503+ 1 file changed, 10 insertions(+), 1 deletion(-)
504+
505+diff --git a/modules/ssl/ssl_engine_init.c b/modules/ssl/ssl_engine_init.c
506+index eb41e7f..a2da916 100644
507+--- a/modules/ssl/ssl_engine_init.c
508++++ b/modules/ssl/ssl_engine_init.c
509+@@ -1271,6 +1271,15 @@ static int ssl_no_passwd_prompt_cb(char *buf, int size, int rwflag,
510+ return 0;
511+ }
512+
513++static APR_INLINE int modssl_DH_bits(DH *dh)
514++{
515++#if OPENSSL_VERSION_NUMBER < 0x30000000L
516++ return DH_bits(dh);
517++#else
518++ return BN_num_bits(DH_get0_p(dh));
519++#endif
520++}
521++
522+ static apr_status_t ssl_init_server_certs(server_rec *s,
523+ apr_pool_t *p,
524+ apr_pool_t *ptemp,
525+@@ -1470,7 +1479,7 @@ static apr_status_t ssl_init_server_certs(server_rec *s,
526+ SSL_CTX_set_tmp_dh(mctx->ssl_ctx, dh);
527+ ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s, APLOGNO(02540)
528+ "Custom DH parameters (%d bits) for %s loaded from %s",
529+- BN_num_bits(DH_get0_p(dh)), vhost_id, certfile);
530++ modssl_DH_bits(dh), vhost_id, certfile);
531+ DH_free(dh);
532+ }
533+
534diff --git a/debian/patches/support-openssl3-004.patch b/debian/patches/support-openssl3-004.patch
535new file mode 100644
536index 0000000..5566eaf
537--- /dev/null
538+++ b/debian/patches/support-openssl3-004.patch
539@@ -0,0 +1,56 @@
540+From: Joe Orton <jorton@redhat.com>
541+Date: Mon, 26 Jul 2021 12:24:46 +0100
542+Subject: * modules/ssl/ssl_engine_init.c (ssl_init_server_certs): Fix use of
543+ encrypted private keys with OpenSSL 3.0.
544+
545+* test/travis_run_linux.sh: For TEST_SSL, test loading encrypted
546+ private keys.
547+
548+Github: closes #{197}
549+
550+Submitted by: jorton
551+
552+
553+Forwarded: yes, https://github.com/apache/httpd/pull/258
554+Bug-Ubuntu: https://bugs.launchpad.net/ubuntu/+source/apache2/+bug/1951476
555+---
556+ modules/ssl/ssl_engine_init.c | 19 +++++++++++++++++--
557+ 1 file changed, 17 insertions(+), 2 deletions(-)
558+
559+diff --git a/modules/ssl/ssl_engine_init.c b/modules/ssl/ssl_engine_init.c
560+index a2da916..2f3a120 100644
561+--- a/modules/ssl/ssl_engine_init.c
562++++ b/modules/ssl/ssl_engine_init.c
563+@@ -1280,6 +1280,22 @@ static APR_INLINE int modssl_DH_bits(DH *dh)
564+ #endif
565+ }
566+
567++/* SSL_CTX_use_PrivateKey_file() can fail either because the private
568++ * key was encrypted, or due to a mismatch between an already-loaded
569++ * cert and the key - a common misconfiguration - from calling
570++ * X509_check_private_key(). This macro is passed the last error code
571++ * off the OpenSSL stack and evaluates to true only for the first
572++ * case. With OpenSSL < 3 the second case is identifiable by the
573++ * function code, but function codes are not used from 3.0. */
574++#if OPENSSL_VERSION_NUMBER < 0x30000000L
575++#define CHECK_PRIVKEY_ERROR(ec) (ERR_GET_FUNC(ec) != X509_F_X509_CHECK_PRIVATE_KEY)
576++#else
577++#define CHECK_PRIVKEY_ERROR(ec) (ERR_GET_LIB != ERR_LIB_X509 \
578++ || (ERR_GET_REASON(ec) != X509_R_KEY_TYPE_MISMATCH \
579++ && ERR_GET_REASON(ec) != X509_R_KEY_VALUES_MISMATCH \
580++ && ERR_GET_REASON(ec) != X509_R_UNKNOWN_KEY_TYPE))
581++#endif
582++
583+ static apr_status_t ssl_init_server_certs(server_rec *s,
584+ apr_pool_t *p,
585+ apr_pool_t *ptemp,
586+@@ -1385,8 +1401,7 @@ static apr_status_t ssl_init_server_certs(server_rec *s,
587+ }
588+ else if ((SSL_CTX_use_PrivateKey_file(mctx->ssl_ctx, keyfile,
589+ SSL_FILETYPE_PEM) < 1)
590+- && (ERR_GET_FUNC(ERR_peek_last_error())
591+- != X509_F_X509_CHECK_PRIVATE_KEY)) {
592++ && CHECK_PRIVKEY_ERROR(ERR_peek_last_error())) {
593+ ssl_asn1_t *asn1;
594+ const unsigned char *ptr;
595+
596diff --git a/debian/patches/support-openssl3-005.patch b/debian/patches/support-openssl3-005.patch
597new file mode 100644
598index 0000000..5c6ebe8
599--- /dev/null
600+++ b/debian/patches/support-openssl3-005.patch
601@@ -0,0 +1,121 @@
602+From: Joe Orton <jorton@redhat.com>
603+Date: Mon, 26 Jul 2021 12:25:36 +0100
604+Subject: mod_ssl: Switch to using OpenSSL's automatic internal DH parameter
605+ generation from OpenSSL 1.1.0 and later. The SSL_set_tmp_dh_callback() API
606+ is deprecated from OpenSSL 3.0 onwards. Should not be a user-visible change
607+ (except mod_ssl gets smaller).
608+
609+* modules/ssl/ssl_private.h,
610+ modules/ssl/ssl_engine_kernel.c,
611+ modules/ssl/ssl_engine_init.c (ssl_init_ctx_callbacks):
612+ Drop internal DH parameter generation and callback for OpenSSL 1.1+,
613+ use SSL_CTX_set_dh_auto(, 1) instead.
614+
615+Github: closes #188
616+Reviewed by: rpluem
617+
618+Submitted by: jorton
619+
620+
621+Forwarded: yes, https://github.com/apache/httpd/pull/258
622+Bug-Ubuntu: https://bugs.launchpad.net/ubuntu/+source/apache2/+bug/1951476
623+---
624+ modules/ssl/ssl_engine_init.c | 14 ++++++++++----
625+ modules/ssl/ssl_engine_kernel.c | 2 ++
626+ modules/ssl/ssl_private.h | 2 ++
627+ 3 files changed, 14 insertions(+), 4 deletions(-)
628+
629+diff --git a/modules/ssl/ssl_engine_init.c b/modules/ssl/ssl_engine_init.c
630+index 2f3a120..d0ef4ba 100644
631+--- a/modules/ssl/ssl_engine_init.c
632++++ b/modules/ssl/ssl_engine_init.c
633+@@ -91,7 +91,6 @@ static int DH_set0_pqg(DH *dh, BIGNUM *p, BIGNUM *q, BIGNUM *g)
634+
635+ return 1;
636+ }
637+-#endif
638+
639+ /*
640+ * Grab well-defined DH parameters from OpenSSL, see the BN_get_rfc*
641+@@ -171,6 +170,7 @@ DH *modssl_get_dh_params(unsigned keylen)
642+
643+ return NULL; /* impossible to reach. */
644+ }
645++#endif
646+
647+ static void ssl_add_version_components(apr_pool_t *ptemp, apr_pool_t *pconf,
648+ server_rec *s)
649+@@ -440,8 +440,9 @@ apr_status_t ssl_init_Module(apr_pool_t *p, apr_pool_t *plog,
650+
651+ modssl_init_app_data2_idx(); /* for modssl_get_app_data2() at request time */
652+
653++#if MODSSL_USE_OPENSSL_PRE_1_1_API
654+ init_dh_params();
655+-#if !MODSSL_USE_OPENSSL_PRE_1_1_API
656++#else
657+ init_bio_methods();
658+ #endif
659+
660+@@ -834,7 +835,11 @@ static void ssl_init_ctx_callbacks(server_rec *s,
661+ {
662+ SSL_CTX *ctx = mctx->ssl_ctx;
663+
664++#if MODSSL_USE_OPENSSL_PRE_1_1_API
665+ SSL_CTX_set_tmp_dh_callback(ctx, ssl_callback_TmpDH);
666++#else
667++ SSL_CTX_set_dh_auto(ctx, 1);
668++#endif
669+
670+ SSL_CTX_set_info_callback(ctx, ssl_callback_Info);
671+
672+@@ -2317,10 +2322,11 @@ apr_status_t ssl_init_ModuleKill(void *data)
673+
674+ }
675+
676+-#if !MODSSL_USE_OPENSSL_PRE_1_1_API
677++#if MODSSL_USE_OPENSSL_PRE_1_1_API
678++ free_dh_params();
679++#else
680+ free_bio_methods();
681+ #endif
682+- free_dh_params();
683+
684+ return APR_SUCCESS;
685+ }
686+diff --git a/modules/ssl/ssl_engine_kernel.c b/modules/ssl/ssl_engine_kernel.c
687+index f2d49ad..aced92d 100644
688+--- a/modules/ssl/ssl_engine_kernel.c
689++++ b/modules/ssl/ssl_engine_kernel.c
690+@@ -1685,6 +1685,7 @@ const authz_provider ssl_authz_provider_verify_client =
691+ ** _________________________________________________________________
692+ */
693+
694++#if MODSSL_USE_OPENSSL_PRE_1_1_API
695+ /*
696+ * Hand out standard DH parameters, based on the authentication strength
697+ */
698+@@ -1730,6 +1731,7 @@ DH *ssl_callback_TmpDH(SSL *ssl, int export, int keylen)
699+
700+ return modssl_get_dh_params(keylen);
701+ }
702++#endif
703+
704+ /*
705+ * This OpenSSL callback function is called when OpenSSL
706+diff --git a/modules/ssl/ssl_private.h b/modules/ssl/ssl_private.h
707+index 71d658c..b74d956 100644
708+--- a/modules/ssl/ssl_private.h
709++++ b/modules/ssl/ssl_private.h
710+@@ -1127,10 +1127,12 @@ void ssl_init_ocsp_certificates(server_rec *s, modssl_ctx_t *mctx);
711+
712+ #endif
713+
714++#if MODSSL_USE_OPENSSL_PRE_1_1_API
715+ /* Retrieve DH parameters for given key length. Return value should
716+ * be treated as unmutable, since it is stored in process-global
717+ * memory. */
718+ DH *modssl_get_dh_params(unsigned keylen);
719++#endif
720+
721+ /* Returns non-zero if the request was made over SSL/TLS. If sslconn
722+ * is non-NULL and the request is using SSL/TLS, sets *sslconn to the
723diff --git a/debian/patches/support-openssl3-006.patch b/debian/patches/support-openssl3-006.patch
724new file mode 100644
725index 0000000..33e0c1f
726--- /dev/null
727+++ b/debian/patches/support-openssl3-006.patch
728@@ -0,0 +1,33 @@
729+From: Joe Orton <jorton@redhat.com>
730+Date: Mon, 26 Jul 2021 12:29:32 +0100
731+Subject: fix build with LibreSSL [Yann Ylavic] Github issue #188
732+
733+Submitted by: gbechis
734+
735+
736+Forwarded: yes, https://github.com/apache/httpd/pull/258
737+Bug-Ubuntu: https://bugs.launchpad.net/ubuntu/+source/apache2/+bug/1951476
738+---
739+ modules/ssl/ssl_private.h | 5 ++---
740+ 1 file changed, 2 insertions(+), 3 deletions(-)
741+
742+diff --git a/modules/ssl/ssl_private.h b/modules/ssl/ssl_private.h
743+index b74d956..b091c58 100644
744+--- a/modules/ssl/ssl_private.h
745++++ b/modules/ssl/ssl_private.h
746+@@ -137,13 +137,12 @@
747+ SSL_CTX_ctrl(ctx, SSL_CTRL_SET_MIN_PROTO_VERSION, version, NULL)
748+ #define SSL_CTX_set_max_proto_version(ctx, version) \
749+ SSL_CTX_ctrl(ctx, SSL_CTRL_SET_MAX_PROTO_VERSION, version, NULL)
750+-#elif LIBRESSL_VERSION_NUMBER < 0x2070000f
751++#endif /* LIBRESSL_VERSION_NUMBER < 0x2060000f */
752+ /* LibreSSL before 2.7 declares OPENSSL_VERSION_NUMBER == 2.0 but does not
753+ * include most changes from OpenSSL >= 1.1 (new functions, macros,
754+ * deprecations, ...), so we have to work around this...
755+ */
756+-#define MODSSL_USE_OPENSSL_PRE_1_1_API (1)
757+-#endif /* LIBRESSL_VERSION_NUMBER < 0x2060000f */
758++#define MODSSL_USE_OPENSSL_PRE_1_1_API (LIBRESSL_VERSION_NUMBER < 0x2070000f)
759+ #else /* defined(LIBRESSL_VERSION_NUMBER) */
760+ #define MODSSL_USE_OPENSSL_PRE_1_1_API (OPENSSL_VERSION_NUMBER < 0x10100000L)
761+ #endif
762diff --git a/debian/patches/support-openssl3-007.patch b/debian/patches/support-openssl3-007.patch
763new file mode 100644
764index 0000000..6f760b8
765--- /dev/null
766+++ b/debian/patches/support-openssl3-007.patch
767@@ -0,0 +1,72 @@
768+From: Joe Orton <jorton@redhat.com>
769+Date: Mon, 26 Jul 2021 14:15:28 +0100
770+Subject: Support for OpenSSL 1.1.0: - BIO was made opaque after OpenSSL
771+ 1.1.0pre4.
772+
773+Submitted by: rjung
774+
775+
776+Forwarded: yes, https://github.com/apache/httpd/pull/258
777+Bug-Ubuntu: https://bugs.launchpad.net/ubuntu/+source/apache2/+bug/1951476
778+---
779+ modules/ssl/ssl_engine_io.c | 12 ++++++------
780+ 1 file changed, 6 insertions(+), 6 deletions(-)
781+
782+diff --git a/modules/ssl/ssl_engine_io.c b/modules/ssl/ssl_engine_io.c
783+index f7e5cfc..3db7077 100644
784+--- a/modules/ssl/ssl_engine_io.c
785++++ b/modules/ssl/ssl_engine_io.c
786+@@ -194,7 +194,7 @@ static int bio_filter_destroy(BIO *bio)
787+ static int bio_filter_out_read(BIO *bio, char *out, int outl)
788+ {
789+ /* this is never called */
790+- bio_filter_out_ctx_t *outctx = (bio_filter_out_ctx_t *)(bio->ptr);
791++ bio_filter_out_ctx_t *outctx = (bio_filter_out_ctx_t *)BIO_get_data(bio);
792+ ap_log_cerror(APLOG_MARK, APLOG_TRACE1, 0, outctx->c,
793+ "BUG: %s() should not be called", "bio_filter_out_read");
794+ AP_DEBUG_ASSERT(0);
795+@@ -297,7 +297,7 @@ static long bio_filter_out_ctrl(BIO *bio, int cmd, long num, void *ptr)
796+ static int bio_filter_out_gets(BIO *bio, char *buf, int size)
797+ {
798+ /* this is never called */
799+- bio_filter_out_ctx_t *outctx = (bio_filter_out_ctx_t *)(bio->ptr);
800++ bio_filter_out_ctx_t *outctx = (bio_filter_out_ctx_t *)BIO_get_data(bio);
801+ ap_log_cerror(APLOG_MARK, APLOG_TRACE1, 0, outctx->c,
802+ "BUG: %s() should not be called", "bio_filter_out_gets");
803+ AP_DEBUG_ASSERT(0);
804+@@ -307,7 +307,7 @@ static int bio_filter_out_gets(BIO *bio, char *buf, int size)
805+ static int bio_filter_out_puts(BIO *bio, const char *str)
806+ {
807+ /* this is never called */
808+- bio_filter_out_ctx_t *outctx = (bio_filter_out_ctx_t *)(bio->ptr);
809++ bio_filter_out_ctx_t *outctx = (bio_filter_out_ctx_t *)BIO_get_data(bio);
810+ ap_log_cerror(APLOG_MARK, APLOG_TRACE1, 0, outctx->c,
811+ "BUG: %s() should not be called", "bio_filter_out_puts");
812+ AP_DEBUG_ASSERT(0);
813+@@ -545,7 +545,7 @@ static int bio_filter_in_read(BIO *bio, char *in, int inlen)
814+
815+ static int bio_filter_in_write(BIO *bio, const char *in, int inl)
816+ {
817+- bio_filter_in_ctx_t *inctx = (bio_filter_in_ctx_t *)(bio->ptr);
818++ bio_filter_in_ctx_t *inctx = (bio_filter_in_ctx_t *)BIO_get_data(bio);
819+ ap_log_cerror(APLOG_MARK, APLOG_TRACE1, 0, inctx->f->c,
820+ "BUG: %s() should not be called", "bio_filter_in_write");
821+ AP_DEBUG_ASSERT(0);
822+@@ -554,7 +554,7 @@ static int bio_filter_in_write(BIO *bio, const char *in, int inl)
823+
824+ static int bio_filter_in_puts(BIO *bio, const char *str)
825+ {
826+- bio_filter_in_ctx_t *inctx = (bio_filter_in_ctx_t *)(bio->ptr);
827++ bio_filter_in_ctx_t *inctx = (bio_filter_in_ctx_t *)BIO_get_data(bio);
828+ ap_log_cerror(APLOG_MARK, APLOG_TRACE1, 0, inctx->f->c,
829+ "BUG: %s() should not be called", "bio_filter_in_puts");
830+ AP_DEBUG_ASSERT(0);
831+@@ -563,7 +563,7 @@ static int bio_filter_in_puts(BIO *bio, const char *str)
832+
833+ static int bio_filter_in_gets(BIO *bio, char *buf, int size)
834+ {
835+- bio_filter_in_ctx_t *inctx = (bio_filter_in_ctx_t *)(bio->ptr);
836++ bio_filter_in_ctx_t *inctx = (bio_filter_in_ctx_t *)BIO_get_data(bio);
837+ ap_log_cerror(APLOG_MARK, APLOG_TRACE1, 0, inctx->f->c,
838+ "BUG: %s() should not be called", "bio_filter_in_gets");
839+ AP_DEBUG_ASSERT(0);
840diff --git a/debian/patches/support-openssl3-008.patch b/debian/patches/support-openssl3-008.patch
841new file mode 100644
842index 0000000..d04497f
843--- /dev/null
844+++ b/debian/patches/support-openssl3-008.patch
845@@ -0,0 +1,29 @@
846+From: Joe Orton <jorton@redhat.com>
847+Date: Wed, 28 Jul 2021 12:28:59 +0100
848+Subject: mod_ssl: follow up to r1876934: fix
849+ !modssl_X509_STORE_load_locations() logic.
850+
851+Submitted by: ylavic
852+
853+
854+Forwarded: yes, https://github.com/apache/httpd/pull/258
855+Bug-Ubuntu: https://bugs.launchpad.net/ubuntu/+source/apache2/+bug/1951476
856+---
857+ modules/ssl/ssl_engine_init.c | 4 ++--
858+ 1 file changed, 2 insertions(+), 2 deletions(-)
859+
860+diff --git a/modules/ssl/ssl_engine_init.c b/modules/ssl/ssl_engine_init.c
861+index d0ef4ba..5d199cd 100644
862+--- a/modules/ssl/ssl_engine_init.c
863++++ b/modules/ssl/ssl_engine_init.c
864+@@ -1046,8 +1046,8 @@ static apr_status_t ssl_init_ctx_crl(server_rec *s,
865+ ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s, APLOGNO(01900)
866+ "Configuring certificate revocation facility");
867+
868+- if (!store || modssl_X509_STORE_load_locations(store, mctx->crl_file,
869+- mctx->crl_path)) {
870++ if (!store || !modssl_X509_STORE_load_locations(store, mctx->crl_file,
871++ mctx->crl_path)) {
872+ ap_log_error(APLOG_MARK, APLOG_EMERG, 0, s, APLOGNO(01901)
873+ "Host %s: unable to configure X.509 CRL storage "
874+ "for certificate revocation", mctx->sc->vhost_id);
875diff --git a/debian/patches/support-openssl3-009.patch b/debian/patches/support-openssl3-009.patch
876new file mode 100644
877index 0000000..01687e9
878--- /dev/null
879+++ b/debian/patches/support-openssl3-009.patch
880@@ -0,0 +1,36 @@
881+From: Joe Orton <jorton@redhat.com>
882+Date: Mon, 4 Oct 2021 14:26:49 +0100
883+Subject: * modules/ssl/ssl_engine_init.c (ssl_init_server_certs): For OpenSSL
884+ 1.1+,
885+ disable auto DH parameter selection if parameters have been manually
886+ configured. This fixes a regression in r1890067 after which manually
887+ configured parameters are ignored.
888+
889+Submitted by: jorton
890+
891+
892+Forwarded: yes, https://github.com/apache/httpd/pull/258
893+Bug-Ubuntu: https://bugs.launchpad.net/ubuntu/+source/apache2/+bug/1951476
894+---
895+ modules/ssl/ssl_engine_init.c | 7 +++++++
896+ 1 file changed, 7 insertions(+)
897+
898+diff --git a/modules/ssl/ssl_engine_init.c b/modules/ssl/ssl_engine_init.c
899+index 5d199cd..3986ba7 100644
900+--- a/modules/ssl/ssl_engine_init.c
901++++ b/modules/ssl/ssl_engine_init.c
902+@@ -1496,7 +1496,14 @@ static apr_status_t ssl_init_server_certs(server_rec *s,
903+ certfile = APR_ARRAY_IDX(mctx->pks->cert_files, 0, const char *);
904+ if (certfile && !modssl_is_engine_id(certfile)
905+ && (dh = ssl_dh_GetParamFromFile(certfile))) {
906++ /* ### This should be replaced with SSL_CTX_set0_tmp_dh_pkey()
907++ * for OpenSSL 3.0+. */
908+ SSL_CTX_set_tmp_dh(mctx->ssl_ctx, dh);
909++#if !MODSSL_USE_OPENSSL_PRE_1_1_API
910++ /* OpenSSL ignores manually configured DH params if automatic
911++ * selection if enabled, so disable auto selection here. */
912++ SSL_CTX_set_dh_auto(mctx->ssl_ctx, 0);
913++#endif
914+ ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s, APLOGNO(02540)
915+ "Custom DH parameters (%d bits) for %s loaded from %s",
916+ modssl_DH_bits(dh), vhost_id, certfile);
917diff --git a/debian/patches/support-openssl3-010.patch b/debian/patches/support-openssl3-010.patch
918new file mode 100644
919index 0000000..2791e96
920--- /dev/null
921+++ b/debian/patches/support-openssl3-010.patch
922@@ -0,0 +1,54 @@
923+From: Joe Orton <jorton@redhat.com>
924+Date: Tue, 12 Oct 2021 13:48:55 +0100
925+Subject: * modules/ssl/ssl_engine_init.c (ssl_init_ctx_callbacks,
926+ ssl_init_server_certs): Flip logic for enabling/disabling DH auto
927+ parameter selection for OpenSSL 1.1+ to be simpler and consistent with
928+ auto ECDH curve selection.
929+
930+
931+Forwarded: yes, https://github.com/apache/httpd/pull/258
932+Bug-Ubuntu: https://bugs.launchpad.net/ubuntu/+source/apache2/+bug/1951476
933+---
934+ modules/ssl/ssl_engine_init.c | 16 +++++++++-------
935+ 1 file changed, 9 insertions(+), 7 deletions(-)
936+
937+diff --git a/modules/ssl/ssl_engine_init.c b/modules/ssl/ssl_engine_init.c
938+index 3986ba7..f440a37 100644
939+--- a/modules/ssl/ssl_engine_init.c
940++++ b/modules/ssl/ssl_engine_init.c
941+@@ -836,9 +836,9 @@ static void ssl_init_ctx_callbacks(server_rec *s,
942+ SSL_CTX *ctx = mctx->ssl_ctx;
943+
944+ #if MODSSL_USE_OPENSSL_PRE_1_1_API
945++ /* Note that for OpenSSL>=1.1, auto selection is enabled via
946++ * SSL_CTX_set_dh_auto(,1) if no parameter is configured. */
947+ SSL_CTX_set_tmp_dh_callback(ctx, ssl_callback_TmpDH);
948+-#else
949+- SSL_CTX_set_dh_auto(ctx, 1);
950+ #endif
951+
952+ SSL_CTX_set_info_callback(ctx, ssl_callback_Info);
953+@@ -1499,16 +1499,18 @@ static apr_status_t ssl_init_server_certs(server_rec *s,
954+ /* ### This should be replaced with SSL_CTX_set0_tmp_dh_pkey()
955+ * for OpenSSL 3.0+. */
956+ SSL_CTX_set_tmp_dh(mctx->ssl_ctx, dh);
957+-#if !MODSSL_USE_OPENSSL_PRE_1_1_API
958+- /* OpenSSL ignores manually configured DH params if automatic
959+- * selection if enabled, so disable auto selection here. */
960+- SSL_CTX_set_dh_auto(mctx->ssl_ctx, 0);
961+-#endif
962+ ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s, APLOGNO(02540)
963+ "Custom DH parameters (%d bits) for %s loaded from %s",
964+ modssl_DH_bits(dh), vhost_id, certfile);
965+ DH_free(dh);
966+ }
967++#if !MODSSL_USE_OPENSSL_PRE_1_1_API
968++ else {
969++ /* If no parameter is manually configured, enable auto
970++ * selection. */
971++ SSL_CTX_set_dh_auto(mctx->ssl_ctx, 1);
972++ }
973++#endif
974+
975+ #ifdef HAVE_ECC
976+ /*

Subscribers

People subscribed via source and target branches