0001-2.7-bpo-33127-Compatibility-patch-for-LibreSSL-2.7.0.patch 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. From edd541897b9c28ee0d0f0131746aa5f19665a104 Mon Sep 17 00:00:00 2001
  2. From: Christian Heimes <christian@python.org>
  3. Date: Sat, 24 Mar 2018 19:34:15 +0100
  4. Subject: [PATCH] [2.7] bpo-33127: Compatibility patch for LibreSSL 2.7.0
  5. (GH-6210) (GH-6215)
  6. LibreSSL 2.7 introduced OpenSSL 1.1.0 API. The ssl module now detects
  7. LibreSSL 2.7 and only provides API shims for OpenSSL < 1.1.0 and
  8. LibreSSL < 2.7.
  9. Documentation updates and fixes for failing tests will be provided in
  10. another patch set.
  11. Signed-off-by: Christian Heimes <christian@python.org>.
  12. (cherry picked from commit 4ca0739c9d97ac7cd45499e0d31be68dc659d0e1)
  13. Co-authored-by: Christian Heimes <christian@python.org>
  14. ---
  15. .../2018-03-24-15-08-24.bpo-33127.olJmHv.rst | 1 +
  16. Modules/_ssl.c | 24 ++++++++++++++--------
  17. Tools/ssl/multissltests.py | 3 ++-
  18. 3 files changed, 19 insertions(+), 9 deletions(-)
  19. create mode 100644 Misc/NEWS.d/next/Library/2018-03-24-15-08-24.bpo-33127.olJmHv.rst
  20. diff --git a/Modules/_ssl.c b/Modules/_ssl.c
  21. index da8b20f54f..d0ce913d3d 100644
  22. --- a/Modules/_ssl.c
  23. +++ b/Modules/_ssl.c
  24. @@ -102,6 +102,12 @@ struct py_ssl_library_code {
  25. #if (OPENSSL_VERSION_NUMBER >= 0x10100000L) && !defined(LIBRESSL_VERSION_NUMBER)
  26. # define OPENSSL_VERSION_1_1 1
  27. +# define PY_OPENSSL_1_1_API 1
  28. +#endif
  29. +
  30. +/* LibreSSL 2.7.0 provides necessary OpenSSL 1.1.0 APIs */
  31. +#if defined(LIBRESSL_VERSION_NUMBER) && LIBRESSL_VERSION_NUMBER >= 0x2070000fL
  32. +# define PY_OPENSSL_1_1_API 1
  33. #endif
  34. /* Openssl comes with TLSv1.1 and TLSv1.2 between 1.0.0h and 1.0.1
  35. @@ -149,16 +155,18 @@ struct py_ssl_library_code {
  36. #define INVALID_SOCKET (-1)
  37. #endif
  38. -#ifdef OPENSSL_VERSION_1_1
  39. -/* OpenSSL 1.1.0+ */
  40. -#ifndef OPENSSL_NO_SSL2
  41. -#define OPENSSL_NO_SSL2
  42. -#endif
  43. -#else /* OpenSSL < 1.1.0 */
  44. -#if defined(WITH_THREAD)
  45. +/* OpenSSL 1.0.2 and LibreSSL needs extra code for locking */
  46. +#if !defined(OPENSSL_VERSION_1_1) && defined(WITH_THREAD)
  47. #define HAVE_OPENSSL_CRYPTO_LOCK
  48. #endif
  49. +#if defined(OPENSSL_VERSION_1_1) && !defined(OPENSSL_NO_SSL2)
  50. +#define OPENSSL_NO_SSL2
  51. +#endif
  52. +
  53. +#ifndef PY_OPENSSL_1_1_API
  54. +/* OpenSSL 1.1 API shims for OpenSSL < 1.1.0 and LibreSSL < 2.7.0 */
  55. +
  56. #define TLS_method SSLv23_method
  57. static int X509_NAME_ENTRY_set(const X509_NAME_ENTRY *ne)
  58. @@ -201,7 +209,7 @@ static X509_VERIFY_PARAM *X509_STORE_get0_param(X509_STORE *store)
  59. {
  60. return store->param;
  61. }
  62. -#endif /* OpenSSL < 1.1.0 or LibreSSL */
  63. +#endif /* OpenSSL < 1.1.0 or LibreSSL < 2.7.0 */
  64. enum py_ssl_error {
  65. --
  66. 2.16.1