PageRenderTime 47ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/dev-python/pypy3-bin/files/pypy3-2.4.0-libressl.patch

https://gitlab.com/kogaion/portage
Patch | 187 lines | 170 code | 17 blank | 0 comment | 0 complexity | 21ccd2739c97e929b68579ad25971338 MD5 | raw file
  1. From 66bef80988c9efe60b61c6bc05f3206b4c3df7e8 Mon Sep 17 00:00:00 2001
  2. From: hasufell <hasufell@gentoo.org>
  3. Date: Mon, 12 Oct 2015 20:43:50 +0200
  4. Subject: [PATCH] Add LibreSSL support, patches backported from upstream
  5. https://bitbucket.org/pypy/pypy/pull-requests/333/deal-with-platforms-without-rand_egd-take/diff
  6. ---
  7. pypy/module/_ssl/interp_ssl.py | 34 +++++++++++++++-----------
  8. pypy/module/_ssl/test/test_ssl.py | 8 +++---
  9. rpython/rlib/ropenssl.py | 6 ++++-
  10. rpython/rtyper/tool/rffi_platform.py | 12 ++++++---
  11. rpython/rtyper/tool/test/test_rffi_platform.py | 24 +++++++++++++++++-
  12. 5 files changed, 61 insertions(+), 23 deletions(-)
  13. diff --git a/pypy/module/_ssl/interp_ssl.py b/pypy/module/_ssl/interp_ssl.py
  14. index 0cac165..f210167 100644
  15. --- a/pypy/module/_ssl/interp_ssl.py
  16. +++ b/pypy/module/_ssl/interp_ssl.py
  17. @@ -310,20 +310,26 @@ if HAVE_OPENSSL_RAND:
  18. res = libssl_RAND_status()
  19. return space.wrap(res)
  20. - @unwrap_spec(path=str)
  21. - def RAND_egd(space, path):
  22. - """RAND_egd(path) -> bytes
  23. -
  24. - Queries the entropy gather daemon (EGD) on socket path. Returns number
  25. - of bytes read. Raises socket.sslerror if connection to EGD fails or
  26. - if it does provide enough data to seed PRNG."""
  27. - with rffi.scoped_str2charp(path) as socket_path:
  28. - bytes = libssl_RAND_egd(socket_path)
  29. - if bytes == -1:
  30. - raise ssl_error(space,
  31. - "EGD connection failed or EGD did not return "
  32. - "enough data to seed the PRNG")
  33. - return space.wrap(bytes)
  34. + if HAVE_OPENSSL_RAND_EGD:
  35. + @unwrap_spec(path=str)
  36. + def RAND_egd(space, path):
  37. + """RAND_egd(path) -> bytes
  38. +
  39. + Queries the entropy gather daemon (EGD) on socket path. Returns number
  40. + of bytes read. Raises socket.sslerror if connection to EGD fails or
  41. + if it does provide enough data to seed PRNG."""
  42. + with rffi.scoped_str2charp(path) as socket_path:
  43. + bytes = libssl_RAND_egd(socket_path)
  44. + if bytes == -1:
  45. + raise ssl_error(space,
  46. + "EGD connection failed or EGD did not return "
  47. + "enough data to seed the PRNG")
  48. + return space.wrap(bytes)
  49. + else:
  50. + # Dummy func for platforms missing RAND_egd(). Most likely LibreSSL.
  51. + @unwrap_spec(path=str)
  52. + def RAND_egd(space, path):
  53. + raise ssl_error(space, "RAND_egd unavailable")
  54. class SSLSocket(W_Root):
  55. diff --git a/pypy/module/_ssl/test/test_ssl.py b/pypy/module/_ssl/test/test_ssl.py
  56. index 3204610..9722fd5 100644
  57. --- a/pypy/module/_ssl/test/test_ssl.py
  58. +++ b/pypy/module/_ssl/test/test_ssl.py
  59. @@ -33,7 +33,8 @@ class AppTestSSL:
  60. assert isinstance(_ssl.OPENSSL_VERSION_INFO, tuple)
  61. assert len(_ssl.OPENSSL_VERSION_INFO) == 5
  62. assert isinstance(_ssl.OPENSSL_VERSION, str)
  63. - assert 'openssl' in _ssl.OPENSSL_VERSION.lower()
  64. + lower_version = _ssl.OPENSSL_VERSION.lower()
  65. + assert 'openssl' in lower_version or "libressl" in lower_version
  66. def test_RAND_add(self):
  67. import _ssl
  68. @@ -64,8 +65,9 @@ class AppTestSSL:
  69. def test_sslwrap(self):
  70. import ssl, _socket, sys, gc
  71. - if sys.platform == 'darwin' or 'freebsd' in sys.platform:
  72. - skip("hangs indefinitely on OSX & FreeBSD (also on CPython)")
  73. + if sys.platform == 'darwin' or 'freebsd' in sys.platform or \
  74. + 'openbsd' in sys.platform:
  75. + skip("hangs indefinitely on OSX & BSD (also on CPython)")
  76. s = _socket.socket()
  77. ss = ssl.wrap_socket(s)
  78. diff --git a/rpython/rlib/ropenssl.py b/rpython/rlib/ropenssl.py
  79. index c36779d..6fe45d0 100644
  80. --- a/rpython/rlib/ropenssl.py
  81. +++ b/rpython/rlib/ropenssl.py
  82. @@ -168,6 +168,9 @@ OBJ_NAME = rffi.CArrayPtr(OBJ_NAME_st)
  83. HAVE_OPENSSL_RAND = OPENSSL_VERSION_NUMBER >= 0x0090500f
  84. HAVE_SSL_CTX_CLEAR_OPTIONS = OPENSSL_VERSION_NUMBER >= 0x009080df
  85. +HAVE_OPENSSL_RAND_EGD = rffi_platform.has('RAND_egd("/")',
  86. + '#include <openssl/rand.h>',
  87. + libraries=['ssl', 'crypto'])
  88. def external(name, argtypes, restype, **kw):
  89. kw['compilation_info'] = eci
  90. @@ -194,7 +197,8 @@ ssl_external('CRYPTO_set_id_callback',
  91. if HAVE_OPENSSL_RAND:
  92. ssl_external('RAND_add', [rffi.CCHARP, rffi.INT, rffi.DOUBLE], lltype.Void)
  93. ssl_external('RAND_status', [], rffi.INT)
  94. - ssl_external('RAND_egd', [rffi.CCHARP], rffi.INT)
  95. + if HAVE_OPENSSL_RAND_EGD:
  96. + ssl_external('RAND_egd', [rffi.CCHARP], rffi.INT)
  97. ssl_external('SSL_CTX_new', [SSL_METHOD], SSL_CTX)
  98. ssl_external('SSL_get_SSL_CTX', [SSL], SSL_CTX)
  99. ssl_external('TLSv1_method', [], SSL_METHOD)
  100. diff --git a/rpython/rtyper/tool/rffi_platform.py b/rpython/rtyper/tool/rffi_platform.py
  101. index 1760877..1d56c20 100755
  102. --- a/rpython/rtyper/tool/rffi_platform.py
  103. +++ b/rpython/rtyper/tool/rffi_platform.py
  104. @@ -17,12 +17,15 @@ from rpython.rlib.rarithmetic import r_uint, r_longlong, r_ulonglong, intmask
  105. #
  106. # Helpers for simple cases
  107. -def eci_from_header(c_header_source, include_dirs=None):
  108. +def eci_from_header(c_header_source, include_dirs=None, libraries=None):
  109. if include_dirs is None:
  110. include_dirs = []
  111. + if libraries is None:
  112. + libraries = []
  113. return ExternalCompilationInfo(
  114. post_include_bits=[c_header_source],
  115. - include_dirs=include_dirs
  116. + include_dirs=include_dirs,
  117. + libraries=libraries,
  118. )
  119. def getstruct(name, c_header_source, interesting_fields):
  120. @@ -75,9 +78,10 @@ def getintegerfunctionresult(function, args=None, c_header_source='', includes=[
  121. CConfig._compilation_info_.includes = includes
  122. return configure(CConfig)['RESULT']
  123. -def has(name, c_header_source, include_dirs=None):
  124. +def has(name, c_header_source, include_dirs=None, libraries=None):
  125. class CConfig:
  126. - _compilation_info_ = eci_from_header(c_header_source, include_dirs)
  127. + _compilation_info_ = \
  128. + eci_from_header(c_header_source, include_dirs, libraries)
  129. HAS = Has(name)
  130. return configure(CConfig)['HAS']
  131. diff --git a/rpython/rtyper/tool/test/test_rffi_platform.py b/rpython/rtyper/tool/test/test_rffi_platform.py
  132. index bfa069e..4feae87 100644
  133. --- a/rpython/rtyper/tool/test/test_rffi_platform.py
  134. +++ b/rpython/rtyper/tool/test/test_rffi_platform.py
  135. @@ -271,12 +271,34 @@ def test_array():
  136. [("d_name", lltype.FixedSizeArray(rffi.CHAR, 1))])
  137. assert dirent.c_d_name.length == 32
  138. -def test_has():
  139. +def test_has_0001():
  140. assert rffi_platform.has("x", "int x = 3;")
  141. assert not rffi_platform.has("x", "")
  142. # has() should also not crash if it is given an invalid #include
  143. assert not rffi_platform.has("x", "#include <some/path/which/cannot/exist>")
  144. +def test_has_0002():
  145. + assert rffi_platform.has("pow", "#include <math.h>", libraries=["m"])
  146. +
  147. +def test_has_0003():
  148. + """multiple libraries"""
  149. + assert rffi_platform.has("pow", "#include <math.h>", libraries=["m", "c"])
  150. +
  151. +def test_has_0004():
  152. + """bogus symbol name"""
  153. + assert not rffi_platform.has("pow", "#include <math.h>",
  154. + libraries=["boguslibname"])
  155. +
  156. +def test_has_0005():
  157. + """bogus symbol name and lib name"""
  158. + assert not rffi_platform.has("bogus_symbol_name", "#include <math.h>",
  159. + libraries=["boguslibname"])
  160. +
  161. +def test_has_0006():
  162. + """missing include"""
  163. + assert not rffi_platform.has("pow", "", libraries=["m"])
  164. +
  165. +
  166. def test_verify_eci():
  167. eci = ExternalCompilationInfo()
  168. rffi_platform.verify_eci(eci)
  169. --
  170. 2.6.1