]> git.pld-linux.org Git - packages/squid.git/blob - openssl3.patch
- upstream updates for openssl 3.0.0
[packages/squid.git] / openssl3.patch
1 From 2dcbe5cd4661e90030d1e9586f59d01c9c1e945a Mon Sep 17 00:00:00 2001
2 From: Amos Jeffries <amosjeffries@squid-cache.org>
3 Date: Thu, 23 Jul 2020 17:38:26 +1200
4 Subject: [PATCH 01/10] Update license disclaimer
5
6 OpenSSL 3.0 uses Apache License v2 which removes the SSLeay distribution restrictions.
7 ---
8  src/main.cc | 2 ++
9  1 file changed, 2 insertions(+)
10
11 diff --git a/src/main.cc b/src/main.cc
12 index 4576b761c54..4654df0be0a 100644
13 --- a/src/main.cc
14 +++ b/src/main.cc
15 @@ -672,7 +672,9 @@ mainHandleCommandLineOption(const int optId, const char *optValue)
16              printf("%s\n",SQUID_BUILD_INFO);
17  #if USE_OPENSSL
18          printf("\nThis binary uses %s. ", OpenSSL_version(OPENSSL_VERSION));
19 +#if OPENSSL_VERSION_MAJOR < 3
20          printf("For legal restrictions on distribution see https://www.openssl.org/source/license.html\n\n");
21 +#endif
22  #endif
23          printf( "configure options: %s\n", SQUID_CONFIGURE_OPTIONS);
24  
25
26 From 18628a4b53ed6ea1be91b26d201ef8a75e3b39de Mon Sep 17 00:00:00 2001
27 From: Amos Jeffries <amosjeffries@squid-cache.org>
28 Date: Thu, 23 Jul 2020 18:08:15 +1200
29 Subject: [PATCH 02/10] TODO Upgrade API calls verifying loaded DH params file
30
31 ---
32  src/security/ServerOptions.cc | 5 +++++
33  1 file changed, 5 insertions(+)
34
35 diff --git a/src/security/ServerOptions.cc b/src/security/ServerOptions.cc
36 index 2613c279f2c..dee22869a74 100644
37 --- a/src/security/ServerOptions.cc
38 +++ b/src/security/ServerOptions.cc
39 @@ -364,6 +364,10 @@ Security::ServerOptions::loadDhParams()
40          return;
41      }
42  
43 +#if OPENSSL_VERSION_MAJOR < 3
44 +    // DH_check() removed in OpenSSL 3.0.
45 +    // TODO: use the EVP API instead, which also works in OpenSSL 1.1.
46 +    // But it is not yet clear exactly how that API works for DH.
47      int codes;
48      if (DH_check(dhp, &codes) == 0) {
49          if (codes) {
50 @@ -372,6 +376,7 @@ Security::ServerOptions::loadDhParams()
51              dhp = nullptr;
52          }
53      }
54 +#endif
55  
56      parsedDhParams.resetWithoutLocking(dhp);
57  #endif
58
59 From 8de1d03adf5a001c9bf9784543e345b9a5e47804 Mon Sep 17 00:00:00 2001
60 From: Amos Jeffries <amosjeffries@squid-cache.org>
61 Date: Thu, 23 Jul 2020 18:51:20 +1200
62 Subject: [PATCH 03/10] Declaration of CRYPTO_EX_dup changed again in 3.0
63
64 ---
65  src/ssl/support.cc | 6 +++++-
66  1 file changed, 5 insertions(+), 1 deletion(-)
67
68 diff --git a/src/ssl/support.cc b/src/ssl/support.cc
69 index e33fad6adfc..c9d99e9a27e 100644
70 --- a/src/ssl/support.cc
71 +++ b/src/ssl/support.cc
72 @@ -559,7 +559,11 @@ Ssl::VerifyCallbackParameters::At(Security::Connection &sconn)
73  }
74  
75  // "dup" function for SSL_get_ex_new_index("cert_err_check")
76 -#if SQUID_USE_CONST_CRYPTO_EX_DATA_DUP
77 +#if OPENSSL_VERSION_MAJOR >= 3
78 +static int
79 +ssl_dupAclChecklist(CRYPTO_EX_DATA *, const CRYPTO_EX_DATA *, void **,
80 +                    int, long, void *)
81 +#elif SQUID_USE_CONST_CRYPTO_EX_DATA_DUP
82  static int
83  ssl_dupAclChecklist(CRYPTO_EX_DATA *, const CRYPTO_EX_DATA *, void *,
84                      int, long, void *)
85
86 From c194b7327ffd6f22a141b9031d8fb21f5f96596e Mon Sep 17 00:00:00 2001
87 From: Amos Jeffries <amosjeffries@squid-cache.org>
88 Date: Thu, 23 Jul 2020 21:02:36 +1200
89 Subject: [PATCH 04/10] Refactor Ssl::createSslPrivateKey()
90
91 * Use the OpenSSL 1.1+ EVP API for generating RSA keys.
92
93 * Make static since this is only used by the gadgets.cc code.
94 ---
95  src/ssl/gadgets.cc | 41 +++++++++++++++++------------------------
96  src/ssl/gadgets.h  |  8 +-------
97  2 files changed, 18 insertions(+), 31 deletions(-)
98
99 diff --git a/src/ssl/gadgets.cc b/src/ssl/gadgets.cc
100 index 36262e29ba0..c1e81c79291 100644
101 --- a/src/ssl/gadgets.cc
102 +++ b/src/ssl/gadgets.cc
103 @@ -9,35 +9,28 @@
104  #include "squid.h"
105  #include "ssl/gadgets.h"
106  
107 -EVP_PKEY * Ssl::createSslPrivateKey()
108 +static EVP_PKEY *
109 +CreateRsaPrivateKey()
110  {
111 -    Security::PrivateKeyPointer pkey(EVP_PKEY_new());
112 -
113 -    if (!pkey)
114 -        return NULL;
115 -
116 -    BIGNUM_Pointer bn(BN_new());
117 -    if (!bn)
118 -        return NULL;
119 -
120 -    if (!BN_set_word(bn.get(), RSA_F4))
121 -        return NULL;
122 -
123 -    Ssl::RSA_Pointer rsa(RSA_new());
124 +    Ssl::EVP_PKEY_CTX_Pointer rsa(EVP_PKEY_CTX_new_id(EVP_PKEY_RSA, nullptr));
125      if (!rsa)
126 -        return NULL;
127 +        return nullptr;
128  
129 -    int num = 2048; // Maybe use 4096 RSA keys, or better make it configurable?
130 -    if (!RSA_generate_key_ex(rsa.get(), num, bn.get(), NULL))
131 -        return NULL;
132 +    if (EVP_PKEY_keygen_init(rsa.get()) <= 0)
133 +        return nullptr;
134  
135 -    if (!rsa)
136 -        return NULL;
137 +    int num = 2048; // Maybe use 4096 RSA keys, or better make it configurable?
138 +    if (EVP_PKEY_CTX_set_rsa_keygen_bits(rsa.get(), num) <= 0)
139 +        return nullptr;
140  
141 -    if (!EVP_PKEY_assign_RSA(pkey.get(), (rsa.get())))
142 -        return NULL;
143 +    /* Generate key */
144 +    Security::PrivateKeyPointer pkey(EVP_PKEY_new());
145 +    if (pkey) {
146 +        auto *foo = pkey.get();
147 +        if (EVP_PKEY_keygen(rsa.get(), &foo) <= 0)
148 +            return nullptr;
149 +    }
150  
151 -    rsa.release();
152      return pkey.release();
153  }
154  
155 @@ -553,7 +546,7 @@ static bool generateFakeSslCertificate(Security::CertPointer & certToStore, Secu
156      if (properties.signWithPkey.get())
157          pkey.resetAndLock(properties.signWithPkey.get());
158      else // if not exist generate one
159 -        pkey.resetWithoutLocking(Ssl::createSslPrivateKey());
160 +        pkey.resetWithoutLocking(CreateRsaPrivateKey());
161  
162      if (!pkey)
163          return false;
164 diff --git a/src/ssl/gadgets.h b/src/ssl/gadgets.h
165 index 0a2535e41e5..b4395198cce 100644
166 --- a/src/ssl/gadgets.h
167 +++ b/src/ssl/gadgets.h
168 @@ -57,7 +57,7 @@ typedef std::unique_ptr<TXT_DB, HardFun<void, TXT_DB*, &TXT_DB_free>> TXT_DB_Poi
169  
170  typedef std::unique_ptr<X509_NAME, HardFun<void, X509_NAME*, &X509_NAME_free>> X509_NAME_Pointer;
171  
172 -typedef std::unique_ptr<RSA, HardFun<void, RSA*, &RSA_free>> RSA_Pointer;
173 +typedef std::unique_ptr<EVP_PKEY_CTX, HardFun<void, EVP_PKEY_CTX*, &EVP_PKEY_CTX_free>> EVP_PKEY_CTX_Pointer;
174  
175  typedef std::unique_ptr<X509_REQ, HardFun<void, X509_REQ*, &X509_REQ_free>> X509_REQ_Pointer;
176  
177 @@ -71,12 +71,6 @@ typedef std::unique_ptr<GENERAL_NAME, HardFun<void, GENERAL_NAME*, &GENERAL_NAME
178  typedef std::unique_ptr<X509_EXTENSION, HardFun<void, X509_EXTENSION*, &X509_EXTENSION_free>> X509_EXTENSION_Pointer;
179  
180  typedef std::unique_ptr<X509_STORE_CTX, HardFun<void, X509_STORE_CTX *, &X509_STORE_CTX_free>> X509_STORE_CTX_Pointer;
181 -/**
182 - \ingroup SslCrtdSslAPI
183 - * Create 1024 bits rsa key.
184 - */
185 -EVP_PKEY * createSslPrivateKey();
186 -
187  /**
188   \ingroup SslCrtdSslAPI
189   * Write private key and SSL certificate to memory.
190
191 From b62997320204965a765bab0dc9a5b2d3b5daa13c Mon Sep 17 00:00:00 2001
192 From: Amos Jeffries <squid3@treenet.co.nz>
193 Date: Tue, 10 Nov 2020 12:01:28 +1300
194 Subject: [PATCH 05/10] Tweak RSA key generator
195
196 ... rely on EVP_PKEY_keygen() allocating the key memory.
197 ---
198  src/ssl/gadgets.cc | 11 ++++-------
199  1 file changed, 4 insertions(+), 7 deletions(-)
200
201 diff --git a/src/ssl/gadgets.cc b/src/ssl/gadgets.cc
202 index c1e81c79291..0754e4b26b4 100644
203 --- a/src/ssl/gadgets.cc
204 +++ b/src/ssl/gadgets.cc
205 @@ -24,14 +24,11 @@ CreateRsaPrivateKey()
206          return nullptr;
207  
208      /* Generate key */
209 -    Security::PrivateKeyPointer pkey(EVP_PKEY_new());
210 -    if (pkey) {
211 -        auto *foo = pkey.get();
212 -        if (EVP_PKEY_keygen(rsa.get(), &foo) <= 0)
213 -            return nullptr;
214 -    }
215 +    EVP_PKEY *pkey = nullptr;
216 +    if (EVP_PKEY_keygen(rsa.get(), &pkey) <= 0)
217 +        return nullptr;
218  
219 -    return pkey.release();
220 +    return pkey;
221  }
222  
223  /**
224
225 From d38c63c6051d534e0b2eeb1d33e1a2dc380479a9 Mon Sep 17 00:00:00 2001
226 From: Amos Jeffries <amosjeffries@squid-cache.org>
227 Date: Wed, 6 Oct 2021 22:39:49 +1300
228 Subject: [PATCH 06/10] Fix EVP_PKEY_get0_RSA is deprecated
229
230 ---
231  src/ssl/gadgets.cc | 6 +++++-
232  1 file changed, 5 insertions(+), 1 deletion(-)
233
234 diff --git a/src/ssl/gadgets.cc b/src/ssl/gadgets.cc
235 index 0754e4b26b4..c94d57c5dbb 100644
236 --- a/src/ssl/gadgets.cc
237 +++ b/src/ssl/gadgets.cc
238 @@ -369,7 +369,11 @@ mimicExtensions(Security::CertPointer & cert, Security::CertPointer const &mimic
239      // XXX: Add PublicKeyPointer. In OpenSSL, public and private keys are
240      // internally represented by EVP_PKEY pair, but GnuTLS uses distinct types.
241      const Security::PrivateKeyPointer certKey(X509_get_pubkey(mimicCert.get()));
242 -    const auto rsaPkey = EVP_PKEY_get0_RSA(certKey.get()) != nullptr;
243 +#if OPENSSL_VERSION_MAJOR < 3
244 +    const auto rsaPkey = bool(EVP_PKEY_get0_RSA(certKey.get()));
245 +#else
246 +    const auto rsaPkey = EVP_PKEY_is_a(certKey.get(), "RSA");
247 +#endif
248  
249      int added = 0;
250      int nid;
251
252 From f3acc382b9b609eaddb44a747a47dbf85cce4023 Mon Sep 17 00:00:00 2001
253 From: Amos Jeffries <amosjeffries@squid-cache.org>
254 Date: Wed, 6 Oct 2021 21:12:25 +1300
255 Subject: [PATCH 07/10] Initial DH conversion to EVP_PKEY
256
257 3.0 build does not yet complete due to ENGINE and BIGNUM deprecation issues.
258
259 This conversion relies on OSSL_*() functions added in 3.0. So the
260 old DH loading code is left unchanged.
261 ---
262  configure.ac                  |  1 +
263  src/security/ServerOptions.cc | 30 +++++++++++++++++++++++++++---
264  src/security/forward.h        | 24 +++++++++++++++---------
265  3 files changed, 43 insertions(+), 12 deletions(-)
266
267 diff --git a/configure.ac b/configure.ac
268 index 534cec994fd..a97d05f55cf 100644
269 --- a/configure.ac
270 +++ b/configure.ac
271 @@ -1307,6 +1307,7 @@ if test "x$with_openssl" = "xyes"; then
272      openssl/bio.h \
273      openssl/bn.h \
274      openssl/crypto.h \
275 +    openssl/decoder.h \
276      openssl/dh.h \
277      openssl/err.h \
278      openssl/evp.h \
279 diff --git a/src/security/ServerOptions.cc b/src/security/ServerOptions.cc
280 index dee22869a74..040d6888bec 100644
281 --- a/src/security/ServerOptions.cc
282 +++ b/src/security/ServerOptions.cc
283 @@ -19,6 +19,9 @@
284  #include "compat/openssl.h"
285  #include "ssl/support.h"
286  
287 +#if HAVE_OPENSSL_DECODER_H
288 +#include <openssl/decoder.h>
289 +#endif
290  #if HAVE_OPENSSL_ERR_H
291  #include <openssl/err.h>
292  #endif
293 @@ -353,6 +356,7 @@ Security::ServerOptions::loadDhParams()
294          return;
295  
296  #if USE_OPENSSL
297 +#if OPENSSL_VERSION_MAJOR < 3
298      DH *dhp = nullptr;
299      if (FILE *in = fopen(dhParamsFile.c_str(), "r")) {
300          dhp = PEM_read_DHparams(in, NULL, NULL, NULL);
301 @@ -364,7 +368,6 @@ Security::ServerOptions::loadDhParams()
302          return;
303      }
304  
305 -#if OPENSSL_VERSION_MAJOR < 3
306      // DH_check() removed in OpenSSL 3.0.
307      // TODO: use the EVP API instead, which also works in OpenSSL 1.1.
308      // But it is not yet clear exactly how that API works for DH.
309 @@ -376,10 +379,31 @@ Security::ServerOptions::loadDhParams()
310              dhp = nullptr;
311          }
312      }
313 -#endif
314 -
315      parsedDhParams.resetWithoutLocking(dhp);
316 +
317 +#else // OpenSSL 3.0+
318 +    EVP_PKEY *pkey = nullptr;
319 +    if (auto *dctx = OSSL_DECODER_CTX_new_for_pkey(&pkey, "PEM", nullptr, "DH", OSSL_KEYMGMT_SELECT_ALL, nullptr, nullptr)) {
320 +        if (auto *in = fopen(dhParamsFile.c_str(), "r")) {
321 +            if (OSSL_DECODER_from_fp(dctx, in) == 1) {
322 +
323 +                /* pkey is created with the decoded data from the bio */
324 +                Must(pkey);
325 +                parsedDhParams.resetWithoutLocking(pkey);
326 +
327 +            } else {
328 +                debugs(83, DBG_IMPORTANT, "WARNING: Failed to decode DH parameters '" << dhParamsFile << "'");
329 +            }
330 +            fclose(in);
331 +        }
332 +        OSSL_DECODER_CTX_free(dctx);
333 +
334 +    } else {
335 +        debugs(83, DBG_IMPORTANT, "WARNING: no suitable potential decoders found for DH parameters");
336 +        return;
337 +    }
338  #endif
339 +#endif // USE_OPENSSL
340  }
341  
342  bool
343 diff --git a/src/security/forward.h b/src/security/forward.h
344 index 7cf1c5eb5a2..265c07eb021 100644
345 --- a/src/security/forward.h
346 +++ b/src/security/forward.h
347 @@ -93,9 +93,24 @@ typedef std::list<Security::CertPointer> CertList;
348  typedef std::list<Security::CrlPointer> CertRevokeList;
349  
350  #if USE_OPENSSL
351 +CtoCpp1(EVP_PKEY_free, EVP_PKEY *)
352 +typedef Security::LockingPointer<EVP_PKEY, EVP_PKEY_free_cpp, HardFun<int, EVP_PKEY *, EVP_PKEY_up_ref> > PrivateKeyPointer;
353 +#elif USE_GNUTLS
354 +typedef std::shared_ptr<struct gnutls_x509_privkey_int> PrivateKeyPointer;
355 +#else
356 +typedef std::shared_ptr<void> PrivateKeyPointer;
357 +#endif
358 +
359 +#if USE_OPENSSL
360 +#if OPENSSL_VERSION_MAJOR < 3
361  CtoCpp1(DH_free, DH *);
362  typedef Security::LockingPointer<DH, DH_free_cpp, HardFun<int, DH *, DH_up_ref> > DhePointer;
363  #else
364 +typedef PrivateKeyPointer DhePointer;
365 +#endif
366 +#elif USE_GNUTLS
367 +typedef void *DhePointer;
368 +#else
369  typedef void *DhePointer;
370  #endif
371  
372 @@ -178,15 +193,6 @@ class PeerConnector;
373  class PeerConnector;
374  class PeerOptions;
375  
376 -#if USE_OPENSSL
377 -CtoCpp1(EVP_PKEY_free, EVP_PKEY *)
378 -typedef Security::LockingPointer<EVP_PKEY, EVP_PKEY_free_cpp, HardFun<int, EVP_PKEY *, EVP_PKEY_up_ref> > PrivateKeyPointer;
379 -#elif USE_GNUTLS
380 -typedef std::shared_ptr<struct gnutls_x509_privkey_int> PrivateKeyPointer;
381 -#else
382 -typedef std::shared_ptr<void> PrivateKeyPointer;
383 -#endif
384 -
385  class ServerOptions;
386  
387  class ErrorDetail;
388
389 From b2f040b6872314390866e69ee643abe2786f3556 Mon Sep 17 00:00:00 2001
390 From: Amos Jeffries <amosjeffries@squid-cache.org>
391 Date: Wed, 6 Oct 2021 21:55:38 +1300
392 Subject: [PATCH 08/10] Switch to BN_rand()
393
394 BN_pseudo_rand() has been identical since libssl 1.1.0 and is removed in libssl 3.0
395 ---
396  src/cf.data.pre    | 2 ++
397  src/ssl/gadgets.cc | 2 +-
398  src/ssl/support.cc | 5 ++---
399  3 files changed, 5 insertions(+), 4 deletions(-)
400
401 diff --git a/src/cf.data.pre b/src/cf.data.pre
402 index be6741ec2ef..ef82d0a435b 100644
403 --- a/src/cf.data.pre
404 +++ b/src/cf.data.pre
405 @@ -3057,6 +3057,8 @@ DEFAULT: none
406  DOC_START
407         The OpenSSL engine to use. You will need to set this if you
408         would like to use hardware SSL acceleration for example.
409 +
410 +       Note: OpenSSL 3.0 and newer do not provide Engine support.
411  DOC_END
412  
413  NAME: sslproxy_session_ttl
414 diff --git a/src/ssl/gadgets.cc b/src/ssl/gadgets.cc
415 index c94d57c5dbb..626cb81e578 100644
416 --- a/src/ssl/gadgets.cc
417 +++ b/src/ssl/gadgets.cc
418 @@ -46,7 +46,7 @@ static bool setSerialNumber(ASN1_INTEGER *ai, BIGNUM const* serial)
419          if (!bn)
420              return false;
421  
422 -        if (!BN_pseudo_rand(bn.get(), 64, 0, 0))
423 +        if (!BN_rand(bn.get(), 64, 0, 0))
424              return false;
425      }
426  
427 diff --git a/src/ssl/support.cc b/src/ssl/support.cc
428 index c9d99e9a27e..52b94cafdae 100644
429 --- a/src/ssl/support.cc
430 +++ b/src/ssl/support.cc
431 @@ -660,8 +660,8 @@ Ssl::Initialize(void)
432  
433      SQUID_OPENSSL_init_ssl();
434  
435 -#if !defined(OPENSSL_NO_ENGINE)
436      if (::Config.SSL.ssl_engine) {
437 +#if !defined(OPENSSL_NO_ENGINE) && OPENSSL_VERSION_MAJOR < 3
438          ENGINE_load_builtin_engines();
439          ENGINE *e;
440          if (!(e = ENGINE_by_id(::Config.SSL.ssl_engine)))
441 @@ -671,11 +671,10 @@ Ssl::Initialize(void)
442              const auto ssl_error = ERR_get_error();
443              fatalf("Failed to initialise SSL engine: %s\n", Security::ErrorString(ssl_error));
444          }
445 -    }
446  #else
447 -    if (::Config.SSL.ssl_engine)
448          fatalf("Your OpenSSL has no SSL engine support\n");
449  #endif
450 +    }
451  
452      const char *defName = ::Config.SSL.certSignHash ? ::Config.SSL.certSignHash : SQUID_SSL_SIGN_HASH_IF_NONE;
453      Ssl::DefaultSignHash = EVP_get_digestbyname(defName);
454
455 From 6923982e708a6bd58379161a6256f37645792edc Mon Sep 17 00:00:00 2001
456 From: Amos Jeffries <amosjeffries@squid-cache.org>
457 Date: Sun, 10 Oct 2021 02:35:10 +1300
458 Subject: [PATCH 09/10] SSL_OP_* macro definitions changed in 3.0
459
460 ---
461  src/security/PeerOptions.cc | 50 ++++++++++++++++++-------------------
462  1 file changed, 25 insertions(+), 25 deletions(-)
463
464 diff --git a/src/security/PeerOptions.cc b/src/security/PeerOptions.cc
465 index 648f9f2590e..52a154b8c02 100644
466 --- a/src/security/PeerOptions.cc
467 +++ b/src/security/PeerOptions.cc
468 @@ -297,130 +297,130 @@ static struct ssl_option {
469  
470  } ssl_options[] = {
471  
472 -#if SSL_OP_NETSCAPE_REUSE_CIPHER_CHANGE_BUG
473 +#if defined(SSL_OP_NETSCAPE_REUSE_CIPHER_CHANGE_BUG)
474      {
475          "NETSCAPE_REUSE_CIPHER_CHANGE_BUG", SSL_OP_NETSCAPE_REUSE_CIPHER_CHANGE_BUG
476      },
477  #endif
478 -#if SSL_OP_SSLREF2_REUSE_CERT_TYPE_BUG
479 +#if defined(SSL_OP_SSLREF2_REUSE_CERT_TYPE_BUG)
480      {
481          "SSLREF2_REUSE_CERT_TYPE_BUG", SSL_OP_SSLREF2_REUSE_CERT_TYPE_BUG
482      },
483  #endif
484 -#if SSL_OP_MICROSOFT_BIG_SSLV3_BUFFER
485 +#if defined(SSL_OP_MICROSOFT_BIG_SSLV3_BUFFER)
486      {
487          "MICROSOFT_BIG_SSLV3_BUFFER", SSL_OP_MICROSOFT_BIG_SSLV3_BUFFER
488      },
489  #endif
490 -#if SSL_OP_SSLEAY_080_CLIENT_DH_BUG
491 +#if defined(SSL_OP_SSLEAY_080_CLIENT_DH_BUG)
492      {
493          "SSLEAY_080_CLIENT_DH_BUG", SSL_OP_SSLEAY_080_CLIENT_DH_BUG
494      },
495  #endif
496 -#if SSL_OP_TLS_D5_BUG
497 +#if defined(SSL_OP_TLS_D5_BUG)
498      {
499          "TLS_D5_BUG", SSL_OP_TLS_D5_BUG
500      },
501  #endif
502 -#if SSL_OP_TLS_BLOCK_PADDING_BUG
503 +#if defined(SSL_OP_TLS_BLOCK_PADDING_BUG)
504      {
505          "TLS_BLOCK_PADDING_BUG", SSL_OP_TLS_BLOCK_PADDING_BUG
506      },
507  #endif
508 -#if SSL_OP_TLS_ROLLBACK_BUG
509 +#if defined(SSL_OP_TLS_ROLLBACK_BUG)
510      {
511          "TLS_ROLLBACK_BUG", SSL_OP_TLS_ROLLBACK_BUG
512      },
513  #endif
514 -#if SSL_OP_ALL
515 +#if defined(SSL_OP_ALL)
516      {
517          "ALL", (long)SSL_OP_ALL
518      },
519  #endif
520 -#if SSL_OP_SINGLE_DH_USE
521 +#if defined(SSL_OP_SINGLE_DH_USE)
522      {
523          "SINGLE_DH_USE", SSL_OP_SINGLE_DH_USE
524      },
525  #endif
526 -#if SSL_OP_EPHEMERAL_RSA
527 +#if defined(SSL_OP_EPHEMERAL_RSA)
528      {
529          "EPHEMERAL_RSA", SSL_OP_EPHEMERAL_RSA
530      },
531  #endif
532 -#if SSL_OP_PKCS1_CHECK_1
533 +#if defined(SSL_OP_PKCS1_CHECK_1)
534      {
535          "PKCS1_CHECK_1", SSL_OP_PKCS1_CHECK_1
536      },
537  #endif
538 -#if SSL_OP_PKCS1_CHECK_2
539 +#if defined(SSL_OP_PKCS1_CHECK_2)
540      {
541          "PKCS1_CHECK_2", SSL_OP_PKCS1_CHECK_2
542      },
543  #endif
544 -#if SSL_OP_NETSCAPE_CA_DN_BUG
545 +#if defined(SSL_OP_NETSCAPE_CA_DN_BUG)
546      {
547          "NETSCAPE_CA_DN_BUG", SSL_OP_NETSCAPE_CA_DN_BUG
548      },
549  #endif
550 -#if SSL_OP_NON_EXPORT_FIRST
551 +#if defined(SSL_OP_NON_EXPORT_FIRST)
552      {
553          "NON_EXPORT_FIRST", SSL_OP_NON_EXPORT_FIRST
554      },
555  #endif
556 -#if SSL_OP_CIPHER_SERVER_PREFERENCE
557 +#if defined(SSL_OP_CIPHER_SERVER_PREFERENCE)
558      {
559          "CIPHER_SERVER_PREFERENCE", SSL_OP_CIPHER_SERVER_PREFERENCE
560      },
561  #endif
562 -#if SSL_OP_NETSCAPE_DEMO_CIPHER_CHANGE_BUG
563 +#if defined(SSL_OP_NETSCAPE_DEMO_CIPHER_CHANGE_BUG)
564      {
565          "NETSCAPE_DEMO_CIPHER_CHANGE_BUG", SSL_OP_NETSCAPE_DEMO_CIPHER_CHANGE_BUG
566      },
567  #endif
568 -#if SSL_OP_NO_SSLv3
569 +#if defined(SSL_OP_NO_SSLv3)
570      {
571          "NO_SSLv3", SSL_OP_NO_SSLv3
572      },
573  #endif
574 -#if SSL_OP_NO_TLSv1
575 +#if defined(SSL_OP_NO_TLSv1)
576      {
577          "NO_TLSv1", SSL_OP_NO_TLSv1
578      },
579  #else
580      { "NO_TLSv1", 0 },
581  #endif
582 -#if SSL_OP_NO_TLSv1_1
583 +#if defined(SSL_OP_NO_TLSv1_1)
584      {
585          "NO_TLSv1_1", SSL_OP_NO_TLSv1_1
586      },
587  #else
588      { "NO_TLSv1_1", 0 },
589  #endif
590 -#if SSL_OP_NO_TLSv1_2
591 +#if defined(SSL_OP_NO_TLSv1_2)
592      {
593          "NO_TLSv1_2", SSL_OP_NO_TLSv1_2
594      },
595  #else
596      { "NO_TLSv1_2", 0 },
597  #endif
598 -#if SSL_OP_NO_TLSv1_3
599 +#if defined(SSL_OP_NO_TLSv1_3)
600      {
601          "NO_TLSv1_3", SSL_OP_NO_TLSv1_3
602      },
603  #else
604      { "NO_TLSv1_3", 0 },
605  #endif
606 -#if SSL_OP_NO_COMPRESSION
607 +#if defined(SSL_OP_NO_COMPRESSION)
608      {
609          "No_Compression", SSL_OP_NO_COMPRESSION
610      },
611  #endif
612 -#if SSL_OP_NO_TICKET
613 +#if defined(SSL_OP_NO_TICKET)
614      {
615          "NO_TICKET", SSL_OP_NO_TICKET
616      },
617  #endif
618 -#if SSL_OP_SINGLE_ECDH_USE
619 +#if defined(SSL_OP_SINGLE_ECDH_USE)
620      {
621          "SINGLE_ECDH_USE", SSL_OP_SINGLE_ECDH_USE
622      },
623 @@ -512,7 +512,7 @@ Security::PeerOptions::parseOptions()
624  
625      }
626  
627 -#if SSL_OP_NO_SSLv2
628 +#if defined(SSL_OP_NO_SSLv2)
629      // compliance with RFC 6176: Prohibiting Secure Sockets Layer (SSL) Version 2.0
630      op = op | SSL_OP_NO_SSLv2;
631  #endif
632
633 From 0097ab042f705596c317eb69ffa7271bc676ff66 Mon Sep 17 00:00:00 2001
634 From: Amos Jeffries <amosjeffries@squid-cache.org>
635 Date: Mon, 11 Oct 2021 06:01:10 +1300
636 Subject: [PATCH 10/10] Update ECDH key settings
637
638 ---
639  src/security/ServerOptions.cc | 19 +++++++++++++++++--
640  1 file changed, 17 insertions(+), 2 deletions(-)
641
642 diff --git a/src/security/ServerOptions.cc b/src/security/ServerOptions.cc
643 index 040d6888bec..9594350e776 100644
644 --- a/src/security/ServerOptions.cc
645 +++ b/src/security/ServerOptions.cc
646 @@ -383,7 +383,12 @@ Security::ServerOptions::loadDhParams()
647  
648  #else // OpenSSL 3.0+
649      EVP_PKEY *pkey = nullptr;
650 -    if (auto *dctx = OSSL_DECODER_CTX_new_for_pkey(&pkey, "PEM", nullptr, "DH", OSSL_KEYMGMT_SELECT_ALL, nullptr, nullptr)) {
651 +    const char *type = "DH";
652 +    if (!eecdhCurve.isEmpty())
653 +        type = "EC";
654 +    // XXX: use the eecdhCurve name when generating the EVP_KEY object. or at least verify it matches the loaded params.
655 +
656 +    if (auto *dctx = OSSL_DECODER_CTX_new_for_pkey(&pkey, "PEM", nullptr, type, OSSL_KEYMGMT_SELECT_ALL, nullptr, nullptr)) {
657          if (auto *in = fopen(dhParamsFile.c_str(), "r")) {
658              if (OSSL_DECODER_from_fp(dctx, in) == 1) {
659  
660 @@ -482,6 +487,9 @@ Security::ServerOptions::updateContextEecdh(Security::ContextPointer &ctx)
661          debugs(83, 9, "Setting Ephemeral ECDH curve to " << eecdhCurve << ".");
662  
663  #if USE_OPENSSL && OPENSSL_VERSION_NUMBER >= 0x0090800fL && !defined(OPENSSL_NO_ECDH)
664 +
665 +    // OpenSSL 3.0+ generates the key in loadDhParams()
666 +#if OPENSSL_VERSION_MAJOR < 3
667          int nid = OBJ_sn2nid(eecdhCurve.c_str());
668          if (!nid) {
669              debugs(83, DBG_CRITICAL, "ERROR: Unknown EECDH curve '" << eecdhCurve << "'");
670 @@ -489,6 +497,9 @@ Security::ServerOptions::updateContextEecdh(Security::ContextPointer &ctx)
671          }
672  
673          auto ecdh = EC_KEY_new_by_curve_name(nid);
674 +#else
675 +        auto ecdh = parsedDhParams.get();
676 +#endif
677          if (!ecdh) {
678              const auto x = ERR_get_error();
679              debugs(83, DBG_CRITICAL, "ERROR: Unable to configure Ephemeral ECDH: " << Security::ErrorString(x));
680 @@ -499,7 +510,11 @@ Security::ServerOptions::updateContextEecdh(Security::ContextPointer &ctx)
681              const auto x = ERR_get_error();
682              debugs(83, DBG_CRITICAL, "ERROR: Unable to set Ephemeral ECDH: " << Security::ErrorString(x));
683          }
684 +#if OPENSSL_VERSION_MAJOR < 3
685          EC_KEY_free(ecdh);
686 +#else
687 +        return;
688 +#endif
689  
690  #else
691          debugs(83, DBG_CRITICAL, "ERROR: EECDH is not available in this build." <<
692 @@ -508,8 +523,8 @@ Security::ServerOptions::updateContextEecdh(Security::ContextPointer &ctx)
693  #endif
694      }
695  
696 -    // set DH parameters into the server context
697  #if USE_OPENSSL
698 +    // set DH parameters into the server context
699      if (parsedDhParams) {
700          SSL_CTX_set_tmp_dh(ctx.get(), parsedDhParams.get());
701      }
This page took 0.125923 seconds and 3 git commands to generate.