Mercurial > cpython-lru_cache-weakref
annotate Modules/_ssl.c @ 86127:a3d09c19bb93
merge with 3.3
| author | Georg Brandl <georg@python.org> |
|---|---|
| date | Sun, 06 Oct 2013 19:24:00 +0200 |
| parents | 2b1f1a42d1e1 |
| children | d3a13a7be9e9 |
| rev | line source |
|---|---|
|
42954
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
1 /* SSL socket module |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
2 |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
3 SSL support based on patches by Brian E Gallew and Laszlo Kovacs. |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
4 Re-worked a bit by Bill Janssen to add server-side support and |
|
43869
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
5 certificate decoding. Chris Stawarz contributed some non-blocking |
|
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
6 patches. |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
7 |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
8 This module is imported by ssl.py. It should *not* be used |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
9 directly. |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
10 |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
11 XXX should partial writes be enabled, SSL_MODE_ENABLE_PARTIAL_WRITE? |
|
60901
fc97784e5cc2
Merged revisions 80394 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60818
diff
changeset
|
12 |
|
fc97784e5cc2
Merged revisions 80394 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60818
diff
changeset
|
13 XXX integrate several "shutdown modes" as suggested in |
|
fc97784e5cc2
Merged revisions 80394 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60818
diff
changeset
|
14 http://bugs.python.org/issue8108#msg102867 ? |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
15 */ |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
16 |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
17 #include "Python.h" |
|
42954
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
18 |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
19 #ifdef WITH_THREAD |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
20 #include "pythread.h" |
|
85290
8e1194c39bed
Issue #18747: Re-seed OpenSSL's pseudo-random number generator after fork.
Christian Heimes <christian@cheimes.de>
parents:
85263
diff
changeset
|
21 |
|
8e1194c39bed
Issue #18747: Re-seed OpenSSL's pseudo-random number generator after fork.
Christian Heimes <christian@cheimes.de>
parents:
85263
diff
changeset
|
22 #ifdef HAVE_PTHREAD_ATFORK |
|
8e1194c39bed
Issue #18747: Re-seed OpenSSL's pseudo-random number generator after fork.
Christian Heimes <christian@cheimes.de>
parents:
85263
diff
changeset
|
23 # include <pthread.h> |
|
8e1194c39bed
Issue #18747: Re-seed OpenSSL's pseudo-random number generator after fork.
Christian Heimes <christian@cheimes.de>
parents:
85263
diff
changeset
|
24 #endif |
|
8e1194c39bed
Issue #18747: Re-seed OpenSSL's pseudo-random number generator after fork.
Christian Heimes <christian@cheimes.de>
parents:
85263
diff
changeset
|
25 |
|
72071
cdc6c1b072a5
Issue #12803: SSLContext.load_cert_chain() now accepts a password argument
Antoine Pitrou <solipsis@pitrou.net>
parents:
71440
diff
changeset
|
26 #define PySSL_BEGIN_ALLOW_THREADS_S(save) \ |
|
cdc6c1b072a5
Issue #12803: SSLContext.load_cert_chain() now accepts a password argument
Antoine Pitrou <solipsis@pitrou.net>
parents:
71440
diff
changeset
|
27 do { if (_ssl_locks_count>0) { (save) = PyEval_SaveThread(); } } while (0) |
|
cdc6c1b072a5
Issue #12803: SSLContext.load_cert_chain() now accepts a password argument
Antoine Pitrou <solipsis@pitrou.net>
parents:
71440
diff
changeset
|
28 #define PySSL_END_ALLOW_THREADS_S(save) \ |
|
cdc6c1b072a5
Issue #12803: SSLContext.load_cert_chain() now accepts a password argument
Antoine Pitrou <solipsis@pitrou.net>
parents:
71440
diff
changeset
|
29 do { if (_ssl_locks_count>0) { PyEval_RestoreThread(save); } } while (0) |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
30 #define PySSL_BEGIN_ALLOW_THREADS { \ |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
31 PyThreadState *_save = NULL; \ |
|
72071
cdc6c1b072a5
Issue #12803: SSLContext.load_cert_chain() now accepts a password argument
Antoine Pitrou <solipsis@pitrou.net>
parents:
71440
diff
changeset
|
32 PySSL_BEGIN_ALLOW_THREADS_S(_save); |
|
cdc6c1b072a5
Issue #12803: SSLContext.load_cert_chain() now accepts a password argument
Antoine Pitrou <solipsis@pitrou.net>
parents:
71440
diff
changeset
|
33 #define PySSL_BLOCK_THREADS PySSL_END_ALLOW_THREADS_S(_save); |
|
cdc6c1b072a5
Issue #12803: SSLContext.load_cert_chain() now accepts a password argument
Antoine Pitrou <solipsis@pitrou.net>
parents:
71440
diff
changeset
|
34 #define PySSL_UNBLOCK_THREADS PySSL_BEGIN_ALLOW_THREADS_S(_save); |
|
cdc6c1b072a5
Issue #12803: SSLContext.load_cert_chain() now accepts a password argument
Antoine Pitrou <solipsis@pitrou.net>
parents:
71440
diff
changeset
|
35 #define PySSL_END_ALLOW_THREADS PySSL_END_ALLOW_THREADS_S(_save); } |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
36 |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
37 #else /* no WITH_THREAD */ |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
38 |
|
72071
cdc6c1b072a5
Issue #12803: SSLContext.load_cert_chain() now accepts a password argument
Antoine Pitrou <solipsis@pitrou.net>
parents:
71440
diff
changeset
|
39 #define PySSL_BEGIN_ALLOW_THREADS_S(save) |
|
cdc6c1b072a5
Issue #12803: SSLContext.load_cert_chain() now accepts a password argument
Antoine Pitrou <solipsis@pitrou.net>
parents:
71440
diff
changeset
|
40 #define PySSL_END_ALLOW_THREADS_S(save) |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
41 #define PySSL_BEGIN_ALLOW_THREADS |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
42 #define PySSL_BLOCK_THREADS |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
43 #define PySSL_UNBLOCK_THREADS |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
44 #define PySSL_END_ALLOW_THREADS |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
45 |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
46 #endif |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
47 |
|
82992
02a89bd646ca
Issue #16692: The ssl module now supports TLS 1.1 and TLS 1.2. Initial patch by Michele Orrù.
Antoine Pitrou <solipsis@pitrou.net>
parents:
81559
diff
changeset
|
48 /* Include symbols from _socket module */ |
|
02a89bd646ca
Issue #16692: The ssl module now supports TLS 1.1 and TLS 1.2. Initial patch by Michele Orrù.
Antoine Pitrou <solipsis@pitrou.net>
parents:
81559
diff
changeset
|
49 #include "socketmodule.h" |
|
02a89bd646ca
Issue #16692: The ssl module now supports TLS 1.1 and TLS 1.2. Initial patch by Michele Orrù.
Antoine Pitrou <solipsis@pitrou.net>
parents:
81559
diff
changeset
|
50 |
|
02a89bd646ca
Issue #16692: The ssl module now supports TLS 1.1 and TLS 1.2. Initial patch by Michele Orrù.
Antoine Pitrou <solipsis@pitrou.net>
parents:
81559
diff
changeset
|
51 static PySocketModule_APIObject PySocketModule; |
|
02a89bd646ca
Issue #16692: The ssl module now supports TLS 1.1 and TLS 1.2. Initial patch by Michele Orrù.
Antoine Pitrou <solipsis@pitrou.net>
parents:
81559
diff
changeset
|
52 |
|
02a89bd646ca
Issue #16692: The ssl module now supports TLS 1.1 and TLS 1.2. Initial patch by Michele Orrù.
Antoine Pitrou <solipsis@pitrou.net>
parents:
81559
diff
changeset
|
53 #if defined(HAVE_POLL_H) |
|
02a89bd646ca
Issue #16692: The ssl module now supports TLS 1.1 and TLS 1.2. Initial patch by Michele Orrù.
Antoine Pitrou <solipsis@pitrou.net>
parents:
81559
diff
changeset
|
54 #include <poll.h> |
|
02a89bd646ca
Issue #16692: The ssl module now supports TLS 1.1 and TLS 1.2. Initial patch by Michele Orrù.
Antoine Pitrou <solipsis@pitrou.net>
parents:
81559
diff
changeset
|
55 #elif defined(HAVE_SYS_POLL_H) |
|
02a89bd646ca
Issue #16692: The ssl module now supports TLS 1.1 and TLS 1.2. Initial patch by Michele Orrù.
Antoine Pitrou <solipsis@pitrou.net>
parents:
81559
diff
changeset
|
56 #include <sys/poll.h> |
|
02a89bd646ca
Issue #16692: The ssl module now supports TLS 1.1 and TLS 1.2. Initial patch by Michele Orrù.
Antoine Pitrou <solipsis@pitrou.net>
parents:
81559
diff
changeset
|
57 #endif |
|
02a89bd646ca
Issue #16692: The ssl module now supports TLS 1.1 and TLS 1.2. Initial patch by Michele Orrù.
Antoine Pitrou <solipsis@pitrou.net>
parents:
81559
diff
changeset
|
58 |
|
02a89bd646ca
Issue #16692: The ssl module now supports TLS 1.1 and TLS 1.2. Initial patch by Michele Orrù.
Antoine Pitrou <solipsis@pitrou.net>
parents:
81559
diff
changeset
|
59 /* Include OpenSSL header files */ |
|
02a89bd646ca
Issue #16692: The ssl module now supports TLS 1.1 and TLS 1.2. Initial patch by Michele Orrù.
Antoine Pitrou <solipsis@pitrou.net>
parents:
81559
diff
changeset
|
60 #include "openssl/rsa.h" |
|
02a89bd646ca
Issue #16692: The ssl module now supports TLS 1.1 and TLS 1.2. Initial patch by Michele Orrù.
Antoine Pitrou <solipsis@pitrou.net>
parents:
81559
diff
changeset
|
61 #include "openssl/crypto.h" |
|
02a89bd646ca
Issue #16692: The ssl module now supports TLS 1.1 and TLS 1.2. Initial patch by Michele Orrù.
Antoine Pitrou <solipsis@pitrou.net>
parents:
81559
diff
changeset
|
62 #include "openssl/x509.h" |
|
02a89bd646ca
Issue #16692: The ssl module now supports TLS 1.1 and TLS 1.2. Initial patch by Michele Orrù.
Antoine Pitrou <solipsis@pitrou.net>
parents:
81559
diff
changeset
|
63 #include "openssl/x509v3.h" |
|
02a89bd646ca
Issue #16692: The ssl module now supports TLS 1.1 and TLS 1.2. Initial patch by Michele Orrù.
Antoine Pitrou <solipsis@pitrou.net>
parents:
81559
diff
changeset
|
64 #include "openssl/pem.h" |
|
02a89bd646ca
Issue #16692: The ssl module now supports TLS 1.1 and TLS 1.2. Initial patch by Michele Orrù.
Antoine Pitrou <solipsis@pitrou.net>
parents:
81559
diff
changeset
|
65 #include "openssl/ssl.h" |
|
02a89bd646ca
Issue #16692: The ssl module now supports TLS 1.1 and TLS 1.2. Initial patch by Michele Orrù.
Antoine Pitrou <solipsis@pitrou.net>
parents:
81559
diff
changeset
|
66 #include "openssl/err.h" |
|
02a89bd646ca
Issue #16692: The ssl module now supports TLS 1.1 and TLS 1.2. Initial patch by Michele Orrù.
Antoine Pitrou <solipsis@pitrou.net>
parents:
81559
diff
changeset
|
67 #include "openssl/rand.h" |
|
02a89bd646ca
Issue #16692: The ssl module now supports TLS 1.1 and TLS 1.2. Initial patch by Michele Orrù.
Antoine Pitrou <solipsis@pitrou.net>
parents:
81559
diff
changeset
|
68 |
|
02a89bd646ca
Issue #16692: The ssl module now supports TLS 1.1 and TLS 1.2. Initial patch by Michele Orrù.
Antoine Pitrou <solipsis@pitrou.net>
parents:
81559
diff
changeset
|
69 /* SSL error object */ |
|
02a89bd646ca
Issue #16692: The ssl module now supports TLS 1.1 and TLS 1.2. Initial patch by Michele Orrù.
Antoine Pitrou <solipsis@pitrou.net>
parents:
81559
diff
changeset
|
70 static PyObject *PySSLErrorObject; |
|
02a89bd646ca
Issue #16692: The ssl module now supports TLS 1.1 and TLS 1.2. Initial patch by Michele Orrù.
Antoine Pitrou <solipsis@pitrou.net>
parents:
81559
diff
changeset
|
71 static PyObject *PySSLZeroReturnErrorObject; |
|
02a89bd646ca
Issue #16692: The ssl module now supports TLS 1.1 and TLS 1.2. Initial patch by Michele Orrù.
Antoine Pitrou <solipsis@pitrou.net>
parents:
81559
diff
changeset
|
72 static PyObject *PySSLWantReadErrorObject; |
|
02a89bd646ca
Issue #16692: The ssl module now supports TLS 1.1 and TLS 1.2. Initial patch by Michele Orrù.
Antoine Pitrou <solipsis@pitrou.net>
parents:
81559
diff
changeset
|
73 static PyObject *PySSLWantWriteErrorObject; |
|
02a89bd646ca
Issue #16692: The ssl module now supports TLS 1.1 and TLS 1.2. Initial patch by Michele Orrù.
Antoine Pitrou <solipsis@pitrou.net>
parents:
81559
diff
changeset
|
74 static PyObject *PySSLSyscallErrorObject; |
|
02a89bd646ca
Issue #16692: The ssl module now supports TLS 1.1 and TLS 1.2. Initial patch by Michele Orrù.
Antoine Pitrou <solipsis@pitrou.net>
parents:
81559
diff
changeset
|
75 static PyObject *PySSLEOFErrorObject; |
|
02a89bd646ca
Issue #16692: The ssl module now supports TLS 1.1 and TLS 1.2. Initial patch by Michele Orrù.
Antoine Pitrou <solipsis@pitrou.net>
parents:
81559
diff
changeset
|
76 |
|
02a89bd646ca
Issue #16692: The ssl module now supports TLS 1.1 and TLS 1.2. Initial patch by Michele Orrù.
Antoine Pitrou <solipsis@pitrou.net>
parents:
81559
diff
changeset
|
77 /* Error mappings */ |
|
02a89bd646ca
Issue #16692: The ssl module now supports TLS 1.1 and TLS 1.2. Initial patch by Michele Orrù.
Antoine Pitrou <solipsis@pitrou.net>
parents:
81559
diff
changeset
|
78 static PyObject *err_codes_to_names; |
|
02a89bd646ca
Issue #16692: The ssl module now supports TLS 1.1 and TLS 1.2. Initial patch by Michele Orrù.
Antoine Pitrou <solipsis@pitrou.net>
parents:
81559
diff
changeset
|
79 static PyObject *err_names_to_codes; |
|
02a89bd646ca
Issue #16692: The ssl module now supports TLS 1.1 and TLS 1.2. Initial patch by Michele Orrù.
Antoine Pitrou <solipsis@pitrou.net>
parents:
81559
diff
changeset
|
80 static PyObject *lib_codes_to_names; |
|
02a89bd646ca
Issue #16692: The ssl module now supports TLS 1.1 and TLS 1.2. Initial patch by Michele Orrù.
Antoine Pitrou <solipsis@pitrou.net>
parents:
81559
diff
changeset
|
81 |
|
02a89bd646ca
Issue #16692: The ssl module now supports TLS 1.1 and TLS 1.2. Initial patch by Michele Orrù.
Antoine Pitrou <solipsis@pitrou.net>
parents:
81559
diff
changeset
|
82 struct py_ssl_error_code { |
|
02a89bd646ca
Issue #16692: The ssl module now supports TLS 1.1 and TLS 1.2. Initial patch by Michele Orrù.
Antoine Pitrou <solipsis@pitrou.net>
parents:
81559
diff
changeset
|
83 const char *mnemonic; |
|
02a89bd646ca
Issue #16692: The ssl module now supports TLS 1.1 and TLS 1.2. Initial patch by Michele Orrù.
Antoine Pitrou <solipsis@pitrou.net>
parents:
81559
diff
changeset
|
84 int library, reason; |
|
02a89bd646ca
Issue #16692: The ssl module now supports TLS 1.1 and TLS 1.2. Initial patch by Michele Orrù.
Antoine Pitrou <solipsis@pitrou.net>
parents:
81559
diff
changeset
|
85 }; |
|
02a89bd646ca
Issue #16692: The ssl module now supports TLS 1.1 and TLS 1.2. Initial patch by Michele Orrù.
Antoine Pitrou <solipsis@pitrou.net>
parents:
81559
diff
changeset
|
86 struct py_ssl_library_code { |
|
02a89bd646ca
Issue #16692: The ssl module now supports TLS 1.1 and TLS 1.2. Initial patch by Michele Orrù.
Antoine Pitrou <solipsis@pitrou.net>
parents:
81559
diff
changeset
|
87 const char *library; |
|
02a89bd646ca
Issue #16692: The ssl module now supports TLS 1.1 and TLS 1.2. Initial patch by Michele Orrù.
Antoine Pitrou <solipsis@pitrou.net>
parents:
81559
diff
changeset
|
88 int code; |
|
02a89bd646ca
Issue #16692: The ssl module now supports TLS 1.1 and TLS 1.2. Initial patch by Michele Orrù.
Antoine Pitrou <solipsis@pitrou.net>
parents:
81559
diff
changeset
|
89 }; |
|
02a89bd646ca
Issue #16692: The ssl module now supports TLS 1.1 and TLS 1.2. Initial patch by Michele Orrù.
Antoine Pitrou <solipsis@pitrou.net>
parents:
81559
diff
changeset
|
90 |
|
02a89bd646ca
Issue #16692: The ssl module now supports TLS 1.1 and TLS 1.2. Initial patch by Michele Orrù.
Antoine Pitrou <solipsis@pitrou.net>
parents:
81559
diff
changeset
|
91 /* Include generated data (error codes) */ |
|
02a89bd646ca
Issue #16692: The ssl module now supports TLS 1.1 and TLS 1.2. Initial patch by Michele Orrù.
Antoine Pitrou <solipsis@pitrou.net>
parents:
81559
diff
changeset
|
92 #include "_ssl_data.h" |
|
02a89bd646ca
Issue #16692: The ssl module now supports TLS 1.1 and TLS 1.2. Initial patch by Michele Orrù.
Antoine Pitrou <solipsis@pitrou.net>
parents:
81559
diff
changeset
|
93 |
|
02a89bd646ca
Issue #16692: The ssl module now supports TLS 1.1 and TLS 1.2. Initial patch by Michele Orrù.
Antoine Pitrou <solipsis@pitrou.net>
parents:
81559
diff
changeset
|
94 /* Openssl comes with TLSv1.1 and TLSv1.2 between 1.0.0h and 1.0.1 |
|
02a89bd646ca
Issue #16692: The ssl module now supports TLS 1.1 and TLS 1.2. Initial patch by Michele Orrù.
Antoine Pitrou <solipsis@pitrou.net>
parents:
81559
diff
changeset
|
95 http://www.openssl.org/news/changelog.html |
|
02a89bd646ca
Issue #16692: The ssl module now supports TLS 1.1 and TLS 1.2. Initial patch by Michele Orrù.
Antoine Pitrou <solipsis@pitrou.net>
parents:
81559
diff
changeset
|
96 */ |
|
02a89bd646ca
Issue #16692: The ssl module now supports TLS 1.1 and TLS 1.2. Initial patch by Michele Orrù.
Antoine Pitrou <solipsis@pitrou.net>
parents:
81559
diff
changeset
|
97 #if OPENSSL_VERSION_NUMBER >= 0x10001000L |
|
02a89bd646ca
Issue #16692: The ssl module now supports TLS 1.1 and TLS 1.2. Initial patch by Michele Orrù.
Antoine Pitrou <solipsis@pitrou.net>
parents:
81559
diff
changeset
|
98 # define HAVE_TLSv1_2 1 |
|
02a89bd646ca
Issue #16692: The ssl module now supports TLS 1.1 and TLS 1.2. Initial patch by Michele Orrù.
Antoine Pitrou <solipsis@pitrou.net>
parents:
81559
diff
changeset
|
99 #else |
|
02a89bd646ca
Issue #16692: The ssl module now supports TLS 1.1 and TLS 1.2. Initial patch by Michele Orrù.
Antoine Pitrou <solipsis@pitrou.net>
parents:
81559
diff
changeset
|
100 # define HAVE_TLSv1_2 0 |
|
02a89bd646ca
Issue #16692: The ssl module now supports TLS 1.1 and TLS 1.2. Initial patch by Michele Orrù.
Antoine Pitrou <solipsis@pitrou.net>
parents:
81559
diff
changeset
|
101 #endif |
|
02a89bd646ca
Issue #16692: The ssl module now supports TLS 1.1 and TLS 1.2. Initial patch by Michele Orrù.
Antoine Pitrou <solipsis@pitrou.net>
parents:
81559
diff
changeset
|
102 |
|
83026
411e5726f84d
Fix comment about the OpenSSL version in which SNI version was introduced.
Antoine Pitrou <solipsis@pitrou.net>
parents:
83025
diff
changeset
|
103 /* SNI support (client- and server-side) appeared in OpenSSL 1.0.0. |
|
83021
02f9335b7efb
Issue #17581: try to fix building on old OpenSSL versions
Antoine Pitrou <solipsis@pitrou.net>
parents:
82992
diff
changeset
|
104 * This includes the SSL_set_SSL_CTX() function. |
|
02f9335b7efb
Issue #17581: try to fix building on old OpenSSL versions
Antoine Pitrou <solipsis@pitrou.net>
parents:
82992
diff
changeset
|
105 */ |
|
02f9335b7efb
Issue #17581: try to fix building on old OpenSSL versions
Antoine Pitrou <solipsis@pitrou.net>
parents:
82992
diff
changeset
|
106 #ifdef SSL_CTRL_SET_TLSEXT_HOSTNAME |
|
02f9335b7efb
Issue #17581: try to fix building on old OpenSSL versions
Antoine Pitrou <solipsis@pitrou.net>
parents:
82992
diff
changeset
|
107 # define HAVE_SNI 1 |
|
02f9335b7efb
Issue #17581: try to fix building on old OpenSSL versions
Antoine Pitrou <solipsis@pitrou.net>
parents:
82992
diff
changeset
|
108 #else |
|
02f9335b7efb
Issue #17581: try to fix building on old OpenSSL versions
Antoine Pitrou <solipsis@pitrou.net>
parents:
82992
diff
changeset
|
109 # define HAVE_SNI 0 |
|
02f9335b7efb
Issue #17581: try to fix building on old OpenSSL versions
Antoine Pitrou <solipsis@pitrou.net>
parents:
82992
diff
changeset
|
110 #endif |
|
02f9335b7efb
Issue #17581: try to fix building on old OpenSSL versions
Antoine Pitrou <solipsis@pitrou.net>
parents:
82992
diff
changeset
|
111 |
|
23190
0bc3a41d4e40
Forward port of patch # 500311: Work around for buggy https servers.
Martin v. Löwis <martin@v.loewis.de>
parents:
21959
diff
changeset
|
112 enum py_ssl_error { |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
113 /* these mirror ssl.h */ |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
114 PY_SSL_ERROR_NONE, |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
115 PY_SSL_ERROR_SSL, |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
116 PY_SSL_ERROR_WANT_READ, |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
117 PY_SSL_ERROR_WANT_WRITE, |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
118 PY_SSL_ERROR_WANT_X509_LOOKUP, |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
119 PY_SSL_ERROR_SYSCALL, /* look at error stack/return value/errno */ |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
120 PY_SSL_ERROR_ZERO_RETURN, |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
121 PY_SSL_ERROR_WANT_CONNECT, |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
122 /* start of non ssl.h errorcodes */ |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
123 PY_SSL_ERROR_EOF, /* special case of SSL_ERROR_SYSCALL */ |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
124 PY_SSL_ERROR_NO_SOCKET, /* socket has been GC'd */ |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
125 PY_SSL_ERROR_INVALID_ERROR_CODE |
|
23190
0bc3a41d4e40
Forward port of patch # 500311: Work around for buggy https servers.
Martin v. Löwis <martin@v.loewis.de>
parents:
21959
diff
changeset
|
126 }; |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
127 |
|
42954
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
128 enum py_ssl_server_or_client { |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
129 PY_SSL_CLIENT, |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
130 PY_SSL_SERVER |
|
42954
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
131 }; |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
132 |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
133 enum py_ssl_cert_requirements { |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
134 PY_SSL_CERT_NONE, |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
135 PY_SSL_CERT_OPTIONAL, |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
136 PY_SSL_CERT_REQUIRED |
|
42954
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
137 }; |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
138 |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
139 enum py_ssl_version { |
|
69997
b7abf0590e1c
Issue #12012: ssl.PROTOCOL_SSLv2 becomes optional
Victor Stinner <victor.stinner@haypocalc.com>
parents:
66806
diff
changeset
|
140 #ifndef OPENSSL_NO_SSL2 |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
141 PY_SSL_VERSION_SSL2, |
|
69997
b7abf0590e1c
Issue #12012: ssl.PROTOCOL_SSLv2 becomes optional
Victor Stinner <victor.stinner@haypocalc.com>
parents:
66806
diff
changeset
|
142 #endif |
|
b7abf0590e1c
Issue #12012: ssl.PROTOCOL_SSLv2 becomes optional
Victor Stinner <victor.stinner@haypocalc.com>
parents:
66806
diff
changeset
|
143 PY_SSL_VERSION_SSL3=1, |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
144 PY_SSL_VERSION_SSL23, |
|
82992
02a89bd646ca
Issue #16692: The ssl module now supports TLS 1.1 and TLS 1.2. Initial patch by Michele Orrù.
Antoine Pitrou <solipsis@pitrou.net>
parents:
81559
diff
changeset
|
145 #if HAVE_TLSv1_2 |
|
02a89bd646ca
Issue #16692: The ssl module now supports TLS 1.1 and TLS 1.2. Initial patch by Michele Orrù.
Antoine Pitrou <solipsis@pitrou.net>
parents:
81559
diff
changeset
|
146 PY_SSL_VERSION_TLS1, |
|
02a89bd646ca
Issue #16692: The ssl module now supports TLS 1.1 and TLS 1.2. Initial patch by Michele Orrù.
Antoine Pitrou <solipsis@pitrou.net>
parents:
81559
diff
changeset
|
147 PY_SSL_VERSION_TLS1_1, |
|
02a89bd646ca
Issue #16692: The ssl module now supports TLS 1.1 and TLS 1.2. Initial patch by Michele Orrù.
Antoine Pitrou <solipsis@pitrou.net>
parents:
81559
diff
changeset
|
148 PY_SSL_VERSION_TLS1_2 |
|
02a89bd646ca
Issue #16692: The ssl module now supports TLS 1.1 and TLS 1.2. Initial patch by Michele Orrù.
Antoine Pitrou <solipsis@pitrou.net>
parents:
81559
diff
changeset
|
149 #else |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
150 PY_SSL_VERSION_TLS1 |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38453
diff
changeset
|
151 #endif |
|
82992
02a89bd646ca
Issue #16692: The ssl module now supports TLS 1.1 and TLS 1.2. Initial patch by Michele Orrù.
Antoine Pitrou <solipsis@pitrou.net>
parents:
81559
diff
changeset
|
152 }; |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
153 |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
154 #ifdef WITH_THREAD |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
155 |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
156 /* serves as a flag to see whether we've initialized the SSL thread support. */ |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
157 /* 0 means no, greater than 0 means yes */ |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
158 |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
159 static unsigned int _ssl_locks_count = 0; |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
160 |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
161 #endif /* def WITH_THREAD */ |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
162 |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
163 /* SSL socket object */ |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
164 |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
165 #define X509_NAME_MAXLEN 256 |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
166 |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
167 /* RAND_* APIs got added to OpenSSL in 0.9.5 */ |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
168 #if OPENSSL_VERSION_NUMBER >= 0x0090500fL |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
169 # define HAVE_OPENSSL_RAND 1 |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
170 #else |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
171 # undef HAVE_OPENSSL_RAND |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
172 #endif |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
173 |
|
65246
23ec0be07e20
Fix compile on NetBSD 5.0 (or anything else using an old 0.9.9-dev OpenSSL).
Gregory P. Smith <greg@mad-scientist.com>
parents:
65223
diff
changeset
|
174 /* SSL_CTX_clear_options() and SSL_clear_options() were first added in |
|
23ec0be07e20
Fix compile on NetBSD 5.0 (or anything else using an old 0.9.9-dev OpenSSL).
Gregory P. Smith <greg@mad-scientist.com>
parents:
65223
diff
changeset
|
175 * OpenSSL 0.9.8m but do not appear in some 0.9.9-dev versions such the |
|
23ec0be07e20
Fix compile on NetBSD 5.0 (or anything else using an old 0.9.9-dev OpenSSL).
Gregory P. Smith <greg@mad-scientist.com>
parents:
65223
diff
changeset
|
176 * 0.9.9 from "May 2008" that NetBSD 5.0 uses. */ |
|
23ec0be07e20
Fix compile on NetBSD 5.0 (or anything else using an old 0.9.9-dev OpenSSL).
Gregory P. Smith <greg@mad-scientist.com>
parents:
65223
diff
changeset
|
177 #if OPENSSL_VERSION_NUMBER >= 0x009080dfL && OPENSSL_VERSION_NUMBER != 0x00909000L |
|
61782
5ee47f0b26b0
Issue #4870: Add an `options` attribute to SSL contexts, as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
61644
diff
changeset
|
178 # define HAVE_SSL_CTX_CLEAR_OPTIONS |
|
5ee47f0b26b0
Issue #4870: Add an `options` attribute to SSL contexts, as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
61644
diff
changeset
|
179 #else |
|
5ee47f0b26b0
Issue #4870: Add an `options` attribute to SSL contexts, as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
61644
diff
changeset
|
180 # undef HAVE_SSL_CTX_CLEAR_OPTIONS |
|
5ee47f0b26b0
Issue #4870: Add an `options` attribute to SSL contexts, as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
61644
diff
changeset
|
181 #endif |
|
5ee47f0b26b0
Issue #4870: Add an `options` attribute to SSL contexts, as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
61644
diff
changeset
|
182 |
|
71440
cb44fef5ea1d
Issue #12551: Provide a get_channel_binding() method on SSL sockets so as
Antoine Pitrou <solipsis@pitrou.net>
parents:
71256
diff
changeset
|
183 /* In case of 'tls-unique' it will be 12 bytes for TLS, 36 bytes for |
|
cb44fef5ea1d
Issue #12551: Provide a get_channel_binding() method on SSL sockets so as
Antoine Pitrou <solipsis@pitrou.net>
parents:
71256
diff
changeset
|
184 * older SSL, but let's be safe */ |
|
cb44fef5ea1d
Issue #12551: Provide a get_channel_binding() method on SSL sockets so as
Antoine Pitrou <solipsis@pitrou.net>
parents:
71256
diff
changeset
|
185 #define PySSL_CB_MAXLEN 128 |
|
cb44fef5ea1d
Issue #12551: Provide a get_channel_binding() method on SSL sockets so as
Antoine Pitrou <solipsis@pitrou.net>
parents:
71256
diff
changeset
|
186 |
|
cb44fef5ea1d
Issue #12551: Provide a get_channel_binding() method on SSL sockets so as
Antoine Pitrou <solipsis@pitrou.net>
parents:
71256
diff
changeset
|
187 /* SSL_get_finished got added to OpenSSL in 0.9.5 */ |
|
cb44fef5ea1d
Issue #12551: Provide a get_channel_binding() method on SSL sockets so as
Antoine Pitrou <solipsis@pitrou.net>
parents:
71256
diff
changeset
|
188 #if OPENSSL_VERSION_NUMBER >= 0x0090500fL |
|
cb44fef5ea1d
Issue #12551: Provide a get_channel_binding() method on SSL sockets so as
Antoine Pitrou <solipsis@pitrou.net>
parents:
71256
diff
changeset
|
189 # define HAVE_OPENSSL_FINISHED 1 |
|
cb44fef5ea1d
Issue #12551: Provide a get_channel_binding() method on SSL sockets so as
Antoine Pitrou <solipsis@pitrou.net>
parents:
71256
diff
changeset
|
190 #else |
|
cb44fef5ea1d
Issue #12551: Provide a get_channel_binding() method on SSL sockets so as
Antoine Pitrou <solipsis@pitrou.net>
parents:
71256
diff
changeset
|
191 # define HAVE_OPENSSL_FINISHED 0 |
|
cb44fef5ea1d
Issue #12551: Provide a get_channel_binding() method on SSL sockets so as
Antoine Pitrou <solipsis@pitrou.net>
parents:
71256
diff
changeset
|
192 #endif |
|
cb44fef5ea1d
Issue #12551: Provide a get_channel_binding() method on SSL sockets so as
Antoine Pitrou <solipsis@pitrou.net>
parents:
71256
diff
changeset
|
193 |
|
75005
06ed9b3f02af
Try to really fix compilation failures of the _ssl module under very old OpenSSLs.
Antoine Pitrou <solipsis@pitrou.net>
parents:
74995
diff
changeset
|
194 /* ECDH support got added to OpenSSL in 0.9.8 */ |
|
06ed9b3f02af
Try to really fix compilation failures of the _ssl module under very old OpenSSLs.
Antoine Pitrou <solipsis@pitrou.net>
parents:
74995
diff
changeset
|
195 #if OPENSSL_VERSION_NUMBER < 0x0090800fL && !defined(OPENSSL_NO_ECDH) |
|
06ed9b3f02af
Try to really fix compilation failures of the _ssl module under very old OpenSSLs.
Antoine Pitrou <solipsis@pitrou.net>
parents:
74995
diff
changeset
|
196 # define OPENSSL_NO_ECDH |
|
06ed9b3f02af
Try to really fix compilation failures of the _ssl module under very old OpenSSLs.
Antoine Pitrou <solipsis@pitrou.net>
parents:
74995
diff
changeset
|
197 #endif |
|
06ed9b3f02af
Try to really fix compilation failures of the _ssl module under very old OpenSSLs.
Antoine Pitrou <solipsis@pitrou.net>
parents:
74995
diff
changeset
|
198 |
|
75043
1a06f0a8120f
Fix last remaining build issues of _ssl under old OpenSSLs. Patch by Vinay.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75005
diff
changeset
|
199 /* compression support got added to OpenSSL in 0.9.8 */ |
|
1a06f0a8120f
Fix last remaining build issues of _ssl under old OpenSSLs. Patch by Vinay.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75005
diff
changeset
|
200 #if OPENSSL_VERSION_NUMBER < 0x0090800fL && !defined(OPENSSL_NO_COMP) |
|
1a06f0a8120f
Fix last remaining build issues of _ssl under old OpenSSLs. Patch by Vinay.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75005
diff
changeset
|
201 # define OPENSSL_NO_COMP |
|
1a06f0a8120f
Fix last remaining build issues of _ssl under old OpenSSLs. Patch by Vinay.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75005
diff
changeset
|
202 #endif |
|
1a06f0a8120f
Fix last remaining build issues of _ssl under old OpenSSLs. Patch by Vinay.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75005
diff
changeset
|
203 |
|
75005
06ed9b3f02af
Try to really fix compilation failures of the _ssl module under very old OpenSSLs.
Antoine Pitrou <solipsis@pitrou.net>
parents:
74995
diff
changeset
|
204 |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
205 typedef struct { |
|
61244
35221c0158b5
Merged revisions 80789 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61017
diff
changeset
|
206 PyObject_HEAD |
|
61635
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
207 SSL_CTX *ctx; |
|
75865
2514a4e2b3ce
Issue #14204: The ssl module now has support for the Next Protocol Negotiation extension, if available in the underlying OpenSSL library.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75043
diff
changeset
|
208 #ifdef OPENSSL_NPN_NEGOTIATED |
|
2514a4e2b3ce
Issue #14204: The ssl module now has support for the Next Protocol Negotiation extension, if available in the underlying OpenSSL library.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75043
diff
changeset
|
209 char *npn_protocols; |
|
2514a4e2b3ce
Issue #14204: The ssl module now has support for the Next Protocol Negotiation extension, if available in the underlying OpenSSL library.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75043
diff
changeset
|
210 int npn_protocols_len; |
|
2514a4e2b3ce
Issue #14204: The ssl module now has support for the Next Protocol Negotiation extension, if available in the underlying OpenSSL library.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75043
diff
changeset
|
211 #endif |
|
81298
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
212 #ifndef OPENSSL_NO_TLSEXT |
|
84334
28f47a5d59b9
_ssl.c: strip trailing spaces
Victor Stinner <victor.stinner@gmail.com>
parents:
84333
diff
changeset
|
213 PyObject *set_hostname; |
|
81298
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
214 #endif |
|
61635
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
215 } PySSLContext; |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
216 |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
217 typedef struct { |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
218 PyObject_HEAD |
|
61635
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
219 PyObject *Socket; /* weakref to socket on which we're layered */ |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
220 SSL *ssl; |
|
81298
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
221 PySSLContext *ctx; /* weakref to SSL context */ |
|
61635
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
222 X509 *peer_cert; |
|
85857
ddcdf7f7eac8
Issue #19095: SSLSocket.getpeercert() now raises ValueError when the SSL handshake hasn't been done.
Antoine Pitrou <solipsis@pitrou.net>
parents:
85536
diff
changeset
|
223 char shutdown_seen_zero; |
|
ddcdf7f7eac8
Issue #19095: SSLSocket.getpeercert() now raises ValueError when the SSL handshake hasn't been done.
Antoine Pitrou <solipsis@pitrou.net>
parents:
85536
diff
changeset
|
224 char handshake_done; |
|
71440
cb44fef5ea1d
Issue #12551: Provide a get_channel_binding() method on SSL sockets so as
Antoine Pitrou <solipsis@pitrou.net>
parents:
71256
diff
changeset
|
225 enum py_ssl_server_or_client socket_type; |
|
61635
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
226 } PySSLSocket; |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
227 |
|
61635
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
228 static PyTypeObject PySSLContext_Type; |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
229 static PyTypeObject PySSLSocket_Type; |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
230 |
|
61635
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
231 static PyObject *PySSL_SSLwrite(PySSLSocket *self, PyObject *args); |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
232 static PyObject *PySSL_SSLread(PySSLSocket *self, PyObject *args); |
|
42954
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
233 static int check_socket_and_wait_for_timeout(PySocketSockObject *s, |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
234 int writing); |
|
61635
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
235 static PyObject *PySSL_peercert(PySSLSocket *self, PyObject *args); |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
236 static PyObject *PySSL_cipher(PySSLSocket *self); |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
237 |
|
61635
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
238 #define PySSLContext_Check(v) (Py_TYPE(v) == &PySSLContext_Type) |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
239 #define PySSLSocket_Check(v) (Py_TYPE(v) == &PySSLSocket_Type) |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
240 |
|
32599
598a5ce63322
[Patch #945642] Fix non-blocking SSL sockets, which blocked on reads/writes in Python 2.3.
Andrew M. Kuchling <amk@amk.ca>
parents:
31790
diff
changeset
|
241 typedef enum { |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
242 SOCKET_IS_NONBLOCKING, |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
243 SOCKET_IS_BLOCKING, |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
244 SOCKET_HAS_TIMED_OUT, |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
245 SOCKET_HAS_BEEN_CLOSED, |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
246 SOCKET_TOO_LARGE_FOR_SELECT, |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
247 SOCKET_OPERATION_OK |
|
32599
598a5ce63322
[Patch #945642] Fix non-blocking SSL sockets, which blocked on reads/writes in Python 2.3.
Andrew M. Kuchling <amk@amk.ca>
parents:
31790
diff
changeset
|
248 } timeout_state; |
|
598a5ce63322
[Patch #945642] Fix non-blocking SSL sockets, which blocked on reads/writes in Python 2.3.
Andrew M. Kuchling <amk@amk.ca>
parents:
31790
diff
changeset
|
249 |
|
42954
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
250 /* Wrap error strings with filename and line # */ |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
251 #define STRINGIFY1(x) #x |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
252 #define STRINGIFY2(x) STRINGIFY1(x) |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
253 #define ERRSTR1(x,y,z) (x ":" y ": " z) |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
254 #define ERRSTR(x) ERRSTR1("_ssl.c", STRINGIFY2(__LINE__), x) |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
255 |
|
77578
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
256 |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
257 /* |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
258 * SSL errors. |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
259 */ |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
260 |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
261 PyDoc_STRVAR(SSLError_doc, |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
262 "An error occurred in the SSL implementation."); |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
263 |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
264 PyDoc_STRVAR(SSLZeroReturnError_doc, |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
265 "SSL/TLS session closed cleanly."); |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
266 |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
267 PyDoc_STRVAR(SSLWantReadError_doc, |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
268 "Non-blocking SSL socket needs to read more data\n" |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
269 "before the requested operation can be completed."); |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
270 |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
271 PyDoc_STRVAR(SSLWantWriteError_doc, |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
272 "Non-blocking SSL socket needs to write more data\n" |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
273 "before the requested operation can be completed."); |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
274 |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
275 PyDoc_STRVAR(SSLSyscallError_doc, |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
276 "System error when attempting SSL operation."); |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
277 |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
278 PyDoc_STRVAR(SSLEOFError_doc, |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
279 "SSL/TLS connection terminated abruptly."); |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
280 |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
281 static PyObject * |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
282 SSLError_str(PyOSErrorObject *self) |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
283 { |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
284 if (self->strerror != NULL && PyUnicode_Check(self->strerror)) { |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
285 Py_INCREF(self->strerror); |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
286 return self->strerror; |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
287 } |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
288 else |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
289 return PyObject_Str(self->args); |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
290 } |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
291 |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
292 static PyType_Slot sslerror_type_slots[] = { |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
293 {Py_tp_base, NULL}, /* Filled out in module init as it's not a constant */ |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
294 {Py_tp_doc, SSLError_doc}, |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
295 {Py_tp_str, SSLError_str}, |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
296 {0, 0}, |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
297 }; |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
298 |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
299 static PyType_Spec sslerror_type_spec = { |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
300 "ssl.SSLError", |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
301 sizeof(PyOSErrorObject), |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
302 0, |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
303 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
304 sslerror_type_slots |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
305 }; |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
306 |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
307 static void |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
308 fill_and_set_sslerror(PyObject *type, int ssl_errno, const char *errstr, |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
309 int lineno, unsigned long errcode) |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
310 { |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
311 PyObject *err_value = NULL, *reason_obj = NULL, *lib_obj = NULL; |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
312 PyObject *init_value, *msg, *key; |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
313 _Py_IDENTIFIER(reason); |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
314 _Py_IDENTIFIER(library); |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
315 |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
316 if (errcode != 0) { |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
317 int lib, reason; |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
318 |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
319 lib = ERR_GET_LIB(errcode); |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
320 reason = ERR_GET_REASON(errcode); |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
321 key = Py_BuildValue("ii", lib, reason); |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
322 if (key == NULL) |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
323 goto fail; |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
324 reason_obj = PyDict_GetItem(err_codes_to_names, key); |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
325 Py_DECREF(key); |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
326 if (reason_obj == NULL) { |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
327 /* XXX if reason < 100, it might reflect a library number (!!) */ |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
328 PyErr_Clear(); |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
329 } |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
330 key = PyLong_FromLong(lib); |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
331 if (key == NULL) |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
332 goto fail; |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
333 lib_obj = PyDict_GetItem(lib_codes_to_names, key); |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
334 Py_DECREF(key); |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
335 if (lib_obj == NULL) { |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
336 PyErr_Clear(); |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
337 } |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
338 if (errstr == NULL) |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
339 errstr = ERR_reason_error_string(errcode); |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
340 } |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
341 if (errstr == NULL) |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
342 errstr = "unknown error"; |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
343 |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
344 if (reason_obj && lib_obj) |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
345 msg = PyUnicode_FromFormat("[%S: %S] %s (_ssl.c:%d)", |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
346 lib_obj, reason_obj, errstr, lineno); |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
347 else if (lib_obj) |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
348 msg = PyUnicode_FromFormat("[%S] %s (_ssl.c:%d)", |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
349 lib_obj, errstr, lineno); |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
350 else |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
351 msg = PyUnicode_FromFormat("%s (_ssl.c:%d)", errstr, lineno); |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
352 |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
353 if (msg == NULL) |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
354 goto fail; |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
355 init_value = Py_BuildValue("iN", ssl_errno, msg); |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
356 err_value = PyObject_CallObject(type, init_value); |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
357 Py_DECREF(init_value); |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
358 if (err_value == NULL) |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
359 goto fail; |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
360 if (reason_obj == NULL) |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
361 reason_obj = Py_None; |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
362 if (_PyObject_SetAttrId(err_value, &PyId_reason, reason_obj)) |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
363 goto fail; |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
364 if (lib_obj == NULL) |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
365 lib_obj = Py_None; |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
366 if (_PyObject_SetAttrId(err_value, &PyId_library, lib_obj)) |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
367 goto fail; |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
368 PyErr_SetObject(type, err_value); |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
369 fail: |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
370 Py_XDECREF(err_value); |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
371 } |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
372 |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
373 static PyObject * |
|
61635
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
374 PySSL_SetError(PySSLSocket *obj, int ret, char *filename, int lineno) |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
375 { |
|
73150
2c4a9c778bb3
Issue #11183: Add finer-grained exceptions to the ssl module, so that
Antoine Pitrou <solipsis@pitrou.net>
parents:
73059
diff
changeset
|
376 PyObject *type = PySSLErrorObject; |
|
77578
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
377 char *errstr = NULL; |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
378 int err; |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
379 enum py_ssl_error p = PY_SSL_ERROR_NONE; |
|
77578
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
380 unsigned long e = 0; |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
381 |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
382 assert(ret <= 0); |
|
77578
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
383 e = ERR_peek_last_error(); |
|
42954
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
384 |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
385 if (obj->ssl != NULL) { |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
386 err = SSL_get_error(obj->ssl, ret); |
|
23190
0bc3a41d4e40
Forward port of patch # 500311: Work around for buggy https servers.
Martin v. Löwis <martin@v.loewis.de>
parents:
21959
diff
changeset
|
387 |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
388 switch (err) { |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
389 case SSL_ERROR_ZERO_RETURN: |
|
73150
2c4a9c778bb3
Issue #11183: Add finer-grained exceptions to the ssl module, so that
Antoine Pitrou <solipsis@pitrou.net>
parents:
73059
diff
changeset
|
390 errstr = "TLS/SSL connection has been closed (EOF)"; |
|
2c4a9c778bb3
Issue #11183: Add finer-grained exceptions to the ssl module, so that
Antoine Pitrou <solipsis@pitrou.net>
parents:
73059
diff
changeset
|
391 type = PySSLZeroReturnErrorObject; |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
392 p = PY_SSL_ERROR_ZERO_RETURN; |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
393 break; |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
394 case SSL_ERROR_WANT_READ: |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
395 errstr = "The operation did not complete (read)"; |
|
73150
2c4a9c778bb3
Issue #11183: Add finer-grained exceptions to the ssl module, so that
Antoine Pitrou <solipsis@pitrou.net>
parents:
73059
diff
changeset
|
396 type = PySSLWantReadErrorObject; |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
397 p = PY_SSL_ERROR_WANT_READ; |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
398 break; |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
399 case SSL_ERROR_WANT_WRITE: |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
400 p = PY_SSL_ERROR_WANT_WRITE; |
|
73150
2c4a9c778bb3
Issue #11183: Add finer-grained exceptions to the ssl module, so that
Antoine Pitrou <solipsis@pitrou.net>
parents:
73059
diff
changeset
|
401 type = PySSLWantWriteErrorObject; |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
402 errstr = "The operation did not complete (write)"; |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
403 break; |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
404 case SSL_ERROR_WANT_X509_LOOKUP: |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
405 p = PY_SSL_ERROR_WANT_X509_LOOKUP; |
|
61537
330273ec6028
Merged revisions 81116 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61246
diff
changeset
|
406 errstr = "The operation did not complete (X509 lookup)"; |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
407 break; |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
408 case SSL_ERROR_WANT_CONNECT: |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
409 p = PY_SSL_ERROR_WANT_CONNECT; |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
410 errstr = "The operation did not complete (connect)"; |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
411 break; |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
412 case SSL_ERROR_SYSCALL: |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
413 { |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
414 if (e == 0) { |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
415 PySocketSockObject *s |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
416 = (PySocketSockObject *) PyWeakref_GetObject(obj->Socket); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
417 if (ret == 0 || (((PyObject *)s) == Py_None)) { |
|
61537
330273ec6028
Merged revisions 81116 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61246
diff
changeset
|
418 p = PY_SSL_ERROR_EOF; |
|
73150
2c4a9c778bb3
Issue #11183: Add finer-grained exceptions to the ssl module, so that
Antoine Pitrou <solipsis@pitrou.net>
parents:
73059
diff
changeset
|
419 type = PySSLEOFErrorObject; |
|
61537
330273ec6028
Merged revisions 81116 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61246
diff
changeset
|
420 errstr = "EOF occurred in violation of protocol"; |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
421 } else if (ret == -1) { |
|
61537
330273ec6028
Merged revisions 81116 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61246
diff
changeset
|
422 /* underlying BIO reported an I/O error */ |
|
62481
b8b0a15f8a7c
Merged revisions 82204 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61646
diff
changeset
|
423 Py_INCREF(s); |
|
61646
8b6401ae1262
Merged revisions 81242 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61537
diff
changeset
|
424 ERR_clear_error(); |
|
77578
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
425 s->errorhandler(); |
|
62481
b8b0a15f8a7c
Merged revisions 82204 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61646
diff
changeset
|
426 Py_DECREF(s); |
|
77578
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
427 return NULL; |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
428 } else { /* possible? */ |
|
61537
330273ec6028
Merged revisions 81116 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61246
diff
changeset
|
429 p = PY_SSL_ERROR_SYSCALL; |
|
73150
2c4a9c778bb3
Issue #11183: Add finer-grained exceptions to the ssl module, so that
Antoine Pitrou <solipsis@pitrou.net>
parents:
73059
diff
changeset
|
430 type = PySSLSyscallErrorObject; |
|
61537
330273ec6028
Merged revisions 81116 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61246
diff
changeset
|
431 errstr = "Some I/O error occurred"; |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
432 } |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
433 } else { |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
434 p = PY_SSL_ERROR_SYSCALL; |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
435 } |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
436 break; |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
437 } |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
438 case SSL_ERROR_SSL: |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
439 { |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
440 p = PY_SSL_ERROR_SSL; |
|
77578
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
441 if (e == 0) |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
442 /* possible? */ |
|
61537
330273ec6028
Merged revisions 81116 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61246
diff
changeset
|
443 errstr = "A failure in the SSL library occurred"; |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
444 break; |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
445 } |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
446 default: |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
447 p = PY_SSL_ERROR_INVALID_ERROR_CODE; |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
448 errstr = "Invalid error code"; |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
449 } |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
450 } |
|
77578
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
451 fill_and_set_sslerror(type, p, errstr, lineno, e); |
|
61646
8b6401ae1262
Merged revisions 81242 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61537
diff
changeset
|
452 ERR_clear_error(); |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
453 return NULL; |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
454 } |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
455 |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
456 static PyObject * |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
457 _setSSLError (char *errstr, int errcode, char *filename, int lineno) { |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
458 |
|
77578
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
459 if (errstr == NULL) |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
460 errcode = ERR_peek_last_error(); |
|
77578
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
461 else |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
462 errcode = 0; |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
463 fill_and_set_sslerror(PySSLErrorObject, errcode, errstr, lineno, errcode); |
|
61646
8b6401ae1262
Merged revisions 81242 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61537
diff
changeset
|
464 ERR_clear_error(); |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
465 return NULL; |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
466 } |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
467 |
|
77578
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
468 /* |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
469 * SSL objects |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
470 */ |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
471 |
|
61635
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
472 static PySSLSocket * |
|
81298
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
473 newPySSLSocket(PySSLContext *sslctx, PySocketSockObject *sock, |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
474 enum py_ssl_server_or_client socket_type, |
|
65593
846c0e1342d0
Issue #5639: Add a *server_hostname* argument to `SSLContext.wrap_socket`
Antoine Pitrou <solipsis@pitrou.net>
parents:
65267
diff
changeset
|
475 char *server_hostname) |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
476 { |
|
61635
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
477 PySSLSocket *self; |
|
81298
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
478 SSL_CTX *ctx = sslctx->ctx; |
|
83918
0bf4a6b56eb5
Fix compilation under MSVC: ssl_set_mode() is a macro, and the MSVC preprocessor doesn't process #ifdef's inside a macro argument list.
Antoine Pitrou <solipsis@pitrou.net>
parents:
83915
diff
changeset
|
479 long mode; |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
480 |
|
61635
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
481 self = PyObject_New(PySSLSocket, &PySSLSocket_Type); |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
482 if (self == NULL) |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
483 return NULL; |
|
61635
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
484 |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
485 self->peer_cert = NULL; |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
486 self->ssl = NULL; |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
487 self->Socket = NULL; |
|
81298
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
488 self->ctx = sslctx; |
|
85858
e27c767b8d4f
Properly initialize all fields of a SSL object after allocation.
Antoine Pitrou <solipsis@pitrou.net>
parents:
85535
diff
changeset
|
489 self->shutdown_seen_zero = 0; |
|
85857
ddcdf7f7eac8
Issue #19095: SSLSocket.getpeercert() now raises ValueError when the SSL handshake hasn't been done.
Antoine Pitrou <solipsis@pitrou.net>
parents:
85536
diff
changeset
|
490 self->handshake_done = 0; |
|
81298
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
491 Py_INCREF(sslctx); |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
492 |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
493 /* Make sure the SSL error state is initialized */ |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
494 (void) ERR_get_state(); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
495 ERR_clear_error(); |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
496 |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
497 PySSL_BEGIN_ALLOW_THREADS |
|
61635
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
498 self->ssl = SSL_new(ctx); |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
499 PySSL_END_ALLOW_THREADS |
|
81298
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
500 SSL_set_app_data(self->ssl,self); |
|
61635
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
501 SSL_set_fd(self->ssl, sock->sock_fd); |
|
83918
0bf4a6b56eb5
Fix compilation under MSVC: ssl_set_mode() is a macro, and the MSVC preprocessor doesn't process #ifdef's inside a macro argument list.
Antoine Pitrou <solipsis@pitrou.net>
parents:
83915
diff
changeset
|
502 mode = SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER; |
|
60464
837f3bb1575f
Merged revisions 79912 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60038
diff
changeset
|
503 #ifdef SSL_MODE_AUTO_RETRY |
|
83918
0bf4a6b56eb5
Fix compilation under MSVC: ssl_set_mode() is a macro, and the MSVC preprocessor doesn't process #ifdef's inside a macro argument list.
Antoine Pitrou <solipsis@pitrou.net>
parents:
83915
diff
changeset
|
504 mode |= SSL_MODE_AUTO_RETRY; |
|
60464
837f3bb1575f
Merged revisions 79912 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60038
diff
changeset
|
505 #endif |
|
83918
0bf4a6b56eb5
Fix compilation under MSVC: ssl_set_mode() is a macro, and the MSVC preprocessor doesn't process #ifdef's inside a macro argument list.
Antoine Pitrou <solipsis@pitrou.net>
parents:
83915
diff
changeset
|
506 SSL_set_mode(self->ssl, mode); |
|
27557
5eefec94a784
SF patch 676472 by Geoff Talvola, reviewed by Ben Laurie.
Guido van Rossum <guido@python.org>
parents:
27430
diff
changeset
|
507 |
|
83021
02f9335b7efb
Issue #17581: try to fix building on old OpenSSL versions
Antoine Pitrou <solipsis@pitrou.net>
parents:
82992
diff
changeset
|
508 #if HAVE_SNI |
|
65593
846c0e1342d0
Issue #5639: Add a *server_hostname* argument to `SSLContext.wrap_socket`
Antoine Pitrou <solipsis@pitrou.net>
parents:
65267
diff
changeset
|
509 if (server_hostname != NULL) |
|
846c0e1342d0
Issue #5639: Add a *server_hostname* argument to `SSLContext.wrap_socket`
Antoine Pitrou <solipsis@pitrou.net>
parents:
65267
diff
changeset
|
510 SSL_set_tlsext_host_name(self->ssl, server_hostname); |
|
846c0e1342d0
Issue #5639: Add a *server_hostname* argument to `SSLContext.wrap_socket`
Antoine Pitrou <solipsis@pitrou.net>
parents:
65267
diff
changeset
|
511 #endif |
|
846c0e1342d0
Issue #5639: Add a *server_hostname* argument to `SSLContext.wrap_socket`
Antoine Pitrou <solipsis@pitrou.net>
parents:
65267
diff
changeset
|
512 |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
513 /* If the socket is in non-blocking mode or timeout mode, set the BIO |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
514 * to non-blocking mode (blocking is the default) |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
515 */ |
|
61635
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
516 if (sock->sock_timeout >= 0.0) { |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
517 BIO_set_nbio(SSL_get_rbio(self->ssl), 1); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
518 BIO_set_nbio(SSL_get_wbio(self->ssl), 1); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
519 } |
|
27557
5eefec94a784
SF patch 676472 by Geoff Talvola, reviewed by Ben Laurie.
Guido van Rossum <guido@python.org>
parents:
27430
diff
changeset
|
520 |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
521 PySSL_BEGIN_ALLOW_THREADS |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
522 if (socket_type == PY_SSL_CLIENT) |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
523 SSL_set_connect_state(self->ssl); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
524 else |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
525 SSL_set_accept_state(self->ssl); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
526 PySSL_END_ALLOW_THREADS |
|
24398
c7ed925c75b3
Patch #575827: allow threads inside SSL creation.
Martin v. Löwis <martin@v.loewis.de>
parents:
24280
diff
changeset
|
527 |
|
71440
cb44fef5ea1d
Issue #12551: Provide a get_channel_binding() method on SSL sockets so as
Antoine Pitrou <solipsis@pitrou.net>
parents:
71256
diff
changeset
|
528 self->socket_type = socket_type; |
|
61635
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
529 self->Socket = PyWeakref_NewRef((PyObject *) sock, NULL); |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
530 return self; |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
531 } |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
532 |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
533 /* SSL object methods */ |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
534 |
|
61635
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
535 static PyObject *PySSL_SSLdo_handshake(PySSLSocket *self) |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
536 { |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
537 int ret; |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
538 int err; |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
539 int sockstate, nonblocking; |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
540 PySocketSockObject *sock |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
541 = (PySocketSockObject *) PyWeakref_GetObject(self->Socket); |
|
60936
5ed34f3f6c35
Merged revisions 80454 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60901
diff
changeset
|
542 |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
543 if (((PyObject*)sock) == Py_None) { |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
544 _setSSLError("Underlying socket connection gone", |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
545 PY_SSL_ERROR_NO_SOCKET, __FILE__, __LINE__); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
546 return NULL; |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
547 } |
|
62481
b8b0a15f8a7c
Merged revisions 82204 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61646
diff
changeset
|
548 Py_INCREF(sock); |
|
60936
5ed34f3f6c35
Merged revisions 80454 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60901
diff
changeset
|
549 |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
550 /* just in case the blocking state of the socket has been changed */ |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
551 nonblocking = (sock->sock_timeout >= 0.0); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
552 BIO_set_nbio(SSL_get_rbio(self->ssl), nonblocking); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
553 BIO_set_nbio(SSL_get_wbio(self->ssl), nonblocking); |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
554 |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
555 /* Actually negotiate SSL connection */ |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
556 /* XXX If SSL_do_handshake() returns 0, it's also a failure. */ |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
557 do { |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
558 PySSL_BEGIN_ALLOW_THREADS |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
559 ret = SSL_do_handshake(self->ssl); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
560 err = SSL_get_error(self->ssl, ret); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
561 PySSL_END_ALLOW_THREADS |
|
62481
b8b0a15f8a7c
Merged revisions 82204 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61646
diff
changeset
|
562 if (PyErr_CheckSignals()) |
|
b8b0a15f8a7c
Merged revisions 82204 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61646
diff
changeset
|
563 goto error; |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
564 if (err == SSL_ERROR_WANT_READ) { |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
565 sockstate = check_socket_and_wait_for_timeout(sock, 0); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
566 } else if (err == SSL_ERROR_WANT_WRITE) { |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
567 sockstate = check_socket_and_wait_for_timeout(sock, 1); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
568 } else { |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
569 sockstate = SOCKET_OPERATION_OK; |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
570 } |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
571 if (sockstate == SOCKET_HAS_TIMED_OUT) { |
|
66663
3d9a86b8cc98
Issue #10272: The ssl module now raises socket.timeout instead of a generic
Antoine Pitrou <solipsis@pitrou.net>
parents:
66217
diff
changeset
|
572 PyErr_SetString(PySocketModule.timeout_error, |
|
61537
330273ec6028
Merged revisions 81116 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61246
diff
changeset
|
573 ERRSTR("The handshake operation timed out")); |
|
62481
b8b0a15f8a7c
Merged revisions 82204 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61646
diff
changeset
|
574 goto error; |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
575 } else if (sockstate == SOCKET_HAS_BEEN_CLOSED) { |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
576 PyErr_SetString(PySSLErrorObject, |
|
61537
330273ec6028
Merged revisions 81116 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61246
diff
changeset
|
577 ERRSTR("Underlying socket has been closed.")); |
|
62481
b8b0a15f8a7c
Merged revisions 82204 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61646
diff
changeset
|
578 goto error; |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
579 } else if (sockstate == SOCKET_TOO_LARGE_FOR_SELECT) { |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
580 PyErr_SetString(PySSLErrorObject, |
|
61537
330273ec6028
Merged revisions 81116 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61246
diff
changeset
|
581 ERRSTR("Underlying socket too large for select().")); |
|
62481
b8b0a15f8a7c
Merged revisions 82204 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61646
diff
changeset
|
582 goto error; |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
583 } else if (sockstate == SOCKET_IS_NONBLOCKING) { |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
584 break; |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
585 } |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
586 } while (err == SSL_ERROR_WANT_READ || err == SSL_ERROR_WANT_WRITE); |
|
62481
b8b0a15f8a7c
Merged revisions 82204 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61646
diff
changeset
|
587 Py_DECREF(sock); |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
588 if (ret < 1) |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
589 return PySSL_SetError(self, ret, __FILE__, __LINE__); |
|
43869
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
590 |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
591 if (self->peer_cert) |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
592 X509_free (self->peer_cert); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
593 PySSL_BEGIN_ALLOW_THREADS |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
594 self->peer_cert = SSL_get_peer_certificate(self->ssl); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
595 PySSL_END_ALLOW_THREADS |
|
85857
ddcdf7f7eac8
Issue #19095: SSLSocket.getpeercert() now raises ValueError when the SSL handshake hasn't been done.
Antoine Pitrou <solipsis@pitrou.net>
parents:
85536
diff
changeset
|
596 self->handshake_done = 1; |
|
43869
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
597 |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
598 Py_INCREF(Py_None); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
599 return Py_None; |
|
62481
b8b0a15f8a7c
Merged revisions 82204 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61646
diff
changeset
|
600 |
|
b8b0a15f8a7c
Merged revisions 82204 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61646
diff
changeset
|
601 error: |
|
b8b0a15f8a7c
Merged revisions 82204 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61646
diff
changeset
|
602 Py_DECREF(sock); |
|
b8b0a15f8a7c
Merged revisions 82204 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61646
diff
changeset
|
603 return NULL; |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
604 } |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
605 |
|
42954
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
606 static PyObject * |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
607 _create_tuple_for_attribute (ASN1_OBJECT *name, ASN1_STRING *value) { |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
608 |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
609 char namebuf[X509_NAME_MAXLEN]; |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
610 int buflen; |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
611 PyObject *name_obj; |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
612 PyObject *value_obj; |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
613 PyObject *attr; |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
614 unsigned char *valuebuf = NULL; |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
615 |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
616 buflen = OBJ_obj2txt(namebuf, sizeof(namebuf), name, 0); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
617 if (buflen < 0) { |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
618 _setSSLError(NULL, 0, __FILE__, __LINE__); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
619 goto fail; |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
620 } |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
621 name_obj = PyUnicode_FromStringAndSize(namebuf, buflen); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
622 if (name_obj == NULL) |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
623 goto fail; |
|
43948
8e0c4c710375
Make read() and certificate() return bytes instead of bytearray instances.
Guido van Rossum <guido@python.org>
parents:
43869
diff
changeset
|
624 |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
625 buflen = ASN1_STRING_to_UTF8(&valuebuf, value); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
626 if (buflen < 0) { |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
627 _setSSLError(NULL, 0, __FILE__, __LINE__); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
628 Py_DECREF(name_obj); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
629 goto fail; |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
630 } |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
631 value_obj = PyUnicode_DecodeUTF8((char *) valuebuf, |
|
61537
330273ec6028
Merged revisions 81116 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61246
diff
changeset
|
632 buflen, "strict"); |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
633 OPENSSL_free(valuebuf); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
634 if (value_obj == NULL) { |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
635 Py_DECREF(name_obj); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
636 goto fail; |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
637 } |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
638 attr = PyTuple_New(2); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
639 if (attr == NULL) { |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
640 Py_DECREF(name_obj); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
641 Py_DECREF(value_obj); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
642 goto fail; |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
643 } |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
644 PyTuple_SET_ITEM(attr, 0, name_obj); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
645 PyTuple_SET_ITEM(attr, 1, value_obj); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
646 return attr; |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
647 |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
648 fail: |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
649 return NULL; |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
650 } |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
651 |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
652 static PyObject * |
|
43292
876b7ef4775d
Merged revisions 57778-58052 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
42954
diff
changeset
|
653 _create_tuple_for_X509_NAME (X509_NAME *xname) |
|
42954
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
654 { |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
655 PyObject *dn = NULL; /* tuple which represents the "distinguished name" */ |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
656 PyObject *rdn = NULL; /* tuple to hold a "relative distinguished name" */ |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
657 PyObject *rdnt; |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
658 PyObject *attr = NULL; /* tuple to hold an attribute */ |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
659 int entry_count = X509_NAME_entry_count(xname); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
660 X509_NAME_ENTRY *entry; |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
661 ASN1_OBJECT *name; |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
662 ASN1_STRING *value; |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
663 int index_counter; |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
664 int rdn_level = -1; |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
665 int retcode; |
|
42954
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
666 |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
667 dn = PyList_New(0); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
668 if (dn == NULL) |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
669 return NULL; |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
670 /* now create another tuple to hold the top-level RDN */ |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
671 rdn = PyList_New(0); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
672 if (rdn == NULL) |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
673 goto fail0; |
|
42954
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
674 |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
675 for (index_counter = 0; |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
676 index_counter < entry_count; |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
677 index_counter++) |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
678 { |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
679 entry = X509_NAME_get_entry(xname, index_counter); |
|
42954
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
680 |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
681 /* check to see if we've gotten to a new RDN */ |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
682 if (rdn_level >= 0) { |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
683 if (rdn_level != entry->set) { |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
684 /* yes, new RDN */ |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
685 /* add old RDN to DN */ |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
686 rdnt = PyList_AsTuple(rdn); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
687 Py_DECREF(rdn); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
688 if (rdnt == NULL) |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
689 goto fail0; |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
690 retcode = PyList_Append(dn, rdnt); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
691 Py_DECREF(rdnt); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
692 if (retcode < 0) |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
693 goto fail0; |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
694 /* create new RDN */ |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
695 rdn = PyList_New(0); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
696 if (rdn == NULL) |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
697 goto fail0; |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
698 } |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
699 } |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
700 rdn_level = entry->set; |
|
42954
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
701 |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
702 /* now add this attribute to the current RDN */ |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
703 name = X509_NAME_ENTRY_get_object(entry); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
704 value = X509_NAME_ENTRY_get_data(entry); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
705 attr = _create_tuple_for_attribute(name, value); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
706 /* |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
707 fprintf(stderr, "RDN level %d, attribute %s: %s\n", |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
708 entry->set, |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
709 PyBytes_AS_STRING(PyTuple_GET_ITEM(attr, 0)), |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
710 PyBytes_AS_STRING(PyTuple_GET_ITEM(attr, 1))); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
711 */ |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
712 if (attr == NULL) |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
713 goto fail1; |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
714 retcode = PyList_Append(rdn, attr); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
715 Py_DECREF(attr); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
716 if (retcode < 0) |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
717 goto fail1; |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
718 } |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
719 /* now, there's typically a dangling RDN */ |
|
74963
f3a4c2b34973
Issue #13014: Fix a possible reference leak in SSLSocket.getpeercert().
Antoine Pitrou <solipsis@pitrou.net>
parents:
74648
diff
changeset
|
720 if (rdn != NULL) { |
|
f3a4c2b34973
Issue #13014: Fix a possible reference leak in SSLSocket.getpeercert().
Antoine Pitrou <solipsis@pitrou.net>
parents:
74648
diff
changeset
|
721 if (PyList_GET_SIZE(rdn) > 0) { |
|
f3a4c2b34973
Issue #13014: Fix a possible reference leak in SSLSocket.getpeercert().
Antoine Pitrou <solipsis@pitrou.net>
parents:
74648
diff
changeset
|
722 rdnt = PyList_AsTuple(rdn); |
|
f3a4c2b34973
Issue #13014: Fix a possible reference leak in SSLSocket.getpeercert().
Antoine Pitrou <solipsis@pitrou.net>
parents:
74648
diff
changeset
|
723 Py_DECREF(rdn); |
|
f3a4c2b34973
Issue #13014: Fix a possible reference leak in SSLSocket.getpeercert().
Antoine Pitrou <solipsis@pitrou.net>
parents:
74648
diff
changeset
|
724 if (rdnt == NULL) |
|
f3a4c2b34973
Issue #13014: Fix a possible reference leak in SSLSocket.getpeercert().
Antoine Pitrou <solipsis@pitrou.net>
parents:
74648
diff
changeset
|
725 goto fail0; |
|
f3a4c2b34973
Issue #13014: Fix a possible reference leak in SSLSocket.getpeercert().
Antoine Pitrou <solipsis@pitrou.net>
parents:
74648
diff
changeset
|
726 retcode = PyList_Append(dn, rdnt); |
|
f3a4c2b34973
Issue #13014: Fix a possible reference leak in SSLSocket.getpeercert().
Antoine Pitrou <solipsis@pitrou.net>
parents:
74648
diff
changeset
|
727 Py_DECREF(rdnt); |
|
f3a4c2b34973
Issue #13014: Fix a possible reference leak in SSLSocket.getpeercert().
Antoine Pitrou <solipsis@pitrou.net>
parents:
74648
diff
changeset
|
728 if (retcode < 0) |
|
f3a4c2b34973
Issue #13014: Fix a possible reference leak in SSLSocket.getpeercert().
Antoine Pitrou <solipsis@pitrou.net>
parents:
74648
diff
changeset
|
729 goto fail0; |
|
f3a4c2b34973
Issue #13014: Fix a possible reference leak in SSLSocket.getpeercert().
Antoine Pitrou <solipsis@pitrou.net>
parents:
74648
diff
changeset
|
730 } |
|
f3a4c2b34973
Issue #13014: Fix a possible reference leak in SSLSocket.getpeercert().
Antoine Pitrou <solipsis@pitrou.net>
parents:
74648
diff
changeset
|
731 else { |
|
f3a4c2b34973
Issue #13014: Fix a possible reference leak in SSLSocket.getpeercert().
Antoine Pitrou <solipsis@pitrou.net>
parents:
74648
diff
changeset
|
732 Py_DECREF(rdn); |
|
f3a4c2b34973
Issue #13014: Fix a possible reference leak in SSLSocket.getpeercert().
Antoine Pitrou <solipsis@pitrou.net>
parents:
74648
diff
changeset
|
733 } |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
734 } |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
735 |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
736 /* convert list to tuple */ |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
737 rdnt = PyList_AsTuple(dn); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
738 Py_DECREF(dn); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
739 if (rdnt == NULL) |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
740 return NULL; |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
741 return rdnt; |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
742 |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
743 fail1: |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
744 Py_XDECREF(rdn); |
|
42954
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
745 |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
746 fail0: |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
747 Py_XDECREF(dn); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
748 return NULL; |
|
42954
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
749 } |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
750 |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
751 static PyObject * |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
752 _get_peer_alt_names (X509 *certificate) { |
|
43948
8e0c4c710375
Make read() and certificate() return bytes instead of bytearray instances.
Guido van Rossum <guido@python.org>
parents:
43869
diff
changeset
|
753 |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
754 /* this code follows the procedure outlined in |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
755 OpenSSL's crypto/x509v3/v3_prn.c:X509v3_EXT_print() |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
756 function to extract the STACK_OF(GENERAL_NAME), |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
757 then iterates through the stack to add the |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
758 names. */ |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
759 |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
760 int i, j; |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
761 PyObject *peer_alt_names = Py_None; |
|
85535
90040e560527
Issue #18709: GCC 4.6 complains that 'v' may be used uninitialized in GEN_EMAIL/GEN_URI/GEN_DNS case
Christian Heimes <christian@cheimes.de>
parents:
85378
diff
changeset
|
762 PyObject *v = NULL, *t; |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
763 X509_EXTENSION *ext = NULL; |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
764 GENERAL_NAMES *names = NULL; |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
765 GENERAL_NAME *name; |
|
65272
4755744724f2
Merged revisions 85432 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
64404
diff
changeset
|
766 const X509V3_EXT_METHOD *method; |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
767 BIO *biobuf = NULL; |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
768 char buf[2048]; |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
769 char *vptr; |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
770 int len; |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
771 /* Issue #2973: ASN1_item_d2i() API changed in OpenSSL 0.9.6m */ |
|
59279
951c97e2878d
Merged revisions 78598 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
54917
diff
changeset
|
772 #if OPENSSL_VERSION_NUMBER >= 0x009060dfL |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
773 const unsigned char *p; |
|
59279
951c97e2878d
Merged revisions 78598 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
54917
diff
changeset
|
774 #else |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
775 unsigned char *p; |
|
59279
951c97e2878d
Merged revisions 78598 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
54917
diff
changeset
|
776 #endif |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
777 |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
778 if (certificate == NULL) |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
779 return peer_alt_names; |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
780 |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
781 /* get a memory buffer */ |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
782 biobuf = BIO_new(BIO_s_mem()); |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
783 |
|
72567
65e7f40fefd4
Issue #13034: When decoding some SSL certificates, the subjectAltName extension could be unreported.
Antoine Pitrou <solipsis@pitrou.net>
parents:
72115
diff
changeset
|
784 i = -1; |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
785 while ((i = X509_get_ext_by_NID( |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
786 certificate, NID_subject_alt_name, i)) >= 0) { |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
787 |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
788 if (peer_alt_names == Py_None) { |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
789 peer_alt_names = PyList_New(0); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
790 if (peer_alt_names == NULL) |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
791 goto fail; |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
792 } |
|
43948
8e0c4c710375
Make read() and certificate() return bytes instead of bytearray instances.
Guido van Rossum <guido@python.org>
parents:
43869
diff
changeset
|
793 |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
794 /* now decode the altName */ |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
795 ext = X509_get_ext(certificate, i); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
796 if(!(method = X509V3_EXT_get(ext))) { |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
797 PyErr_SetString |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
798 (PySSLErrorObject, |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
799 ERRSTR("No method for internalizing subjectAltName!")); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
800 goto fail; |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
801 } |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
802 |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
803 p = ext->value->data; |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
804 if (method->it) |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
805 names = (GENERAL_NAMES*) |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
806 (ASN1_item_d2i(NULL, |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
807 &p, |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
808 ext->value->length, |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
809 ASN1_ITEM_ptr(method->it))); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
810 else |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
811 names = (GENERAL_NAMES*) |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
812 (method->d2i(NULL, |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
813 &p, |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
814 ext->value->length)); |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
815 |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
816 for(j = 0; j < sk_GENERAL_NAME_num(names); j++) { |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
817 /* get a rendering of each name in the set of names */ |
|
85211
c9f073e593b0
Issue #18709: Fix CVE-2013-4238. The SSL module now handles NULL bytes
Christian Heimes <christian@cheimes.de>
parents:
84838
diff
changeset
|
818 int gntype; |
|
c9f073e593b0
Issue #18709: Fix CVE-2013-4238. The SSL module now handles NULL bytes
Christian Heimes <christian@cheimes.de>
parents:
84838
diff
changeset
|
819 ASN1_STRING *as = NULL; |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
820 |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
821 name = sk_GENERAL_NAME_value(names, j); |
|
85233
b352a5cb60b6
Issue #18768: coding style nitpick. Thanks to Vajrasky Kok
Christian Heimes <christian@cheimes.de>
parents:
85231
diff
changeset
|
822 gntype = name->type; |
|
85211
c9f073e593b0
Issue #18709: Fix CVE-2013-4238. The SSL module now handles NULL bytes
Christian Heimes <christian@cheimes.de>
parents:
84838
diff
changeset
|
823 switch (gntype) { |
|
c9f073e593b0
Issue #18709: Fix CVE-2013-4238. The SSL module now handles NULL bytes
Christian Heimes <christian@cheimes.de>
parents:
84838
diff
changeset
|
824 case GEN_DIRNAME: |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
825 /* we special-case DirName as a tuple of |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
826 tuples of attributes */ |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
827 |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
828 t = PyTuple_New(2); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
829 if (t == NULL) { |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
830 goto fail; |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
831 } |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
832 |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
833 v = PyUnicode_FromString("DirName"); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
834 if (v == NULL) { |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
835 Py_DECREF(t); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
836 goto fail; |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
837 } |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
838 PyTuple_SET_ITEM(t, 0, v); |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
839 |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
840 v = _create_tuple_for_X509_NAME (name->d.dirn); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
841 if (v == NULL) { |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
842 Py_DECREF(t); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
843 goto fail; |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
844 } |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
845 PyTuple_SET_ITEM(t, 1, v); |
|
85211
c9f073e593b0
Issue #18709: Fix CVE-2013-4238. The SSL module now handles NULL bytes
Christian Heimes <christian@cheimes.de>
parents:
84838
diff
changeset
|
846 break; |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
847 |
|
85211
c9f073e593b0
Issue #18709: Fix CVE-2013-4238. The SSL module now handles NULL bytes
Christian Heimes <christian@cheimes.de>
parents:
84838
diff
changeset
|
848 case GEN_EMAIL: |
|
c9f073e593b0
Issue #18709: Fix CVE-2013-4238. The SSL module now handles NULL bytes
Christian Heimes <christian@cheimes.de>
parents:
84838
diff
changeset
|
849 case GEN_DNS: |
|
c9f073e593b0
Issue #18709: Fix CVE-2013-4238. The SSL module now handles NULL bytes
Christian Heimes <christian@cheimes.de>
parents:
84838
diff
changeset
|
850 case GEN_URI: |
|
c9f073e593b0
Issue #18709: Fix CVE-2013-4238. The SSL module now handles NULL bytes
Christian Heimes <christian@cheimes.de>
parents:
84838
diff
changeset
|
851 /* GENERAL_NAME_print() doesn't handle NULL bytes in ASN1_string |
|
c9f073e593b0
Issue #18709: Fix CVE-2013-4238. The SSL module now handles NULL bytes
Christian Heimes <christian@cheimes.de>
parents:
84838
diff
changeset
|
852 correctly, CVE-2013-4238 */ |
|
c9f073e593b0
Issue #18709: Fix CVE-2013-4238. The SSL module now handles NULL bytes
Christian Heimes <christian@cheimes.de>
parents:
84838
diff
changeset
|
853 t = PyTuple_New(2); |
|
c9f073e593b0
Issue #18709: Fix CVE-2013-4238. The SSL module now handles NULL bytes
Christian Heimes <christian@cheimes.de>
parents:
84838
diff
changeset
|
854 if (t == NULL) |
|
c9f073e593b0
Issue #18709: Fix CVE-2013-4238. The SSL module now handles NULL bytes
Christian Heimes <christian@cheimes.de>
parents:
84838
diff
changeset
|
855 goto fail; |
|
c9f073e593b0
Issue #18709: Fix CVE-2013-4238. The SSL module now handles NULL bytes
Christian Heimes <christian@cheimes.de>
parents:
84838
diff
changeset
|
856 switch (gntype) { |
|
c9f073e593b0
Issue #18709: Fix CVE-2013-4238. The SSL module now handles NULL bytes
Christian Heimes <christian@cheimes.de>
parents:
84838
diff
changeset
|
857 case GEN_EMAIL: |
|
c9f073e593b0
Issue #18709: Fix CVE-2013-4238. The SSL module now handles NULL bytes
Christian Heimes <christian@cheimes.de>
parents:
84838
diff
changeset
|
858 v = PyUnicode_FromString("email"); |
|
c9f073e593b0
Issue #18709: Fix CVE-2013-4238. The SSL module now handles NULL bytes
Christian Heimes <christian@cheimes.de>
parents:
84838
diff
changeset
|
859 as = name->d.rfc822Name; |
|
c9f073e593b0
Issue #18709: Fix CVE-2013-4238. The SSL module now handles NULL bytes
Christian Heimes <christian@cheimes.de>
parents:
84838
diff
changeset
|
860 break; |
|
c9f073e593b0
Issue #18709: Fix CVE-2013-4238. The SSL module now handles NULL bytes
Christian Heimes <christian@cheimes.de>
parents:
84838
diff
changeset
|
861 case GEN_DNS: |
|
c9f073e593b0
Issue #18709: Fix CVE-2013-4238. The SSL module now handles NULL bytes
Christian Heimes <christian@cheimes.de>
parents:
84838
diff
changeset
|
862 v = PyUnicode_FromString("DNS"); |
|
c9f073e593b0
Issue #18709: Fix CVE-2013-4238. The SSL module now handles NULL bytes
Christian Heimes <christian@cheimes.de>
parents:
84838
diff
changeset
|
863 as = name->d.dNSName; |
|
c9f073e593b0
Issue #18709: Fix CVE-2013-4238. The SSL module now handles NULL bytes
Christian Heimes <christian@cheimes.de>
parents:
84838
diff
changeset
|
864 break; |
|
c9f073e593b0
Issue #18709: Fix CVE-2013-4238. The SSL module now handles NULL bytes
Christian Heimes <christian@cheimes.de>
parents:
84838
diff
changeset
|
865 case GEN_URI: |
|
c9f073e593b0
Issue #18709: Fix CVE-2013-4238. The SSL module now handles NULL bytes
Christian Heimes <christian@cheimes.de>
parents:
84838
diff
changeset
|
866 v = PyUnicode_FromString("URI"); |
|
c9f073e593b0
Issue #18709: Fix CVE-2013-4238. The SSL module now handles NULL bytes
Christian Heimes <christian@cheimes.de>
parents:
84838
diff
changeset
|
867 as = name->d.uniformResourceIdentifier; |
|
c9f073e593b0
Issue #18709: Fix CVE-2013-4238. The SSL module now handles NULL bytes
Christian Heimes <christian@cheimes.de>
parents:
84838
diff
changeset
|
868 break; |
|
c9f073e593b0
Issue #18709: Fix CVE-2013-4238. The SSL module now handles NULL bytes
Christian Heimes <christian@cheimes.de>
parents:
84838
diff
changeset
|
869 } |
|
c9f073e593b0
Issue #18709: Fix CVE-2013-4238. The SSL module now handles NULL bytes
Christian Heimes <christian@cheimes.de>
parents:
84838
diff
changeset
|
870 if (v == NULL) { |
|
c9f073e593b0
Issue #18709: Fix CVE-2013-4238. The SSL module now handles NULL bytes
Christian Heimes <christian@cheimes.de>
parents:
84838
diff
changeset
|
871 Py_DECREF(t); |
|
c9f073e593b0
Issue #18709: Fix CVE-2013-4238. The SSL module now handles NULL bytes
Christian Heimes <christian@cheimes.de>
parents:
84838
diff
changeset
|
872 goto fail; |
|
c9f073e593b0
Issue #18709: Fix CVE-2013-4238. The SSL module now handles NULL bytes
Christian Heimes <christian@cheimes.de>
parents:
84838
diff
changeset
|
873 } |
|
c9f073e593b0
Issue #18709: Fix CVE-2013-4238. The SSL module now handles NULL bytes
Christian Heimes <christian@cheimes.de>
parents:
84838
diff
changeset
|
874 PyTuple_SET_ITEM(t, 0, v); |
|
c9f073e593b0
Issue #18709: Fix CVE-2013-4238. The SSL module now handles NULL bytes
Christian Heimes <christian@cheimes.de>
parents:
84838
diff
changeset
|
875 v = PyUnicode_FromStringAndSize((char *)ASN1_STRING_data(as), |
|
c9f073e593b0
Issue #18709: Fix CVE-2013-4238. The SSL module now handles NULL bytes
Christian Heimes <christian@cheimes.de>
parents:
84838
diff
changeset
|
876 ASN1_STRING_length(as)); |
|
c9f073e593b0
Issue #18709: Fix CVE-2013-4238. The SSL module now handles NULL bytes
Christian Heimes <christian@cheimes.de>
parents:
84838
diff
changeset
|
877 if (v == NULL) { |
|
c9f073e593b0
Issue #18709: Fix CVE-2013-4238. The SSL module now handles NULL bytes
Christian Heimes <christian@cheimes.de>
parents:
84838
diff
changeset
|
878 Py_DECREF(t); |
|
c9f073e593b0
Issue #18709: Fix CVE-2013-4238. The SSL module now handles NULL bytes
Christian Heimes <christian@cheimes.de>
parents:
84838
diff
changeset
|
879 goto fail; |
|
c9f073e593b0
Issue #18709: Fix CVE-2013-4238. The SSL module now handles NULL bytes
Christian Heimes <christian@cheimes.de>
parents:
84838
diff
changeset
|
880 } |
|
c9f073e593b0
Issue #18709: Fix CVE-2013-4238. The SSL module now handles NULL bytes
Christian Heimes <christian@cheimes.de>
parents:
84838
diff
changeset
|
881 PyTuple_SET_ITEM(t, 1, v); |
|
c9f073e593b0
Issue #18709: Fix CVE-2013-4238. The SSL module now handles NULL bytes
Christian Heimes <christian@cheimes.de>
parents:
84838
diff
changeset
|
882 break; |
|
c9f073e593b0
Issue #18709: Fix CVE-2013-4238. The SSL module now handles NULL bytes
Christian Heimes <christian@cheimes.de>
parents:
84838
diff
changeset
|
883 |
|
c9f073e593b0
Issue #18709: Fix CVE-2013-4238. The SSL module now handles NULL bytes
Christian Heimes <christian@cheimes.de>
parents:
84838
diff
changeset
|
884 default: |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
885 /* for everything else, we use the OpenSSL print form */ |
|
85211
c9f073e593b0
Issue #18709: Fix CVE-2013-4238. The SSL module now handles NULL bytes
Christian Heimes <christian@cheimes.de>
parents:
84838
diff
changeset
|
886 switch (gntype) { |
|
c9f073e593b0
Issue #18709: Fix CVE-2013-4238. The SSL module now handles NULL bytes
Christian Heimes <christian@cheimes.de>
parents:
84838
diff
changeset
|
887 /* check for new general name type */ |
|
c9f073e593b0
Issue #18709: Fix CVE-2013-4238. The SSL module now handles NULL bytes
Christian Heimes <christian@cheimes.de>
parents:
84838
diff
changeset
|
888 case GEN_OTHERNAME: |
|
c9f073e593b0
Issue #18709: Fix CVE-2013-4238. The SSL module now handles NULL bytes
Christian Heimes <christian@cheimes.de>
parents:
84838
diff
changeset
|
889 case GEN_X400: |
|
c9f073e593b0
Issue #18709: Fix CVE-2013-4238. The SSL module now handles NULL bytes
Christian Heimes <christian@cheimes.de>
parents:
84838
diff
changeset
|
890 case GEN_EDIPARTY: |
|
c9f073e593b0
Issue #18709: Fix CVE-2013-4238. The SSL module now handles NULL bytes
Christian Heimes <christian@cheimes.de>
parents:
84838
diff
changeset
|
891 case GEN_IPADD: |
|
c9f073e593b0
Issue #18709: Fix CVE-2013-4238. The SSL module now handles NULL bytes
Christian Heimes <christian@cheimes.de>
parents:
84838
diff
changeset
|
892 case GEN_RID: |
|
c9f073e593b0
Issue #18709: Fix CVE-2013-4238. The SSL module now handles NULL bytes
Christian Heimes <christian@cheimes.de>
parents:
84838
diff
changeset
|
893 break; |
|
c9f073e593b0
Issue #18709: Fix CVE-2013-4238. The SSL module now handles NULL bytes
Christian Heimes <christian@cheimes.de>
parents:
84838
diff
changeset
|
894 default: |
|
c9f073e593b0
Issue #18709: Fix CVE-2013-4238. The SSL module now handles NULL bytes
Christian Heimes <christian@cheimes.de>
parents:
84838
diff
changeset
|
895 if (PyErr_WarnFormat(PyExc_RuntimeWarning, 1, |
|
c9f073e593b0
Issue #18709: Fix CVE-2013-4238. The SSL module now handles NULL bytes
Christian Heimes <christian@cheimes.de>
parents:
84838
diff
changeset
|
896 "Unknown general name type %d", |
|
c9f073e593b0
Issue #18709: Fix CVE-2013-4238. The SSL module now handles NULL bytes
Christian Heimes <christian@cheimes.de>
parents:
84838
diff
changeset
|
897 gntype) == -1) { |
|
c9f073e593b0
Issue #18709: Fix CVE-2013-4238. The SSL module now handles NULL bytes
Christian Heimes <christian@cheimes.de>
parents:
84838
diff
changeset
|
898 goto fail; |
|
c9f073e593b0
Issue #18709: Fix CVE-2013-4238. The SSL module now handles NULL bytes
Christian Heimes <christian@cheimes.de>
parents:
84838
diff
changeset
|
899 } |
|
c9f073e593b0
Issue #18709: Fix CVE-2013-4238. The SSL module now handles NULL bytes
Christian Heimes <christian@cheimes.de>
parents:
84838
diff
changeset
|
900 break; |
|
c9f073e593b0
Issue #18709: Fix CVE-2013-4238. The SSL module now handles NULL bytes
Christian Heimes <christian@cheimes.de>
parents:
84838
diff
changeset
|
901 } |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
902 (void) BIO_reset(biobuf); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
903 GENERAL_NAME_print(biobuf, name); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
904 len = BIO_gets(biobuf, buf, sizeof(buf)-1); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
905 if (len < 0) { |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
906 _setSSLError(NULL, 0, __FILE__, __LINE__); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
907 goto fail; |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
908 } |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
909 vptr = strchr(buf, ':'); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
910 if (vptr == NULL) |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
911 goto fail; |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
912 t = PyTuple_New(2); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
913 if (t == NULL) |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
914 goto fail; |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
915 v = PyUnicode_FromStringAndSize(buf, (vptr - buf)); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
916 if (v == NULL) { |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
917 Py_DECREF(t); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
918 goto fail; |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
919 } |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
920 PyTuple_SET_ITEM(t, 0, v); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
921 v = PyUnicode_FromStringAndSize((vptr + 1), |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
922 (len - (vptr - buf + 1))); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
923 if (v == NULL) { |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
924 Py_DECREF(t); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
925 goto fail; |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
926 } |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
927 PyTuple_SET_ITEM(t, 1, v); |
|
85211
c9f073e593b0
Issue #18709: Fix CVE-2013-4238. The SSL module now handles NULL bytes
Christian Heimes <christian@cheimes.de>
parents:
84838
diff
changeset
|
928 break; |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
929 } |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
930 |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
931 /* and add that rendering to the list */ |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
932 |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
933 if (PyList_Append(peer_alt_names, t) < 0) { |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
934 Py_DECREF(t); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
935 goto fail; |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
936 } |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
937 Py_DECREF(t); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
938 } |
|
73711
80d491aaeed2
Issue #13458: Fix a memory leak in the ssl module when decoding a certificate with a subjectAltName.
Antoine Pitrou <solipsis@pitrou.net>
parents:
72567
diff
changeset
|
939 sk_GENERAL_NAME_pop_free(names, GENERAL_NAME_free); |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
940 } |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
941 BIO_free(biobuf); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
942 if (peer_alt_names != Py_None) { |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
943 v = PyList_AsTuple(peer_alt_names); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
944 Py_DECREF(peer_alt_names); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
945 return v; |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
946 } else { |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
947 return peer_alt_names; |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
948 } |
|
43948
8e0c4c710375
Make read() and certificate() return bytes instead of bytearray instances.
Guido van Rossum <guido@python.org>
parents:
43869
diff
changeset
|
949 |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
950 |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
951 fail: |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
952 if (biobuf != NULL) |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
953 BIO_free(biobuf); |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
954 |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
955 if (peer_alt_names != Py_None) { |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
956 Py_XDECREF(peer_alt_names); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
957 } |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
958 |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
959 return NULL; |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
960 } |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
961 |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
962 static PyObject * |
|
66114
eeebb622fd08
Issue #10022: The dictionary returned by the `getpeercert()` method
Antoine Pitrou <solipsis@pitrou.net>
parents:
65593
diff
changeset
|
963 _decode_certificate(X509 *certificate) { |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
964 |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
965 PyObject *retval = NULL; |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
966 BIO *biobuf = NULL; |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
967 PyObject *peer; |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
968 PyObject *peer_alt_names = NULL; |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
969 PyObject *issuer; |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
970 PyObject *version; |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
971 PyObject *sn_obj; |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
972 ASN1_INTEGER *serialNumber; |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
973 char buf[2048]; |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
974 int len; |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
975 ASN1_TIME *notBefore, *notAfter; |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
976 PyObject *pnotBefore, *pnotAfter; |
|
42954
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
977 |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
978 retval = PyDict_New(); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
979 if (retval == NULL) |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
980 return NULL; |
|
42954
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
981 |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
982 peer = _create_tuple_for_X509_NAME( |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
983 X509_get_subject_name(certificate)); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
984 if (peer == NULL) |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
985 goto fail0; |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
986 if (PyDict_SetItemString(retval, (const char *) "subject", peer) < 0) { |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
987 Py_DECREF(peer); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
988 goto fail0; |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
989 } |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
990 Py_DECREF(peer); |
|
42954
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
991 |
|
66114
eeebb622fd08
Issue #10022: The dictionary returned by the `getpeercert()` method
Antoine Pitrou <solipsis@pitrou.net>
parents:
65593
diff
changeset
|
992 issuer = _create_tuple_for_X509_NAME( |
|
eeebb622fd08
Issue #10022: The dictionary returned by the `getpeercert()` method
Antoine Pitrou <solipsis@pitrou.net>
parents:
65593
diff
changeset
|
993 X509_get_issuer_name(certificate)); |
|
eeebb622fd08
Issue #10022: The dictionary returned by the `getpeercert()` method
Antoine Pitrou <solipsis@pitrou.net>
parents:
65593
diff
changeset
|
994 if (issuer == NULL) |
|
eeebb622fd08
Issue #10022: The dictionary returned by the `getpeercert()` method
Antoine Pitrou <solipsis@pitrou.net>
parents:
65593
diff
changeset
|
995 goto fail0; |
|
eeebb622fd08
Issue #10022: The dictionary returned by the `getpeercert()` method
Antoine Pitrou <solipsis@pitrou.net>
parents:
65593
diff
changeset
|
996 if (PyDict_SetItemString(retval, (const char *)"issuer", issuer) < 0) { |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
997 Py_DECREF(issuer); |
|
66114
eeebb622fd08
Issue #10022: The dictionary returned by the `getpeercert()` method
Antoine Pitrou <solipsis@pitrou.net>
parents:
65593
diff
changeset
|
998 goto fail0; |
|
eeebb622fd08
Issue #10022: The dictionary returned by the `getpeercert()` method
Antoine Pitrou <solipsis@pitrou.net>
parents:
65593
diff
changeset
|
999 } |
|
eeebb622fd08
Issue #10022: The dictionary returned by the `getpeercert()` method
Antoine Pitrou <solipsis@pitrou.net>
parents:
65593
diff
changeset
|
1000 Py_DECREF(issuer); |
|
43948
8e0c4c710375
Make read() and certificate() return bytes instead of bytearray instances.
Guido van Rossum <guido@python.org>
parents:
43869
diff
changeset
|
1001 |
|
66114
eeebb622fd08
Issue #10022: The dictionary returned by the `getpeercert()` method
Antoine Pitrou <solipsis@pitrou.net>
parents:
65593
diff
changeset
|
1002 version = PyLong_FromLong(X509_get_version(certificate) + 1); |
|
84838
7d6781ec35ea
Check return value of PyLong_FromLong(X509_get_version()). It might be NULL if
Christian Heimes <christian@cheimes.de>
parents:
84332
diff
changeset
|
1003 if (version == NULL) |
|
7d6781ec35ea
Check return value of PyLong_FromLong(X509_get_version()). It might be NULL if
Christian Heimes <christian@cheimes.de>
parents:
84332
diff
changeset
|
1004 goto fail0; |
|
66114
eeebb622fd08
Issue #10022: The dictionary returned by the `getpeercert()` method
Antoine Pitrou <solipsis@pitrou.net>
parents:
65593
diff
changeset
|
1005 if (PyDict_SetItemString(retval, "version", version) < 0) { |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1006 Py_DECREF(version); |
|
66114
eeebb622fd08
Issue #10022: The dictionary returned by the `getpeercert()` method
Antoine Pitrou <solipsis@pitrou.net>
parents:
65593
diff
changeset
|
1007 goto fail0; |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1008 } |
|
66114
eeebb622fd08
Issue #10022: The dictionary returned by the `getpeercert()` method
Antoine Pitrou <solipsis@pitrou.net>
parents:
65593
diff
changeset
|
1009 Py_DECREF(version); |
|
43948
8e0c4c710375
Make read() and certificate() return bytes instead of bytearray instances.
Guido van Rossum <guido@python.org>
parents:
43869
diff
changeset
|
1010 |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1011 /* get a memory buffer */ |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1012 biobuf = BIO_new(BIO_s_mem()); |
|
43948
8e0c4c710375
Make read() and certificate() return bytes instead of bytearray instances.
Guido van Rossum <guido@python.org>
parents:
43869
diff
changeset
|
1013 |
|
66114
eeebb622fd08
Issue #10022: The dictionary returned by the `getpeercert()` method
Antoine Pitrou <solipsis@pitrou.net>
parents:
65593
diff
changeset
|
1014 (void) BIO_reset(biobuf); |
|
eeebb622fd08
Issue #10022: The dictionary returned by the `getpeercert()` method
Antoine Pitrou <solipsis@pitrou.net>
parents:
65593
diff
changeset
|
1015 serialNumber = X509_get_serialNumber(certificate); |
|
eeebb622fd08
Issue #10022: The dictionary returned by the `getpeercert()` method
Antoine Pitrou <solipsis@pitrou.net>
parents:
65593
diff
changeset
|
1016 /* should not exceed 20 octets, 160 bits, so buf is big enough */ |
|
eeebb622fd08
Issue #10022: The dictionary returned by the `getpeercert()` method
Antoine Pitrou <solipsis@pitrou.net>
parents:
65593
diff
changeset
|
1017 i2a_ASN1_INTEGER(biobuf, serialNumber); |
|
eeebb622fd08
Issue #10022: The dictionary returned by the `getpeercert()` method
Antoine Pitrou <solipsis@pitrou.net>
parents:
65593
diff
changeset
|
1018 len = BIO_gets(biobuf, buf, sizeof(buf)-1); |
|
eeebb622fd08
Issue #10022: The dictionary returned by the `getpeercert()` method
Antoine Pitrou <solipsis@pitrou.net>
parents:
65593
diff
changeset
|
1019 if (len < 0) { |
|
eeebb622fd08
Issue #10022: The dictionary returned by the `getpeercert()` method
Antoine Pitrou <solipsis@pitrou.net>
parents:
65593
diff
changeset
|
1020 _setSSLError(NULL, 0, __FILE__, __LINE__); |
|
eeebb622fd08
Issue #10022: The dictionary returned by the `getpeercert()` method
Antoine Pitrou <solipsis@pitrou.net>
parents:
65593
diff
changeset
|
1021 goto fail1; |
|
eeebb622fd08
Issue #10022: The dictionary returned by the `getpeercert()` method
Antoine Pitrou <solipsis@pitrou.net>
parents:
65593
diff
changeset
|
1022 } |
|
eeebb622fd08
Issue #10022: The dictionary returned by the `getpeercert()` method
Antoine Pitrou <solipsis@pitrou.net>
parents:
65593
diff
changeset
|
1023 sn_obj = PyUnicode_FromStringAndSize(buf, len); |
|
eeebb622fd08
Issue #10022: The dictionary returned by the `getpeercert()` method
Antoine Pitrou <solipsis@pitrou.net>
parents:
65593
diff
changeset
|
1024 if (sn_obj == NULL) |
|
eeebb622fd08
Issue #10022: The dictionary returned by the `getpeercert()` method
Antoine Pitrou <solipsis@pitrou.net>
parents:
65593
diff
changeset
|
1025 goto fail1; |
|
eeebb622fd08
Issue #10022: The dictionary returned by the `getpeercert()` method
Antoine Pitrou <solipsis@pitrou.net>
parents:
65593
diff
changeset
|
1026 if (PyDict_SetItemString(retval, "serialNumber", sn_obj) < 0) { |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1027 Py_DECREF(sn_obj); |
|
66114
eeebb622fd08
Issue #10022: The dictionary returned by the `getpeercert()` method
Antoine Pitrou <solipsis@pitrou.net>
parents:
65593
diff
changeset
|
1028 goto fail1; |
|
eeebb622fd08
Issue #10022: The dictionary returned by the `getpeercert()` method
Antoine Pitrou <solipsis@pitrou.net>
parents:
65593
diff
changeset
|
1029 } |
|
eeebb622fd08
Issue #10022: The dictionary returned by the `getpeercert()` method
Antoine Pitrou <solipsis@pitrou.net>
parents:
65593
diff
changeset
|
1030 Py_DECREF(sn_obj); |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1031 |
|
66114
eeebb622fd08
Issue #10022: The dictionary returned by the `getpeercert()` method
Antoine Pitrou <solipsis@pitrou.net>
parents:
65593
diff
changeset
|
1032 (void) BIO_reset(biobuf); |
|
eeebb622fd08
Issue #10022: The dictionary returned by the `getpeercert()` method
Antoine Pitrou <solipsis@pitrou.net>
parents:
65593
diff
changeset
|
1033 notBefore = X509_get_notBefore(certificate); |
|
eeebb622fd08
Issue #10022: The dictionary returned by the `getpeercert()` method
Antoine Pitrou <solipsis@pitrou.net>
parents:
65593
diff
changeset
|
1034 ASN1_TIME_print(biobuf, notBefore); |
|
eeebb622fd08
Issue #10022: The dictionary returned by the `getpeercert()` method
Antoine Pitrou <solipsis@pitrou.net>
parents:
65593
diff
changeset
|
1035 len = BIO_gets(biobuf, buf, sizeof(buf)-1); |
|
eeebb622fd08
Issue #10022: The dictionary returned by the `getpeercert()` method
Antoine Pitrou <solipsis@pitrou.net>
parents:
65593
diff
changeset
|
1036 if (len < 0) { |
|
eeebb622fd08
Issue #10022: The dictionary returned by the `getpeercert()` method
Antoine Pitrou <solipsis@pitrou.net>
parents:
65593
diff
changeset
|
1037 _setSSLError(NULL, 0, __FILE__, __LINE__); |
|
eeebb622fd08
Issue #10022: The dictionary returned by the `getpeercert()` method
Antoine Pitrou <solipsis@pitrou.net>
parents:
65593
diff
changeset
|
1038 goto fail1; |
|
eeebb622fd08
Issue #10022: The dictionary returned by the `getpeercert()` method
Antoine Pitrou <solipsis@pitrou.net>
parents:
65593
diff
changeset
|
1039 } |
|
eeebb622fd08
Issue #10022: The dictionary returned by the `getpeercert()` method
Antoine Pitrou <solipsis@pitrou.net>
parents:
65593
diff
changeset
|
1040 pnotBefore = PyUnicode_FromStringAndSize(buf, len); |
|
eeebb622fd08
Issue #10022: The dictionary returned by the `getpeercert()` method
Antoine Pitrou <solipsis@pitrou.net>
parents:
65593
diff
changeset
|
1041 if (pnotBefore == NULL) |
|
eeebb622fd08
Issue #10022: The dictionary returned by the `getpeercert()` method
Antoine Pitrou <solipsis@pitrou.net>
parents:
65593
diff
changeset
|
1042 goto fail1; |
|
eeebb622fd08
Issue #10022: The dictionary returned by the `getpeercert()` method
Antoine Pitrou <solipsis@pitrou.net>
parents:
65593
diff
changeset
|
1043 if (PyDict_SetItemString(retval, "notBefore", pnotBefore) < 0) { |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1044 Py_DECREF(pnotBefore); |
|
66114
eeebb622fd08
Issue #10022: The dictionary returned by the `getpeercert()` method
Antoine Pitrou <solipsis@pitrou.net>
parents:
65593
diff
changeset
|
1045 goto fail1; |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1046 } |
|
66114
eeebb622fd08
Issue #10022: The dictionary returned by the `getpeercert()` method
Antoine Pitrou <solipsis@pitrou.net>
parents:
65593
diff
changeset
|
1047 Py_DECREF(pnotBefore); |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1048 |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1049 (void) BIO_reset(biobuf); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1050 notAfter = X509_get_notAfter(certificate); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1051 ASN1_TIME_print(biobuf, notAfter); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1052 len = BIO_gets(biobuf, buf, sizeof(buf)-1); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1053 if (len < 0) { |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1054 _setSSLError(NULL, 0, __FILE__, __LINE__); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1055 goto fail1; |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1056 } |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1057 pnotAfter = PyUnicode_FromStringAndSize(buf, len); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1058 if (pnotAfter == NULL) |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1059 goto fail1; |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1060 if (PyDict_SetItemString(retval, "notAfter", pnotAfter) < 0) { |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1061 Py_DECREF(pnotAfter); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1062 goto fail1; |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1063 } |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1064 Py_DECREF(pnotAfter); |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1065 |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1066 /* Now look for subjectAltName */ |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1067 |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1068 peer_alt_names = _get_peer_alt_names(certificate); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1069 if (peer_alt_names == NULL) |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1070 goto fail1; |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1071 else if (peer_alt_names != Py_None) { |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1072 if (PyDict_SetItemString(retval, "subjectAltName", |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1073 peer_alt_names) < 0) { |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1074 Py_DECREF(peer_alt_names); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1075 goto fail1; |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1076 } |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1077 Py_DECREF(peer_alt_names); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1078 } |
|
43948
8e0c4c710375
Make read() and certificate() return bytes instead of bytearray instances.
Guido van Rossum <guido@python.org>
parents:
43869
diff
changeset
|
1079 |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1080 BIO_free(biobuf); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1081 return retval; |
|
42954
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
1082 |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
1083 fail1: |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1084 if (biobuf != NULL) |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1085 BIO_free(biobuf); |
|
42954
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
1086 fail0: |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1087 Py_XDECREF(retval); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1088 return NULL; |
|
42954
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
1089 } |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
1090 |
|
84185
38e759e4c9e6
Issue #18147: Add diagnostic functions to ssl.SSLContext().
Christian Heimes <christian@cheimes.de>
parents:
84119
diff
changeset
|
1091 static PyObject * |
|
38e759e4c9e6
Issue #18147: Add diagnostic functions to ssl.SSLContext().
Christian Heimes <christian@cheimes.de>
parents:
84119
diff
changeset
|
1092 _certificate_to_der(X509 *certificate) |
|
38e759e4c9e6
Issue #18147: Add diagnostic functions to ssl.SSLContext().
Christian Heimes <christian@cheimes.de>
parents:
84119
diff
changeset
|
1093 { |
|
38e759e4c9e6
Issue #18147: Add diagnostic functions to ssl.SSLContext().
Christian Heimes <christian@cheimes.de>
parents:
84119
diff
changeset
|
1094 unsigned char *bytes_buf = NULL; |
|
38e759e4c9e6
Issue #18147: Add diagnostic functions to ssl.SSLContext().
Christian Heimes <christian@cheimes.de>
parents:
84119
diff
changeset
|
1095 int len; |
|
38e759e4c9e6
Issue #18147: Add diagnostic functions to ssl.SSLContext().
Christian Heimes <christian@cheimes.de>
parents:
84119
diff
changeset
|
1096 PyObject *retval; |
|
38e759e4c9e6
Issue #18147: Add diagnostic functions to ssl.SSLContext().
Christian Heimes <christian@cheimes.de>
parents:
84119
diff
changeset
|
1097 |
|
38e759e4c9e6
Issue #18147: Add diagnostic functions to ssl.SSLContext().
Christian Heimes <christian@cheimes.de>
parents:
84119
diff
changeset
|
1098 bytes_buf = NULL; |
|
38e759e4c9e6
Issue #18147: Add diagnostic functions to ssl.SSLContext().
Christian Heimes <christian@cheimes.de>
parents:
84119
diff
changeset
|
1099 len = i2d_X509(certificate, &bytes_buf); |
|
38e759e4c9e6
Issue #18147: Add diagnostic functions to ssl.SSLContext().
Christian Heimes <christian@cheimes.de>
parents:
84119
diff
changeset
|
1100 if (len < 0) { |
|
38e759e4c9e6
Issue #18147: Add diagnostic functions to ssl.SSLContext().
Christian Heimes <christian@cheimes.de>
parents:
84119
diff
changeset
|
1101 _setSSLError(NULL, 0, __FILE__, __LINE__); |
|
38e759e4c9e6
Issue #18147: Add diagnostic functions to ssl.SSLContext().
Christian Heimes <christian@cheimes.de>
parents:
84119
diff
changeset
|
1102 return NULL; |
|
38e759e4c9e6
Issue #18147: Add diagnostic functions to ssl.SSLContext().
Christian Heimes <christian@cheimes.de>
parents:
84119
diff
changeset
|
1103 } |
|
38e759e4c9e6
Issue #18147: Add diagnostic functions to ssl.SSLContext().
Christian Heimes <christian@cheimes.de>
parents:
84119
diff
changeset
|
1104 /* this is actually an immutable bytes sequence */ |
|
38e759e4c9e6
Issue #18147: Add diagnostic functions to ssl.SSLContext().
Christian Heimes <christian@cheimes.de>
parents:
84119
diff
changeset
|
1105 retval = PyBytes_FromStringAndSize((const char *) bytes_buf, len); |
|
38e759e4c9e6
Issue #18147: Add diagnostic functions to ssl.SSLContext().
Christian Heimes <christian@cheimes.de>
parents:
84119
diff
changeset
|
1106 OPENSSL_free(bytes_buf); |
|
38e759e4c9e6
Issue #18147: Add diagnostic functions to ssl.SSLContext().
Christian Heimes <christian@cheimes.de>
parents:
84119
diff
changeset
|
1107 return retval; |
|
38e759e4c9e6
Issue #18147: Add diagnostic functions to ssl.SSLContext().
Christian Heimes <christian@cheimes.de>
parents:
84119
diff
changeset
|
1108 } |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1109 |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1110 static PyObject * |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1111 PySSL_test_decode_certificate (PyObject *mod, PyObject *args) { |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1112 |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1113 PyObject *retval = NULL; |
|
61639
08abbdc99be6
Issue #8477: _ssl._test_decode_cert() supports str with surrogates and bytes
Victor Stinner <victor.stinner@haypocalc.com>
parents:
61637
diff
changeset
|
1114 PyObject *filename; |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1115 X509 *x=NULL; |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1116 BIO *cert; |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1117 |
|
66114
eeebb622fd08
Issue #10022: The dictionary returned by the `getpeercert()` method
Antoine Pitrou <solipsis@pitrou.net>
parents:
65593
diff
changeset
|
1118 if (!PyArg_ParseTuple(args, "O&:test_decode_certificate", |
|
eeebb622fd08
Issue #10022: The dictionary returned by the `getpeercert()` method
Antoine Pitrou <solipsis@pitrou.net>
parents:
65593
diff
changeset
|
1119 PyUnicode_FSConverter, &filename)) |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1120 return NULL; |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1121 |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1122 if ((cert=BIO_new(BIO_s_file())) == NULL) { |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1123 PyErr_SetString(PySSLErrorObject, |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1124 "Can't malloc memory to read file"); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1125 goto fail0; |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1126 } |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1127 |
|
61639
08abbdc99be6
Issue #8477: _ssl._test_decode_cert() supports str with surrogates and bytes
Victor Stinner <victor.stinner@haypocalc.com>
parents:
61637
diff
changeset
|
1128 if (BIO_read_filename(cert, PyBytes_AsString(filename)) <= 0) { |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1129 PyErr_SetString(PySSLErrorObject, |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1130 "Can't open file"); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1131 goto fail0; |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1132 } |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1133 |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1134 x = PEM_read_bio_X509_AUX(cert,NULL, NULL, NULL); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1135 if (x == NULL) { |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1136 PyErr_SetString(PySSLErrorObject, |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1137 "Error decoding PEM-encoded file"); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1138 goto fail0; |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1139 } |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1140 |
|
66114
eeebb622fd08
Issue #10022: The dictionary returned by the `getpeercert()` method
Antoine Pitrou <solipsis@pitrou.net>
parents:
65593
diff
changeset
|
1141 retval = _decode_certificate(x); |
|
63694
c4bbda2d4c49
Merged revisions 83677 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
62489
diff
changeset
|
1142 X509_free(x); |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1143 |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1144 fail0: |
|
61639
08abbdc99be6
Issue #8477: _ssl._test_decode_cert() supports str with surrogates and bytes
Victor Stinner <victor.stinner@haypocalc.com>
parents:
61637
diff
changeset
|
1145 Py_DECREF(filename); |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1146 if (cert != NULL) BIO_free(cert); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1147 return retval; |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1148 } |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1149 |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1150 |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1151 static PyObject * |
|
61635
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
1152 PySSL_peercert(PySSLSocket *self, PyObject *args) |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1153 { |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1154 int verification; |
|
78605
b878df1d23b1
Issue #15604: Update uses of PyObject_IsTrue() to check for and handle errors correctly.
Antoine Pitrou <solipsis@pitrou.net>
diff
changeset
|
1155 int binary_mode = 0; |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1156 |
|
78605
b878df1d23b1
Issue #15604: Update uses of PyObject_IsTrue() to check for and handle errors correctly.
Antoine Pitrou <solipsis@pitrou.net>
diff
changeset
|
1157 if (!PyArg_ParseTuple(args, "|p:peer_certificate", &binary_mode)) |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1158 return NULL; |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1159 |
|
85857
ddcdf7f7eac8
Issue #19095: SSLSocket.getpeercert() now raises ValueError when the SSL handshake hasn't been done.
Antoine Pitrou <solipsis@pitrou.net>
parents:
85536
diff
changeset
|
1160 if (!self->handshake_done) { |
|
ddcdf7f7eac8
Issue #19095: SSLSocket.getpeercert() now raises ValueError when the SSL handshake hasn't been done.
Antoine Pitrou <solipsis@pitrou.net>
parents:
85536
diff
changeset
|
1161 PyErr_SetString(PyExc_ValueError, |
|
ddcdf7f7eac8
Issue #19095: SSLSocket.getpeercert() now raises ValueError when the SSL handshake hasn't been done.
Antoine Pitrou <solipsis@pitrou.net>
parents:
85536
diff
changeset
|
1162 "handshake not done yet"); |
|
ddcdf7f7eac8
Issue #19095: SSLSocket.getpeercert() now raises ValueError when the SSL handshake hasn't been done.
Antoine Pitrou <solipsis@pitrou.net>
parents:
85536
diff
changeset
|
1163 return NULL; |
|
ddcdf7f7eac8
Issue #19095: SSLSocket.getpeercert() now raises ValueError when the SSL handshake hasn't been done.
Antoine Pitrou <solipsis@pitrou.net>
parents:
85536
diff
changeset
|
1164 } |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1165 if (!self->peer_cert) |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1166 Py_RETURN_NONE; |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1167 |
|
78605
b878df1d23b1
Issue #15604: Update uses of PyObject_IsTrue() to check for and handle errors correctly.
Antoine Pitrou <solipsis@pitrou.net>
diff
changeset
|
1168 if (binary_mode) { |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1169 /* return cert in DER-encoded format */ |
|
84185
38e759e4c9e6
Issue #18147: Add diagnostic functions to ssl.SSLContext().
Christian Heimes <christian@cheimes.de>
parents:
84119
diff
changeset
|
1170 return _certificate_to_der(self->peer_cert); |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1171 } else { |
|
61635
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
1172 verification = SSL_CTX_get_verify_mode(SSL_get_SSL_CTX(self->ssl)); |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1173 if ((verification & SSL_VERIFY_PEER) == 0) |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1174 return PyDict_New(); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1175 else |
|
66114
eeebb622fd08
Issue #10022: The dictionary returned by the `getpeercert()` method
Antoine Pitrou <solipsis@pitrou.net>
parents:
65593
diff
changeset
|
1176 return _decode_certificate(self->peer_cert); |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1177 } |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1178 } |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1179 |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1180 PyDoc_STRVAR(PySSL_peercert_doc, |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1181 "peer_certificate([der=False]) -> certificate\n\ |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1182 \n\ |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1183 Returns the certificate for the peer. If no certificate was provided,\n\ |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1184 returns None. If a certificate was provided, but not validated, returns\n\ |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1185 an empty dictionary. Otherwise returns a dict containing information\n\ |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1186 about the peer certificate.\n\ |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1187 \n\ |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1188 If the optional argument is True, returns a DER-encoded copy of the\n\ |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1189 peer certificate, or None if no certificate was provided. This will\n\ |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1190 return the certificate even if it wasn't validated."); |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1191 |
|
61635
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
1192 static PyObject *PySSL_cipher (PySSLSocket *self) { |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1193 |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1194 PyObject *retval, *v; |
|
65272
4755744724f2
Merged revisions 85432 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
64404
diff
changeset
|
1195 const SSL_CIPHER *current; |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1196 char *cipher_name; |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1197 char *cipher_protocol; |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1198 |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1199 if (self->ssl == NULL) |
|
66806
800563ac057e
Merged revisions 87140 via svnmerge from
Hirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp>
parents:
65272
diff
changeset
|
1200 Py_RETURN_NONE; |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1201 current = SSL_get_current_cipher(self->ssl); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1202 if (current == NULL) |
|
66806
800563ac057e
Merged revisions 87140 via svnmerge from
Hirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp>
parents:
65272
diff
changeset
|
1203 Py_RETURN_NONE; |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1204 |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1205 retval = PyTuple_New(3); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1206 if (retval == NULL) |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1207 return NULL; |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1208 |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1209 cipher_name = (char *) SSL_CIPHER_get_name(current); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1210 if (cipher_name == NULL) { |
|
66806
800563ac057e
Merged revisions 87140 via svnmerge from
Hirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp>
parents:
65272
diff
changeset
|
1211 Py_INCREF(Py_None); |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1212 PyTuple_SET_ITEM(retval, 0, Py_None); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1213 } else { |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1214 v = PyUnicode_FromString(cipher_name); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1215 if (v == NULL) |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1216 goto fail0; |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1217 PyTuple_SET_ITEM(retval, 0, v); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1218 } |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1219 cipher_protocol = SSL_CIPHER_get_version(current); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1220 if (cipher_protocol == NULL) { |
|
66806
800563ac057e
Merged revisions 87140 via svnmerge from
Hirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp>
parents:
65272
diff
changeset
|
1221 Py_INCREF(Py_None); |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1222 PyTuple_SET_ITEM(retval, 1, Py_None); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1223 } else { |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1224 v = PyUnicode_FromString(cipher_protocol); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1225 if (v == NULL) |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1226 goto fail0; |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1227 PyTuple_SET_ITEM(retval, 1, v); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1228 } |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1229 v = PyLong_FromLong(SSL_CIPHER_get_bits(current, NULL)); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1230 if (v == NULL) |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1231 goto fail0; |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1232 PyTuple_SET_ITEM(retval, 2, v); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1233 return retval; |
|
43948
8e0c4c710375
Make read() and certificate() return bytes instead of bytearray instances.
Guido van Rossum <guido@python.org>
parents:
43869
diff
changeset
|
1234 |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1235 fail0: |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1236 Py_DECREF(retval); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1237 return NULL; |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1238 } |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1239 |
|
75865
2514a4e2b3ce
Issue #14204: The ssl module now has support for the Next Protocol Negotiation extension, if available in the underlying OpenSSL library.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75043
diff
changeset
|
1240 #ifdef OPENSSL_NPN_NEGOTIATED |
|
2514a4e2b3ce
Issue #14204: The ssl module now has support for the Next Protocol Negotiation extension, if available in the underlying OpenSSL library.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75043
diff
changeset
|
1241 static PyObject *PySSL_selected_npn_protocol(PySSLSocket *self) { |
|
2514a4e2b3ce
Issue #14204: The ssl module now has support for the Next Protocol Negotiation extension, if available in the underlying OpenSSL library.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75043
diff
changeset
|
1242 const unsigned char *out; |
|
2514a4e2b3ce
Issue #14204: The ssl module now has support for the Next Protocol Negotiation extension, if available in the underlying OpenSSL library.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75043
diff
changeset
|
1243 unsigned int outlen; |
|
2514a4e2b3ce
Issue #14204: The ssl module now has support for the Next Protocol Negotiation extension, if available in the underlying OpenSSL library.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75043
diff
changeset
|
1244 |
|
84269
1bd49f8a30da
_ssl.c: strip trailing spaces
Victor Stinner <victor.stinner@gmail.com>
parents:
81463
diff
changeset
|
1245 SSL_get0_next_proto_negotiated(self->ssl, |
|
75865
2514a4e2b3ce
Issue #14204: The ssl module now has support for the Next Protocol Negotiation extension, if available in the underlying OpenSSL library.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75043
diff
changeset
|
1246 &out, &outlen); |
|
2514a4e2b3ce
Issue #14204: The ssl module now has support for the Next Protocol Negotiation extension, if available in the underlying OpenSSL library.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75043
diff
changeset
|
1247 |
|
2514a4e2b3ce
Issue #14204: The ssl module now has support for the Next Protocol Negotiation extension, if available in the underlying OpenSSL library.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75043
diff
changeset
|
1248 if (out == NULL) |
|
2514a4e2b3ce
Issue #14204: The ssl module now has support for the Next Protocol Negotiation extension, if available in the underlying OpenSSL library.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75043
diff
changeset
|
1249 Py_RETURN_NONE; |
|
2514a4e2b3ce
Issue #14204: The ssl module now has support for the Next Protocol Negotiation extension, if available in the underlying OpenSSL library.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75043
diff
changeset
|
1250 return PyUnicode_FromStringAndSize((char *) out, outlen); |
|
2514a4e2b3ce
Issue #14204: The ssl module now has support for the Next Protocol Negotiation extension, if available in the underlying OpenSSL library.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75043
diff
changeset
|
1251 } |
|
2514a4e2b3ce
Issue #14204: The ssl module now has support for the Next Protocol Negotiation extension, if available in the underlying OpenSSL library.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75043
diff
changeset
|
1252 #endif |
|
2514a4e2b3ce
Issue #14204: The ssl module now has support for the Next Protocol Negotiation extension, if available in the underlying OpenSSL library.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75043
diff
changeset
|
1253 |
|
74091
20b52be99b5d
Issue #13634: Add support for querying and disabling SSL compression.
Antoine Pitrou <solipsis@pitrou.net>
parents:
74084
diff
changeset
|
1254 static PyObject *PySSL_compression(PySSLSocket *self) { |
|
20b52be99b5d
Issue #13634: Add support for querying and disabling SSL compression.
Antoine Pitrou <solipsis@pitrou.net>
parents:
74084
diff
changeset
|
1255 #ifdef OPENSSL_NO_COMP |
|
20b52be99b5d
Issue #13634: Add support for querying and disabling SSL compression.
Antoine Pitrou <solipsis@pitrou.net>
parents:
74084
diff
changeset
|
1256 Py_RETURN_NONE; |
|
20b52be99b5d
Issue #13634: Add support for querying and disabling SSL compression.
Antoine Pitrou <solipsis@pitrou.net>
parents:
74084
diff
changeset
|
1257 #else |
|
20b52be99b5d
Issue #13634: Add support for querying and disabling SSL compression.
Antoine Pitrou <solipsis@pitrou.net>
parents:
74084
diff
changeset
|
1258 const COMP_METHOD *comp_method; |
|
20b52be99b5d
Issue #13634: Add support for querying and disabling SSL compression.
Antoine Pitrou <solipsis@pitrou.net>
parents:
74084
diff
changeset
|
1259 const char *short_name; |
|
20b52be99b5d
Issue #13634: Add support for querying and disabling SSL compression.
Antoine Pitrou <solipsis@pitrou.net>
parents:
74084
diff
changeset
|
1260 |
|
20b52be99b5d
Issue #13634: Add support for querying and disabling SSL compression.
Antoine Pitrou <solipsis@pitrou.net>
parents:
74084
diff
changeset
|
1261 if (self->ssl == NULL) |
|
20b52be99b5d
Issue #13634: Add support for querying and disabling SSL compression.
Antoine Pitrou <solipsis@pitrou.net>
parents:
74084
diff
changeset
|
1262 Py_RETURN_NONE; |
|
20b52be99b5d
Issue #13634: Add support for querying and disabling SSL compression.
Antoine Pitrou <solipsis@pitrou.net>
parents:
74084
diff
changeset
|
1263 comp_method = SSL_get_current_compression(self->ssl); |
|
20b52be99b5d
Issue #13634: Add support for querying and disabling SSL compression.
Antoine Pitrou <solipsis@pitrou.net>
parents:
74084
diff
changeset
|
1264 if (comp_method == NULL || comp_method->type == NID_undef) |
|
20b52be99b5d
Issue #13634: Add support for querying and disabling SSL compression.
Antoine Pitrou <solipsis@pitrou.net>
parents:
74084
diff
changeset
|
1265 Py_RETURN_NONE; |
|
20b52be99b5d
Issue #13634: Add support for querying and disabling SSL compression.
Antoine Pitrou <solipsis@pitrou.net>
parents:
74084
diff
changeset
|
1266 short_name = OBJ_nid2sn(comp_method->type); |
|
20b52be99b5d
Issue #13634: Add support for querying and disabling SSL compression.
Antoine Pitrou <solipsis@pitrou.net>
parents:
74084
diff
changeset
|
1267 if (short_name == NULL) |
|
20b52be99b5d
Issue #13634: Add support for querying and disabling SSL compression.
Antoine Pitrou <solipsis@pitrou.net>
parents:
74084
diff
changeset
|
1268 Py_RETURN_NONE; |
|
20b52be99b5d
Issue #13634: Add support for querying and disabling SSL compression.
Antoine Pitrou <solipsis@pitrou.net>
parents:
74084
diff
changeset
|
1269 return PyUnicode_DecodeFSDefault(short_name); |
|
20b52be99b5d
Issue #13634: Add support for querying and disabling SSL compression.
Antoine Pitrou <solipsis@pitrou.net>
parents:
74084
diff
changeset
|
1270 #endif |
|
20b52be99b5d
Issue #13634: Add support for querying and disabling SSL compression.
Antoine Pitrou <solipsis@pitrou.net>
parents:
74084
diff
changeset
|
1271 } |
|
20b52be99b5d
Issue #13634: Add support for querying and disabling SSL compression.
Antoine Pitrou <solipsis@pitrou.net>
parents:
74084
diff
changeset
|
1272 |
|
81298
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
1273 static PySSLContext *PySSL_get_context(PySSLSocket *self, void *closure) { |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
1274 Py_INCREF(self->ctx); |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
1275 return self->ctx; |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
1276 } |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
1277 |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
1278 static int PySSL_set_context(PySSLSocket *self, PyObject *value, |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
1279 void *closure) { |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
1280 |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
1281 if (PyObject_TypeCheck(value, &PySSLContext_Type)) { |
|
83021
02f9335b7efb
Issue #17581: try to fix building on old OpenSSL versions
Antoine Pitrou <solipsis@pitrou.net>
parents:
82992
diff
changeset
|
1282 #if !HAVE_SNI |
|
02f9335b7efb
Issue #17581: try to fix building on old OpenSSL versions
Antoine Pitrou <solipsis@pitrou.net>
parents:
82992
diff
changeset
|
1283 PyErr_SetString(PyExc_NotImplementedError, "setting a socket's " |
|
02f9335b7efb
Issue #17581: try to fix building on old OpenSSL versions
Antoine Pitrou <solipsis@pitrou.net>
parents:
82992
diff
changeset
|
1284 "context is not supported by your OpenSSL library"); |
|
83023
ad9effdc0ac3
Further compiling fixes (issue #17581)
Antoine Pitrou <solipsis@pitrou.net>
parents:
83021
diff
changeset
|
1285 return -1; |
|
83021
02f9335b7efb
Issue #17581: try to fix building on old OpenSSL versions
Antoine Pitrou <solipsis@pitrou.net>
parents:
82992
diff
changeset
|
1286 #else |
|
81298
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
1287 Py_INCREF(value); |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
1288 Py_DECREF(self->ctx); |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
1289 self->ctx = (PySSLContext *) value; |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
1290 SSL_set_SSL_CTX(self->ssl, self->ctx->ctx); |
|
83021
02f9335b7efb
Issue #17581: try to fix building on old OpenSSL versions
Antoine Pitrou <solipsis@pitrou.net>
parents:
82992
diff
changeset
|
1291 #endif |
|
81298
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
1292 } else { |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
1293 PyErr_SetString(PyExc_TypeError, "The value must be a SSLContext"); |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
1294 return -1; |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
1295 } |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
1296 |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
1297 return 0; |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
1298 } |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
1299 |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
1300 PyDoc_STRVAR(PySSL_set_context_doc, |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
1301 "_setter_context(ctx)\n\ |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
1302 \ |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
1303 This changes the context associated with the SSLSocket. This is typically\n\ |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
1304 used from within a callback function set by the set_servername_callback\n\ |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
1305 on the SSLContext to change the certificate information associated with the\n\ |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
1306 SSLSocket before the cryptographic exchange handshake messages\n"); |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
1307 |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
1308 |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
1309 |
|
61635
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
1310 static void PySSL_dealloc(PySSLSocket *self) |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
1311 { |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1312 if (self->peer_cert) /* Possible not to have one? */ |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1313 X509_free (self->peer_cert); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1314 if (self->ssl) |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1315 SSL_free(self->ssl); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1316 Py_XDECREF(self->Socket); |
|
81298
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
1317 Py_XDECREF(self->ctx); |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1318 PyObject_Del(self); |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
1319 } |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
1320 |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38453
diff
changeset
|
1321 /* If the socket has a timeout, do a select()/poll() on the socket. |
|
27430
1ae0b142370e
Support socket timeout in SSL, by Geoff Talvola.
Guido van Rossum <guido@python.org>
parents:
24471
diff
changeset
|
1322 The argument writing indicates the direction. |
|
32599
598a5ce63322
[Patch #945642] Fix non-blocking SSL sockets, which blocked on reads/writes in Python 2.3.
Andrew M. Kuchling <amk@amk.ca>
parents:
31790
diff
changeset
|
1323 Returns one of the possibilities in the timeout_state enum (above). |
|
27430
1ae0b142370e
Support socket timeout in SSL, by Geoff Talvola.
Guido van Rossum <guido@python.org>
parents:
24471
diff
changeset
|
1324 */ |
|
32599
598a5ce63322
[Patch #945642] Fix non-blocking SSL sockets, which blocked on reads/writes in Python 2.3.
Andrew M. Kuchling <amk@amk.ca>
parents:
31790
diff
changeset
|
1325 |
|
27430
1ae0b142370e
Support socket timeout in SSL, by Geoff Talvola.
Guido van Rossum <guido@python.org>
parents:
24471
diff
changeset
|
1326 static int |
|
32599
598a5ce63322
[Patch #945642] Fix non-blocking SSL sockets, which blocked on reads/writes in Python 2.3.
Andrew M. Kuchling <amk@amk.ca>
parents:
31790
diff
changeset
|
1327 check_socket_and_wait_for_timeout(PySocketSockObject *s, int writing) |
|
27430
1ae0b142370e
Support socket timeout in SSL, by Geoff Talvola.
Guido van Rossum <guido@python.org>
parents:
24471
diff
changeset
|
1328 { |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1329 fd_set fds; |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1330 struct timeval tv; |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1331 int rc; |
|
27430
1ae0b142370e
Support socket timeout in SSL, by Geoff Talvola.
Guido van Rossum <guido@python.org>
parents:
24471
diff
changeset
|
1332 |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1333 /* Nothing to do unless we're in timeout mode (not non-blocking) */ |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1334 if (s->sock_timeout < 0.0) |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1335 return SOCKET_IS_BLOCKING; |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1336 else if (s->sock_timeout == 0.0) |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1337 return SOCKET_IS_NONBLOCKING; |
|
27430
1ae0b142370e
Support socket timeout in SSL, by Geoff Talvola.
Guido van Rossum <guido@python.org>
parents:
24471
diff
changeset
|
1338 |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1339 /* Guard against closed socket */ |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1340 if (s->sock_fd < 0) |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1341 return SOCKET_HAS_BEEN_CLOSED; |
|
27430
1ae0b142370e
Support socket timeout in SSL, by Geoff Talvola.
Guido van Rossum <guido@python.org>
parents:
24471
diff
changeset
|
1342 |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1343 /* Prefer poll, if available, since you can poll() any fd |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1344 * which can't be done with select(). */ |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38453
diff
changeset
|
1345 #ifdef HAVE_POLL |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1346 { |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1347 struct pollfd pollfd; |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1348 int timeout; |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38453
diff
changeset
|
1349 |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1350 pollfd.fd = s->sock_fd; |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1351 pollfd.events = writing ? POLLOUT : POLLIN; |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38453
diff
changeset
|
1352 |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1353 /* s->sock_timeout is in seconds, timeout in ms */ |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1354 timeout = (int)(s->sock_timeout * 1000 + 0.5); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1355 PySSL_BEGIN_ALLOW_THREADS |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1356 rc = poll(&pollfd, 1, timeout); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1357 PySSL_END_ALLOW_THREADS |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38453
diff
changeset
|
1358 |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1359 goto normal_return; |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1360 } |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38453
diff
changeset
|
1361 #endif |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38453
diff
changeset
|
1362 |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1363 /* Guard against socket too large for select*/ |
|
72115
852ca32eb18d
Issue #12287: Fix a stack corruption in ossaudiodev module when the FD is
Charles-François Natali <neologix@free.fr>
parents:
71255
diff
changeset
|
1364 if (!_PyIsSelectable_fd(s->sock_fd)) |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1365 return SOCKET_TOO_LARGE_FOR_SELECT; |
|
36452
7789cc557e1e
Bug #876637, prevent stack corruption when socket descriptor
Neal Norwitz <nnorwitz@gmail.com>
parents:
36451
diff
changeset
|
1366 |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1367 /* Construct the arguments to select */ |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1368 tv.tv_sec = (int)s->sock_timeout; |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1369 tv.tv_usec = (int)((s->sock_timeout - tv.tv_sec) * 1e6); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1370 FD_ZERO(&fds); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1371 FD_SET(s->sock_fd, &fds); |
|
27430
1ae0b142370e
Support socket timeout in SSL, by Geoff Talvola.
Guido van Rossum <guido@python.org>
parents:
24471
diff
changeset
|
1372 |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1373 /* See if the socket is ready */ |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1374 PySSL_BEGIN_ALLOW_THREADS |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1375 if (writing) |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1376 rc = select(s->sock_fd+1, NULL, &fds, NULL, &tv); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1377 else |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1378 rc = select(s->sock_fd+1, &fds, NULL, NULL, &tv); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1379 PySSL_END_ALLOW_THREADS |
|
27430
1ae0b142370e
Support socket timeout in SSL, by Geoff Talvola.
Guido van Rossum <guido@python.org>
parents:
24471
diff
changeset
|
1380 |
|
43869
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
1381 #ifdef HAVE_POLL |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38453
diff
changeset
|
1382 normal_return: |
|
43869
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
1383 #endif |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1384 /* Return SOCKET_TIMED_OUT on timeout, SOCKET_OPERATION_OK otherwise |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1385 (when we are able to write or when there's something to read) */ |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1386 return rc == 0 ? SOCKET_HAS_TIMED_OUT : SOCKET_OPERATION_OK; |
|
27430
1ae0b142370e
Support socket timeout in SSL, by Geoff Talvola.
Guido van Rossum <guido@python.org>
parents:
24471
diff
changeset
|
1387 } |
|
1ae0b142370e
Support socket timeout in SSL, by Geoff Talvola.
Guido van Rossum <guido@python.org>
parents:
24471
diff
changeset
|
1388 |
|
61635
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
1389 static PyObject *PySSL_SSLwrite(PySSLSocket *self, PyObject *args) |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
1390 { |
|
61244
35221c0158b5
Merged revisions 80789 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61017
diff
changeset
|
1391 Py_buffer buf; |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1392 int len; |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1393 int sockstate; |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1394 int err; |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1395 int nonblocking; |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1396 PySocketSockObject *sock |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1397 = (PySocketSockObject *) PyWeakref_GetObject(self->Socket); |
|
44305
19f894ae864a
update to fix leak in SSL code
Bill Janssen <janssen@parc.com>
parents:
44206
diff
changeset
|
1398 |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1399 if (((PyObject*)sock) == Py_None) { |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1400 _setSSLError("Underlying socket connection gone", |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1401 PY_SSL_ERROR_NO_SOCKET, __FILE__, __LINE__); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1402 return NULL; |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1403 } |
|
62481
b8b0a15f8a7c
Merged revisions 82204 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61646
diff
changeset
|
1404 Py_INCREF(sock); |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
1405 |
|
62480
21e86dd328f1
Issue #8682: The ssl module now temporary increments the reference count of
Antoine Pitrou <solipsis@pitrou.net>
parents:
61782
diff
changeset
|
1406 if (!PyArg_ParseTuple(args, "y*:write", &buf)) { |
|
62481
b8b0a15f8a7c
Merged revisions 82204 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61646
diff
changeset
|
1407 Py_DECREF(sock); |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1408 return NULL; |
|
62481
b8b0a15f8a7c
Merged revisions 82204 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61646
diff
changeset
|
1409 } |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
1410 |
|
84332
bfede07268a1
Issue #18135: ssl.SSLSocket.write() now raises an OverflowError if the input
Victor Stinner <victor.stinner@gmail.com>
parents:
84270
diff
changeset
|
1411 if (buf.len > INT_MAX) { |
|
bfede07268a1
Issue #18135: ssl.SSLSocket.write() now raises an OverflowError if the input
Victor Stinner <victor.stinner@gmail.com>
parents:
84270
diff
changeset
|
1412 PyErr_Format(PyExc_OverflowError, |
|
bfede07268a1
Issue #18135: ssl.SSLSocket.write() now raises an OverflowError if the input
Victor Stinner <victor.stinner@gmail.com>
parents:
84270
diff
changeset
|
1413 "string longer than %d bytes", INT_MAX); |
|
bfede07268a1
Issue #18135: ssl.SSLSocket.write() now raises an OverflowError if the input
Victor Stinner <victor.stinner@gmail.com>
parents:
84270
diff
changeset
|
1414 goto error; |
|
bfede07268a1
Issue #18135: ssl.SSLSocket.write() now raises an OverflowError if the input
Victor Stinner <victor.stinner@gmail.com>
parents:
84270
diff
changeset
|
1415 } |
|
bfede07268a1
Issue #18135: ssl.SSLSocket.write() now raises an OverflowError if the input
Victor Stinner <victor.stinner@gmail.com>
parents:
84270
diff
changeset
|
1416 |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1417 /* just in case the blocking state of the socket has been changed */ |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1418 nonblocking = (sock->sock_timeout >= 0.0); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1419 BIO_set_nbio(SSL_get_rbio(self->ssl), nonblocking); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1420 BIO_set_nbio(SSL_get_wbio(self->ssl), nonblocking); |
|
43869
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
1421 |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1422 sockstate = check_socket_and_wait_for_timeout(sock, 1); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1423 if (sockstate == SOCKET_HAS_TIMED_OUT) { |
|
66663
3d9a86b8cc98
Issue #10272: The ssl module now raises socket.timeout instead of a generic
Antoine Pitrou <solipsis@pitrou.net>
parents:
66217
diff
changeset
|
1424 PyErr_SetString(PySocketModule.timeout_error, |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1425 "The write operation timed out"); |
|
62481
b8b0a15f8a7c
Merged revisions 82204 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61646
diff
changeset
|
1426 goto error; |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1427 } else if (sockstate == SOCKET_HAS_BEEN_CLOSED) { |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1428 PyErr_SetString(PySSLErrorObject, |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1429 "Underlying socket has been closed."); |
|
62481
b8b0a15f8a7c
Merged revisions 82204 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61646
diff
changeset
|
1430 goto error; |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1431 } else if (sockstate == SOCKET_TOO_LARGE_FOR_SELECT) { |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1432 PyErr_SetString(PySSLErrorObject, |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1433 "Underlying socket too large for select()."); |
|
62481
b8b0a15f8a7c
Merged revisions 82204 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61646
diff
changeset
|
1434 goto error; |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1435 } |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1436 do { |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1437 PySSL_BEGIN_ALLOW_THREADS |
|
84332
bfede07268a1
Issue #18135: ssl.SSLSocket.write() now raises an OverflowError if the input
Victor Stinner <victor.stinner@gmail.com>
parents:
84270
diff
changeset
|
1438 len = SSL_write(self->ssl, buf.buf, (int)buf.len); |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1439 err = SSL_get_error(self->ssl, len); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1440 PySSL_END_ALLOW_THREADS |
|
61244
35221c0158b5
Merged revisions 80789 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61017
diff
changeset
|
1441 if (PyErr_CheckSignals()) { |
|
62481
b8b0a15f8a7c
Merged revisions 82204 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61646
diff
changeset
|
1442 goto error; |
|
61244
35221c0158b5
Merged revisions 80789 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61017
diff
changeset
|
1443 } |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1444 if (err == SSL_ERROR_WANT_READ) { |
|
61537
330273ec6028
Merged revisions 81116 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61246
diff
changeset
|
1445 sockstate = check_socket_and_wait_for_timeout(sock, 0); |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1446 } else if (err == SSL_ERROR_WANT_WRITE) { |
|
61537
330273ec6028
Merged revisions 81116 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61246
diff
changeset
|
1447 sockstate = check_socket_and_wait_for_timeout(sock, 1); |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1448 } else { |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1449 sockstate = SOCKET_OPERATION_OK; |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1450 } |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1451 if (sockstate == SOCKET_HAS_TIMED_OUT) { |
|
66663
3d9a86b8cc98
Issue #10272: The ssl module now raises socket.timeout instead of a generic
Antoine Pitrou <solipsis@pitrou.net>
parents:
66217
diff
changeset
|
1452 PyErr_SetString(PySocketModule.timeout_error, |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1453 "The write operation timed out"); |
|
62481
b8b0a15f8a7c
Merged revisions 82204 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61646
diff
changeset
|
1454 goto error; |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1455 } else if (sockstate == SOCKET_HAS_BEEN_CLOSED) { |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1456 PyErr_SetString(PySSLErrorObject, |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1457 "Underlying socket has been closed."); |
|
62481
b8b0a15f8a7c
Merged revisions 82204 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61646
diff
changeset
|
1458 goto error; |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1459 } else if (sockstate == SOCKET_IS_NONBLOCKING) { |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1460 break; |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1461 } |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1462 } while (err == SSL_ERROR_WANT_READ || err == SSL_ERROR_WANT_WRITE); |
|
62481
b8b0a15f8a7c
Merged revisions 82204 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61646
diff
changeset
|
1463 |
|
b8b0a15f8a7c
Merged revisions 82204 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61646
diff
changeset
|
1464 Py_DECREF(sock); |
|
61244
35221c0158b5
Merged revisions 80789 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61017
diff
changeset
|
1465 PyBuffer_Release(&buf); |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1466 if (len > 0) |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1467 return PyLong_FromLong(len); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1468 else |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1469 return PySSL_SetError(self, len, __FILE__, __LINE__); |
|
62481
b8b0a15f8a7c
Merged revisions 82204 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61646
diff
changeset
|
1470 |
|
b8b0a15f8a7c
Merged revisions 82204 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61646
diff
changeset
|
1471 error: |
|
b8b0a15f8a7c
Merged revisions 82204 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61646
diff
changeset
|
1472 Py_DECREF(sock); |
|
61244
35221c0158b5
Merged revisions 80789 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61017
diff
changeset
|
1473 PyBuffer_Release(&buf); |
|
62481
b8b0a15f8a7c
Merged revisions 82204 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61646
diff
changeset
|
1474 return NULL; |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
1475 } |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
1476 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23295
diff
changeset
|
1477 PyDoc_STRVAR(PySSL_SSLwrite_doc, |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
1478 "write(s) -> len\n\ |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
1479 \n\ |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
1480 Writes the string s into the SSL object. Returns the number\n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23295
diff
changeset
|
1481 of bytes written."); |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
1482 |
|
61635
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
1483 static PyObject *PySSL_SSLpending(PySSLSocket *self) |
|
43869
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
1484 { |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1485 int count = 0; |
|
43869
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
1486 |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1487 PySSL_BEGIN_ALLOW_THREADS |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1488 count = SSL_pending(self->ssl); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1489 PySSL_END_ALLOW_THREADS |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1490 if (count < 0) |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1491 return PySSL_SetError(self, count, __FILE__, __LINE__); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1492 else |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1493 return PyLong_FromLong(count); |
|
43869
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
1494 } |
|
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
1495 |
|
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
1496 PyDoc_STRVAR(PySSL_SSLpending_doc, |
|
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
1497 "pending() -> count\n\ |
|
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
1498 \n\ |
|
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
1499 Returns the number of already decrypted bytes available for read,\n\ |
|
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
1500 pending on the connection.\n"); |
|
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
1501 |
|
61635
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
1502 static PyObject *PySSL_SSLread(PySSLSocket *self, PyObject *args) |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
1503 { |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1504 PyObject *dest = NULL; |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1505 Py_buffer buf; |
|
64404
988718e9f93d
Merged revisions 84464 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
63694
diff
changeset
|
1506 char *mem; |
|
988718e9f93d
Merged revisions 84464 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
63694
diff
changeset
|
1507 int len, count; |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1508 int buf_passed = 0; |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1509 int sockstate; |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1510 int err; |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1511 int nonblocking; |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1512 PySocketSockObject *sock |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1513 = (PySocketSockObject *) PyWeakref_GetObject(self->Socket); |
|
44305
19f894ae864a
update to fix leak in SSL code
Bill Janssen <janssen@parc.com>
parents:
44206
diff
changeset
|
1514 |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1515 if (((PyObject*)sock) == Py_None) { |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1516 _setSSLError("Underlying socket connection gone", |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1517 PY_SSL_ERROR_NO_SOCKET, __FILE__, __LINE__); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1518 return NULL; |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1519 } |
|
62481
b8b0a15f8a7c
Merged revisions 82204 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61646
diff
changeset
|
1520 Py_INCREF(sock); |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
1521 |
|
64404
988718e9f93d
Merged revisions 84464 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
63694
diff
changeset
|
1522 buf.obj = NULL; |
|
988718e9f93d
Merged revisions 84464 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
63694
diff
changeset
|
1523 buf.buf = NULL; |
|
988718e9f93d
Merged revisions 84464 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
63694
diff
changeset
|
1524 if (!PyArg_ParseTuple(args, "i|w*:read", &len, &buf)) |
|
62481
b8b0a15f8a7c
Merged revisions 82204 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61646
diff
changeset
|
1525 goto error; |
|
b8b0a15f8a7c
Merged revisions 82204 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61646
diff
changeset
|
1526 |
|
64404
988718e9f93d
Merged revisions 84464 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
63694
diff
changeset
|
1527 if ((buf.buf == NULL) && (buf.obj == NULL)) { |
|
988718e9f93d
Merged revisions 84464 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
63694
diff
changeset
|
1528 dest = PyBytes_FromStringAndSize(NULL, len); |
|
988718e9f93d
Merged revisions 84464 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
63694
diff
changeset
|
1529 if (dest == NULL) |
|
62481
b8b0a15f8a7c
Merged revisions 82204 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61646
diff
changeset
|
1530 goto error; |
|
64404
988718e9f93d
Merged revisions 84464 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
63694
diff
changeset
|
1531 mem = PyBytes_AS_STRING(dest); |
|
988718e9f93d
Merged revisions 84464 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
63694
diff
changeset
|
1532 } |
|
988718e9f93d
Merged revisions 84464 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
63694
diff
changeset
|
1533 else { |
|
988718e9f93d
Merged revisions 84464 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
63694
diff
changeset
|
1534 buf_passed = 1; |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1535 mem = buf.buf; |
|
64404
988718e9f93d
Merged revisions 84464 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
63694
diff
changeset
|
1536 if (len <= 0 || len > buf.len) { |
|
988718e9f93d
Merged revisions 84464 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
63694
diff
changeset
|
1537 len = (int) buf.len; |
|
988718e9f93d
Merged revisions 84464 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
63694
diff
changeset
|
1538 if (buf.len != len) { |
|
988718e9f93d
Merged revisions 84464 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
63694
diff
changeset
|
1539 PyErr_SetString(PyExc_OverflowError, |
|
988718e9f93d
Merged revisions 84464 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
63694
diff
changeset
|
1540 "maximum length can't fit in a C 'int'"); |
|
988718e9f93d
Merged revisions 84464 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
63694
diff
changeset
|
1541 goto error; |
|
988718e9f93d
Merged revisions 84464 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
63694
diff
changeset
|
1542 } |
|
988718e9f93d
Merged revisions 84464 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
63694
diff
changeset
|
1543 } |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1544 } |
|
43869
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
1545 |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1546 /* just in case the blocking state of the socket has been changed */ |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1547 nonblocking = (sock->sock_timeout >= 0.0); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1548 BIO_set_nbio(SSL_get_rbio(self->ssl), nonblocking); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1549 BIO_set_nbio(SSL_get_wbio(self->ssl), nonblocking); |
|
42954
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
1550 |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1551 /* first check if there are bytes ready to be read */ |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1552 PySSL_BEGIN_ALLOW_THREADS |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1553 count = SSL_pending(self->ssl); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1554 PySSL_END_ALLOW_THREADS |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
1555 |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1556 if (!count) { |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1557 sockstate = check_socket_and_wait_for_timeout(sock, 0); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1558 if (sockstate == SOCKET_HAS_TIMED_OUT) { |
|
66663
3d9a86b8cc98
Issue #10272: The ssl module now raises socket.timeout instead of a generic
Antoine Pitrou <solipsis@pitrou.net>
parents:
66217
diff
changeset
|
1559 PyErr_SetString(PySocketModule.timeout_error, |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1560 "The read operation timed out"); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1561 goto error; |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1562 } else if (sockstate == SOCKET_TOO_LARGE_FOR_SELECT) { |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1563 PyErr_SetString(PySSLErrorObject, |
|
61537
330273ec6028
Merged revisions 81116 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61246
diff
changeset
|
1564 "Underlying socket too large for select()."); |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1565 goto error; |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1566 } else if (sockstate == SOCKET_HAS_BEEN_CLOSED) { |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1567 count = 0; |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1568 goto done; |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1569 } |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1570 } |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1571 do { |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1572 PySSL_BEGIN_ALLOW_THREADS |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1573 count = SSL_read(self->ssl, mem, len); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1574 err = SSL_get_error(self->ssl, count); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1575 PySSL_END_ALLOW_THREADS |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1576 if (PyErr_CheckSignals()) |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1577 goto error; |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1578 if (err == SSL_ERROR_WANT_READ) { |
|
61537
330273ec6028
Merged revisions 81116 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61246
diff
changeset
|
1579 sockstate = check_socket_and_wait_for_timeout(sock, 0); |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1580 } else if (err == SSL_ERROR_WANT_WRITE) { |
|
61537
330273ec6028
Merged revisions 81116 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61246
diff
changeset
|
1581 sockstate = check_socket_and_wait_for_timeout(sock, 1); |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1582 } else if ((err == SSL_ERROR_ZERO_RETURN) && |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1583 (SSL_get_shutdown(self->ssl) == |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1584 SSL_RECEIVED_SHUTDOWN)) |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1585 { |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1586 count = 0; |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1587 goto done; |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1588 } else { |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1589 sockstate = SOCKET_OPERATION_OK; |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1590 } |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1591 if (sockstate == SOCKET_HAS_TIMED_OUT) { |
|
66663
3d9a86b8cc98
Issue #10272: The ssl module now raises socket.timeout instead of a generic
Antoine Pitrou <solipsis@pitrou.net>
parents:
66217
diff
changeset
|
1592 PyErr_SetString(PySocketModule.timeout_error, |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1593 "The read operation timed out"); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1594 goto error; |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1595 } else if (sockstate == SOCKET_IS_NONBLOCKING) { |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1596 break; |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1597 } |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1598 } while (err == SSL_ERROR_WANT_READ || err == SSL_ERROR_WANT_WRITE); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1599 if (count <= 0) { |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1600 PySSL_SetError(self, count, __FILE__, __LINE__); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1601 goto error; |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1602 } |
|
64404
988718e9f93d
Merged revisions 84464 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
63694
diff
changeset
|
1603 |
|
988718e9f93d
Merged revisions 84464 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
63694
diff
changeset
|
1604 done: |
|
62481
b8b0a15f8a7c
Merged revisions 82204 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61646
diff
changeset
|
1605 Py_DECREF(sock); |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1606 if (!buf_passed) { |
|
64404
988718e9f93d
Merged revisions 84464 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
63694
diff
changeset
|
1607 _PyBytes_Resize(&dest, count); |
|
988718e9f93d
Merged revisions 84464 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
63694
diff
changeset
|
1608 return dest; |
|
988718e9f93d
Merged revisions 84464 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
63694
diff
changeset
|
1609 } |
|
988718e9f93d
Merged revisions 84464 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
63694
diff
changeset
|
1610 else { |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1611 PyBuffer_Release(&buf); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1612 return PyLong_FromLong(count); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1613 } |
|
64404
988718e9f93d
Merged revisions 84464 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
63694
diff
changeset
|
1614 |
|
988718e9f93d
Merged revisions 84464 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
63694
diff
changeset
|
1615 error: |
|
62481
b8b0a15f8a7c
Merged revisions 82204 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61646
diff
changeset
|
1616 Py_DECREF(sock); |
|
64404
988718e9f93d
Merged revisions 84464 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
63694
diff
changeset
|
1617 if (!buf_passed) |
|
62481
b8b0a15f8a7c
Merged revisions 82204 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61646
diff
changeset
|
1618 Py_XDECREF(dest); |
|
64404
988718e9f93d
Merged revisions 84464 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
63694
diff
changeset
|
1619 else |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1620 PyBuffer_Release(&buf); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1621 return NULL; |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
1622 } |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
1623 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23295
diff
changeset
|
1624 PyDoc_STRVAR(PySSL_SSLread_doc, |
|
43869
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
1625 "read([len]) -> string\n\ |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
1626 \n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23295
diff
changeset
|
1627 Read up to len bytes from the SSL socket."); |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
1628 |
|
61635
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
1629 static PyObject *PySSL_SSLshutdown(PySSLSocket *self) |
|
48681
3c8ef3466923
clean up ssl.py; expose unwrap and add test for it
Bill Janssen <janssen@parc.com>
parents:
48660
diff
changeset
|
1630 { |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1631 int err, ssl_err, sockstate, nonblocking; |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1632 int zeros = 0; |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1633 PySocketSockObject *sock |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1634 = (PySocketSockObject *) PyWeakref_GetObject(self->Socket); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1635 |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1636 /* Guard against closed socket */ |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1637 if ((((PyObject*)sock) == Py_None) || (sock->sock_fd < 0)) { |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1638 _setSSLError("Underlying socket connection gone", |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1639 PY_SSL_ERROR_NO_SOCKET, __FILE__, __LINE__); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1640 return NULL; |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1641 } |
|
62481
b8b0a15f8a7c
Merged revisions 82204 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61646
diff
changeset
|
1642 Py_INCREF(sock); |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1643 |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1644 /* Just in case the blocking state of the socket has been changed */ |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1645 nonblocking = (sock->sock_timeout >= 0.0); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1646 BIO_set_nbio(SSL_get_rbio(self->ssl), nonblocking); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1647 BIO_set_nbio(SSL_get_wbio(self->ssl), nonblocking); |
|
48681
3c8ef3466923
clean up ssl.py; expose unwrap and add test for it
Bill Janssen <janssen@parc.com>
parents:
48660
diff
changeset
|
1648 |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1649 while (1) { |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1650 PySSL_BEGIN_ALLOW_THREADS |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1651 /* Disable read-ahead so that unwrap can work correctly. |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1652 * Otherwise OpenSSL might read in too much data, |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1653 * eating clear text data that happens to be |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1654 * transmitted after the SSL shutdown. |
|
85231
61227b4c169f
#18466: fix more typos. Patch by Févry Thibault.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
85211
diff
changeset
|
1655 * Should be safe to call repeatedly every time this |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1656 * function is used and the shutdown_seen_zero != 0 |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1657 * condition is met. |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1658 */ |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1659 if (self->shutdown_seen_zero) |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1660 SSL_set_read_ahead(self->ssl, 0); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1661 err = SSL_shutdown(self->ssl); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1662 PySSL_END_ALLOW_THREADS |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1663 /* If err == 1, a secure shutdown with SSL_shutdown() is complete */ |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1664 if (err > 0) |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1665 break; |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1666 if (err == 0) { |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1667 /* Don't loop endlessly; instead preserve legacy |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1668 behaviour of trying SSL_shutdown() only twice. |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1669 This looks necessary for OpenSSL < 0.9.8m */ |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1670 if (++zeros > 1) |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1671 break; |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1672 /* Shutdown was sent, now try receiving */ |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1673 self->shutdown_seen_zero = 1; |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1674 continue; |
|
48681
3c8ef3466923
clean up ssl.py; expose unwrap and add test for it
Bill Janssen <janssen@parc.com>
parents:
48660
diff
changeset
|
1675 } |
|
3c8ef3466923
clean up ssl.py; expose unwrap and add test for it
Bill Janssen <janssen@parc.com>
parents:
48660
diff
changeset
|
1676 |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1677 /* Possibly retry shutdown until timeout or failure */ |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1678 ssl_err = SSL_get_error(self->ssl, err); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1679 if (ssl_err == SSL_ERROR_WANT_READ) |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1680 sockstate = check_socket_and_wait_for_timeout(sock, 0); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1681 else if (ssl_err == SSL_ERROR_WANT_WRITE) |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1682 sockstate = check_socket_and_wait_for_timeout(sock, 1); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1683 else |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1684 break; |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1685 if (sockstate == SOCKET_HAS_TIMED_OUT) { |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1686 if (ssl_err == SSL_ERROR_WANT_READ) |
|
66663
3d9a86b8cc98
Issue #10272: The ssl module now raises socket.timeout instead of a generic
Antoine Pitrou <solipsis@pitrou.net>
parents:
66217
diff
changeset
|
1687 PyErr_SetString(PySocketModule.timeout_error, |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1688 "The read operation timed out"); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1689 else |
|
66663
3d9a86b8cc98
Issue #10272: The ssl module now raises socket.timeout instead of a generic
Antoine Pitrou <solipsis@pitrou.net>
parents:
66217
diff
changeset
|
1690 PyErr_SetString(PySocketModule.timeout_error, |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1691 "The write operation timed out"); |
|
62481
b8b0a15f8a7c
Merged revisions 82204 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61646
diff
changeset
|
1692 goto error; |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1693 } |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1694 else if (sockstate == SOCKET_TOO_LARGE_FOR_SELECT) { |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1695 PyErr_SetString(PySSLErrorObject, |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1696 "Underlying socket too large for select()."); |
|
62481
b8b0a15f8a7c
Merged revisions 82204 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61646
diff
changeset
|
1697 goto error; |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1698 } |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1699 else if (sockstate != SOCKET_OPERATION_OK) |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1700 /* Retain the SSL error code */ |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1701 break; |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1702 } |
|
60901
fc97784e5cc2
Merged revisions 80394 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60818
diff
changeset
|
1703 |
|
62481
b8b0a15f8a7c
Merged revisions 82204 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61646
diff
changeset
|
1704 if (err < 0) { |
|
b8b0a15f8a7c
Merged revisions 82204 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61646
diff
changeset
|
1705 Py_DECREF(sock); |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1706 return PySSL_SetError(self, err, __FILE__, __LINE__); |
|
62481
b8b0a15f8a7c
Merged revisions 82204 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61646
diff
changeset
|
1707 } |
|
b8b0a15f8a7c
Merged revisions 82204 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61646
diff
changeset
|
1708 else |
|
b8b0a15f8a7c
Merged revisions 82204 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61646
diff
changeset
|
1709 /* It's already INCREF'ed */ |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1710 return (PyObject *) sock; |
|
62481
b8b0a15f8a7c
Merged revisions 82204 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61646
diff
changeset
|
1711 |
|
b8b0a15f8a7c
Merged revisions 82204 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61646
diff
changeset
|
1712 error: |
|
b8b0a15f8a7c
Merged revisions 82204 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61646
diff
changeset
|
1713 Py_DECREF(sock); |
|
b8b0a15f8a7c
Merged revisions 82204 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61646
diff
changeset
|
1714 return NULL; |
|
48681
3c8ef3466923
clean up ssl.py; expose unwrap and add test for it
Bill Janssen <janssen@parc.com>
parents:
48660
diff
changeset
|
1715 } |
|
3c8ef3466923
clean up ssl.py; expose unwrap and add test for it
Bill Janssen <janssen@parc.com>
parents:
48660
diff
changeset
|
1716 |
|
3c8ef3466923
clean up ssl.py; expose unwrap and add test for it
Bill Janssen <janssen@parc.com>
parents:
48660
diff
changeset
|
1717 PyDoc_STRVAR(PySSL_SSLshutdown_doc, |
|
3c8ef3466923
clean up ssl.py; expose unwrap and add test for it
Bill Janssen <janssen@parc.com>
parents:
48660
diff
changeset
|
1718 "shutdown(s) -> socket\n\ |
|
3c8ef3466923
clean up ssl.py; expose unwrap and add test for it
Bill Janssen <janssen@parc.com>
parents:
48660
diff
changeset
|
1719 \n\ |
|
3c8ef3466923
clean up ssl.py; expose unwrap and add test for it
Bill Janssen <janssen@parc.com>
parents:
48660
diff
changeset
|
1720 Does the SSL shutdown handshake with the remote end, and returns\n\ |
|
3c8ef3466923
clean up ssl.py; expose unwrap and add test for it
Bill Janssen <janssen@parc.com>
parents:
48660
diff
changeset
|
1721 the underlying socket object."); |
|
3c8ef3466923
clean up ssl.py; expose unwrap and add test for it
Bill Janssen <janssen@parc.com>
parents:
48660
diff
changeset
|
1722 |
|
71440
cb44fef5ea1d
Issue #12551: Provide a get_channel_binding() method on SSL sockets so as
Antoine Pitrou <solipsis@pitrou.net>
parents:
71256
diff
changeset
|
1723 #if HAVE_OPENSSL_FINISHED |
|
cb44fef5ea1d
Issue #12551: Provide a get_channel_binding() method on SSL sockets so as
Antoine Pitrou <solipsis@pitrou.net>
parents:
71256
diff
changeset
|
1724 static PyObject * |
|
cb44fef5ea1d
Issue #12551: Provide a get_channel_binding() method on SSL sockets so as
Antoine Pitrou <solipsis@pitrou.net>
parents:
71256
diff
changeset
|
1725 PySSL_tls_unique_cb(PySSLSocket *self) |
|
cb44fef5ea1d
Issue #12551: Provide a get_channel_binding() method on SSL sockets so as
Antoine Pitrou <solipsis@pitrou.net>
parents:
71256
diff
changeset
|
1726 { |
|
cb44fef5ea1d
Issue #12551: Provide a get_channel_binding() method on SSL sockets so as
Antoine Pitrou <solipsis@pitrou.net>
parents:
71256
diff
changeset
|
1727 PyObject *retval = NULL; |
|
cb44fef5ea1d
Issue #12551: Provide a get_channel_binding() method on SSL sockets so as
Antoine Pitrou <solipsis@pitrou.net>
parents:
71256
diff
changeset
|
1728 char buf[PySSL_CB_MAXLEN]; |
|
84270
f0d934732ab1
Issue #18135: Fix a possible integer overflow in ssl.SSLSocket.write()
Victor Stinner <victor.stinner@gmail.com>
parents:
84269
diff
changeset
|
1729 size_t len; |
|
71440
cb44fef5ea1d
Issue #12551: Provide a get_channel_binding() method on SSL sockets so as
Antoine Pitrou <solipsis@pitrou.net>
parents:
71256
diff
changeset
|
1730 |
|
cb44fef5ea1d
Issue #12551: Provide a get_channel_binding() method on SSL sockets so as
Antoine Pitrou <solipsis@pitrou.net>
parents:
71256
diff
changeset
|
1731 if (SSL_session_reused(self->ssl) ^ !self->socket_type) { |
|
cb44fef5ea1d
Issue #12551: Provide a get_channel_binding() method on SSL sockets so as
Antoine Pitrou <solipsis@pitrou.net>
parents:
71256
diff
changeset
|
1732 /* if session is resumed XOR we are the client */ |
|
cb44fef5ea1d
Issue #12551: Provide a get_channel_binding() method on SSL sockets so as
Antoine Pitrou <solipsis@pitrou.net>
parents:
71256
diff
changeset
|
1733 len = SSL_get_finished(self->ssl, buf, PySSL_CB_MAXLEN); |
|
cb44fef5ea1d
Issue #12551: Provide a get_channel_binding() method on SSL sockets so as
Antoine Pitrou <solipsis@pitrou.net>
parents:
71256
diff
changeset
|
1734 } |
|
cb44fef5ea1d
Issue #12551: Provide a get_channel_binding() method on SSL sockets so as
Antoine Pitrou <solipsis@pitrou.net>
parents:
71256
diff
changeset
|
1735 else { |
|
cb44fef5ea1d
Issue #12551: Provide a get_channel_binding() method on SSL sockets so as
Antoine Pitrou <solipsis@pitrou.net>
parents:
71256
diff
changeset
|
1736 /* if a new session XOR we are the server */ |
|
cb44fef5ea1d
Issue #12551: Provide a get_channel_binding() method on SSL sockets so as
Antoine Pitrou <solipsis@pitrou.net>
parents:
71256
diff
changeset
|
1737 len = SSL_get_peer_finished(self->ssl, buf, PySSL_CB_MAXLEN); |
|
cb44fef5ea1d
Issue #12551: Provide a get_channel_binding() method on SSL sockets so as
Antoine Pitrou <solipsis@pitrou.net>
parents:
71256
diff
changeset
|
1738 } |
|
cb44fef5ea1d
Issue #12551: Provide a get_channel_binding() method on SSL sockets so as
Antoine Pitrou <solipsis@pitrou.net>
parents:
71256
diff
changeset
|
1739 |
|
cb44fef5ea1d
Issue #12551: Provide a get_channel_binding() method on SSL sockets so as
Antoine Pitrou <solipsis@pitrou.net>
parents:
71256
diff
changeset
|
1740 /* It cannot be negative in current OpenSSL version as of July 2011 */ |
|
cb44fef5ea1d
Issue #12551: Provide a get_channel_binding() method on SSL sockets so as
Antoine Pitrou <solipsis@pitrou.net>
parents:
71256
diff
changeset
|
1741 if (len == 0) |
|
cb44fef5ea1d
Issue #12551: Provide a get_channel_binding() method on SSL sockets so as
Antoine Pitrou <solipsis@pitrou.net>
parents:
71256
diff
changeset
|
1742 Py_RETURN_NONE; |
|
cb44fef5ea1d
Issue #12551: Provide a get_channel_binding() method on SSL sockets so as
Antoine Pitrou <solipsis@pitrou.net>
parents:
71256
diff
changeset
|
1743 |
|
cb44fef5ea1d
Issue #12551: Provide a get_channel_binding() method on SSL sockets so as
Antoine Pitrou <solipsis@pitrou.net>
parents:
71256
diff
changeset
|
1744 retval = PyBytes_FromStringAndSize(buf, len); |
|
cb44fef5ea1d
Issue #12551: Provide a get_channel_binding() method on SSL sockets so as
Antoine Pitrou <solipsis@pitrou.net>
parents:
71256
diff
changeset
|
1745 |
|
cb44fef5ea1d
Issue #12551: Provide a get_channel_binding() method on SSL sockets so as
Antoine Pitrou <solipsis@pitrou.net>
parents:
71256
diff
changeset
|
1746 return retval; |
|
cb44fef5ea1d
Issue #12551: Provide a get_channel_binding() method on SSL sockets so as
Antoine Pitrou <solipsis@pitrou.net>
parents:
71256
diff
changeset
|
1747 } |
|
cb44fef5ea1d
Issue #12551: Provide a get_channel_binding() method on SSL sockets so as
Antoine Pitrou <solipsis@pitrou.net>
parents:
71256
diff
changeset
|
1748 |
|
cb44fef5ea1d
Issue #12551: Provide a get_channel_binding() method on SSL sockets so as
Antoine Pitrou <solipsis@pitrou.net>
parents:
71256
diff
changeset
|
1749 PyDoc_STRVAR(PySSL_tls_unique_cb_doc, |
|
cb44fef5ea1d
Issue #12551: Provide a get_channel_binding() method on SSL sockets so as
Antoine Pitrou <solipsis@pitrou.net>
parents:
71256
diff
changeset
|
1750 "tls_unique_cb() -> bytes\n\ |
|
cb44fef5ea1d
Issue #12551: Provide a get_channel_binding() method on SSL sockets so as
Antoine Pitrou <solipsis@pitrou.net>
parents:
71256
diff
changeset
|
1751 \n\ |
|
cb44fef5ea1d
Issue #12551: Provide a get_channel_binding() method on SSL sockets so as
Antoine Pitrou <solipsis@pitrou.net>
parents:
71256
diff
changeset
|
1752 Returns the 'tls-unique' channel binding data, as defined by RFC 5929.\n\ |
|
cb44fef5ea1d
Issue #12551: Provide a get_channel_binding() method on SSL sockets so as
Antoine Pitrou <solipsis@pitrou.net>
parents:
71256
diff
changeset
|
1753 \n\ |
|
cb44fef5ea1d
Issue #12551: Provide a get_channel_binding() method on SSL sockets so as
Antoine Pitrou <solipsis@pitrou.net>
parents:
71256
diff
changeset
|
1754 If the TLS handshake is not yet complete, None is returned"); |
|
cb44fef5ea1d
Issue #12551: Provide a get_channel_binding() method on SSL sockets so as
Antoine Pitrou <solipsis@pitrou.net>
parents:
71256
diff
changeset
|
1755 |
|
cb44fef5ea1d
Issue #12551: Provide a get_channel_binding() method on SSL sockets so as
Antoine Pitrou <solipsis@pitrou.net>
parents:
71256
diff
changeset
|
1756 #endif /* HAVE_OPENSSL_FINISHED */ |
|
48681
3c8ef3466923
clean up ssl.py; expose unwrap and add test for it
Bill Janssen <janssen@parc.com>
parents:
48660
diff
changeset
|
1757 |
|
81298
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
1758 static PyGetSetDef ssl_getsetlist[] = { |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
1759 {"context", (getter) PySSL_get_context, |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
1760 (setter) PySSL_set_context, PySSL_set_context_doc}, |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
1761 {NULL}, /* sentinel */ |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
1762 }; |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
1763 |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
1764 static PyMethodDef PySSLMethods[] = { |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1765 {"do_handshake", (PyCFunction)PySSL_SSLdo_handshake, METH_NOARGS}, |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1766 {"write", (PyCFunction)PySSL_SSLwrite, METH_VARARGS, |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1767 PySSL_SSLwrite_doc}, |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1768 {"read", (PyCFunction)PySSL_SSLread, METH_VARARGS, |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1769 PySSL_SSLread_doc}, |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1770 {"pending", (PyCFunction)PySSL_SSLpending, METH_NOARGS, |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1771 PySSL_SSLpending_doc}, |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1772 {"peer_certificate", (PyCFunction)PySSL_peercert, METH_VARARGS, |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1773 PySSL_peercert_doc}, |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1774 {"cipher", (PyCFunction)PySSL_cipher, METH_NOARGS}, |
|
75865
2514a4e2b3ce
Issue #14204: The ssl module now has support for the Next Protocol Negotiation extension, if available in the underlying OpenSSL library.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75043
diff
changeset
|
1775 #ifdef OPENSSL_NPN_NEGOTIATED |
|
2514a4e2b3ce
Issue #14204: The ssl module now has support for the Next Protocol Negotiation extension, if available in the underlying OpenSSL library.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75043
diff
changeset
|
1776 {"selected_npn_protocol", (PyCFunction)PySSL_selected_npn_protocol, METH_NOARGS}, |
|
2514a4e2b3ce
Issue #14204: The ssl module now has support for the Next Protocol Negotiation extension, if available in the underlying OpenSSL library.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75043
diff
changeset
|
1777 #endif |
|
74091
20b52be99b5d
Issue #13634: Add support for querying and disabling SSL compression.
Antoine Pitrou <solipsis@pitrou.net>
parents:
74084
diff
changeset
|
1778 {"compression", (PyCFunction)PySSL_compression, METH_NOARGS}, |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1779 {"shutdown", (PyCFunction)PySSL_SSLshutdown, METH_NOARGS, |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1780 PySSL_SSLshutdown_doc}, |
|
71440
cb44fef5ea1d
Issue #12551: Provide a get_channel_binding() method on SSL sockets so as
Antoine Pitrou <solipsis@pitrou.net>
parents:
71256
diff
changeset
|
1781 #if HAVE_OPENSSL_FINISHED |
|
cb44fef5ea1d
Issue #12551: Provide a get_channel_binding() method on SSL sockets so as
Antoine Pitrou <solipsis@pitrou.net>
parents:
71256
diff
changeset
|
1782 {"tls_unique_cb", (PyCFunction)PySSL_tls_unique_cb, METH_NOARGS, |
|
cb44fef5ea1d
Issue #12551: Provide a get_channel_binding() method on SSL sockets so as
Antoine Pitrou <solipsis@pitrou.net>
parents:
71256
diff
changeset
|
1783 PySSL_tls_unique_cb_doc}, |
|
cb44fef5ea1d
Issue #12551: Provide a get_channel_binding() method on SSL sockets so as
Antoine Pitrou <solipsis@pitrou.net>
parents:
71256
diff
changeset
|
1784 #endif |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1785 {NULL, NULL} |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
1786 }; |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
1787 |
|
61635
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
1788 static PyTypeObject PySSLSocket_Type = { |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1789 PyVarObject_HEAD_INIT(NULL, 0) |
|
61635
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
1790 "_ssl._SSLSocket", /*tp_name*/ |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
1791 sizeof(PySSLSocket), /*tp_basicsize*/ |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1792 0, /*tp_itemsize*/ |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1793 /* methods */ |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1794 (destructor)PySSL_dealloc, /*tp_dealloc*/ |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1795 0, /*tp_print*/ |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1796 0, /*tp_getattr*/ |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1797 0, /*tp_setattr*/ |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1798 0, /*tp_reserved*/ |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1799 0, /*tp_repr*/ |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1800 0, /*tp_as_number*/ |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1801 0, /*tp_as_sequence*/ |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1802 0, /*tp_as_mapping*/ |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1803 0, /*tp_hash*/ |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1804 0, /*tp_call*/ |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1805 0, /*tp_str*/ |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1806 0, /*tp_getattro*/ |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1807 0, /*tp_setattro*/ |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1808 0, /*tp_as_buffer*/ |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1809 Py_TPFLAGS_DEFAULT, /*tp_flags*/ |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1810 0, /*tp_doc*/ |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1811 0, /*tp_traverse*/ |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1812 0, /*tp_clear*/ |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1813 0, /*tp_richcompare*/ |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1814 0, /*tp_weaklistoffset*/ |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1815 0, /*tp_iter*/ |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1816 0, /*tp_iternext*/ |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
1817 PySSLMethods, /*tp_methods*/ |
|
81298
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
1818 0, /*tp_members*/ |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
1819 ssl_getsetlist, /*tp_getset*/ |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
1820 }; |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
1821 |
|
61635
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
1822 |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
1823 /* |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
1824 * _SSLContext objects |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
1825 */ |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
1826 |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
1827 static PyObject * |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
1828 context_new(PyTypeObject *type, PyObject *args, PyObject *kwds) |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
1829 { |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
1830 char *kwlist[] = {"protocol", NULL}; |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
1831 PySSLContext *self; |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
1832 int proto_version = PY_SSL_VERSION_SSL23; |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
1833 SSL_CTX *ctx = NULL; |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
1834 |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
1835 if (!PyArg_ParseTupleAndKeywords( |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
1836 args, kwds, "i:_SSLContext", kwlist, |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
1837 &proto_version)) |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
1838 return NULL; |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
1839 |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
1840 PySSL_BEGIN_ALLOW_THREADS |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
1841 if (proto_version == PY_SSL_VERSION_TLS1) |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
1842 ctx = SSL_CTX_new(TLSv1_method()); |
|
82992
02a89bd646ca
Issue #16692: The ssl module now supports TLS 1.1 and TLS 1.2. Initial patch by Michele Orrù.
Antoine Pitrou <solipsis@pitrou.net>
parents:
81559
diff
changeset
|
1843 #if HAVE_TLSv1_2 |
|
02a89bd646ca
Issue #16692: The ssl module now supports TLS 1.1 and TLS 1.2. Initial patch by Michele Orrù.
Antoine Pitrou <solipsis@pitrou.net>
parents:
81559
diff
changeset
|
1844 else if (proto_version == PY_SSL_VERSION_TLS1_1) |
|
02a89bd646ca
Issue #16692: The ssl module now supports TLS 1.1 and TLS 1.2. Initial patch by Michele Orrù.
Antoine Pitrou <solipsis@pitrou.net>
parents:
81559
diff
changeset
|
1845 ctx = SSL_CTX_new(TLSv1_1_method()); |
|
02a89bd646ca
Issue #16692: The ssl module now supports TLS 1.1 and TLS 1.2. Initial patch by Michele Orrù.
Antoine Pitrou <solipsis@pitrou.net>
parents:
81559
diff
changeset
|
1846 else if (proto_version == PY_SSL_VERSION_TLS1_2) |
|
02a89bd646ca
Issue #16692: The ssl module now supports TLS 1.1 and TLS 1.2. Initial patch by Michele Orrù.
Antoine Pitrou <solipsis@pitrou.net>
parents:
81559
diff
changeset
|
1847 ctx = SSL_CTX_new(TLSv1_2_method()); |
|
02a89bd646ca
Issue #16692: The ssl module now supports TLS 1.1 and TLS 1.2. Initial patch by Michele Orrù.
Antoine Pitrou <solipsis@pitrou.net>
parents:
81559
diff
changeset
|
1848 #endif |
|
61635
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
1849 else if (proto_version == PY_SSL_VERSION_SSL3) |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
1850 ctx = SSL_CTX_new(SSLv3_method()); |
|
69998
20beec22764f
(Merge 3.1) Issue #12012: ssl.PROTOCOL_SSLv2 becomes optional
Victor Stinner <victor.stinner@haypocalc.com>
diff
changeset
|
1851 #ifndef OPENSSL_NO_SSL2 |
|
61635
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
1852 else if (proto_version == PY_SSL_VERSION_SSL2) |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
1853 ctx = SSL_CTX_new(SSLv2_method()); |
|
69998
20beec22764f
(Merge 3.1) Issue #12012: ssl.PROTOCOL_SSLv2 becomes optional
Victor Stinner <victor.stinner@haypocalc.com>
diff
changeset
|
1854 #endif |
|
61635
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
1855 else if (proto_version == PY_SSL_VERSION_SSL23) |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
1856 ctx = SSL_CTX_new(SSLv23_method()); |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
1857 else |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
1858 proto_version = -1; |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
1859 PySSL_END_ALLOW_THREADS |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
1860 |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
1861 if (proto_version == -1) { |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
1862 PyErr_SetString(PyExc_ValueError, |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
1863 "invalid protocol version"); |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
1864 return NULL; |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
1865 } |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
1866 if (ctx == NULL) { |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
1867 PyErr_SetString(PySSLErrorObject, |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
1868 "failed to allocate SSL context"); |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
1869 return NULL; |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
1870 } |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
1871 |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
1872 assert(type != NULL && type->tp_alloc != NULL); |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
1873 self = (PySSLContext *) type->tp_alloc(type, 0); |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
1874 if (self == NULL) { |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
1875 SSL_CTX_free(ctx); |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
1876 return NULL; |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
1877 } |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
1878 self->ctx = ctx; |
|
79114
4cf53684e14e
Issue #15977: Fix memory leak in Modules/_ssl.c when the function _set_npn_protocols() is called multiple times
Christian Heimes <christian@cheimes.de>
parents:
78605
diff
changeset
|
1879 #ifdef OPENSSL_NPN_NEGOTIATED |
|
4cf53684e14e
Issue #15977: Fix memory leak in Modules/_ssl.c when the function _set_npn_protocols() is called multiple times
Christian Heimes <christian@cheimes.de>
parents:
78605
diff
changeset
|
1880 self->npn_protocols = NULL; |
|
4cf53684e14e
Issue #15977: Fix memory leak in Modules/_ssl.c when the function _set_npn_protocols() is called multiple times
Christian Heimes <christian@cheimes.de>
parents:
78605
diff
changeset
|
1881 #endif |
|
81298
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
1882 #ifndef OPENSSL_NO_TLSEXT |
|
84334
28f47a5d59b9
_ssl.c: strip trailing spaces
Victor Stinner <victor.stinner@gmail.com>
parents:
84333
diff
changeset
|
1883 self->set_hostname = NULL; |
|
81298
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
1884 #endif |
|
61635
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
1885 /* Defaults */ |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
1886 SSL_CTX_set_verify(self->ctx, SSL_VERIFY_NONE, NULL); |
|
74648
4386686a035d
Issue #13885: CVE-2011-3389: the _ssl module would always disable the CBC IV attack countermeasure.
Antoine Pitrou <solipsis@pitrou.net>
diff
changeset
|
1887 SSL_CTX_set_options(self->ctx, |
|
4386686a035d
Issue #13885: CVE-2011-3389: the _ssl module would always disable the CBC IV attack countermeasure.
Antoine Pitrou <solipsis@pitrou.net>
diff
changeset
|
1888 SSL_OP_ALL & ~SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS); |
|
61635
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
1889 |
|
65255
c48c09e693e6
Define a "session_id_context" at context creation. This is recommended
Antoine Pitrou <solipsis@pitrou.net>
parents:
65246
diff
changeset
|
1890 #define SID_CTX "Python" |
|
c48c09e693e6
Define a "session_id_context" at context creation. This is recommended
Antoine Pitrou <solipsis@pitrou.net>
parents:
65246
diff
changeset
|
1891 SSL_CTX_set_session_id_context(self->ctx, (const unsigned char *) SID_CTX, |
|
c48c09e693e6
Define a "session_id_context" at context creation. This is recommended
Antoine Pitrou <solipsis@pitrou.net>
parents:
65246
diff
changeset
|
1892 sizeof(SID_CTX)); |
|
c48c09e693e6
Define a "session_id_context" at context creation. This is recommended
Antoine Pitrou <solipsis@pitrou.net>
parents:
65246
diff
changeset
|
1893 #undef SID_CTX |
|
c48c09e693e6
Define a "session_id_context" at context creation. This is recommended
Antoine Pitrou <solipsis@pitrou.net>
parents:
65246
diff
changeset
|
1894 |
|
61635
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
1895 return (PyObject *)self; |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
1896 } |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
1897 |
|
81298
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
1898 static int |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
1899 context_traverse(PySSLContext *self, visitproc visit, void *arg) |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
1900 { |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
1901 #ifndef OPENSSL_NO_TLSEXT |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
1902 Py_VISIT(self->set_hostname); |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
1903 #endif |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
1904 return 0; |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
1905 } |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
1906 |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
1907 static int |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
1908 context_clear(PySSLContext *self) |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
1909 { |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
1910 #ifndef OPENSSL_NO_TLSEXT |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
1911 Py_CLEAR(self->set_hostname); |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
1912 #endif |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
1913 return 0; |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
1914 } |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
1915 |
|
61635
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
1916 static void |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
1917 context_dealloc(PySSLContext *self) |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
1918 { |
|
81298
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
1919 context_clear(self); |
|
61635
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
1920 SSL_CTX_free(self->ctx); |
|
75865
2514a4e2b3ce
Issue #14204: The ssl module now has support for the Next Protocol Negotiation extension, if available in the underlying OpenSSL library.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75043
diff
changeset
|
1921 #ifdef OPENSSL_NPN_NEGOTIATED |
|
2514a4e2b3ce
Issue #14204: The ssl module now has support for the Next Protocol Negotiation extension, if available in the underlying OpenSSL library.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75043
diff
changeset
|
1922 PyMem_Free(self->npn_protocols); |
|
2514a4e2b3ce
Issue #14204: The ssl module now has support for the Next Protocol Negotiation extension, if available in the underlying OpenSSL library.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75043
diff
changeset
|
1923 #endif |
|
61635
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
1924 Py_TYPE(self)->tp_free(self); |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
1925 } |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
1926 |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
1927 static PyObject * |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
1928 set_ciphers(PySSLContext *self, PyObject *args) |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
1929 { |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
1930 int ret; |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
1931 const char *cipherlist; |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
1932 |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
1933 if (!PyArg_ParseTuple(args, "s:set_ciphers", &cipherlist)) |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
1934 return NULL; |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
1935 ret = SSL_CTX_set_cipher_list(self->ctx, cipherlist); |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
1936 if (ret == 0) { |
|
61637
2ca4626d9c93
Fix (hopefully) the remaining test_ssl buildbot failures
Antoine Pitrou <solipsis@pitrou.net>
parents:
61635
diff
changeset
|
1937 /* Clearing the error queue is necessary on some OpenSSL versions, |
|
2ca4626d9c93
Fix (hopefully) the remaining test_ssl buildbot failures
Antoine Pitrou <solipsis@pitrou.net>
parents:
61635
diff
changeset
|
1938 otherwise the error will be reported again when another SSL call |
|
2ca4626d9c93
Fix (hopefully) the remaining test_ssl buildbot failures
Antoine Pitrou <solipsis@pitrou.net>
parents:
61635
diff
changeset
|
1939 is done. */ |
|
2ca4626d9c93
Fix (hopefully) the remaining test_ssl buildbot failures
Antoine Pitrou <solipsis@pitrou.net>
parents:
61635
diff
changeset
|
1940 ERR_clear_error(); |
|
61635
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
1941 PyErr_SetString(PySSLErrorObject, |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
1942 "No cipher can be selected."); |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
1943 return NULL; |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
1944 } |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
1945 Py_RETURN_NONE; |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
1946 } |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
1947 |
|
75865
2514a4e2b3ce
Issue #14204: The ssl module now has support for the Next Protocol Negotiation extension, if available in the underlying OpenSSL library.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75043
diff
changeset
|
1948 #ifdef OPENSSL_NPN_NEGOTIATED |
|
2514a4e2b3ce
Issue #14204: The ssl module now has support for the Next Protocol Negotiation extension, if available in the underlying OpenSSL library.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75043
diff
changeset
|
1949 /* this callback gets passed to SSL_CTX_set_next_protos_advertise_cb */ |
|
2514a4e2b3ce
Issue #14204: The ssl module now has support for the Next Protocol Negotiation extension, if available in the underlying OpenSSL library.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75043
diff
changeset
|
1950 static int |
|
84269
1bd49f8a30da
_ssl.c: strip trailing spaces
Victor Stinner <victor.stinner@gmail.com>
parents:
81463
diff
changeset
|
1951 _advertiseNPN_cb(SSL *s, |
|
1bd49f8a30da
_ssl.c: strip trailing spaces
Victor Stinner <victor.stinner@gmail.com>
parents:
81463
diff
changeset
|
1952 const unsigned char **data, unsigned int *len, |
|
75865
2514a4e2b3ce
Issue #14204: The ssl module now has support for the Next Protocol Negotiation extension, if available in the underlying OpenSSL library.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75043
diff
changeset
|
1953 void *args) |
|
2514a4e2b3ce
Issue #14204: The ssl module now has support for the Next Protocol Negotiation extension, if available in the underlying OpenSSL library.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75043
diff
changeset
|
1954 { |
|
2514a4e2b3ce
Issue #14204: The ssl module now has support for the Next Protocol Negotiation extension, if available in the underlying OpenSSL library.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75043
diff
changeset
|
1955 PySSLContext *ssl_ctx = (PySSLContext *) args; |
|
2514a4e2b3ce
Issue #14204: The ssl module now has support for the Next Protocol Negotiation extension, if available in the underlying OpenSSL library.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75043
diff
changeset
|
1956 |
|
2514a4e2b3ce
Issue #14204: The ssl module now has support for the Next Protocol Negotiation extension, if available in the underlying OpenSSL library.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75043
diff
changeset
|
1957 if (ssl_ctx->npn_protocols == NULL) { |
|
2514a4e2b3ce
Issue #14204: The ssl module now has support for the Next Protocol Negotiation extension, if available in the underlying OpenSSL library.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75043
diff
changeset
|
1958 *data = (unsigned char *) ""; |
|
2514a4e2b3ce
Issue #14204: The ssl module now has support for the Next Protocol Negotiation extension, if available in the underlying OpenSSL library.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75043
diff
changeset
|
1959 *len = 0; |
|
2514a4e2b3ce
Issue #14204: The ssl module now has support for the Next Protocol Negotiation extension, if available in the underlying OpenSSL library.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75043
diff
changeset
|
1960 } else { |
|
2514a4e2b3ce
Issue #14204: The ssl module now has support for the Next Protocol Negotiation extension, if available in the underlying OpenSSL library.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75043
diff
changeset
|
1961 *data = (unsigned char *) ssl_ctx->npn_protocols; |
|
2514a4e2b3ce
Issue #14204: The ssl module now has support for the Next Protocol Negotiation extension, if available in the underlying OpenSSL library.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75043
diff
changeset
|
1962 *len = ssl_ctx->npn_protocols_len; |
|
2514a4e2b3ce
Issue #14204: The ssl module now has support for the Next Protocol Negotiation extension, if available in the underlying OpenSSL library.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75043
diff
changeset
|
1963 } |
|
2514a4e2b3ce
Issue #14204: The ssl module now has support for the Next Protocol Negotiation extension, if available in the underlying OpenSSL library.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75043
diff
changeset
|
1964 |
|
2514a4e2b3ce
Issue #14204: The ssl module now has support for the Next Protocol Negotiation extension, if available in the underlying OpenSSL library.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75043
diff
changeset
|
1965 return SSL_TLSEXT_ERR_OK; |
|
2514a4e2b3ce
Issue #14204: The ssl module now has support for the Next Protocol Negotiation extension, if available in the underlying OpenSSL library.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75043
diff
changeset
|
1966 } |
|
2514a4e2b3ce
Issue #14204: The ssl module now has support for the Next Protocol Negotiation extension, if available in the underlying OpenSSL library.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75043
diff
changeset
|
1967 /* this callback gets passed to SSL_CTX_set_next_proto_select_cb */ |
|
2514a4e2b3ce
Issue #14204: The ssl module now has support for the Next Protocol Negotiation extension, if available in the underlying OpenSSL library.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75043
diff
changeset
|
1968 static int |
|
84269
1bd49f8a30da
_ssl.c: strip trailing spaces
Victor Stinner <victor.stinner@gmail.com>
parents:
81463
diff
changeset
|
1969 _selectNPN_cb(SSL *s, |
|
75865
2514a4e2b3ce
Issue #14204: The ssl module now has support for the Next Protocol Negotiation extension, if available in the underlying OpenSSL library.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75043
diff
changeset
|
1970 unsigned char **out, unsigned char *outlen, |
|
2514a4e2b3ce
Issue #14204: The ssl module now has support for the Next Protocol Negotiation extension, if available in the underlying OpenSSL library.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75043
diff
changeset
|
1971 const unsigned char *server, unsigned int server_len, |
|
2514a4e2b3ce
Issue #14204: The ssl module now has support for the Next Protocol Negotiation extension, if available in the underlying OpenSSL library.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75043
diff
changeset
|
1972 void *args) |
|
2514a4e2b3ce
Issue #14204: The ssl module now has support for the Next Protocol Negotiation extension, if available in the underlying OpenSSL library.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75043
diff
changeset
|
1973 { |
|
2514a4e2b3ce
Issue #14204: The ssl module now has support for the Next Protocol Negotiation extension, if available in the underlying OpenSSL library.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75043
diff
changeset
|
1974 PySSLContext *ssl_ctx = (PySSLContext *) args; |
|
2514a4e2b3ce
Issue #14204: The ssl module now has support for the Next Protocol Negotiation extension, if available in the underlying OpenSSL library.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75043
diff
changeset
|
1975 |
|
2514a4e2b3ce
Issue #14204: The ssl module now has support for the Next Protocol Negotiation extension, if available in the underlying OpenSSL library.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75043
diff
changeset
|
1976 unsigned char *client = (unsigned char *) ssl_ctx->npn_protocols; |
|
2514a4e2b3ce
Issue #14204: The ssl module now has support for the Next Protocol Negotiation extension, if available in the underlying OpenSSL library.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75043
diff
changeset
|
1977 int client_len; |
|
2514a4e2b3ce
Issue #14204: The ssl module now has support for the Next Protocol Negotiation extension, if available in the underlying OpenSSL library.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75043
diff
changeset
|
1978 |
|
2514a4e2b3ce
Issue #14204: The ssl module now has support for the Next Protocol Negotiation extension, if available in the underlying OpenSSL library.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75043
diff
changeset
|
1979 if (client == NULL) { |
|
2514a4e2b3ce
Issue #14204: The ssl module now has support for the Next Protocol Negotiation extension, if available in the underlying OpenSSL library.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75043
diff
changeset
|
1980 client = (unsigned char *) ""; |
|
2514a4e2b3ce
Issue #14204: The ssl module now has support for the Next Protocol Negotiation extension, if available in the underlying OpenSSL library.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75043
diff
changeset
|
1981 client_len = 0; |
|
2514a4e2b3ce
Issue #14204: The ssl module now has support for the Next Protocol Negotiation extension, if available in the underlying OpenSSL library.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75043
diff
changeset
|
1982 } else { |
|
2514a4e2b3ce
Issue #14204: The ssl module now has support for the Next Protocol Negotiation extension, if available in the underlying OpenSSL library.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75043
diff
changeset
|
1983 client_len = ssl_ctx->npn_protocols_len; |
|
2514a4e2b3ce
Issue #14204: The ssl module now has support for the Next Protocol Negotiation extension, if available in the underlying OpenSSL library.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75043
diff
changeset
|
1984 } |
|
2514a4e2b3ce
Issue #14204: The ssl module now has support for the Next Protocol Negotiation extension, if available in the underlying OpenSSL library.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75043
diff
changeset
|
1985 |
|
2514a4e2b3ce
Issue #14204: The ssl module now has support for the Next Protocol Negotiation extension, if available in the underlying OpenSSL library.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75043
diff
changeset
|
1986 SSL_select_next_proto(out, outlen, |
|
2514a4e2b3ce
Issue #14204: The ssl module now has support for the Next Protocol Negotiation extension, if available in the underlying OpenSSL library.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75043
diff
changeset
|
1987 server, server_len, |
|
2514a4e2b3ce
Issue #14204: The ssl module now has support for the Next Protocol Negotiation extension, if available in the underlying OpenSSL library.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75043
diff
changeset
|
1988 client, client_len); |
|
2514a4e2b3ce
Issue #14204: The ssl module now has support for the Next Protocol Negotiation extension, if available in the underlying OpenSSL library.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75043
diff
changeset
|
1989 |
|
2514a4e2b3ce
Issue #14204: The ssl module now has support for the Next Protocol Negotiation extension, if available in the underlying OpenSSL library.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75043
diff
changeset
|
1990 return SSL_TLSEXT_ERR_OK; |
|
2514a4e2b3ce
Issue #14204: The ssl module now has support for the Next Protocol Negotiation extension, if available in the underlying OpenSSL library.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75043
diff
changeset
|
1991 } |
|
2514a4e2b3ce
Issue #14204: The ssl module now has support for the Next Protocol Negotiation extension, if available in the underlying OpenSSL library.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75043
diff
changeset
|
1992 #endif |
|
2514a4e2b3ce
Issue #14204: The ssl module now has support for the Next Protocol Negotiation extension, if available in the underlying OpenSSL library.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75043
diff
changeset
|
1993 |
|
2514a4e2b3ce
Issue #14204: The ssl module now has support for the Next Protocol Negotiation extension, if available in the underlying OpenSSL library.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75043
diff
changeset
|
1994 static PyObject * |
|
2514a4e2b3ce
Issue #14204: The ssl module now has support for the Next Protocol Negotiation extension, if available in the underlying OpenSSL library.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75043
diff
changeset
|
1995 _set_npn_protocols(PySSLContext *self, PyObject *args) |
|
2514a4e2b3ce
Issue #14204: The ssl module now has support for the Next Protocol Negotiation extension, if available in the underlying OpenSSL library.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75043
diff
changeset
|
1996 { |
|
2514a4e2b3ce
Issue #14204: The ssl module now has support for the Next Protocol Negotiation extension, if available in the underlying OpenSSL library.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75043
diff
changeset
|
1997 #ifdef OPENSSL_NPN_NEGOTIATED |
|
2514a4e2b3ce
Issue #14204: The ssl module now has support for the Next Protocol Negotiation extension, if available in the underlying OpenSSL library.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75043
diff
changeset
|
1998 Py_buffer protos; |
|
2514a4e2b3ce
Issue #14204: The ssl module now has support for the Next Protocol Negotiation extension, if available in the underlying OpenSSL library.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75043
diff
changeset
|
1999 |
|
2514a4e2b3ce
Issue #14204: The ssl module now has support for the Next Protocol Negotiation extension, if available in the underlying OpenSSL library.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75043
diff
changeset
|
2000 if (!PyArg_ParseTuple(args, "y*:set_npn_protocols", &protos)) |
|
2514a4e2b3ce
Issue #14204: The ssl module now has support for the Next Protocol Negotiation extension, if available in the underlying OpenSSL library.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75043
diff
changeset
|
2001 return NULL; |
|
2514a4e2b3ce
Issue #14204: The ssl module now has support for the Next Protocol Negotiation extension, if available in the underlying OpenSSL library.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75043
diff
changeset
|
2002 |
|
79114
4cf53684e14e
Issue #15977: Fix memory leak in Modules/_ssl.c when the function _set_npn_protocols() is called multiple times
Christian Heimes <christian@cheimes.de>
parents:
78605
diff
changeset
|
2003 if (self->npn_protocols != NULL) { |
|
4cf53684e14e
Issue #15977: Fix memory leak in Modules/_ssl.c when the function _set_npn_protocols() is called multiple times
Christian Heimes <christian@cheimes.de>
parents:
78605
diff
changeset
|
2004 PyMem_Free(self->npn_protocols); |
|
4cf53684e14e
Issue #15977: Fix memory leak in Modules/_ssl.c when the function _set_npn_protocols() is called multiple times
Christian Heimes <christian@cheimes.de>
parents:
78605
diff
changeset
|
2005 } |
|
4cf53684e14e
Issue #15977: Fix memory leak in Modules/_ssl.c when the function _set_npn_protocols() is called multiple times
Christian Heimes <christian@cheimes.de>
parents:
78605
diff
changeset
|
2006 |
|
75865
2514a4e2b3ce
Issue #14204: The ssl module now has support for the Next Protocol Negotiation extension, if available in the underlying OpenSSL library.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75043
diff
changeset
|
2007 self->npn_protocols = PyMem_Malloc(protos.len); |
|
2514a4e2b3ce
Issue #14204: The ssl module now has support for the Next Protocol Negotiation extension, if available in the underlying OpenSSL library.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75043
diff
changeset
|
2008 if (self->npn_protocols == NULL) { |
|
2514a4e2b3ce
Issue #14204: The ssl module now has support for the Next Protocol Negotiation extension, if available in the underlying OpenSSL library.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75043
diff
changeset
|
2009 PyBuffer_Release(&protos); |
|
2514a4e2b3ce
Issue #14204: The ssl module now has support for the Next Protocol Negotiation extension, if available in the underlying OpenSSL library.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75043
diff
changeset
|
2010 return PyErr_NoMemory(); |
|
2514a4e2b3ce
Issue #14204: The ssl module now has support for the Next Protocol Negotiation extension, if available in the underlying OpenSSL library.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75043
diff
changeset
|
2011 } |
|
2514a4e2b3ce
Issue #14204: The ssl module now has support for the Next Protocol Negotiation extension, if available in the underlying OpenSSL library.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75043
diff
changeset
|
2012 memcpy(self->npn_protocols, protos.buf, protos.len); |
|
2514a4e2b3ce
Issue #14204: The ssl module now has support for the Next Protocol Negotiation extension, if available in the underlying OpenSSL library.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75043
diff
changeset
|
2013 self->npn_protocols_len = (int) protos.len; |
|
2514a4e2b3ce
Issue #14204: The ssl module now has support for the Next Protocol Negotiation extension, if available in the underlying OpenSSL library.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75043
diff
changeset
|
2014 |
|
2514a4e2b3ce
Issue #14204: The ssl module now has support for the Next Protocol Negotiation extension, if available in the underlying OpenSSL library.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75043
diff
changeset
|
2015 /* set both server and client callbacks, because the context can |
|
2514a4e2b3ce
Issue #14204: The ssl module now has support for the Next Protocol Negotiation extension, if available in the underlying OpenSSL library.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75043
diff
changeset
|
2016 * be used to create both types of sockets */ |
|
2514a4e2b3ce
Issue #14204: The ssl module now has support for the Next Protocol Negotiation extension, if available in the underlying OpenSSL library.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75043
diff
changeset
|
2017 SSL_CTX_set_next_protos_advertised_cb(self->ctx, |
|
2514a4e2b3ce
Issue #14204: The ssl module now has support for the Next Protocol Negotiation extension, if available in the underlying OpenSSL library.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75043
diff
changeset
|
2018 _advertiseNPN_cb, |
|
2514a4e2b3ce
Issue #14204: The ssl module now has support for the Next Protocol Negotiation extension, if available in the underlying OpenSSL library.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75043
diff
changeset
|
2019 self); |
|
2514a4e2b3ce
Issue #14204: The ssl module now has support for the Next Protocol Negotiation extension, if available in the underlying OpenSSL library.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75043
diff
changeset
|
2020 SSL_CTX_set_next_proto_select_cb(self->ctx, |
|
2514a4e2b3ce
Issue #14204: The ssl module now has support for the Next Protocol Negotiation extension, if available in the underlying OpenSSL library.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75043
diff
changeset
|
2021 _selectNPN_cb, |
|
2514a4e2b3ce
Issue #14204: The ssl module now has support for the Next Protocol Negotiation extension, if available in the underlying OpenSSL library.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75043
diff
changeset
|
2022 self); |
|
2514a4e2b3ce
Issue #14204: The ssl module now has support for the Next Protocol Negotiation extension, if available in the underlying OpenSSL library.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75043
diff
changeset
|
2023 |
|
2514a4e2b3ce
Issue #14204: The ssl module now has support for the Next Protocol Negotiation extension, if available in the underlying OpenSSL library.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75043
diff
changeset
|
2024 PyBuffer_Release(&protos); |
|
2514a4e2b3ce
Issue #14204: The ssl module now has support for the Next Protocol Negotiation extension, if available in the underlying OpenSSL library.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75043
diff
changeset
|
2025 Py_RETURN_NONE; |
|
2514a4e2b3ce
Issue #14204: The ssl module now has support for the Next Protocol Negotiation extension, if available in the underlying OpenSSL library.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75043
diff
changeset
|
2026 #else |
|
2514a4e2b3ce
Issue #14204: The ssl module now has support for the Next Protocol Negotiation extension, if available in the underlying OpenSSL library.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75043
diff
changeset
|
2027 PyErr_SetString(PyExc_NotImplementedError, |
|
2514a4e2b3ce
Issue #14204: The ssl module now has support for the Next Protocol Negotiation extension, if available in the underlying OpenSSL library.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75043
diff
changeset
|
2028 "The NPN extension requires OpenSSL 1.0.1 or later."); |
|
2514a4e2b3ce
Issue #14204: The ssl module now has support for the Next Protocol Negotiation extension, if available in the underlying OpenSSL library.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75043
diff
changeset
|
2029 return NULL; |
|
2514a4e2b3ce
Issue #14204: The ssl module now has support for the Next Protocol Negotiation extension, if available in the underlying OpenSSL library.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75043
diff
changeset
|
2030 #endif |
|
2514a4e2b3ce
Issue #14204: The ssl module now has support for the Next Protocol Negotiation extension, if available in the underlying OpenSSL library.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75043
diff
changeset
|
2031 } |
|
2514a4e2b3ce
Issue #14204: The ssl module now has support for the Next Protocol Negotiation extension, if available in the underlying OpenSSL library.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75043
diff
changeset
|
2032 |
|
61635
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2033 static PyObject * |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2034 get_verify_mode(PySSLContext *self, void *c) |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2035 { |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2036 switch (SSL_CTX_get_verify_mode(self->ctx)) { |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2037 case SSL_VERIFY_NONE: |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2038 return PyLong_FromLong(PY_SSL_CERT_NONE); |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2039 case SSL_VERIFY_PEER: |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2040 return PyLong_FromLong(PY_SSL_CERT_OPTIONAL); |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2041 case SSL_VERIFY_PEER | SSL_VERIFY_FAIL_IF_NO_PEER_CERT: |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2042 return PyLong_FromLong(PY_SSL_CERT_REQUIRED); |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2043 } |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2044 PyErr_SetString(PySSLErrorObject, |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2045 "invalid return value from SSL_CTX_get_verify_mode"); |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2046 return NULL; |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2047 } |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2048 |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2049 static int |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2050 set_verify_mode(PySSLContext *self, PyObject *arg, void *c) |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2051 { |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2052 int n, mode; |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2053 if (!PyArg_Parse(arg, "i", &n)) |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2054 return -1; |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2055 if (n == PY_SSL_CERT_NONE) |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2056 mode = SSL_VERIFY_NONE; |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2057 else if (n == PY_SSL_CERT_OPTIONAL) |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2058 mode = SSL_VERIFY_PEER; |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2059 else if (n == PY_SSL_CERT_REQUIRED) |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2060 mode = SSL_VERIFY_PEER | SSL_VERIFY_FAIL_IF_NO_PEER_CERT; |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2061 else { |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2062 PyErr_SetString(PyExc_ValueError, |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2063 "invalid value for verify_mode"); |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2064 return -1; |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2065 } |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2066 SSL_CTX_set_verify(self->ctx, mode, NULL); |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2067 return 0; |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2068 } |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2069 |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2070 static PyObject * |
|
61782
5ee47f0b26b0
Issue #4870: Add an `options` attribute to SSL contexts, as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
61644
diff
changeset
|
2071 get_options(PySSLContext *self, void *c) |
|
5ee47f0b26b0
Issue #4870: Add an `options` attribute to SSL contexts, as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
61644
diff
changeset
|
2072 { |
|
5ee47f0b26b0
Issue #4870: Add an `options` attribute to SSL contexts, as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
61644
diff
changeset
|
2073 return PyLong_FromLong(SSL_CTX_get_options(self->ctx)); |
|
5ee47f0b26b0
Issue #4870: Add an `options` attribute to SSL contexts, as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
61644
diff
changeset
|
2074 } |
|
5ee47f0b26b0
Issue #4870: Add an `options` attribute to SSL contexts, as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
61644
diff
changeset
|
2075 |
|
5ee47f0b26b0
Issue #4870: Add an `options` attribute to SSL contexts, as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
61644
diff
changeset
|
2076 static int |
|
5ee47f0b26b0
Issue #4870: Add an `options` attribute to SSL contexts, as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
61644
diff
changeset
|
2077 set_options(PySSLContext *self, PyObject *arg, void *c) |
|
5ee47f0b26b0
Issue #4870: Add an `options` attribute to SSL contexts, as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
61644
diff
changeset
|
2078 { |
|
5ee47f0b26b0
Issue #4870: Add an `options` attribute to SSL contexts, as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
61644
diff
changeset
|
2079 long new_opts, opts, set, clear; |
|
5ee47f0b26b0
Issue #4870: Add an `options` attribute to SSL contexts, as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
61644
diff
changeset
|
2080 if (!PyArg_Parse(arg, "l", &new_opts)) |
|
5ee47f0b26b0
Issue #4870: Add an `options` attribute to SSL contexts, as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
61644
diff
changeset
|
2081 return -1; |
|
5ee47f0b26b0
Issue #4870: Add an `options` attribute to SSL contexts, as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
61644
diff
changeset
|
2082 opts = SSL_CTX_get_options(self->ctx); |
|
5ee47f0b26b0
Issue #4870: Add an `options` attribute to SSL contexts, as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
61644
diff
changeset
|
2083 clear = opts & ~new_opts; |
|
5ee47f0b26b0
Issue #4870: Add an `options` attribute to SSL contexts, as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
61644
diff
changeset
|
2084 set = ~opts & new_opts; |
|
5ee47f0b26b0
Issue #4870: Add an `options` attribute to SSL contexts, as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
61644
diff
changeset
|
2085 if (clear) { |
|
5ee47f0b26b0
Issue #4870: Add an `options` attribute to SSL contexts, as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
61644
diff
changeset
|
2086 #ifdef HAVE_SSL_CTX_CLEAR_OPTIONS |
|
5ee47f0b26b0
Issue #4870: Add an `options` attribute to SSL contexts, as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
61644
diff
changeset
|
2087 SSL_CTX_clear_options(self->ctx, clear); |
|
5ee47f0b26b0
Issue #4870: Add an `options` attribute to SSL contexts, as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
61644
diff
changeset
|
2088 #else |
|
5ee47f0b26b0
Issue #4870: Add an `options` attribute to SSL contexts, as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
61644
diff
changeset
|
2089 PyErr_SetString(PyExc_ValueError, |
|
5ee47f0b26b0
Issue #4870: Add an `options` attribute to SSL contexts, as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
61644
diff
changeset
|
2090 "can't clear options before OpenSSL 0.9.8m"); |
|
5ee47f0b26b0
Issue #4870: Add an `options` attribute to SSL contexts, as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
61644
diff
changeset
|
2091 return -1; |
|
5ee47f0b26b0
Issue #4870: Add an `options` attribute to SSL contexts, as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
61644
diff
changeset
|
2092 #endif |
|
5ee47f0b26b0
Issue #4870: Add an `options` attribute to SSL contexts, as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
61644
diff
changeset
|
2093 } |
|
5ee47f0b26b0
Issue #4870: Add an `options` attribute to SSL contexts, as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
61644
diff
changeset
|
2094 if (set) |
|
5ee47f0b26b0
Issue #4870: Add an `options` attribute to SSL contexts, as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
61644
diff
changeset
|
2095 SSL_CTX_set_options(self->ctx, set); |
|
5ee47f0b26b0
Issue #4870: Add an `options` attribute to SSL contexts, as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
61644
diff
changeset
|
2096 return 0; |
|
5ee47f0b26b0
Issue #4870: Add an `options` attribute to SSL contexts, as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
61644
diff
changeset
|
2097 } |
|
5ee47f0b26b0
Issue #4870: Add an `options` attribute to SSL contexts, as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
61644
diff
changeset
|
2098 |
|
72071
cdc6c1b072a5
Issue #12803: SSLContext.load_cert_chain() now accepts a password argument
Antoine Pitrou <solipsis@pitrou.net>
parents:
71440
diff
changeset
|
2099 typedef struct { |
|
cdc6c1b072a5
Issue #12803: SSLContext.load_cert_chain() now accepts a password argument
Antoine Pitrou <solipsis@pitrou.net>
parents:
71440
diff
changeset
|
2100 PyThreadState *thread_state; |
|
cdc6c1b072a5
Issue #12803: SSLContext.load_cert_chain() now accepts a password argument
Antoine Pitrou <solipsis@pitrou.net>
parents:
71440
diff
changeset
|
2101 PyObject *callable; |
|
cdc6c1b072a5
Issue #12803: SSLContext.load_cert_chain() now accepts a password argument
Antoine Pitrou <solipsis@pitrou.net>
parents:
71440
diff
changeset
|
2102 char *password; |
|
84270
f0d934732ab1
Issue #18135: Fix a possible integer overflow in ssl.SSLSocket.write()
Victor Stinner <victor.stinner@gmail.com>
parents:
84269
diff
changeset
|
2103 int size; |
|
72071
cdc6c1b072a5
Issue #12803: SSLContext.load_cert_chain() now accepts a password argument
Antoine Pitrou <solipsis@pitrou.net>
parents:
71440
diff
changeset
|
2104 int error; |
|
cdc6c1b072a5
Issue #12803: SSLContext.load_cert_chain() now accepts a password argument
Antoine Pitrou <solipsis@pitrou.net>
parents:
71440
diff
changeset
|
2105 } _PySSLPasswordInfo; |
|
cdc6c1b072a5
Issue #12803: SSLContext.load_cert_chain() now accepts a password argument
Antoine Pitrou <solipsis@pitrou.net>
parents:
71440
diff
changeset
|
2106 |
|
cdc6c1b072a5
Issue #12803: SSLContext.load_cert_chain() now accepts a password argument
Antoine Pitrou <solipsis@pitrou.net>
parents:
71440
diff
changeset
|
2107 static int |
|
cdc6c1b072a5
Issue #12803: SSLContext.load_cert_chain() now accepts a password argument
Antoine Pitrou <solipsis@pitrou.net>
parents:
71440
diff
changeset
|
2108 _pwinfo_set(_PySSLPasswordInfo *pw_info, PyObject* password, |
|
cdc6c1b072a5
Issue #12803: SSLContext.load_cert_chain() now accepts a password argument
Antoine Pitrou <solipsis@pitrou.net>
parents:
71440
diff
changeset
|
2109 const char *bad_type_error) |
|
cdc6c1b072a5
Issue #12803: SSLContext.load_cert_chain() now accepts a password argument
Antoine Pitrou <solipsis@pitrou.net>
parents:
71440
diff
changeset
|
2110 { |
|
cdc6c1b072a5
Issue #12803: SSLContext.load_cert_chain() now accepts a password argument
Antoine Pitrou <solipsis@pitrou.net>
parents:
71440
diff
changeset
|
2111 /* Set the password and size fields of a _PySSLPasswordInfo struct |
|
cdc6c1b072a5
Issue #12803: SSLContext.load_cert_chain() now accepts a password argument
Antoine Pitrou <solipsis@pitrou.net>
parents:
71440
diff
changeset
|
2112 from a unicode, bytes, or byte array object. |
|
cdc6c1b072a5
Issue #12803: SSLContext.load_cert_chain() now accepts a password argument
Antoine Pitrou <solipsis@pitrou.net>
parents:
71440
diff
changeset
|
2113 The password field will be dynamically allocated and must be freed |
|
cdc6c1b072a5
Issue #12803: SSLContext.load_cert_chain() now accepts a password argument
Antoine Pitrou <solipsis@pitrou.net>
parents:
71440
diff
changeset
|
2114 by the caller */ |
|
cdc6c1b072a5
Issue #12803: SSLContext.load_cert_chain() now accepts a password argument
Antoine Pitrou <solipsis@pitrou.net>
parents:
71440
diff
changeset
|
2115 PyObject *password_bytes = NULL; |
|
cdc6c1b072a5
Issue #12803: SSLContext.load_cert_chain() now accepts a password argument
Antoine Pitrou <solipsis@pitrou.net>
parents:
71440
diff
changeset
|
2116 const char *data = NULL; |
|
cdc6c1b072a5
Issue #12803: SSLContext.load_cert_chain() now accepts a password argument
Antoine Pitrou <solipsis@pitrou.net>
parents:
71440
diff
changeset
|
2117 Py_ssize_t size; |
|
cdc6c1b072a5
Issue #12803: SSLContext.load_cert_chain() now accepts a password argument
Antoine Pitrou <solipsis@pitrou.net>
parents:
71440
diff
changeset
|
2118 |
|
cdc6c1b072a5
Issue #12803: SSLContext.load_cert_chain() now accepts a password argument
Antoine Pitrou <solipsis@pitrou.net>
parents:
71440
diff
changeset
|
2119 if (PyUnicode_Check(password)) { |
|
cdc6c1b072a5
Issue #12803: SSLContext.load_cert_chain() now accepts a password argument
Antoine Pitrou <solipsis@pitrou.net>
parents:
71440
diff
changeset
|
2120 password_bytes = PyUnicode_AsEncodedString(password, NULL, NULL); |
|
cdc6c1b072a5
Issue #12803: SSLContext.load_cert_chain() now accepts a password argument
Antoine Pitrou <solipsis@pitrou.net>
parents:
71440
diff
changeset
|
2121 if (!password_bytes) { |
|
cdc6c1b072a5
Issue #12803: SSLContext.load_cert_chain() now accepts a password argument
Antoine Pitrou <solipsis@pitrou.net>
parents:
71440
diff
changeset
|
2122 goto error; |
|
cdc6c1b072a5
Issue #12803: SSLContext.load_cert_chain() now accepts a password argument
Antoine Pitrou <solipsis@pitrou.net>
parents:
71440
diff
changeset
|
2123 } |
|
cdc6c1b072a5
Issue #12803: SSLContext.load_cert_chain() now accepts a password argument
Antoine Pitrou <solipsis@pitrou.net>
parents:
71440
diff
changeset
|
2124 data = PyBytes_AS_STRING(password_bytes); |
|
cdc6c1b072a5
Issue #12803: SSLContext.load_cert_chain() now accepts a password argument
Antoine Pitrou <solipsis@pitrou.net>
parents:
71440
diff
changeset
|
2125 size = PyBytes_GET_SIZE(password_bytes); |
|
cdc6c1b072a5
Issue #12803: SSLContext.load_cert_chain() now accepts a password argument
Antoine Pitrou <solipsis@pitrou.net>
parents:
71440
diff
changeset
|
2126 } else if (PyBytes_Check(password)) { |
|
cdc6c1b072a5
Issue #12803: SSLContext.load_cert_chain() now accepts a password argument
Antoine Pitrou <solipsis@pitrou.net>
parents:
71440
diff
changeset
|
2127 data = PyBytes_AS_STRING(password); |
|
cdc6c1b072a5
Issue #12803: SSLContext.load_cert_chain() now accepts a password argument
Antoine Pitrou <solipsis@pitrou.net>
parents:
71440
diff
changeset
|
2128 size = PyBytes_GET_SIZE(password); |
|
cdc6c1b072a5
Issue #12803: SSLContext.load_cert_chain() now accepts a password argument
Antoine Pitrou <solipsis@pitrou.net>
parents:
71440
diff
changeset
|
2129 } else if (PyByteArray_Check(password)) { |
|
cdc6c1b072a5
Issue #12803: SSLContext.load_cert_chain() now accepts a password argument
Antoine Pitrou <solipsis@pitrou.net>
parents:
71440
diff
changeset
|
2130 data = PyByteArray_AS_STRING(password); |
|
cdc6c1b072a5
Issue #12803: SSLContext.load_cert_chain() now accepts a password argument
Antoine Pitrou <solipsis@pitrou.net>
parents:
71440
diff
changeset
|
2131 size = PyByteArray_GET_SIZE(password); |
|
cdc6c1b072a5
Issue #12803: SSLContext.load_cert_chain() now accepts a password argument
Antoine Pitrou <solipsis@pitrou.net>
parents:
71440
diff
changeset
|
2132 } else { |
|
cdc6c1b072a5
Issue #12803: SSLContext.load_cert_chain() now accepts a password argument
Antoine Pitrou <solipsis@pitrou.net>
parents:
71440
diff
changeset
|
2133 PyErr_SetString(PyExc_TypeError, bad_type_error); |
|
cdc6c1b072a5
Issue #12803: SSLContext.load_cert_chain() now accepts a password argument
Antoine Pitrou <solipsis@pitrou.net>
parents:
71440
diff
changeset
|
2134 goto error; |
|
cdc6c1b072a5
Issue #12803: SSLContext.load_cert_chain() now accepts a password argument
Antoine Pitrou <solipsis@pitrou.net>
parents:
71440
diff
changeset
|
2135 } |
|
cdc6c1b072a5
Issue #12803: SSLContext.load_cert_chain() now accepts a password argument
Antoine Pitrou <solipsis@pitrou.net>
parents:
71440
diff
changeset
|
2136 |
|
84270
f0d934732ab1
Issue #18135: Fix a possible integer overflow in ssl.SSLSocket.write()
Victor Stinner <victor.stinner@gmail.com>
parents:
84269
diff
changeset
|
2137 if (size > (Py_ssize_t)INT_MAX) { |
|
f0d934732ab1
Issue #18135: Fix a possible integer overflow in ssl.SSLSocket.write()
Victor Stinner <victor.stinner@gmail.com>
parents:
84269
diff
changeset
|
2138 PyErr_Format(PyExc_ValueError, |
|
f0d934732ab1
Issue #18135: Fix a possible integer overflow in ssl.SSLSocket.write()
Victor Stinner <victor.stinner@gmail.com>
parents:
84269
diff
changeset
|
2139 "password cannot be longer than %d bytes", INT_MAX); |
|
f0d934732ab1
Issue #18135: Fix a possible integer overflow in ssl.SSLSocket.write()
Victor Stinner <victor.stinner@gmail.com>
parents:
84269
diff
changeset
|
2140 goto error; |
|
f0d934732ab1
Issue #18135: Fix a possible integer overflow in ssl.SSLSocket.write()
Victor Stinner <victor.stinner@gmail.com>
parents:
84269
diff
changeset
|
2141 } |
|
f0d934732ab1
Issue #18135: Fix a possible integer overflow in ssl.SSLSocket.write()
Victor Stinner <victor.stinner@gmail.com>
parents:
84269
diff
changeset
|
2142 |
|
84495
638d43665356
Issue #18203: Replace malloc() with PyMem_Malloc() in _ssl for the password
Victor Stinner <victor.stinner@gmail.com>
parents:
84491
diff
changeset
|
2143 PyMem_Free(pw_info->password); |
|
638d43665356
Issue #18203: Replace malloc() with PyMem_Malloc() in _ssl for the password
Victor Stinner <victor.stinner@gmail.com>
parents:
84491
diff
changeset
|
2144 pw_info->password = PyMem_Malloc(size); |
|
72071
cdc6c1b072a5
Issue #12803: SSLContext.load_cert_chain() now accepts a password argument
Antoine Pitrou <solipsis@pitrou.net>
parents:
71440
diff
changeset
|
2145 if (!pw_info->password) { |
|
cdc6c1b072a5
Issue #12803: SSLContext.load_cert_chain() now accepts a password argument
Antoine Pitrou <solipsis@pitrou.net>
parents:
71440
diff
changeset
|
2146 PyErr_SetString(PyExc_MemoryError, |
|
cdc6c1b072a5
Issue #12803: SSLContext.load_cert_chain() now accepts a password argument
Antoine Pitrou <solipsis@pitrou.net>
parents:
71440
diff
changeset
|
2147 "unable to allocate password buffer"); |
|
cdc6c1b072a5
Issue #12803: SSLContext.load_cert_chain() now accepts a password argument
Antoine Pitrou <solipsis@pitrou.net>
parents:
71440
diff
changeset
|
2148 goto error; |
|
cdc6c1b072a5
Issue #12803: SSLContext.load_cert_chain() now accepts a password argument
Antoine Pitrou <solipsis@pitrou.net>
parents:
71440
diff
changeset
|
2149 } |
|
cdc6c1b072a5
Issue #12803: SSLContext.load_cert_chain() now accepts a password argument
Antoine Pitrou <solipsis@pitrou.net>
parents:
71440
diff
changeset
|
2150 memcpy(pw_info->password, data, size); |
|
84270
f0d934732ab1
Issue #18135: Fix a possible integer overflow in ssl.SSLSocket.write()
Victor Stinner <victor.stinner@gmail.com>
parents:
84269
diff
changeset
|
2151 pw_info->size = (int)size; |
|
72071
cdc6c1b072a5
Issue #12803: SSLContext.load_cert_chain() now accepts a password argument
Antoine Pitrou <solipsis@pitrou.net>
parents:
71440
diff
changeset
|
2152 |
|
cdc6c1b072a5
Issue #12803: SSLContext.load_cert_chain() now accepts a password argument
Antoine Pitrou <solipsis@pitrou.net>
parents:
71440
diff
changeset
|
2153 Py_XDECREF(password_bytes); |
|
cdc6c1b072a5
Issue #12803: SSLContext.load_cert_chain() now accepts a password argument
Antoine Pitrou <solipsis@pitrou.net>
parents:
71440
diff
changeset
|
2154 return 1; |
|
cdc6c1b072a5
Issue #12803: SSLContext.load_cert_chain() now accepts a password argument
Antoine Pitrou <solipsis@pitrou.net>
parents:
71440
diff
changeset
|
2155 |
|
cdc6c1b072a5
Issue #12803: SSLContext.load_cert_chain() now accepts a password argument
Antoine Pitrou <solipsis@pitrou.net>
parents:
71440
diff
changeset
|
2156 error: |
|
cdc6c1b072a5
Issue #12803: SSLContext.load_cert_chain() now accepts a password argument
Antoine Pitrou <solipsis@pitrou.net>
parents:
71440
diff
changeset
|
2157 Py_XDECREF(password_bytes); |
|
cdc6c1b072a5
Issue #12803: SSLContext.load_cert_chain() now accepts a password argument
Antoine Pitrou <solipsis@pitrou.net>
parents:
71440
diff
changeset
|
2158 return 0; |
|
cdc6c1b072a5
Issue #12803: SSLContext.load_cert_chain() now accepts a password argument
Antoine Pitrou <solipsis@pitrou.net>
parents:
71440
diff
changeset
|
2159 } |
|
cdc6c1b072a5
Issue #12803: SSLContext.load_cert_chain() now accepts a password argument
Antoine Pitrou <solipsis@pitrou.net>
parents:
71440
diff
changeset
|
2160 |
|
cdc6c1b072a5
Issue #12803: SSLContext.load_cert_chain() now accepts a password argument
Antoine Pitrou <solipsis@pitrou.net>
parents:
71440
diff
changeset
|
2161 static int |
|
cdc6c1b072a5
Issue #12803: SSLContext.load_cert_chain() now accepts a password argument
Antoine Pitrou <solipsis@pitrou.net>
parents:
71440
diff
changeset
|
2162 _password_callback(char *buf, int size, int rwflag, void *userdata) |
|
cdc6c1b072a5
Issue #12803: SSLContext.load_cert_chain() now accepts a password argument
Antoine Pitrou <solipsis@pitrou.net>
parents:
71440
diff
changeset
|
2163 { |
|
cdc6c1b072a5
Issue #12803: SSLContext.load_cert_chain() now accepts a password argument
Antoine Pitrou <solipsis@pitrou.net>
parents:
71440
diff
changeset
|
2164 _PySSLPasswordInfo *pw_info = (_PySSLPasswordInfo*) userdata; |
|
cdc6c1b072a5
Issue #12803: SSLContext.load_cert_chain() now accepts a password argument
Antoine Pitrou <solipsis@pitrou.net>
parents:
71440
diff
changeset
|
2165 PyObject *fn_ret = NULL; |
|
cdc6c1b072a5
Issue #12803: SSLContext.load_cert_chain() now accepts a password argument
Antoine Pitrou <solipsis@pitrou.net>
parents:
71440
diff
changeset
|
2166 |
|
cdc6c1b072a5
Issue #12803: SSLContext.load_cert_chain() now accepts a password argument
Antoine Pitrou <solipsis@pitrou.net>
parents:
71440
diff
changeset
|
2167 PySSL_END_ALLOW_THREADS_S(pw_info->thread_state); |
|
cdc6c1b072a5
Issue #12803: SSLContext.load_cert_chain() now accepts a password argument
Antoine Pitrou <solipsis@pitrou.net>
parents:
71440
diff
changeset
|
2168 |
|
cdc6c1b072a5
Issue #12803: SSLContext.load_cert_chain() now accepts a password argument
Antoine Pitrou <solipsis@pitrou.net>
parents:
71440
diff
changeset
|
2169 if (pw_info->callable) { |
|
cdc6c1b072a5
Issue #12803: SSLContext.load_cert_chain() now accepts a password argument
Antoine Pitrou <solipsis@pitrou.net>
parents:
71440
diff
changeset
|
2170 fn_ret = PyObject_CallFunctionObjArgs(pw_info->callable, NULL); |
|
cdc6c1b072a5
Issue #12803: SSLContext.load_cert_chain() now accepts a password argument
Antoine Pitrou <solipsis@pitrou.net>
parents:
71440
diff
changeset
|
2171 if (!fn_ret) { |
|
cdc6c1b072a5
Issue #12803: SSLContext.load_cert_chain() now accepts a password argument
Antoine Pitrou <solipsis@pitrou.net>
parents:
71440
diff
changeset
|
2172 /* TODO: It would be nice to move _ctypes_add_traceback() into the |
|
cdc6c1b072a5
Issue #12803: SSLContext.load_cert_chain() now accepts a password argument
Antoine Pitrou <solipsis@pitrou.net>
parents:
71440
diff
changeset
|
2173 core python API, so we could use it to add a frame here */ |
|
cdc6c1b072a5
Issue #12803: SSLContext.load_cert_chain() now accepts a password argument
Antoine Pitrou <solipsis@pitrou.net>
parents:
71440
diff
changeset
|
2174 goto error; |
|
cdc6c1b072a5
Issue #12803: SSLContext.load_cert_chain() now accepts a password argument
Antoine Pitrou <solipsis@pitrou.net>
parents:
71440
diff
changeset
|
2175 } |
|
cdc6c1b072a5
Issue #12803: SSLContext.load_cert_chain() now accepts a password argument
Antoine Pitrou <solipsis@pitrou.net>
parents:
71440
diff
changeset
|
2176 |
|
cdc6c1b072a5
Issue #12803: SSLContext.load_cert_chain() now accepts a password argument
Antoine Pitrou <solipsis@pitrou.net>
parents:
71440
diff
changeset
|
2177 if (!_pwinfo_set(pw_info, fn_ret, |
|
cdc6c1b072a5
Issue #12803: SSLContext.load_cert_chain() now accepts a password argument
Antoine Pitrou <solipsis@pitrou.net>
parents:
71440
diff
changeset
|
2178 "password callback must return a string")) { |
|
cdc6c1b072a5
Issue #12803: SSLContext.load_cert_chain() now accepts a password argument
Antoine Pitrou <solipsis@pitrou.net>
parents:
71440
diff
changeset
|
2179 goto error; |
|
cdc6c1b072a5
Issue #12803: SSLContext.load_cert_chain() now accepts a password argument
Antoine Pitrou <solipsis@pitrou.net>
parents:
71440
diff
changeset
|
2180 } |
|
cdc6c1b072a5
Issue #12803: SSLContext.load_cert_chain() now accepts a password argument
Antoine Pitrou <solipsis@pitrou.net>
parents:
71440
diff
changeset
|
2181 Py_CLEAR(fn_ret); |
|
cdc6c1b072a5
Issue #12803: SSLContext.load_cert_chain() now accepts a password argument
Antoine Pitrou <solipsis@pitrou.net>
parents:
71440
diff
changeset
|
2182 } |
|
cdc6c1b072a5
Issue #12803: SSLContext.load_cert_chain() now accepts a password argument
Antoine Pitrou <solipsis@pitrou.net>
parents:
71440
diff
changeset
|
2183 |
|
cdc6c1b072a5
Issue #12803: SSLContext.load_cert_chain() now accepts a password argument
Antoine Pitrou <solipsis@pitrou.net>
parents:
71440
diff
changeset
|
2184 if (pw_info->size > size) { |
|
cdc6c1b072a5
Issue #12803: SSLContext.load_cert_chain() now accepts a password argument
Antoine Pitrou <solipsis@pitrou.net>
parents:
71440
diff
changeset
|
2185 PyErr_Format(PyExc_ValueError, |
|
cdc6c1b072a5
Issue #12803: SSLContext.load_cert_chain() now accepts a password argument
Antoine Pitrou <solipsis@pitrou.net>
parents:
71440
diff
changeset
|
2186 "password cannot be longer than %d bytes", size); |
|
cdc6c1b072a5
Issue #12803: SSLContext.load_cert_chain() now accepts a password argument
Antoine Pitrou <solipsis@pitrou.net>
parents:
71440
diff
changeset
|
2187 goto error; |
|
cdc6c1b072a5
Issue #12803: SSLContext.load_cert_chain() now accepts a password argument
Antoine Pitrou <solipsis@pitrou.net>
parents:
71440
diff
changeset
|
2188 } |
|
cdc6c1b072a5
Issue #12803: SSLContext.load_cert_chain() now accepts a password argument
Antoine Pitrou <solipsis@pitrou.net>
parents:
71440
diff
changeset
|
2189 |
|
cdc6c1b072a5
Issue #12803: SSLContext.load_cert_chain() now accepts a password argument
Antoine Pitrou <solipsis@pitrou.net>
parents:
71440
diff
changeset
|
2190 PySSL_BEGIN_ALLOW_THREADS_S(pw_info->thread_state); |
|
cdc6c1b072a5
Issue #12803: SSLContext.load_cert_chain() now accepts a password argument
Antoine Pitrou <solipsis@pitrou.net>
parents:
71440
diff
changeset
|
2191 memcpy(buf, pw_info->password, pw_info->size); |
|
cdc6c1b072a5
Issue #12803: SSLContext.load_cert_chain() now accepts a password argument
Antoine Pitrou <solipsis@pitrou.net>
parents:
71440
diff
changeset
|
2192 return pw_info->size; |
|
cdc6c1b072a5
Issue #12803: SSLContext.load_cert_chain() now accepts a password argument
Antoine Pitrou <solipsis@pitrou.net>
parents:
71440
diff
changeset
|
2193 |
|
cdc6c1b072a5
Issue #12803: SSLContext.load_cert_chain() now accepts a password argument
Antoine Pitrou <solipsis@pitrou.net>
parents:
71440
diff
changeset
|
2194 error: |
|
cdc6c1b072a5
Issue #12803: SSLContext.load_cert_chain() now accepts a password argument
Antoine Pitrou <solipsis@pitrou.net>
parents:
71440
diff
changeset
|
2195 Py_XDECREF(fn_ret); |
|
cdc6c1b072a5
Issue #12803: SSLContext.load_cert_chain() now accepts a password argument
Antoine Pitrou <solipsis@pitrou.net>
parents:
71440
diff
changeset
|
2196 PySSL_BEGIN_ALLOW_THREADS_S(pw_info->thread_state); |
|
cdc6c1b072a5
Issue #12803: SSLContext.load_cert_chain() now accepts a password argument
Antoine Pitrou <solipsis@pitrou.net>
parents:
71440
diff
changeset
|
2197 pw_info->error = 1; |
|
cdc6c1b072a5
Issue #12803: SSLContext.load_cert_chain() now accepts a password argument
Antoine Pitrou <solipsis@pitrou.net>
parents:
71440
diff
changeset
|
2198 return -1; |
|
cdc6c1b072a5
Issue #12803: SSLContext.load_cert_chain() now accepts a password argument
Antoine Pitrou <solipsis@pitrou.net>
parents:
71440
diff
changeset
|
2199 } |
|
cdc6c1b072a5
Issue #12803: SSLContext.load_cert_chain() now accepts a password argument
Antoine Pitrou <solipsis@pitrou.net>
parents:
71440
diff
changeset
|
2200 |
|
61782
5ee47f0b26b0
Issue #4870: Add an `options` attribute to SSL contexts, as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
61644
diff
changeset
|
2201 static PyObject * |
|
61635
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2202 load_cert_chain(PySSLContext *self, PyObject *args, PyObject *kwds) |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2203 { |
|
72071
cdc6c1b072a5
Issue #12803: SSLContext.load_cert_chain() now accepts a password argument
Antoine Pitrou <solipsis@pitrou.net>
parents:
71440
diff
changeset
|
2204 char *kwlist[] = {"certfile", "keyfile", "password", NULL}; |
|
cdc6c1b072a5
Issue #12803: SSLContext.load_cert_chain() now accepts a password argument
Antoine Pitrou <solipsis@pitrou.net>
parents:
71440
diff
changeset
|
2205 PyObject *certfile, *keyfile = NULL, *password = NULL; |
|
61635
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2206 PyObject *certfile_bytes = NULL, *keyfile_bytes = NULL; |
|
72071
cdc6c1b072a5
Issue #12803: SSLContext.load_cert_chain() now accepts a password argument
Antoine Pitrou <solipsis@pitrou.net>
parents:
71440
diff
changeset
|
2207 pem_password_cb *orig_passwd_cb = self->ctx->default_passwd_callback; |
|
cdc6c1b072a5
Issue #12803: SSLContext.load_cert_chain() now accepts a password argument
Antoine Pitrou <solipsis@pitrou.net>
parents:
71440
diff
changeset
|
2208 void *orig_passwd_userdata = self->ctx->default_passwd_callback_userdata; |
|
cdc6c1b072a5
Issue #12803: SSLContext.load_cert_chain() now accepts a password argument
Antoine Pitrou <solipsis@pitrou.net>
parents:
71440
diff
changeset
|
2209 _PySSLPasswordInfo pw_info = { NULL, NULL, NULL, 0, 0 }; |
|
61635
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2210 int r; |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2211 |
|
64306
9297974604ff
Fix issue issue9706: provides a better error handling for various SSL operations
Giampaolo Rodolà <g.rodola@gmail.com>
parents:
63692
diff
changeset
|
2212 errno = 0; |
|
64358
063b554d3153
Try to fix some buildbot failures on test_ssl
Antoine Pitrou <solipsis@pitrou.net>
parents:
64352
diff
changeset
|
2213 ERR_clear_error(); |
|
61635
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2214 if (!PyArg_ParseTupleAndKeywords(args, kwds, |
|
72071
cdc6c1b072a5
Issue #12803: SSLContext.load_cert_chain() now accepts a password argument
Antoine Pitrou <solipsis@pitrou.net>
parents:
71440
diff
changeset
|
2215 "O|OO:load_cert_chain", kwlist, |
|
cdc6c1b072a5
Issue #12803: SSLContext.load_cert_chain() now accepts a password argument
Antoine Pitrou <solipsis@pitrou.net>
parents:
71440
diff
changeset
|
2216 &certfile, &keyfile, &password)) |
|
61635
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2217 return NULL; |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2218 if (keyfile == Py_None) |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2219 keyfile = NULL; |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2220 if (!PyUnicode_FSConverter(certfile, &certfile_bytes)) { |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2221 PyErr_SetString(PyExc_TypeError, |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2222 "certfile should be a valid filesystem path"); |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2223 return NULL; |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2224 } |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2225 if (keyfile && !PyUnicode_FSConverter(keyfile, &keyfile_bytes)) { |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2226 PyErr_SetString(PyExc_TypeError, |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2227 "keyfile should be a valid filesystem path"); |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2228 goto error; |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2229 } |
|
72071
cdc6c1b072a5
Issue #12803: SSLContext.load_cert_chain() now accepts a password argument
Antoine Pitrou <solipsis@pitrou.net>
parents:
71440
diff
changeset
|
2230 if (password && password != Py_None) { |
|
cdc6c1b072a5
Issue #12803: SSLContext.load_cert_chain() now accepts a password argument
Antoine Pitrou <solipsis@pitrou.net>
parents:
71440
diff
changeset
|
2231 if (PyCallable_Check(password)) { |
|
cdc6c1b072a5
Issue #12803: SSLContext.load_cert_chain() now accepts a password argument
Antoine Pitrou <solipsis@pitrou.net>
parents:
71440
diff
changeset
|
2232 pw_info.callable = password; |
|
cdc6c1b072a5
Issue #12803: SSLContext.load_cert_chain() now accepts a password argument
Antoine Pitrou <solipsis@pitrou.net>
parents:
71440
diff
changeset
|
2233 } else if (!_pwinfo_set(&pw_info, password, |
|
cdc6c1b072a5
Issue #12803: SSLContext.load_cert_chain() now accepts a password argument
Antoine Pitrou <solipsis@pitrou.net>
parents:
71440
diff
changeset
|
2234 "password should be a string or callable")) { |
|
cdc6c1b072a5
Issue #12803: SSLContext.load_cert_chain() now accepts a password argument
Antoine Pitrou <solipsis@pitrou.net>
parents:
71440
diff
changeset
|
2235 goto error; |
|
cdc6c1b072a5
Issue #12803: SSLContext.load_cert_chain() now accepts a password argument
Antoine Pitrou <solipsis@pitrou.net>
parents:
71440
diff
changeset
|
2236 } |
|
cdc6c1b072a5
Issue #12803: SSLContext.load_cert_chain() now accepts a password argument
Antoine Pitrou <solipsis@pitrou.net>
parents:
71440
diff
changeset
|
2237 SSL_CTX_set_default_passwd_cb(self->ctx, _password_callback); |
|
cdc6c1b072a5
Issue #12803: SSLContext.load_cert_chain() now accepts a password argument
Antoine Pitrou <solipsis@pitrou.net>
parents:
71440
diff
changeset
|
2238 SSL_CTX_set_default_passwd_cb_userdata(self->ctx, &pw_info); |
|
cdc6c1b072a5
Issue #12803: SSLContext.load_cert_chain() now accepts a password argument
Antoine Pitrou <solipsis@pitrou.net>
parents:
71440
diff
changeset
|
2239 } |
|
cdc6c1b072a5
Issue #12803: SSLContext.load_cert_chain() now accepts a password argument
Antoine Pitrou <solipsis@pitrou.net>
parents:
71440
diff
changeset
|
2240 PySSL_BEGIN_ALLOW_THREADS_S(pw_info.thread_state); |
|
61635
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2241 r = SSL_CTX_use_certificate_chain_file(self->ctx, |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2242 PyBytes_AS_STRING(certfile_bytes)); |
|
72071
cdc6c1b072a5
Issue #12803: SSLContext.load_cert_chain() now accepts a password argument
Antoine Pitrou <solipsis@pitrou.net>
parents:
71440
diff
changeset
|
2243 PySSL_END_ALLOW_THREADS_S(pw_info.thread_state); |
|
61635
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2244 if (r != 1) { |
|
72071
cdc6c1b072a5
Issue #12803: SSLContext.load_cert_chain() now accepts a password argument
Antoine Pitrou <solipsis@pitrou.net>
parents:
71440
diff
changeset
|
2245 if (pw_info.error) { |
|
cdc6c1b072a5
Issue #12803: SSLContext.load_cert_chain() now accepts a password argument
Antoine Pitrou <solipsis@pitrou.net>
parents:
71440
diff
changeset
|
2246 ERR_clear_error(); |
|
cdc6c1b072a5
Issue #12803: SSLContext.load_cert_chain() now accepts a password argument
Antoine Pitrou <solipsis@pitrou.net>
parents:
71440
diff
changeset
|
2247 /* the password callback has already set the error information */ |
|
cdc6c1b072a5
Issue #12803: SSLContext.load_cert_chain() now accepts a password argument
Antoine Pitrou <solipsis@pitrou.net>
parents:
71440
diff
changeset
|
2248 } |
|
cdc6c1b072a5
Issue #12803: SSLContext.load_cert_chain() now accepts a password argument
Antoine Pitrou <solipsis@pitrou.net>
parents:
71440
diff
changeset
|
2249 else if (errno != 0) { |
|
64352
2dc17dcc9734
Issue #9693 - msg 115273: attempt to fix ssl module failures on certain OpenSSL versions by calling ERR_clear_error() before raising IOError
Giampaolo Rodolà <g.rodola@gmail.com>
parents:
64306
diff
changeset
|
2250 ERR_clear_error(); |
|
64306
9297974604ff
Fix issue issue9706: provides a better error handling for various SSL operations
Giampaolo Rodolà <g.rodola@gmail.com>
parents:
63692
diff
changeset
|
2251 PyErr_SetFromErrno(PyExc_IOError); |
|
9297974604ff
Fix issue issue9706: provides a better error handling for various SSL operations
Giampaolo Rodolà <g.rodola@gmail.com>
parents:
63692
diff
changeset
|
2252 } |
|
9297974604ff
Fix issue issue9706: provides a better error handling for various SSL operations
Giampaolo Rodolà <g.rodola@gmail.com>
parents:
63692
diff
changeset
|
2253 else { |
|
9297974604ff
Fix issue issue9706: provides a better error handling for various SSL operations
Giampaolo Rodolà <g.rodola@gmail.com>
parents:
63692
diff
changeset
|
2254 _setSSLError(NULL, 0, __FILE__, __LINE__); |
|
9297974604ff
Fix issue issue9706: provides a better error handling for various SSL operations
Giampaolo Rodolà <g.rodola@gmail.com>
parents:
63692
diff
changeset
|
2255 } |
|
61635
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2256 goto error; |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2257 } |
|
72071
cdc6c1b072a5
Issue #12803: SSLContext.load_cert_chain() now accepts a password argument
Antoine Pitrou <solipsis@pitrou.net>
parents:
71440
diff
changeset
|
2258 PySSL_BEGIN_ALLOW_THREADS_S(pw_info.thread_state); |
|
69114
88ed3de28520
Issue #11746: Fix SSLContext.load_cert_chain() to accept elliptic curve private keys.
Antoine Pitrou <solipsis@pitrou.net>
parents:
68257
diff
changeset
|
2259 r = SSL_CTX_use_PrivateKey_file(self->ctx, |
|
61635
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2260 PyBytes_AS_STRING(keyfile ? keyfile_bytes : certfile_bytes), |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2261 SSL_FILETYPE_PEM); |
|
72071
cdc6c1b072a5
Issue #12803: SSLContext.load_cert_chain() now accepts a password argument
Antoine Pitrou <solipsis@pitrou.net>
parents:
71440
diff
changeset
|
2262 PySSL_END_ALLOW_THREADS_S(pw_info.thread_state); |
|
cdc6c1b072a5
Issue #12803: SSLContext.load_cert_chain() now accepts a password argument
Antoine Pitrou <solipsis@pitrou.net>
parents:
71440
diff
changeset
|
2263 Py_CLEAR(keyfile_bytes); |
|
cdc6c1b072a5
Issue #12803: SSLContext.load_cert_chain() now accepts a password argument
Antoine Pitrou <solipsis@pitrou.net>
parents:
71440
diff
changeset
|
2264 Py_CLEAR(certfile_bytes); |
|
61635
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2265 if (r != 1) { |
|
72071
cdc6c1b072a5
Issue #12803: SSLContext.load_cert_chain() now accepts a password argument
Antoine Pitrou <solipsis@pitrou.net>
parents:
71440
diff
changeset
|
2266 if (pw_info.error) { |
|
cdc6c1b072a5
Issue #12803: SSLContext.load_cert_chain() now accepts a password argument
Antoine Pitrou <solipsis@pitrou.net>
parents:
71440
diff
changeset
|
2267 ERR_clear_error(); |
|
cdc6c1b072a5
Issue #12803: SSLContext.load_cert_chain() now accepts a password argument
Antoine Pitrou <solipsis@pitrou.net>
parents:
71440
diff
changeset
|
2268 /* the password callback has already set the error information */ |
|
cdc6c1b072a5
Issue #12803: SSLContext.load_cert_chain() now accepts a password argument
Antoine Pitrou <solipsis@pitrou.net>
parents:
71440
diff
changeset
|
2269 } |
|
cdc6c1b072a5
Issue #12803: SSLContext.load_cert_chain() now accepts a password argument
Antoine Pitrou <solipsis@pitrou.net>
parents:
71440
diff
changeset
|
2270 else if (errno != 0) { |
|
64352
2dc17dcc9734
Issue #9693 - msg 115273: attempt to fix ssl module failures on certain OpenSSL versions by calling ERR_clear_error() before raising IOError
Giampaolo Rodolà <g.rodola@gmail.com>
parents:
64306
diff
changeset
|
2271 ERR_clear_error(); |
|
64306
9297974604ff
Fix issue issue9706: provides a better error handling for various SSL operations
Giampaolo Rodolà <g.rodola@gmail.com>
parents:
63692
diff
changeset
|
2272 PyErr_SetFromErrno(PyExc_IOError); |
|
9297974604ff
Fix issue issue9706: provides a better error handling for various SSL operations
Giampaolo Rodolà <g.rodola@gmail.com>
parents:
63692
diff
changeset
|
2273 } |
|
9297974604ff
Fix issue issue9706: provides a better error handling for various SSL operations
Giampaolo Rodolà <g.rodola@gmail.com>
parents:
63692
diff
changeset
|
2274 else { |
|
9297974604ff
Fix issue issue9706: provides a better error handling for various SSL operations
Giampaolo Rodolà <g.rodola@gmail.com>
parents:
63692
diff
changeset
|
2275 _setSSLError(NULL, 0, __FILE__, __LINE__); |
|
9297974604ff
Fix issue issue9706: provides a better error handling for various SSL operations
Giampaolo Rodolà <g.rodola@gmail.com>
parents:
63692
diff
changeset
|
2276 } |
|
72071
cdc6c1b072a5
Issue #12803: SSLContext.load_cert_chain() now accepts a password argument
Antoine Pitrou <solipsis@pitrou.net>
parents:
71440
diff
changeset
|
2277 goto error; |
|
61635
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2278 } |
|
72071
cdc6c1b072a5
Issue #12803: SSLContext.load_cert_chain() now accepts a password argument
Antoine Pitrou <solipsis@pitrou.net>
parents:
71440
diff
changeset
|
2279 PySSL_BEGIN_ALLOW_THREADS_S(pw_info.thread_state); |
|
61635
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2280 r = SSL_CTX_check_private_key(self->ctx); |
|
72071
cdc6c1b072a5
Issue #12803: SSLContext.load_cert_chain() now accepts a password argument
Antoine Pitrou <solipsis@pitrou.net>
parents:
71440
diff
changeset
|
2281 PySSL_END_ALLOW_THREADS_S(pw_info.thread_state); |
|
61635
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2282 if (r != 1) { |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2283 _setSSLError(NULL, 0, __FILE__, __LINE__); |
|
72071
cdc6c1b072a5
Issue #12803: SSLContext.load_cert_chain() now accepts a password argument
Antoine Pitrou <solipsis@pitrou.net>
parents:
71440
diff
changeset
|
2284 goto error; |
|
61635
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2285 } |
|
72071
cdc6c1b072a5
Issue #12803: SSLContext.load_cert_chain() now accepts a password argument
Antoine Pitrou <solipsis@pitrou.net>
parents:
71440
diff
changeset
|
2286 SSL_CTX_set_default_passwd_cb(self->ctx, orig_passwd_cb); |
|
cdc6c1b072a5
Issue #12803: SSLContext.load_cert_chain() now accepts a password argument
Antoine Pitrou <solipsis@pitrou.net>
parents:
71440
diff
changeset
|
2287 SSL_CTX_set_default_passwd_cb_userdata(self->ctx, orig_passwd_userdata); |
|
84495
638d43665356
Issue #18203: Replace malloc() with PyMem_Malloc() in _ssl for the password
Victor Stinner <victor.stinner@gmail.com>
parents:
84491
diff
changeset
|
2288 PyMem_Free(pw_info.password); |
|
61635
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2289 Py_RETURN_NONE; |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2290 |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2291 error: |
|
72071
cdc6c1b072a5
Issue #12803: SSLContext.load_cert_chain() now accepts a password argument
Antoine Pitrou <solipsis@pitrou.net>
parents:
71440
diff
changeset
|
2292 SSL_CTX_set_default_passwd_cb(self->ctx, orig_passwd_cb); |
|
cdc6c1b072a5
Issue #12803: SSLContext.load_cert_chain() now accepts a password argument
Antoine Pitrou <solipsis@pitrou.net>
parents:
71440
diff
changeset
|
2293 SSL_CTX_set_default_passwd_cb_userdata(self->ctx, orig_passwd_userdata); |
|
84495
638d43665356
Issue #18203: Replace malloc() with PyMem_Malloc() in _ssl for the password
Victor Stinner <victor.stinner@gmail.com>
parents:
84491
diff
changeset
|
2294 PyMem_Free(pw_info.password); |
|
61635
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2295 Py_XDECREF(keyfile_bytes); |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2296 Py_XDECREF(certfile_bytes); |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2297 return NULL; |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2298 } |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2299 |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2300 static PyObject * |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2301 load_verify_locations(PySSLContext *self, PyObject *args, PyObject *kwds) |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2302 { |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2303 char *kwlist[] = {"cafile", "capath", NULL}; |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2304 PyObject *cafile = NULL, *capath = NULL; |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2305 PyObject *cafile_bytes = NULL, *capath_bytes = NULL; |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2306 const char *cafile_buf = NULL, *capath_buf = NULL; |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2307 int r; |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2308 |
|
64306
9297974604ff
Fix issue issue9706: provides a better error handling for various SSL operations
Giampaolo Rodolà <g.rodola@gmail.com>
parents:
63692
diff
changeset
|
2309 errno = 0; |
|
61635
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2310 if (!PyArg_ParseTupleAndKeywords(args, kwds, |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2311 "|OO:load_verify_locations", kwlist, |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2312 &cafile, &capath)) |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2313 return NULL; |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2314 if (cafile == Py_None) |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2315 cafile = NULL; |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2316 if (capath == Py_None) |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2317 capath = NULL; |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2318 if (cafile == NULL && capath == NULL) { |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2319 PyErr_SetString(PyExc_TypeError, |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2320 "cafile and capath cannot be both omitted"); |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2321 return NULL; |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2322 } |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2323 if (cafile && !PyUnicode_FSConverter(cafile, &cafile_bytes)) { |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2324 PyErr_SetString(PyExc_TypeError, |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2325 "cafile should be a valid filesystem path"); |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2326 return NULL; |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2327 } |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2328 if (capath && !PyUnicode_FSConverter(capath, &capath_bytes)) { |
|
67792
852186e5ae2a
Issue #10989: Fix a crash on SSLContext.load_verify_locations(None, True).
Victor Stinner <victor.stinner@haypocalc.com>
parents:
66802
diff
changeset
|
2329 Py_XDECREF(cafile_bytes); |
|
61635
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2330 PyErr_SetString(PyExc_TypeError, |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2331 "capath should be a valid filesystem path"); |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2332 return NULL; |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2333 } |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2334 if (cafile) |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2335 cafile_buf = PyBytes_AS_STRING(cafile_bytes); |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2336 if (capath) |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2337 capath_buf = PyBytes_AS_STRING(capath_bytes); |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2338 PySSL_BEGIN_ALLOW_THREADS |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2339 r = SSL_CTX_load_verify_locations(self->ctx, cafile_buf, capath_buf); |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2340 PySSL_END_ALLOW_THREADS |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2341 Py_XDECREF(cafile_bytes); |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2342 Py_XDECREF(capath_bytes); |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2343 if (r != 1) { |
|
64306
9297974604ff
Fix issue issue9706: provides a better error handling for various SSL operations
Giampaolo Rodolà <g.rodola@gmail.com>
parents:
63692
diff
changeset
|
2344 if (errno != 0) { |
|
64352
2dc17dcc9734
Issue #9693 - msg 115273: attempt to fix ssl module failures on certain OpenSSL versions by calling ERR_clear_error() before raising IOError
Giampaolo Rodolà <g.rodola@gmail.com>
parents:
64306
diff
changeset
|
2345 ERR_clear_error(); |
|
64306
9297974604ff
Fix issue issue9706: provides a better error handling for various SSL operations
Giampaolo Rodolà <g.rodola@gmail.com>
parents:
63692
diff
changeset
|
2346 PyErr_SetFromErrno(PyExc_IOError); |
|
9297974604ff
Fix issue issue9706: provides a better error handling for various SSL operations
Giampaolo Rodolà <g.rodola@gmail.com>
parents:
63692
diff
changeset
|
2347 } |
|
9297974604ff
Fix issue issue9706: provides a better error handling for various SSL operations
Giampaolo Rodolà <g.rodola@gmail.com>
parents:
63692
diff
changeset
|
2348 else { |
|
9297974604ff
Fix issue issue9706: provides a better error handling for various SSL operations
Giampaolo Rodolà <g.rodola@gmail.com>
parents:
63692
diff
changeset
|
2349 _setSSLError(NULL, 0, __FILE__, __LINE__); |
|
9297974604ff
Fix issue issue9706: provides a better error handling for various SSL operations
Giampaolo Rodolà <g.rodola@gmail.com>
parents:
63692
diff
changeset
|
2350 } |
|
61635
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2351 return NULL; |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2352 } |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2353 Py_RETURN_NONE; |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2354 } |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2355 |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2356 static PyObject * |
|
74129
33dea851f918
Issue #13626: Add support for SSL Diffie-Hellman key exchange, through the
Antoine Pitrou <solipsis@pitrou.net>
parents:
74103
diff
changeset
|
2357 load_dh_params(PySSLContext *self, PyObject *filepath) |
|
33dea851f918
Issue #13626: Add support for SSL Diffie-Hellman key exchange, through the
Antoine Pitrou <solipsis@pitrou.net>
parents:
74103
diff
changeset
|
2358 { |
|
33dea851f918
Issue #13626: Add support for SSL Diffie-Hellman key exchange, through the
Antoine Pitrou <solipsis@pitrou.net>
parents:
74103
diff
changeset
|
2359 FILE *f; |
|
33dea851f918
Issue #13626: Add support for SSL Diffie-Hellman key exchange, through the
Antoine Pitrou <solipsis@pitrou.net>
parents:
74103
diff
changeset
|
2360 DH *dh; |
|
33dea851f918
Issue #13626: Add support for SSL Diffie-Hellman key exchange, through the
Antoine Pitrou <solipsis@pitrou.net>
parents:
74103
diff
changeset
|
2361 |
|
85420
ef889c3d5dc6
Issue #18571: Implementation of the PEP 446: file descriptors and file handles
Victor Stinner <victor.stinner@gmail.com>
parents:
85379
diff
changeset
|
2362 f = _Py_fopen_obj(filepath, "rb"); |
|
74129
33dea851f918
Issue #13626: Add support for SSL Diffie-Hellman key exchange, through the
Antoine Pitrou <solipsis@pitrou.net>
parents:
74103
diff
changeset
|
2363 if (f == NULL) { |
|
33dea851f918
Issue #13626: Add support for SSL Diffie-Hellman key exchange, through the
Antoine Pitrou <solipsis@pitrou.net>
parents:
74103
diff
changeset
|
2364 if (!PyErr_Occurred()) |
|
33dea851f918
Issue #13626: Add support for SSL Diffie-Hellman key exchange, through the
Antoine Pitrou <solipsis@pitrou.net>
parents:
74103
diff
changeset
|
2365 PyErr_SetFromErrnoWithFilenameObject(PyExc_OSError, filepath); |
|
33dea851f918
Issue #13626: Add support for SSL Diffie-Hellman key exchange, through the
Antoine Pitrou <solipsis@pitrou.net>
parents:
74103
diff
changeset
|
2366 return NULL; |
|
33dea851f918
Issue #13626: Add support for SSL Diffie-Hellman key exchange, through the
Antoine Pitrou <solipsis@pitrou.net>
parents:
74103
diff
changeset
|
2367 } |
|
33dea851f918
Issue #13626: Add support for SSL Diffie-Hellman key exchange, through the
Antoine Pitrou <solipsis@pitrou.net>
parents:
74103
diff
changeset
|
2368 errno = 0; |
|
33dea851f918
Issue #13626: Add support for SSL Diffie-Hellman key exchange, through the
Antoine Pitrou <solipsis@pitrou.net>
parents:
74103
diff
changeset
|
2369 PySSL_BEGIN_ALLOW_THREADS |
|
33dea851f918
Issue #13626: Add support for SSL Diffie-Hellman key exchange, through the
Antoine Pitrou <solipsis@pitrou.net>
parents:
74103
diff
changeset
|
2370 dh = PEM_read_DHparams(f, NULL, NULL, NULL); |
|
81463
523d5b1e3fd5
SSLContext.load_dh_params() now properly closes the input file.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
2371 fclose(f); |
|
74129
33dea851f918
Issue #13626: Add support for SSL Diffie-Hellman key exchange, through the
Antoine Pitrou <solipsis@pitrou.net>
parents:
74103
diff
changeset
|
2372 PySSL_END_ALLOW_THREADS |
|
33dea851f918
Issue #13626: Add support for SSL Diffie-Hellman key exchange, through the
Antoine Pitrou <solipsis@pitrou.net>
parents:
74103
diff
changeset
|
2373 if (dh == NULL) { |
|
33dea851f918
Issue #13626: Add support for SSL Diffie-Hellman key exchange, through the
Antoine Pitrou <solipsis@pitrou.net>
parents:
74103
diff
changeset
|
2374 if (errno != 0) { |
|
33dea851f918
Issue #13626: Add support for SSL Diffie-Hellman key exchange, through the
Antoine Pitrou <solipsis@pitrou.net>
parents:
74103
diff
changeset
|
2375 ERR_clear_error(); |
|
33dea851f918
Issue #13626: Add support for SSL Diffie-Hellman key exchange, through the
Antoine Pitrou <solipsis@pitrou.net>
parents:
74103
diff
changeset
|
2376 PyErr_SetFromErrnoWithFilenameObject(PyExc_OSError, filepath); |
|
33dea851f918
Issue #13626: Add support for SSL Diffie-Hellman key exchange, through the
Antoine Pitrou <solipsis@pitrou.net>
parents:
74103
diff
changeset
|
2377 } |
|
33dea851f918
Issue #13626: Add support for SSL Diffie-Hellman key exchange, through the
Antoine Pitrou <solipsis@pitrou.net>
parents:
74103
diff
changeset
|
2378 else { |
|
33dea851f918
Issue #13626: Add support for SSL Diffie-Hellman key exchange, through the
Antoine Pitrou <solipsis@pitrou.net>
parents:
74103
diff
changeset
|
2379 _setSSLError(NULL, 0, __FILE__, __LINE__); |
|
33dea851f918
Issue #13626: Add support for SSL Diffie-Hellman key exchange, through the
Antoine Pitrou <solipsis@pitrou.net>
parents:
74103
diff
changeset
|
2380 } |
|
33dea851f918
Issue #13626: Add support for SSL Diffie-Hellman key exchange, through the
Antoine Pitrou <solipsis@pitrou.net>
parents:
74103
diff
changeset
|
2381 return NULL; |
|
33dea851f918
Issue #13626: Add support for SSL Diffie-Hellman key exchange, through the
Antoine Pitrou <solipsis@pitrou.net>
parents:
74103
diff
changeset
|
2382 } |
|
33dea851f918
Issue #13626: Add support for SSL Diffie-Hellman key exchange, through the
Antoine Pitrou <solipsis@pitrou.net>
parents:
74103
diff
changeset
|
2383 if (SSL_CTX_set_tmp_dh(self->ctx, dh) == 0) |
|
33dea851f918
Issue #13626: Add support for SSL Diffie-Hellman key exchange, through the
Antoine Pitrou <solipsis@pitrou.net>
parents:
74103
diff
changeset
|
2384 _setSSLError(NULL, 0, __FILE__, __LINE__); |
|
33dea851f918
Issue #13626: Add support for SSL Diffie-Hellman key exchange, through the
Antoine Pitrou <solipsis@pitrou.net>
parents:
74103
diff
changeset
|
2385 DH_free(dh); |
|
33dea851f918
Issue #13626: Add support for SSL Diffie-Hellman key exchange, through the
Antoine Pitrou <solipsis@pitrou.net>
parents:
74103
diff
changeset
|
2386 Py_RETURN_NONE; |
|
33dea851f918
Issue #13626: Add support for SSL Diffie-Hellman key exchange, through the
Antoine Pitrou <solipsis@pitrou.net>
parents:
74103
diff
changeset
|
2387 } |
|
33dea851f918
Issue #13626: Add support for SSL Diffie-Hellman key exchange, through the
Antoine Pitrou <solipsis@pitrou.net>
parents:
74103
diff
changeset
|
2388 |
|
33dea851f918
Issue #13626: Add support for SSL Diffie-Hellman key exchange, through the
Antoine Pitrou <solipsis@pitrou.net>
parents:
74103
diff
changeset
|
2389 static PyObject * |
|
61635
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2390 context_wrap_socket(PySSLContext *self, PyObject *args, PyObject *kwds) |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2391 { |
|
65593
846c0e1342d0
Issue #5639: Add a *server_hostname* argument to `SSLContext.wrap_socket`
Antoine Pitrou <solipsis@pitrou.net>
parents:
65267
diff
changeset
|
2392 char *kwlist[] = {"sock", "server_side", "server_hostname", NULL}; |
|
61635
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2393 PySocketSockObject *sock; |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2394 int server_side = 0; |
|
65593
846c0e1342d0
Issue #5639: Add a *server_hostname* argument to `SSLContext.wrap_socket`
Antoine Pitrou <solipsis@pitrou.net>
parents:
65267
diff
changeset
|
2395 char *hostname = NULL; |
|
846c0e1342d0
Issue #5639: Add a *server_hostname* argument to `SSLContext.wrap_socket`
Antoine Pitrou <solipsis@pitrou.net>
parents:
65267
diff
changeset
|
2396 PyObject *hostname_obj, *res; |
|
61635
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2397 |
|
65593
846c0e1342d0
Issue #5639: Add a *server_hostname* argument to `SSLContext.wrap_socket`
Antoine Pitrou <solipsis@pitrou.net>
parents:
65267
diff
changeset
|
2398 /* server_hostname is either None (or absent), or to be encoded |
|
846c0e1342d0
Issue #5639: Add a *server_hostname* argument to `SSLContext.wrap_socket`
Antoine Pitrou <solipsis@pitrou.net>
parents:
65267
diff
changeset
|
2399 using the idna encoding. */ |
|
846c0e1342d0
Issue #5639: Add a *server_hostname* argument to `SSLContext.wrap_socket`
Antoine Pitrou <solipsis@pitrou.net>
parents:
65267
diff
changeset
|
2400 if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!i|O!:_wrap_socket", kwlist, |
|
61635
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2401 PySocketModule.Sock_Type, |
|
65593
846c0e1342d0
Issue #5639: Add a *server_hostname* argument to `SSLContext.wrap_socket`
Antoine Pitrou <solipsis@pitrou.net>
parents:
65267
diff
changeset
|
2402 &sock, &server_side, |
|
846c0e1342d0
Issue #5639: Add a *server_hostname* argument to `SSLContext.wrap_socket`
Antoine Pitrou <solipsis@pitrou.net>
parents:
65267
diff
changeset
|
2403 Py_TYPE(Py_None), &hostname_obj)) { |
|
846c0e1342d0
Issue #5639: Add a *server_hostname* argument to `SSLContext.wrap_socket`
Antoine Pitrou <solipsis@pitrou.net>
parents:
65267
diff
changeset
|
2404 PyErr_Clear(); |
|
846c0e1342d0
Issue #5639: Add a *server_hostname* argument to `SSLContext.wrap_socket`
Antoine Pitrou <solipsis@pitrou.net>
parents:
65267
diff
changeset
|
2405 if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!iet:_wrap_socket", kwlist, |
|
846c0e1342d0
Issue #5639: Add a *server_hostname* argument to `SSLContext.wrap_socket`
Antoine Pitrou <solipsis@pitrou.net>
parents:
65267
diff
changeset
|
2406 PySocketModule.Sock_Type, |
|
846c0e1342d0
Issue #5639: Add a *server_hostname* argument to `SSLContext.wrap_socket`
Antoine Pitrou <solipsis@pitrou.net>
parents:
65267
diff
changeset
|
2407 &sock, &server_side, |
|
846c0e1342d0
Issue #5639: Add a *server_hostname* argument to `SSLContext.wrap_socket`
Antoine Pitrou <solipsis@pitrou.net>
parents:
65267
diff
changeset
|
2408 "idna", &hostname)) |
|
846c0e1342d0
Issue #5639: Add a *server_hostname* argument to `SSLContext.wrap_socket`
Antoine Pitrou <solipsis@pitrou.net>
parents:
65267
diff
changeset
|
2409 return NULL; |
|
83021
02f9335b7efb
Issue #17581: try to fix building on old OpenSSL versions
Antoine Pitrou <solipsis@pitrou.net>
parents:
82992
diff
changeset
|
2410 #if !HAVE_SNI |
|
65593
846c0e1342d0
Issue #5639: Add a *server_hostname* argument to `SSLContext.wrap_socket`
Antoine Pitrou <solipsis@pitrou.net>
parents:
65267
diff
changeset
|
2411 PyMem_Free(hostname); |
|
846c0e1342d0
Issue #5639: Add a *server_hostname* argument to `SSLContext.wrap_socket`
Antoine Pitrou <solipsis@pitrou.net>
parents:
65267
diff
changeset
|
2412 PyErr_SetString(PyExc_ValueError, "server_hostname is not supported " |
|
846c0e1342d0
Issue #5639: Add a *server_hostname* argument to `SSLContext.wrap_socket`
Antoine Pitrou <solipsis@pitrou.net>
parents:
65267
diff
changeset
|
2413 "by your OpenSSL library"); |
|
61635
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2414 return NULL; |
|
65593
846c0e1342d0
Issue #5639: Add a *server_hostname* argument to `SSLContext.wrap_socket`
Antoine Pitrou <solipsis@pitrou.net>
parents:
65267
diff
changeset
|
2415 #endif |
|
846c0e1342d0
Issue #5639: Add a *server_hostname* argument to `SSLContext.wrap_socket`
Antoine Pitrou <solipsis@pitrou.net>
parents:
65267
diff
changeset
|
2416 } |
|
61635
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2417 |
|
81298
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
2418 res = (PyObject *) newPySSLSocket(self, sock, server_side, |
|
65593
846c0e1342d0
Issue #5639: Add a *server_hostname* argument to `SSLContext.wrap_socket`
Antoine Pitrou <solipsis@pitrou.net>
parents:
65267
diff
changeset
|
2419 hostname); |
|
846c0e1342d0
Issue #5639: Add a *server_hostname* argument to `SSLContext.wrap_socket`
Antoine Pitrou <solipsis@pitrou.net>
parents:
65267
diff
changeset
|
2420 if (hostname != NULL) |
|
846c0e1342d0
Issue #5639: Add a *server_hostname* argument to `SSLContext.wrap_socket`
Antoine Pitrou <solipsis@pitrou.net>
parents:
65267
diff
changeset
|
2421 PyMem_Free(hostname); |
|
846c0e1342d0
Issue #5639: Add a *server_hostname* argument to `SSLContext.wrap_socket`
Antoine Pitrou <solipsis@pitrou.net>
parents:
65267
diff
changeset
|
2422 return res; |
|
61635
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2423 } |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2424 |
|
65223
9c723afa44da
Issue #10075: Add a session_stats() method to SSLContext objects.
Antoine Pitrou <solipsis@pitrou.net>
parents:
64403
diff
changeset
|
2425 static PyObject * |
|
9c723afa44da
Issue #10075: Add a session_stats() method to SSLContext objects.
Antoine Pitrou <solipsis@pitrou.net>
parents:
64403
diff
changeset
|
2426 session_stats(PySSLContext *self, PyObject *unused) |
|
9c723afa44da
Issue #10075: Add a session_stats() method to SSLContext objects.
Antoine Pitrou <solipsis@pitrou.net>
parents:
64403
diff
changeset
|
2427 { |
|
9c723afa44da
Issue #10075: Add a session_stats() method to SSLContext objects.
Antoine Pitrou <solipsis@pitrou.net>
parents:
64403
diff
changeset
|
2428 int r; |
|
9c723afa44da
Issue #10075: Add a session_stats() method to SSLContext objects.
Antoine Pitrou <solipsis@pitrou.net>
parents:
64403
diff
changeset
|
2429 PyObject *value, *stats = PyDict_New(); |
|
9c723afa44da
Issue #10075: Add a session_stats() method to SSLContext objects.
Antoine Pitrou <solipsis@pitrou.net>
parents:
64403
diff
changeset
|
2430 if (!stats) |
|
9c723afa44da
Issue #10075: Add a session_stats() method to SSLContext objects.
Antoine Pitrou <solipsis@pitrou.net>
parents:
64403
diff
changeset
|
2431 return NULL; |
|
9c723afa44da
Issue #10075: Add a session_stats() method to SSLContext objects.
Antoine Pitrou <solipsis@pitrou.net>
parents:
64403
diff
changeset
|
2432 |
|
9c723afa44da
Issue #10075: Add a session_stats() method to SSLContext objects.
Antoine Pitrou <solipsis@pitrou.net>
parents:
64403
diff
changeset
|
2433 #define ADD_STATS(SSL_NAME, KEY_NAME) \ |
|
9c723afa44da
Issue #10075: Add a session_stats() method to SSLContext objects.
Antoine Pitrou <solipsis@pitrou.net>
parents:
64403
diff
changeset
|
2434 value = PyLong_FromLong(SSL_CTX_sess_ ## SSL_NAME (self->ctx)); \ |
|
9c723afa44da
Issue #10075: Add a session_stats() method to SSLContext objects.
Antoine Pitrou <solipsis@pitrou.net>
parents:
64403
diff
changeset
|
2435 if (value == NULL) \ |
|
9c723afa44da
Issue #10075: Add a session_stats() method to SSLContext objects.
Antoine Pitrou <solipsis@pitrou.net>
parents:
64403
diff
changeset
|
2436 goto error; \ |
|
9c723afa44da
Issue #10075: Add a session_stats() method to SSLContext objects.
Antoine Pitrou <solipsis@pitrou.net>
parents:
64403
diff
changeset
|
2437 r = PyDict_SetItemString(stats, KEY_NAME, value); \ |
|
9c723afa44da
Issue #10075: Add a session_stats() method to SSLContext objects.
Antoine Pitrou <solipsis@pitrou.net>
parents:
64403
diff
changeset
|
2438 Py_DECREF(value); \ |
|
9c723afa44da
Issue #10075: Add a session_stats() method to SSLContext objects.
Antoine Pitrou <solipsis@pitrou.net>
parents:
64403
diff
changeset
|
2439 if (r < 0) \ |
|
9c723afa44da
Issue #10075: Add a session_stats() method to SSLContext objects.
Antoine Pitrou <solipsis@pitrou.net>
parents:
64403
diff
changeset
|
2440 goto error; |
|
9c723afa44da
Issue #10075: Add a session_stats() method to SSLContext objects.
Antoine Pitrou <solipsis@pitrou.net>
parents:
64403
diff
changeset
|
2441 |
|
9c723afa44da
Issue #10075: Add a session_stats() method to SSLContext objects.
Antoine Pitrou <solipsis@pitrou.net>
parents:
64403
diff
changeset
|
2442 ADD_STATS(number, "number"); |
|
9c723afa44da
Issue #10075: Add a session_stats() method to SSLContext objects.
Antoine Pitrou <solipsis@pitrou.net>
parents:
64403
diff
changeset
|
2443 ADD_STATS(connect, "connect"); |
|
9c723afa44da
Issue #10075: Add a session_stats() method to SSLContext objects.
Antoine Pitrou <solipsis@pitrou.net>
parents:
64403
diff
changeset
|
2444 ADD_STATS(connect_good, "connect_good"); |
|
9c723afa44da
Issue #10075: Add a session_stats() method to SSLContext objects.
Antoine Pitrou <solipsis@pitrou.net>
parents:
64403
diff
changeset
|
2445 ADD_STATS(connect_renegotiate, "connect_renegotiate"); |
|
9c723afa44da
Issue #10075: Add a session_stats() method to SSLContext objects.
Antoine Pitrou <solipsis@pitrou.net>
parents:
64403
diff
changeset
|
2446 ADD_STATS(accept, "accept"); |
|
9c723afa44da
Issue #10075: Add a session_stats() method to SSLContext objects.
Antoine Pitrou <solipsis@pitrou.net>
parents:
64403
diff
changeset
|
2447 ADD_STATS(accept_good, "accept_good"); |
|
9c723afa44da
Issue #10075: Add a session_stats() method to SSLContext objects.
Antoine Pitrou <solipsis@pitrou.net>
parents:
64403
diff
changeset
|
2448 ADD_STATS(accept_renegotiate, "accept_renegotiate"); |
|
9c723afa44da
Issue #10075: Add a session_stats() method to SSLContext objects.
Antoine Pitrou <solipsis@pitrou.net>
parents:
64403
diff
changeset
|
2449 ADD_STATS(accept, "accept"); |
|
9c723afa44da
Issue #10075: Add a session_stats() method to SSLContext objects.
Antoine Pitrou <solipsis@pitrou.net>
parents:
64403
diff
changeset
|
2450 ADD_STATS(hits, "hits"); |
|
9c723afa44da
Issue #10075: Add a session_stats() method to SSLContext objects.
Antoine Pitrou <solipsis@pitrou.net>
parents:
64403
diff
changeset
|
2451 ADD_STATS(misses, "misses"); |
|
9c723afa44da
Issue #10075: Add a session_stats() method to SSLContext objects.
Antoine Pitrou <solipsis@pitrou.net>
parents:
64403
diff
changeset
|
2452 ADD_STATS(timeouts, "timeouts"); |
|
9c723afa44da
Issue #10075: Add a session_stats() method to SSLContext objects.
Antoine Pitrou <solipsis@pitrou.net>
parents:
64403
diff
changeset
|
2453 ADD_STATS(cache_full, "cache_full"); |
|
9c723afa44da
Issue #10075: Add a session_stats() method to SSLContext objects.
Antoine Pitrou <solipsis@pitrou.net>
parents:
64403
diff
changeset
|
2454 |
|
9c723afa44da
Issue #10075: Add a session_stats() method to SSLContext objects.
Antoine Pitrou <solipsis@pitrou.net>
parents:
64403
diff
changeset
|
2455 #undef ADD_STATS |
|
9c723afa44da
Issue #10075: Add a session_stats() method to SSLContext objects.
Antoine Pitrou <solipsis@pitrou.net>
parents:
64403
diff
changeset
|
2456 |
|
9c723afa44da
Issue #10075: Add a session_stats() method to SSLContext objects.
Antoine Pitrou <solipsis@pitrou.net>
parents:
64403
diff
changeset
|
2457 return stats; |
|
9c723afa44da
Issue #10075: Add a session_stats() method to SSLContext objects.
Antoine Pitrou <solipsis@pitrou.net>
parents:
64403
diff
changeset
|
2458 |
|
9c723afa44da
Issue #10075: Add a session_stats() method to SSLContext objects.
Antoine Pitrou <solipsis@pitrou.net>
parents:
64403
diff
changeset
|
2459 error: |
|
9c723afa44da
Issue #10075: Add a session_stats() method to SSLContext objects.
Antoine Pitrou <solipsis@pitrou.net>
parents:
64403
diff
changeset
|
2460 Py_DECREF(stats); |
|
9c723afa44da
Issue #10075: Add a session_stats() method to SSLContext objects.
Antoine Pitrou <solipsis@pitrou.net>
parents:
64403
diff
changeset
|
2461 return NULL; |
|
9c723afa44da
Issue #10075: Add a session_stats() method to SSLContext objects.
Antoine Pitrou <solipsis@pitrou.net>
parents:
64403
diff
changeset
|
2462 } |
|
9c723afa44da
Issue #10075: Add a session_stats() method to SSLContext objects.
Antoine Pitrou <solipsis@pitrou.net>
parents:
64403
diff
changeset
|
2463 |
|
66217
7826d907b765
Issue #10443: Add the SSLContext.set_default_verify_paths() method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
66114
diff
changeset
|
2464 static PyObject * |
|
7826d907b765
Issue #10443: Add the SSLContext.set_default_verify_paths() method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
66114
diff
changeset
|
2465 set_default_verify_paths(PySSLContext *self, PyObject *unused) |
|
7826d907b765
Issue #10443: Add the SSLContext.set_default_verify_paths() method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
66114
diff
changeset
|
2466 { |
|
7826d907b765
Issue #10443: Add the SSLContext.set_default_verify_paths() method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
66114
diff
changeset
|
2467 if (!SSL_CTX_set_default_verify_paths(self->ctx)) { |
|
7826d907b765
Issue #10443: Add the SSLContext.set_default_verify_paths() method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
66114
diff
changeset
|
2468 _setSSLError(NULL, 0, __FILE__, __LINE__); |
|
7826d907b765
Issue #10443: Add the SSLContext.set_default_verify_paths() method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
66114
diff
changeset
|
2469 return NULL; |
|
7826d907b765
Issue #10443: Add the SSLContext.set_default_verify_paths() method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
66114
diff
changeset
|
2470 } |
|
7826d907b765
Issue #10443: Add the SSLContext.set_default_verify_paths() method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
66114
diff
changeset
|
2471 Py_RETURN_NONE; |
|
7826d907b765
Issue #10443: Add the SSLContext.set_default_verify_paths() method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
66114
diff
changeset
|
2472 } |
|
7826d907b765
Issue #10443: Add the SSLContext.set_default_verify_paths() method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
66114
diff
changeset
|
2473 |
|
74103
ec44f2e82707
Fix ssl module compilation if ECDH support was disabled in the OpenSSL build.
Antoine Pitrou <solipsis@pitrou.net>
parents:
74091
diff
changeset
|
2474 #ifndef OPENSSL_NO_ECDH |
|
74084
8b729d65cfd2
Issue #13627: Add support for SSL Elliptic Curve-based Diffie-Hellman
Antoine Pitrou <solipsis@pitrou.net>
parents:
74075
diff
changeset
|
2475 static PyObject * |
|
8b729d65cfd2
Issue #13627: Add support for SSL Elliptic Curve-based Diffie-Hellman
Antoine Pitrou <solipsis@pitrou.net>
parents:
74075
diff
changeset
|
2476 set_ecdh_curve(PySSLContext *self, PyObject *name) |
|
8b729d65cfd2
Issue #13627: Add support for SSL Elliptic Curve-based Diffie-Hellman
Antoine Pitrou <solipsis@pitrou.net>
parents:
74075
diff
changeset
|
2477 { |
|
8b729d65cfd2
Issue #13627: Add support for SSL Elliptic Curve-based Diffie-Hellman
Antoine Pitrou <solipsis@pitrou.net>
parents:
74075
diff
changeset
|
2478 PyObject *name_bytes; |
|
8b729d65cfd2
Issue #13627: Add support for SSL Elliptic Curve-based Diffie-Hellman
Antoine Pitrou <solipsis@pitrou.net>
parents:
74075
diff
changeset
|
2479 int nid; |
|
8b729d65cfd2
Issue #13627: Add support for SSL Elliptic Curve-based Diffie-Hellman
Antoine Pitrou <solipsis@pitrou.net>
parents:
74075
diff
changeset
|
2480 EC_KEY *key; |
|
8b729d65cfd2
Issue #13627: Add support for SSL Elliptic Curve-based Diffie-Hellman
Antoine Pitrou <solipsis@pitrou.net>
parents:
74075
diff
changeset
|
2481 |
|
8b729d65cfd2
Issue #13627: Add support for SSL Elliptic Curve-based Diffie-Hellman
Antoine Pitrou <solipsis@pitrou.net>
parents:
74075
diff
changeset
|
2482 if (!PyUnicode_FSConverter(name, &name_bytes)) |
|
8b729d65cfd2
Issue #13627: Add support for SSL Elliptic Curve-based Diffie-Hellman
Antoine Pitrou <solipsis@pitrou.net>
parents:
74075
diff
changeset
|
2483 return NULL; |
|
8b729d65cfd2
Issue #13627: Add support for SSL Elliptic Curve-based Diffie-Hellman
Antoine Pitrou <solipsis@pitrou.net>
parents:
74075
diff
changeset
|
2484 assert(PyBytes_Check(name_bytes)); |
|
8b729d65cfd2
Issue #13627: Add support for SSL Elliptic Curve-based Diffie-Hellman
Antoine Pitrou <solipsis@pitrou.net>
parents:
74075
diff
changeset
|
2485 nid = OBJ_sn2nid(PyBytes_AS_STRING(name_bytes)); |
|
8b729d65cfd2
Issue #13627: Add support for SSL Elliptic Curve-based Diffie-Hellman
Antoine Pitrou <solipsis@pitrou.net>
parents:
74075
diff
changeset
|
2486 Py_DECREF(name_bytes); |
|
8b729d65cfd2
Issue #13627: Add support for SSL Elliptic Curve-based Diffie-Hellman
Antoine Pitrou <solipsis@pitrou.net>
parents:
74075
diff
changeset
|
2487 if (nid == 0) { |
|
8b729d65cfd2
Issue #13627: Add support for SSL Elliptic Curve-based Diffie-Hellman
Antoine Pitrou <solipsis@pitrou.net>
parents:
74075
diff
changeset
|
2488 PyErr_Format(PyExc_ValueError, |
|
8b729d65cfd2
Issue #13627: Add support for SSL Elliptic Curve-based Diffie-Hellman
Antoine Pitrou <solipsis@pitrou.net>
parents:
74075
diff
changeset
|
2489 "unknown elliptic curve name %R", name); |
|
8b729d65cfd2
Issue #13627: Add support for SSL Elliptic Curve-based Diffie-Hellman
Antoine Pitrou <solipsis@pitrou.net>
parents:
74075
diff
changeset
|
2490 return NULL; |
|
8b729d65cfd2
Issue #13627: Add support for SSL Elliptic Curve-based Diffie-Hellman
Antoine Pitrou <solipsis@pitrou.net>
parents:
74075
diff
changeset
|
2491 } |
|
8b729d65cfd2
Issue #13627: Add support for SSL Elliptic Curve-based Diffie-Hellman
Antoine Pitrou <solipsis@pitrou.net>
parents:
74075
diff
changeset
|
2492 key = EC_KEY_new_by_curve_name(nid); |
|
8b729d65cfd2
Issue #13627: Add support for SSL Elliptic Curve-based Diffie-Hellman
Antoine Pitrou <solipsis@pitrou.net>
parents:
74075
diff
changeset
|
2493 if (key == NULL) { |
|
8b729d65cfd2
Issue #13627: Add support for SSL Elliptic Curve-based Diffie-Hellman
Antoine Pitrou <solipsis@pitrou.net>
parents:
74075
diff
changeset
|
2494 _setSSLError(NULL, 0, __FILE__, __LINE__); |
|
8b729d65cfd2
Issue #13627: Add support for SSL Elliptic Curve-based Diffie-Hellman
Antoine Pitrou <solipsis@pitrou.net>
parents:
74075
diff
changeset
|
2495 return NULL; |
|
8b729d65cfd2
Issue #13627: Add support for SSL Elliptic Curve-based Diffie-Hellman
Antoine Pitrou <solipsis@pitrou.net>
parents:
74075
diff
changeset
|
2496 } |
|
8b729d65cfd2
Issue #13627: Add support for SSL Elliptic Curve-based Diffie-Hellman
Antoine Pitrou <solipsis@pitrou.net>
parents:
74075
diff
changeset
|
2497 SSL_CTX_set_tmp_ecdh(self->ctx, key); |
|
8b729d65cfd2
Issue #13627: Add support for SSL Elliptic Curve-based Diffie-Hellman
Antoine Pitrou <solipsis@pitrou.net>
parents:
74075
diff
changeset
|
2498 EC_KEY_free(key); |
|
8b729d65cfd2
Issue #13627: Add support for SSL Elliptic Curve-based Diffie-Hellman
Antoine Pitrou <solipsis@pitrou.net>
parents:
74075
diff
changeset
|
2499 Py_RETURN_NONE; |
|
8b729d65cfd2
Issue #13627: Add support for SSL Elliptic Curve-based Diffie-Hellman
Antoine Pitrou <solipsis@pitrou.net>
parents:
74075
diff
changeset
|
2500 } |
|
74103
ec44f2e82707
Fix ssl module compilation if ECDH support was disabled in the OpenSSL build.
Antoine Pitrou <solipsis@pitrou.net>
parents:
74091
diff
changeset
|
2501 #endif |
|
74084
8b729d65cfd2
Issue #13627: Add support for SSL Elliptic Curve-based Diffie-Hellman
Antoine Pitrou <solipsis@pitrou.net>
parents:
74075
diff
changeset
|
2502 |
|
83021
02f9335b7efb
Issue #17581: try to fix building on old OpenSSL versions
Antoine Pitrou <solipsis@pitrou.net>
parents:
82992
diff
changeset
|
2503 #if HAVE_SNI && !defined(OPENSSL_NO_TLSEXT) |
|
81298
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
2504 static int |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
2505 _servername_callback(SSL *s, int *al, void *args) |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
2506 { |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
2507 int ret; |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
2508 PySSLContext *ssl_ctx = (PySSLContext *) args; |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
2509 PySSLSocket *ssl; |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
2510 PyObject *servername_o; |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
2511 PyObject *servername_idna; |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
2512 PyObject *result; |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
2513 /* The high-level ssl.SSLSocket object */ |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
2514 PyObject *ssl_socket; |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
2515 const char *servername = SSL_get_servername(s, TLSEXT_NAMETYPE_host_name); |
|
81559
8630fa732cf6
Issue #16982: Fix --without-threads build failure.
Stefan Krah <skrah@bytereef.org>
parents:
81464
diff
changeset
|
2516 #ifdef WITH_THREAD |
|
8630fa732cf6
Issue #16982: Fix --without-threads build failure.
Stefan Krah <skrah@bytereef.org>
parents:
81464
diff
changeset
|
2517 PyGILState_STATE gstate = PyGILState_Ensure(); |
|
8630fa732cf6
Issue #16982: Fix --without-threads build failure.
Stefan Krah <skrah@bytereef.org>
parents:
81464
diff
changeset
|
2518 #endif |
|
81298
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
2519 |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
2520 if (ssl_ctx->set_hostname == NULL) { |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
2521 /* remove race condition in this the call back while if removing the |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
2522 * callback is in progress */ |
|
81559
8630fa732cf6
Issue #16982: Fix --without-threads build failure.
Stefan Krah <skrah@bytereef.org>
parents:
81464
diff
changeset
|
2523 #ifdef WITH_THREAD |
|
81298
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
2524 PyGILState_Release(gstate); |
|
81559
8630fa732cf6
Issue #16982: Fix --without-threads build failure.
Stefan Krah <skrah@bytereef.org>
parents:
81464
diff
changeset
|
2525 #endif |
|
81299
52b4d9bfc9ea
Fix returning uninitialized variable (issue #8109).
Antoine Pitrou <solipsis@pitrou.net>
parents:
81298
diff
changeset
|
2526 return SSL_TLSEXT_ERR_OK; |
|
81298
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
2527 } |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
2528 |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
2529 ssl = SSL_get_app_data(s); |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
2530 assert(PySSLSocket_Check(ssl)); |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
2531 ssl_socket = PyWeakref_GetObject(ssl->Socket); |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
2532 Py_INCREF(ssl_socket); |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
2533 if (ssl_socket == Py_None) { |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
2534 goto error; |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
2535 } |
|
84334
28f47a5d59b9
_ssl.c: strip trailing spaces
Victor Stinner <victor.stinner@gmail.com>
parents:
84333
diff
changeset
|
2536 |
|
83251
4ae6095b4638
Fix a crash when setting a servername callback on a SSL server socket and the client doesn't send a server name.
Antoine Pitrou <solipsis@pitrou.net>
parents:
83026
diff
changeset
|
2537 if (servername == NULL) { |
|
4ae6095b4638
Fix a crash when setting a servername callback on a SSL server socket and the client doesn't send a server name.
Antoine Pitrou <solipsis@pitrou.net>
parents:
83026
diff
changeset
|
2538 result = PyObject_CallFunctionObjArgs(ssl_ctx->set_hostname, ssl_socket, |
|
4ae6095b4638
Fix a crash when setting a servername callback on a SSL server socket and the client doesn't send a server name.
Antoine Pitrou <solipsis@pitrou.net>
parents:
83026
diff
changeset
|
2539 Py_None, ssl_ctx, NULL); |
|
81298
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
2540 } |
|
83251
4ae6095b4638
Fix a crash when setting a servername callback on a SSL server socket and the client doesn't send a server name.
Antoine Pitrou <solipsis@pitrou.net>
parents:
83026
diff
changeset
|
2541 else { |
|
4ae6095b4638
Fix a crash when setting a servername callback on a SSL server socket and the client doesn't send a server name.
Antoine Pitrou <solipsis@pitrou.net>
parents:
83026
diff
changeset
|
2542 servername_o = PyBytes_FromString(servername); |
|
4ae6095b4638
Fix a crash when setting a servername callback on a SSL server socket and the client doesn't send a server name.
Antoine Pitrou <solipsis@pitrou.net>
parents:
83026
diff
changeset
|
2543 if (servername_o == NULL) { |
|
4ae6095b4638
Fix a crash when setting a servername callback on a SSL server socket and the client doesn't send a server name.
Antoine Pitrou <solipsis@pitrou.net>
parents:
83026
diff
changeset
|
2544 PyErr_WriteUnraisable((PyObject *) ssl_ctx); |
|
4ae6095b4638
Fix a crash when setting a servername callback on a SSL server socket and the client doesn't send a server name.
Antoine Pitrou <solipsis@pitrou.net>
parents:
83026
diff
changeset
|
2545 goto error; |
|
4ae6095b4638
Fix a crash when setting a servername callback on a SSL server socket and the client doesn't send a server name.
Antoine Pitrou <solipsis@pitrou.net>
parents:
83026
diff
changeset
|
2546 } |
|
4ae6095b4638
Fix a crash when setting a servername callback on a SSL server socket and the client doesn't send a server name.
Antoine Pitrou <solipsis@pitrou.net>
parents:
83026
diff
changeset
|
2547 servername_idna = PyUnicode_FromEncodedObject(servername_o, "idna", NULL); |
|
4ae6095b4638
Fix a crash when setting a servername callback on a SSL server socket and the client doesn't send a server name.
Antoine Pitrou <solipsis@pitrou.net>
parents:
83026
diff
changeset
|
2548 if (servername_idna == NULL) { |
|
4ae6095b4638
Fix a crash when setting a servername callback on a SSL server socket and the client doesn't send a server name.
Antoine Pitrou <solipsis@pitrou.net>
parents:
83026
diff
changeset
|
2549 PyErr_WriteUnraisable(servername_o); |
|
4ae6095b4638
Fix a crash when setting a servername callback on a SSL server socket and the client doesn't send a server name.
Antoine Pitrou <solipsis@pitrou.net>
parents:
83026
diff
changeset
|
2550 Py_DECREF(servername_o); |
|
4ae6095b4638
Fix a crash when setting a servername callback on a SSL server socket and the client doesn't send a server name.
Antoine Pitrou <solipsis@pitrou.net>
parents:
83026
diff
changeset
|
2551 goto error; |
|
4ae6095b4638
Fix a crash when setting a servername callback on a SSL server socket and the client doesn't send a server name.
Antoine Pitrou <solipsis@pitrou.net>
parents:
83026
diff
changeset
|
2552 } |
|
81298
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
2553 Py_DECREF(servername_o); |
|
83251
4ae6095b4638
Fix a crash when setting a servername callback on a SSL server socket and the client doesn't send a server name.
Antoine Pitrou <solipsis@pitrou.net>
parents:
83026
diff
changeset
|
2554 result = PyObject_CallFunctionObjArgs(ssl_ctx->set_hostname, ssl_socket, |
|
4ae6095b4638
Fix a crash when setting a servername callback on a SSL server socket and the client doesn't send a server name.
Antoine Pitrou <solipsis@pitrou.net>
parents:
83026
diff
changeset
|
2555 servername_idna, ssl_ctx, NULL); |
|
4ae6095b4638
Fix a crash when setting a servername callback on a SSL server socket and the client doesn't send a server name.
Antoine Pitrou <solipsis@pitrou.net>
parents:
83026
diff
changeset
|
2556 Py_DECREF(servername_idna); |
|
81298
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
2557 } |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
2558 Py_DECREF(ssl_socket); |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
2559 |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
2560 if (result == NULL) { |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
2561 PyErr_WriteUnraisable(ssl_ctx->set_hostname); |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
2562 *al = SSL_AD_HANDSHAKE_FAILURE; |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
2563 ret = SSL_TLSEXT_ERR_ALERT_FATAL; |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
2564 } |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
2565 else { |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
2566 if (result != Py_None) { |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
2567 *al = (int) PyLong_AsLong(result); |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
2568 if (PyErr_Occurred()) { |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
2569 PyErr_WriteUnraisable(result); |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
2570 *al = SSL_AD_INTERNAL_ERROR; |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
2571 } |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
2572 ret = SSL_TLSEXT_ERR_ALERT_FATAL; |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
2573 } |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
2574 else { |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
2575 ret = SSL_TLSEXT_ERR_OK; |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
2576 } |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
2577 Py_DECREF(result); |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
2578 } |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
2579 |
|
81559
8630fa732cf6
Issue #16982: Fix --without-threads build failure.
Stefan Krah <skrah@bytereef.org>
parents:
81464
diff
changeset
|
2580 #ifdef WITH_THREAD |
|
81298
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
2581 PyGILState_Release(gstate); |
|
81559
8630fa732cf6
Issue #16982: Fix --without-threads build failure.
Stefan Krah <skrah@bytereef.org>
parents:
81464
diff
changeset
|
2582 #endif |
|
81298
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
2583 return ret; |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
2584 |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
2585 error: |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
2586 Py_DECREF(ssl_socket); |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
2587 *al = SSL_AD_INTERNAL_ERROR; |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
2588 ret = SSL_TLSEXT_ERR_ALERT_FATAL; |
|
81559
8630fa732cf6
Issue #16982: Fix --without-threads build failure.
Stefan Krah <skrah@bytereef.org>
parents:
81464
diff
changeset
|
2589 #ifdef WITH_THREAD |
|
81298
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
2590 PyGILState_Release(gstate); |
|
81559
8630fa732cf6
Issue #16982: Fix --without-threads build failure.
Stefan Krah <skrah@bytereef.org>
parents:
81464
diff
changeset
|
2591 #endif |
|
81298
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
2592 return ret; |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
2593 } |
|
83024
fc4f68b51ba0
Fix previous fix (the cause was actually a misplaced #endif, or so it seems)
Antoine Pitrou <solipsis@pitrou.net>
parents:
83023
diff
changeset
|
2594 #endif |
|
81298
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
2595 |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
2596 PyDoc_STRVAR(PySSL_set_servername_callback_doc, |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
2597 "set_servername_callback(method)\n\ |
|
83025
b45630913715
Improve set_servername_callback docstring.
Antoine Pitrou <solipsis@pitrou.net>
parents:
83024
diff
changeset
|
2598 \n\ |
|
81298
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
2599 This sets a callback that will be called when a server name is provided by\n\ |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
2600 the SSL/TLS client in the SNI extension.\n\ |
|
83025
b45630913715
Improve set_servername_callback docstring.
Antoine Pitrou <solipsis@pitrou.net>
parents:
83024
diff
changeset
|
2601 \n\ |
|
81298
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
2602 If the argument is None then the callback is disabled. The method is called\n\ |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
2603 with the SSLSocket, the server name as a string, and the SSLContext object.\n\ |
|
83025
b45630913715
Improve set_servername_callback docstring.
Antoine Pitrou <solipsis@pitrou.net>
parents:
83024
diff
changeset
|
2604 See RFC 6066 for details of the SNI extension."); |
|
81298
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
2605 |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
2606 static PyObject * |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
2607 set_servername_callback(PySSLContext *self, PyObject *args) |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
2608 { |
|
83021
02f9335b7efb
Issue #17581: try to fix building on old OpenSSL versions
Antoine Pitrou <solipsis@pitrou.net>
parents:
82992
diff
changeset
|
2609 #if HAVE_SNI && !defined(OPENSSL_NO_TLSEXT) |
|
81298
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
2610 PyObject *cb; |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
2611 |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
2612 if (!PyArg_ParseTuple(args, "O", &cb)) |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
2613 return NULL; |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
2614 |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
2615 Py_CLEAR(self->set_hostname); |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
2616 if (cb == Py_None) { |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
2617 SSL_CTX_set_tlsext_servername_callback(self->ctx, NULL); |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
2618 } |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
2619 else { |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
2620 if (!PyCallable_Check(cb)) { |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
2621 SSL_CTX_set_tlsext_servername_callback(self->ctx, NULL); |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
2622 PyErr_SetString(PyExc_TypeError, |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
2623 "not a callable object"); |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
2624 return NULL; |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
2625 } |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
2626 Py_INCREF(cb); |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
2627 self->set_hostname = cb; |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
2628 SSL_CTX_set_tlsext_servername_callback(self->ctx, _servername_callback); |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
2629 SSL_CTX_set_tlsext_servername_arg(self->ctx, self); |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
2630 } |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
2631 Py_RETURN_NONE; |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
2632 #else |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
2633 PyErr_SetString(PyExc_NotImplementedError, |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
2634 "The TLS extension servername callback, " |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
2635 "SSL_CTX_set_tlsext_servername_callback, " |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
2636 "is not in the current OpenSSL library."); |
|
83023
ad9effdc0ac3
Further compiling fixes (issue #17581)
Antoine Pitrou <solipsis@pitrou.net>
parents:
83021
diff
changeset
|
2637 return NULL; |
|
81298
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
2638 #endif |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
2639 } |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
2640 |
|
84185
38e759e4c9e6
Issue #18147: Add diagnostic functions to ssl.SSLContext().
Christian Heimes <christian@cheimes.de>
parents:
84119
diff
changeset
|
2641 PyDoc_STRVAR(PySSL_get_stats_doc, |
|
38e759e4c9e6
Issue #18147: Add diagnostic functions to ssl.SSLContext().
Christian Heimes <christian@cheimes.de>
parents:
84119
diff
changeset
|
2642 "cert_store_stats() -> {'crl': int, 'x509_ca': int, 'x509': int}\n\ |
|
38e759e4c9e6
Issue #18147: Add diagnostic functions to ssl.SSLContext().
Christian Heimes <christian@cheimes.de>
parents:
84119
diff
changeset
|
2643 \n\ |
|
38e759e4c9e6
Issue #18147: Add diagnostic functions to ssl.SSLContext().
Christian Heimes <christian@cheimes.de>
parents:
84119
diff
changeset
|
2644 Returns quantities of loaded X.509 certificates. X.509 certificates with a\n\ |
|
38e759e4c9e6
Issue #18147: Add diagnostic functions to ssl.SSLContext().
Christian Heimes <christian@cheimes.de>
parents:
84119
diff
changeset
|
2645 CA extension and certificate revocation lists inside the context's cert\n\ |
|
38e759e4c9e6
Issue #18147: Add diagnostic functions to ssl.SSLContext().
Christian Heimes <christian@cheimes.de>
parents:
84119
diff
changeset
|
2646 store.\n\ |
|
38e759e4c9e6
Issue #18147: Add diagnostic functions to ssl.SSLContext().
Christian Heimes <christian@cheimes.de>
parents:
84119
diff
changeset
|
2647 NOTE: Certificates in a capath directory aren't loaded unless they have\n\ |
|
38e759e4c9e6
Issue #18147: Add diagnostic functions to ssl.SSLContext().
Christian Heimes <christian@cheimes.de>
parents:
84119
diff
changeset
|
2648 been used at least once."); |
|
38e759e4c9e6
Issue #18147: Add diagnostic functions to ssl.SSLContext().
Christian Heimes <christian@cheimes.de>
parents:
84119
diff
changeset
|
2649 |
|
38e759e4c9e6
Issue #18147: Add diagnostic functions to ssl.SSLContext().
Christian Heimes <christian@cheimes.de>
parents:
84119
diff
changeset
|
2650 static PyObject * |
|
38e759e4c9e6
Issue #18147: Add diagnostic functions to ssl.SSLContext().
Christian Heimes <christian@cheimes.de>
parents:
84119
diff
changeset
|
2651 cert_store_stats(PySSLContext *self) |
|
38e759e4c9e6
Issue #18147: Add diagnostic functions to ssl.SSLContext().
Christian Heimes <christian@cheimes.de>
parents:
84119
diff
changeset
|
2652 { |
|
38e759e4c9e6
Issue #18147: Add diagnostic functions to ssl.SSLContext().
Christian Heimes <christian@cheimes.de>
parents:
84119
diff
changeset
|
2653 X509_STORE *store; |
|
38e759e4c9e6
Issue #18147: Add diagnostic functions to ssl.SSLContext().
Christian Heimes <christian@cheimes.de>
parents:
84119
diff
changeset
|
2654 X509_OBJECT *obj; |
|
38e759e4c9e6
Issue #18147: Add diagnostic functions to ssl.SSLContext().
Christian Heimes <christian@cheimes.de>
parents:
84119
diff
changeset
|
2655 int x509 = 0, crl = 0, pkey = 0, ca = 0, i; |
|
38e759e4c9e6
Issue #18147: Add diagnostic functions to ssl.SSLContext().
Christian Heimes <christian@cheimes.de>
parents:
84119
diff
changeset
|
2656 |
|
38e759e4c9e6
Issue #18147: Add diagnostic functions to ssl.SSLContext().
Christian Heimes <christian@cheimes.de>
parents:
84119
diff
changeset
|
2657 store = SSL_CTX_get_cert_store(self->ctx); |
|
38e759e4c9e6
Issue #18147: Add diagnostic functions to ssl.SSLContext().
Christian Heimes <christian@cheimes.de>
parents:
84119
diff
changeset
|
2658 for (i = 0; i < sk_X509_OBJECT_num(store->objs); i++) { |
|
38e759e4c9e6
Issue #18147: Add diagnostic functions to ssl.SSLContext().
Christian Heimes <christian@cheimes.de>
parents:
84119
diff
changeset
|
2659 obj = sk_X509_OBJECT_value(store->objs, i); |
|
38e759e4c9e6
Issue #18147: Add diagnostic functions to ssl.SSLContext().
Christian Heimes <christian@cheimes.de>
parents:
84119
diff
changeset
|
2660 switch (obj->type) { |
|
38e759e4c9e6
Issue #18147: Add diagnostic functions to ssl.SSLContext().
Christian Heimes <christian@cheimes.de>
parents:
84119
diff
changeset
|
2661 case X509_LU_X509: |
|
38e759e4c9e6
Issue #18147: Add diagnostic functions to ssl.SSLContext().
Christian Heimes <christian@cheimes.de>
parents:
84119
diff
changeset
|
2662 x509++; |
|
38e759e4c9e6
Issue #18147: Add diagnostic functions to ssl.SSLContext().
Christian Heimes <christian@cheimes.de>
parents:
84119
diff
changeset
|
2663 if (X509_check_ca(obj->data.x509)) { |
|
38e759e4c9e6
Issue #18147: Add diagnostic functions to ssl.SSLContext().
Christian Heimes <christian@cheimes.de>
parents:
84119
diff
changeset
|
2664 ca++; |
|
38e759e4c9e6
Issue #18147: Add diagnostic functions to ssl.SSLContext().
Christian Heimes <christian@cheimes.de>
parents:
84119
diff
changeset
|
2665 } |
|
38e759e4c9e6
Issue #18147: Add diagnostic functions to ssl.SSLContext().
Christian Heimes <christian@cheimes.de>
parents:
84119
diff
changeset
|
2666 break; |
|
38e759e4c9e6
Issue #18147: Add diagnostic functions to ssl.SSLContext().
Christian Heimes <christian@cheimes.de>
parents:
84119
diff
changeset
|
2667 case X509_LU_CRL: |
|
38e759e4c9e6
Issue #18147: Add diagnostic functions to ssl.SSLContext().
Christian Heimes <christian@cheimes.de>
parents:
84119
diff
changeset
|
2668 crl++; |
|
38e759e4c9e6
Issue #18147: Add diagnostic functions to ssl.SSLContext().
Christian Heimes <christian@cheimes.de>
parents:
84119
diff
changeset
|
2669 break; |
|
38e759e4c9e6
Issue #18147: Add diagnostic functions to ssl.SSLContext().
Christian Heimes <christian@cheimes.de>
parents:
84119
diff
changeset
|
2670 case X509_LU_PKEY: |
|
38e759e4c9e6
Issue #18147: Add diagnostic functions to ssl.SSLContext().
Christian Heimes <christian@cheimes.de>
parents:
84119
diff
changeset
|
2671 pkey++; |
|
38e759e4c9e6
Issue #18147: Add diagnostic functions to ssl.SSLContext().
Christian Heimes <christian@cheimes.de>
parents:
84119
diff
changeset
|
2672 break; |
|
38e759e4c9e6
Issue #18147: Add diagnostic functions to ssl.SSLContext().
Christian Heimes <christian@cheimes.de>
parents:
84119
diff
changeset
|
2673 default: |
|
38e759e4c9e6
Issue #18147: Add diagnostic functions to ssl.SSLContext().
Christian Heimes <christian@cheimes.de>
parents:
84119
diff
changeset
|
2674 /* Ignore X509_LU_FAIL, X509_LU_RETRY, X509_LU_PKEY. |
|
38e759e4c9e6
Issue #18147: Add diagnostic functions to ssl.SSLContext().
Christian Heimes <christian@cheimes.de>
parents:
84119
diff
changeset
|
2675 * As far as I can tell they are internal states and never |
|
38e759e4c9e6
Issue #18147: Add diagnostic functions to ssl.SSLContext().
Christian Heimes <christian@cheimes.de>
parents:
84119
diff
changeset
|
2676 * stored in a cert store */ |
|
38e759e4c9e6
Issue #18147: Add diagnostic functions to ssl.SSLContext().
Christian Heimes <christian@cheimes.de>
parents:
84119
diff
changeset
|
2677 break; |
|
38e759e4c9e6
Issue #18147: Add diagnostic functions to ssl.SSLContext().
Christian Heimes <christian@cheimes.de>
parents:
84119
diff
changeset
|
2678 } |
|
38e759e4c9e6
Issue #18147: Add diagnostic functions to ssl.SSLContext().
Christian Heimes <christian@cheimes.de>
parents:
84119
diff
changeset
|
2679 } |
|
38e759e4c9e6
Issue #18147: Add diagnostic functions to ssl.SSLContext().
Christian Heimes <christian@cheimes.de>
parents:
84119
diff
changeset
|
2680 return Py_BuildValue("{sisisi}", "x509", x509, "crl", crl, |
|
38e759e4c9e6
Issue #18147: Add diagnostic functions to ssl.SSLContext().
Christian Heimes <christian@cheimes.de>
parents:
84119
diff
changeset
|
2681 "x509_ca", ca); |
|
38e759e4c9e6
Issue #18147: Add diagnostic functions to ssl.SSLContext().
Christian Heimes <christian@cheimes.de>
parents:
84119
diff
changeset
|
2682 } |
|
38e759e4c9e6
Issue #18147: Add diagnostic functions to ssl.SSLContext().
Christian Heimes <christian@cheimes.de>
parents:
84119
diff
changeset
|
2683 |
|
38e759e4c9e6
Issue #18147: Add diagnostic functions to ssl.SSLContext().
Christian Heimes <christian@cheimes.de>
parents:
84119
diff
changeset
|
2684 PyDoc_STRVAR(PySSL_get_ca_certs_doc, |
|
38e759e4c9e6
Issue #18147: Add diagnostic functions to ssl.SSLContext().
Christian Heimes <christian@cheimes.de>
parents:
84119
diff
changeset
|
2685 "get_ca_certs([der=False]) -> list of loaded certificate\n\ |
|
38e759e4c9e6
Issue #18147: Add diagnostic functions to ssl.SSLContext().
Christian Heimes <christian@cheimes.de>
parents:
84119
diff
changeset
|
2686 \n\ |
|
38e759e4c9e6
Issue #18147: Add diagnostic functions to ssl.SSLContext().
Christian Heimes <christian@cheimes.de>
parents:
84119
diff
changeset
|
2687 Returns a list of dicts with information of loaded CA certs. If the\n\ |
|
38e759e4c9e6
Issue #18147: Add diagnostic functions to ssl.SSLContext().
Christian Heimes <christian@cheimes.de>
parents:
84119
diff
changeset
|
2688 optional argument is True, returns a DER-encoded copy of the CA certificate.\n\ |
|
38e759e4c9e6
Issue #18147: Add diagnostic functions to ssl.SSLContext().
Christian Heimes <christian@cheimes.de>
parents:
84119
diff
changeset
|
2689 NOTE: Certificates in a capath directory aren't loaded unless they have\n\ |
|
38e759e4c9e6
Issue #18147: Add diagnostic functions to ssl.SSLContext().
Christian Heimes <christian@cheimes.de>
parents:
84119
diff
changeset
|
2690 been used at least once."); |
|
38e759e4c9e6
Issue #18147: Add diagnostic functions to ssl.SSLContext().
Christian Heimes <christian@cheimes.de>
parents:
84119
diff
changeset
|
2691 |
|
38e759e4c9e6
Issue #18147: Add diagnostic functions to ssl.SSLContext().
Christian Heimes <christian@cheimes.de>
parents:
84119
diff
changeset
|
2692 static PyObject * |
|
38e759e4c9e6
Issue #18147: Add diagnostic functions to ssl.SSLContext().
Christian Heimes <christian@cheimes.de>
parents:
84119
diff
changeset
|
2693 get_ca_certs(PySSLContext *self, PyObject *args) |
|
38e759e4c9e6
Issue #18147: Add diagnostic functions to ssl.SSLContext().
Christian Heimes <christian@cheimes.de>
parents:
84119
diff
changeset
|
2694 { |
|
38e759e4c9e6
Issue #18147: Add diagnostic functions to ssl.SSLContext().
Christian Heimes <christian@cheimes.de>
parents:
84119
diff
changeset
|
2695 X509_STORE *store; |
|
38e759e4c9e6
Issue #18147: Add diagnostic functions to ssl.SSLContext().
Christian Heimes <christian@cheimes.de>
parents:
84119
diff
changeset
|
2696 PyObject *ci = NULL, *rlist = NULL; |
|
38e759e4c9e6
Issue #18147: Add diagnostic functions to ssl.SSLContext().
Christian Heimes <christian@cheimes.de>
parents:
84119
diff
changeset
|
2697 int i; |
|
38e759e4c9e6
Issue #18147: Add diagnostic functions to ssl.SSLContext().
Christian Heimes <christian@cheimes.de>
parents:
84119
diff
changeset
|
2698 int binary_mode = 0; |
|
38e759e4c9e6
Issue #18147: Add diagnostic functions to ssl.SSLContext().
Christian Heimes <christian@cheimes.de>
parents:
84119
diff
changeset
|
2699 |
|
38e759e4c9e6
Issue #18147: Add diagnostic functions to ssl.SSLContext().
Christian Heimes <christian@cheimes.de>
parents:
84119
diff
changeset
|
2700 if (!PyArg_ParseTuple(args, "|p:get_ca_certs", &binary_mode)) { |
|
38e759e4c9e6
Issue #18147: Add diagnostic functions to ssl.SSLContext().
Christian Heimes <christian@cheimes.de>
parents:
84119
diff
changeset
|
2701 return NULL; |
|
38e759e4c9e6
Issue #18147: Add diagnostic functions to ssl.SSLContext().
Christian Heimes <christian@cheimes.de>
parents:
84119
diff
changeset
|
2702 } |
|
38e759e4c9e6
Issue #18147: Add diagnostic functions to ssl.SSLContext().
Christian Heimes <christian@cheimes.de>
parents:
84119
diff
changeset
|
2703 |
|
38e759e4c9e6
Issue #18147: Add diagnostic functions to ssl.SSLContext().
Christian Heimes <christian@cheimes.de>
parents:
84119
diff
changeset
|
2704 if ((rlist = PyList_New(0)) == NULL) { |
|
38e759e4c9e6
Issue #18147: Add diagnostic functions to ssl.SSLContext().
Christian Heimes <christian@cheimes.de>
parents:
84119
diff
changeset
|
2705 return NULL; |
|
38e759e4c9e6
Issue #18147: Add diagnostic functions to ssl.SSLContext().
Christian Heimes <christian@cheimes.de>
parents:
84119
diff
changeset
|
2706 } |
|
38e759e4c9e6
Issue #18147: Add diagnostic functions to ssl.SSLContext().
Christian Heimes <christian@cheimes.de>
parents:
84119
diff
changeset
|
2707 |
|
38e759e4c9e6
Issue #18147: Add diagnostic functions to ssl.SSLContext().
Christian Heimes <christian@cheimes.de>
parents:
84119
diff
changeset
|
2708 store = SSL_CTX_get_cert_store(self->ctx); |
|
38e759e4c9e6
Issue #18147: Add diagnostic functions to ssl.SSLContext().
Christian Heimes <christian@cheimes.de>
parents:
84119
diff
changeset
|
2709 for (i = 0; i < sk_X509_OBJECT_num(store->objs); i++) { |
|
38e759e4c9e6
Issue #18147: Add diagnostic functions to ssl.SSLContext().
Christian Heimes <christian@cheimes.de>
parents:
84119
diff
changeset
|
2710 X509_OBJECT *obj; |
|
38e759e4c9e6
Issue #18147: Add diagnostic functions to ssl.SSLContext().
Christian Heimes <christian@cheimes.de>
parents:
84119
diff
changeset
|
2711 X509 *cert; |
|
38e759e4c9e6
Issue #18147: Add diagnostic functions to ssl.SSLContext().
Christian Heimes <christian@cheimes.de>
parents:
84119
diff
changeset
|
2712 |
|
38e759e4c9e6
Issue #18147: Add diagnostic functions to ssl.SSLContext().
Christian Heimes <christian@cheimes.de>
parents:
84119
diff
changeset
|
2713 obj = sk_X509_OBJECT_value(store->objs, i); |
|
38e759e4c9e6
Issue #18147: Add diagnostic functions to ssl.SSLContext().
Christian Heimes <christian@cheimes.de>
parents:
84119
diff
changeset
|
2714 if (obj->type != X509_LU_X509) { |
|
38e759e4c9e6
Issue #18147: Add diagnostic functions to ssl.SSLContext().
Christian Heimes <christian@cheimes.de>
parents:
84119
diff
changeset
|
2715 /* not a x509 cert */ |
|
38e759e4c9e6
Issue #18147: Add diagnostic functions to ssl.SSLContext().
Christian Heimes <christian@cheimes.de>
parents:
84119
diff
changeset
|
2716 continue; |
|
38e759e4c9e6
Issue #18147: Add diagnostic functions to ssl.SSLContext().
Christian Heimes <christian@cheimes.de>
parents:
84119
diff
changeset
|
2717 } |
|
38e759e4c9e6
Issue #18147: Add diagnostic functions to ssl.SSLContext().
Christian Heimes <christian@cheimes.de>
parents:
84119
diff
changeset
|
2718 /* CA for any purpose */ |
|
38e759e4c9e6
Issue #18147: Add diagnostic functions to ssl.SSLContext().
Christian Heimes <christian@cheimes.de>
parents:
84119
diff
changeset
|
2719 cert = obj->data.x509; |
|
38e759e4c9e6
Issue #18147: Add diagnostic functions to ssl.SSLContext().
Christian Heimes <christian@cheimes.de>
parents:
84119
diff
changeset
|
2720 if (!X509_check_ca(cert)) { |
|
38e759e4c9e6
Issue #18147: Add diagnostic functions to ssl.SSLContext().
Christian Heimes <christian@cheimes.de>
parents:
84119
diff
changeset
|
2721 continue; |
|
38e759e4c9e6
Issue #18147: Add diagnostic functions to ssl.SSLContext().
Christian Heimes <christian@cheimes.de>
parents:
84119
diff
changeset
|
2722 } |
|
38e759e4c9e6
Issue #18147: Add diagnostic functions to ssl.SSLContext().
Christian Heimes <christian@cheimes.de>
parents:
84119
diff
changeset
|
2723 if (binary_mode) { |
|
38e759e4c9e6
Issue #18147: Add diagnostic functions to ssl.SSLContext().
Christian Heimes <christian@cheimes.de>
parents:
84119
diff
changeset
|
2724 ci = _certificate_to_der(cert); |
|
38e759e4c9e6
Issue #18147: Add diagnostic functions to ssl.SSLContext().
Christian Heimes <christian@cheimes.de>
parents:
84119
diff
changeset
|
2725 } else { |
|
38e759e4c9e6
Issue #18147: Add diagnostic functions to ssl.SSLContext().
Christian Heimes <christian@cheimes.de>
parents:
84119
diff
changeset
|
2726 ci = _decode_certificate(cert); |
|
38e759e4c9e6
Issue #18147: Add diagnostic functions to ssl.SSLContext().
Christian Heimes <christian@cheimes.de>
parents:
84119
diff
changeset
|
2727 } |
|
38e759e4c9e6
Issue #18147: Add diagnostic functions to ssl.SSLContext().
Christian Heimes <christian@cheimes.de>
parents:
84119
diff
changeset
|
2728 if (ci == NULL) { |
|
38e759e4c9e6
Issue #18147: Add diagnostic functions to ssl.SSLContext().
Christian Heimes <christian@cheimes.de>
parents:
84119
diff
changeset
|
2729 goto error; |
|
38e759e4c9e6
Issue #18147: Add diagnostic functions to ssl.SSLContext().
Christian Heimes <christian@cheimes.de>
parents:
84119
diff
changeset
|
2730 } |
|
38e759e4c9e6
Issue #18147: Add diagnostic functions to ssl.SSLContext().
Christian Heimes <christian@cheimes.de>
parents:
84119
diff
changeset
|
2731 if (PyList_Append(rlist, ci) == -1) { |
|
38e759e4c9e6
Issue #18147: Add diagnostic functions to ssl.SSLContext().
Christian Heimes <christian@cheimes.de>
parents:
84119
diff
changeset
|
2732 goto error; |
|
38e759e4c9e6
Issue #18147: Add diagnostic functions to ssl.SSLContext().
Christian Heimes <christian@cheimes.de>
parents:
84119
diff
changeset
|
2733 } |
|
38e759e4c9e6
Issue #18147: Add diagnostic functions to ssl.SSLContext().
Christian Heimes <christian@cheimes.de>
parents:
84119
diff
changeset
|
2734 Py_CLEAR(ci); |
|
38e759e4c9e6
Issue #18147: Add diagnostic functions to ssl.SSLContext().
Christian Heimes <christian@cheimes.de>
parents:
84119
diff
changeset
|
2735 } |
|
38e759e4c9e6
Issue #18147: Add diagnostic functions to ssl.SSLContext().
Christian Heimes <christian@cheimes.de>
parents:
84119
diff
changeset
|
2736 return rlist; |
|
38e759e4c9e6
Issue #18147: Add diagnostic functions to ssl.SSLContext().
Christian Heimes <christian@cheimes.de>
parents:
84119
diff
changeset
|
2737 |
|
38e759e4c9e6
Issue #18147: Add diagnostic functions to ssl.SSLContext().
Christian Heimes <christian@cheimes.de>
parents:
84119
diff
changeset
|
2738 error: |
|
38e759e4c9e6
Issue #18147: Add diagnostic functions to ssl.SSLContext().
Christian Heimes <christian@cheimes.de>
parents:
84119
diff
changeset
|
2739 Py_XDECREF(ci); |
|
38e759e4c9e6
Issue #18147: Add diagnostic functions to ssl.SSLContext().
Christian Heimes <christian@cheimes.de>
parents:
84119
diff
changeset
|
2740 Py_XDECREF(rlist); |
|
38e759e4c9e6
Issue #18147: Add diagnostic functions to ssl.SSLContext().
Christian Heimes <christian@cheimes.de>
parents:
84119
diff
changeset
|
2741 return NULL; |
|
38e759e4c9e6
Issue #18147: Add diagnostic functions to ssl.SSLContext().
Christian Heimes <christian@cheimes.de>
parents:
84119
diff
changeset
|
2742 } |
|
38e759e4c9e6
Issue #18147: Add diagnostic functions to ssl.SSLContext().
Christian Heimes <christian@cheimes.de>
parents:
84119
diff
changeset
|
2743 |
|
38e759e4c9e6
Issue #18147: Add diagnostic functions to ssl.SSLContext().
Christian Heimes <christian@cheimes.de>
parents:
84119
diff
changeset
|
2744 |
|
61635
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2745 static PyGetSetDef context_getsetlist[] = { |
|
61782
5ee47f0b26b0
Issue #4870: Add an `options` attribute to SSL contexts, as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
61644
diff
changeset
|
2746 {"options", (getter) get_options, |
|
5ee47f0b26b0
Issue #4870: Add an `options` attribute to SSL contexts, as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
61644
diff
changeset
|
2747 (setter) set_options, NULL}, |
|
61635
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2748 {"verify_mode", (getter) get_verify_mode, |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2749 (setter) set_verify_mode, NULL}, |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2750 {NULL}, /* sentinel */ |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2751 }; |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2752 |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2753 static struct PyMethodDef context_methods[] = { |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2754 {"_wrap_socket", (PyCFunction) context_wrap_socket, |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2755 METH_VARARGS | METH_KEYWORDS, NULL}, |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2756 {"set_ciphers", (PyCFunction) set_ciphers, |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2757 METH_VARARGS, NULL}, |
|
75865
2514a4e2b3ce
Issue #14204: The ssl module now has support for the Next Protocol Negotiation extension, if available in the underlying OpenSSL library.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75043
diff
changeset
|
2758 {"_set_npn_protocols", (PyCFunction) _set_npn_protocols, |
|
2514a4e2b3ce
Issue #14204: The ssl module now has support for the Next Protocol Negotiation extension, if available in the underlying OpenSSL library.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75043
diff
changeset
|
2759 METH_VARARGS, NULL}, |
|
61635
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2760 {"load_cert_chain", (PyCFunction) load_cert_chain, |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2761 METH_VARARGS | METH_KEYWORDS, NULL}, |
|
74129
33dea851f918
Issue #13626: Add support for SSL Diffie-Hellman key exchange, through the
Antoine Pitrou <solipsis@pitrou.net>
parents:
74103
diff
changeset
|
2762 {"load_dh_params", (PyCFunction) load_dh_params, |
|
33dea851f918
Issue #13626: Add support for SSL Diffie-Hellman key exchange, through the
Antoine Pitrou <solipsis@pitrou.net>
parents:
74103
diff
changeset
|
2763 METH_O, NULL}, |
|
61635
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2764 {"load_verify_locations", (PyCFunction) load_verify_locations, |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2765 METH_VARARGS | METH_KEYWORDS, NULL}, |
|
65223
9c723afa44da
Issue #10075: Add a session_stats() method to SSLContext objects.
Antoine Pitrou <solipsis@pitrou.net>
parents:
64403
diff
changeset
|
2766 {"session_stats", (PyCFunction) session_stats, |
|
9c723afa44da
Issue #10075: Add a session_stats() method to SSLContext objects.
Antoine Pitrou <solipsis@pitrou.net>
parents:
64403
diff
changeset
|
2767 METH_NOARGS, NULL}, |
|
66217
7826d907b765
Issue #10443: Add the SSLContext.set_default_verify_paths() method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
66114
diff
changeset
|
2768 {"set_default_verify_paths", (PyCFunction) set_default_verify_paths, |
|
7826d907b765
Issue #10443: Add the SSLContext.set_default_verify_paths() method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
66114
diff
changeset
|
2769 METH_NOARGS, NULL}, |
|
74103
ec44f2e82707
Fix ssl module compilation if ECDH support was disabled in the OpenSSL build.
Antoine Pitrou <solipsis@pitrou.net>
parents:
74091
diff
changeset
|
2770 #ifndef OPENSSL_NO_ECDH |
|
74084
8b729d65cfd2
Issue #13627: Add support for SSL Elliptic Curve-based Diffie-Hellman
Antoine Pitrou <solipsis@pitrou.net>
parents:
74075
diff
changeset
|
2771 {"set_ecdh_curve", (PyCFunction) set_ecdh_curve, |
|
8b729d65cfd2
Issue #13627: Add support for SSL Elliptic Curve-based Diffie-Hellman
Antoine Pitrou <solipsis@pitrou.net>
parents:
74075
diff
changeset
|
2772 METH_O, NULL}, |
|
74103
ec44f2e82707
Fix ssl module compilation if ECDH support was disabled in the OpenSSL build.
Antoine Pitrou <solipsis@pitrou.net>
parents:
74091
diff
changeset
|
2773 #endif |
|
81298
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
2774 {"set_servername_callback", (PyCFunction) set_servername_callback, |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
2775 METH_VARARGS, PySSL_set_servername_callback_doc}, |
|
84185
38e759e4c9e6
Issue #18147: Add diagnostic functions to ssl.SSLContext().
Christian Heimes <christian@cheimes.de>
parents:
84119
diff
changeset
|
2776 {"cert_store_stats", (PyCFunction) cert_store_stats, |
|
38e759e4c9e6
Issue #18147: Add diagnostic functions to ssl.SSLContext().
Christian Heimes <christian@cheimes.de>
parents:
84119
diff
changeset
|
2777 METH_NOARGS, PySSL_get_stats_doc}, |
|
38e759e4c9e6
Issue #18147: Add diagnostic functions to ssl.SSLContext().
Christian Heimes <christian@cheimes.de>
parents:
84119
diff
changeset
|
2778 {"get_ca_certs", (PyCFunction) get_ca_certs, |
|
38e759e4c9e6
Issue #18147: Add diagnostic functions to ssl.SSLContext().
Christian Heimes <christian@cheimes.de>
parents:
84119
diff
changeset
|
2779 METH_VARARGS, PySSL_get_ca_certs_doc}, |
|
61635
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2780 {NULL, NULL} /* sentinel */ |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2781 }; |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2782 |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2783 static PyTypeObject PySSLContext_Type = { |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2784 PyVarObject_HEAD_INIT(NULL, 0) |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2785 "_ssl._SSLContext", /*tp_name*/ |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2786 sizeof(PySSLContext), /*tp_basicsize*/ |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2787 0, /*tp_itemsize*/ |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2788 (destructor)context_dealloc, /*tp_dealloc*/ |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2789 0, /*tp_print*/ |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2790 0, /*tp_getattr*/ |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2791 0, /*tp_setattr*/ |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2792 0, /*tp_reserved*/ |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2793 0, /*tp_repr*/ |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2794 0, /*tp_as_number*/ |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2795 0, /*tp_as_sequence*/ |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2796 0, /*tp_as_mapping*/ |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2797 0, /*tp_hash*/ |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2798 0, /*tp_call*/ |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2799 0, /*tp_str*/ |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2800 0, /*tp_getattro*/ |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2801 0, /*tp_setattro*/ |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2802 0, /*tp_as_buffer*/ |
|
81298
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
2803 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/ |
|
61635
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2804 0, /*tp_doc*/ |
|
81298
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
2805 (traverseproc) context_traverse, /*tp_traverse*/ |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
2806 (inquiry) context_clear, /*tp_clear*/ |
|
61635
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2807 0, /*tp_richcompare*/ |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2808 0, /*tp_weaklistoffset*/ |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2809 0, /*tp_iter*/ |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2810 0, /*tp_iternext*/ |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2811 context_methods, /*tp_methods*/ |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2812 0, /*tp_members*/ |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2813 context_getsetlist, /*tp_getset*/ |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2814 0, /*tp_base*/ |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2815 0, /*tp_dict*/ |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2816 0, /*tp_descr_get*/ |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2817 0, /*tp_descr_set*/ |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2818 0, /*tp_dictoffset*/ |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2819 0, /*tp_init*/ |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2820 0, /*tp_alloc*/ |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2821 context_new, /*tp_new*/ |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2822 }; |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2823 |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2824 |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
2825 |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
2826 #ifdef HAVE_OPENSSL_RAND |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
2827 |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
2828 /* helper routines for seeding the SSL PRNG */ |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
2829 static PyObject * |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
2830 PySSL_RAND_add(PyObject *self, PyObject *args) |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
2831 { |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
2832 char *buf; |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
2833 int len; |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
2834 double entropy; |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
2835 |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
2836 if (!PyArg_ParseTuple(args, "s#d:RAND_add", &buf, &len, &entropy)) |
|
61537
330273ec6028
Merged revisions 81116 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61246
diff
changeset
|
2837 return NULL; |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
2838 RAND_add(buf, len, entropy); |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
2839 Py_INCREF(Py_None); |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
2840 return Py_None; |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
2841 } |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
2842 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23295
diff
changeset
|
2843 PyDoc_STRVAR(PySSL_RAND_add_doc, |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
2844 "RAND_add(string, entropy)\n\ |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
2845 \n\ |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
2846 Mix string into the OpenSSL PRNG state. entropy (a float) is a lower\n\ |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
2847 bound on the entropy contained in string. See RFC 1750."); |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
2848 |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
2849 static PyObject * |
|
70328
5c716437a83a
Issue #12049: Add RAND_bytes() and RAND_pseudo_bytes() functions to the ssl
Victor Stinner <victor.stinner@haypocalc.com>
parents:
69999
diff
changeset
|
2850 PySSL_RAND(int len, int pseudo) |
|
5c716437a83a
Issue #12049: Add RAND_bytes() and RAND_pseudo_bytes() functions to the ssl
Victor Stinner <victor.stinner@haypocalc.com>
parents:
69999
diff
changeset
|
2851 { |
|
5c716437a83a
Issue #12049: Add RAND_bytes() and RAND_pseudo_bytes() functions to the ssl
Victor Stinner <victor.stinner@haypocalc.com>
parents:
69999
diff
changeset
|
2852 int ok; |
|
5c716437a83a
Issue #12049: Add RAND_bytes() and RAND_pseudo_bytes() functions to the ssl
Victor Stinner <victor.stinner@haypocalc.com>
parents:
69999
diff
changeset
|
2853 PyObject *bytes; |
|
5c716437a83a
Issue #12049: Add RAND_bytes() and RAND_pseudo_bytes() functions to the ssl
Victor Stinner <victor.stinner@haypocalc.com>
parents:
69999
diff
changeset
|
2854 unsigned long err; |
|
5c716437a83a
Issue #12049: Add RAND_bytes() and RAND_pseudo_bytes() functions to the ssl
Victor Stinner <victor.stinner@haypocalc.com>
parents:
69999
diff
changeset
|
2855 const char *errstr; |
|
5c716437a83a
Issue #12049: Add RAND_bytes() and RAND_pseudo_bytes() functions to the ssl
Victor Stinner <victor.stinner@haypocalc.com>
parents:
69999
diff
changeset
|
2856 PyObject *v; |
|
5c716437a83a
Issue #12049: Add RAND_bytes() and RAND_pseudo_bytes() functions to the ssl
Victor Stinner <victor.stinner@haypocalc.com>
parents:
69999
diff
changeset
|
2857 |
|
5c716437a83a
Issue #12049: Add RAND_bytes() and RAND_pseudo_bytes() functions to the ssl
Victor Stinner <victor.stinner@haypocalc.com>
parents:
69999
diff
changeset
|
2858 bytes = PyBytes_FromStringAndSize(NULL, len); |
|
5c716437a83a
Issue #12049: Add RAND_bytes() and RAND_pseudo_bytes() functions to the ssl
Victor Stinner <victor.stinner@haypocalc.com>
parents:
69999
diff
changeset
|
2859 if (bytes == NULL) |
|
5c716437a83a
Issue #12049: Add RAND_bytes() and RAND_pseudo_bytes() functions to the ssl
Victor Stinner <victor.stinner@haypocalc.com>
parents:
69999
diff
changeset
|
2860 return NULL; |
|
5c716437a83a
Issue #12049: Add RAND_bytes() and RAND_pseudo_bytes() functions to the ssl
Victor Stinner <victor.stinner@haypocalc.com>
parents:
69999
diff
changeset
|
2861 if (pseudo) { |
|
5c716437a83a
Issue #12049: Add RAND_bytes() and RAND_pseudo_bytes() functions to the ssl
Victor Stinner <victor.stinner@haypocalc.com>
parents:
69999
diff
changeset
|
2862 ok = RAND_pseudo_bytes((unsigned char*)PyBytes_AS_STRING(bytes), len); |
|
5c716437a83a
Issue #12049: Add RAND_bytes() and RAND_pseudo_bytes() functions to the ssl
Victor Stinner <victor.stinner@haypocalc.com>
parents:
69999
diff
changeset
|
2863 if (ok == 0 || ok == 1) |
|
5c716437a83a
Issue #12049: Add RAND_bytes() and RAND_pseudo_bytes() functions to the ssl
Victor Stinner <victor.stinner@haypocalc.com>
parents:
69999
diff
changeset
|
2864 return Py_BuildValue("NO", bytes, ok == 1 ? Py_True : Py_False); |
|
5c716437a83a
Issue #12049: Add RAND_bytes() and RAND_pseudo_bytes() functions to the ssl
Victor Stinner <victor.stinner@haypocalc.com>
parents:
69999
diff
changeset
|
2865 } |
|
5c716437a83a
Issue #12049: Add RAND_bytes() and RAND_pseudo_bytes() functions to the ssl
Victor Stinner <victor.stinner@haypocalc.com>
parents:
69999
diff
changeset
|
2866 else { |
|
5c716437a83a
Issue #12049: Add RAND_bytes() and RAND_pseudo_bytes() functions to the ssl
Victor Stinner <victor.stinner@haypocalc.com>
parents:
69999
diff
changeset
|
2867 ok = RAND_bytes((unsigned char*)PyBytes_AS_STRING(bytes), len); |
|
5c716437a83a
Issue #12049: Add RAND_bytes() and RAND_pseudo_bytes() functions to the ssl
Victor Stinner <victor.stinner@haypocalc.com>
parents:
69999
diff
changeset
|
2868 if (ok == 1) |
|
5c716437a83a
Issue #12049: Add RAND_bytes() and RAND_pseudo_bytes() functions to the ssl
Victor Stinner <victor.stinner@haypocalc.com>
parents:
69999
diff
changeset
|
2869 return bytes; |
|
5c716437a83a
Issue #12049: Add RAND_bytes() and RAND_pseudo_bytes() functions to the ssl
Victor Stinner <victor.stinner@haypocalc.com>
parents:
69999
diff
changeset
|
2870 } |
|
5c716437a83a
Issue #12049: Add RAND_bytes() and RAND_pseudo_bytes() functions to the ssl
Victor Stinner <victor.stinner@haypocalc.com>
parents:
69999
diff
changeset
|
2871 Py_DECREF(bytes); |
|
5c716437a83a
Issue #12049: Add RAND_bytes() and RAND_pseudo_bytes() functions to the ssl
Victor Stinner <victor.stinner@haypocalc.com>
parents:
69999
diff
changeset
|
2872 |
|
5c716437a83a
Issue #12049: Add RAND_bytes() and RAND_pseudo_bytes() functions to the ssl
Victor Stinner <victor.stinner@haypocalc.com>
parents:
69999
diff
changeset
|
2873 err = ERR_get_error(); |
|
5c716437a83a
Issue #12049: Add RAND_bytes() and RAND_pseudo_bytes() functions to the ssl
Victor Stinner <victor.stinner@haypocalc.com>
parents:
69999
diff
changeset
|
2874 errstr = ERR_reason_error_string(err); |
|
5c716437a83a
Issue #12049: Add RAND_bytes() and RAND_pseudo_bytes() functions to the ssl
Victor Stinner <victor.stinner@haypocalc.com>
parents:
69999
diff
changeset
|
2875 v = Py_BuildValue("(ks)", err, errstr); |
|
5c716437a83a
Issue #12049: Add RAND_bytes() and RAND_pseudo_bytes() functions to the ssl
Victor Stinner <victor.stinner@haypocalc.com>
parents:
69999
diff
changeset
|
2876 if (v != NULL) { |
|
5c716437a83a
Issue #12049: Add RAND_bytes() and RAND_pseudo_bytes() functions to the ssl
Victor Stinner <victor.stinner@haypocalc.com>
parents:
69999
diff
changeset
|
2877 PyErr_SetObject(PySSLErrorObject, v); |
|
5c716437a83a
Issue #12049: Add RAND_bytes() and RAND_pseudo_bytes() functions to the ssl
Victor Stinner <victor.stinner@haypocalc.com>
parents:
69999
diff
changeset
|
2878 Py_DECREF(v); |
|
5c716437a83a
Issue #12049: Add RAND_bytes() and RAND_pseudo_bytes() functions to the ssl
Victor Stinner <victor.stinner@haypocalc.com>
parents:
69999
diff
changeset
|
2879 } |
|
5c716437a83a
Issue #12049: Add RAND_bytes() and RAND_pseudo_bytes() functions to the ssl
Victor Stinner <victor.stinner@haypocalc.com>
parents:
69999
diff
changeset
|
2880 return NULL; |
|
5c716437a83a
Issue #12049: Add RAND_bytes() and RAND_pseudo_bytes() functions to the ssl
Victor Stinner <victor.stinner@haypocalc.com>
parents:
69999
diff
changeset
|
2881 } |
|
5c716437a83a
Issue #12049: Add RAND_bytes() and RAND_pseudo_bytes() functions to the ssl
Victor Stinner <victor.stinner@haypocalc.com>
parents:
69999
diff
changeset
|
2882 |
|
5c716437a83a
Issue #12049: Add RAND_bytes() and RAND_pseudo_bytes() functions to the ssl
Victor Stinner <victor.stinner@haypocalc.com>
parents:
69999
diff
changeset
|
2883 static PyObject * |
|
5c716437a83a
Issue #12049: Add RAND_bytes() and RAND_pseudo_bytes() functions to the ssl
Victor Stinner <victor.stinner@haypocalc.com>
parents:
69999
diff
changeset
|
2884 PySSL_RAND_bytes(PyObject *self, PyObject *args) |
|
5c716437a83a
Issue #12049: Add RAND_bytes() and RAND_pseudo_bytes() functions to the ssl
Victor Stinner <victor.stinner@haypocalc.com>
parents:
69999
diff
changeset
|
2885 { |
|
5c716437a83a
Issue #12049: Add RAND_bytes() and RAND_pseudo_bytes() functions to the ssl
Victor Stinner <victor.stinner@haypocalc.com>
parents:
69999
diff
changeset
|
2886 int len; |
|
5c716437a83a
Issue #12049: Add RAND_bytes() and RAND_pseudo_bytes() functions to the ssl
Victor Stinner <victor.stinner@haypocalc.com>
parents:
69999
diff
changeset
|
2887 if (!PyArg_ParseTuple(args, "i:RAND_bytes", &len)) |
|
5c716437a83a
Issue #12049: Add RAND_bytes() and RAND_pseudo_bytes() functions to the ssl
Victor Stinner <victor.stinner@haypocalc.com>
parents:
69999
diff
changeset
|
2888 return NULL; |
|
5c716437a83a
Issue #12049: Add RAND_bytes() and RAND_pseudo_bytes() functions to the ssl
Victor Stinner <victor.stinner@haypocalc.com>
parents:
69999
diff
changeset
|
2889 return PySSL_RAND(len, 0); |
|
5c716437a83a
Issue #12049: Add RAND_bytes() and RAND_pseudo_bytes() functions to the ssl
Victor Stinner <victor.stinner@haypocalc.com>
parents:
69999
diff
changeset
|
2890 } |
|
5c716437a83a
Issue #12049: Add RAND_bytes() and RAND_pseudo_bytes() functions to the ssl
Victor Stinner <victor.stinner@haypocalc.com>
parents:
69999
diff
changeset
|
2891 |
|
5c716437a83a
Issue #12049: Add RAND_bytes() and RAND_pseudo_bytes() functions to the ssl
Victor Stinner <victor.stinner@haypocalc.com>
parents:
69999
diff
changeset
|
2892 PyDoc_STRVAR(PySSL_RAND_bytes_doc, |
|
5c716437a83a
Issue #12049: Add RAND_bytes() and RAND_pseudo_bytes() functions to the ssl
Victor Stinner <victor.stinner@haypocalc.com>
parents:
69999
diff
changeset
|
2893 "RAND_bytes(n) -> bytes\n\ |
|
5c716437a83a
Issue #12049: Add RAND_bytes() and RAND_pseudo_bytes() functions to the ssl
Victor Stinner <victor.stinner@haypocalc.com>
parents:
69999
diff
changeset
|
2894 \n\ |
|
5c716437a83a
Issue #12049: Add RAND_bytes() and RAND_pseudo_bytes() functions to the ssl
Victor Stinner <victor.stinner@haypocalc.com>
parents:
69999
diff
changeset
|
2895 Generate n cryptographically strong pseudo-random bytes."); |
|
5c716437a83a
Issue #12049: Add RAND_bytes() and RAND_pseudo_bytes() functions to the ssl
Victor Stinner <victor.stinner@haypocalc.com>
parents:
69999
diff
changeset
|
2896 |
|
5c716437a83a
Issue #12049: Add RAND_bytes() and RAND_pseudo_bytes() functions to the ssl
Victor Stinner <victor.stinner@haypocalc.com>
parents:
69999
diff
changeset
|
2897 static PyObject * |
|
5c716437a83a
Issue #12049: Add RAND_bytes() and RAND_pseudo_bytes() functions to the ssl
Victor Stinner <victor.stinner@haypocalc.com>
parents:
69999
diff
changeset
|
2898 PySSL_RAND_pseudo_bytes(PyObject *self, PyObject *args) |
|
5c716437a83a
Issue #12049: Add RAND_bytes() and RAND_pseudo_bytes() functions to the ssl
Victor Stinner <victor.stinner@haypocalc.com>
parents:
69999
diff
changeset
|
2899 { |
|
5c716437a83a
Issue #12049: Add RAND_bytes() and RAND_pseudo_bytes() functions to the ssl
Victor Stinner <victor.stinner@haypocalc.com>
parents:
69999
diff
changeset
|
2900 int len; |
|
5c716437a83a
Issue #12049: Add RAND_bytes() and RAND_pseudo_bytes() functions to the ssl
Victor Stinner <victor.stinner@haypocalc.com>
parents:
69999
diff
changeset
|
2901 if (!PyArg_ParseTuple(args, "i:RAND_pseudo_bytes", &len)) |
|
5c716437a83a
Issue #12049: Add RAND_bytes() and RAND_pseudo_bytes() functions to the ssl
Victor Stinner <victor.stinner@haypocalc.com>
parents:
69999
diff
changeset
|
2902 return NULL; |
|
5c716437a83a
Issue #12049: Add RAND_bytes() and RAND_pseudo_bytes() functions to the ssl
Victor Stinner <victor.stinner@haypocalc.com>
parents:
69999
diff
changeset
|
2903 return PySSL_RAND(len, 1); |
|
5c716437a83a
Issue #12049: Add RAND_bytes() and RAND_pseudo_bytes() functions to the ssl
Victor Stinner <victor.stinner@haypocalc.com>
parents:
69999
diff
changeset
|
2904 } |
|
5c716437a83a
Issue #12049: Add RAND_bytes() and RAND_pseudo_bytes() functions to the ssl
Victor Stinner <victor.stinner@haypocalc.com>
parents:
69999
diff
changeset
|
2905 |
|
5c716437a83a
Issue #12049: Add RAND_bytes() and RAND_pseudo_bytes() functions to the ssl
Victor Stinner <victor.stinner@haypocalc.com>
parents:
69999
diff
changeset
|
2906 PyDoc_STRVAR(PySSL_RAND_pseudo_bytes_doc, |
|
5c716437a83a
Issue #12049: Add RAND_bytes() and RAND_pseudo_bytes() functions to the ssl
Victor Stinner <victor.stinner@haypocalc.com>
parents:
69999
diff
changeset
|
2907 "RAND_pseudo_bytes(n) -> (bytes, is_cryptographic)\n\ |
|
5c716437a83a
Issue #12049: Add RAND_bytes() and RAND_pseudo_bytes() functions to the ssl
Victor Stinner <victor.stinner@haypocalc.com>
parents:
69999
diff
changeset
|
2908 \n\ |
|
5c716437a83a
Issue #12049: Add RAND_bytes() and RAND_pseudo_bytes() functions to the ssl
Victor Stinner <victor.stinner@haypocalc.com>
parents:
69999
diff
changeset
|
2909 Generate n pseudo-random bytes. is_cryptographic is True if the bytes\ |
|
5c716437a83a
Issue #12049: Add RAND_bytes() and RAND_pseudo_bytes() functions to the ssl
Victor Stinner <victor.stinner@haypocalc.com>
parents:
69999
diff
changeset
|
2910 generated are cryptographically strong."); |
|
5c716437a83a
Issue #12049: Add RAND_bytes() and RAND_pseudo_bytes() functions to the ssl
Victor Stinner <victor.stinner@haypocalc.com>
parents:
69999
diff
changeset
|
2911 |
|
5c716437a83a
Issue #12049: Add RAND_bytes() and RAND_pseudo_bytes() functions to the ssl
Victor Stinner <victor.stinner@haypocalc.com>
parents:
69999
diff
changeset
|
2912 static PyObject * |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
2913 PySSL_RAND_status(PyObject *self) |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
2914 { |
|
44099
f324631462a2
Cleanup: Replaced most PyInt_ aliases with PyLong_ and disabled the aliases in intobject.h
Christian Heimes <christian@cheimes.de>
parents:
43948
diff
changeset
|
2915 return PyLong_FromLong(RAND_status()); |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
2916 } |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
2917 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23295
diff
changeset
|
2918 PyDoc_STRVAR(PySSL_RAND_status_doc, |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
2919 "RAND_status() -> 0 or 1\n\ |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
2920 \n\ |
|
43869
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
2921 Returns 1 if the OpenSSL PRNG has been seeded with enough data and 0 if not.\n\ |
|
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
2922 It is necessary to seed the PRNG with RAND_add() on some platforms before\n\ |
|
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
2923 using the ssl() function."); |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
2924 |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
2925 static PyObject * |
|
61641
a09eb3d59ff7
Issue #8477: ssl.RAND_egd() supports str with surrogates and bytes for the path
Victor Stinner <victor.stinner@haypocalc.com>
parents:
61639
diff
changeset
|
2926 PySSL_RAND_egd(PyObject *self, PyObject *args) |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
2927 { |
|
61641
a09eb3d59ff7
Issue #8477: ssl.RAND_egd() supports str with surrogates and bytes for the path
Victor Stinner <victor.stinner@haypocalc.com>
parents:
61639
diff
changeset
|
2928 PyObject *path; |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
2929 int bytes; |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
2930 |
|
78983
827bb0554f1f
Closes #15793: Stack corruption in ssl.RAND_egd()
Jesus Cea <jcea@jcea.es>
parents:
78604
diff
changeset
|
2931 if (!PyArg_ParseTuple(args, "O&:RAND_egd", |
|
61641
a09eb3d59ff7
Issue #8477: ssl.RAND_egd() supports str with surrogates and bytes for the path
Victor Stinner <victor.stinner@haypocalc.com>
parents:
61639
diff
changeset
|
2932 PyUnicode_FSConverter, &path)) |
|
a09eb3d59ff7
Issue #8477: ssl.RAND_egd() supports str with surrogates and bytes for the path
Victor Stinner <victor.stinner@haypocalc.com>
parents:
61639
diff
changeset
|
2933 return NULL; |
|
a09eb3d59ff7
Issue #8477: ssl.RAND_egd() supports str with surrogates and bytes for the path
Victor Stinner <victor.stinner@haypocalc.com>
parents:
61639
diff
changeset
|
2934 |
|
a09eb3d59ff7
Issue #8477: ssl.RAND_egd() supports str with surrogates and bytes for the path
Victor Stinner <victor.stinner@haypocalc.com>
parents:
61639
diff
changeset
|
2935 bytes = RAND_egd(PyBytes_AsString(path)); |
|
a09eb3d59ff7
Issue #8477: ssl.RAND_egd() supports str with surrogates and bytes for the path
Victor Stinner <victor.stinner@haypocalc.com>
parents:
61639
diff
changeset
|
2936 Py_DECREF(path); |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
2937 if (bytes == -1) { |
|
61537
330273ec6028
Merged revisions 81116 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61246
diff
changeset
|
2938 PyErr_SetString(PySSLErrorObject, |
|
330273ec6028
Merged revisions 81116 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61246
diff
changeset
|
2939 "EGD connection failed or EGD did not return " |
|
330273ec6028
Merged revisions 81116 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61246
diff
changeset
|
2940 "enough data to seed the PRNG"); |
|
330273ec6028
Merged revisions 81116 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61246
diff
changeset
|
2941 return NULL; |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
2942 } |
|
44099
f324631462a2
Cleanup: Replaced most PyInt_ aliases with PyLong_ and disabled the aliases in intobject.h
Christian Heimes <christian@cheimes.de>
parents:
43948
diff
changeset
|
2943 return PyLong_FromLong(bytes); |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
2944 } |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
2945 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23295
diff
changeset
|
2946 PyDoc_STRVAR(PySSL_RAND_egd_doc, |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
2947 "RAND_egd(path) -> bytes\n\ |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
2948 \n\ |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
2949 Queries the entropy gather daemon (EGD) on the socket named by 'path'.\n\ |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
2950 Returns number of bytes read. Raises SSLError if connection to EGD\n\ |
|
85236
ae91252943bf
Issue 18768: Correct doc string of RAND_edg(). Patch by Vajrasky Kok.
Christian Heimes <christian@cheimes.de>
parents:
85233
diff
changeset
|
2951 fails or if it does not provide enough data to seed PRNG."); |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
2952 |
|
85290
8e1194c39bed
Issue #18747: Re-seed OpenSSL's pseudo-random number generator after fork.
Christian Heimes <christian@cheimes.de>
parents:
85263
diff
changeset
|
2953 /* Seed OpenSSL's PRNG at fork(), http://bugs.python.org/issue18747 |
|
8e1194c39bed
Issue #18747: Re-seed OpenSSL's pseudo-random number generator after fork.
Christian Heimes <christian@cheimes.de>
parents:
85263
diff
changeset
|
2954 * |
|
85314
39c9dbed3aa1
Issue #18747: Use a parent atfork handler instead of a child atfork handler.
Christian Heimes <christian@cheimes.de>
parents:
85290
diff
changeset
|
2955 * The parent handler seeds the PRNG from pseudo-random data like pid, the |
|
85378
8b962e831ff0
Issue #18747: Fix spelling errors in my commit message and comments,
Christian Heimes <christian@cheimes.de>
parents:
85314
diff
changeset
|
2956 * current time (miliseconds or seconds) and an uninitialized array. |
|
85314
39c9dbed3aa1
Issue #18747: Use a parent atfork handler instead of a child atfork handler.
Christian Heimes <christian@cheimes.de>
parents:
85290
diff
changeset
|
2957 * The array contains stack variables that are impossible to predict |
|
85290
8e1194c39bed
Issue #18747: Re-seed OpenSSL's pseudo-random number generator after fork.
Christian Heimes <christian@cheimes.de>
parents:
85263
diff
changeset
|
2958 * on most systems, e.g. function return address (subject to ASLR), the |
|
8e1194c39bed
Issue #18747: Re-seed OpenSSL's pseudo-random number generator after fork.
Christian Heimes <christian@cheimes.de>
parents:
85263
diff
changeset
|
2959 * stack protection canary and automatic variables. |
|
8e1194c39bed
Issue #18747: Re-seed OpenSSL's pseudo-random number generator after fork.
Christian Heimes <christian@cheimes.de>
parents:
85263
diff
changeset
|
2960 * The code is inspired by Apache's ssl_rand_seed() function. |
|
8e1194c39bed
Issue #18747: Re-seed OpenSSL's pseudo-random number generator after fork.
Christian Heimes <christian@cheimes.de>
parents:
85263
diff
changeset
|
2961 * |
|
8e1194c39bed
Issue #18747: Re-seed OpenSSL's pseudo-random number generator after fork.
Christian Heimes <christian@cheimes.de>
parents:
85263
diff
changeset
|
2962 * Note: |
|
8e1194c39bed
Issue #18747: Re-seed OpenSSL's pseudo-random number generator after fork.
Christian Heimes <christian@cheimes.de>
parents:
85263
diff
changeset
|
2963 * The code uses pthread_atfork() until Python has a proper atfork API. The |
|
85314
39c9dbed3aa1
Issue #18747: Use a parent atfork handler instead of a child atfork handler.
Christian Heimes <christian@cheimes.de>
parents:
85290
diff
changeset
|
2964 * handlers are not removed from the child process. A parent handler is used |
|
85378
8b962e831ff0
Issue #18747: Fix spelling errors in my commit message and comments,
Christian Heimes <christian@cheimes.de>
parents:
85314
diff
changeset
|
2965 * instead of a child handler because fork() is supposed to be async-signal |
|
85314
39c9dbed3aa1
Issue #18747: Use a parent atfork handler instead of a child atfork handler.
Christian Heimes <christian@cheimes.de>
parents:
85290
diff
changeset
|
2966 * safe but the handler calls unsafe functions. |
|
85290
8e1194c39bed
Issue #18747: Re-seed OpenSSL's pseudo-random number generator after fork.
Christian Heimes <christian@cheimes.de>
parents:
85263
diff
changeset
|
2967 */ |
|
8e1194c39bed
Issue #18747: Re-seed OpenSSL's pseudo-random number generator after fork.
Christian Heimes <christian@cheimes.de>
parents:
85263
diff
changeset
|
2968 |
|
8e1194c39bed
Issue #18747: Re-seed OpenSSL's pseudo-random number generator after fork.
Christian Heimes <christian@cheimes.de>
parents:
85263
diff
changeset
|
2969 #if defined(HAVE_PTHREAD_ATFORK) && defined(WITH_THREAD) |
|
8e1194c39bed
Issue #18747: Re-seed OpenSSL's pseudo-random number generator after fork.
Christian Heimes <christian@cheimes.de>
parents:
85263
diff
changeset
|
2970 #define PYSSL_RAND_ATFORK 1 |
|
8e1194c39bed
Issue #18747: Re-seed OpenSSL's pseudo-random number generator after fork.
Christian Heimes <christian@cheimes.de>
parents:
85263
diff
changeset
|
2971 |
|
8e1194c39bed
Issue #18747: Re-seed OpenSSL's pseudo-random number generator after fork.
Christian Heimes <christian@cheimes.de>
parents:
85263
diff
changeset
|
2972 static void |
|
85314
39c9dbed3aa1
Issue #18747: Use a parent atfork handler instead of a child atfork handler.
Christian Heimes <christian@cheimes.de>
parents:
85290
diff
changeset
|
2973 PySSL_RAND_atfork_parent(void) |
|
85290
8e1194c39bed
Issue #18747: Re-seed OpenSSL's pseudo-random number generator after fork.
Christian Heimes <christian@cheimes.de>
parents:
85263
diff
changeset
|
2974 { |
|
8e1194c39bed
Issue #18747: Re-seed OpenSSL's pseudo-random number generator after fork.
Christian Heimes <christian@cheimes.de>
parents:
85263
diff
changeset
|
2975 struct { |
|
8e1194c39bed
Issue #18747: Re-seed OpenSSL's pseudo-random number generator after fork.
Christian Heimes <christian@cheimes.de>
parents:
85263
diff
changeset
|
2976 char stack[128]; /* uninitialized (!) stack data, 128 is an |
|
8e1194c39bed
Issue #18747: Re-seed OpenSSL's pseudo-random number generator after fork.
Christian Heimes <christian@cheimes.de>
parents:
85263
diff
changeset
|
2977 arbitrary number. */ |
|
8e1194c39bed
Issue #18747: Re-seed OpenSSL's pseudo-random number generator after fork.
Christian Heimes <christian@cheimes.de>
parents:
85263
diff
changeset
|
2978 pid_t pid; /* current pid */ |
|
8e1194c39bed
Issue #18747: Re-seed OpenSSL's pseudo-random number generator after fork.
Christian Heimes <christian@cheimes.de>
parents:
85263
diff
changeset
|
2979 _PyTime_timeval tp; /* current time */ |
|
8e1194c39bed
Issue #18747: Re-seed OpenSSL's pseudo-random number generator after fork.
Christian Heimes <christian@cheimes.de>
parents:
85263
diff
changeset
|
2980 } seed; |
|
8e1194c39bed
Issue #18747: Re-seed OpenSSL's pseudo-random number generator after fork.
Christian Heimes <christian@cheimes.de>
parents:
85263
diff
changeset
|
2981 |
|
8e1194c39bed
Issue #18747: Re-seed OpenSSL's pseudo-random number generator after fork.
Christian Heimes <christian@cheimes.de>
parents:
85263
diff
changeset
|
2982 #ifdef WITH_VALGRIND |
|
8e1194c39bed
Issue #18747: Re-seed OpenSSL's pseudo-random number generator after fork.
Christian Heimes <christian@cheimes.de>
parents:
85263
diff
changeset
|
2983 VALGRIND_MAKE_MEM_DEFINED(seed.stack, sizeof(seed.stack)); |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
2984 #endif |
|
85290
8e1194c39bed
Issue #18747: Re-seed OpenSSL's pseudo-random number generator after fork.
Christian Heimes <christian@cheimes.de>
parents:
85263
diff
changeset
|
2985 seed.pid = getpid(); |
|
8e1194c39bed
Issue #18747: Re-seed OpenSSL's pseudo-random number generator after fork.
Christian Heimes <christian@cheimes.de>
parents:
85263
diff
changeset
|
2986 _PyTime_gettimeofday(&(seed.tp)); |
|
8e1194c39bed
Issue #18747: Re-seed OpenSSL's pseudo-random number generator after fork.
Christian Heimes <christian@cheimes.de>
parents:
85263
diff
changeset
|
2987 RAND_add((unsigned char *)&seed, sizeof(seed), 0.0); |
|
8e1194c39bed
Issue #18747: Re-seed OpenSSL's pseudo-random number generator after fork.
Christian Heimes <christian@cheimes.de>
parents:
85263
diff
changeset
|
2988 } |
|
8e1194c39bed
Issue #18747: Re-seed OpenSSL's pseudo-random number generator after fork.
Christian Heimes <christian@cheimes.de>
parents:
85263
diff
changeset
|
2989 |
|
8e1194c39bed
Issue #18747: Re-seed OpenSSL's pseudo-random number generator after fork.
Christian Heimes <christian@cheimes.de>
parents:
85263
diff
changeset
|
2990 static int |
|
8e1194c39bed
Issue #18747: Re-seed OpenSSL's pseudo-random number generator after fork.
Christian Heimes <christian@cheimes.de>
parents:
85263
diff
changeset
|
2991 PySSL_RAND_atfork(void) |
|
8e1194c39bed
Issue #18747: Re-seed OpenSSL's pseudo-random number generator after fork.
Christian Heimes <christian@cheimes.de>
parents:
85263
diff
changeset
|
2992 { |
|
8e1194c39bed
Issue #18747: Re-seed OpenSSL's pseudo-random number generator after fork.
Christian Heimes <christian@cheimes.de>
parents:
85263
diff
changeset
|
2993 static int registered = 0; |
|
8e1194c39bed
Issue #18747: Re-seed OpenSSL's pseudo-random number generator after fork.
Christian Heimes <christian@cheimes.de>
parents:
85263
diff
changeset
|
2994 int retval; |
|
8e1194c39bed
Issue #18747: Re-seed OpenSSL's pseudo-random number generator after fork.
Christian Heimes <christian@cheimes.de>
parents:
85263
diff
changeset
|
2995 |
|
8e1194c39bed
Issue #18747: Re-seed OpenSSL's pseudo-random number generator after fork.
Christian Heimes <christian@cheimes.de>
parents:
85263
diff
changeset
|
2996 if (registered) |
|
8e1194c39bed
Issue #18747: Re-seed OpenSSL's pseudo-random number generator after fork.
Christian Heimes <christian@cheimes.de>
parents:
85263
diff
changeset
|
2997 return 0; |
|
8e1194c39bed
Issue #18747: Re-seed OpenSSL's pseudo-random number generator after fork.
Christian Heimes <christian@cheimes.de>
parents:
85263
diff
changeset
|
2998 |
|
8e1194c39bed
Issue #18747: Re-seed OpenSSL's pseudo-random number generator after fork.
Christian Heimes <christian@cheimes.de>
parents:
85263
diff
changeset
|
2999 retval = pthread_atfork(NULL, /* prepare */ |
|
85314
39c9dbed3aa1
Issue #18747: Use a parent atfork handler instead of a child atfork handler.
Christian Heimes <christian@cheimes.de>
parents:
85290
diff
changeset
|
3000 PySSL_RAND_atfork_parent, /* parent */ |
|
39c9dbed3aa1
Issue #18747: Use a parent atfork handler instead of a child atfork handler.
Christian Heimes <christian@cheimes.de>
parents:
85290
diff
changeset
|
3001 NULL); /* child */ |
|
85290
8e1194c39bed
Issue #18747: Re-seed OpenSSL's pseudo-random number generator after fork.
Christian Heimes <christian@cheimes.de>
parents:
85263
diff
changeset
|
3002 if (retval != 0) { |
|
8e1194c39bed
Issue #18747: Re-seed OpenSSL's pseudo-random number generator after fork.
Christian Heimes <christian@cheimes.de>
parents:
85263
diff
changeset
|
3003 PyErr_SetFromErrno(PyExc_OSError); |
|
8e1194c39bed
Issue #18747: Re-seed OpenSSL's pseudo-random number generator after fork.
Christian Heimes <christian@cheimes.de>
parents:
85263
diff
changeset
|
3004 return -1; |
|
8e1194c39bed
Issue #18747: Re-seed OpenSSL's pseudo-random number generator after fork.
Christian Heimes <christian@cheimes.de>
parents:
85263
diff
changeset
|
3005 } |
|
8e1194c39bed
Issue #18747: Re-seed OpenSSL's pseudo-random number generator after fork.
Christian Heimes <christian@cheimes.de>
parents:
85263
diff
changeset
|
3006 registered = 1; |
|
8e1194c39bed
Issue #18747: Re-seed OpenSSL's pseudo-random number generator after fork.
Christian Heimes <christian@cheimes.de>
parents:
85263
diff
changeset
|
3007 return 0; |
|
8e1194c39bed
Issue #18747: Re-seed OpenSSL's pseudo-random number generator after fork.
Christian Heimes <christian@cheimes.de>
parents:
85263
diff
changeset
|
3008 } |
|
8e1194c39bed
Issue #18747: Re-seed OpenSSL's pseudo-random number generator after fork.
Christian Heimes <christian@cheimes.de>
parents:
85263
diff
changeset
|
3009 #endif /* HAVE_PTHREAD_ATFORK */ |
|
8e1194c39bed
Issue #18747: Re-seed OpenSSL's pseudo-random number generator after fork.
Christian Heimes <christian@cheimes.de>
parents:
85263
diff
changeset
|
3010 |
|
8e1194c39bed
Issue #18747: Re-seed OpenSSL's pseudo-random number generator after fork.
Christian Heimes <christian@cheimes.de>
parents:
85263
diff
changeset
|
3011 #endif /* HAVE_OPENSSL_RAND */ |
|
8e1194c39bed
Issue #18747: Re-seed OpenSSL's pseudo-random number generator after fork.
Christian Heimes <christian@cheimes.de>
parents:
85263
diff
changeset
|
3012 |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
3013 |
|
84068
a4d31e56075d
Issue #18143: Implement ssl.get_default_verify_paths() in order to debug
Christian Heimes <christian@cheimes.de>
parents:
83918
diff
changeset
|
3014 PyDoc_STRVAR(PySSL_get_default_verify_paths_doc, |
|
a4d31e56075d
Issue #18143: Implement ssl.get_default_verify_paths() in order to debug
Christian Heimes <christian@cheimes.de>
parents:
83918
diff
changeset
|
3015 "get_default_verify_paths() -> tuple\n\ |
|
a4d31e56075d
Issue #18143: Implement ssl.get_default_verify_paths() in order to debug
Christian Heimes <christian@cheimes.de>
parents:
83918
diff
changeset
|
3016 \n\ |
|
a4d31e56075d
Issue #18143: Implement ssl.get_default_verify_paths() in order to debug
Christian Heimes <christian@cheimes.de>
parents:
83918
diff
changeset
|
3017 Return search paths and environment vars that are used by SSLContext's\n\ |
|
a4d31e56075d
Issue #18143: Implement ssl.get_default_verify_paths() in order to debug
Christian Heimes <christian@cheimes.de>
parents:
83918
diff
changeset
|
3018 set_default_verify_paths() to load default CAs. The values are\n\ |
|
a4d31e56075d
Issue #18143: Implement ssl.get_default_verify_paths() in order to debug
Christian Heimes <christian@cheimes.de>
parents:
83918
diff
changeset
|
3019 'cert_file_env', 'cert_file', 'cert_dir_env', 'cert_dir'."); |
|
a4d31e56075d
Issue #18143: Implement ssl.get_default_verify_paths() in order to debug
Christian Heimes <christian@cheimes.de>
parents:
83918
diff
changeset
|
3020 |
|
a4d31e56075d
Issue #18143: Implement ssl.get_default_verify_paths() in order to debug
Christian Heimes <christian@cheimes.de>
parents:
83918
diff
changeset
|
3021 static PyObject * |
|
84119
5f7e12eb65b8
Simplify return value of ssl.get_default_verify_paths
Christian Heimes <christian@cheimes.de>
parents:
84077
diff
changeset
|
3022 PySSL_get_default_verify_paths(PyObject *self) |
|
84068
a4d31e56075d
Issue #18143: Implement ssl.get_default_verify_paths() in order to debug
Christian Heimes <christian@cheimes.de>
parents:
83918
diff
changeset
|
3023 { |
|
a4d31e56075d
Issue #18143: Implement ssl.get_default_verify_paths() in order to debug
Christian Heimes <christian@cheimes.de>
parents:
83918
diff
changeset
|
3024 PyObject *ofile_env = NULL; |
|
a4d31e56075d
Issue #18143: Implement ssl.get_default_verify_paths() in order to debug
Christian Heimes <christian@cheimes.de>
parents:
83918
diff
changeset
|
3025 PyObject *ofile = NULL; |
|
a4d31e56075d
Issue #18143: Implement ssl.get_default_verify_paths() in order to debug
Christian Heimes <christian@cheimes.de>
parents:
83918
diff
changeset
|
3026 PyObject *odir_env = NULL; |
|
a4d31e56075d
Issue #18143: Implement ssl.get_default_verify_paths() in order to debug
Christian Heimes <christian@cheimes.de>
parents:
83918
diff
changeset
|
3027 PyObject *odir = NULL; |
|
a4d31e56075d
Issue #18143: Implement ssl.get_default_verify_paths() in order to debug
Christian Heimes <christian@cheimes.de>
parents:
83918
diff
changeset
|
3028 |
|
a4d31e56075d
Issue #18143: Implement ssl.get_default_verify_paths() in order to debug
Christian Heimes <christian@cheimes.de>
parents:
83918
diff
changeset
|
3029 #define convert(info, target) { \ |
|
a4d31e56075d
Issue #18143: Implement ssl.get_default_verify_paths() in order to debug
Christian Heimes <christian@cheimes.de>
parents:
83918
diff
changeset
|
3030 const char *tmp = (info); \ |
|
a4d31e56075d
Issue #18143: Implement ssl.get_default_verify_paths() in order to debug
Christian Heimes <christian@cheimes.de>
parents:
83918
diff
changeset
|
3031 target = NULL; \ |
|
a4d31e56075d
Issue #18143: Implement ssl.get_default_verify_paths() in order to debug
Christian Heimes <christian@cheimes.de>
parents:
83918
diff
changeset
|
3032 if (!tmp) { Py_INCREF(Py_None); target = Py_None; } \ |
|
a4d31e56075d
Issue #18143: Implement ssl.get_default_verify_paths() in order to debug
Christian Heimes <christian@cheimes.de>
parents:
83918
diff
changeset
|
3033 else if ((target = PyUnicode_DecodeFSDefault(tmp)) == NULL) { \ |
|
a4d31e56075d
Issue #18143: Implement ssl.get_default_verify_paths() in order to debug
Christian Heimes <christian@cheimes.de>
parents:
83918
diff
changeset
|
3034 target = PyBytes_FromString(tmp); } \ |
|
a4d31e56075d
Issue #18143: Implement ssl.get_default_verify_paths() in order to debug
Christian Heimes <christian@cheimes.de>
parents:
83918
diff
changeset
|
3035 if (!target) goto error; \ |
|
a4d31e56075d
Issue #18143: Implement ssl.get_default_verify_paths() in order to debug
Christian Heimes <christian@cheimes.de>
parents:
83918
diff
changeset
|
3036 } while(0) |
|
a4d31e56075d
Issue #18143: Implement ssl.get_default_verify_paths() in order to debug
Christian Heimes <christian@cheimes.de>
parents:
83918
diff
changeset
|
3037 |
|
a4d31e56075d
Issue #18143: Implement ssl.get_default_verify_paths() in order to debug
Christian Heimes <christian@cheimes.de>
parents:
83918
diff
changeset
|
3038 convert(X509_get_default_cert_file_env(), ofile_env); |
|
a4d31e56075d
Issue #18143: Implement ssl.get_default_verify_paths() in order to debug
Christian Heimes <christian@cheimes.de>
parents:
83918
diff
changeset
|
3039 convert(X509_get_default_cert_file(), ofile); |
|
a4d31e56075d
Issue #18143: Implement ssl.get_default_verify_paths() in order to debug
Christian Heimes <christian@cheimes.de>
parents:
83918
diff
changeset
|
3040 convert(X509_get_default_cert_dir_env(), odir_env); |
|
a4d31e56075d
Issue #18143: Implement ssl.get_default_verify_paths() in order to debug
Christian Heimes <christian@cheimes.de>
parents:
83918
diff
changeset
|
3041 convert(X509_get_default_cert_dir(), odir); |
|
a4d31e56075d
Issue #18143: Implement ssl.get_default_verify_paths() in order to debug
Christian Heimes <christian@cheimes.de>
parents:
83918
diff
changeset
|
3042 #undef convert |
|
a4d31e56075d
Issue #18143: Implement ssl.get_default_verify_paths() in order to debug
Christian Heimes <christian@cheimes.de>
parents:
83918
diff
changeset
|
3043 |
|
84119
5f7e12eb65b8
Simplify return value of ssl.get_default_verify_paths
Christian Heimes <christian@cheimes.de>
parents:
84077
diff
changeset
|
3044 return Py_BuildValue("NNNN", ofile_env, ofile, odir_env, odir); |
|
84068
a4d31e56075d
Issue #18143: Implement ssl.get_default_verify_paths() in order to debug
Christian Heimes <christian@cheimes.de>
parents:
83918
diff
changeset
|
3045 |
|
a4d31e56075d
Issue #18143: Implement ssl.get_default_verify_paths() in order to debug
Christian Heimes <christian@cheimes.de>
parents:
83918
diff
changeset
|
3046 error: |
|
a4d31e56075d
Issue #18143: Implement ssl.get_default_verify_paths() in order to debug
Christian Heimes <christian@cheimes.de>
parents:
83918
diff
changeset
|
3047 Py_XDECREF(ofile_env); |
|
a4d31e56075d
Issue #18143: Implement ssl.get_default_verify_paths() in order to debug
Christian Heimes <christian@cheimes.de>
parents:
83918
diff
changeset
|
3048 Py_XDECREF(ofile); |
|
a4d31e56075d
Issue #18143: Implement ssl.get_default_verify_paths() in order to debug
Christian Heimes <christian@cheimes.de>
parents:
83918
diff
changeset
|
3049 Py_XDECREF(odir_env); |
|
a4d31e56075d
Issue #18143: Implement ssl.get_default_verify_paths() in order to debug
Christian Heimes <christian@cheimes.de>
parents:
83918
diff
changeset
|
3050 Py_XDECREF(odir); |
|
a4d31e56075d
Issue #18143: Implement ssl.get_default_verify_paths() in order to debug
Christian Heimes <christian@cheimes.de>
parents:
83918
diff
changeset
|
3051 return NULL; |
|
a4d31e56075d
Issue #18143: Implement ssl.get_default_verify_paths() in order to debug
Christian Heimes <christian@cheimes.de>
parents:
83918
diff
changeset
|
3052 } |
|
a4d31e56075d
Issue #18143: Implement ssl.get_default_verify_paths() in order to debug
Christian Heimes <christian@cheimes.de>
parents:
83918
diff
changeset
|
3053 |
|
84071
10d325f674f5
Issue #17134: Add ssl.enum_cert_store() as interface to Windows' cert store.
Christian Heimes <christian@cheimes.de>
parents:
84070
diff
changeset
|
3054 #ifdef _MSC_VER |
|
10d325f674f5
Issue #17134: Add ssl.enum_cert_store() as interface to Windows' cert store.
Christian Heimes <christian@cheimes.de>
parents:
84070
diff
changeset
|
3055 PyDoc_STRVAR(PySSL_enum_cert_store_doc, |
|
10d325f674f5
Issue #17134: Add ssl.enum_cert_store() as interface to Windows' cert store.
Christian Heimes <christian@cheimes.de>
parents:
84070
diff
changeset
|
3056 "enum_cert_store(store_name, cert_type='certificate') -> []\n\ |
|
10d325f674f5
Issue #17134: Add ssl.enum_cert_store() as interface to Windows' cert store.
Christian Heimes <christian@cheimes.de>
parents:
84070
diff
changeset
|
3057 \n\ |
|
10d325f674f5
Issue #17134: Add ssl.enum_cert_store() as interface to Windows' cert store.
Christian Heimes <christian@cheimes.de>
parents:
84070
diff
changeset
|
3058 Retrieve certificates from Windows' cert store. store_name may be one of\n\ |
|
10d325f674f5
Issue #17134: Add ssl.enum_cert_store() as interface to Windows' cert store.
Christian Heimes <christian@cheimes.de>
parents:
84070
diff
changeset
|
3059 'CA', 'ROOT' or 'MY'. The system may provide more cert storages, too.\n\ |
|
10d325f674f5
Issue #17134: Add ssl.enum_cert_store() as interface to Windows' cert store.
Christian Heimes <christian@cheimes.de>
parents:
84070
diff
changeset
|
3060 cert_type must be either 'certificate' or 'crl'.\n\ |
|
10d325f674f5
Issue #17134: Add ssl.enum_cert_store() as interface to Windows' cert store.
Christian Heimes <christian@cheimes.de>
parents:
84070
diff
changeset
|
3061 The function returns a list of (bytes, encoding_type) tuples. The\n\ |
|
10d325f674f5
Issue #17134: Add ssl.enum_cert_store() as interface to Windows' cert store.
Christian Heimes <christian@cheimes.de>
parents:
84070
diff
changeset
|
3062 encoding_type flag can be interpreted with X509_ASN_ENCODING or\n\ |
|
10d325f674f5
Issue #17134: Add ssl.enum_cert_store() as interface to Windows' cert store.
Christian Heimes <christian@cheimes.de>
parents:
84070
diff
changeset
|
3063 PKCS_7_ASN_ENCODING."); |
|
10d325f674f5
Issue #17134: Add ssl.enum_cert_store() as interface to Windows' cert store.
Christian Heimes <christian@cheimes.de>
parents:
84070
diff
changeset
|
3064 |
|
10d325f674f5
Issue #17134: Add ssl.enum_cert_store() as interface to Windows' cert store.
Christian Heimes <christian@cheimes.de>
parents:
84070
diff
changeset
|
3065 static PyObject * |
|
10d325f674f5
Issue #17134: Add ssl.enum_cert_store() as interface to Windows' cert store.
Christian Heimes <christian@cheimes.de>
parents:
84070
diff
changeset
|
3066 PySSL_enum_cert_store(PyObject *self, PyObject *args, PyObject *kwds) |
|
10d325f674f5
Issue #17134: Add ssl.enum_cert_store() as interface to Windows' cert store.
Christian Heimes <christian@cheimes.de>
parents:
84070
diff
changeset
|
3067 { |
|
10d325f674f5
Issue #17134: Add ssl.enum_cert_store() as interface to Windows' cert store.
Christian Heimes <christian@cheimes.de>
parents:
84070
diff
changeset
|
3068 char *kwlist[] = {"store_name", "cert_type", NULL}; |
|
10d325f674f5
Issue #17134: Add ssl.enum_cert_store() as interface to Windows' cert store.
Christian Heimes <christian@cheimes.de>
parents:
84070
diff
changeset
|
3069 char *store_name; |
|
10d325f674f5
Issue #17134: Add ssl.enum_cert_store() as interface to Windows' cert store.
Christian Heimes <christian@cheimes.de>
parents:
84070
diff
changeset
|
3070 char *cert_type = "certificate"; |
|
10d325f674f5
Issue #17134: Add ssl.enum_cert_store() as interface to Windows' cert store.
Christian Heimes <christian@cheimes.de>
parents:
84070
diff
changeset
|
3071 HCERTSTORE hStore = NULL; |
|
10d325f674f5
Issue #17134: Add ssl.enum_cert_store() as interface to Windows' cert store.
Christian Heimes <christian@cheimes.de>
parents:
84070
diff
changeset
|
3072 PyObject *result = NULL; |
|
10d325f674f5
Issue #17134: Add ssl.enum_cert_store() as interface to Windows' cert store.
Christian Heimes <christian@cheimes.de>
parents:
84070
diff
changeset
|
3073 PyObject *tup = NULL, *cert = NULL, *enc = NULL; |
|
10d325f674f5
Issue #17134: Add ssl.enum_cert_store() as interface to Windows' cert store.
Christian Heimes <christian@cheimes.de>
parents:
84070
diff
changeset
|
3074 int ok = 1; |
|
10d325f674f5
Issue #17134: Add ssl.enum_cert_store() as interface to Windows' cert store.
Christian Heimes <christian@cheimes.de>
parents:
84070
diff
changeset
|
3075 |
|
10d325f674f5
Issue #17134: Add ssl.enum_cert_store() as interface to Windows' cert store.
Christian Heimes <christian@cheimes.de>
parents:
84070
diff
changeset
|
3076 if (!PyArg_ParseTupleAndKeywords(args, kwds, "s|s:enum_cert_store", |
|
10d325f674f5
Issue #17134: Add ssl.enum_cert_store() as interface to Windows' cert store.
Christian Heimes <christian@cheimes.de>
parents:
84070
diff
changeset
|
3077 kwlist, &store_name, &cert_type)) { |
|
10d325f674f5
Issue #17134: Add ssl.enum_cert_store() as interface to Windows' cert store.
Christian Heimes <christian@cheimes.de>
parents:
84070
diff
changeset
|
3078 return NULL; |
|
10d325f674f5
Issue #17134: Add ssl.enum_cert_store() as interface to Windows' cert store.
Christian Heimes <christian@cheimes.de>
parents:
84070
diff
changeset
|
3079 } |
|
10d325f674f5
Issue #17134: Add ssl.enum_cert_store() as interface to Windows' cert store.
Christian Heimes <christian@cheimes.de>
parents:
84070
diff
changeset
|
3080 |
|
10d325f674f5
Issue #17134: Add ssl.enum_cert_store() as interface to Windows' cert store.
Christian Heimes <christian@cheimes.de>
parents:
84070
diff
changeset
|
3081 if ((strcmp(cert_type, "certificate") != 0) && |
|
10d325f674f5
Issue #17134: Add ssl.enum_cert_store() as interface to Windows' cert store.
Christian Heimes <christian@cheimes.de>
parents:
84070
diff
changeset
|
3082 (strcmp(cert_type, "crl") != 0)) { |
|
10d325f674f5
Issue #17134: Add ssl.enum_cert_store() as interface to Windows' cert store.
Christian Heimes <christian@cheimes.de>
parents:
84070
diff
changeset
|
3083 return PyErr_Format(PyExc_ValueError, |
|
10d325f674f5
Issue #17134: Add ssl.enum_cert_store() as interface to Windows' cert store.
Christian Heimes <christian@cheimes.de>
parents:
84070
diff
changeset
|
3084 "cert_type must be 'certificate' or 'crl', " |
|
10d325f674f5
Issue #17134: Add ssl.enum_cert_store() as interface to Windows' cert store.
Christian Heimes <christian@cheimes.de>
parents:
84070
diff
changeset
|
3085 "not %.100s", cert_type); |
|
10d325f674f5
Issue #17134: Add ssl.enum_cert_store() as interface to Windows' cert store.
Christian Heimes <christian@cheimes.de>
parents:
84070
diff
changeset
|
3086 } |
|
10d325f674f5
Issue #17134: Add ssl.enum_cert_store() as interface to Windows' cert store.
Christian Heimes <christian@cheimes.de>
parents:
84070
diff
changeset
|
3087 |
|
10d325f674f5
Issue #17134: Add ssl.enum_cert_store() as interface to Windows' cert store.
Christian Heimes <christian@cheimes.de>
parents:
84070
diff
changeset
|
3088 if ((result = PyList_New(0)) == NULL) { |
|
10d325f674f5
Issue #17134: Add ssl.enum_cert_store() as interface to Windows' cert store.
Christian Heimes <christian@cheimes.de>
parents:
84070
diff
changeset
|
3089 return NULL; |
|
10d325f674f5
Issue #17134: Add ssl.enum_cert_store() as interface to Windows' cert store.
Christian Heimes <christian@cheimes.de>
parents:
84070
diff
changeset
|
3090 } |
|
10d325f674f5
Issue #17134: Add ssl.enum_cert_store() as interface to Windows' cert store.
Christian Heimes <christian@cheimes.de>
parents:
84070
diff
changeset
|
3091 |
|
85372
70d1dc219eb6
Fix compiler warning on Windows.
Richard Oudkerk <shibturn@gmail.com>
parents:
85315
diff
changeset
|
3092 if ((hStore = CertOpenSystemStore((HCRYPTPROV)NULL, store_name)) == NULL) { |
|
84071
10d325f674f5
Issue #17134: Add ssl.enum_cert_store() as interface to Windows' cert store.
Christian Heimes <christian@cheimes.de>
parents:
84070
diff
changeset
|
3093 Py_DECREF(result); |
|
10d325f674f5
Issue #17134: Add ssl.enum_cert_store() as interface to Windows' cert store.
Christian Heimes <christian@cheimes.de>
parents:
84070
diff
changeset
|
3094 return PyErr_SetFromWindowsErr(GetLastError()); |
|
10d325f674f5
Issue #17134: Add ssl.enum_cert_store() as interface to Windows' cert store.
Christian Heimes <christian@cheimes.de>
parents:
84070
diff
changeset
|
3095 } |
|
10d325f674f5
Issue #17134: Add ssl.enum_cert_store() as interface to Windows' cert store.
Christian Heimes <christian@cheimes.de>
parents:
84070
diff
changeset
|
3096 |
|
10d325f674f5
Issue #17134: Add ssl.enum_cert_store() as interface to Windows' cert store.
Christian Heimes <christian@cheimes.de>
parents:
84070
diff
changeset
|
3097 if (strcmp(cert_type, "certificate") == 0) { |
|
10d325f674f5
Issue #17134: Add ssl.enum_cert_store() as interface to Windows' cert store.
Christian Heimes <christian@cheimes.de>
parents:
84070
diff
changeset
|
3098 PCCERT_CONTEXT pCertCtx = NULL; |
|
10d325f674f5
Issue #17134: Add ssl.enum_cert_store() as interface to Windows' cert store.
Christian Heimes <christian@cheimes.de>
parents:
84070
diff
changeset
|
3099 while (pCertCtx = CertEnumCertificatesInStore(hStore, pCertCtx)) { |
|
10d325f674f5
Issue #17134: Add ssl.enum_cert_store() as interface to Windows' cert store.
Christian Heimes <christian@cheimes.de>
parents:
84070
diff
changeset
|
3100 cert = PyBytes_FromStringAndSize((const char*)pCertCtx->pbCertEncoded, |
|
10d325f674f5
Issue #17134: Add ssl.enum_cert_store() as interface to Windows' cert store.
Christian Heimes <christian@cheimes.de>
parents:
84070
diff
changeset
|
3101 pCertCtx->cbCertEncoded); |
|
10d325f674f5
Issue #17134: Add ssl.enum_cert_store() as interface to Windows' cert store.
Christian Heimes <christian@cheimes.de>
parents:
84070
diff
changeset
|
3102 if (!cert) { |
|
10d325f674f5
Issue #17134: Add ssl.enum_cert_store() as interface to Windows' cert store.
Christian Heimes <christian@cheimes.de>
parents:
84070
diff
changeset
|
3103 ok = 0; |
|
10d325f674f5
Issue #17134: Add ssl.enum_cert_store() as interface to Windows' cert store.
Christian Heimes <christian@cheimes.de>
parents:
84070
diff
changeset
|
3104 break; |
|
10d325f674f5
Issue #17134: Add ssl.enum_cert_store() as interface to Windows' cert store.
Christian Heimes <christian@cheimes.de>
parents:
84070
diff
changeset
|
3105 } |
|
10d325f674f5
Issue #17134: Add ssl.enum_cert_store() as interface to Windows' cert store.
Christian Heimes <christian@cheimes.de>
parents:
84070
diff
changeset
|
3106 if ((enc = PyLong_FromLong(pCertCtx->dwCertEncodingType)) == NULL) { |
|
10d325f674f5
Issue #17134: Add ssl.enum_cert_store() as interface to Windows' cert store.
Christian Heimes <christian@cheimes.de>
parents:
84070
diff
changeset
|
3107 ok = 0; |
|
10d325f674f5
Issue #17134: Add ssl.enum_cert_store() as interface to Windows' cert store.
Christian Heimes <christian@cheimes.de>
parents:
84070
diff
changeset
|
3108 break; |
|
10d325f674f5
Issue #17134: Add ssl.enum_cert_store() as interface to Windows' cert store.
Christian Heimes <christian@cheimes.de>
parents:
84070
diff
changeset
|
3109 } |
|
10d325f674f5
Issue #17134: Add ssl.enum_cert_store() as interface to Windows' cert store.
Christian Heimes <christian@cheimes.de>
parents:
84070
diff
changeset
|
3110 if ((tup = PyTuple_New(2)) == NULL) { |
|
10d325f674f5
Issue #17134: Add ssl.enum_cert_store() as interface to Windows' cert store.
Christian Heimes <christian@cheimes.de>
parents:
84070
diff
changeset
|
3111 ok = 0; |
|
10d325f674f5
Issue #17134: Add ssl.enum_cert_store() as interface to Windows' cert store.
Christian Heimes <christian@cheimes.de>
parents:
84070
diff
changeset
|
3112 break; |
|
10d325f674f5
Issue #17134: Add ssl.enum_cert_store() as interface to Windows' cert store.
Christian Heimes <christian@cheimes.de>
parents:
84070
diff
changeset
|
3113 } |
|
10d325f674f5
Issue #17134: Add ssl.enum_cert_store() as interface to Windows' cert store.
Christian Heimes <christian@cheimes.de>
parents:
84070
diff
changeset
|
3114 PyTuple_SET_ITEM(tup, 0, cert); cert = NULL; |
|
10d325f674f5
Issue #17134: Add ssl.enum_cert_store() as interface to Windows' cert store.
Christian Heimes <christian@cheimes.de>
parents:
84070
diff
changeset
|
3115 PyTuple_SET_ITEM(tup, 1, enc); enc = NULL; |
|
10d325f674f5
Issue #17134: Add ssl.enum_cert_store() as interface to Windows' cert store.
Christian Heimes <christian@cheimes.de>
parents:
84070
diff
changeset
|
3116 |
|
10d325f674f5
Issue #17134: Add ssl.enum_cert_store() as interface to Windows' cert store.
Christian Heimes <christian@cheimes.de>
parents:
84070
diff
changeset
|
3117 if (PyList_Append(result, tup) < 0) { |
|
10d325f674f5
Issue #17134: Add ssl.enum_cert_store() as interface to Windows' cert store.
Christian Heimes <christian@cheimes.de>
parents:
84070
diff
changeset
|
3118 ok = 0; |
|
10d325f674f5
Issue #17134: Add ssl.enum_cert_store() as interface to Windows' cert store.
Christian Heimes <christian@cheimes.de>
parents:
84070
diff
changeset
|
3119 break; |
|
10d325f674f5
Issue #17134: Add ssl.enum_cert_store() as interface to Windows' cert store.
Christian Heimes <christian@cheimes.de>
parents:
84070
diff
changeset
|
3120 } |
|
10d325f674f5
Issue #17134: Add ssl.enum_cert_store() as interface to Windows' cert store.
Christian Heimes <christian@cheimes.de>
parents:
84070
diff
changeset
|
3121 Py_CLEAR(tup); |
|
10d325f674f5
Issue #17134: Add ssl.enum_cert_store() as interface to Windows' cert store.
Christian Heimes <christian@cheimes.de>
parents:
84070
diff
changeset
|
3122 } |
|
10d325f674f5
Issue #17134: Add ssl.enum_cert_store() as interface to Windows' cert store.
Christian Heimes <christian@cheimes.de>
parents:
84070
diff
changeset
|
3123 if (pCertCtx) { |
|
10d325f674f5
Issue #17134: Add ssl.enum_cert_store() as interface to Windows' cert store.
Christian Heimes <christian@cheimes.de>
parents:
84070
diff
changeset
|
3124 /* loop ended with an error, need to clean up context manually */ |
|
10d325f674f5
Issue #17134: Add ssl.enum_cert_store() as interface to Windows' cert store.
Christian Heimes <christian@cheimes.de>
parents:
84070
diff
changeset
|
3125 CertFreeCertificateContext(pCertCtx); |
|
10d325f674f5
Issue #17134: Add ssl.enum_cert_store() as interface to Windows' cert store.
Christian Heimes <christian@cheimes.de>
parents:
84070
diff
changeset
|
3126 } |
|
10d325f674f5
Issue #17134: Add ssl.enum_cert_store() as interface to Windows' cert store.
Christian Heimes <christian@cheimes.de>
parents:
84070
diff
changeset
|
3127 } else { |
|
10d325f674f5
Issue #17134: Add ssl.enum_cert_store() as interface to Windows' cert store.
Christian Heimes <christian@cheimes.de>
parents:
84070
diff
changeset
|
3128 PCCRL_CONTEXT pCrlCtx = NULL; |
|
10d325f674f5
Issue #17134: Add ssl.enum_cert_store() as interface to Windows' cert store.
Christian Heimes <christian@cheimes.de>
parents:
84070
diff
changeset
|
3129 while (pCrlCtx = CertEnumCRLsInStore(hStore, pCrlCtx)) { |
|
10d325f674f5
Issue #17134: Add ssl.enum_cert_store() as interface to Windows' cert store.
Christian Heimes <christian@cheimes.de>
parents:
84070
diff
changeset
|
3130 cert = PyBytes_FromStringAndSize((const char*)pCrlCtx->pbCrlEncoded, |
|
10d325f674f5
Issue #17134: Add ssl.enum_cert_store() as interface to Windows' cert store.
Christian Heimes <christian@cheimes.de>
parents:
84070
diff
changeset
|
3131 pCrlCtx->cbCrlEncoded); |
|
10d325f674f5
Issue #17134: Add ssl.enum_cert_store() as interface to Windows' cert store.
Christian Heimes <christian@cheimes.de>
parents:
84070
diff
changeset
|
3132 if (!cert) { |
|
10d325f674f5
Issue #17134: Add ssl.enum_cert_store() as interface to Windows' cert store.
Christian Heimes <christian@cheimes.de>
parents:
84070
diff
changeset
|
3133 ok = 0; |
|
10d325f674f5
Issue #17134: Add ssl.enum_cert_store() as interface to Windows' cert store.
Christian Heimes <christian@cheimes.de>
parents:
84070
diff
changeset
|
3134 break; |
|
10d325f674f5
Issue #17134: Add ssl.enum_cert_store() as interface to Windows' cert store.
Christian Heimes <christian@cheimes.de>
parents:
84070
diff
changeset
|
3135 } |
|
10d325f674f5
Issue #17134: Add ssl.enum_cert_store() as interface to Windows' cert store.
Christian Heimes <christian@cheimes.de>
parents:
84070
diff
changeset
|
3136 if ((enc = PyLong_FromLong(pCrlCtx->dwCertEncodingType)) == NULL) { |
|
10d325f674f5
Issue #17134: Add ssl.enum_cert_store() as interface to Windows' cert store.
Christian Heimes <christian@cheimes.de>
parents:
84070
diff
changeset
|
3137 ok = 0; |
|
10d325f674f5
Issue #17134: Add ssl.enum_cert_store() as interface to Windows' cert store.
Christian Heimes <christian@cheimes.de>
parents:
84070
diff
changeset
|
3138 break; |
|
10d325f674f5
Issue #17134: Add ssl.enum_cert_store() as interface to Windows' cert store.
Christian Heimes <christian@cheimes.de>
parents:
84070
diff
changeset
|
3139 } |
|
10d325f674f5
Issue #17134: Add ssl.enum_cert_store() as interface to Windows' cert store.
Christian Heimes <christian@cheimes.de>
parents:
84070
diff
changeset
|
3140 if ((tup = PyTuple_New(2)) == NULL) { |
|
10d325f674f5
Issue #17134: Add ssl.enum_cert_store() as interface to Windows' cert store.
Christian Heimes <christian@cheimes.de>
parents:
84070
diff
changeset
|
3141 ok = 0; |
|
10d325f674f5
Issue #17134: Add ssl.enum_cert_store() as interface to Windows' cert store.
Christian Heimes <christian@cheimes.de>
parents:
84070
diff
changeset
|
3142 break; |
|
10d325f674f5
Issue #17134: Add ssl.enum_cert_store() as interface to Windows' cert store.
Christian Heimes <christian@cheimes.de>
parents:
84070
diff
changeset
|
3143 } |
|
10d325f674f5
Issue #17134: Add ssl.enum_cert_store() as interface to Windows' cert store.
Christian Heimes <christian@cheimes.de>
parents:
84070
diff
changeset
|
3144 PyTuple_SET_ITEM(tup, 0, cert); cert = NULL; |
|
10d325f674f5
Issue #17134: Add ssl.enum_cert_store() as interface to Windows' cert store.
Christian Heimes <christian@cheimes.de>
parents:
84070
diff
changeset
|
3145 PyTuple_SET_ITEM(tup, 1, enc); enc = NULL; |
|
10d325f674f5
Issue #17134: Add ssl.enum_cert_store() as interface to Windows' cert store.
Christian Heimes <christian@cheimes.de>
parents:
84070
diff
changeset
|
3146 |
|
10d325f674f5
Issue #17134: Add ssl.enum_cert_store() as interface to Windows' cert store.
Christian Heimes <christian@cheimes.de>
parents:
84070
diff
changeset
|
3147 if (PyList_Append(result, tup) < 0) { |
|
10d325f674f5
Issue #17134: Add ssl.enum_cert_store() as interface to Windows' cert store.
Christian Heimes <christian@cheimes.de>
parents:
84070
diff
changeset
|
3148 ok = 0; |
|
10d325f674f5
Issue #17134: Add ssl.enum_cert_store() as interface to Windows' cert store.
Christian Heimes <christian@cheimes.de>
parents:
84070
diff
changeset
|
3149 break; |
|
10d325f674f5
Issue #17134: Add ssl.enum_cert_store() as interface to Windows' cert store.
Christian Heimes <christian@cheimes.de>
parents:
84070
diff
changeset
|
3150 } |
|
10d325f674f5
Issue #17134: Add ssl.enum_cert_store() as interface to Windows' cert store.
Christian Heimes <christian@cheimes.de>
parents:
84070
diff
changeset
|
3151 Py_CLEAR(tup); |
|
10d325f674f5
Issue #17134: Add ssl.enum_cert_store() as interface to Windows' cert store.
Christian Heimes <christian@cheimes.de>
parents:
84070
diff
changeset
|
3152 } |
|
10d325f674f5
Issue #17134: Add ssl.enum_cert_store() as interface to Windows' cert store.
Christian Heimes <christian@cheimes.de>
parents:
84070
diff
changeset
|
3153 if (pCrlCtx) { |
|
10d325f674f5
Issue #17134: Add ssl.enum_cert_store() as interface to Windows' cert store.
Christian Heimes <christian@cheimes.de>
parents:
84070
diff
changeset
|
3154 /* loop ended with an error, need to clean up context manually */ |
|
10d325f674f5
Issue #17134: Add ssl.enum_cert_store() as interface to Windows' cert store.
Christian Heimes <christian@cheimes.de>
parents:
84070
diff
changeset
|
3155 CertFreeCRLContext(pCrlCtx); |
|
10d325f674f5
Issue #17134: Add ssl.enum_cert_store() as interface to Windows' cert store.
Christian Heimes <christian@cheimes.de>
parents:
84070
diff
changeset
|
3156 } |
|
10d325f674f5
Issue #17134: Add ssl.enum_cert_store() as interface to Windows' cert store.
Christian Heimes <christian@cheimes.de>
parents:
84070
diff
changeset
|
3157 } |
|
10d325f674f5
Issue #17134: Add ssl.enum_cert_store() as interface to Windows' cert store.
Christian Heimes <christian@cheimes.de>
parents:
84070
diff
changeset
|
3158 |
|
10d325f674f5
Issue #17134: Add ssl.enum_cert_store() as interface to Windows' cert store.
Christian Heimes <christian@cheimes.de>
parents:
84070
diff
changeset
|
3159 /* In error cases cert, enc and tup may not be NULL */ |
|
10d325f674f5
Issue #17134: Add ssl.enum_cert_store() as interface to Windows' cert store.
Christian Heimes <christian@cheimes.de>
parents:
84070
diff
changeset
|
3160 Py_XDECREF(cert); |
|
10d325f674f5
Issue #17134: Add ssl.enum_cert_store() as interface to Windows' cert store.
Christian Heimes <christian@cheimes.de>
parents:
84070
diff
changeset
|
3161 Py_XDECREF(enc); |
|
10d325f674f5
Issue #17134: Add ssl.enum_cert_store() as interface to Windows' cert store.
Christian Heimes <christian@cheimes.de>
parents:
84070
diff
changeset
|
3162 Py_XDECREF(tup); |
|
10d325f674f5
Issue #17134: Add ssl.enum_cert_store() as interface to Windows' cert store.
Christian Heimes <christian@cheimes.de>
parents:
84070
diff
changeset
|
3163 |
|
10d325f674f5
Issue #17134: Add ssl.enum_cert_store() as interface to Windows' cert store.
Christian Heimes <christian@cheimes.de>
parents:
84070
diff
changeset
|
3164 if (!CertCloseStore(hStore, 0)) { |
|
10d325f674f5
Issue #17134: Add ssl.enum_cert_store() as interface to Windows' cert store.
Christian Heimes <christian@cheimes.de>
parents:
84070
diff
changeset
|
3165 /* This error case might shadow another exception.*/ |
|
10d325f674f5
Issue #17134: Add ssl.enum_cert_store() as interface to Windows' cert store.
Christian Heimes <christian@cheimes.de>
parents:
84070
diff
changeset
|
3166 Py_DECREF(result); |
|
10d325f674f5
Issue #17134: Add ssl.enum_cert_store() as interface to Windows' cert store.
Christian Heimes <christian@cheimes.de>
parents:
84070
diff
changeset
|
3167 return PyErr_SetFromWindowsErr(GetLastError()); |
|
10d325f674f5
Issue #17134: Add ssl.enum_cert_store() as interface to Windows' cert store.
Christian Heimes <christian@cheimes.de>
parents:
84070
diff
changeset
|
3168 } |
|
10d325f674f5
Issue #17134: Add ssl.enum_cert_store() as interface to Windows' cert store.
Christian Heimes <christian@cheimes.de>
parents:
84070
diff
changeset
|
3169 if (ok) { |
|
10d325f674f5
Issue #17134: Add ssl.enum_cert_store() as interface to Windows' cert store.
Christian Heimes <christian@cheimes.de>
parents:
84070
diff
changeset
|
3170 return result; |
|
10d325f674f5
Issue #17134: Add ssl.enum_cert_store() as interface to Windows' cert store.
Christian Heimes <christian@cheimes.de>
parents:
84070
diff
changeset
|
3171 } else { |
|
10d325f674f5
Issue #17134: Add ssl.enum_cert_store() as interface to Windows' cert store.
Christian Heimes <christian@cheimes.de>
parents:
84070
diff
changeset
|
3172 Py_DECREF(result); |
|
10d325f674f5
Issue #17134: Add ssl.enum_cert_store() as interface to Windows' cert store.
Christian Heimes <christian@cheimes.de>
parents:
84070
diff
changeset
|
3173 return NULL; |
|
10d325f674f5
Issue #17134: Add ssl.enum_cert_store() as interface to Windows' cert store.
Christian Heimes <christian@cheimes.de>
parents:
84070
diff
changeset
|
3174 } |
|
10d325f674f5
Issue #17134: Add ssl.enum_cert_store() as interface to Windows' cert store.
Christian Heimes <christian@cheimes.de>
parents:
84070
diff
changeset
|
3175 } |
|
10d325f674f5
Issue #17134: Add ssl.enum_cert_store() as interface to Windows' cert store.
Christian Heimes <christian@cheimes.de>
parents:
84070
diff
changeset
|
3176 #endif |
|
48681
3c8ef3466923
clean up ssl.py; expose unwrap and add test for it
Bill Janssen <janssen@parc.com>
parents:
48660
diff
changeset
|
3177 |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
3178 /* List of functions exported by this module. */ |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
3179 |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
3180 static PyMethodDef PySSL_methods[] = { |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
3181 {"_test_decode_cert", PySSL_test_decode_certificate, |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
3182 METH_VARARGS}, |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
3183 #ifdef HAVE_OPENSSL_RAND |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
3184 {"RAND_add", PySSL_RAND_add, METH_VARARGS, |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
3185 PySSL_RAND_add_doc}, |
|
70328
5c716437a83a
Issue #12049: Add RAND_bytes() and RAND_pseudo_bytes() functions to the ssl
Victor Stinner <victor.stinner@haypocalc.com>
parents:
69999
diff
changeset
|
3186 {"RAND_bytes", PySSL_RAND_bytes, METH_VARARGS, |
|
5c716437a83a
Issue #12049: Add RAND_bytes() and RAND_pseudo_bytes() functions to the ssl
Victor Stinner <victor.stinner@haypocalc.com>
parents:
69999
diff
changeset
|
3187 PySSL_RAND_bytes_doc}, |
|
5c716437a83a
Issue #12049: Add RAND_bytes() and RAND_pseudo_bytes() functions to the ssl
Victor Stinner <victor.stinner@haypocalc.com>
parents:
69999
diff
changeset
|
3188 {"RAND_pseudo_bytes", PySSL_RAND_pseudo_bytes, METH_VARARGS, |
|
5c716437a83a
Issue #12049: Add RAND_bytes() and RAND_pseudo_bytes() functions to the ssl
Victor Stinner <victor.stinner@haypocalc.com>
parents:
69999
diff
changeset
|
3189 PySSL_RAND_pseudo_bytes_doc}, |
|
61641
a09eb3d59ff7
Issue #8477: ssl.RAND_egd() supports str with surrogates and bytes for the path
Victor Stinner <victor.stinner@haypocalc.com>
parents:
61639
diff
changeset
|
3190 {"RAND_egd", PySSL_RAND_egd, METH_VARARGS, |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
3191 PySSL_RAND_egd_doc}, |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
3192 {"RAND_status", (PyCFunction)PySSL_RAND_status, METH_NOARGS, |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
3193 PySSL_RAND_status_doc}, |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
3194 #endif |
|
84119
5f7e12eb65b8
Simplify return value of ssl.get_default_verify_paths
Christian Heimes <christian@cheimes.de>
parents:
84077
diff
changeset
|
3195 {"get_default_verify_paths", (PyCFunction)PySSL_get_default_verify_paths, |
|
84068
a4d31e56075d
Issue #18143: Implement ssl.get_default_verify_paths() in order to debug
Christian Heimes <christian@cheimes.de>
parents:
83918
diff
changeset
|
3196 METH_NOARGS, PySSL_get_default_verify_paths_doc}, |
|
84071
10d325f674f5
Issue #17134: Add ssl.enum_cert_store() as interface to Windows' cert store.
Christian Heimes <christian@cheimes.de>
parents:
84070
diff
changeset
|
3197 #ifdef _MSC_VER |
|
10d325f674f5
Issue #17134: Add ssl.enum_cert_store() as interface to Windows' cert store.
Christian Heimes <christian@cheimes.de>
parents:
84070
diff
changeset
|
3198 {"enum_cert_store", (PyCFunction)PySSL_enum_cert_store, |
|
10d325f674f5
Issue #17134: Add ssl.enum_cert_store() as interface to Windows' cert store.
Christian Heimes <christian@cheimes.de>
parents:
84070
diff
changeset
|
3199 METH_VARARGS | METH_KEYWORDS, PySSL_enum_cert_store_doc}, |
|
10d325f674f5
Issue #17134: Add ssl.enum_cert_store() as interface to Windows' cert store.
Christian Heimes <christian@cheimes.de>
parents:
84070
diff
changeset
|
3200 #endif |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
3201 {NULL, NULL} /* Sentinel */ |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
3202 }; |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
3203 |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
3204 |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
3205 #ifdef WITH_THREAD |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
3206 |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
3207 /* an implementation of OpenSSL threading operations in terms |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
3208 of the Python C thread library */ |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
3209 |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
3210 static PyThread_type_lock *_ssl_locks = NULL; |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
3211 |
|
85263
f967ded6f9dd
Issue #18777: The ssl module now uses the new CRYPTO_THREADID API of
Christian Heimes <christian@cheimes.de>
parents:
85236
diff
changeset
|
3212 #if OPENSSL_VERSION_NUMBER >= 0x10000000 |
|
f967ded6f9dd
Issue #18777: The ssl module now uses the new CRYPTO_THREADID API of
Christian Heimes <christian@cheimes.de>
parents:
85236
diff
changeset
|
3213 /* use new CRYPTO_THREADID API. */ |
|
f967ded6f9dd
Issue #18777: The ssl module now uses the new CRYPTO_THREADID API of
Christian Heimes <christian@cheimes.de>
parents:
85236
diff
changeset
|
3214 static void |
|
f967ded6f9dd
Issue #18777: The ssl module now uses the new CRYPTO_THREADID API of
Christian Heimes <christian@cheimes.de>
parents:
85236
diff
changeset
|
3215 _ssl_threadid_callback(CRYPTO_THREADID *id) |
|
f967ded6f9dd
Issue #18777: The ssl module now uses the new CRYPTO_THREADID API of
Christian Heimes <christian@cheimes.de>
parents:
85236
diff
changeset
|
3216 { |
|
f967ded6f9dd
Issue #18777: The ssl module now uses the new CRYPTO_THREADID API of
Christian Heimes <christian@cheimes.de>
parents:
85236
diff
changeset
|
3217 CRYPTO_THREADID_set_numeric(id, |
|
f967ded6f9dd
Issue #18777: The ssl module now uses the new CRYPTO_THREADID API of
Christian Heimes <christian@cheimes.de>
parents:
85236
diff
changeset
|
3218 (unsigned long)PyThread_get_thread_ident()); |
|
f967ded6f9dd
Issue #18777: The ssl module now uses the new CRYPTO_THREADID API of
Christian Heimes <christian@cheimes.de>
parents:
85236
diff
changeset
|
3219 } |
|
f967ded6f9dd
Issue #18777: The ssl module now uses the new CRYPTO_THREADID API of
Christian Heimes <christian@cheimes.de>
parents:
85236
diff
changeset
|
3220 #else |
|
f967ded6f9dd
Issue #18777: The ssl module now uses the new CRYPTO_THREADID API of
Christian Heimes <christian@cheimes.de>
parents:
85236
diff
changeset
|
3221 /* deprecated CRYPTO_set_id_callback() API. */ |
|
f967ded6f9dd
Issue #18777: The ssl module now uses the new CRYPTO_THREADID API of
Christian Heimes <christian@cheimes.de>
parents:
85236
diff
changeset
|
3222 static unsigned long |
|
f967ded6f9dd
Issue #18777: The ssl module now uses the new CRYPTO_THREADID API of
Christian Heimes <christian@cheimes.de>
parents:
85236
diff
changeset
|
3223 _ssl_thread_id_function (void) { |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
3224 return PyThread_get_thread_ident(); |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
3225 } |
|
85263
f967ded6f9dd
Issue #18777: The ssl module now uses the new CRYPTO_THREADID API of
Christian Heimes <christian@cheimes.de>
parents:
85236
diff
changeset
|
3226 #endif |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
3227 |
|
43869
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
3228 static void _ssl_thread_locking_function |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
3229 (int mode, int n, const char *file, int line) { |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
3230 /* this function is needed to perform locking on shared data |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
3231 structures. (Note that OpenSSL uses a number of global data |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
3232 structures that will be implicitly shared whenever multiple |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
3233 threads use OpenSSL.) Multi-threaded applications will |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
3234 crash at random if it is not set. |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
3235 |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
3236 locking_function() must be able to handle up to |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
3237 CRYPTO_num_locks() different mutex locks. It sets the n-th |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
3238 lock if mode & CRYPTO_LOCK, and releases it otherwise. |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
3239 |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
3240 file and line are the file number of the function setting the |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
3241 lock. They can be useful for debugging. |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
3242 */ |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
3243 |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
3244 if ((_ssl_locks == NULL) || |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
3245 (n < 0) || ((unsigned)n >= _ssl_locks_count)) |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
3246 return; |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
3247 |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
3248 if (mode & CRYPTO_LOCK) { |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
3249 PyThread_acquire_lock(_ssl_locks[n], 1); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
3250 } else { |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
3251 PyThread_release_lock(_ssl_locks[n]); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
3252 } |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
3253 } |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
3254 |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
3255 static int _setup_ssl_threads(void) { |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
3256 |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
3257 unsigned int i; |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
3258 |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
3259 if (_ssl_locks == NULL) { |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
3260 _ssl_locks_count = CRYPTO_num_locks(); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
3261 _ssl_locks = (PyThread_type_lock *) |
|
84491
41ef797e6639
Issue #18203: Replace malloc() with PyMem_Malloc() in Python modules
Victor Stinner <victor.stinner@gmail.com>
parents:
84334
diff
changeset
|
3262 PyMem_Malloc(sizeof(PyThread_type_lock) * _ssl_locks_count); |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
3263 if (_ssl_locks == NULL) |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
3264 return 0; |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
3265 memset(_ssl_locks, 0, |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
3266 sizeof(PyThread_type_lock) * _ssl_locks_count); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
3267 for (i = 0; i < _ssl_locks_count; i++) { |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
3268 _ssl_locks[i] = PyThread_allocate_lock(); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
3269 if (_ssl_locks[i] == NULL) { |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
3270 unsigned int j; |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
3271 for (j = 0; j < i; j++) { |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
3272 PyThread_free_lock(_ssl_locks[j]); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
3273 } |
|
84491
41ef797e6639
Issue #18203: Replace malloc() with PyMem_Malloc() in Python modules
Victor Stinner <victor.stinner@gmail.com>
parents:
84334
diff
changeset
|
3274 PyMem_Free(_ssl_locks); |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
3275 return 0; |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
3276 } |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
3277 } |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
3278 CRYPTO_set_locking_callback(_ssl_thread_locking_function); |
|
85263
f967ded6f9dd
Issue #18777: The ssl module now uses the new CRYPTO_THREADID API of
Christian Heimes <christian@cheimes.de>
parents:
85236
diff
changeset
|
3279 #if OPENSSL_VERSION_NUMBER >= 0x10000000 |
|
f967ded6f9dd
Issue #18777: The ssl module now uses the new CRYPTO_THREADID API of
Christian Heimes <christian@cheimes.de>
parents:
85236
diff
changeset
|
3280 CRYPTO_THREADID_set_callback(_ssl_threadid_callback); |
|
f967ded6f9dd
Issue #18777: The ssl module now uses the new CRYPTO_THREADID API of
Christian Heimes <christian@cheimes.de>
parents:
85236
diff
changeset
|
3281 #else |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
3282 CRYPTO_set_id_callback(_ssl_thread_id_function); |
|
85263
f967ded6f9dd
Issue #18777: The ssl module now uses the new CRYPTO_THREADID API of
Christian Heimes <christian@cheimes.de>
parents:
85236
diff
changeset
|
3283 #endif |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
3284 } |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
3285 return 1; |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
3286 } |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
3287 |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
3288 #endif /* def HAVE_THREAD */ |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
3289 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23295
diff
changeset
|
3290 PyDoc_STRVAR(module_doc, |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
3291 "Implementation module for SSL socket operations. See the socket module\n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23295
diff
changeset
|
3292 for documentation."); |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
3293 |
|
47580
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47301
diff
changeset
|
3294 |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47301
diff
changeset
|
3295 static struct PyModuleDef _sslmodule = { |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
3296 PyModuleDef_HEAD_INIT, |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
3297 "_ssl", |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
3298 module_doc, |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
3299 -1, |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
3300 PySSL_methods, |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
3301 NULL, |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
3302 NULL, |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
3303 NULL, |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
3304 NULL |
|
47580
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47301
diff
changeset
|
3305 }; |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47301
diff
changeset
|
3306 |
|
71255
52ed0c6bb461
Issue #12440: When testing whether some bits in SSLContext.options can be
Antoine Pitrou <solipsis@pitrou.net>
parents:
69998
diff
changeset
|
3307 |
|
52ed0c6bb461
Issue #12440: When testing whether some bits in SSLContext.options can be
Antoine Pitrou <solipsis@pitrou.net>
parents:
69998
diff
changeset
|
3308 static void |
|
52ed0c6bb461
Issue #12440: When testing whether some bits in SSLContext.options can be
Antoine Pitrou <solipsis@pitrou.net>
parents:
69998
diff
changeset
|
3309 parse_openssl_version(unsigned long libver, |
|
52ed0c6bb461
Issue #12440: When testing whether some bits in SSLContext.options can be
Antoine Pitrou <solipsis@pitrou.net>
parents:
69998
diff
changeset
|
3310 unsigned int *major, unsigned int *minor, |
|
52ed0c6bb461
Issue #12440: When testing whether some bits in SSLContext.options can be
Antoine Pitrou <solipsis@pitrou.net>
parents:
69998
diff
changeset
|
3311 unsigned int *fix, unsigned int *patch, |
|
52ed0c6bb461
Issue #12440: When testing whether some bits in SSLContext.options can be
Antoine Pitrou <solipsis@pitrou.net>
parents:
69998
diff
changeset
|
3312 unsigned int *status) |
|
52ed0c6bb461
Issue #12440: When testing whether some bits in SSLContext.options can be
Antoine Pitrou <solipsis@pitrou.net>
parents:
69998
diff
changeset
|
3313 { |
|
52ed0c6bb461
Issue #12440: When testing whether some bits in SSLContext.options can be
Antoine Pitrou <solipsis@pitrou.net>
parents:
69998
diff
changeset
|
3314 *status = libver & 0xF; |
|
52ed0c6bb461
Issue #12440: When testing whether some bits in SSLContext.options can be
Antoine Pitrou <solipsis@pitrou.net>
parents:
69998
diff
changeset
|
3315 libver >>= 4; |
|
52ed0c6bb461
Issue #12440: When testing whether some bits in SSLContext.options can be
Antoine Pitrou <solipsis@pitrou.net>
parents:
69998
diff
changeset
|
3316 *patch = libver & 0xFF; |
|
52ed0c6bb461
Issue #12440: When testing whether some bits in SSLContext.options can be
Antoine Pitrou <solipsis@pitrou.net>
parents:
69998
diff
changeset
|
3317 libver >>= 8; |
|
52ed0c6bb461
Issue #12440: When testing whether some bits in SSLContext.options can be
Antoine Pitrou <solipsis@pitrou.net>
parents:
69998
diff
changeset
|
3318 *fix = libver & 0xFF; |
|
52ed0c6bb461
Issue #12440: When testing whether some bits in SSLContext.options can be
Antoine Pitrou <solipsis@pitrou.net>
parents:
69998
diff
changeset
|
3319 libver >>= 8; |
|
52ed0c6bb461
Issue #12440: When testing whether some bits in SSLContext.options can be
Antoine Pitrou <solipsis@pitrou.net>
parents:
69998
diff
changeset
|
3320 *minor = libver & 0xFF; |
|
52ed0c6bb461
Issue #12440: When testing whether some bits in SSLContext.options can be
Antoine Pitrou <solipsis@pitrou.net>
parents:
69998
diff
changeset
|
3321 libver >>= 8; |
|
52ed0c6bb461
Issue #12440: When testing whether some bits in SSLContext.options can be
Antoine Pitrou <solipsis@pitrou.net>
parents:
69998
diff
changeset
|
3322 *major = libver & 0xFF; |
|
52ed0c6bb461
Issue #12440: When testing whether some bits in SSLContext.options can be
Antoine Pitrou <solipsis@pitrou.net>
parents:
69998
diff
changeset
|
3323 } |
|
52ed0c6bb461
Issue #12440: When testing whether some bits in SSLContext.options can be
Antoine Pitrou <solipsis@pitrou.net>
parents:
69998
diff
changeset
|
3324 |
|
24471
f66b3a3509c7
Excise DL_EXPORT/DL_IMPORT from Modules/*. Required adding a prototype
Mark Hammond <mhammond@skippinet.com.au>
parents:
24398
diff
changeset
|
3325 PyMODINIT_FUNC |
|
47580
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47301
diff
changeset
|
3326 PyInit__ssl(void) |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
3327 { |
|
61244
35221c0158b5
Merged revisions 80789 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61017
diff
changeset
|
3328 PyObject *m, *d, *r; |
|
35221c0158b5
Merged revisions 80789 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61017
diff
changeset
|
3329 unsigned long libver; |
|
35221c0158b5
Merged revisions 80789 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61017
diff
changeset
|
3330 unsigned int major, minor, fix, patch, status; |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
3331 PySocketModule_APIObject *socket_api; |
|
77578
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
3332 struct py_ssl_error_code *errcode; |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
3333 struct py_ssl_library_code *libcode; |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
3334 |
|
61635
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
3335 if (PyType_Ready(&PySSLContext_Type) < 0) |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
3336 return NULL; |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
3337 if (PyType_Ready(&PySSLSocket_Type) < 0) |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
3338 return NULL; |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
3339 |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
3340 m = PyModule_Create(&_sslmodule); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
3341 if (m == NULL) |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
3342 return NULL; |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
3343 d = PyModule_GetDict(m); |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
3344 |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
3345 /* Load _socket module and its C API */ |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
3346 socket_api = PySocketModule_ImportModuleAndAPI(); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
3347 if (!socket_api) |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
3348 return NULL; |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
3349 PySocketModule = *socket_api; |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
3350 |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
3351 /* Init OpenSSL */ |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
3352 SSL_load_error_strings(); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
3353 SSL_library_init(); |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
3354 #ifdef WITH_THREAD |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
3355 /* note that this will start threading if not already started */ |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
3356 if (!_setup_ssl_threads()) { |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
3357 return NULL; |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
3358 } |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
3359 #endif |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
3360 OpenSSL_add_all_algorithms(); |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
3361 |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
3362 /* Add symbols to module dict */ |
|
77578
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
3363 sslerror_type_slots[0].pfunc = PyExc_OSError; |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
3364 PySSLErrorObject = PyType_FromSpec(&sslerror_type_spec); |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
3365 if (PySSLErrorObject == NULL) |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
3366 return NULL; |
|
77578
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
3367 |
|
73150
2c4a9c778bb3
Issue #11183: Add finer-grained exceptions to the ssl module, so that
Antoine Pitrou <solipsis@pitrou.net>
parents:
73059
diff
changeset
|
3368 PySSLZeroReturnErrorObject = PyErr_NewExceptionWithDoc( |
|
2c4a9c778bb3
Issue #11183: Add finer-grained exceptions to the ssl module, so that
Antoine Pitrou <solipsis@pitrou.net>
parents:
73059
diff
changeset
|
3369 "ssl.SSLZeroReturnError", SSLZeroReturnError_doc, |
|
2c4a9c778bb3
Issue #11183: Add finer-grained exceptions to the ssl module, so that
Antoine Pitrou <solipsis@pitrou.net>
parents:
73059
diff
changeset
|
3370 PySSLErrorObject, NULL); |
|
2c4a9c778bb3
Issue #11183: Add finer-grained exceptions to the ssl module, so that
Antoine Pitrou <solipsis@pitrou.net>
parents:
73059
diff
changeset
|
3371 PySSLWantReadErrorObject = PyErr_NewExceptionWithDoc( |
|
2c4a9c778bb3
Issue #11183: Add finer-grained exceptions to the ssl module, so that
Antoine Pitrou <solipsis@pitrou.net>
parents:
73059
diff
changeset
|
3372 "ssl.SSLWantReadError", SSLWantReadError_doc, |
|
2c4a9c778bb3
Issue #11183: Add finer-grained exceptions to the ssl module, so that
Antoine Pitrou <solipsis@pitrou.net>
parents:
73059
diff
changeset
|
3373 PySSLErrorObject, NULL); |
|
2c4a9c778bb3
Issue #11183: Add finer-grained exceptions to the ssl module, so that
Antoine Pitrou <solipsis@pitrou.net>
parents:
73059
diff
changeset
|
3374 PySSLWantWriteErrorObject = PyErr_NewExceptionWithDoc( |
|
2c4a9c778bb3
Issue #11183: Add finer-grained exceptions to the ssl module, so that
Antoine Pitrou <solipsis@pitrou.net>
parents:
73059
diff
changeset
|
3375 "ssl.SSLWantWriteError", SSLWantWriteError_doc, |
|
2c4a9c778bb3
Issue #11183: Add finer-grained exceptions to the ssl module, so that
Antoine Pitrou <solipsis@pitrou.net>
parents:
73059
diff
changeset
|
3376 PySSLErrorObject, NULL); |
|
2c4a9c778bb3
Issue #11183: Add finer-grained exceptions to the ssl module, so that
Antoine Pitrou <solipsis@pitrou.net>
parents:
73059
diff
changeset
|
3377 PySSLSyscallErrorObject = PyErr_NewExceptionWithDoc( |
|
2c4a9c778bb3
Issue #11183: Add finer-grained exceptions to the ssl module, so that
Antoine Pitrou <solipsis@pitrou.net>
parents:
73059
diff
changeset
|
3378 "ssl.SSLSyscallError", SSLSyscallError_doc, |
|
2c4a9c778bb3
Issue #11183: Add finer-grained exceptions to the ssl module, so that
Antoine Pitrou <solipsis@pitrou.net>
parents:
73059
diff
changeset
|
3379 PySSLErrorObject, NULL); |
|
2c4a9c778bb3
Issue #11183: Add finer-grained exceptions to the ssl module, so that
Antoine Pitrou <solipsis@pitrou.net>
parents:
73059
diff
changeset
|
3380 PySSLEOFErrorObject = PyErr_NewExceptionWithDoc( |
|
2c4a9c778bb3
Issue #11183: Add finer-grained exceptions to the ssl module, so that
Antoine Pitrou <solipsis@pitrou.net>
parents:
73059
diff
changeset
|
3381 "ssl.SSLEOFError", SSLEOFError_doc, |
|
2c4a9c778bb3
Issue #11183: Add finer-grained exceptions to the ssl module, so that
Antoine Pitrou <solipsis@pitrou.net>
parents:
73059
diff
changeset
|
3382 PySSLErrorObject, NULL); |
|
2c4a9c778bb3
Issue #11183: Add finer-grained exceptions to the ssl module, so that
Antoine Pitrou <solipsis@pitrou.net>
parents:
73059
diff
changeset
|
3383 if (PySSLZeroReturnErrorObject == NULL |
|
2c4a9c778bb3
Issue #11183: Add finer-grained exceptions to the ssl module, so that
Antoine Pitrou <solipsis@pitrou.net>
parents:
73059
diff
changeset
|
3384 || PySSLWantReadErrorObject == NULL |
|
2c4a9c778bb3
Issue #11183: Add finer-grained exceptions to the ssl module, so that
Antoine Pitrou <solipsis@pitrou.net>
parents:
73059
diff
changeset
|
3385 || PySSLWantWriteErrorObject == NULL |
|
2c4a9c778bb3
Issue #11183: Add finer-grained exceptions to the ssl module, so that
Antoine Pitrou <solipsis@pitrou.net>
parents:
73059
diff
changeset
|
3386 || PySSLSyscallErrorObject == NULL |
|
2c4a9c778bb3
Issue #11183: Add finer-grained exceptions to the ssl module, so that
Antoine Pitrou <solipsis@pitrou.net>
parents:
73059
diff
changeset
|
3387 || PySSLEOFErrorObject == NULL) |
|
2c4a9c778bb3
Issue #11183: Add finer-grained exceptions to the ssl module, so that
Antoine Pitrou <solipsis@pitrou.net>
parents:
73059
diff
changeset
|
3388 return NULL; |
|
2c4a9c778bb3
Issue #11183: Add finer-grained exceptions to the ssl module, so that
Antoine Pitrou <solipsis@pitrou.net>
parents:
73059
diff
changeset
|
3389 if (PyDict_SetItemString(d, "SSLError", PySSLErrorObject) != 0 |
|
2c4a9c778bb3
Issue #11183: Add finer-grained exceptions to the ssl module, so that
Antoine Pitrou <solipsis@pitrou.net>
parents:
73059
diff
changeset
|
3390 || PyDict_SetItemString(d, "SSLZeroReturnError", PySSLZeroReturnErrorObject) != 0 |
|
2c4a9c778bb3
Issue #11183: Add finer-grained exceptions to the ssl module, so that
Antoine Pitrou <solipsis@pitrou.net>
parents:
73059
diff
changeset
|
3391 || PyDict_SetItemString(d, "SSLWantReadError", PySSLWantReadErrorObject) != 0 |
|
2c4a9c778bb3
Issue #11183: Add finer-grained exceptions to the ssl module, so that
Antoine Pitrou <solipsis@pitrou.net>
parents:
73059
diff
changeset
|
3392 || PyDict_SetItemString(d, "SSLWantWriteError", PySSLWantWriteErrorObject) != 0 |
|
2c4a9c778bb3
Issue #11183: Add finer-grained exceptions to the ssl module, so that
Antoine Pitrou <solipsis@pitrou.net>
parents:
73059
diff
changeset
|
3393 || PyDict_SetItemString(d, "SSLSyscallError", PySSLSyscallErrorObject) != 0 |
|
2c4a9c778bb3
Issue #11183: Add finer-grained exceptions to the ssl module, so that
Antoine Pitrou <solipsis@pitrou.net>
parents:
73059
diff
changeset
|
3394 || PyDict_SetItemString(d, "SSLEOFError", PySSLEOFErrorObject) != 0) |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
3395 return NULL; |
|
61635
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
3396 if (PyDict_SetItemString(d, "_SSLContext", |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
3397 (PyObject *)&PySSLContext_Type) != 0) |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
3398 return NULL; |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
3399 if (PyDict_SetItemString(d, "_SSLSocket", |
|
4bb03cc1d421
Issue #8550: Add first class `SSLContext` objects to the ssl module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61535
diff
changeset
|
3400 (PyObject *)&PySSLSocket_Type) != 0) |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
3401 return NULL; |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
3402 PyModule_AddIntConstant(m, "SSL_ERROR_ZERO_RETURN", |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
3403 PY_SSL_ERROR_ZERO_RETURN); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
3404 PyModule_AddIntConstant(m, "SSL_ERROR_WANT_READ", |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
3405 PY_SSL_ERROR_WANT_READ); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
3406 PyModule_AddIntConstant(m, "SSL_ERROR_WANT_WRITE", |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
3407 PY_SSL_ERROR_WANT_WRITE); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
3408 PyModule_AddIntConstant(m, "SSL_ERROR_WANT_X509_LOOKUP", |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
3409 PY_SSL_ERROR_WANT_X509_LOOKUP); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
3410 PyModule_AddIntConstant(m, "SSL_ERROR_SYSCALL", |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
3411 PY_SSL_ERROR_SYSCALL); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
3412 PyModule_AddIntConstant(m, "SSL_ERROR_SSL", |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
3413 PY_SSL_ERROR_SSL); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
3414 PyModule_AddIntConstant(m, "SSL_ERROR_WANT_CONNECT", |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
3415 PY_SSL_ERROR_WANT_CONNECT); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
3416 /* non ssl.h errorcodes */ |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
3417 PyModule_AddIntConstant(m, "SSL_ERROR_EOF", |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
3418 PY_SSL_ERROR_EOF); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
3419 PyModule_AddIntConstant(m, "SSL_ERROR_INVALID_ERROR_CODE", |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
3420 PY_SSL_ERROR_INVALID_ERROR_CODE); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
3421 /* cert requirements */ |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
3422 PyModule_AddIntConstant(m, "CERT_NONE", |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
3423 PY_SSL_CERT_NONE); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
3424 PyModule_AddIntConstant(m, "CERT_OPTIONAL", |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
3425 PY_SSL_CERT_OPTIONAL); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
3426 PyModule_AddIntConstant(m, "CERT_REQUIRED", |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
3427 PY_SSL_CERT_REQUIRED); |
|
23190
0bc3a41d4e40
Forward port of patch # 500311: Work around for buggy https servers.
Martin v. Löwis <martin@v.loewis.de>
parents:
21959
diff
changeset
|
3428 |
|
84071
10d325f674f5
Issue #17134: Add ssl.enum_cert_store() as interface to Windows' cert store.
Christian Heimes <christian@cheimes.de>
parents:
84070
diff
changeset
|
3429 #ifdef _MSC_VER |
|
10d325f674f5
Issue #17134: Add ssl.enum_cert_store() as interface to Windows' cert store.
Christian Heimes <christian@cheimes.de>
parents:
84070
diff
changeset
|
3430 /* Windows dwCertEncodingType */ |
|
10d325f674f5
Issue #17134: Add ssl.enum_cert_store() as interface to Windows' cert store.
Christian Heimes <christian@cheimes.de>
parents:
84070
diff
changeset
|
3431 PyModule_AddIntMacro(m, X509_ASN_ENCODING); |
|
10d325f674f5
Issue #17134: Add ssl.enum_cert_store() as interface to Windows' cert store.
Christian Heimes <christian@cheimes.de>
parents:
84070
diff
changeset
|
3432 PyModule_AddIntMacro(m, PKCS_7_ASN_ENCODING); |
|
10d325f674f5
Issue #17134: Add ssl.enum_cert_store() as interface to Windows' cert store.
Christian Heimes <christian@cheimes.de>
parents:
84070
diff
changeset
|
3433 #endif |
|
10d325f674f5
Issue #17134: Add ssl.enum_cert_store() as interface to Windows' cert store.
Christian Heimes <christian@cheimes.de>
parents:
84070
diff
changeset
|
3434 |
|
81298
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
3435 /* Alert Descriptions from ssl.h */ |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
3436 /* note RESERVED constants no longer intended for use have been removed */ |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
3437 /* http://www.iana.org/assignments/tls-parameters/tls-parameters.xml#tls-parameters-6 */ |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
3438 |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
3439 #define ADD_AD_CONSTANT(s) \ |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
3440 PyModule_AddIntConstant(m, "ALERT_DESCRIPTION_"#s, \ |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
3441 SSL_AD_##s) |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
3442 |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
3443 ADD_AD_CONSTANT(CLOSE_NOTIFY); |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
3444 ADD_AD_CONSTANT(UNEXPECTED_MESSAGE); |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
3445 ADD_AD_CONSTANT(BAD_RECORD_MAC); |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
3446 ADD_AD_CONSTANT(RECORD_OVERFLOW); |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
3447 ADD_AD_CONSTANT(DECOMPRESSION_FAILURE); |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
3448 ADD_AD_CONSTANT(HANDSHAKE_FAILURE); |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
3449 ADD_AD_CONSTANT(BAD_CERTIFICATE); |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
3450 ADD_AD_CONSTANT(UNSUPPORTED_CERTIFICATE); |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
3451 ADD_AD_CONSTANT(CERTIFICATE_REVOKED); |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
3452 ADD_AD_CONSTANT(CERTIFICATE_EXPIRED); |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
3453 ADD_AD_CONSTANT(CERTIFICATE_UNKNOWN); |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
3454 ADD_AD_CONSTANT(ILLEGAL_PARAMETER); |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
3455 ADD_AD_CONSTANT(UNKNOWN_CA); |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
3456 ADD_AD_CONSTANT(ACCESS_DENIED); |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
3457 ADD_AD_CONSTANT(DECODE_ERROR); |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
3458 ADD_AD_CONSTANT(DECRYPT_ERROR); |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
3459 ADD_AD_CONSTANT(PROTOCOL_VERSION); |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
3460 ADD_AD_CONSTANT(INSUFFICIENT_SECURITY); |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
3461 ADD_AD_CONSTANT(INTERNAL_ERROR); |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
3462 ADD_AD_CONSTANT(USER_CANCELLED); |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
3463 ADD_AD_CONSTANT(NO_RENEGOTIATION); |
|
83021
02f9335b7efb
Issue #17581: try to fix building on old OpenSSL versions
Antoine Pitrou <solipsis@pitrou.net>
parents:
82992
diff
changeset
|
3464 /* Not all constants are in old OpenSSL versions */ |
|
02f9335b7efb
Issue #17581: try to fix building on old OpenSSL versions
Antoine Pitrou <solipsis@pitrou.net>
parents:
82992
diff
changeset
|
3465 #ifdef SSL_AD_UNSUPPORTED_EXTENSION |
|
81298
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
3466 ADD_AD_CONSTANT(UNSUPPORTED_EXTENSION); |
|
83021
02f9335b7efb
Issue #17581: try to fix building on old OpenSSL versions
Antoine Pitrou <solipsis@pitrou.net>
parents:
82992
diff
changeset
|
3467 #endif |
|
02f9335b7efb
Issue #17581: try to fix building on old OpenSSL versions
Antoine Pitrou <solipsis@pitrou.net>
parents:
82992
diff
changeset
|
3468 #ifdef SSL_AD_CERTIFICATE_UNOBTAINABLE |
|
81298
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
3469 ADD_AD_CONSTANT(CERTIFICATE_UNOBTAINABLE); |
|
83021
02f9335b7efb
Issue #17581: try to fix building on old OpenSSL versions
Antoine Pitrou <solipsis@pitrou.net>
parents:
82992
diff
changeset
|
3470 #endif |
|
02f9335b7efb
Issue #17581: try to fix building on old OpenSSL versions
Antoine Pitrou <solipsis@pitrou.net>
parents:
82992
diff
changeset
|
3471 #ifdef SSL_AD_UNRECOGNIZED_NAME |
|
81298
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
3472 ADD_AD_CONSTANT(UNRECOGNIZED_NAME); |
|
83021
02f9335b7efb
Issue #17581: try to fix building on old OpenSSL versions
Antoine Pitrou <solipsis@pitrou.net>
parents:
82992
diff
changeset
|
3473 #endif |
|
81298
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
3474 #ifdef SSL_AD_BAD_CERTIFICATE_STATUS_RESPONSE |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
3475 ADD_AD_CONSTANT(BAD_CERTIFICATE_STATUS_RESPONSE); |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
3476 #endif |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
3477 #ifdef SSL_AD_BAD_CERTIFICATE_HASH_VALUE |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
3478 ADD_AD_CONSTANT(BAD_CERTIFICATE_HASH_VALUE); |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
3479 #endif |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
3480 #ifdef SSL_AD_UNKNOWN_PSK_IDENTITY |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
3481 ADD_AD_CONSTANT(UNKNOWN_PSK_IDENTITY); |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
3482 #endif |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
3483 |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
3484 #undef ADD_AD_CONSTANT |
|
927afb7bca2a
Issue #8109: The ssl module now has support for server-side SNI, thanks to a :meth:`SSLContext.set_servername_callback` method.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79136
diff
changeset
|
3485 |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
3486 /* protocol versions */ |
|
69997
b7abf0590e1c
Issue #12012: ssl.PROTOCOL_SSLv2 becomes optional
Victor Stinner <victor.stinner@haypocalc.com>
parents:
66806
diff
changeset
|
3487 #ifndef OPENSSL_NO_SSL2 |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
3488 PyModule_AddIntConstant(m, "PROTOCOL_SSLv2", |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
3489 PY_SSL_VERSION_SSL2); |
|
69997
b7abf0590e1c
Issue #12012: ssl.PROTOCOL_SSLv2 becomes optional
Victor Stinner <victor.stinner@haypocalc.com>
parents:
66806
diff
changeset
|
3490 #endif |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
3491 PyModule_AddIntConstant(m, "PROTOCOL_SSLv3", |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
3492 PY_SSL_VERSION_SSL3); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
3493 PyModule_AddIntConstant(m, "PROTOCOL_SSLv23", |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
3494 PY_SSL_VERSION_SSL23); |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
3495 PyModule_AddIntConstant(m, "PROTOCOL_TLSv1", |
|
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
3496 PY_SSL_VERSION_TLS1); |
|
82992
02a89bd646ca
Issue #16692: The ssl module now supports TLS 1.1 and TLS 1.2. Initial patch by Michele Orrù.
Antoine Pitrou <solipsis@pitrou.net>
parents:
81559
diff
changeset
|
3497 #if HAVE_TLSv1_2 |
|
02a89bd646ca
Issue #16692: The ssl module now supports TLS 1.1 and TLS 1.2. Initial patch by Michele Orrù.
Antoine Pitrou <solipsis@pitrou.net>
parents:
81559
diff
changeset
|
3498 PyModule_AddIntConstant(m, "PROTOCOL_TLSv1_1", |
|
02a89bd646ca
Issue #16692: The ssl module now supports TLS 1.1 and TLS 1.2. Initial patch by Michele Orrù.
Antoine Pitrou <solipsis@pitrou.net>
parents:
81559
diff
changeset
|
3499 PY_SSL_VERSION_TLS1_1); |
|
02a89bd646ca
Issue #16692: The ssl module now supports TLS 1.1 and TLS 1.2. Initial patch by Michele Orrù.
Antoine Pitrou <solipsis@pitrou.net>
parents:
81559
diff
changeset
|
3500 PyModule_AddIntConstant(m, "PROTOCOL_TLSv1_2", |
|
02a89bd646ca
Issue #16692: The ssl module now supports TLS 1.1 and TLS 1.2. Initial patch by Michele Orrù.
Antoine Pitrou <solipsis@pitrou.net>
parents:
81559
diff
changeset
|
3501 PY_SSL_VERSION_TLS1_2); |
|
02a89bd646ca
Issue #16692: The ssl module now supports TLS 1.1 and TLS 1.2. Initial patch by Michele Orrù.
Antoine Pitrou <solipsis@pitrou.net>
parents:
81559
diff
changeset
|
3502 #endif |
|
60373
9e5e9d8fa847
Merged revisions 79812 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60034
diff
changeset
|
3503 |
|
61782
5ee47f0b26b0
Issue #4870: Add an `options` attribute to SSL contexts, as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
61644
diff
changeset
|
3504 /* protocol options */ |
|
74648
4386686a035d
Issue #13885: CVE-2011-3389: the _ssl module would always disable the CBC IV attack countermeasure.
Antoine Pitrou <solipsis@pitrou.net>
diff
changeset
|
3505 PyModule_AddIntConstant(m, "OP_ALL", |
|
4386686a035d
Issue #13885: CVE-2011-3389: the _ssl module would always disable the CBC IV attack countermeasure.
Antoine Pitrou <solipsis@pitrou.net>
diff
changeset
|
3506 SSL_OP_ALL & ~SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS); |
|
61782
5ee47f0b26b0
Issue #4870: Add an `options` attribute to SSL contexts, as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
61644
diff
changeset
|
3507 PyModule_AddIntConstant(m, "OP_NO_SSLv2", SSL_OP_NO_SSLv2); |
|
5ee47f0b26b0
Issue #4870: Add an `options` attribute to SSL contexts, as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
61644
diff
changeset
|
3508 PyModule_AddIntConstant(m, "OP_NO_SSLv3", SSL_OP_NO_SSLv3); |
|
5ee47f0b26b0
Issue #4870: Add an `options` attribute to SSL contexts, as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
61644
diff
changeset
|
3509 PyModule_AddIntConstant(m, "OP_NO_TLSv1", SSL_OP_NO_TLSv1); |
|
82992
02a89bd646ca
Issue #16692: The ssl module now supports TLS 1.1 and TLS 1.2. Initial patch by Michele Orrù.
Antoine Pitrou <solipsis@pitrou.net>
parents:
81559
diff
changeset
|
3510 #if HAVE_TLSv1_2 |
|
02a89bd646ca
Issue #16692: The ssl module now supports TLS 1.1 and TLS 1.2. Initial patch by Michele Orrù.
Antoine Pitrou <solipsis@pitrou.net>
parents:
81559
diff
changeset
|
3511 PyModule_AddIntConstant(m, "OP_NO_TLSv1_1", SSL_OP_NO_TLSv1_1); |
|
02a89bd646ca
Issue #16692: The ssl module now supports TLS 1.1 and TLS 1.2. Initial patch by Michele Orrù.
Antoine Pitrou <solipsis@pitrou.net>
parents:
81559
diff
changeset
|
3512 PyModule_AddIntConstant(m, "OP_NO_TLSv1_2", SSL_OP_NO_TLSv1_2); |
|
02a89bd646ca
Issue #16692: The ssl module now supports TLS 1.1 and TLS 1.2. Initial patch by Michele Orrù.
Antoine Pitrou <solipsis@pitrou.net>
parents:
81559
diff
changeset
|
3513 #endif |
|
74075
c706f76c9ea8
Issue #13635: Add ssl.OP_CIPHER_SERVER_PREFERENCE, so that SSL servers
Antoine Pitrou <solipsis@pitrou.net>
parents:
73712
diff
changeset
|
3514 PyModule_AddIntConstant(m, "OP_CIPHER_SERVER_PREFERENCE", |
|
c706f76c9ea8
Issue #13635: Add ssl.OP_CIPHER_SERVER_PREFERENCE, so that SSL servers
Antoine Pitrou <solipsis@pitrou.net>
parents:
73712
diff
changeset
|
3515 SSL_OP_CIPHER_SERVER_PREFERENCE); |
|
74129
33dea851f918
Issue #13626: Add support for SSL Diffie-Hellman key exchange, through the
Antoine Pitrou <solipsis@pitrou.net>
parents:
74103
diff
changeset
|
3516 PyModule_AddIntConstant(m, "OP_SINGLE_DH_USE", SSL_OP_SINGLE_DH_USE); |
|
74995
c1a07c8092f7
Fix compilation when SSL_OP_SINGLE_ECDH_USE isn't defined
Antoine Pitrou <solipsis@pitrou.net>
parents:
74964
diff
changeset
|
3517 #ifdef SSL_OP_SINGLE_ECDH_USE |
|
74084
8b729d65cfd2
Issue #13627: Add support for SSL Elliptic Curve-based Diffie-Hellman
Antoine Pitrou <solipsis@pitrou.net>
parents:
74075
diff
changeset
|
3518 PyModule_AddIntConstant(m, "OP_SINGLE_ECDH_USE", SSL_OP_SINGLE_ECDH_USE); |
|
74995
c1a07c8092f7
Fix compilation when SSL_OP_SINGLE_ECDH_USE isn't defined
Antoine Pitrou <solipsis@pitrou.net>
parents:
74964
diff
changeset
|
3519 #endif |
|
74091
20b52be99b5d
Issue #13634: Add support for querying and disabling SSL compression.
Antoine Pitrou <solipsis@pitrou.net>
parents:
74084
diff
changeset
|
3520 #ifdef SSL_OP_NO_COMPRESSION |
|
20b52be99b5d
Issue #13634: Add support for querying and disabling SSL compression.
Antoine Pitrou <solipsis@pitrou.net>
parents:
74084
diff
changeset
|
3521 PyModule_AddIntConstant(m, "OP_NO_COMPRESSION", |
|
20b52be99b5d
Issue #13634: Add support for querying and disabling SSL compression.
Antoine Pitrou <solipsis@pitrou.net>
parents:
74084
diff
changeset
|
3522 SSL_OP_NO_COMPRESSION); |
|
20b52be99b5d
Issue #13634: Add support for querying and disabling SSL compression.
Antoine Pitrou <solipsis@pitrou.net>
parents:
74084
diff
changeset
|
3523 #endif |
|
61782
5ee47f0b26b0
Issue #4870: Add an `options` attribute to SSL contexts, as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
61644
diff
changeset
|
3524 |
|
83021
02f9335b7efb
Issue #17581: try to fix building on old OpenSSL versions
Antoine Pitrou <solipsis@pitrou.net>
parents:
82992
diff
changeset
|
3525 #if HAVE_SNI |
|
65593
846c0e1342d0
Issue #5639: Add a *server_hostname* argument to `SSLContext.wrap_socket`
Antoine Pitrou <solipsis@pitrou.net>
parents:
65267
diff
changeset
|
3526 r = Py_True; |
|
846c0e1342d0
Issue #5639: Add a *server_hostname* argument to `SSLContext.wrap_socket`
Antoine Pitrou <solipsis@pitrou.net>
parents:
65267
diff
changeset
|
3527 #else |
|
846c0e1342d0
Issue #5639: Add a *server_hostname* argument to `SSLContext.wrap_socket`
Antoine Pitrou <solipsis@pitrou.net>
parents:
65267
diff
changeset
|
3528 r = Py_False; |
|
846c0e1342d0
Issue #5639: Add a *server_hostname* argument to `SSLContext.wrap_socket`
Antoine Pitrou <solipsis@pitrou.net>
parents:
65267
diff
changeset
|
3529 #endif |
|
846c0e1342d0
Issue #5639: Add a *server_hostname* argument to `SSLContext.wrap_socket`
Antoine Pitrou <solipsis@pitrou.net>
parents:
65267
diff
changeset
|
3530 Py_INCREF(r); |
|
846c0e1342d0
Issue #5639: Add a *server_hostname* argument to `SSLContext.wrap_socket`
Antoine Pitrou <solipsis@pitrou.net>
parents:
65267
diff
changeset
|
3531 PyModule_AddObject(m, "HAS_SNI", r); |
|
846c0e1342d0
Issue #5639: Add a *server_hostname* argument to `SSLContext.wrap_socket`
Antoine Pitrou <solipsis@pitrou.net>
parents:
65267
diff
changeset
|
3532 |
|
71440
cb44fef5ea1d
Issue #12551: Provide a get_channel_binding() method on SSL sockets so as
Antoine Pitrou <solipsis@pitrou.net>
parents:
71256
diff
changeset
|
3533 #if HAVE_OPENSSL_FINISHED |
|
cb44fef5ea1d
Issue #12551: Provide a get_channel_binding() method on SSL sockets so as
Antoine Pitrou <solipsis@pitrou.net>
parents:
71256
diff
changeset
|
3534 r = Py_True; |
|
cb44fef5ea1d
Issue #12551: Provide a get_channel_binding() method on SSL sockets so as
Antoine Pitrou <solipsis@pitrou.net>
parents:
71256
diff
changeset
|
3535 #else |
|
cb44fef5ea1d
Issue #12551: Provide a get_channel_binding() method on SSL sockets so as
Antoine Pitrou <solipsis@pitrou.net>
parents:
71256
diff
changeset
|
3536 r = Py_False; |
|
cb44fef5ea1d
Issue #12551: Provide a get_channel_binding() method on SSL sockets so as
Antoine Pitrou <solipsis@pitrou.net>
parents:
71256
diff
changeset
|
3537 #endif |
|
cb44fef5ea1d
Issue #12551: Provide a get_channel_binding() method on SSL sockets so as
Antoine Pitrou <solipsis@pitrou.net>
parents:
71256
diff
changeset
|
3538 Py_INCREF(r); |
|
cb44fef5ea1d
Issue #12551: Provide a get_channel_binding() method on SSL sockets so as
Antoine Pitrou <solipsis@pitrou.net>
parents:
71256
diff
changeset
|
3539 PyModule_AddObject(m, "HAS_TLS_UNIQUE", r); |
|
cb44fef5ea1d
Issue #12551: Provide a get_channel_binding() method on SSL sockets so as
Antoine Pitrou <solipsis@pitrou.net>
parents:
71256
diff
changeset
|
3540 |
|
74103
ec44f2e82707
Fix ssl module compilation if ECDH support was disabled in the OpenSSL build.
Antoine Pitrou <solipsis@pitrou.net>
parents:
74091
diff
changeset
|
3541 #ifdef OPENSSL_NO_ECDH |
|
ec44f2e82707
Fix ssl module compilation if ECDH support was disabled in the OpenSSL build.
Antoine Pitrou <solipsis@pitrou.net>
parents:
74091
diff
changeset
|
3542 r = Py_False; |
|
ec44f2e82707
Fix ssl module compilation if ECDH support was disabled in the OpenSSL build.
Antoine Pitrou <solipsis@pitrou.net>
parents:
74091
diff
changeset
|
3543 #else |
|
ec44f2e82707
Fix ssl module compilation if ECDH support was disabled in the OpenSSL build.
Antoine Pitrou <solipsis@pitrou.net>
parents:
74091
diff
changeset
|
3544 r = Py_True; |
|
ec44f2e82707
Fix ssl module compilation if ECDH support was disabled in the OpenSSL build.
Antoine Pitrou <solipsis@pitrou.net>
parents:
74091
diff
changeset
|
3545 #endif |
|
ec44f2e82707
Fix ssl module compilation if ECDH support was disabled in the OpenSSL build.
Antoine Pitrou <solipsis@pitrou.net>
parents:
74091
diff
changeset
|
3546 Py_INCREF(r); |
|
ec44f2e82707
Fix ssl module compilation if ECDH support was disabled in the OpenSSL build.
Antoine Pitrou <solipsis@pitrou.net>
parents:
74091
diff
changeset
|
3547 PyModule_AddObject(m, "HAS_ECDH", r); |
|
ec44f2e82707
Fix ssl module compilation if ECDH support was disabled in the OpenSSL build.
Antoine Pitrou <solipsis@pitrou.net>
parents:
74091
diff
changeset
|
3548 |
|
75865
2514a4e2b3ce
Issue #14204: The ssl module now has support for the Next Protocol Negotiation extension, if available in the underlying OpenSSL library.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75043
diff
changeset
|
3549 #ifdef OPENSSL_NPN_NEGOTIATED |
|
2514a4e2b3ce
Issue #14204: The ssl module now has support for the Next Protocol Negotiation extension, if available in the underlying OpenSSL library.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75043
diff
changeset
|
3550 r = Py_True; |
|
2514a4e2b3ce
Issue #14204: The ssl module now has support for the Next Protocol Negotiation extension, if available in the underlying OpenSSL library.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75043
diff
changeset
|
3551 #else |
|
2514a4e2b3ce
Issue #14204: The ssl module now has support for the Next Protocol Negotiation extension, if available in the underlying OpenSSL library.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75043
diff
changeset
|
3552 r = Py_False; |
|
2514a4e2b3ce
Issue #14204: The ssl module now has support for the Next Protocol Negotiation extension, if available in the underlying OpenSSL library.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75043
diff
changeset
|
3553 #endif |
|
2514a4e2b3ce
Issue #14204: The ssl module now has support for the Next Protocol Negotiation extension, if available in the underlying OpenSSL library.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75043
diff
changeset
|
3554 Py_INCREF(r); |
|
2514a4e2b3ce
Issue #14204: The ssl module now has support for the Next Protocol Negotiation extension, if available in the underlying OpenSSL library.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75043
diff
changeset
|
3555 PyModule_AddObject(m, "HAS_NPN", r); |
|
2514a4e2b3ce
Issue #14204: The ssl module now has support for the Next Protocol Negotiation extension, if available in the underlying OpenSSL library.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75043
diff
changeset
|
3556 |
|
77578
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
3557 /* Mappings for error codes */ |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
3558 err_codes_to_names = PyDict_New(); |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
3559 err_names_to_codes = PyDict_New(); |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
3560 if (err_codes_to_names == NULL || err_names_to_codes == NULL) |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
3561 return NULL; |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
3562 errcode = error_codes; |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
3563 while (errcode->mnemonic != NULL) { |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
3564 PyObject *mnemo, *key; |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
3565 mnemo = PyUnicode_FromString(errcode->mnemonic); |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
3566 key = Py_BuildValue("ii", errcode->library, errcode->reason); |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
3567 if (mnemo == NULL || key == NULL) |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
3568 return NULL; |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
3569 if (PyDict_SetItem(err_codes_to_names, key, mnemo)) |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
3570 return NULL; |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
3571 if (PyDict_SetItem(err_names_to_codes, mnemo, key)) |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
3572 return NULL; |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
3573 Py_DECREF(key); |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
3574 Py_DECREF(mnemo); |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
3575 errcode++; |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
3576 } |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
3577 if (PyModule_AddObject(m, "err_codes_to_names", err_codes_to_names)) |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
3578 return NULL; |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
3579 if (PyModule_AddObject(m, "err_names_to_codes", err_names_to_codes)) |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
3580 return NULL; |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
3581 |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
3582 lib_codes_to_names = PyDict_New(); |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
3583 if (lib_codes_to_names == NULL) |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
3584 return NULL; |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
3585 libcode = library_codes; |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
3586 while (libcode->library != NULL) { |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
3587 PyObject *mnemo, *key; |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
3588 key = PyLong_FromLong(libcode->code); |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
3589 mnemo = PyUnicode_FromString(libcode->library); |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
3590 if (key == NULL || mnemo == NULL) |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
3591 return NULL; |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
3592 if (PyDict_SetItem(lib_codes_to_names, key, mnemo)) |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
3593 return NULL; |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
3594 Py_DECREF(key); |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
3595 Py_DECREF(mnemo); |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
3596 libcode++; |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
3597 } |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
3598 if (PyModule_AddObject(m, "lib_codes_to_names", lib_codes_to_names)) |
|
96513d71e650
Issue #14837: SSL errors now have `library` and `reason` attributes describing precisely what happened and in which OpenSSL submodule.
Antoine Pitrou <solipsis@pitrou.net>
parents:
75865
diff
changeset
|
3599 return NULL; |
|
84269
1bd49f8a30da
_ssl.c: strip trailing spaces
Victor Stinner <victor.stinner@gmail.com>
parents:
81463
diff
changeset
|
3600 |
|
61244
35221c0158b5
Merged revisions 80789 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61017
diff
changeset
|
3601 /* OpenSSL version */ |
|
35221c0158b5
Merged revisions 80789 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61017
diff
changeset
|
3602 /* SSLeay() gives us the version of the library linked against, |
|
35221c0158b5
Merged revisions 80789 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61017
diff
changeset
|
3603 which could be different from the headers version. |
|
35221c0158b5
Merged revisions 80789 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61017
diff
changeset
|
3604 */ |
|
35221c0158b5
Merged revisions 80789 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61017
diff
changeset
|
3605 libver = SSLeay(); |
|
35221c0158b5
Merged revisions 80789 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61017
diff
changeset
|
3606 r = PyLong_FromUnsignedLong(libver); |
|
35221c0158b5
Merged revisions 80789 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61017
diff
changeset
|
3607 if (r == NULL) |
|
35221c0158b5
Merged revisions 80789 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61017
diff
changeset
|
3608 return NULL; |
|
35221c0158b5
Merged revisions 80789 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61017
diff
changeset
|
3609 if (PyModule_AddObject(m, "OPENSSL_VERSION_NUMBER", r)) |
|
35221c0158b5
Merged revisions 80789 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61017
diff
changeset
|
3610 return NULL; |
|
71255
52ed0c6bb461
Issue #12440: When testing whether some bits in SSLContext.options can be
Antoine Pitrou <solipsis@pitrou.net>
parents:
69998
diff
changeset
|
3611 parse_openssl_version(libver, &major, &minor, &fix, &patch, &status); |
|
61244
35221c0158b5
Merged revisions 80789 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61017
diff
changeset
|
3612 r = Py_BuildValue("IIIII", major, minor, fix, patch, status); |
|
35221c0158b5
Merged revisions 80789 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61017
diff
changeset
|
3613 if (r == NULL || PyModule_AddObject(m, "OPENSSL_VERSION_INFO", r)) |
|
35221c0158b5
Merged revisions 80789 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61017
diff
changeset
|
3614 return NULL; |
|
35221c0158b5
Merged revisions 80789 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61017
diff
changeset
|
3615 r = PyUnicode_FromString(SSLeay_version(SSLEAY_VERSION)); |
|
35221c0158b5
Merged revisions 80789 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61017
diff
changeset
|
3616 if (r == NULL || PyModule_AddObject(m, "OPENSSL_VERSION", r)) |
|
35221c0158b5
Merged revisions 80789 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61017
diff
changeset
|
3617 return NULL; |
|
60373
9e5e9d8fa847
Merged revisions 79812 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60034
diff
changeset
|
3618 |
|
71255
52ed0c6bb461
Issue #12440: When testing whether some bits in SSLContext.options can be
Antoine Pitrou <solipsis@pitrou.net>
parents:
69998
diff
changeset
|
3619 libver = OPENSSL_VERSION_NUMBER; |
|
52ed0c6bb461
Issue #12440: When testing whether some bits in SSLContext.options can be
Antoine Pitrou <solipsis@pitrou.net>
parents:
69998
diff
changeset
|
3620 parse_openssl_version(libver, &major, &minor, &fix, &patch, &status); |
|
52ed0c6bb461
Issue #12440: When testing whether some bits in SSLContext.options can be
Antoine Pitrou <solipsis@pitrou.net>
parents:
69998
diff
changeset
|
3621 r = Py_BuildValue("IIIII", major, minor, fix, patch, status); |
|
52ed0c6bb461
Issue #12440: When testing whether some bits in SSLContext.options can be
Antoine Pitrou <solipsis@pitrou.net>
parents:
69998
diff
changeset
|
3622 if (r == NULL || PyModule_AddObject(m, "_OPENSSL_API_VERSION", r)) |
|
52ed0c6bb461
Issue #12440: When testing whether some bits in SSLContext.options can be
Antoine Pitrou <solipsis@pitrou.net>
parents:
69998
diff
changeset
|
3623 return NULL; |
|
52ed0c6bb461
Issue #12440: When testing whether some bits in SSLContext.options can be
Antoine Pitrou <solipsis@pitrou.net>
parents:
69998
diff
changeset
|
3624 |
|
85290
8e1194c39bed
Issue #18747: Re-seed OpenSSL's pseudo-random number generator after fork.
Christian Heimes <christian@cheimes.de>
parents:
85263
diff
changeset
|
3625 #ifdef PYSSL_RAND_ATFORK |
|
8e1194c39bed
Issue #18747: Re-seed OpenSSL's pseudo-random number generator after fork.
Christian Heimes <christian@cheimes.de>
parents:
85263
diff
changeset
|
3626 if (PySSL_RAND_atfork() == -1) |
|
8e1194c39bed
Issue #18747: Re-seed OpenSSL's pseudo-random number generator after fork.
Christian Heimes <christian@cheimes.de>
parents:
85263
diff
changeset
|
3627 return NULL; |
|
8e1194c39bed
Issue #18747: Re-seed OpenSSL's pseudo-random number generator after fork.
Christian Heimes <christian@cheimes.de>
parents:
85263
diff
changeset
|
3628 #endif |
|
8e1194c39bed
Issue #18747: Re-seed OpenSSL's pseudo-random number generator after fork.
Christian Heimes <christian@cheimes.de>
parents:
85263
diff
changeset
|
3629 |
|
61246
50a4ec37361d
Merged revisions 80790 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61018
diff
changeset
|
3630 return m; |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
3631 } |
