_ssl.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #ifndef Py_SSL_H
  2. #define Py_SSL_H
  3. /* OpenSSL header files */
  4. #include "openssl/evp.h"
  5. #include "openssl/x509.h"
  6. /*
  7. * ssl module state
  8. */
  9. typedef struct {
  10. /* Types */
  11. PyTypeObject *PySSLContext_Type;
  12. PyTypeObject *PySSLSocket_Type;
  13. PyTypeObject *PySSLMemoryBIO_Type;
  14. PyTypeObject *PySSLSession_Type;
  15. PyTypeObject *PySSLCertificate_Type;
  16. /* SSL error object */
  17. PyObject *PySSLErrorObject;
  18. PyObject *PySSLCertVerificationErrorObject;
  19. PyObject *PySSLZeroReturnErrorObject;
  20. PyObject *PySSLWantReadErrorObject;
  21. PyObject *PySSLWantWriteErrorObject;
  22. PyObject *PySSLSyscallErrorObject;
  23. PyObject *PySSLEOFErrorObject;
  24. /* Error mappings */
  25. PyObject *err_codes_to_names;
  26. PyObject *lib_codes_to_names;
  27. /* socket type from module CAPI */
  28. PyTypeObject *Sock_Type;
  29. /* Interned strings */
  30. PyObject *str_library;
  31. PyObject *str_reason;
  32. PyObject *str_verify_code;
  33. PyObject *str_verify_message;
  34. /* keylog lock */
  35. PyThread_type_lock keylog_lock;
  36. } _sslmodulestate;
  37. static struct PyModuleDef _sslmodule_def;
  38. Py_LOCAL_INLINE(_sslmodulestate*)
  39. get_ssl_state(PyObject *module)
  40. {
  41. void *state = PyModule_GetState(module);
  42. assert(state != NULL);
  43. return (_sslmodulestate *)state;
  44. }
  45. #define get_state_type(type) \
  46. (get_ssl_state(PyType_GetModuleByDef(type, &_sslmodule_def)))
  47. #define get_state_ctx(c) (((PySSLContext *)(c))->state)
  48. #define get_state_sock(s) (((PySSLSocket *)(s))->ctx->state)
  49. #define get_state_obj(o) ((_sslmodulestate *)PyType_GetModuleState(Py_TYPE(o)))
  50. #define get_state_mbio(b) get_state_obj(b)
  51. #define get_state_cert(c) get_state_obj(c)
  52. /* ************************************************************************
  53. * certificate
  54. */
  55. enum py_ssl_encoding {
  56. PY_SSL_ENCODING_PEM=X509_FILETYPE_PEM,
  57. PY_SSL_ENCODING_DER=X509_FILETYPE_ASN1,
  58. PY_SSL_ENCODING_PEM_AUX=X509_FILETYPE_PEM + 0x100,
  59. };
  60. typedef struct {
  61. PyObject_HEAD
  62. X509 *cert;
  63. Py_hash_t hash;
  64. } PySSLCertificate;
  65. /* ************************************************************************
  66. * helpers and utils
  67. */
  68. static PyObject *_PySSL_BytesFromBIO(_sslmodulestate *state, BIO *bio);
  69. static PyObject *_PySSL_UnicodeFromBIO(_sslmodulestate *state, BIO *bio, const char *error);
  70. #endif /* Py_SSL_H */