_conditional.py 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  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 absolute_import, division, print_function
  5. def cryptography_has_ec2m():
  6. return [
  7. "EC_POINT_set_affine_coordinates_GF2m",
  8. "EC_POINT_get_affine_coordinates_GF2m",
  9. "EC_POINT_set_compressed_coordinates_GF2m",
  10. ]
  11. def cryptography_has_rsa_oaep_md():
  12. return [
  13. "EVP_PKEY_CTX_set_rsa_oaep_md",
  14. ]
  15. def cryptography_has_rsa_oaep_label():
  16. return [
  17. "EVP_PKEY_CTX_set0_rsa_oaep_label",
  18. ]
  19. def cryptography_has_ssl3_method():
  20. return [
  21. "SSLv3_method",
  22. "SSLv3_client_method",
  23. "SSLv3_server_method",
  24. ]
  25. def cryptography_has_102_verification():
  26. return [
  27. "X509_V_ERR_SUITE_B_INVALID_VERSION",
  28. "X509_V_ERR_SUITE_B_INVALID_ALGORITHM",
  29. "X509_V_ERR_SUITE_B_INVALID_CURVE",
  30. "X509_V_ERR_SUITE_B_INVALID_SIGNATURE_ALGORITHM",
  31. "X509_V_ERR_SUITE_B_LOS_NOT_ALLOWED",
  32. "X509_V_ERR_SUITE_B_CANNOT_SIGN_P_384_WITH_P_256",
  33. "X509_V_FLAG_SUITEB_128_LOS_ONLY",
  34. "X509_V_FLAG_SUITEB_192_LOS",
  35. "X509_V_FLAG_SUITEB_128_LOS",
  36. ]
  37. def cryptography_has_110_verification_params():
  38. return ["X509_CHECK_FLAG_NEVER_CHECK_SUBJECT"]
  39. def cryptography_has_set_cert_cb():
  40. return [
  41. "SSL_CTX_set_cert_cb",
  42. "SSL_set_cert_cb",
  43. ]
  44. def cryptography_has_ssl_st():
  45. return [
  46. "SSL_ST_BEFORE",
  47. "SSL_ST_OK",
  48. "SSL_ST_INIT",
  49. "SSL_ST_RENEGOTIATE",
  50. ]
  51. def cryptography_has_tls_st():
  52. return [
  53. "TLS_ST_BEFORE",
  54. "TLS_ST_OK",
  55. ]
  56. def cryptography_has_locking_callbacks():
  57. return [
  58. "Cryptography_setup_ssl_threads",
  59. ]
  60. def cryptography_has_scrypt():
  61. return [
  62. "EVP_PBE_scrypt",
  63. ]
  64. def cryptography_has_evp_pkey_dhx():
  65. return [
  66. "EVP_PKEY_DHX",
  67. ]
  68. def cryptography_has_mem_functions():
  69. return [
  70. "Cryptography_CRYPTO_set_mem_functions",
  71. ]
  72. def cryptography_has_sct():
  73. return [
  74. "SCT_get_version",
  75. "SCT_get_log_entry_type",
  76. "SCT_get0_log_id",
  77. "SCT_get0_signature",
  78. "SCT_get_timestamp",
  79. "SCT_set_source",
  80. "sk_SCT_num",
  81. "sk_SCT_value",
  82. "SCT_LIST_free",
  83. "sk_SCT_push",
  84. "sk_SCT_new_null",
  85. "SCT_new",
  86. "SCT_set1_log_id",
  87. "SCT_set_timestamp",
  88. "SCT_set_version",
  89. "SCT_set_log_entry_type",
  90. ]
  91. def cryptography_has_x509_store_ctx_get_issuer():
  92. return [
  93. "X509_STORE_get_get_issuer",
  94. "X509_STORE_set_get_issuer",
  95. ]
  96. def cryptography_has_x25519():
  97. return [
  98. "EVP_PKEY_X25519",
  99. "NID_X25519",
  100. ]
  101. def cryptography_has_x448():
  102. return [
  103. "EVP_PKEY_X448",
  104. "NID_X448",
  105. ]
  106. def cryptography_has_ed448():
  107. return [
  108. "EVP_PKEY_ED448",
  109. "NID_ED448",
  110. ]
  111. def cryptography_has_ed25519():
  112. return [
  113. "NID_ED25519",
  114. "EVP_PKEY_ED25519",
  115. ]
  116. def cryptography_has_poly1305():
  117. return [
  118. "NID_poly1305",
  119. "EVP_PKEY_POLY1305",
  120. ]
  121. def cryptography_has_oneshot_evp_digest_sign_verify():
  122. return [
  123. "EVP_DigestSign",
  124. "EVP_DigestVerify",
  125. ]
  126. def cryptography_has_evp_digestfinal_xof():
  127. return [
  128. "EVP_DigestFinalXOF",
  129. ]
  130. def cryptography_has_evp_pkey_get_set_tls_encodedpoint():
  131. return [
  132. "EVP_PKEY_get1_tls_encodedpoint",
  133. "EVP_PKEY_set1_tls_encodedpoint",
  134. ]
  135. def cryptography_has_fips():
  136. return [
  137. "FIPS_mode_set",
  138. "FIPS_mode",
  139. ]
  140. def cryptography_has_ssl_sigalgs():
  141. return [
  142. "SSL_CTX_set1_sigalgs_list",
  143. "SSL_get_sigalgs",
  144. ]
  145. def cryptography_has_psk():
  146. return [
  147. "SSL_CTX_use_psk_identity_hint",
  148. "SSL_CTX_set_psk_server_callback",
  149. "SSL_CTX_set_psk_client_callback",
  150. ]
  151. def cryptography_has_custom_ext():
  152. return [
  153. "SSL_CTX_add_client_custom_ext",
  154. "SSL_CTX_add_server_custom_ext",
  155. "SSL_extension_supported",
  156. ]
  157. def cryptography_has_openssl_cleanup():
  158. return [
  159. "OPENSSL_cleanup",
  160. ]
  161. def cryptography_has_cipher_details():
  162. return [
  163. "SSL_CIPHER_is_aead",
  164. "SSL_CIPHER_get_cipher_nid",
  165. "SSL_CIPHER_get_digest_nid",
  166. "SSL_CIPHER_get_kx_nid",
  167. "SSL_CIPHER_get_auth_nid",
  168. ]
  169. def cryptography_has_tlsv13():
  170. return [
  171. "SSL_OP_NO_TLSv1_3",
  172. "SSL_VERIFY_POST_HANDSHAKE",
  173. "SSL_CTX_set_ciphersuites",
  174. "SSL_verify_client_post_handshake",
  175. "SSL_CTX_set_post_handshake_auth",
  176. "SSL_set_post_handshake_auth",
  177. "SSL_SESSION_get_max_early_data",
  178. "SSL_write_early_data",
  179. "SSL_read_early_data",
  180. "SSL_CTX_set_max_early_data",
  181. ]
  182. def cryptography_has_keylog():
  183. return [
  184. "SSL_CTX_set_keylog_callback",
  185. "SSL_CTX_get_keylog_callback",
  186. ]
  187. def cryptography_has_raw_key():
  188. return [
  189. "EVP_PKEY_new_raw_private_key",
  190. "EVP_PKEY_new_raw_public_key",
  191. "EVP_PKEY_get_raw_private_key",
  192. "EVP_PKEY_get_raw_public_key",
  193. ]
  194. def cryptography_has_engine():
  195. return [
  196. "ENGINE_by_id",
  197. "ENGINE_init",
  198. "ENGINE_finish",
  199. "ENGINE_get_default_RAND",
  200. "ENGINE_set_default_RAND",
  201. "ENGINE_unregister_RAND",
  202. "ENGINE_ctrl_cmd",
  203. "ENGINE_free",
  204. "ENGINE_get_name",
  205. "Cryptography_add_osrandom_engine",
  206. "ENGINE_ctrl_cmd_string",
  207. "ENGINE_load_builtin_engines",
  208. "ENGINE_load_private_key",
  209. "ENGINE_load_public_key",
  210. ]
  211. def cryptography_has_verified_chain():
  212. return [
  213. "SSL_get0_verified_chain",
  214. ]
  215. def cryptography_has_srtp():
  216. return [
  217. "SSL_CTX_set_tlsext_use_srtp",
  218. "SSL_set_tlsext_use_srtp",
  219. "SSL_get_selected_srtp_profile",
  220. ]
  221. # This is a mapping of
  222. # {condition: function-returning-names-dependent-on-that-condition} so we can
  223. # loop over them and delete unsupported names at runtime. It will be removed
  224. # when cffi supports #if in cdef. We use functions instead of just a dict of
  225. # lists so we can use coverage to measure which are used.
  226. CONDITIONAL_NAMES = {
  227. "Cryptography_HAS_EC2M": cryptography_has_ec2m,
  228. "Cryptography_HAS_RSA_OAEP_MD": cryptography_has_rsa_oaep_md,
  229. "Cryptography_HAS_RSA_OAEP_LABEL": cryptography_has_rsa_oaep_label,
  230. "Cryptography_HAS_SSL3_METHOD": cryptography_has_ssl3_method,
  231. "Cryptography_HAS_102_VERIFICATION": cryptography_has_102_verification,
  232. "Cryptography_HAS_110_VERIFICATION_PARAMS": (
  233. cryptography_has_110_verification_params
  234. ),
  235. "Cryptography_HAS_SET_CERT_CB": cryptography_has_set_cert_cb,
  236. "Cryptography_HAS_SSL_ST": cryptography_has_ssl_st,
  237. "Cryptography_HAS_TLS_ST": cryptography_has_tls_st,
  238. "Cryptography_HAS_LOCKING_CALLBACKS": cryptography_has_locking_callbacks,
  239. "Cryptography_HAS_SCRYPT": cryptography_has_scrypt,
  240. "Cryptography_HAS_EVP_PKEY_DHX": cryptography_has_evp_pkey_dhx,
  241. "Cryptography_HAS_MEM_FUNCTIONS": cryptography_has_mem_functions,
  242. "Cryptography_HAS_SCT": cryptography_has_sct,
  243. "Cryptography_HAS_X509_STORE_CTX_GET_ISSUER": (
  244. cryptography_has_x509_store_ctx_get_issuer
  245. ),
  246. "Cryptography_HAS_X25519": cryptography_has_x25519,
  247. "Cryptography_HAS_X448": cryptography_has_x448,
  248. "Cryptography_HAS_ED448": cryptography_has_ed448,
  249. "Cryptography_HAS_ED25519": cryptography_has_ed25519,
  250. "Cryptography_HAS_POLY1305": cryptography_has_poly1305,
  251. "Cryptography_HAS_ONESHOT_EVP_DIGEST_SIGN_VERIFY": (
  252. cryptography_has_oneshot_evp_digest_sign_verify
  253. ),
  254. "Cryptography_HAS_EVP_PKEY_get_set_tls_encodedpoint": (
  255. cryptography_has_evp_pkey_get_set_tls_encodedpoint
  256. ),
  257. "Cryptography_HAS_FIPS": cryptography_has_fips,
  258. "Cryptography_HAS_SIGALGS": cryptography_has_ssl_sigalgs,
  259. "Cryptography_HAS_PSK": cryptography_has_psk,
  260. "Cryptography_HAS_CUSTOM_EXT": cryptography_has_custom_ext,
  261. "Cryptography_HAS_OPENSSL_CLEANUP": cryptography_has_openssl_cleanup,
  262. "Cryptography_HAS_CIPHER_DETAILS": cryptography_has_cipher_details,
  263. "Cryptography_HAS_TLSv1_3": cryptography_has_tlsv13,
  264. "Cryptography_HAS_KEYLOG": cryptography_has_keylog,
  265. "Cryptography_HAS_RAW_KEY": cryptography_has_raw_key,
  266. "Cryptography_HAS_EVP_DIGESTFINAL_XOF": (
  267. cryptography_has_evp_digestfinal_xof
  268. ),
  269. "Cryptography_HAS_ENGINE": cryptography_has_engine,
  270. "Cryptography_HAS_VERIFIED_CHAIN": cryptography_has_verified_chain,
  271. "Cryptography_HAS_SRTP": cryptography_has_srtp,
  272. }