brain_ssl.py 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. # Copyright (c) 2016, 2018, 2020 Claudiu Popa <pcmanticore@gmail.com>
  2. # Copyright (c) 2016 Ceridwen <ceridwenv@gmail.com>
  3. # Copyright (c) 2019 Benjamin Elven <25181435+S3ntinelX@users.noreply.github.com>
  4. # Copyright (c) 2020-2021 hippo91 <guillaume.peillex@gmail.com>
  5. # Copyright (c) 2021 Pierre Sassoulas <pierre.sassoulas@gmail.com>
  6. # Copyright (c) 2021 Marc Mueller <30130371+cdce8p@users.noreply.github.com>
  7. # Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html
  8. # For details: https://github.com/PyCQA/astroid/blob/main/LICENSE
  9. """Astroid hooks for the ssl library."""
  10. from astroid import parse
  11. from astroid.brain.helpers import register_module_extender
  12. from astroid.manager import AstroidManager
  13. def ssl_transform():
  14. return parse(
  15. """
  16. from _ssl import OPENSSL_VERSION_NUMBER, OPENSSL_VERSION_INFO, OPENSSL_VERSION
  17. from _ssl import _SSLContext, MemoryBIO
  18. from _ssl import (
  19. SSLError, SSLZeroReturnError, SSLWantReadError, SSLWantWriteError,
  20. SSLSyscallError, SSLEOFError,
  21. )
  22. from _ssl import CERT_NONE, CERT_OPTIONAL, CERT_REQUIRED
  23. from _ssl import txt2obj as _txt2obj, nid2obj as _nid2obj
  24. from _ssl import RAND_status, RAND_add, RAND_bytes, RAND_pseudo_bytes
  25. try:
  26. from _ssl import RAND_egd
  27. except ImportError:
  28. # LibreSSL does not provide RAND_egd
  29. pass
  30. from _ssl import (OP_ALL, OP_CIPHER_SERVER_PREFERENCE,
  31. OP_NO_COMPRESSION, OP_NO_SSLv2, OP_NO_SSLv3,
  32. OP_NO_TLSv1, OP_NO_TLSv1_1, OP_NO_TLSv1_2,
  33. OP_SINGLE_DH_USE, OP_SINGLE_ECDH_USE)
  34. from _ssl import (ALERT_DESCRIPTION_ACCESS_DENIED, ALERT_DESCRIPTION_BAD_CERTIFICATE,
  35. ALERT_DESCRIPTION_BAD_CERTIFICATE_HASH_VALUE,
  36. ALERT_DESCRIPTION_BAD_CERTIFICATE_STATUS_RESPONSE,
  37. ALERT_DESCRIPTION_BAD_RECORD_MAC,
  38. ALERT_DESCRIPTION_CERTIFICATE_EXPIRED,
  39. ALERT_DESCRIPTION_CERTIFICATE_REVOKED,
  40. ALERT_DESCRIPTION_CERTIFICATE_UNKNOWN,
  41. ALERT_DESCRIPTION_CERTIFICATE_UNOBTAINABLE,
  42. ALERT_DESCRIPTION_CLOSE_NOTIFY, ALERT_DESCRIPTION_DECODE_ERROR,
  43. ALERT_DESCRIPTION_DECOMPRESSION_FAILURE,
  44. ALERT_DESCRIPTION_DECRYPT_ERROR,
  45. ALERT_DESCRIPTION_HANDSHAKE_FAILURE,
  46. ALERT_DESCRIPTION_ILLEGAL_PARAMETER,
  47. ALERT_DESCRIPTION_INSUFFICIENT_SECURITY,
  48. ALERT_DESCRIPTION_INTERNAL_ERROR,
  49. ALERT_DESCRIPTION_NO_RENEGOTIATION,
  50. ALERT_DESCRIPTION_PROTOCOL_VERSION,
  51. ALERT_DESCRIPTION_RECORD_OVERFLOW,
  52. ALERT_DESCRIPTION_UNEXPECTED_MESSAGE,
  53. ALERT_DESCRIPTION_UNKNOWN_CA,
  54. ALERT_DESCRIPTION_UNKNOWN_PSK_IDENTITY,
  55. ALERT_DESCRIPTION_UNRECOGNIZED_NAME,
  56. ALERT_DESCRIPTION_UNSUPPORTED_CERTIFICATE,
  57. ALERT_DESCRIPTION_UNSUPPORTED_EXTENSION,
  58. ALERT_DESCRIPTION_USER_CANCELLED)
  59. from _ssl import (SSL_ERROR_EOF, SSL_ERROR_INVALID_ERROR_CODE, SSL_ERROR_SSL,
  60. SSL_ERROR_SYSCALL, SSL_ERROR_WANT_CONNECT, SSL_ERROR_WANT_READ,
  61. SSL_ERROR_WANT_WRITE, SSL_ERROR_WANT_X509_LOOKUP, SSL_ERROR_ZERO_RETURN)
  62. from _ssl import VERIFY_CRL_CHECK_CHAIN, VERIFY_CRL_CHECK_LEAF, VERIFY_DEFAULT, VERIFY_X509_STRICT
  63. from _ssl import HAS_SNI, HAS_ECDH, HAS_NPN, HAS_ALPN
  64. from _ssl import _OPENSSL_API_VERSION
  65. from _ssl import PROTOCOL_SSLv23, PROTOCOL_TLSv1, PROTOCOL_TLSv1_1, PROTOCOL_TLSv1_2
  66. from _ssl import PROTOCOL_TLS, PROTOCOL_TLS_CLIENT, PROTOCOL_TLS_SERVER
  67. """
  68. )
  69. register_module_extender(AstroidManager(), "ssl", ssl_transform)