Mercurial > cpython-lru_cache-weakref
annotate Modules/_ssl.c @ 57114:d3a81051663b
importlib.test.source.util referenced variables in the 'finally' part of a
try/finally which may not have been set.
| author | Brett Cannon <bcannon@gmail.com> |
|---|---|
| date | Thu, 05 Nov 2009 01:17:22 +0000 |
| parents | f94c09aa4444 |
| children | 951c97e2878d a1d166ab18c4 |
| 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? |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
12 |
|
43869
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
13 XXX what about SSL_MODE_AUTO_RETRY? |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
14 */ |
|
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 #include "Python.h" |
|
42954
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
17 |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
18 #ifdef WITH_THREAD |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
19 #include "pythread.h" |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
20 #define PySSL_BEGIN_ALLOW_THREADS { \ |
|
43869
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
21 PyThreadState *_save = NULL; \ |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
22 if (_ssl_locks_count>0) {_save = PyEval_SaveThread();} |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
23 #define PySSL_BLOCK_THREADS if (_ssl_locks_count>0){PyEval_RestoreThread(_save)}; |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
24 #define PySSL_UNBLOCK_THREADS if (_ssl_locks_count>0){_save = PyEval_SaveThread()}; |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
25 #define PySSL_END_ALLOW_THREADS if (_ssl_locks_count>0){PyEval_RestoreThread(_save);} \ |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
26 } |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
27 |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
28 #else /* no WITH_THREAD */ |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
29 |
|
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 |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
31 #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
|
32 #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
|
33 #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
|
34 |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
35 #endif |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
36 |
|
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
|
37 enum py_ssl_error { |
|
0bc3a41d4e40
Forward port of patch # 500311: Work around for buggy https servers.
Martin v. Löwis <martin@v.loewis.de>
parents:
21959
diff
changeset
|
38 /* these mirror ssl.h */ |
|
42954
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
39 PY_SSL_ERROR_NONE, |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
40 PY_SSL_ERROR_SSL, |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
41 PY_SSL_ERROR_WANT_READ, |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
42 PY_SSL_ERROR_WANT_WRITE, |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
43 PY_SSL_ERROR_WANT_X509_LOOKUP, |
|
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
|
44 PY_SSL_ERROR_SYSCALL, /* look at error stack/return value/errno */ |
|
42954
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
45 PY_SSL_ERROR_ZERO_RETURN, |
|
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
|
46 PY_SSL_ERROR_WANT_CONNECT, |
|
42954
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
47 /* start of non ssl.h errorcodes */ |
|
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
|
48 PY_SSL_ERROR_EOF, /* special case of SSL_ERROR_SYSCALL */ |
|
44305
19f894ae864a
update to fix leak in SSL code
Bill Janssen <janssen@parc.com>
parents:
44206
diff
changeset
|
49 PY_SSL_ERROR_NO_SOCKET, /* socket has been GC'd */ |
|
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
|
50 PY_SSL_ERROR_INVALID_ERROR_CODE |
|
0bc3a41d4e40
Forward port of patch # 500311: Work around for buggy https servers.
Martin v. Löwis <martin@v.loewis.de>
parents:
21959
diff
changeset
|
51 }; |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
52 |
|
42954
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
53 enum py_ssl_server_or_client { |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
54 PY_SSL_CLIENT, |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
55 PY_SSL_SERVER |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
56 }; |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
57 |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
58 enum py_ssl_cert_requirements { |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
59 PY_SSL_CERT_NONE, |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
60 PY_SSL_CERT_OPTIONAL, |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
61 PY_SSL_CERT_REQUIRED |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
62 }; |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
63 |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
64 enum py_ssl_version { |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
65 PY_SSL_VERSION_SSL2, |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
66 PY_SSL_VERSION_SSL3, |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
67 PY_SSL_VERSION_SSL23, |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
68 PY_SSL_VERSION_TLS1, |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
69 }; |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
70 |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
71 /* Include symbols from _socket module */ |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
72 #include "socketmodule.h" |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
73 |
|
53816
911df82bc25d
add a replacement API for PyCObject, PyCapsule #5630
Benjamin Peterson <benjamin@python.org>
parents:
51922
diff
changeset
|
74 static PySocketModule_APIObject PySocketModule; |
|
911df82bc25d
add a replacement API for PyCObject, PyCapsule #5630
Benjamin Peterson <benjamin@python.org>
parents:
51922
diff
changeset
|
75 |
|
42954
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
76 #if defined(HAVE_POLL_H) |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38453
diff
changeset
|
77 #include <poll.h> |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38453
diff
changeset
|
78 #elif defined(HAVE_SYS_POLL_H) |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38453
diff
changeset
|
79 #include <sys/poll.h> |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38453
diff
changeset
|
80 #endif |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38453
diff
changeset
|
81 |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
82 /* Include OpenSSL header files */ |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
83 #include "openssl/rsa.h" |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
84 #include "openssl/crypto.h" |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
85 #include "openssl/x509.h" |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
86 #include "openssl/x509v3.h" |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
87 #include "openssl/pem.h" |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
88 #include "openssl/ssl.h" |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
89 #include "openssl/err.h" |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
90 #include "openssl/rand.h" |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
91 |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
92 /* SSL error object */ |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
93 static PyObject *PySSLErrorObject; |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
94 |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
95 #ifdef WITH_THREAD |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
96 |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
97 /* 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
|
98 /* 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
|
99 |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
100 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
|
101 |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
102 #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
|
103 |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
104 /* 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
|
105 |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
106 #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
|
107 |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
108 /* 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
|
109 #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
|
110 # 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
|
111 #else |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
112 # 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
|
113 #endif |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
114 |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
115 typedef struct { |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
116 PyObject_HEAD |
|
44305
19f894ae864a
update to fix leak in SSL code
Bill Janssen <janssen@parc.com>
parents:
44206
diff
changeset
|
117 PyObject *Socket; /* weakref to socket on which we're layered */ |
|
42954
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
118 SSL_CTX* ctx; |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
119 SSL* ssl; |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
120 X509* peer_cert; |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
121 |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
122 } PySSLObject; |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
123 |
|
24280
1598a1e473e2
staticforward bites the dust.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24086
diff
changeset
|
124 static PyTypeObject PySSL_Type; |
|
1598a1e473e2
staticforward bites the dust.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24086
diff
changeset
|
125 static PyObject *PySSL_SSLwrite(PySSLObject *self, PyObject *args); |
|
1598a1e473e2
staticforward bites the dust.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24086
diff
changeset
|
126 static PyObject *PySSL_SSLread(PySSLObject *self, PyObject *args); |
|
42954
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
127 static int check_socket_and_wait_for_timeout(PySocketSockObject *s, |
|
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
|
128 int writing); |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
129 static PyObject *PySSL_peercert(PySSLObject *self, PyObject *args); |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
130 static PyObject *PySSL_cipher(PySSLObject *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
|
131 |
|
44351
86a2679dca46
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents:
44310
diff
changeset
|
132 #define PySSLObject_Check(v) (Py_TYPE(v) == &PySSL_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
|
133 |
|
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
|
134 typedef enum { |
|
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
|
135 SOCKET_IS_NONBLOCKING, |
|
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
|
136 SOCKET_IS_BLOCKING, |
|
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
|
137 SOCKET_HAS_TIMED_OUT, |
|
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
|
138 SOCKET_HAS_BEEN_CLOSED, |
|
36487
07ba8aae3dc6
Try to improve name based on discussion on python-checkins with Jim Jewett
Neal Norwitz <nnorwitz@gmail.com>
parents:
36476
diff
changeset
|
139 SOCKET_TOO_LARGE_FOR_SELECT, |
|
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
|
140 SOCKET_OPERATION_OK |
|
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
|
141 } 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
|
142 |
|
42954
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
143 /* 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
|
144 #define STRINGIFY1(x) #x |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
145 #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
|
146 #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
|
147 #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
|
148 |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
149 /* XXX It might be helpful to augment the error message generated |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
150 below with the name of the SSL function that generated the error. |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
151 I expect it's obvious most of the time. |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
152 */ |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
153 |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
154 static PyObject * |
|
42954
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
155 PySSL_SetError(PySSLObject *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
|
156 { |
|
42954
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
157 PyObject *v; |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
158 char buf[2048]; |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
159 char *errstr; |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
160 int err; |
|
42954
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
161 enum py_ssl_error p = PY_SSL_ERROR_NONE; |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
162 |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
163 assert(ret <= 0); |
|
42954
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
164 |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
165 if (obj->ssl != NULL) { |
|
42954
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
166 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
|
167 |
|
42954
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
168 switch (err) { |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
169 case SSL_ERROR_ZERO_RETURN: |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
170 errstr = "TLS/SSL connection has been closed"; |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
171 p = PY_SSL_ERROR_ZERO_RETURN; |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
172 break; |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
173 case SSL_ERROR_WANT_READ: |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
174 errstr = "The operation did not complete (read)"; |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
175 p = PY_SSL_ERROR_WANT_READ; |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
176 break; |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
177 case SSL_ERROR_WANT_WRITE: |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
178 p = PY_SSL_ERROR_WANT_WRITE; |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
179 errstr = "The operation did not complete (write)"; |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
180 break; |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
181 case SSL_ERROR_WANT_X509_LOOKUP: |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
182 p = PY_SSL_ERROR_WANT_X509_LOOKUP; |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
183 errstr = |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
184 "The operation did not complete (X509 lookup)"; |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
185 break; |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
186 case SSL_ERROR_WANT_CONNECT: |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
187 p = PY_SSL_ERROR_WANT_CONNECT; |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
188 errstr = "The operation did not complete (connect)"; |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
189 break; |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
190 case SSL_ERROR_SYSCALL: |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
191 { |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
192 unsigned long e = ERR_get_error(); |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
193 if (e == 0) { |
|
44305
19f894ae864a
update to fix leak in SSL code
Bill Janssen <janssen@parc.com>
parents:
44206
diff
changeset
|
194 PySocketSockObject *s |
|
19f894ae864a
update to fix leak in SSL code
Bill Janssen <janssen@parc.com>
parents:
44206
diff
changeset
|
195 = (PySocketSockObject *) PyWeakref_GetObject(obj->Socket); |
|
19f894ae864a
update to fix leak in SSL code
Bill Janssen <janssen@parc.com>
parents:
44206
diff
changeset
|
196 if (ret == 0 || (((PyObject *)s) == Py_None)) { |
|
42954
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
197 p = PY_SSL_ERROR_EOF; |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
198 errstr = |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
199 "EOF occurred in violation of protocol"; |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
200 } else if (ret == -1) { |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
201 /* underlying BIO reported an I/O error */ |
|
44305
19f894ae864a
update to fix leak in SSL code
Bill Janssen <janssen@parc.com>
parents:
44206
diff
changeset
|
202 return s->errorhandler(); |
|
42954
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
203 } else { /* possible? */ |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
204 p = PY_SSL_ERROR_SYSCALL; |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
205 errstr = "Some I/O error occurred"; |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
206 } |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
207 } else { |
|
24086
86dfb96a1831
Repair badly formatted code.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
23832
diff
changeset
|
208 p = PY_SSL_ERROR_SYSCALL; |
|
42954
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
209 /* XXX Protected by global interpreter lock */ |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
210 errstr = ERR_error_string(e, NULL); |
|
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
|
211 } |
|
42954
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
212 break; |
|
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
|
213 } |
|
42954
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
214 case SSL_ERROR_SSL: |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
215 { |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
216 unsigned long e = ERR_get_error(); |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
217 p = PY_SSL_ERROR_SSL; |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
218 if (e != 0) |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
219 /* XXX Protected by global interpreter lock */ |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
220 errstr = ERR_error_string(e, NULL); |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
221 else { /* possible? */ |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
222 errstr = |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
223 "A failure in the SSL library occurred"; |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
224 } |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
225 break; |
|
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
|
226 } |
|
42954
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
227 default: |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
228 p = PY_SSL_ERROR_INVALID_ERROR_CODE; |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
229 errstr = "Invalid error code"; |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
230 } |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
231 } else { |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
232 errstr = ERR_error_string(ERR_peek_last_error(), NULL); |
|
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
|
233 } |
|
42954
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
234 PyOS_snprintf(buf, sizeof(buf), "_ssl.c:%d: %s", lineno, errstr); |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
235 v = Py_BuildValue("(is)", p, buf); |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
236 if (v != NULL) { |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
237 PyErr_SetObject(PySSLErrorObject, v); |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
238 Py_DECREF(v); |
|
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
|
239 } |
|
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 return NULL; |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
241 } |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
242 |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
243 static PyObject * |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
244 _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
|
245 |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
246 char buf[2048]; |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
247 PyObject *v; |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
248 |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
249 if (errstr == NULL) { |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
250 errcode = ERR_peek_last_error(); |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
251 errstr = ERR_error_string(errcode, NULL); |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
252 } |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
253 PyOS_snprintf(buf, sizeof(buf), "_ssl.c:%d: %s", lineno, errstr); |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
254 v = Py_BuildValue("(is)", errcode, buf); |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
255 if (v != NULL) { |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
256 PyErr_SetObject(PySSLErrorObject, v); |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
257 Py_DECREF(v); |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
258 } |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
259 return NULL; |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
260 } |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
261 |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
262 static PySSLObject * |
|
42954
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
263 newPySSLObject(PySocketSockObject *Sock, char *key_file, char *cert_file, |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
264 enum py_ssl_server_or_client socket_type, |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
265 enum py_ssl_cert_requirements certreq, |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
266 enum py_ssl_version proto_version, |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
267 char *cacerts_file) |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
268 { |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
269 PySSLObject *self; |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
270 char *errstr = NULL; |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
271 int ret; |
|
42954
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
272 int verification_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
|
273 |
|
44206
ce280a04f55e
Reverting revision 59394. We'll sort this out later.
Guido van Rossum <guido@python.org>
parents:
44205
diff
changeset
|
274 self = PyObject_New(PySSLObject, &PySSL_Type); /* Create new object */ |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
275 if (self == NULL) |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
276 return NULL; |
|
42954
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
277 self->peer_cert = 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
|
278 self->ssl = NULL; |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
279 self->ctx = NULL; |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
280 self->Socket = NULL; |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
281 |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
282 /* Make sure the SSL error state is initialized */ |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
283 (void) ERR_get_state(); |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
284 ERR_clear_error(); |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
285 |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
286 if ((key_file && !cert_file) || (!key_file && cert_file)) { |
|
42954
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
287 errstr = ERRSTR("Both the key & certificate files " |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
288 "must be specified"); |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
289 goto fail; |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
290 } |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
291 |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
292 if ((socket_type == PY_SSL_SERVER) && |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
293 ((key_file == NULL) || (cert_file == NULL))) { |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
294 errstr = ERRSTR("Both the key & certificate files " |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
295 "must be specified for server-side operation"); |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
296 goto fail; |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
297 } |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
298 |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
299 PySSL_BEGIN_ALLOW_THREADS |
|
42954
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
300 if (proto_version == PY_SSL_VERSION_TLS1) |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
301 self->ctx = SSL_CTX_new(TLSv1_method()); /* Set up context */ |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
302 else if (proto_version == PY_SSL_VERSION_SSL3) |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
303 self->ctx = SSL_CTX_new(SSLv3_method()); /* Set up context */ |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
304 else if (proto_version == PY_SSL_VERSION_SSL2) |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
305 self->ctx = SSL_CTX_new(SSLv2_method()); /* Set up context */ |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
306 else if (proto_version == PY_SSL_VERSION_SSL23) |
|
42954
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
307 self->ctx = SSL_CTX_new(SSLv23_method()); /* Set up context */ |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
308 PySSL_END_ALLOW_THREADS |
|
42954
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
309 |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
310 if (self->ctx == NULL) { |
|
42954
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
311 errstr = ERRSTR("Invalid SSL protocol variant specified."); |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
312 goto fail; |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
313 } |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
314 |
|
42954
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
315 if (certreq != PY_SSL_CERT_NONE) { |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
316 if (cacerts_file == NULL) { |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
317 errstr = ERRSTR("No root certificates specified for " |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
318 "verification of other-side certificates."); |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
319 goto fail; |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
320 } else { |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
321 PySSL_BEGIN_ALLOW_THREADS |
|
42954
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
322 ret = SSL_CTX_load_verify_locations(self->ctx, |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
323 cacerts_file, |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
324 NULL); |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
325 PySSL_END_ALLOW_THREADS |
|
42954
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
326 if (ret != 1) { |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
327 _setSSLError(NULL, 0, __FILE__, __LINE__); |
|
42954
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
328 goto fail; |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
329 } |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
330 } |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
331 } |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
332 if (key_file) { |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
333 PySSL_BEGIN_ALLOW_THREADS |
|
24398
c7ed925c75b3
Patch #575827: allow threads inside SSL creation.
Martin v. Löwis <martin@v.loewis.de>
parents:
24280
diff
changeset
|
334 ret = SSL_CTX_use_PrivateKey_file(self->ctx, key_file, |
|
42954
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
335 SSL_FILETYPE_PEM); |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
336 PySSL_END_ALLOW_THREADS |
|
42954
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
337 if (ret != 1) { |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
338 _setSSLError(NULL, ret, __FILE__, __LINE__); |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
339 goto fail; |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
340 } |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
341 |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
342 PySSL_BEGIN_ALLOW_THREADS |
|
24398
c7ed925c75b3
Patch #575827: allow threads inside SSL creation.
Martin v. Löwis <martin@v.loewis.de>
parents:
24280
diff
changeset
|
343 ret = SSL_CTX_use_certificate_chain_file(self->ctx, |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
344 cert_file); |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
345 PySSL_END_ALLOW_THREADS |
|
42954
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
346 if (ret != 1) { |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
347 /* |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
348 fprintf(stderr, "ret is %d, errcode is %lu, %lu, with file \"%s\"\n", |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
349 ret, ERR_peek_error(), ERR_peek_last_error(), cert_file); |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
350 */ |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
351 if (ERR_peek_last_error() != 0) { |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
352 _setSSLError(NULL, ret, __FILE__, __LINE__); |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
353 goto fail; |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
354 } |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
355 } |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
356 } |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
357 |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
358 /* ssl compatibility */ |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
359 SSL_CTX_set_options(self->ctx, SSL_OP_ALL); |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
360 |
|
42954
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
361 verification_mode = SSL_VERIFY_NONE; |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
362 if (certreq == PY_SSL_CERT_OPTIONAL) |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
363 verification_mode = SSL_VERIFY_PEER; |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
364 else if (certreq == PY_SSL_CERT_REQUIRED) |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
365 verification_mode = (SSL_VERIFY_PEER | |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
366 SSL_VERIFY_FAIL_IF_NO_PEER_CERT); |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
367 SSL_CTX_set_verify(self->ctx, verification_mode, |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
368 NULL); /* set verify lvl */ |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
369 |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
370 PySSL_BEGIN_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
|
371 self->ssl = SSL_new(self->ctx); /* New ssl struct */ |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
372 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
|
373 SSL_set_fd(self->ssl, Sock->sock_fd); /* Set the socket for SSL */ |
|
27557
5eefec94a784
SF patch 676472 by Geoff Talvola, reviewed by Ben Laurie.
Guido van Rossum <guido@python.org>
parents:
27430
diff
changeset
|
374 |
| 30723 | 375 /* If the socket is in non-blocking mode or timeout mode, set the BIO |
|
27557
5eefec94a784
SF patch 676472 by Geoff Talvola, reviewed by Ben Laurie.
Guido van Rossum <guido@python.org>
parents:
27430
diff
changeset
|
376 * to non-blocking mode (blocking is the default) |
|
5eefec94a784
SF patch 676472 by Geoff Talvola, reviewed by Ben Laurie.
Guido van Rossum <guido@python.org>
parents:
27430
diff
changeset
|
377 */ |
|
5eefec94a784
SF patch 676472 by Geoff Talvola, reviewed by Ben Laurie.
Guido van Rossum <guido@python.org>
parents:
27430
diff
changeset
|
378 if (Sock->sock_timeout >= 0.0) { |
|
5eefec94a784
SF patch 676472 by Geoff Talvola, reviewed by Ben Laurie.
Guido van Rossum <guido@python.org>
parents:
27430
diff
changeset
|
379 /* Set both the read and write BIO's to non-blocking mode */ |
|
5eefec94a784
SF patch 676472 by Geoff Talvola, reviewed by Ben Laurie.
Guido van Rossum <guido@python.org>
parents:
27430
diff
changeset
|
380 BIO_set_nbio(SSL_get_rbio(self->ssl), 1); |
|
5eefec94a784
SF patch 676472 by Geoff Talvola, reviewed by Ben Laurie.
Guido van Rossum <guido@python.org>
parents:
27430
diff
changeset
|
381 BIO_set_nbio(SSL_get_wbio(self->ssl), 1); |
|
5eefec94a784
SF patch 676472 by Geoff Talvola, reviewed by Ben Laurie.
Guido van Rossum <guido@python.org>
parents:
27430
diff
changeset
|
382 } |
|
5eefec94a784
SF patch 676472 by Geoff Talvola, reviewed by Ben Laurie.
Guido van Rossum <guido@python.org>
parents:
27430
diff
changeset
|
383 |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
384 PySSL_BEGIN_ALLOW_THREADS |
|
42954
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
385 if (socket_type == PY_SSL_CLIENT) |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
386 SSL_set_connect_state(self->ssl); |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
387 else |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
388 SSL_set_accept_state(self->ssl); |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
389 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
|
390 |
|
44305
19f894ae864a
update to fix leak in SSL code
Bill Janssen <janssen@parc.com>
parents:
44206
diff
changeset
|
391 self->Socket = PyWeakref_NewRef((PyObject *) Sock, Py_None); |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
392 return self; |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
393 fail: |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
394 if (errstr) |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
395 PyErr_SetString(PySSLErrorObject, errstr); |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
396 Py_DECREF(self); |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
397 return NULL; |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
398 } |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
399 |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
400 static PyObject * |
|
42954
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
401 PySSL_sslwrap(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
|
402 { |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
403 PySocketSockObject *Sock; |
|
42954
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
404 int server_side = 0; |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
405 int verification_mode = PY_SSL_CERT_NONE; |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
406 int protocol = PY_SSL_VERSION_SSL23; |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
407 char *key_file = NULL; |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
408 char *cert_file = NULL; |
|
42954
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
409 char *cacerts_file = 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
|
410 |
|
42954
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
411 if (!PyArg_ParseTuple(args, "O!i|zziiz:sslwrap", |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
412 PySocketModule.Sock_Type, |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39442
diff
changeset
|
413 &Sock, |
|
42954
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
414 &server_side, |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
415 &key_file, &cert_file, |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
416 &verification_mode, &protocol, |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
417 &cacerts_file)) |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
418 return NULL; |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
419 |
|
42954
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
420 /* |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
421 fprintf(stderr, |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
422 "server_side is %d, keyfile %p, certfile %p, verify_mode %d, " |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
423 "protocol %d, certs %p\n", |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
424 server_side, key_file, cert_file, verification_mode, |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
425 protocol, cacerts_file); |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
426 */ |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
427 |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
428 return (PyObject *) newPySSLObject(Sock, key_file, cert_file, |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
429 server_side, verification_mode, |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
430 protocol, cacerts_file); |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
431 } |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
432 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23295
diff
changeset
|
433 PyDoc_STRVAR(ssl_doc, |
|
42954
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
434 "sslwrap(socket, server_side, [keyfile, certfile, certs_mode, protocol,\n" |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
435 " cacertsfile]) -> sslobject"); |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
436 |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
437 /* 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
|
438 |
|
43869
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
439 static PyObject *PySSL_SSLdo_handshake(PySSLObject *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
|
440 { |
|
43869
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
441 int ret; |
|
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
442 int err; |
|
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
443 int sockstate; |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
444 |
|
43869
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
445 /* Actually negotiate SSL connection */ |
|
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
446 /* XXX If SSL_do_handshake() returns 0, it's also a failure. */ |
|
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
447 sockstate = 0; |
|
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
448 do { |
|
44305
19f894ae864a
update to fix leak in SSL code
Bill Janssen <janssen@parc.com>
parents:
44206
diff
changeset
|
449 PySocketSockObject *sock |
|
19f894ae864a
update to fix leak in SSL code
Bill Janssen <janssen@parc.com>
parents:
44206
diff
changeset
|
450 = (PySocketSockObject *) PyWeakref_GetObject(self->Socket); |
|
19f894ae864a
update to fix leak in SSL code
Bill Janssen <janssen@parc.com>
parents:
44206
diff
changeset
|
451 if (((PyObject*)sock) == Py_None) { |
|
19f894ae864a
update to fix leak in SSL code
Bill Janssen <janssen@parc.com>
parents:
44206
diff
changeset
|
452 _setSSLError("Underlying socket connection gone", |
|
19f894ae864a
update to fix leak in SSL code
Bill Janssen <janssen@parc.com>
parents:
44206
diff
changeset
|
453 PY_SSL_ERROR_NO_SOCKET, __FILE__, __LINE__); |
|
19f894ae864a
update to fix leak in SSL code
Bill Janssen <janssen@parc.com>
parents:
44206
diff
changeset
|
454 return NULL; |
|
19f894ae864a
update to fix leak in SSL code
Bill Janssen <janssen@parc.com>
parents:
44206
diff
changeset
|
455 } |
|
19f894ae864a
update to fix leak in SSL code
Bill Janssen <janssen@parc.com>
parents:
44206
diff
changeset
|
456 |
|
43869
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
457 PySSL_BEGIN_ALLOW_THREADS |
|
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
458 ret = SSL_do_handshake(self->ssl); |
|
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
459 err = SSL_get_error(self->ssl, ret); |
|
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
460 PySSL_END_ALLOW_THREADS |
|
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
461 if(PyErr_CheckSignals()) { |
|
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
462 return NULL; |
|
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
463 } |
|
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
464 if (err == SSL_ERROR_WANT_READ) { |
|
44305
19f894ae864a
update to fix leak in SSL code
Bill Janssen <janssen@parc.com>
parents:
44206
diff
changeset
|
465 sockstate = check_socket_and_wait_for_timeout(sock, 0); |
|
43869
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
466 } else if (err == SSL_ERROR_WANT_WRITE) { |
|
44305
19f894ae864a
update to fix leak in SSL code
Bill Janssen <janssen@parc.com>
parents:
44206
diff
changeset
|
467 sockstate = check_socket_and_wait_for_timeout(sock, 1); |
|
43869
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
468 } else { |
|
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
469 sockstate = SOCKET_OPERATION_OK; |
|
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
470 } |
|
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
471 if (sockstate == SOCKET_HAS_TIMED_OUT) { |
|
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
472 PyErr_SetString(PySSLErrorObject, |
|
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
473 ERRSTR("The handshake operation timed out")); |
|
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
474 return NULL; |
|
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
475 } else if (sockstate == SOCKET_HAS_BEEN_CLOSED) { |
|
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
476 PyErr_SetString(PySSLErrorObject, |
|
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
477 ERRSTR("Underlying socket has been closed.")); |
|
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
478 return NULL; |
|
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
479 } else if (sockstate == SOCKET_TOO_LARGE_FOR_SELECT) { |
|
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
480 PyErr_SetString(PySSLErrorObject, |
|
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
481 ERRSTR("Underlying socket too large for select().")); |
|
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
482 return NULL; |
|
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
483 } else if (sockstate == SOCKET_IS_NONBLOCKING) { |
|
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
484 break; |
|
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
485 } |
|
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
486 } while (err == SSL_ERROR_WANT_READ || err == SSL_ERROR_WANT_WRITE); |
|
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
487 if (ret < 1) |
|
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
488 return PySSL_SetError(self, ret, __FILE__, __LINE__); |
|
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
489 self->ssl->debug = 1; |
|
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
490 |
|
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
491 if (self->peer_cert) |
|
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
492 X509_free (self->peer_cert); |
|
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
493 PySSL_BEGIN_ALLOW_THREADS |
|
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
494 self->peer_cert = SSL_get_peer_certificate(self->ssl); |
|
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
495 PySSL_END_ALLOW_THREADS |
|
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
496 |
|
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
497 Py_INCREF(Py_None); |
|
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
498 return Py_None; |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
499 } |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
500 |
|
42954
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
501 static PyObject * |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
502 _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
|
503 |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
504 char namebuf[X509_NAME_MAXLEN]; |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
505 int buflen; |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
506 PyObject *name_obj; |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
507 PyObject *value_obj; |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
508 PyObject *attr; |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
509 unsigned char *valuebuf = NULL; |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
510 |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
511 buflen = OBJ_obj2txt(namebuf, sizeof(namebuf), name, 0); |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
512 if (buflen < 0) { |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
513 _setSSLError(NULL, 0, __FILE__, __LINE__); |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
514 goto fail; |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
515 } |
|
43869
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
516 name_obj = PyUnicode_FromStringAndSize(namebuf, buflen); |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
517 if (name_obj == NULL) |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
518 goto fail; |
|
43948
8e0c4c710375
Make read() and certificate() return bytes instead of bytearray instances.
Guido van Rossum <guido@python.org>
parents:
43869
diff
changeset
|
519 |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
520 buflen = ASN1_STRING_to_UTF8(&valuebuf, value); |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
521 if (buflen < 0) { |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
522 _setSSLError(NULL, 0, __FILE__, __LINE__); |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
523 Py_DECREF(name_obj); |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
524 goto fail; |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
525 } |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
526 value_obj = PyUnicode_DecodeUTF8((char *) valuebuf, |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
527 buflen, "strict"); |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
528 OPENSSL_free(valuebuf); |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
529 if (value_obj == NULL) { |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
530 Py_DECREF(name_obj); |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
531 goto fail; |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
532 } |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
533 attr = PyTuple_New(2); |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
534 if (attr == NULL) { |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
535 Py_DECREF(name_obj); |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
536 Py_DECREF(value_obj); |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
537 goto fail; |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
538 } |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
539 PyTuple_SET_ITEM(attr, 0, name_obj); |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
540 PyTuple_SET_ITEM(attr, 1, value_obj); |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
541 return attr; |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
542 |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
543 fail: |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
544 return NULL; |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
545 } |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
546 |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
547 static PyObject * |
|
43292
876b7ef4775d
Merged revisions 57778-58052 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
42954
diff
changeset
|
548 _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
|
549 { |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
550 PyObject *dn = NULL; /* tuple which represents the "distinguished name" */ |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
551 PyObject *rdn = NULL; /* tuple to hold a "relative distinguished name" */ |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
552 PyObject *rdnt; |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
553 PyObject *attr = NULL; /* tuple to hold an attribute */ |
|
43292
876b7ef4775d
Merged revisions 57778-58052 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
42954
diff
changeset
|
554 int entry_count = X509_NAME_entry_count(xname); |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
555 X509_NAME_ENTRY *entry; |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
556 ASN1_OBJECT *name; |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
557 ASN1_STRING *value; |
|
42954
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
558 int index_counter; |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
559 int rdn_level = -1; |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
560 int retcode; |
|
42954
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
561 |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
562 dn = PyList_New(0); |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
563 if (dn == NULL) |
|
42954
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
564 return NULL; |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
565 /* now create another tuple to hold the top-level RDN */ |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
566 rdn = PyList_New(0); |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
567 if (rdn == NULL) |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
568 goto fail0; |
|
42954
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
569 |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
570 for (index_counter = 0; |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
571 index_counter < entry_count; |
|
42954
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
572 index_counter++) |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
573 { |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
574 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
|
575 |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
576 /* check to see if we've gotten to a new RDN */ |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
577 if (rdn_level >= 0) { |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
578 if (rdn_level != entry->set) { |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
579 /* yes, new RDN */ |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
580 /* add old RDN to DN */ |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
581 rdnt = PyList_AsTuple(rdn); |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
582 Py_DECREF(rdn); |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
583 if (rdnt == NULL) |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
584 goto fail0; |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
585 retcode = PyList_Append(dn, rdnt); |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
586 Py_DECREF(rdnt); |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
587 if (retcode < 0) |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
588 goto fail0; |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
589 /* create new RDN */ |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
590 rdn = PyList_New(0); |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
591 if (rdn == NULL) |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
592 goto fail0; |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
593 } |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
594 } |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
595 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
|
596 |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
597 /* now add this attribute to the current RDN */ |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
598 name = X509_NAME_ENTRY_get_object(entry); |
|
42954
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
599 value = X509_NAME_ENTRY_get_data(entry); |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
600 attr = _create_tuple_for_attribute(name, value); |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
601 /* |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
602 fprintf(stderr, "RDN level %d, attribute %s: %s\n", |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
603 entry->set, |
|
47301
23ab586c427a
Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents:
47300
diff
changeset
|
604 PyBytes_AS_STRING(PyTuple_GET_ITEM(attr, 0)), |
|
23ab586c427a
Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents:
47300
diff
changeset
|
605 PyBytes_AS_STRING(PyTuple_GET_ITEM(attr, 1))); |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
606 */ |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
607 if (attr == NULL) |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
608 goto fail1; |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
609 retcode = PyList_Append(rdn, attr); |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
610 Py_DECREF(attr); |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
611 if (retcode < 0) |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
612 goto fail1; |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
613 } |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
614 /* now, there's typically a dangling RDN */ |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
615 if ((rdn != NULL) && (PyList_Size(rdn) > 0)) { |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
616 rdnt = PyList_AsTuple(rdn); |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
617 Py_DECREF(rdn); |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
618 if (rdnt == NULL) |
|
42954
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
619 goto fail0; |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
620 retcode = PyList_Append(dn, rdnt); |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
621 Py_DECREF(rdnt); |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
622 if (retcode < 0) |
|
42954
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
623 goto fail0; |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
624 } |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
625 |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
626 /* convert list to tuple */ |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
627 rdnt = PyList_AsTuple(dn); |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
628 Py_DECREF(dn); |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
629 if (rdnt == NULL) |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
630 return NULL; |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
631 return rdnt; |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
632 |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
633 fail1: |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
634 Py_XDECREF(rdn); |
|
42954
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
635 |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
636 fail0: |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
637 Py_XDECREF(dn); |
|
42954
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
638 return NULL; |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
639 } |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
640 |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
641 static PyObject * |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
642 _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
|
643 |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
644 /* this code follows the procedure outlined in |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
645 OpenSSL's crypto/x509v3/v3_prn.c:X509v3_EXT_print() |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
646 function to extract the STACK_OF(GENERAL_NAME), |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
647 then iterates through the stack to add the |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
648 names. */ |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
649 |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
650 int i, j; |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
651 PyObject *peer_alt_names = Py_None; |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
652 PyObject *v, *t; |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
653 X509_EXTENSION *ext = NULL; |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
654 GENERAL_NAMES *names = NULL; |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
655 GENERAL_NAME *name; |
|
43948
8e0c4c710375
Make read() and certificate() return bytes instead of bytearray instances.
Guido van Rossum <guido@python.org>
parents:
43869
diff
changeset
|
656 X509V3_EXT_METHOD *method; |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
657 BIO *biobuf = NULL; |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
658 char buf[2048]; |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
659 char *vptr; |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
660 int len; |
|
54917
f94c09aa4444
Merged revisions 73623-73624 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
53816
diff
changeset
|
661 unsigned char *p; |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
662 |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
663 if (certificate == NULL) |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
664 return peer_alt_names; |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
665 |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
666 /* get a memory buffer */ |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
667 biobuf = BIO_new(BIO_s_mem()); |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
668 |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
669 i = 0; |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
670 while ((i = X509_get_ext_by_NID( |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
671 certificate, NID_subject_alt_name, i)) >= 0) { |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
672 |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
673 if (peer_alt_names == Py_None) { |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
674 peer_alt_names = PyList_New(0); |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
675 if (peer_alt_names == NULL) |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
676 goto fail; |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
677 } |
|
43948
8e0c4c710375
Make read() and certificate() return bytes instead of bytearray instances.
Guido van Rossum <guido@python.org>
parents:
43869
diff
changeset
|
678 |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
679 /* now decode the altName */ |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
680 ext = X509_get_ext(certificate, i); |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
681 if(!(method = X509V3_EXT_get(ext))) { |
|
43869
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
682 PyErr_SetString |
|
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
683 (PySSLErrorObject, |
|
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
684 ERRSTR("No method for internalizing subjectAltName!")); |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
685 goto fail; |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
686 } |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
687 |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
688 p = ext->value->data; |
|
45017
4725c84b0422
Merged revisions 60350-60363 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
689 if (method->it) |
|
43869
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
690 names = (GENERAL_NAMES*) |
|
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
691 (ASN1_item_d2i(NULL, |
|
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
692 &p, |
|
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
693 ext->value->length, |
|
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
694 ASN1_ITEM_ptr(method->it))); |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
695 else |
|
43869
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
696 names = (GENERAL_NAMES*) |
|
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
697 (method->d2i(NULL, |
|
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
698 &p, |
|
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
699 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
|
700 |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
701 for(j = 0; j < sk_GENERAL_NAME_num(names); j++) { |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
702 |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
703 /* get a rendering of each name in the set of names */ |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
704 |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
705 name = sk_GENERAL_NAME_value(names, j); |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
706 if (name->type == GEN_DIRNAME) { |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
707 |
|
43869
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
708 /* we special-case DirName as a tuple of |
|
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
709 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
|
710 |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
711 t = PyTuple_New(2); |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
712 if (t == NULL) { |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
713 goto fail; |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
714 } |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
715 |
|
43869
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
716 v = PyUnicode_FromString("DirName"); |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
717 if (v == NULL) { |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
718 Py_DECREF(t); |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
719 goto fail; |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
720 } |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
721 PyTuple_SET_ITEM(t, 0, v); |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
722 |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
723 v = _create_tuple_for_X509_NAME (name->d.dirn); |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
724 if (v == NULL) { |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
725 Py_DECREF(t); |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
726 goto fail; |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
727 } |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
728 PyTuple_SET_ITEM(t, 1, v); |
|
43948
8e0c4c710375
Make read() and certificate() return bytes instead of bytearray instances.
Guido van Rossum <guido@python.org>
parents:
43869
diff
changeset
|
729 |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
730 } else { |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
731 |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
732 /* for everything else, we use the OpenSSL print form */ |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
733 |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
734 (void) BIO_reset(biobuf); |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
735 GENERAL_NAME_print(biobuf, name); |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
736 len = BIO_gets(biobuf, buf, sizeof(buf)-1); |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
737 if (len < 0) { |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
738 _setSSLError(NULL, 0, __FILE__, __LINE__); |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
739 goto fail; |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
740 } |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
741 vptr = strchr(buf, ':'); |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
742 if (vptr == NULL) |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
743 goto fail; |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
744 t = PyTuple_New(2); |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
745 if (t == NULL) |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
746 goto fail; |
|
43869
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
747 v = PyUnicode_FromStringAndSize(buf, (vptr - buf)); |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
748 if (v == NULL) { |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
749 Py_DECREF(t); |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
750 goto fail; |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
751 } |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
752 PyTuple_SET_ITEM(t, 0, v); |
|
43869
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
753 v = PyUnicode_FromStringAndSize((vptr + 1), |
|
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
754 (len - (vptr - buf + 1))); |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
755 if (v == NULL) { |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
756 Py_DECREF(t); |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
757 goto fail; |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
758 } |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
759 PyTuple_SET_ITEM(t, 1, v); |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
760 } |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
761 |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
762 /* and add that rendering to the list */ |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
763 |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
764 if (PyList_Append(peer_alt_names, t) < 0) { |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
765 Py_DECREF(t); |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
766 goto fail; |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
767 } |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
768 Py_DECREF(t); |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
769 } |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
770 } |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
771 BIO_free(biobuf); |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
772 if (peer_alt_names != Py_None) { |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
773 v = PyList_AsTuple(peer_alt_names); |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
774 Py_DECREF(peer_alt_names); |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
775 return v; |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
776 } else { |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
777 return peer_alt_names; |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
778 } |
|
43948
8e0c4c710375
Make read() and certificate() return bytes instead of bytearray instances.
Guido van Rossum <guido@python.org>
parents:
43869
diff
changeset
|
779 |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
780 |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
781 fail: |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
782 if (biobuf != NULL) |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
783 BIO_free(biobuf); |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
784 |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
785 if (peer_alt_names != Py_None) { |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
786 Py_XDECREF(peer_alt_names); |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
787 } |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
788 |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
789 return NULL; |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
790 } |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
791 |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
792 static PyObject * |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
793 _decode_certificate (X509 *certificate, int verbose) { |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
794 |
|
42954
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
795 PyObject *retval = NULL; |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
796 BIO *biobuf = NULL; |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
797 PyObject *peer; |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
798 PyObject *peer_alt_names = NULL; |
|
42954
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
799 PyObject *issuer; |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
800 PyObject *version; |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
801 PyObject *sn_obj; |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
802 ASN1_INTEGER *serialNumber; |
|
42954
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
803 char buf[2048]; |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
804 int len; |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
805 ASN1_TIME *notBefore, *notAfter; |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
806 PyObject *pnotBefore, *pnotAfter; |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
807 |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
808 retval = PyDict_New(); |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
809 if (retval == NULL) |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
810 return NULL; |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
811 |
|
43292
876b7ef4775d
Merged revisions 57778-58052 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
42954
diff
changeset
|
812 peer = _create_tuple_for_X509_NAME( |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
813 X509_get_subject_name(certificate)); |
|
42954
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
814 if (peer == NULL) |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
815 goto fail0; |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
816 if (PyDict_SetItemString(retval, (const char *) "subject", peer) < 0) { |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
817 Py_DECREF(peer); |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
818 goto fail0; |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
819 } |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
820 Py_DECREF(peer); |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
821 |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
822 if (verbose) { |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
823 issuer = _create_tuple_for_X509_NAME( |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
824 X509_get_issuer_name(certificate)); |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
825 if (issuer == NULL) |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
826 goto fail0; |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
827 if (PyDict_SetItemString(retval, (const char *)"issuer", issuer) < 0) { |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
828 Py_DECREF(issuer); |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
829 goto fail0; |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
830 } |
|
42954
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
831 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
|
832 |
|
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
|
833 version = PyLong_FromLong(X509_get_version(certificate) + 1); |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
834 if (PyDict_SetItemString(retval, "version", version) < 0) { |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
835 Py_DECREF(version); |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
836 goto fail0; |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
837 } |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
838 Py_DECREF(version); |
|
42954
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
839 } |
|
43948
8e0c4c710375
Make read() and certificate() return bytes instead of bytearray instances.
Guido van Rossum <guido@python.org>
parents:
43869
diff
changeset
|
840 |
|
42954
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
841 /* get a memory buffer */ |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
842 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
|
843 |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
844 if (verbose) { |
|
42954
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
845 |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
846 (void) BIO_reset(biobuf); |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
847 serialNumber = X509_get_serialNumber(certificate); |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
848 /* should not exceed 20 octets, 160 bits, so buf is big enough */ |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
849 i2a_ASN1_INTEGER(biobuf, serialNumber); |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
850 len = BIO_gets(biobuf, buf, sizeof(buf)-1); |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
851 if (len < 0) { |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
852 _setSSLError(NULL, 0, __FILE__, __LINE__); |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
853 goto fail1; |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
854 } |
|
43869
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
855 sn_obj = PyUnicode_FromStringAndSize(buf, len); |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
856 if (sn_obj == NULL) |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
857 goto fail1; |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
858 if (PyDict_SetItemString(retval, "serialNumber", sn_obj) < 0) { |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
859 Py_DECREF(sn_obj); |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
860 goto fail1; |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
861 } |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
862 Py_DECREF(sn_obj); |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
863 |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
864 (void) BIO_reset(biobuf); |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
865 notBefore = X509_get_notBefore(certificate); |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
866 ASN1_TIME_print(biobuf, notBefore); |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
867 len = BIO_gets(biobuf, buf, sizeof(buf)-1); |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
868 if (len < 0) { |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
869 _setSSLError(NULL, 0, __FILE__, __LINE__); |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
870 goto fail1; |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
871 } |
|
43869
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
872 pnotBefore = PyUnicode_FromStringAndSize(buf, len); |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
873 if (pnotBefore == NULL) |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
874 goto fail1; |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
875 if (PyDict_SetItemString(retval, "notBefore", pnotBefore) < 0) { |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
876 Py_DECREF(pnotBefore); |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
877 goto fail1; |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
878 } |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
879 Py_DECREF(pnotBefore); |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
880 } |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
881 |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
882 (void) BIO_reset(biobuf); |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
883 notAfter = X509_get_notAfter(certificate); |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
884 ASN1_TIME_print(biobuf, notAfter); |
|
42954
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
885 len = BIO_gets(biobuf, buf, sizeof(buf)-1); |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
886 if (len < 0) { |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
887 _setSSLError(NULL, 0, __FILE__, __LINE__); |
|
42954
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
888 goto fail1; |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
889 } |
|
43869
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
890 pnotAfter = PyUnicode_FromStringAndSize(buf, len); |
|
42954
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
891 if (pnotAfter == NULL) |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
892 goto fail1; |
|
42954
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
893 if (PyDict_SetItemString(retval, "notAfter", pnotAfter) < 0) { |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
894 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
|
895 goto fail1; |
|
42954
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
896 } |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
897 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
|
898 |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
899 /* Now look for subjectAltName */ |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
900 |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
901 peer_alt_names = _get_peer_alt_names(certificate); |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
902 if (peer_alt_names == NULL) |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
903 goto fail1; |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
904 else if (peer_alt_names != Py_None) { |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
905 if (PyDict_SetItemString(retval, "subjectAltName", |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
906 peer_alt_names) < 0) { |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
907 Py_DECREF(peer_alt_names); |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
908 goto fail1; |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
909 } |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
910 Py_DECREF(peer_alt_names); |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
911 } |
|
43948
8e0c4c710375
Make read() and certificate() return bytes instead of bytearray instances.
Guido van Rossum <guido@python.org>
parents:
43869
diff
changeset
|
912 |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
913 BIO_free(biobuf); |
|
42954
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
914 return retval; |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
915 |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
916 fail1: |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
917 if (biobuf != NULL) |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
918 BIO_free(biobuf); |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
919 fail0: |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
920 Py_XDECREF(retval); |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
921 return NULL; |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
922 } |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
923 |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
924 |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
925 static PyObject * |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
926 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
|
927 |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
928 PyObject *retval = NULL; |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
929 char *filename = NULL; |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
930 X509 *x=NULL; |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
931 BIO *cert; |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
932 int verbose = 1; |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
933 |
|
43869
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
934 if (!PyArg_ParseTuple(args, "s|i:test_decode_certificate", |
|
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
935 &filename, &verbose)) |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
936 return NULL; |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
937 |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
938 if ((cert=BIO_new(BIO_s_file())) == NULL) { |
|
43869
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
939 PyErr_SetString(PySSLErrorObject, |
|
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
940 "Can't malloc memory to read file"); |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
941 goto fail0; |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
942 } |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
943 |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
944 if (BIO_read_filename(cert,filename) <= 0) { |
|
43869
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
945 PyErr_SetString(PySSLErrorObject, |
|
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
946 "Can't open file"); |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
947 goto fail0; |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
948 } |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
949 |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
950 x = PEM_read_bio_X509_AUX(cert,NULL, NULL, NULL); |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
951 if (x == NULL) { |
|
43869
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
952 PyErr_SetString(PySSLErrorObject, |
|
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
953 "Error decoding PEM-encoded file"); |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
954 goto fail0; |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
955 } |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
956 |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
957 retval = _decode_certificate(x, verbose); |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
958 |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
959 fail0: |
|
43948
8e0c4c710375
Make read() and certificate() return bytes instead of bytearray instances.
Guido van Rossum <guido@python.org>
parents:
43869
diff
changeset
|
960 |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
961 if (cert != NULL) BIO_free(cert); |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
962 return retval; |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
963 } |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
964 |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
965 |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
966 static PyObject * |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
967 PySSL_peercert(PySSLObject *self, PyObject *args) |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
968 { |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
969 PyObject *retval = NULL; |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
970 int len; |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
971 int verification; |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
972 PyObject *binary_mode = Py_None; |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
973 |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
974 if (!PyArg_ParseTuple(args, "|O:peer_certificate", &binary_mode)) |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
975 return NULL; |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
976 |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
977 if (!self->peer_cert) |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
978 Py_RETURN_NONE; |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
979 |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
980 if (PyObject_IsTrue(binary_mode)) { |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
981 /* return cert in DER-encoded format */ |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
982 |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
983 unsigned char *bytes_buf = NULL; |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
984 |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
985 bytes_buf = NULL; |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
986 len = i2d_X509(self->peer_cert, &bytes_buf); |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
987 if (len < 0) { |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
988 PySSL_SetError(self, len, __FILE__, __LINE__); |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
989 return NULL; |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
990 } |
|
43869
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
991 /* this is actually an immutable bytes sequence */ |
|
47301
23ab586c427a
Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents:
47300
diff
changeset
|
992 retval = PyBytes_FromStringAndSize |
|
43869
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
993 ((const char *) bytes_buf, len); |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
994 OPENSSL_free(bytes_buf); |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
995 return retval; |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
996 |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
997 } else { |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
998 |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
999 verification = SSL_CTX_get_verify_mode(self->ctx); |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1000 if ((verification & SSL_VERIFY_PEER) == 0) |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1001 return PyDict_New(); |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1002 else |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1003 return _decode_certificate (self->peer_cert, 0); |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1004 } |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1005 } |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1006 |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1007 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
|
1008 "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
|
1009 \n\ |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1010 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
|
1011 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
|
1012 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
|
1013 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
|
1014 \n\ |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1015 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
|
1016 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
|
1017 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
|
1018 |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1019 static PyObject *PySSL_cipher (PySSLObject *self) { |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1020 |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1021 PyObject *retval, *v; |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1022 SSL_CIPHER *current; |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1023 char *cipher_name; |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1024 char *cipher_protocol; |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1025 |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1026 if (self->ssl == NULL) |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1027 return Py_None; |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1028 current = SSL_get_current_cipher(self->ssl); |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1029 if (current == NULL) |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1030 return Py_None; |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1031 |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1032 retval = PyTuple_New(3); |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1033 if (retval == NULL) |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1034 return NULL; |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1035 |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1036 cipher_name = (char *) SSL_CIPHER_get_name(current); |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1037 if (cipher_name == NULL) { |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1038 PyTuple_SET_ITEM(retval, 0, Py_None); |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1039 } else { |
|
43869
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
1040 v = PyUnicode_FromString(cipher_name); |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1041 if (v == NULL) |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1042 goto fail0; |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1043 PyTuple_SET_ITEM(retval, 0, v); |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1044 } |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1045 cipher_protocol = SSL_CIPHER_get_version(current); |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1046 if (cipher_protocol == NULL) { |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1047 PyTuple_SET_ITEM(retval, 1, Py_None); |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1048 } else { |
|
43869
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
1049 v = PyUnicode_FromString(cipher_protocol); |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1050 if (v == NULL) |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1051 goto fail0; |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1052 PyTuple_SET_ITEM(retval, 1, v); |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1053 } |
|
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
|
1054 v = PyLong_FromLong(SSL_CIPHER_get_bits(current, NULL)); |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1055 if (v == NULL) |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1056 goto fail0; |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1057 PyTuple_SET_ITEM(retval, 2, v); |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1058 return retval; |
|
43948
8e0c4c710375
Make read() and certificate() return bytes instead of bytearray instances.
Guido van Rossum <guido@python.org>
parents:
43869
diff
changeset
|
1059 |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1060 fail0: |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1061 Py_DECREF(retval); |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1062 return NULL; |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1063 } |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1064 |
|
44206
ce280a04f55e
Reverting revision 59394. We'll sort this out later.
Guido van Rossum <guido@python.org>
parents:
44205
diff
changeset
|
1065 static void PySSL_dealloc(PySSLObject *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
|
1066 { |
|
42954
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
1067 if (self->peer_cert) /* Possible not to have one? */ |
|
44206
ce280a04f55e
Reverting revision 59394. We'll sort this out later.
Guido van Rossum <guido@python.org>
parents:
44205
diff
changeset
|
1068 X509_free (self->peer_cert); |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
1069 if (self->ssl) |
|
42954
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
1070 SSL_free(self->ssl); |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
1071 if (self->ctx) |
|
42954
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
1072 SSL_CTX_free(self->ctx); |
|
44206
ce280a04f55e
Reverting revision 59394. We'll sort this out later.
Guido van Rossum <guido@python.org>
parents:
44205
diff
changeset
|
1073 Py_XDECREF(self->Socket); |
|
ce280a04f55e
Reverting revision 59394. We'll sort this out later.
Guido van Rossum <guido@python.org>
parents:
44205
diff
changeset
|
1074 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
|
1075 } |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
1076 |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38453
diff
changeset
|
1077 /* 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
|
1078 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
|
1079 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
|
1080 */ |
|
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
|
1081 |
|
27430
1ae0b142370e
Support socket timeout in SSL, by Geoff Talvola.
Guido van Rossum <guido@python.org>
parents:
24471
diff
changeset
|
1082 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
|
1083 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
|
1084 { |
|
1ae0b142370e
Support socket timeout in SSL, by Geoff Talvola.
Guido van Rossum <guido@python.org>
parents:
24471
diff
changeset
|
1085 fd_set fds; |
|
1ae0b142370e
Support socket timeout in SSL, by Geoff Talvola.
Guido van Rossum <guido@python.org>
parents:
24471
diff
changeset
|
1086 struct timeval tv; |
|
1ae0b142370e
Support socket timeout in SSL, by Geoff Talvola.
Guido van Rossum <guido@python.org>
parents:
24471
diff
changeset
|
1087 int rc; |
|
1ae0b142370e
Support socket timeout in SSL, by Geoff Talvola.
Guido van Rossum <guido@python.org>
parents:
24471
diff
changeset
|
1088 |
|
1ae0b142370e
Support socket timeout in SSL, by Geoff Talvola.
Guido van Rossum <guido@python.org>
parents:
24471
diff
changeset
|
1089 /* Nothing to do unless we're in timeout mode (not non-blocking) */ |
|
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
|
1090 if (s->sock_timeout < 0.0) |
|
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
|
1091 return SOCKET_IS_BLOCKING; |
|
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
|
1092 else if (s->sock_timeout == 0.0) |
|
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
|
1093 return SOCKET_IS_NONBLOCKING; |
|
27430
1ae0b142370e
Support socket timeout in SSL, by Geoff Talvola.
Guido van Rossum <guido@python.org>
parents:
24471
diff
changeset
|
1094 |
|
1ae0b142370e
Support socket timeout in SSL, by Geoff Talvola.
Guido van Rossum <guido@python.org>
parents:
24471
diff
changeset
|
1095 /* Guard against closed socket */ |
|
1ae0b142370e
Support socket timeout in SSL, by Geoff Talvola.
Guido van Rossum <guido@python.org>
parents:
24471
diff
changeset
|
1096 if (s->sock_fd < 0) |
|
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
|
1097 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
|
1098 |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38453
diff
changeset
|
1099 /* Prefer poll, if available, since you can poll() any fd |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38453
diff
changeset
|
1100 * which can't be done with select(). */ |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38453
diff
changeset
|
1101 #ifdef HAVE_POLL |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38453
diff
changeset
|
1102 { |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38453
diff
changeset
|
1103 struct pollfd pollfd; |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38453
diff
changeset
|
1104 int timeout; |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38453
diff
changeset
|
1105 |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38453
diff
changeset
|
1106 pollfd.fd = s->sock_fd; |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38453
diff
changeset
|
1107 pollfd.events = writing ? POLLOUT : POLLIN; |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38453
diff
changeset
|
1108 |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38453
diff
changeset
|
1109 /* s->sock_timeout is in seconds, timeout in ms */ |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38453
diff
changeset
|
1110 timeout = (int)(s->sock_timeout * 1000 + 0.5); |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1111 PySSL_BEGIN_ALLOW_THREADS |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38453
diff
changeset
|
1112 rc = poll(&pollfd, 1, timeout); |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1113 PySSL_END_ALLOW_THREADS |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38453
diff
changeset
|
1114 |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38453
diff
changeset
|
1115 goto normal_return; |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38453
diff
changeset
|
1116 } |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38453
diff
changeset
|
1117 #endif |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38453
diff
changeset
|
1118 |
|
36452
7789cc557e1e
Bug #876637, prevent stack corruption when socket descriptor
Neal Norwitz <nnorwitz@gmail.com>
parents:
36451
diff
changeset
|
1119 /* Guard against socket too large for select*/ |
|
36476
c073dffbe70e
Introduce Py_SOCKET_FD_CAN_BE_GE_FD_SETSIZE.
Martin v. Löwis <martin@v.loewis.de>
parents:
36452
diff
changeset
|
1120 #ifndef Py_SOCKET_FD_CAN_BE_GE_FD_SETSIZE |
|
36452
7789cc557e1e
Bug #876637, prevent stack corruption when socket descriptor
Neal Norwitz <nnorwitz@gmail.com>
parents:
36451
diff
changeset
|
1121 if (s->sock_fd >= FD_SETSIZE) |
|
36487
07ba8aae3dc6
Try to improve name based on discussion on python-checkins with Jim Jewett
Neal Norwitz <nnorwitz@gmail.com>
parents:
36476
diff
changeset
|
1122 return SOCKET_TOO_LARGE_FOR_SELECT; |
|
36476
c073dffbe70e
Introduce Py_SOCKET_FD_CAN_BE_GE_FD_SETSIZE.
Martin v. Löwis <martin@v.loewis.de>
parents:
36452
diff
changeset
|
1123 #endif |
|
36452
7789cc557e1e
Bug #876637, prevent stack corruption when socket descriptor
Neal Norwitz <nnorwitz@gmail.com>
parents:
36451
diff
changeset
|
1124 |
|
27430
1ae0b142370e
Support socket timeout in SSL, by Geoff Talvola.
Guido van Rossum <guido@python.org>
parents:
24471
diff
changeset
|
1125 /* Construct the arguments to select */ |
|
1ae0b142370e
Support socket timeout in SSL, by Geoff Talvola.
Guido van Rossum <guido@python.org>
parents:
24471
diff
changeset
|
1126 tv.tv_sec = (int)s->sock_timeout; |
|
1ae0b142370e
Support socket timeout in SSL, by Geoff Talvola.
Guido van Rossum <guido@python.org>
parents:
24471
diff
changeset
|
1127 tv.tv_usec = (int)((s->sock_timeout - tv.tv_sec) * 1e6); |
|
1ae0b142370e
Support socket timeout in SSL, by Geoff Talvola.
Guido van Rossum <guido@python.org>
parents:
24471
diff
changeset
|
1128 FD_ZERO(&fds); |
|
1ae0b142370e
Support socket timeout in SSL, by Geoff Talvola.
Guido van Rossum <guido@python.org>
parents:
24471
diff
changeset
|
1129 FD_SET(s->sock_fd, &fds); |
|
1ae0b142370e
Support socket timeout in SSL, by Geoff Talvola.
Guido van Rossum <guido@python.org>
parents:
24471
diff
changeset
|
1130 |
|
1ae0b142370e
Support socket timeout in SSL, by Geoff Talvola.
Guido van Rossum <guido@python.org>
parents:
24471
diff
changeset
|
1131 /* See if the socket is ready */ |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1132 PySSL_BEGIN_ALLOW_THREADS |
|
27430
1ae0b142370e
Support socket timeout in SSL, by Geoff Talvola.
Guido van Rossum <guido@python.org>
parents:
24471
diff
changeset
|
1133 if (writing) |
|
1ae0b142370e
Support socket timeout in SSL, by Geoff Talvola.
Guido van Rossum <guido@python.org>
parents:
24471
diff
changeset
|
1134 rc = select(s->sock_fd+1, NULL, &fds, NULL, &tv); |
|
1ae0b142370e
Support socket timeout in SSL, by Geoff Talvola.
Guido van Rossum <guido@python.org>
parents:
24471
diff
changeset
|
1135 else |
|
1ae0b142370e
Support socket timeout in SSL, by Geoff Talvola.
Guido van Rossum <guido@python.org>
parents:
24471
diff
changeset
|
1136 rc = select(s->sock_fd+1, &fds, NULL, NULL, &tv); |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1137 PySSL_END_ALLOW_THREADS |
|
27430
1ae0b142370e
Support socket timeout in SSL, by Geoff Talvola.
Guido van Rossum <guido@python.org>
parents:
24471
diff
changeset
|
1138 |
|
43869
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
1139 #ifdef HAVE_POLL |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38453
diff
changeset
|
1140 normal_return: |
|
43869
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
1141 #endif |
|
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
|
1142 /* Return SOCKET_TIMED_OUT on timeout, SOCKET_OPERATION_OK otherwise |
|
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
|
1143 (when we are able to write or when there's something to read) */ |
|
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
|
1144 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
|
1145 } |
|
1ae0b142370e
Support socket timeout in SSL, by Geoff Talvola.
Guido van Rossum <guido@python.org>
parents:
24471
diff
changeset
|
1146 |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
1147 static PyObject *PySSL_SSLwrite(PySSLObject *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
|
1148 { |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
1149 char *data; |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
1150 int len; |
|
30795
9da537167b74
Patch #803998: Correctly check for error in SSL_write.
Martin v. Löwis <martin@v.loewis.de>
parents:
30723
diff
changeset
|
1151 int count; |
|
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
|
1152 int sockstate; |
|
27557
5eefec94a784
SF patch 676472 by Geoff Talvola, reviewed by Ben Laurie.
Guido van Rossum <guido@python.org>
parents:
27430
diff
changeset
|
1153 int err; |
|
43869
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
1154 int nonblocking; |
|
44305
19f894ae864a
update to fix leak in SSL code
Bill Janssen <janssen@parc.com>
parents:
44206
diff
changeset
|
1155 PySocketSockObject *sock |
|
19f894ae864a
update to fix leak in SSL code
Bill Janssen <janssen@parc.com>
parents:
44206
diff
changeset
|
1156 = (PySocketSockObject *) PyWeakref_GetObject(self->Socket); |
|
19f894ae864a
update to fix leak in SSL code
Bill Janssen <janssen@parc.com>
parents:
44206
diff
changeset
|
1157 |
|
19f894ae864a
update to fix leak in SSL code
Bill Janssen <janssen@parc.com>
parents:
44206
diff
changeset
|
1158 if (((PyObject*)sock) == Py_None) { |
|
19f894ae864a
update to fix leak in SSL code
Bill Janssen <janssen@parc.com>
parents:
44206
diff
changeset
|
1159 _setSSLError("Underlying socket connection gone", |
|
19f894ae864a
update to fix leak in SSL code
Bill Janssen <janssen@parc.com>
parents:
44206
diff
changeset
|
1160 PY_SSL_ERROR_NO_SOCKET, __FILE__, __LINE__); |
|
19f894ae864a
update to fix leak in SSL code
Bill Janssen <janssen@parc.com>
parents:
44206
diff
changeset
|
1161 return NULL; |
|
19f894ae864a
update to fix leak in SSL code
Bill Janssen <janssen@parc.com>
parents:
44206
diff
changeset
|
1162 } |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
1163 |
|
43869
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
1164 if (!PyArg_ParseTuple(args, "y#:write", &data, &count)) |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
1165 return NULL; |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
1166 |
|
43869
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
1167 /* just in case the blocking state of the socket has been changed */ |
|
44305
19f894ae864a
update to fix leak in SSL code
Bill Janssen <janssen@parc.com>
parents:
44206
diff
changeset
|
1168 nonblocking = (sock->sock_timeout >= 0.0); |
|
43869
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
1169 BIO_set_nbio(SSL_get_rbio(self->ssl), nonblocking); |
|
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
1170 BIO_set_nbio(SSL_get_wbio(self->ssl), nonblocking); |
|
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
1171 |
|
44305
19f894ae864a
update to fix leak in SSL code
Bill Janssen <janssen@parc.com>
parents:
44206
diff
changeset
|
1172 sockstate = check_socket_and_wait_for_timeout(sock, 1); |
|
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
|
1173 if (sockstate == SOCKET_HAS_TIMED_OUT) { |
|
42954
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
1174 PyErr_SetString(PySSLErrorObject, |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
1175 "The write operation timed out"); |
|
27430
1ae0b142370e
Support socket timeout in SSL, by Geoff Talvola.
Guido van Rossum <guido@python.org>
parents:
24471
diff
changeset
|
1176 return NULL; |
|
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
|
1177 } else if (sockstate == SOCKET_HAS_BEEN_CLOSED) { |
|
42954
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
1178 PyErr_SetString(PySSLErrorObject, |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
1179 "Underlying socket has been closed."); |
|
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
|
1180 return NULL; |
|
36487
07ba8aae3dc6
Try to improve name based on discussion on python-checkins with Jim Jewett
Neal Norwitz <nnorwitz@gmail.com>
parents:
36476
diff
changeset
|
1181 } else if (sockstate == SOCKET_TOO_LARGE_FOR_SELECT) { |
|
42954
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
1182 PyErr_SetString(PySSLErrorObject, |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
1183 "Underlying socket too large for select()."); |
|
36452
7789cc557e1e
Bug #876637, prevent stack corruption when socket descriptor
Neal Norwitz <nnorwitz@gmail.com>
parents:
36451
diff
changeset
|
1184 return NULL; |
|
27430
1ae0b142370e
Support socket timeout in SSL, by Geoff Talvola.
Guido van Rossum <guido@python.org>
parents:
24471
diff
changeset
|
1185 } |
|
27557
5eefec94a784
SF patch 676472 by Geoff Talvola, reviewed by Ben Laurie.
Guido van Rossum <guido@python.org>
parents:
27430
diff
changeset
|
1186 do { |
|
5eefec94a784
SF patch 676472 by Geoff Talvola, reviewed by Ben Laurie.
Guido van Rossum <guido@python.org>
parents:
27430
diff
changeset
|
1187 err = 0; |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1188 PySSL_BEGIN_ALLOW_THREADS |
|
30795
9da537167b74
Patch #803998: Correctly check for error in SSL_write.
Martin v. Löwis <martin@v.loewis.de>
parents:
30723
diff
changeset
|
1189 len = SSL_write(self->ssl, data, count); |
|
27557
5eefec94a784
SF patch 676472 by Geoff Talvola, reviewed by Ben Laurie.
Guido van Rossum <guido@python.org>
parents:
27430
diff
changeset
|
1190 err = SSL_get_error(self->ssl, len); |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1191 PySSL_END_ALLOW_THREADS |
|
29629
a4d6bc71f091
Patch #751916: Check for signals, fix some refcounting errors.
Martin v. Löwis <martin@v.loewis.de>
parents:
27594
diff
changeset
|
1192 if(PyErr_CheckSignals()) { |
|
a4d6bc71f091
Patch #751916: Check for signals, fix some refcounting errors.
Martin v. Löwis <martin@v.loewis.de>
parents:
27594
diff
changeset
|
1193 return NULL; |
|
a4d6bc71f091
Patch #751916: Check for signals, fix some refcounting errors.
Martin v. Löwis <martin@v.loewis.de>
parents:
27594
diff
changeset
|
1194 } |
|
27557
5eefec94a784
SF patch 676472 by Geoff Talvola, reviewed by Ben Laurie.
Guido van Rossum <guido@python.org>
parents:
27430
diff
changeset
|
1195 if (err == SSL_ERROR_WANT_READ) { |
|
42954
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
1196 sockstate = |
|
44305
19f894ae864a
update to fix leak in SSL code
Bill Janssen <janssen@parc.com>
parents:
44206
diff
changeset
|
1197 check_socket_and_wait_for_timeout(sock, 0); |
|
27557
5eefec94a784
SF patch 676472 by Geoff Talvola, reviewed by Ben Laurie.
Guido van Rossum <guido@python.org>
parents:
27430
diff
changeset
|
1198 } else if (err == SSL_ERROR_WANT_WRITE) { |
|
42954
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
1199 sockstate = |
|
44305
19f894ae864a
update to fix leak in SSL code
Bill Janssen <janssen@parc.com>
parents:
44206
diff
changeset
|
1200 check_socket_and_wait_for_timeout(sock, 1); |
|
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
|
1201 } else { |
|
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
|
1202 sockstate = SOCKET_OPERATION_OK; |
|
27557
5eefec94a784
SF patch 676472 by Geoff Talvola, reviewed by Ben Laurie.
Guido van Rossum <guido@python.org>
parents:
27430
diff
changeset
|
1203 } |
|
42954
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
1204 if (sockstate == SOCKET_HAS_TIMED_OUT) { |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
1205 PyErr_SetString(PySSLErrorObject, |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
1206 "The write operation timed out"); |
|
27557
5eefec94a784
SF patch 676472 by Geoff Talvola, reviewed by Ben Laurie.
Guido van Rossum <guido@python.org>
parents:
27430
diff
changeset
|
1207 return NULL; |
|
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
|
1208 } else if (sockstate == SOCKET_HAS_BEEN_CLOSED) { |
|
42954
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
1209 PyErr_SetString(PySSLErrorObject, |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
1210 "Underlying socket has been closed."); |
|
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
|
1211 return NULL; |
|
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
|
1212 } else if (sockstate == SOCKET_IS_NONBLOCKING) { |
|
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
|
1213 break; |
|
27557
5eefec94a784
SF patch 676472 by Geoff Talvola, reviewed by Ben Laurie.
Guido van Rossum <guido@python.org>
parents:
27430
diff
changeset
|
1214 } |
|
5eefec94a784
SF patch 676472 by Geoff Talvola, reviewed by Ben Laurie.
Guido van Rossum <guido@python.org>
parents:
27430
diff
changeset
|
1215 } while (err == SSL_ERROR_WANT_READ || err == SSL_ERROR_WANT_WRITE); |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
1216 if (len > 0) |
|
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
|
1217 return PyLong_FromLong(len); |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
1218 else |
|
42954
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
1219 return PySSL_SetError(self, len, __FILE__, __LINE__); |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
1220 } |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
1221 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23295
diff
changeset
|
1222 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
|
1223 "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
|
1224 \n\ |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
1225 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
|
1226 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
|
1227 |
|
43869
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
1228 static PyObject *PySSL_SSLpending(PySSLObject *self) |
|
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
1229 { |
|
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
1230 int count = 0; |
|
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
1231 |
|
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
1232 PySSL_BEGIN_ALLOW_THREADS |
|
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
1233 count = SSL_pending(self->ssl); |
|
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
1234 PySSL_END_ALLOW_THREADS |
|
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
1235 if (count < 0) |
|
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
1236 return PySSL_SetError(self, count, __FILE__, __LINE__); |
|
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
1237 else |
|
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
|
1238 return PyLong_FromLong(count); |
|
43869
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
1239 } |
|
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
1240 |
|
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
1241 PyDoc_STRVAR(PySSL_SSLpending_doc, |
|
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
1242 "pending() -> count\n\ |
|
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
1243 \n\ |
|
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
1244 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
|
1245 pending on the connection.\n"); |
|
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
1246 |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
1247 static PyObject *PySSL_SSLread(PySSLObject *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
|
1248 { |
|
51922
b421441ee679
Merged revisions 70072 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
51271
diff
changeset
|
1249 PyObject *dest = NULL; |
|
b421441ee679
Merged revisions 70072 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
51271
diff
changeset
|
1250 Py_buffer buf; |
|
43869
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
1251 int buf_passed = 0; |
|
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
1252 int count = -1; |
|
51922
b421441ee679
Merged revisions 70072 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
51271
diff
changeset
|
1253 char *mem; |
|
b421441ee679
Merged revisions 70072 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
51271
diff
changeset
|
1254 /* XXX this should use Py_ssize_t */ |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
1255 int len = 1024; |
|
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
|
1256 int sockstate; |
|
27557
5eefec94a784
SF patch 676472 by Geoff Talvola, reviewed by Ben Laurie.
Guido van Rossum <guido@python.org>
parents:
27430
diff
changeset
|
1257 int err; |
|
43869
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
1258 int nonblocking; |
|
44305
19f894ae864a
update to fix leak in SSL code
Bill Janssen <janssen@parc.com>
parents:
44206
diff
changeset
|
1259 PySocketSockObject *sock |
|
19f894ae864a
update to fix leak in SSL code
Bill Janssen <janssen@parc.com>
parents:
44206
diff
changeset
|
1260 = (PySocketSockObject *) PyWeakref_GetObject(self->Socket); |
|
19f894ae864a
update to fix leak in SSL code
Bill Janssen <janssen@parc.com>
parents:
44206
diff
changeset
|
1261 |
|
19f894ae864a
update to fix leak in SSL code
Bill Janssen <janssen@parc.com>
parents:
44206
diff
changeset
|
1262 if (((PyObject*)sock) == Py_None) { |
|
19f894ae864a
update to fix leak in SSL code
Bill Janssen <janssen@parc.com>
parents:
44206
diff
changeset
|
1263 _setSSLError("Underlying socket connection gone", |
|
19f894ae864a
update to fix leak in SSL code
Bill Janssen <janssen@parc.com>
parents:
44206
diff
changeset
|
1264 PY_SSL_ERROR_NO_SOCKET, __FILE__, __LINE__); |
|
19f894ae864a
update to fix leak in SSL code
Bill Janssen <janssen@parc.com>
parents:
44206
diff
changeset
|
1265 return NULL; |
|
19f894ae864a
update to fix leak in SSL code
Bill Janssen <janssen@parc.com>
parents:
44206
diff
changeset
|
1266 } |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
1267 |
|
51922
b421441ee679
Merged revisions 70072 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
51271
diff
changeset
|
1268 if (!PyArg_ParseTuple(args, "|Oi:read", &dest, &count)) |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
1269 return NULL; |
|
51922
b421441ee679
Merged revisions 70072 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
51271
diff
changeset
|
1270 if ((dest == NULL) || (dest == Py_None)) { |
|
b421441ee679
Merged revisions 70072 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
51271
diff
changeset
|
1271 if (!(dest = PyByteArray_FromStringAndSize((char *) 0, len))) |
|
43869
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
1272 return NULL; |
|
51922
b421441ee679
Merged revisions 70072 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
51271
diff
changeset
|
1273 mem = PyByteArray_AS_STRING(dest); |
|
b421441ee679
Merged revisions 70072 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
51271
diff
changeset
|
1274 } else if (PyLong_Check(dest)) { |
|
b421441ee679
Merged revisions 70072 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
51271
diff
changeset
|
1275 len = PyLong_AS_LONG(dest); |
|
b421441ee679
Merged revisions 70072 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
51271
diff
changeset
|
1276 if (!(dest = PyByteArray_FromStringAndSize((char *) 0, len))) |
|
43869
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
1277 return NULL; |
|
51922
b421441ee679
Merged revisions 70072 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
51271
diff
changeset
|
1278 mem = PyByteArray_AS_STRING(dest); |
|
43869
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
1279 } else { |
|
51922
b421441ee679
Merged revisions 70072 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
51271
diff
changeset
|
1280 if (PyObject_GetBuffer(dest, &buf, PyBUF_CONTIG) < 0) |
|
43869
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
1281 return NULL; |
|
51922
b421441ee679
Merged revisions 70072 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
51271
diff
changeset
|
1282 mem = buf.buf; |
|
b421441ee679
Merged revisions 70072 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
51271
diff
changeset
|
1283 len = buf.len; |
|
43869
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
1284 if ((count > 0) && (count <= len)) |
|
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
1285 len = count; |
|
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
1286 buf_passed = 1; |
|
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
1287 } |
|
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
1288 |
|
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
1289 /* just in case the blocking state of the socket has been changed */ |
|
44305
19f894ae864a
update to fix leak in SSL code
Bill Janssen <janssen@parc.com>
parents:
44206
diff
changeset
|
1290 nonblocking = (sock->sock_timeout >= 0.0); |
|
43869
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
1291 BIO_set_nbio(SSL_get_rbio(self->ssl), nonblocking); |
|
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
1292 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
|
1293 |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36487
diff
changeset
|
1294 /* first check if there are bytes ready to be read */ |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1295 PySSL_BEGIN_ALLOW_THREADS |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36487
diff
changeset
|
1296 count = SSL_pending(self->ssl); |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1297 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
|
1298 |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36487
diff
changeset
|
1299 if (!count) { |
|
44305
19f894ae864a
update to fix leak in SSL code
Bill Janssen <janssen@parc.com>
parents:
44206
diff
changeset
|
1300 sockstate = check_socket_and_wait_for_timeout(sock, 0); |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36487
diff
changeset
|
1301 if (sockstate == SOCKET_HAS_TIMED_OUT) { |
|
42954
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
1302 PyErr_SetString(PySSLErrorObject, |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
1303 "The read operation timed out"); |
|
51922
b421441ee679
Merged revisions 70072 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
51271
diff
changeset
|
1304 goto error; |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36487
diff
changeset
|
1305 } else if (sockstate == SOCKET_TOO_LARGE_FOR_SELECT) { |
|
42954
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
1306 PyErr_SetString(PySSLErrorObject, |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
1307 "Underlying socket too large for select()."); |
|
51922
b421441ee679
Merged revisions 70072 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
51271
diff
changeset
|
1308 goto error; |
|
42954
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
1309 } else if (sockstate == SOCKET_HAS_BEEN_CLOSED) { |
|
43948
8e0c4c710375
Make read() and certificate() return bytes instead of bytearray instances.
Guido van Rossum <guido@python.org>
parents:
43869
diff
changeset
|
1310 count = 0; |
|
8e0c4c710375
Make read() and certificate() return bytes instead of bytearray instances.
Guido van Rossum <guido@python.org>
parents:
43869
diff
changeset
|
1311 goto done; |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36487
diff
changeset
|
1312 } |
|
27430
1ae0b142370e
Support socket timeout in SSL, by Geoff Talvola.
Guido van Rossum <guido@python.org>
parents:
24471
diff
changeset
|
1313 } |
|
27557
5eefec94a784
SF patch 676472 by Geoff Talvola, reviewed by Ben Laurie.
Guido van Rossum <guido@python.org>
parents:
27430
diff
changeset
|
1314 do { |
|
5eefec94a784
SF patch 676472 by Geoff Talvola, reviewed by Ben Laurie.
Guido van Rossum <guido@python.org>
parents:
27430
diff
changeset
|
1315 err = 0; |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1316 PySSL_BEGIN_ALLOW_THREADS |
|
51922
b421441ee679
Merged revisions 70072 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
51271
diff
changeset
|
1317 count = SSL_read(self->ssl, mem, len); |
|
27557
5eefec94a784
SF patch 676472 by Geoff Talvola, reviewed by Ben Laurie.
Guido van Rossum <guido@python.org>
parents:
27430
diff
changeset
|
1318 err = SSL_get_error(self->ssl, count); |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1319 PySSL_END_ALLOW_THREADS |
|
51922
b421441ee679
Merged revisions 70072 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
51271
diff
changeset
|
1320 if (PyErr_CheckSignals()) |
|
b421441ee679
Merged revisions 70072 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
51271
diff
changeset
|
1321 goto error; |
|
27557
5eefec94a784
SF patch 676472 by Geoff Talvola, reviewed by Ben Laurie.
Guido van Rossum <guido@python.org>
parents:
27430
diff
changeset
|
1322 if (err == SSL_ERROR_WANT_READ) { |
|
42954
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
1323 sockstate = |
|
44305
19f894ae864a
update to fix leak in SSL code
Bill Janssen <janssen@parc.com>
parents:
44206
diff
changeset
|
1324 check_socket_and_wait_for_timeout(sock, 0); |
|
27557
5eefec94a784
SF patch 676472 by Geoff Talvola, reviewed by Ben Laurie.
Guido van Rossum <guido@python.org>
parents:
27430
diff
changeset
|
1325 } else if (err == SSL_ERROR_WANT_WRITE) { |
|
42954
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
1326 sockstate = |
|
44305
19f894ae864a
update to fix leak in SSL code
Bill Janssen <janssen@parc.com>
parents:
44206
diff
changeset
|
1327 check_socket_and_wait_for_timeout(sock, 1); |
|
42954
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
1328 } else if ((err == SSL_ERROR_ZERO_RETURN) && |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
1329 (SSL_get_shutdown(self->ssl) == |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
1330 SSL_RECEIVED_SHUTDOWN)) |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
1331 { |
|
43948
8e0c4c710375
Make read() and certificate() return bytes instead of bytearray instances.
Guido van Rossum <guido@python.org>
parents:
43869
diff
changeset
|
1332 count = 0; |
|
8e0c4c710375
Make read() and certificate() return bytes instead of bytearray instances.
Guido van Rossum <guido@python.org>
parents:
43869
diff
changeset
|
1333 goto done; |
|
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
|
1334 } else { |
|
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
|
1335 sockstate = SOCKET_OPERATION_OK; |
|
27557
5eefec94a784
SF patch 676472 by Geoff Talvola, reviewed by Ben Laurie.
Guido van Rossum <guido@python.org>
parents:
27430
diff
changeset
|
1336 } |
|
42954
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
1337 if (sockstate == SOCKET_HAS_TIMED_OUT) { |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
1338 PyErr_SetString(PySSLErrorObject, |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
1339 "The read operation timed out"); |
|
51922
b421441ee679
Merged revisions 70072 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
51271
diff
changeset
|
1340 goto error; |
|
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
|
1341 } else if (sockstate == SOCKET_IS_NONBLOCKING) { |
|
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
|
1342 break; |
|
27557
5eefec94a784
SF patch 676472 by Geoff Talvola, reviewed by Ben Laurie.
Guido van Rossum <guido@python.org>
parents:
27430
diff
changeset
|
1343 } |
|
5eefec94a784
SF patch 676472 by Geoff Talvola, reviewed by Ben Laurie.
Guido van Rossum <guido@python.org>
parents:
27430
diff
changeset
|
1344 } while (err == SSL_ERROR_WANT_READ || err == SSL_ERROR_WANT_WRITE); |
|
42954
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
1345 if (count <= 0) { |
|
51922
b421441ee679
Merged revisions 70072 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
51271
diff
changeset
|
1346 PySSL_SetError(self, count, __FILE__, __LINE__); |
|
b421441ee679
Merged revisions 70072 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
51271
diff
changeset
|
1347 goto error; |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
1348 } |
|
43948
8e0c4c710375
Make read() and certificate() return bytes instead of bytearray instances.
Guido van Rossum <guido@python.org>
parents:
43869
diff
changeset
|
1349 done: |
|
43869
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
1350 if (!buf_passed) { |
|
51922
b421441ee679
Merged revisions 70072 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
51271
diff
changeset
|
1351 PyObject *res = PyBytes_FromStringAndSize(mem, count); |
|
b421441ee679
Merged revisions 70072 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
51271
diff
changeset
|
1352 Py_DECREF(dest); |
|
43948
8e0c4c710375
Make read() and certificate() return bytes instead of bytearray instances.
Guido van Rossum <guido@python.org>
parents:
43869
diff
changeset
|
1353 return res; |
|
43869
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
1354 } else { |
|
51922
b421441ee679
Merged revisions 70072 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
51271
diff
changeset
|
1355 PyBuffer_Release(&buf); |
|
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
|
1356 return PyLong_FromLong(count); |
|
43869
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
1357 } |
|
51922
b421441ee679
Merged revisions 70072 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
51271
diff
changeset
|
1358 error: |
|
b421441ee679
Merged revisions 70072 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
51271
diff
changeset
|
1359 if (!buf_passed) { |
|
b421441ee679
Merged revisions 70072 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
51271
diff
changeset
|
1360 Py_DECREF(dest); |
|
b421441ee679
Merged revisions 70072 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
51271
diff
changeset
|
1361 } else { |
|
b421441ee679
Merged revisions 70072 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
51271
diff
changeset
|
1362 PyBuffer_Release(&buf); |
|
b421441ee679
Merged revisions 70072 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
51271
diff
changeset
|
1363 } |
|
b421441ee679
Merged revisions 70072 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
51271
diff
changeset
|
1364 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
|
1365 } |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
1366 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23295
diff
changeset
|
1367 PyDoc_STRVAR(PySSL_SSLread_doc, |
|
43869
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
1368 "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
|
1369 \n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23295
diff
changeset
|
1370 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
|
1371 |
|
48681
3c8ef3466923
clean up ssl.py; expose unwrap and add test for it
Bill Janssen <janssen@parc.com>
parents:
48660
diff
changeset
|
1372 static PyObject *PySSL_SSLshutdown(PySSLObject *self) |
|
3c8ef3466923
clean up ssl.py; expose unwrap and add test for it
Bill Janssen <janssen@parc.com>
parents:
48660
diff
changeset
|
1373 { |
|
3c8ef3466923
clean up ssl.py; expose unwrap and add test for it
Bill Janssen <janssen@parc.com>
parents:
48660
diff
changeset
|
1374 int err; |
|
3c8ef3466923
clean up ssl.py; expose unwrap and add test for it
Bill Janssen <janssen@parc.com>
parents:
48660
diff
changeset
|
1375 PySocketSockObject *sock |
|
3c8ef3466923
clean up ssl.py; expose unwrap and add test for it
Bill Janssen <janssen@parc.com>
parents:
48660
diff
changeset
|
1376 = (PySocketSockObject *) PyWeakref_GetObject(self->Socket); |
|
3c8ef3466923
clean up ssl.py; expose unwrap and add test for it
Bill Janssen <janssen@parc.com>
parents:
48660
diff
changeset
|
1377 |
|
3c8ef3466923
clean up ssl.py; expose unwrap and add test for it
Bill Janssen <janssen@parc.com>
parents:
48660
diff
changeset
|
1378 /* Guard against closed socket */ |
|
3c8ef3466923
clean up ssl.py; expose unwrap and add test for it
Bill Janssen <janssen@parc.com>
parents:
48660
diff
changeset
|
1379 if ((((PyObject*)sock) == Py_None) || (sock->sock_fd < 0)) { |
|
3c8ef3466923
clean up ssl.py; expose unwrap and add test for it
Bill Janssen <janssen@parc.com>
parents:
48660
diff
changeset
|
1380 _setSSLError("Underlying socket connection gone", |
|
3c8ef3466923
clean up ssl.py; expose unwrap and add test for it
Bill Janssen <janssen@parc.com>
parents:
48660
diff
changeset
|
1381 PY_SSL_ERROR_NO_SOCKET, __FILE__, __LINE__); |
|
3c8ef3466923
clean up ssl.py; expose unwrap and add test for it
Bill Janssen <janssen@parc.com>
parents:
48660
diff
changeset
|
1382 return NULL; |
|
3c8ef3466923
clean up ssl.py; expose unwrap and add test for it
Bill Janssen <janssen@parc.com>
parents:
48660
diff
changeset
|
1383 } |
|
3c8ef3466923
clean up ssl.py; expose unwrap and add test for it
Bill Janssen <janssen@parc.com>
parents:
48660
diff
changeset
|
1384 |
|
3c8ef3466923
clean up ssl.py; expose unwrap and add test for it
Bill Janssen <janssen@parc.com>
parents:
48660
diff
changeset
|
1385 PySSL_BEGIN_ALLOW_THREADS |
|
3c8ef3466923
clean up ssl.py; expose unwrap and add test for it
Bill Janssen <janssen@parc.com>
parents:
48660
diff
changeset
|
1386 err = SSL_shutdown(self->ssl); |
|
3c8ef3466923
clean up ssl.py; expose unwrap and add test for it
Bill Janssen <janssen@parc.com>
parents:
48660
diff
changeset
|
1387 if (err == 0) { |
|
3c8ef3466923
clean up ssl.py; expose unwrap and add test for it
Bill Janssen <janssen@parc.com>
parents:
48660
diff
changeset
|
1388 /* we need to call it again to finish the shutdown */ |
|
3c8ef3466923
clean up ssl.py; expose unwrap and add test for it
Bill Janssen <janssen@parc.com>
parents:
48660
diff
changeset
|
1389 err = SSL_shutdown(self->ssl); |
|
3c8ef3466923
clean up ssl.py; expose unwrap and add test for it
Bill Janssen <janssen@parc.com>
parents:
48660
diff
changeset
|
1390 } |
|
3c8ef3466923
clean up ssl.py; expose unwrap and add test for it
Bill Janssen <janssen@parc.com>
parents:
48660
diff
changeset
|
1391 PySSL_END_ALLOW_THREADS |
|
3c8ef3466923
clean up ssl.py; expose unwrap and add test for it
Bill Janssen <janssen@parc.com>
parents:
48660
diff
changeset
|
1392 |
|
3c8ef3466923
clean up ssl.py; expose unwrap and add test for it
Bill Janssen <janssen@parc.com>
parents:
48660
diff
changeset
|
1393 if (err < 0) |
|
3c8ef3466923
clean up ssl.py; expose unwrap and add test for it
Bill Janssen <janssen@parc.com>
parents:
48660
diff
changeset
|
1394 return PySSL_SetError(self, err, __FILE__, __LINE__); |
|
3c8ef3466923
clean up ssl.py; expose unwrap and add test for it
Bill Janssen <janssen@parc.com>
parents:
48660
diff
changeset
|
1395 else { |
|
3c8ef3466923
clean up ssl.py; expose unwrap and add test for it
Bill Janssen <janssen@parc.com>
parents:
48660
diff
changeset
|
1396 Py_INCREF(sock); |
|
3c8ef3466923
clean up ssl.py; expose unwrap and add test for it
Bill Janssen <janssen@parc.com>
parents:
48660
diff
changeset
|
1397 return (PyObject *) sock; |
|
3c8ef3466923
clean up ssl.py; expose unwrap and add test for it
Bill Janssen <janssen@parc.com>
parents:
48660
diff
changeset
|
1398 } |
|
3c8ef3466923
clean up ssl.py; expose unwrap and add test for it
Bill Janssen <janssen@parc.com>
parents:
48660
diff
changeset
|
1399 } |
|
3c8ef3466923
clean up ssl.py; expose unwrap and add test for it
Bill Janssen <janssen@parc.com>
parents:
48660
diff
changeset
|
1400 |
|
3c8ef3466923
clean up ssl.py; expose unwrap and add test for it
Bill Janssen <janssen@parc.com>
parents:
48660
diff
changeset
|
1401 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
|
1402 "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
|
1403 \n\ |
|
3c8ef3466923
clean up ssl.py; expose unwrap and add test for it
Bill Janssen <janssen@parc.com>
parents:
48660
diff
changeset
|
1404 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
|
1405 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
|
1406 |
|
3c8ef3466923
clean up ssl.py; expose unwrap and add test for it
Bill Janssen <janssen@parc.com>
parents:
48660
diff
changeset
|
1407 |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
1408 static PyMethodDef PySSLMethods[] = { |
|
43869
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
1409 {"do_handshake", (PyCFunction)PySSL_SSLdo_handshake, METH_NOARGS}, |
|
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 {"write", (PyCFunction)PySSL_SSLwrite, METH_VARARGS, |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1411 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
|
1412 {"read", (PyCFunction)PySSL_SSLread, METH_VARARGS, |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1413 PySSL_SSLread_doc}, |
|
43869
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
1414 {"pending", (PyCFunction)PySSL_SSLpending, METH_NOARGS, |
|
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
1415 PySSL_SSLpending_doc}, |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1416 {"peer_certificate", (PyCFunction)PySSL_peercert, METH_VARARGS, |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1417 PySSL_peercert_doc}, |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1418 {"cipher", (PyCFunction)PySSL_cipher, METH_NOARGS}, |
|
48681
3c8ef3466923
clean up ssl.py; expose unwrap and add test for it
Bill Janssen <janssen@parc.com>
parents:
48660
diff
changeset
|
1419 {"shutdown", (PyCFunction)PySSL_SSLshutdown, METH_NOARGS, |
|
3c8ef3466923
clean up ssl.py; expose unwrap and add test for it
Bill Janssen <janssen@parc.com>
parents:
48660
diff
changeset
|
1420 PySSL_SSLshutdown_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
|
1421 {NULL, NULL} |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
1422 }; |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
1423 |
|
24280
1598a1e473e2
staticforward bites the dust.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24086
diff
changeset
|
1424 static PyTypeObject PySSL_Type = { |
|
42334
e70cdce0e8b2
Merged revisions 56467-56482 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
40450
diff
changeset
|
1425 PyVarObject_HEAD_INIT(NULL, 0) |
|
44206
ce280a04f55e
Reverting revision 59394. We'll sort this out later.
Guido van Rossum <guido@python.org>
parents:
44205
diff
changeset
|
1426 "ssl.SSLContext", /*tp_name*/ |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
1427 sizeof(PySSLObject), /*tp_basicsize*/ |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
1428 0, /*tp_itemsize*/ |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
1429 /* methods */ |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
1430 (destructor)PySSL_dealloc, /*tp_dealloc*/ |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
1431 0, /*tp_print*/ |
|
48413
7e56016a6565
#3247 Get rid of Py_FindMethod; use tp_members instead.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47580
diff
changeset
|
1432 0, /*tp_getattr*/ |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
1433 0, /*tp_setattr*/ |
|
51271
87fbbf22adf3
Merged revisions 69214 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
51068
diff
changeset
|
1434 0, /*tp_reserved*/ |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
1435 0, /*tp_repr*/ |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
1436 0, /*tp_as_number*/ |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
1437 0, /*tp_as_sequence*/ |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
1438 0, /*tp_as_mapping*/ |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
1439 0, /*tp_hash*/ |
|
48413
7e56016a6565
#3247 Get rid of Py_FindMethod; use tp_members instead.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47580
diff
changeset
|
1440 0, /*tp_call*/ |
|
7e56016a6565
#3247 Get rid of Py_FindMethod; use tp_members instead.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47580
diff
changeset
|
1441 0, /*tp_str*/ |
|
7e56016a6565
#3247 Get rid of Py_FindMethod; use tp_members instead.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47580
diff
changeset
|
1442 0, /*tp_getattro*/ |
|
7e56016a6565
#3247 Get rid of Py_FindMethod; use tp_members instead.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47580
diff
changeset
|
1443 0, /*tp_setattro*/ |
|
7e56016a6565
#3247 Get rid of Py_FindMethod; use tp_members instead.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47580
diff
changeset
|
1444 0, /*tp_as_buffer*/ |
|
7e56016a6565
#3247 Get rid of Py_FindMethod; use tp_members instead.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47580
diff
changeset
|
1445 Py_TPFLAGS_DEFAULT, /*tp_flags*/ |
|
7e56016a6565
#3247 Get rid of Py_FindMethod; use tp_members instead.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47580
diff
changeset
|
1446 0, /*tp_doc*/ |
|
7e56016a6565
#3247 Get rid of Py_FindMethod; use tp_members instead.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47580
diff
changeset
|
1447 0, /*tp_traverse*/ |
|
7e56016a6565
#3247 Get rid of Py_FindMethod; use tp_members instead.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47580
diff
changeset
|
1448 0, /*tp_clear*/ |
|
7e56016a6565
#3247 Get rid of Py_FindMethod; use tp_members instead.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47580
diff
changeset
|
1449 0, /*tp_richcompare*/ |
|
7e56016a6565
#3247 Get rid of Py_FindMethod; use tp_members instead.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47580
diff
changeset
|
1450 0, /*tp_weaklistoffset*/ |
|
7e56016a6565
#3247 Get rid of Py_FindMethod; use tp_members instead.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47580
diff
changeset
|
1451 0, /*tp_iter*/ |
|
7e56016a6565
#3247 Get rid of Py_FindMethod; use tp_members instead.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47580
diff
changeset
|
1452 0, /*tp_iternext*/ |
|
7e56016a6565
#3247 Get rid of Py_FindMethod; use tp_members instead.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47580
diff
changeset
|
1453 PySSLMethods, /*tp_methods*/ |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
1454 }; |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
1455 |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
1456 #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
|
1457 |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
1458 /* 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
|
1459 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
|
1460 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
|
1461 { |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
1462 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
|
1463 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
|
1464 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
|
1465 |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
1466 if (!PyArg_ParseTuple(args, "s#d: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
|
1467 return NULL; |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
1468 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
|
1469 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
|
1470 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
|
1471 } |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
1472 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23295
diff
changeset
|
1473 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
|
1474 "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
|
1475 \n\ |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
1476 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
|
1477 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
|
1478 |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
1479 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
|
1480 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
|
1481 { |
|
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
|
1482 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
|
1483 } |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
1484 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23295
diff
changeset
|
1485 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
|
1486 "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
|
1487 \n\ |
|
43869
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
1488 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
|
1489 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
|
1490 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
|
1491 |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
1492 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
|
1493 PySSL_RAND_egd(PyObject *self, PyObject *arg) |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
1494 { |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
1495 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
|
1496 |
|
43869
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
1497 if (!PyUnicode_Check(arg)) |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
1498 return PyErr_Format(PyExc_TypeError, |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
1499 "RAND_egd() expected string, found %s", |
|
44351
86a2679dca46
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents:
44310
diff
changeset
|
1500 Py_TYPE(arg)->tp_name); |
|
48660
85b67fb5672b
Rename PyUnicode_AsString -> _PyUnicode_AsString and
Marc-André Lemburg <mal@egenix.com>
parents:
48413
diff
changeset
|
1501 bytes = RAND_egd(_PyUnicode_AsString(arg)); |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
1502 if (bytes == -1) { |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
1503 PyErr_SetString(PySSLErrorObject, |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
1504 "EGD connection failed or EGD did not return " |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
1505 "enough data to seed the PRNG"); |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
1506 return NULL; |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
1507 } |
|
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
|
1508 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
|
1509 } |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
1510 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23295
diff
changeset
|
1511 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
|
1512 "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
|
1513 \n\ |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1514 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
|
1515 Returns number of bytes read. Raises SSLError if connection to EGD\n\ |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1516 fails or if it does 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
|
1517 |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
1518 #endif |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
1519 |
|
48681
3c8ef3466923
clean up ssl.py; expose unwrap and add test for it
Bill Janssen <janssen@parc.com>
parents:
48660
diff
changeset
|
1520 |
|
3c8ef3466923
clean up ssl.py; expose unwrap and add test for it
Bill Janssen <janssen@parc.com>
parents:
48660
diff
changeset
|
1521 |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
1522 /* 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
|
1523 |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
1524 static PyMethodDef PySSL_methods[] = { |
|
42954
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
1525 {"sslwrap", PySSL_sslwrap, |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
1526 METH_VARARGS, ssl_doc}, |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1527 {"_test_decode_cert", PySSL_test_decode_certificate, |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1528 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
|
1529 #ifdef HAVE_OPENSSL_RAND |
|
42954
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
1530 {"RAND_add", PySSL_RAND_add, 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
|
1531 PySSL_RAND_add_doc}, |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
1532 {"RAND_egd", PySSL_RAND_egd, METH_O, |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
1533 PySSL_RAND_egd_doc}, |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
1534 {"RAND_status", (PyCFunction)PySSL_RAND_status, METH_NOARGS, |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
1535 PySSL_RAND_status_doc}, |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
1536 #endif |
|
42954
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
1537 {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
|
1538 }; |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
1539 |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
1540 |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1541 #ifdef WITH_THREAD |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1542 |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1543 /* 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
|
1544 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
|
1545 |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1546 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
|
1547 |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1548 static unsigned long _ssl_thread_id_function (void) { |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1549 return PyThread_get_thread_ident(); |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1550 } |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1551 |
|
43869
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
1552 static void _ssl_thread_locking_function |
|
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
1553 (int mode, int n, const char *file, int line) { |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1554 /* this function is needed to perform locking on shared data |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1555 structures. (Note that OpenSSL uses a number of global data |
|
43869
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
1556 structures that will be implicitly shared whenever multiple |
|
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
1557 threads use OpenSSL.) Multi-threaded applications will |
|
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
1558 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
|
1559 |
|
43869
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
1560 locking_function() must be able to handle up to |
|
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
1561 CRYPTO_num_locks() different mutex locks. It sets the n-th |
|
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
1562 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
|
1563 |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1564 file and line are the file number of the function setting the |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1565 lock. They can be useful for debugging. |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1566 */ |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1567 |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1568 if ((_ssl_locks == NULL) || |
|
46145
da5597a5c195
Merged revisions 61964-61979 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45017
diff
changeset
|
1569 (n < 0) || ((unsigned)n >= _ssl_locks_count)) |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1570 return; |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1571 |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1572 if (mode & CRYPTO_LOCK) { |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1573 PyThread_acquire_lock(_ssl_locks[n], 1); |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1574 } else { |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1575 PyThread_release_lock(_ssl_locks[n]); |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1576 } |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1577 } |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1578 |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1579 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
|
1580 |
|
46145
da5597a5c195
Merged revisions 61964-61979 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45017
diff
changeset
|
1581 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
|
1582 |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1583 if (_ssl_locks == NULL) { |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1584 _ssl_locks_count = CRYPTO_num_locks(); |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1585 _ssl_locks = (PyThread_type_lock *) |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1586 malloc(sizeof(PyThread_type_lock) * _ssl_locks_count); |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1587 if (_ssl_locks == NULL) |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1588 return 0; |
|
43869
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
1589 memset(_ssl_locks, 0, |
|
b59825d9db8f
get SSL support to work again
Bill Janssen <janssen@parc.com>
parents:
43400
diff
changeset
|
1590 sizeof(PyThread_type_lock) * _ssl_locks_count); |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1591 for (i = 0; i < _ssl_locks_count; i++) { |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1592 _ssl_locks[i] = PyThread_allocate_lock(); |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1593 if (_ssl_locks[i] == NULL) { |
|
51068
02e1c5ce6a69
Fix signed/unsigned mismatch.
Raymond Hettinger <python@rcn.com>
parents:
48681
diff
changeset
|
1594 unsigned int j; |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1595 for (j = 0; j < i; j++) { |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1596 PyThread_free_lock(_ssl_locks[j]); |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1597 } |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1598 free(_ssl_locks); |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1599 return 0; |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1600 } |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1601 } |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1602 CRYPTO_set_locking_callback(_ssl_thread_locking_function); |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1603 CRYPTO_set_id_callback(_ssl_thread_id_function); |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1604 } |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1605 return 1; |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1606 } |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1607 |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1608 #endif /* def HAVE_THREAD */ |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1609 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23295
diff
changeset
|
1610 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
|
1611 "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
|
1612 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
|
1613 |
|
47580
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47301
diff
changeset
|
1614 |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47301
diff
changeset
|
1615 static struct PyModuleDef _sslmodule = { |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47301
diff
changeset
|
1616 PyModuleDef_HEAD_INIT, |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47301
diff
changeset
|
1617 "_ssl", |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47301
diff
changeset
|
1618 module_doc, |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47301
diff
changeset
|
1619 -1, |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47301
diff
changeset
|
1620 PySSL_methods, |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47301
diff
changeset
|
1621 NULL, |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47301
diff
changeset
|
1622 NULL, |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47301
diff
changeset
|
1623 NULL, |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47301
diff
changeset
|
1624 NULL |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47301
diff
changeset
|
1625 }; |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47301
diff
changeset
|
1626 |
|
24471
f66b3a3509c7
Excise DL_EXPORT/DL_IMPORT from Modules/*. Required adding a prototype
Mark Hammond <mhammond@skippinet.com.au>
parents:
24398
diff
changeset
|
1627 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
|
1628 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
|
1629 { |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
1630 PyObject *m, *d; |
|
53816
911df82bc25d
add a replacement API for PyCObject, PyCapsule #5630
Benjamin Peterson <benjamin@python.org>
parents:
51922
diff
changeset
|
1631 PySocketModule_APIObject *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
|
1632 |
|
48413
7e56016a6565
#3247 Get rid of Py_FindMethod; use tp_members instead.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47580
diff
changeset
|
1633 if (PyType_Ready(&PySSL_Type) < 0) |
|
7e56016a6565
#3247 Get rid of Py_FindMethod; use tp_members instead.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47580
diff
changeset
|
1634 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
|
1635 |
|
47580
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47301
diff
changeset
|
1636 m = PyModule_Create(&_sslmodule); |
|
36324
1af7f719ed28
Check return result from Py_InitModule*(). This API can fail.
Neal Norwitz <nnorwitz@gmail.com>
parents:
32960
diff
changeset
|
1637 if (m == NULL) |
|
47580
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47301
diff
changeset
|
1638 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
|
1639 d = PyModule_GetDict(m); |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
1640 |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
1641 /* Load _socket module and its C API */ |
|
53816
911df82bc25d
add a replacement API for PyCObject, PyCapsule #5630
Benjamin Peterson <benjamin@python.org>
parents:
51922
diff
changeset
|
1642 socket_api = PySocketModule_ImportModuleAndAPI(); |
|
911df82bc25d
add a replacement API for PyCObject, PyCapsule #5630
Benjamin Peterson <benjamin@python.org>
parents:
51922
diff
changeset
|
1643 if (!socket_api) |
|
47580
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47301
diff
changeset
|
1644 return NULL; |
|
53816
911df82bc25d
add a replacement API for PyCObject, PyCapsule #5630
Benjamin Peterson <benjamin@python.org>
parents:
51922
diff
changeset
|
1645 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
|
1646 |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
1647 /* Init OpenSSL */ |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
1648 SSL_load_error_strings(); |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1649 #ifdef WITH_THREAD |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1650 /* note that this will start threading if not already started */ |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1651 if (!_setup_ssl_threads()) { |
|
47580
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47301
diff
changeset
|
1652 return NULL; |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1653 } |
|
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1654 #endif |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
1655 SSLeay_add_ssl_algorithms(); |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
1656 |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
1657 /* Add symbols to module dict */ |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1658 PySSLErrorObject = PyErr_NewException("ssl.SSLError", |
|
42954
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
1659 PySocketModule.error, |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
1660 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
|
1661 if (PySSLErrorObject == NULL) |
|
47580
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47301
diff
changeset
|
1662 return NULL; |
|
43400
1bac386c17cc
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
43292
diff
changeset
|
1663 if (PyDict_SetItemString(d, "SSLError", PySSLErrorObject) != 0) |
|
47580
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47301
diff
changeset
|
1664 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
|
1665 if (PyDict_SetItemString(d, "SSLType", |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
1666 (PyObject *)&PySSL_Type) != 0) |
|
47580
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47301
diff
changeset
|
1667 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
|
1668 PyModule_AddIntConstant(m, "SSL_ERROR_ZERO_RETURN", |
|
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
|
1669 PY_SSL_ERROR_ZERO_RETURN); |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
1670 PyModule_AddIntConstant(m, "SSL_ERROR_WANT_READ", |
|
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
|
1671 PY_SSL_ERROR_WANT_READ); |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
1672 PyModule_AddIntConstant(m, "SSL_ERROR_WANT_WRITE", |
|
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
|
1673 PY_SSL_ERROR_WANT_WRITE); |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
1674 PyModule_AddIntConstant(m, "SSL_ERROR_WANT_X509_LOOKUP", |
|
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
|
1675 PY_SSL_ERROR_WANT_X509_LOOKUP); |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
1676 PyModule_AddIntConstant(m, "SSL_ERROR_SYSCALL", |
|
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
|
1677 PY_SSL_ERROR_SYSCALL); |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
1678 PyModule_AddIntConstant(m, "SSL_ERROR_SSL", |
|
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
|
1679 PY_SSL_ERROR_SSL); |
|
0bc3a41d4e40
Forward port of patch # 500311: Work around for buggy https servers.
Martin v. Löwis <martin@v.loewis.de>
parents:
21959
diff
changeset
|
1680 PyModule_AddIntConstant(m, "SSL_ERROR_WANT_CONNECT", |
|
0bc3a41d4e40
Forward port of patch # 500311: Work around for buggy https servers.
Martin v. Löwis <martin@v.loewis.de>
parents:
21959
diff
changeset
|
1681 PY_SSL_ERROR_WANT_CONNECT); |
|
0bc3a41d4e40
Forward port of patch # 500311: Work around for buggy https servers.
Martin v. Löwis <martin@v.loewis.de>
parents:
21959
diff
changeset
|
1682 /* non ssl.h errorcodes */ |
|
0bc3a41d4e40
Forward port of patch # 500311: Work around for buggy https servers.
Martin v. Löwis <martin@v.loewis.de>
parents:
21959
diff
changeset
|
1683 PyModule_AddIntConstant(m, "SSL_ERROR_EOF", |
|
0bc3a41d4e40
Forward port of patch # 500311: Work around for buggy https servers.
Martin v. Löwis <martin@v.loewis.de>
parents:
21959
diff
changeset
|
1684 PY_SSL_ERROR_EOF); |
|
0bc3a41d4e40
Forward port of patch # 500311: Work around for buggy https servers.
Martin v. Löwis <martin@v.loewis.de>
parents:
21959
diff
changeset
|
1685 PyModule_AddIntConstant(m, "SSL_ERROR_INVALID_ERROR_CODE", |
|
0bc3a41d4e40
Forward port of patch # 500311: Work around for buggy https servers.
Martin v. Löwis <martin@v.loewis.de>
parents:
21959
diff
changeset
|
1686 PY_SSL_ERROR_INVALID_ERROR_CODE); |
|
42954
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
1687 /* cert requirements */ |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
1688 PyModule_AddIntConstant(m, "CERT_NONE", |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
1689 PY_SSL_CERT_NONE); |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
1690 PyModule_AddIntConstant(m, "CERT_OPTIONAL", |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
1691 PY_SSL_CERT_OPTIONAL); |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
1692 PyModule_AddIntConstant(m, "CERT_REQUIRED", |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
1693 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
|
1694 |
|
42954
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
1695 /* protocol versions */ |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
1696 PyModule_AddIntConstant(m, "PROTOCOL_SSLv2", |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
1697 PY_SSL_VERSION_SSL2); |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
1698 PyModule_AddIntConstant(m, "PROTOCOL_SSLv3", |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
1699 PY_SSL_VERSION_SSL3); |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
1700 PyModule_AddIntConstant(m, "PROTOCOL_SSLv23", |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
1701 PY_SSL_VERSION_SSL23); |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
1702 PyModule_AddIntConstant(m, "PROTOCOL_TLSv1", |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42847
diff
changeset
|
1703 PY_SSL_VERSION_TLS1); |
|
47580
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47301
diff
changeset
|
1704 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
|
1705 } |
