You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

128 lines
5.4 KiB

  1. From 9b400b32eb3673ab525f12f41a2ff3e4e3bfcccb Mon Sep 17 00:00:00 2001
  2. From: Eneas U de Queiroz <cotequeiroz@gmail.com>
  3. Date: Fri, 28 Jun 2019 11:05:20 -0300
  4. Subject: [PATCH] Add locking support to wolfSSL
  5. This takes advantage of wolfSSL openssl compatibility layer, so all
  6. that that's needed are library detection, and inclusion of specific
  7. headers.
  8. WolfSSL must be built with --enable-opensslextra to enable the required
  9. API, and that's being checked at build time, with a warning if disabled.
  10. Signed-off-by: Eneas U de Queiroz <cotequeiroz@gmail.com>
  11. diff --git a/setup.py b/setup.py
  12. index 3be0fcb..d4303b0 100644
  13. --- a/setup.py
  14. +++ b/setup.py
  15. @@ -143,6 +143,7 @@ class ExtensionConfiguration(object):
  16. return {
  17. '--with-openssl': self.using_openssl,
  18. '--with-ssl': self.using_openssl,
  19. + '--with-wolfssl': self.using_wolfssl,
  20. '--with-gnutls': self.using_gnutls,
  21. '--with-nss': self.using_nss,
  22. '--with-mbedtls': self.using_mbedtls,
  23. @@ -163,7 +164,7 @@ class ExtensionConfiguration(object):
  24. if 'PYCURL_SSL_LIBRARY' in os.environ:
  25. ssl_lib = os.environ['PYCURL_SSL_LIBRARY']
  26. - if ssl_lib in ['openssl', 'gnutls', 'nss', 'mbedtls']:
  27. + if ssl_lib in ['openssl', 'wolfssl', 'gnutls', 'nss', 'mbedtls']:
  28. ssl_lib_detected = ssl_lib
  29. getattr(self, 'using_%s' % ssl_lib)()
  30. else:
  31. @@ -188,6 +189,10 @@ class ExtensionConfiguration(object):
  32. self.using_openssl()
  33. ssl_lib_detected = 'openssl'
  34. break
  35. + if arg[2:] == 'wolfssl':
  36. + self.using_wolfssl()
  37. + ssl_lib_detected = 'wolfssl'
  38. + break
  39. if arg[2:] == 'gnutls':
  40. self.using_gnutls()
  41. ssl_lib_detected = 'gnutls'
  42. @@ -506,6 +511,11 @@ manually. For other SSL backends please ignore this message.''')
  43. self.libraries.append('ssl')
  44. self.define_macros.append(('HAVE_CURL_SSL', 1))
  45. + def using_wolfssl(self):
  46. + self.define_macros.append(('HAVE_CURL_WOLFSSL', 1))
  47. + self.libraries.append('wolfssl')
  48. + self.define_macros.append(('HAVE_CURL_SSL', 1))
  49. +
  50. def using_gnutls(self):
  51. self.define_macros.append(('HAVE_CURL_GNUTLS', 1))
  52. self.libraries.append('gnutls')
  53. @@ -572,6 +582,7 @@ def strip_pycurl_options(argv):
  54. PRETTY_SSL_LIBS = {
  55. # setup.py may be detecting BoringSSL properly, need to test
  56. 'openssl': 'OpenSSL/LibreSSL/BoringSSL',
  57. + 'wolfssl': 'wolfSSL',
  58. 'gnutls': 'GnuTLS',
  59. 'nss': 'NSS',
  60. 'mbedtls': 'mbedTLS',
  61. @@ -902,6 +913,7 @@ PycURL Unix options:
  62. --with-gnutls libcurl is linked against GnuTLS
  63. --with-nss libcurl is linked against NSS
  64. --with-mbedtls libcurl is linked against mbedTLS
  65. + --with-wolfssl libcurl is linked against wolfSSL
  66. '''
  67. windows_help = '''\
  68. diff --git a/src/module.c b/src/module.c
  69. index 909cdfe..23387ec 100644
  70. --- a/src/module.c
  71. +++ b/src/module.c
  72. @@ -351,6 +351,8 @@ initpycurl(void)
  73. } else if (!strncmp(vi->ssl_version, "OpenSSL/", 8) || !strncmp(vi->ssl_version, "LibreSSL/", 9) ||
  74. !strncmp(vi->ssl_version, "BoringSSL", 9)) {
  75. runtime_ssl_lib = "openssl";
  76. + } else if (!strncmp(vi->ssl_version, "wolfSSL/", 8)) {
  77. + runtime_ssl_lib = "wolfssl";
  78. } else if (!strncmp(vi->ssl_version, "GnuTLS/", 7)) {
  79. runtime_ssl_lib = "gnutls";
  80. } else if (!strncmp(vi->ssl_version, "NSS/", 4)) {
  81. diff --git a/src/pycurl.h b/src/pycurl.h
  82. index 2294cb8..092387f 100644
  83. --- a/src/pycurl.h
  84. +++ b/src/pycurl.h
  85. @@ -164,6 +164,28 @@ pycurl_inet_ntop (int family, void *addr, char *string, size_t string_size);
  86. # include <openssl/ssl.h>
  87. # include <openssl/err.h>
  88. # define COMPILE_SSL_LIB "openssl"
  89. +# elif defined(HAVE_CURL_WOLFSSL)
  90. +# include <wolfssl/options.h>
  91. +# if defined(OPENSSL_EXTRA)
  92. +# define HAVE_CURL_OPENSSL
  93. +# define PYCURL_NEED_SSL_TSL
  94. +# define PYCURL_NEED_OPENSSL_TSL
  95. +# include <wolfssl/openssl/ssl.h>
  96. +# include <wolfssl/openssl/err.h>
  97. +# else
  98. +# ifdef _MSC_VER
  99. +# pragma message(\
  100. + "libcurl was compiled with wolfSSL, but the library was built without " \
  101. + "--enable-opensslextra; thus no SSL crypto locking callbacks will be set, " \
  102. + "which may cause random crashes on SSL requests")
  103. +# else
  104. +# warning \
  105. + "libcurl was compiled with wolfSSL, but the library was built without " \
  106. + "--enable-opensslextra; thus no SSL crypto locking callbacks will be set, " \
  107. + "which may cause random crashes on SSL requests"
  108. +# endif
  109. +# endif
  110. +# define COMPILE_SSL_LIB "wolfssl"
  111. # elif defined(HAVE_CURL_GNUTLS)
  112. # include <gnutls/gnutls.h>
  113. # if GNUTLS_VERSION_NUMBER <= 0x020b00
  114. @@ -195,7 +217,7 @@ pycurl_inet_ntop (int family, void *addr, char *string, size_t string_size);
  115. /* since we have no crypto callbacks for other ssl backends,
  116. * no reason to require users match those */
  117. # define COMPILE_SSL_LIB "none/other"
  118. -# endif /* HAVE_CURL_OPENSSL || HAVE_CURL_GNUTLS || HAVE_CURL_NSS || HAVE_CURL_MBEDTLS */
  119. +# endif /* HAVE_CURL_OPENSSL || HAVE_CURL_WOLFSSL || HAVE_CURL_GNUTLS || HAVE_CURL_NSS || HAVE_CURL_MBEDTLS */
  120. #else
  121. # define COMPILE_SSL_LIB "none/other"
  122. #endif /* HAVE_CURL_SSL */