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