Lines 55-60
static PySocketModule_APIObject PySocketModule;
Link Here
|
55 |
#include <sys/poll.h> |
55 |
#include <sys/poll.h> |
56 |
#endif |
56 |
#endif |
57 |
|
57 |
|
|
|
58 |
/* Don't warn about deprecated functions */ |
59 |
#ifdef __GNUC__ |
60 |
#pragma GCC diagnostic ignored "-Wdeprecated-declarations" |
61 |
#endif |
62 |
#ifdef __clang__ |
63 |
#pragma clang diagnostic ignored "-Wdeprecated-declarations" |
64 |
#endif |
65 |
|
58 |
/* Include OpenSSL header files */ |
66 |
/* Include OpenSSL header files */ |
59 |
#include "openssl/rsa.h" |
67 |
#include "openssl/rsa.h" |
60 |
#include "openssl/crypto.h" |
68 |
#include "openssl/crypto.h" |
Lines 90-95
struct py_ssl_library_code {
Link Here
|
90 |
/* Include generated data (error codes) */ |
98 |
/* Include generated data (error codes) */ |
91 |
#include "_ssl_data.h" |
99 |
#include "_ssl_data.h" |
92 |
|
100 |
|
|
|
101 |
#if (OPENSSL_VERSION_NUMBER >= 0x10100000L) && !defined(LIBRESSL_VERSION_NUMBER) |
102 |
# define OPENSSL_VERSION_1_1 1 |
103 |
#endif |
104 |
|
93 |
/* Openssl comes with TLSv1.1 and TLSv1.2 between 1.0.0h and 1.0.1 |
105 |
/* Openssl comes with TLSv1.1 and TLSv1.2 between 1.0.0h and 1.0.1 |
94 |
http://www.openssl.org/news/changelog.html |
106 |
http://www.openssl.org/news/changelog.html |
95 |
*/ |
107 |
*/ |
Lines 108-113
struct py_ssl_library_code {
Link Here
|
108 |
# define HAVE_SNI 0 |
120 |
# define HAVE_SNI 0 |
109 |
#endif |
121 |
#endif |
110 |
|
122 |
|
|
|
123 |
#ifndef INVALID_SOCKET /* MS defines this */ |
124 |
#define INVALID_SOCKET (-1) |
125 |
#endif |
126 |
|
127 |
#ifdef OPENSSL_VERSION_1_1 |
128 |
/* OpenSSL 1.1.0+ */ |
129 |
#ifndef OPENSSL_NO_SSL2 |
130 |
#define OPENSSL_NO_SSL2 |
131 |
#endif |
132 |
#else /* OpenSSL < 1.1.0 */ |
133 |
#if defined(WITH_THREAD) |
134 |
#define HAVE_OPENSSL_CRYPTO_LOCK |
135 |
#endif |
136 |
|
137 |
#define TLS_method SSLv23_method |
138 |
|
139 |
static int X509_NAME_ENTRY_set(const X509_NAME_ENTRY *ne) |
140 |
{ |
141 |
return ne->set; |
142 |
} |
143 |
|
144 |
#ifndef OPENSSL_NO_COMP |
145 |
static int COMP_get_type(const COMP_METHOD *meth) |
146 |
{ |
147 |
return meth->type; |
148 |
} |
149 |
|
150 |
static const char *COMP_get_name(const COMP_METHOD *meth) |
151 |
{ |
152 |
return meth->name; |
153 |
} |
154 |
#endif |
155 |
|
156 |
static pem_password_cb *SSL_CTX_get_default_passwd_cb(SSL_CTX *ctx) |
157 |
{ |
158 |
return ctx->default_passwd_callback; |
159 |
} |
160 |
|
161 |
static void *SSL_CTX_get_default_passwd_cb_userdata(SSL_CTX *ctx) |
162 |
{ |
163 |
return ctx->default_passwd_callback_userdata; |
164 |
} |
165 |
|
166 |
static int X509_OBJECT_get_type(X509_OBJECT *x) |
167 |
{ |
168 |
return x->type; |
169 |
} |
170 |
|
171 |
static X509 *X509_OBJECT_get0_X509(X509_OBJECT *x) |
172 |
{ |
173 |
return x->data.x509; |
174 |
} |
175 |
|
176 |
static int BIO_up_ref(BIO *b) |
177 |
{ |
178 |
CRYPTO_add(&b->references, 1, CRYPTO_LOCK_BIO); |
179 |
return 1; |
180 |
} |
181 |
|
182 |
static STACK_OF(X509_OBJECT) *X509_STORE_get0_objects(X509_STORE *store) { |
183 |
return store->objs; |
184 |
} |
185 |
|
186 |
static X509_VERIFY_PARAM *X509_STORE_get0_param(X509_STORE *store) |
187 |
{ |
188 |
return store->param; |
189 |
} |
190 |
#endif /* OpenSSL < 1.1.0 or LibreSSL */ |
191 |
|
192 |
|
111 |
enum py_ssl_error { |
193 |
enum py_ssl_error { |
112 |
/* these mirror ssl.h */ |
194 |
/* these mirror ssl.h */ |
113 |
PY_SSL_ERROR_NONE, |
195 |
PY_SSL_ERROR_NONE, |
Lines 138-144
enum py_ssl_cert_requirements {
Link Here
|
138 |
enum py_ssl_version { |
220 |
enum py_ssl_version { |
139 |
PY_SSL_VERSION_SSL2, |
221 |
PY_SSL_VERSION_SSL2, |
140 |
PY_SSL_VERSION_SSL3=1, |
222 |
PY_SSL_VERSION_SSL3=1, |
141 |
PY_SSL_VERSION_SSL23, |
223 |
PY_SSL_VERSION_TLS, |
142 |
#if HAVE_TLSv1_2 |
224 |
#if HAVE_TLSv1_2 |
143 |
PY_SSL_VERSION_TLS1, |
225 |
PY_SSL_VERSION_TLS1, |
144 |
PY_SSL_VERSION_TLS1_1, |
226 |
PY_SSL_VERSION_TLS1_1, |
Lines 504-510
newPySSLSocket(PySSLContext *sslctx, PySocketSockObject *sock,
Link Here
|
504 |
PySSL_BEGIN_ALLOW_THREADS |
586 |
PySSL_BEGIN_ALLOW_THREADS |
505 |
self->ssl = SSL_new(ctx); |
587 |
self->ssl = SSL_new(ctx); |
506 |
PySSL_END_ALLOW_THREADS |
588 |
PySSL_END_ALLOW_THREADS |
507 |
SSL_set_app_data(self->ssl,self); |
589 |
SSL_set_app_data(self->ssl, self); |
508 |
SSL_set_fd(self->ssl, Py_SAFE_DOWNCAST(sock->sock_fd, SOCKET_T, int)); |
590 |
SSL_set_fd(self->ssl, Py_SAFE_DOWNCAST(sock->sock_fd, SOCKET_T, int)); |
509 |
mode = SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER; |
591 |
mode = SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER; |
510 |
#ifdef SSL_MODE_AUTO_RETRY |
592 |
#ifdef SSL_MODE_AUTO_RETRY |
Lines 691-697
_create_tuple_for_X509_NAME (X509_NAME *xname)
Link Here
|
691 |
|
773 |
|
692 |
/* check to see if we've gotten to a new RDN */ |
774 |
/* check to see if we've gotten to a new RDN */ |
693 |
if (rdn_level >= 0) { |
775 |
if (rdn_level >= 0) { |
694 |
if (rdn_level != entry->set) { |
776 |
if (rdn_level != X509_NAME_ENTRY_set(entry)) { |
695 |
/* yes, new RDN */ |
777 |
/* yes, new RDN */ |
696 |
/* add old RDN to DN */ |
778 |
/* add old RDN to DN */ |
697 |
rdnt = PyList_AsTuple(rdn); |
779 |
rdnt = PyList_AsTuple(rdn); |
Lines 708-714
_create_tuple_for_X509_NAME (X509_NAME *xname)
Link Here
|
708 |
goto fail0; |
790 |
goto fail0; |
709 |
} |
791 |
} |
710 |
} |
792 |
} |
711 |
rdn_level = entry->set; |
793 |
rdn_level = X509_NAME_ENTRY_set(entry); |
712 |
|
794 |
|
713 |
/* now add this attribute to the current RDN */ |
795 |
/* now add this attribute to the current RDN */ |
714 |
name = X509_NAME_ENTRY_get_object(entry); |
796 |
name = X509_NAME_ENTRY_get_object(entry); |
Lines 811-828
_get_peer_alt_names (X509 *certificate) {
Link Here
|
811 |
goto fail; |
893 |
goto fail; |
812 |
} |
894 |
} |
813 |
|
895 |
|
814 |
p = ext->value->data; |
896 |
p = X509_EXTENSION_get_data(ext)->data; |
815 |
if (method->it) |
897 |
if (method->it) |
816 |
names = (GENERAL_NAMES*) |
898 |
names = (GENERAL_NAMES*) |
817 |
(ASN1_item_d2i(NULL, |
899 |
(ASN1_item_d2i(NULL, |
818 |
&p, |
900 |
&p, |
819 |
ext->value->length, |
901 |
X509_EXTENSION_get_data(ext)->length, |
820 |
ASN1_ITEM_ptr(method->it))); |
902 |
ASN1_ITEM_ptr(method->it))); |
821 |
else |
903 |
else |
822 |
names = (GENERAL_NAMES*) |
904 |
names = (GENERAL_NAMES*) |
823 |
(method->d2i(NULL, |
905 |
(method->d2i(NULL, |
824 |
&p, |
906 |
&p, |
825 |
ext->value->length)); |
907 |
X509_EXTENSION_get_data(ext)->length)); |
826 |
|
908 |
|
827 |
for(j = 0; j < sk_GENERAL_NAME_num(names); j++) { |
909 |
for(j = 0; j < sk_GENERAL_NAME_num(names); j++) { |
828 |
/* get a rendering of each name in the set of names */ |
910 |
/* get a rendering of each name in the set of names */ |
Lines 1033-1045
_get_crl_dp(X509 *certificate) {
Link Here
|
1033 |
int i, j; |
1115 |
int i, j; |
1034 |
PyObject *lst, *res = NULL; |
1116 |
PyObject *lst, *res = NULL; |
1035 |
|
1117 |
|
1036 |
#if OPENSSL_VERSION_NUMBER < 0x10001000L |
1118 |
#if OPENSSL_VERSION_NUMBER >= 0x10001000L |
1037 |
dps = X509_get_ext_d2i(certificate, NID_crl_distribution_points, NULL, NULL); |
|
|
1038 |
#else |
1039 |
/* Calls x509v3_cache_extensions and sets up crldp */ |
1119 |
/* Calls x509v3_cache_extensions and sets up crldp */ |
1040 |
X509_check_ca(certificate); |
1120 |
X509_check_ca(certificate); |
1041 |
dps = certificate->crldp; |
|
|
1042 |
#endif |
1121 |
#endif |
|
|
1122 |
dps = X509_get_ext_d2i(certificate, NID_crl_distribution_points, NULL, NULL); |
1043 |
|
1123 |
|
1044 |
if (dps == NULL) |
1124 |
if (dps == NULL) |
1045 |
return Py_None; |
1125 |
return Py_None; |
Lines 1403-1408
static PyObject *PySSL_cipher (PySSLSocket *self) {
Link Here
|
1403 |
return NULL; |
1483 |
return NULL; |
1404 |
} |
1484 |
} |
1405 |
|
1485 |
|
|
|
1486 |
/*[clinic input] |
1487 |
_ssl._SSLSocket.shared_ciphers |
1488 |
[clinic start generated code]*/ |
1489 |
|
1490 |
static PyObject * |
1491 |
_ssl__SSLSocket_shared_ciphers_impl(PySSLSocket *self) |
1492 |
/*[clinic end generated code: output=3d174ead2e42c4fd input=0bfe149da8fe6306]*/ |
1493 |
{ |
1494 |
STACK_OF(SSL_CIPHER) *ciphers; |
1495 |
int i; |
1496 |
PyObject *res; |
1497 |
|
1498 |
ciphers = SSL_get_ciphers(self->ssl); |
1499 |
if (!ciphers) |
1500 |
Py_RETURN_NONE; |
1501 |
res = PyList_New(sk_SSL_CIPHER_num(ciphers)); |
1502 |
if (!res) |
1503 |
return NULL; |
1504 |
for (i = 0; i < sk_SSL_CIPHER_num(ciphers); i++) { |
1505 |
PyObject *tup = cipher_to_tuple(sk_SSL_CIPHER_value(ciphers, i)); |
1506 |
if (!tup) { |
1507 |
Py_DECREF(res); |
1508 |
return NULL; |
1509 |
} |
1510 |
PyList_SET_ITEM(res, i, tup); |
1511 |
} |
1512 |
return res; |
1513 |
} |
1514 |
|
1515 |
/*[clinic input] |
1516 |
_ssl._SSLSocket.cipher |
1517 |
[clinic start generated code]*/ |
1518 |
|
1519 |
static PyObject * |
1520 |
_ssl__SSLSocket_cipher_impl(PySSLSocket *self) |
1521 |
/*[clinic end generated code: output=376417c16d0e5815 input=548fb0e27243796d]*/ |
1522 |
{ |
1523 |
const SSL_CIPHER *current; |
1524 |
|
1525 |
if (self->ssl == NULL) |
1526 |
Py_RETURN_NONE; |
1527 |
current = SSL_get_current_cipher(self->ssl); |
1528 |
if (current == NULL) |
1529 |
Py_RETURN_NONE; |
1530 |
return cipher_to_tuple(current); |
1531 |
} |
1532 |
|
1533 |
/*[clinic input] |
1534 |
_ssl._SSLSocket.version |
1535 |
[clinic start generated code]*/ |
1536 |
|
1537 |
static PyObject * |
1538 |
_ssl__SSLSocket_version_impl(PySSLSocket *self) |
1539 |
/*[clinic end generated code: output=178aed33193b2cdb input=900186a503436fd6]*/ |
1540 |
{ |
1541 |
const char *version; |
1542 |
|
1543 |
if (self->ssl == NULL) |
1544 |
Py_RETURN_NONE; |
1545 |
version = SSL_get_version(self->ssl); |
1546 |
if (!strcmp(version, "unknown")) |
1547 |
Py_RETURN_NONE; |
1548 |
return PyUnicode_FromString(version); |
1549 |
} |
1550 |
|
1406 |
#ifdef OPENSSL_NPN_NEGOTIATED |
1551 |
#ifdef OPENSSL_NPN_NEGOTIATED |
1407 |
static PyObject *PySSL_selected_npn_protocol(PySSLSocket *self) { |
1552 |
static PyObject *PySSL_selected_npn_protocol(PySSLSocket *self) { |
1408 |
const unsigned char *out; |
1553 |
const unsigned char *out; |
Lines 1427-1435
static PyObject *PySSL_compression(PySSLSocket *self) {
Link Here
|
1427 |
if (self->ssl == NULL) |
1572 |
if (self->ssl == NULL) |
1428 |
Py_RETURN_NONE; |
1573 |
Py_RETURN_NONE; |
1429 |
comp_method = SSL_get_current_compression(self->ssl); |
1574 |
comp_method = SSL_get_current_compression(self->ssl); |
1430 |
if (comp_method == NULL || comp_method->type == NID_undef) |
1575 |
if (comp_method == NULL || COMP_get_type(comp_method) == NID_undef) |
1431 |
Py_RETURN_NONE; |
1576 |
Py_RETURN_NONE; |
1432 |
short_name = OBJ_nid2sn(comp_method->type); |
1577 |
short_name = COMP_get_name(comp_method); |
1433 |
if (short_name == NULL) |
1578 |
if (short_name == NULL) |
1434 |
Py_RETURN_NONE; |
1579 |
Py_RETURN_NONE; |
1435 |
return PyUnicode_DecodeFSDefault(short_name); |
1580 |
return PyUnicode_DecodeFSDefault(short_name); |
Lines 1977-1983
context_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
Link Here
|
1977 |
{ |
2122 |
{ |
1978 |
char *kwlist[] = {"protocol", NULL}; |
2123 |
char *kwlist[] = {"protocol", NULL}; |
1979 |
PySSLContext *self; |
2124 |
PySSLContext *self; |
1980 |
int proto_version = PY_SSL_VERSION_SSL23; |
2125 |
int proto_version = PY_SSL_VERSION_TLS; |
1981 |
long options; |
2126 |
long options; |
1982 |
SSL_CTX *ctx = NULL; |
2127 |
SSL_CTX *ctx = NULL; |
1983 |
|
2128 |
|
Lines 2003-2010
context_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
Link Here
|
2003 |
else if (proto_version == PY_SSL_VERSION_SSL2) |
2148 |
else if (proto_version == PY_SSL_VERSION_SSL2) |
2004 |
ctx = SSL_CTX_new(SSLv2_method()); |
2149 |
ctx = SSL_CTX_new(SSLv2_method()); |
2005 |
#endif |
2150 |
#endif |
2006 |
else if (proto_version == PY_SSL_VERSION_SSL23) |
2151 |
else if (proto_version == PY_SSL_VERSION_TLS) |
2007 |
ctx = SSL_CTX_new(SSLv23_method()); |
2152 |
ctx = SSL_CTX_new(TLS_method()); |
2008 |
else |
2153 |
else |
2009 |
proto_version = -1; |
2154 |
proto_version = -1; |
2010 |
PySSL_END_ALLOW_THREADS |
2155 |
PySSL_END_ALLOW_THREADS |
Lines 2047-2054
context_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
Link Here
|
2047 |
#ifndef OPENSSL_NO_ECDH |
2192 |
#ifndef OPENSSL_NO_ECDH |
2048 |
/* Allow automatic ECDH curve selection (on OpenSSL 1.0.2+), or use |
2193 |
/* Allow automatic ECDH curve selection (on OpenSSL 1.0.2+), or use |
2049 |
prime256v1 by default. This is Apache mod_ssl's initialization |
2194 |
prime256v1 by default. This is Apache mod_ssl's initialization |
2050 |
policy, so we should be safe. */ |
2195 |
policy, so we should be safe. OpenSSL 1.1 has it enabled by default. |
2051 |
#if defined(SSL_CTX_set_ecdh_auto) |
2196 |
*/ |
|
|
2197 |
#if defined(SSL_CTX_set_ecdh_auto) && !defined(OPENSSL_VERSION_1_1) |
2052 |
SSL_CTX_set_ecdh_auto(self->ctx, 1); |
2198 |
SSL_CTX_set_ecdh_auto(self->ctx, 1); |
2053 |
#else |
2199 |
#else |
2054 |
{ |
2200 |
{ |
Lines 2259-2268
static PyObject *
Link Here
|
2259 |
get_verify_flags(PySSLContext *self, void *c) |
2405 |
get_verify_flags(PySSLContext *self, void *c) |
2260 |
{ |
2406 |
{ |
2261 |
X509_STORE *store; |
2407 |
X509_STORE *store; |
|
|
2408 |
X509_VERIFY_PARAM *param; |
2262 |
unsigned long flags; |
2409 |
unsigned long flags; |
2263 |
|
2410 |
|
2264 |
store = SSL_CTX_get_cert_store(self->ctx); |
2411 |
store = SSL_CTX_get_cert_store(self->ctx); |
2265 |
flags = X509_VERIFY_PARAM_get_flags(store->param); |
2412 |
param = X509_STORE_get0_param(store); |
|
|
2413 |
flags = X509_VERIFY_PARAM_get_flags(param); |
2266 |
return PyLong_FromUnsignedLong(flags); |
2414 |
return PyLong_FromUnsignedLong(flags); |
2267 |
} |
2415 |
} |
2268 |
|
2416 |
|
Lines 2270-2291
static int
Link Here
|
2270 |
set_verify_flags(PySSLContext *self, PyObject *arg, void *c) |
2418 |
set_verify_flags(PySSLContext *self, PyObject *arg, void *c) |
2271 |
{ |
2419 |
{ |
2272 |
X509_STORE *store; |
2420 |
X509_STORE *store; |
|
|
2421 |
X509_VERIFY_PARAM *param; |
2273 |
unsigned long new_flags, flags, set, clear; |
2422 |
unsigned long new_flags, flags, set, clear; |
2274 |
|
2423 |
|
2275 |
if (!PyArg_Parse(arg, "k", &new_flags)) |
2424 |
if (!PyArg_Parse(arg, "k", &new_flags)) |
2276 |
return -1; |
2425 |
return -1; |
2277 |
store = SSL_CTX_get_cert_store(self->ctx); |
2426 |
store = SSL_CTX_get_cert_store(self->ctx); |
2278 |
flags = X509_VERIFY_PARAM_get_flags(store->param); |
2427 |
param = X509_STORE_get0_param(store); |
|
|
2428 |
flags = X509_VERIFY_PARAM_get_flags(param); |
2279 |
clear = flags & ~new_flags; |
2429 |
clear = flags & ~new_flags; |
2280 |
set = ~flags & new_flags; |
2430 |
set = ~flags & new_flags; |
2281 |
if (clear) { |
2431 |
if (clear) { |
2282 |
if (!X509_VERIFY_PARAM_clear_flags(store->param, clear)) { |
2432 |
if (!X509_VERIFY_PARAM_clear_flags(param, clear)) { |
2283 |
_setSSLError(NULL, 0, __FILE__, __LINE__); |
2433 |
_setSSLError(NULL, 0, __FILE__, __LINE__); |
2284 |
return -1; |
2434 |
return -1; |
2285 |
} |
2435 |
} |
2286 |
} |
2436 |
} |
2287 |
if (set) { |
2437 |
if (set) { |
2288 |
if (!X509_VERIFY_PARAM_set_flags(store->param, set)) { |
2438 |
if (!X509_VERIFY_PARAM_set_flags(param, set)) { |
2289 |
_setSSLError(NULL, 0, __FILE__, __LINE__); |
2439 |
_setSSLError(NULL, 0, __FILE__, __LINE__); |
2290 |
return -1; |
2440 |
return -1; |
2291 |
} |
2441 |
} |
Lines 2455-2462
load_cert_chain(PySSLContext *self, PyObject *args, PyObject *kwds)
Link Here
|
2455 |
char *kwlist[] = {"certfile", "keyfile", "password", NULL}; |
2605 |
char *kwlist[] = {"certfile", "keyfile", "password", NULL}; |
2456 |
PyObject *certfile, *keyfile = NULL, *password = NULL; |
2606 |
PyObject *certfile, *keyfile = NULL, *password = NULL; |
2457 |
PyObject *certfile_bytes = NULL, *keyfile_bytes = NULL; |
2607 |
PyObject *certfile_bytes = NULL, *keyfile_bytes = NULL; |
2458 |
pem_password_cb *orig_passwd_cb = self->ctx->default_passwd_callback; |
2608 |
pem_password_cb *orig_passwd_cb = SSL_CTX_get_default_passwd_cb(self->ctx); |
2459 |
void *orig_passwd_userdata = self->ctx->default_passwd_callback_userdata; |
2609 |
void *orig_passwd_userdata = SSL_CTX_get_default_passwd_cb_userdata(self->ctx); |
2460 |
_PySSLPasswordInfo pw_info = { NULL, NULL, NULL, 0, 0 }; |
2610 |
_PySSLPasswordInfo pw_info = { NULL, NULL, NULL, 0, 0 }; |
2461 |
int r; |
2611 |
int r; |
2462 |
|
2612 |
|
Lines 2587-2594
_add_ca_certs(PySSLContext *self, void *data, Py_ssize_t len,
Link Here
|
2587 |
cert = d2i_X509_bio(biobuf, NULL); |
2737 |
cert = d2i_X509_bio(biobuf, NULL); |
2588 |
} else { |
2738 |
} else { |
2589 |
cert = PEM_read_bio_X509(biobuf, NULL, |
2739 |
cert = PEM_read_bio_X509(biobuf, NULL, |
2590 |
self->ctx->default_passwd_callback, |
2740 |
SSL_CTX_get_default_passwd_cb(self->ctx), |
2591 |
self->ctx->default_passwd_callback_userdata); |
2741 |
SSL_CTX_get_default_passwd_cb_userdata(self->ctx) |
|
|
2742 |
); |
2592 |
} |
2743 |
} |
2593 |
if (cert == NULL) { |
2744 |
if (cert == NULL) { |
2594 |
break; |
2745 |
break; |
Lines 3036-3060
static PyObject *
Link Here
|
3036 |
cert_store_stats(PySSLContext *self) |
3187 |
cert_store_stats(PySSLContext *self) |
3037 |
{ |
3188 |
{ |
3038 |
X509_STORE *store; |
3189 |
X509_STORE *store; |
|
|
3190 |
STACK_OF(X509_OBJECT) *objs; |
3039 |
X509_OBJECT *obj; |
3191 |
X509_OBJECT *obj; |
3040 |
int x509 = 0, crl = 0, pkey = 0, ca = 0, i; |
3192 |
int x509 = 0, crl = 0, ca = 0, i; |
3041 |
|
3193 |
|
3042 |
store = SSL_CTX_get_cert_store(self->ctx); |
3194 |
store = SSL_CTX_get_cert_store(self->ctx); |
3043 |
for (i = 0; i < sk_X509_OBJECT_num(store->objs); i++) { |
3195 |
objs = X509_STORE_get0_objects(store); |
3044 |
obj = sk_X509_OBJECT_value(store->objs, i); |
3196 |
for (i = 0; i < sk_X509_OBJECT_num(objs); i++) { |
3045 |
switch (obj->type) { |
3197 |
obj = sk_X509_OBJECT_value(objs, i); |
|
|
3198 |
switch (X509_OBJECT_get_type(obj)) { |
3046 |
case X509_LU_X509: |
3199 |
case X509_LU_X509: |
3047 |
x509++; |
3200 |
x509++; |
3048 |
if (X509_check_ca(obj->data.x509)) { |
3201 |
if (X509_check_ca(X509_OBJECT_get0_X509(obj))) { |
3049 |
ca++; |
3202 |
ca++; |
3050 |
} |
3203 |
} |
3051 |
break; |
3204 |
break; |
3052 |
case X509_LU_CRL: |
3205 |
case X509_LU_CRL: |
3053 |
crl++; |
3206 |
crl++; |
3054 |
break; |
3207 |
break; |
3055 |
case X509_LU_PKEY: |
|
|
3056 |
pkey++; |
3057 |
break; |
3058 |
default: |
3208 |
default: |
3059 |
/* Ignore X509_LU_FAIL, X509_LU_RETRY, X509_LU_PKEY. |
3209 |
/* Ignore X509_LU_FAIL, X509_LU_RETRY, X509_LU_PKEY. |
3060 |
* As far as I can tell they are internal states and never |
3210 |
* As far as I can tell they are internal states and never |
Lines 3079-3084
get_ca_certs(PySSLContext *self, PyObject *args, PyObject *kwds)
Link Here
|
3079 |
{ |
3229 |
{ |
3080 |
char *kwlist[] = {"binary_form", NULL}; |
3230 |
char *kwlist[] = {"binary_form", NULL}; |
3081 |
X509_STORE *store; |
3231 |
X509_STORE *store; |
|
|
3232 |
STACK_OF(X509_OBJECT) *objs; |
3082 |
PyObject *ci = NULL, *rlist = NULL; |
3233 |
PyObject *ci = NULL, *rlist = NULL; |
3083 |
int i; |
3234 |
int i; |
3084 |
int binary_mode = 0; |
3235 |
int binary_mode = 0; |
Lines 3093-3109
get_ca_certs(PySSLContext *self, PyObject *args, PyObject *kwds)
Link Here
|
3093 |
} |
3244 |
} |
3094 |
|
3245 |
|
3095 |
store = SSL_CTX_get_cert_store(self->ctx); |
3246 |
store = SSL_CTX_get_cert_store(self->ctx); |
3096 |
for (i = 0; i < sk_X509_OBJECT_num(store->objs); i++) { |
3247 |
objs = X509_STORE_get0_objects(store); |
|
|
3248 |
for (i = 0; i < sk_X509_OBJECT_num(objs); i++) { |
3097 |
X509_OBJECT *obj; |
3249 |
X509_OBJECT *obj; |
3098 |
X509 *cert; |
3250 |
X509 *cert; |
3099 |
|
3251 |
|
3100 |
obj = sk_X509_OBJECT_value(store->objs, i); |
3252 |
obj = sk_X509_OBJECT_value(objs, i); |
3101 |
if (obj->type != X509_LU_X509) { |
3253 |
if (X509_OBJECT_get_type(obj) != X509_LU_X509) { |
3102 |
/* not a x509 cert */ |
3254 |
/* not a x509 cert */ |
3103 |
continue; |
3255 |
continue; |
3104 |
} |
3256 |
} |
3105 |
/* CA for any purpose */ |
3257 |
/* CA for any purpose */ |
3106 |
cert = obj->data.x509; |
3258 |
cert = X509_OBJECT_get0_X509(obj); |
3107 |
if (!X509_check_ca(cert)) { |
3259 |
if (!X509_check_ca(cert)) { |
3108 |
continue; |
3260 |
continue; |
3109 |
} |
3261 |
} |
Lines 3776-3785
static PyMethodDef PySSL_methods[] = {
Link Here
|
3776 |
}; |
3928 |
}; |
3777 |
|
3929 |
|
3778 |
|
3930 |
|
3779 |
#ifdef WITH_THREAD |
3931 |
#ifdef HAVE_OPENSSL_CRYPTO_LOCK |
3780 |
|
3932 |
|
3781 |
/* an implementation of OpenSSL threading operations in terms |
3933 |
/* an implementation of OpenSSL threading operations in terms |
3782 |
of the Python C thread library */ |
3934 |
* of the Python C thread library |
|
|
3935 |
* Only used up to 1.0.2. OpenSSL 1.1.0+ has its own locking code. |
3936 |
*/ |
3783 |
|
3937 |
|
3784 |
static PyThread_type_lock *_ssl_locks = NULL; |
3938 |
static PyThread_type_lock *_ssl_locks = NULL; |
3785 |
|
3939 |
|
Lines 3860-3866
static int _setup_ssl_threads(void) {
Link Here
|
3860 |
return 1; |
4014 |
return 1; |
3861 |
} |
4015 |
} |
3862 |
|
4016 |
|
3863 |
#endif /* def HAVE_THREAD */ |
4017 |
#endif /* HAVE_OPENSSL_CRYPTO_LOCK for WITH_THREAD && OpenSSL < 1.1.0 */ |
3864 |
|
4018 |
|
3865 |
PyDoc_STRVAR(module_doc, |
4019 |
PyDoc_STRVAR(module_doc, |
3866 |
"Implementation module for SSL socket operations. See the socket module\n\ |
4020 |
"Implementation module for SSL socket operations. See the socket module\n\ |
Lines 3927-3937
PyInit__ssl(void)
Link Here
|
3927 |
SSL_load_error_strings(); |
4081 |
SSL_load_error_strings(); |
3928 |
SSL_library_init(); |
4082 |
SSL_library_init(); |
3929 |
#ifdef WITH_THREAD |
4083 |
#ifdef WITH_THREAD |
|
|
4084 |
#ifdef HAVE_OPENSSL_CRYPTO_LOCK |
3930 |
/* note that this will start threading if not already started */ |
4085 |
/* note that this will start threading if not already started */ |
3931 |
if (!_setup_ssl_threads()) { |
4086 |
if (!_setup_ssl_threads()) { |
3932 |
return NULL; |
4087 |
return NULL; |
3933 |
} |
4088 |
} |
|
|
4089 |
#elif OPENSSL_VERSION_1_1 && defined(OPENSSL_THREADS) |
4090 |
/* OpenSSL 1.1.0 builtin thread support is enabled */ |
4091 |
_ssl_locks_count++; |
3934 |
#endif |
4092 |
#endif |
|
|
4093 |
#endif /* WITH_THREAD */ |
3935 |
OpenSSL_add_all_algorithms(); |
4094 |
OpenSSL_add_all_algorithms(); |
3936 |
|
4095 |
|
3937 |
/* Add symbols to module dict */ |
4096 |
/* Add symbols to module dict */ |
Lines 4075-4081
PyInit__ssl(void)
Link Here
|
4075 |
PY_SSL_VERSION_SSL3); |
4234 |
PY_SSL_VERSION_SSL3); |
4076 |
#endif |
4235 |
#endif |
4077 |
PyModule_AddIntConstant(m, "PROTOCOL_SSLv23", |
4236 |
PyModule_AddIntConstant(m, "PROTOCOL_SSLv23", |
4078 |
PY_SSL_VERSION_SSL23); |
4237 |
PY_SSL_VERSION_TLS); |
|
|
4238 |
PyModule_AddIntConstant(m, "PROTOCOL_TLS", |
4239 |
PY_SSL_VERSION_TLS); |
4079 |
PyModule_AddIntConstant(m, "PROTOCOL_TLSv1", |
4240 |
PyModule_AddIntConstant(m, "PROTOCOL_TLSv1", |
4080 |
PY_SSL_VERSION_TLS1); |
4241 |
PY_SSL_VERSION_TLS1); |
4081 |
#if HAVE_TLSv1_2 |
4242 |
#if HAVE_TLSv1_2 |