Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
allendowney
GitHub Repository: allendowney/cpython
Path: blob/main/Modules/_ssl.h
12 views
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 *lib_codes_to_names;
29
/* socket type from module CAPI */
30
PyTypeObject *Sock_Type;
31
/* Interned strings */
32
PyObject *str_library;
33
PyObject *str_reason;
34
PyObject *str_verify_code;
35
PyObject *str_verify_message;
36
/* keylog lock */
37
PyThread_type_lock keylog_lock;
38
} _sslmodulestate;
39
40
static struct PyModuleDef _sslmodule_def;
41
42
Py_LOCAL_INLINE(_sslmodulestate*)
43
get_ssl_state(PyObject *module)
44
{
45
void *state = PyModule_GetState(module);
46
assert(state != NULL);
47
return (_sslmodulestate *)state;
48
}
49
50
#define get_state_type(type) \
51
(get_ssl_state(PyType_GetModuleByDef(type, &_sslmodule_def)))
52
#define get_state_ctx(c) (((PySSLContext *)(c))->state)
53
#define get_state_sock(s) (((PySSLSocket *)(s))->ctx->state)
54
#define get_state_obj(o) ((_sslmodulestate *)PyType_GetModuleState(Py_TYPE(o)))
55
#define get_state_mbio(b) get_state_obj(b)
56
#define get_state_cert(c) get_state_obj(c)
57
58
/* ************************************************************************
59
* certificate
60
*/
61
62
enum py_ssl_encoding {
63
PY_SSL_ENCODING_PEM=X509_FILETYPE_PEM,
64
PY_SSL_ENCODING_DER=X509_FILETYPE_ASN1,
65
PY_SSL_ENCODING_PEM_AUX=X509_FILETYPE_PEM + 0x100,
66
};
67
68
typedef struct {
69
PyObject_HEAD
70
X509 *cert;
71
Py_hash_t hash;
72
} PySSLCertificate;
73
74
/* ************************************************************************
75
* helpers and utils
76
*/
77
static PyObject *_PySSL_BytesFromBIO(_sslmodulestate *state, BIO *bio);
78
static PyObject *_PySSL_UnicodeFromBIO(_sslmodulestate *state, BIO *bio, const char *error);
79
80
#endif /* Py_SSL_H */
81
82