_conditional.py 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. # This file is dual licensed under the terms of the Apache License, Version
  2. # 2.0, and the BSD License. See the LICENSE file in the root of this repository
  3. # for complete details.
  4. from __future__ import annotations
  5. def cryptography_has_set_cert_cb() -> list[str]:
  6. return [
  7. "SSL_CTX_set_cert_cb",
  8. "SSL_set_cert_cb",
  9. ]
  10. def cryptography_has_ssl_st() -> list[str]:
  11. return [
  12. "SSL_ST_BEFORE",
  13. "SSL_ST_OK",
  14. "SSL_ST_INIT",
  15. "SSL_ST_RENEGOTIATE",
  16. ]
  17. def cryptography_has_tls_st() -> list[str]:
  18. return [
  19. "TLS_ST_BEFORE",
  20. "TLS_ST_OK",
  21. ]
  22. def cryptography_has_ssl_sigalgs() -> list[str]:
  23. return [
  24. "SSL_CTX_set1_sigalgs_list",
  25. ]
  26. def cryptography_has_psk() -> list[str]:
  27. return [
  28. "SSL_CTX_use_psk_identity_hint",
  29. "SSL_CTX_set_psk_server_callback",
  30. "SSL_CTX_set_psk_client_callback",
  31. ]
  32. def cryptography_has_psk_tlsv13() -> list[str]:
  33. return [
  34. "SSL_CTX_set_psk_find_session_callback",
  35. "SSL_CTX_set_psk_use_session_callback",
  36. "Cryptography_SSL_SESSION_new",
  37. "SSL_CIPHER_find",
  38. "SSL_SESSION_set1_master_key",
  39. "SSL_SESSION_set_cipher",
  40. "SSL_SESSION_set_protocol_version",
  41. ]
  42. def cryptography_has_custom_ext() -> list[str]:
  43. return [
  44. "SSL_CTX_add_client_custom_ext",
  45. "SSL_CTX_add_server_custom_ext",
  46. "SSL_extension_supported",
  47. ]
  48. def cryptography_has_tlsv13_functions() -> list[str]:
  49. return [
  50. "SSL_VERIFY_POST_HANDSHAKE",
  51. "SSL_CTX_set_ciphersuites",
  52. "SSL_verify_client_post_handshake",
  53. "SSL_CTX_set_post_handshake_auth",
  54. "SSL_set_post_handshake_auth",
  55. "SSL_SESSION_get_max_early_data",
  56. "SSL_write_early_data",
  57. "SSL_read_early_data",
  58. "SSL_CTX_set_max_early_data",
  59. ]
  60. def cryptography_has_engine() -> list[str]:
  61. return [
  62. "ENGINE_by_id",
  63. "ENGINE_init",
  64. "ENGINE_finish",
  65. "ENGINE_get_default_RAND",
  66. "ENGINE_set_default_RAND",
  67. "ENGINE_unregister_RAND",
  68. "ENGINE_ctrl_cmd",
  69. "ENGINE_free",
  70. "ENGINE_get_name",
  71. "ENGINE_ctrl_cmd_string",
  72. "ENGINE_load_builtin_engines",
  73. "ENGINE_load_private_key",
  74. "ENGINE_load_public_key",
  75. "SSL_CTX_set_client_cert_engine",
  76. ]
  77. def cryptography_has_verified_chain() -> list[str]:
  78. return [
  79. "SSL_get0_verified_chain",
  80. ]
  81. def cryptography_has_srtp() -> list[str]:
  82. return [
  83. "SSL_CTX_set_tlsext_use_srtp",
  84. "SSL_set_tlsext_use_srtp",
  85. "SSL_get_selected_srtp_profile",
  86. ]
  87. def cryptography_has_op_no_renegotiation() -> list[str]:
  88. return [
  89. "SSL_OP_NO_RENEGOTIATION",
  90. ]
  91. def cryptography_has_dtls_get_data_mtu() -> list[str]:
  92. return [
  93. "DTLS_get_data_mtu",
  94. ]
  95. def cryptography_has_ssl_cookie() -> list[str]:
  96. return [
  97. "SSL_OP_COOKIE_EXCHANGE",
  98. "DTLSv1_listen",
  99. "SSL_CTX_set_cookie_generate_cb",
  100. "SSL_CTX_set_cookie_verify_cb",
  101. ]
  102. def cryptography_has_prime_checks() -> list[str]:
  103. return [
  104. "BN_prime_checks_for_size",
  105. ]
  106. def cryptography_has_unexpected_eof_while_reading() -> list[str]:
  107. return ["SSL_R_UNEXPECTED_EOF_WHILE_READING"]
  108. def cryptography_has_ssl_op_ignore_unexpected_eof() -> list[str]:
  109. return [
  110. "SSL_OP_IGNORE_UNEXPECTED_EOF",
  111. ]
  112. def cryptography_has_get_extms_support() -> list[str]:
  113. return ["SSL_get_extms_support"]
  114. # This is a mapping of
  115. # {condition: function-returning-names-dependent-on-that-condition} so we can
  116. # loop over them and delete unsupported names at runtime. It will be removed
  117. # when cffi supports #if in cdef. We use functions instead of just a dict of
  118. # lists so we can use coverage to measure which are used.
  119. CONDITIONAL_NAMES = {
  120. "Cryptography_HAS_SET_CERT_CB": cryptography_has_set_cert_cb,
  121. "Cryptography_HAS_SSL_ST": cryptography_has_ssl_st,
  122. "Cryptography_HAS_TLS_ST": cryptography_has_tls_st,
  123. "Cryptography_HAS_SIGALGS": cryptography_has_ssl_sigalgs,
  124. "Cryptography_HAS_PSK": cryptography_has_psk,
  125. "Cryptography_HAS_PSK_TLSv1_3": cryptography_has_psk_tlsv13,
  126. "Cryptography_HAS_CUSTOM_EXT": cryptography_has_custom_ext,
  127. "Cryptography_HAS_TLSv1_3_FUNCTIONS": cryptography_has_tlsv13_functions,
  128. "Cryptography_HAS_ENGINE": cryptography_has_engine,
  129. "Cryptography_HAS_VERIFIED_CHAIN": cryptography_has_verified_chain,
  130. "Cryptography_HAS_SRTP": cryptography_has_srtp,
  131. "Cryptography_HAS_OP_NO_RENEGOTIATION": (
  132. cryptography_has_op_no_renegotiation
  133. ),
  134. "Cryptography_HAS_DTLS_GET_DATA_MTU": cryptography_has_dtls_get_data_mtu,
  135. "Cryptography_HAS_SSL_COOKIE": cryptography_has_ssl_cookie,
  136. "Cryptography_HAS_PRIME_CHECKS": cryptography_has_prime_checks,
  137. "Cryptography_HAS_UNEXPECTED_EOF_WHILE_READING": (
  138. cryptography_has_unexpected_eof_while_reading
  139. ),
  140. "Cryptography_HAS_SSL_OP_IGNORE_UNEXPECTED_EOF": (
  141. cryptography_has_ssl_op_ignore_unexpected_eof
  142. ),
  143. "Cryptography_HAS_GET_EXTMS_SUPPORT": cryptography_has_get_extms_support,
  144. }