embed-builtin-cadata.patch 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. commit f973b22a716935e4ceb507dd6738236570cd2b98
  2. merge: d4c608daaa9086189bbbb3214113edddc2082069 02c93d0cdd494ecb2b95524fd0619931975fb0cb
  3. author: orivej
  4. date: 2019-07-03T18:34:12+03:00
  5. revision: 5208986
  6. Embed builtin_cadata() into ssl module. CONTRIB-1287
  7. Fixes using ssl from python started with Y_PYTHON_ENTRY_POINT=:main.
  8. REVIEW: 865741
  9. Note: mandatory check (NEED_CHECK) was skipped
  10. commit 4a060eba5386ec1fc4b7f2d0cafffff8832cae5f
  11. merge: dc1ec05cf5f3db39c49ec0d03a06e14e330637f5 8277f2d7d63229e5c85ef55ba84285dd59576365
  12. author: orivej
  13. date: 2019-07-01T16:12:03+03:00
  14. revision: 5191643
  15. Load certs/cacert.pem into the default Python SSL context. CONTRIB-1287
  16. This allows to enable SSL verification in Python 2 by default.
  17. REVIEW: 861704
  18. Note: mandatory check (NEED_CHECK) was skipped
  19. --- contrib/tools/python3/Lib/ssl.py (index)
  20. +++ contrib/tools/python3/Lib/ssl.py (working tree)
  21. @@ -481,6 +481,20 @@ class Purpose(_ASN1Object, _Enum):
  22. CLIENT_AUTH = '1.3.6.1.5.5.7.3.2'
  23. +_builtin_cadata = None
  24. +
  25. +
  26. +def builtin_cadata():
  27. + global _builtin_cadata
  28. + if _builtin_cadata is None:
  29. + import __res
  30. + data = __res.find(b'/builtin/cacert')
  31. + # load_verify_locations expects PEM cadata to be an ASCII-only unicode
  32. + # object, so we discard unicode in comments.
  33. + _builtin_cadata = data.decode('ASCII', errors='ignore')
  34. + return _builtin_cadata
  35. +
  36. +
  37. class SSLContext(_SSLContext):
  38. """An SSLContext holds various SSL-related configuration options and
  39. data, such as certificates and possibly a private key."""
  40. @@ -591,6 +605,9 @@ class SSLContext(_SSLContext):
  41. def load_default_certs(self, purpose=Purpose.SERVER_AUTH):
  42. if not isinstance(purpose, _ASN1Object):
  43. raise TypeError(purpose)
  44. +
  45. + self.load_verify_locations(cadata=builtin_cadata())
  46. +
  47. if sys.platform == "win32":
  48. for storename in self._windows_cert_stores:
  49. self._load_windows_store_certs(storename, purpose)