Mercurial > cpython-lru_cache-weakref
annotate Modules/_ssl.c @ 32527:0da660e05e69 legacy-trunk
"#if WITH_THREAD" is incorrect; must be #ifdef instead; WITH_THREAD
isn't always set to an integer value when it's defined.
| author | Tim Peters <tim.peters@gmail.com> |
|---|---|
| date | Wed, 07 Jul 2004 20:42:07 +0000 |
| parents | 29da8bdfeb4e |
| children | 598a5ce63322 |
| rev | line source |
|---|---|
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
1 /* SSL 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
|
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. |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
4 |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
5 This module is imported by socket.py. It should *not* be used |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
6 directly. |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
7 |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
8 */ |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
9 |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
10 #include "Python.h" |
|
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
|
11 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
|
12 /* these mirror ssl.h */ |
|
0bc3a41d4e40
Forward port of patch # 500311: Work around for buggy https servers.
Martin v. Löwis <martin@v.loewis.de>
parents:
21959
diff
changeset
|
13 PY_SSL_ERROR_NONE, |
|
0bc3a41d4e40
Forward port of patch # 500311: Work around for buggy https servers.
Martin v. Löwis <martin@v.loewis.de>
parents:
21959
diff
changeset
|
14 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
|
15 PY_SSL_ERROR_WANT_READ, |
|
0bc3a41d4e40
Forward port of patch # 500311: Work around for buggy https servers.
Martin v. Löwis <martin@v.loewis.de>
parents:
21959
diff
changeset
|
16 PY_SSL_ERROR_WANT_WRITE, |
|
0bc3a41d4e40
Forward port of patch # 500311: Work around for buggy https servers.
Martin v. Löwis <martin@v.loewis.de>
parents:
21959
diff
changeset
|
17 PY_SSL_ERROR_WANT_X509_LOOKUP, |
|
0bc3a41d4e40
Forward port of patch # 500311: Work around for buggy https servers.
Martin v. Löwis <martin@v.loewis.de>
parents:
21959
diff
changeset
|
18 PY_SSL_ERROR_SYSCALL, /* look at error stack/return value/errno */ |
|
0bc3a41d4e40
Forward port of patch # 500311: Work around for buggy https servers.
Martin v. Löwis <martin@v.loewis.de>
parents:
21959
diff
changeset
|
19 PY_SSL_ERROR_ZERO_RETURN, |
|
0bc3a41d4e40
Forward port of patch # 500311: Work around for buggy https servers.
Martin v. Löwis <martin@v.loewis.de>
parents:
21959
diff
changeset
|
20 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
|
21 /* start of 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
|
22 PY_SSL_ERROR_EOF, /* special case of SSL_ERROR_SYSCALL */ |
|
0bc3a41d4e40
Forward port of patch # 500311: Work around for buggy https servers.
Martin v. Löwis <martin@v.loewis.de>
parents:
21959
diff
changeset
|
23 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
|
24 }; |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
25 |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
26 /* 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
|
27 #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
|
28 |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
29 /* 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
|
30 #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
|
31 #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
|
32 #include "openssl/x509.h" |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
33 #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
|
34 #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
|
35 #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
|
36 #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
|
37 |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
38 /* 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
|
39 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
|
40 |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
41 /* 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
|
42 |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
43 #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
|
44 |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
45 /* 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
|
46 #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
|
47 # 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
|
48 #else |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
49 # 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
|
50 #endif |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
51 |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
52 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
|
53 PyObject_HEAD |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
54 PySocketSockObject *Socket; /* Socket on which we're layered */ |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
55 SSL_CTX* ctx; |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
56 SSL* ssl; |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
57 X509* server_cert; |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
58 BIO* sbio; |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
59 char server[X509_NAME_MAXLEN]; |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
60 char issuer[X509_NAME_MAXLEN]; |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
61 |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
62 } PySSLObject; |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
63 |
|
24280
1598a1e473e2
staticforward bites the dust.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24086
diff
changeset
|
64 static PyTypeObject PySSL_Type; |
|
1598a1e473e2
staticforward bites the dust.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24086
diff
changeset
|
65 static PyObject *PySSL_SSLwrite(PySSLObject *self, PyObject *args); |
|
1598a1e473e2
staticforward bites the dust.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24086
diff
changeset
|
66 static PyObject *PySSL_SSLread(PySSLObject *self, PyObject *args); |
| 27594 | 67 static int wait_for_timeout(PySocketSockObject *s, int writing); |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
68 |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
69 #define PySSLObject_Check(v) ((v)->ob_type == &PySSL_Type) |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
70 |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
71 /* 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
|
72 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
|
73 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
|
74 */ |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
75 |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
76 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
|
77 PySSL_SetError(PySSLObject *obj, int ret) |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
78 { |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
79 PyObject *v, *n, *s; |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
80 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
|
81 int err; |
|
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
|
82 enum py_ssl_error p; |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
83 |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
84 assert(ret <= 0); |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
85 |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
86 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
|
87 |
|
0bc3a41d4e40
Forward port of patch # 500311: Work around for buggy https servers.
Martin v. Löwis <martin@v.loewis.de>
parents:
21959
diff
changeset
|
88 switch (err) { |
|
0bc3a41d4e40
Forward port of patch # 500311: Work around for buggy https servers.
Martin v. Löwis <martin@v.loewis.de>
parents:
21959
diff
changeset
|
89 case SSL_ERROR_ZERO_RETURN: |
|
0bc3a41d4e40
Forward port of patch # 500311: Work around for buggy https servers.
Martin v. Löwis <martin@v.loewis.de>
parents:
21959
diff
changeset
|
90 errstr = "TLS/SSL connection has been closed"; |
|
24086
86dfb96a1831
Repair badly formatted code.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
23832
diff
changeset
|
91 p = 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
|
92 break; |
|
0bc3a41d4e40
Forward port of patch # 500311: Work around for buggy https servers.
Martin v. Löwis <martin@v.loewis.de>
parents:
21959
diff
changeset
|
93 case SSL_ERROR_WANT_READ: |
|
0bc3a41d4e40
Forward port of patch # 500311: Work around for buggy https servers.
Martin v. Löwis <martin@v.loewis.de>
parents:
21959
diff
changeset
|
94 errstr = "The operation did not complete (read)"; |
|
24086
86dfb96a1831
Repair badly formatted code.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
23832
diff
changeset
|
95 p = PY_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
|
96 break; |
|
0bc3a41d4e40
Forward port of patch # 500311: Work around for buggy https servers.
Martin v. Löwis <martin@v.loewis.de>
parents:
21959
diff
changeset
|
97 case SSL_ERROR_WANT_WRITE: |
|
24086
86dfb96a1831
Repair badly formatted code.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
23832
diff
changeset
|
98 p = PY_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
|
99 errstr = "The operation did not complete (write)"; |
|
0bc3a41d4e40
Forward port of patch # 500311: Work around for buggy https servers.
Martin v. Löwis <martin@v.loewis.de>
parents:
21959
diff
changeset
|
100 break; |
|
0bc3a41d4e40
Forward port of patch # 500311: Work around for buggy https servers.
Martin v. Löwis <martin@v.loewis.de>
parents:
21959
diff
changeset
|
101 case SSL_ERROR_WANT_X509_LOOKUP: |
|
24086
86dfb96a1831
Repair badly formatted code.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
23832
diff
changeset
|
102 p = 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
|
103 errstr = "The operation did not complete (X509 lookup)"; |
|
0bc3a41d4e40
Forward port of patch # 500311: Work around for buggy https servers.
Martin v. Löwis <martin@v.loewis.de>
parents:
21959
diff
changeset
|
104 break; |
|
0bc3a41d4e40
Forward port of patch # 500311: Work around for buggy https servers.
Martin v. Löwis <martin@v.loewis.de>
parents:
21959
diff
changeset
|
105 case SSL_ERROR_WANT_CONNECT: |
|
24086
86dfb96a1831
Repair badly formatted code.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
23832
diff
changeset
|
106 p = PY_SSL_ERROR_WANT_CONNECT; |
|
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
|
107 errstr = "The operation did not complete (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
|
108 break; |
|
0bc3a41d4e40
Forward port of patch # 500311: Work around for buggy https servers.
Martin v. Löwis <martin@v.loewis.de>
parents:
21959
diff
changeset
|
109 case SSL_ERROR_SYSCALL: |
|
0bc3a41d4e40
Forward port of patch # 500311: Work around for buggy https servers.
Martin v. Löwis <martin@v.loewis.de>
parents:
21959
diff
changeset
|
110 { |
|
0bc3a41d4e40
Forward port of patch # 500311: Work around for buggy https servers.
Martin v. Löwis <martin@v.loewis.de>
parents:
21959
diff
changeset
|
111 unsigned long e = ERR_get_error(); |
|
24086
86dfb96a1831
Repair badly formatted code.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
23832
diff
changeset
|
112 if (e == 0) { |
|
29695
d0dc956467bf
Fix SF #754870, SSL crash interpreter when remote side closes during connect
Neal Norwitz <nnorwitz@gmail.com>
parents:
29629
diff
changeset
|
113 if (ret == 0 || !obj->Socket) { |
|
24086
86dfb96a1831
Repair badly formatted code.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
23832
diff
changeset
|
114 p = PY_SSL_ERROR_EOF; |
|
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
|
115 errstr = "EOF occurred in violation of protocol"; |
|
24086
86dfb96a1831
Repair badly formatted code.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
23832
diff
changeset
|
116 } else if (ret == -1) { |
|
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
|
117 /* the underlying BIO reported an I/O 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
|
118 return obj->Socket->errorhandler(); |
|
24086
86dfb96a1831
Repair badly formatted code.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
23832
diff
changeset
|
119 } else { /* possible? */ |
|
86dfb96a1831
Repair badly formatted code.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
23832
diff
changeset
|
120 p = PY_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
|
121 errstr = "Some I/O error occurred"; |
|
0bc3a41d4e40
Forward port of patch # 500311: Work around for buggy https servers.
Martin v. Löwis <martin@v.loewis.de>
parents:
21959
diff
changeset
|
122 } |
|
0bc3a41d4e40
Forward port of patch # 500311: Work around for buggy https servers.
Martin v. Löwis <martin@v.loewis.de>
parents:
21959
diff
changeset
|
123 } else { |
|
24086
86dfb96a1831
Repair badly formatted code.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
23832
diff
changeset
|
124 p = PY_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
|
125 /* XXX Protected by global interpreter lock */ |
|
0bc3a41d4e40
Forward port of patch # 500311: Work around for buggy https servers.
Martin v. Löwis <martin@v.loewis.de>
parents:
21959
diff
changeset
|
126 errstr = ERR_error_string(e, NULL); |
|
0bc3a41d4e40
Forward port of patch # 500311: Work around for buggy https servers.
Martin v. Löwis <martin@v.loewis.de>
parents:
21959
diff
changeset
|
127 } |
|
0bc3a41d4e40
Forward port of patch # 500311: Work around for buggy https servers.
Martin v. Löwis <martin@v.loewis.de>
parents:
21959
diff
changeset
|
128 break; |
|
0bc3a41d4e40
Forward port of patch # 500311: Work around for buggy https servers.
Martin v. Löwis <martin@v.loewis.de>
parents:
21959
diff
changeset
|
129 } |
|
0bc3a41d4e40
Forward port of patch # 500311: Work around for buggy https servers.
Martin v. Löwis <martin@v.loewis.de>
parents:
21959
diff
changeset
|
130 case 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
|
131 { |
|
0bc3a41d4e40
Forward port of patch # 500311: Work around for buggy https servers.
Martin v. Löwis <martin@v.loewis.de>
parents:
21959
diff
changeset
|
132 unsigned long e = ERR_get_error(); |
|
24086
86dfb96a1831
Repair badly formatted code.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
23832
diff
changeset
|
133 p = PY_SSL_ERROR_SSL; |
|
86dfb96a1831
Repair badly formatted code.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
23832
diff
changeset
|
134 if (e != 0) |
|
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
|
135 /* XXX Protected by global interpreter lock */ |
|
0bc3a41d4e40
Forward port of patch # 500311: Work around for buggy https servers.
Martin v. Löwis <martin@v.loewis.de>
parents:
21959
diff
changeset
|
136 errstr = ERR_error_string(e, NULL); |
|
24086
86dfb96a1831
Repair badly formatted code.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
23832
diff
changeset
|
137 else { /* possible? */ |
|
86dfb96a1831
Repair badly formatted code.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
23832
diff
changeset
|
138 errstr = "A failure in the SSL library occurred"; |
|
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
|
139 } |
|
0bc3a41d4e40
Forward port of patch # 500311: Work around for buggy https servers.
Martin v. Löwis <martin@v.loewis.de>
parents:
21959
diff
changeset
|
140 break; |
|
0bc3a41d4e40
Forward port of patch # 500311: Work around for buggy https servers.
Martin v. Löwis <martin@v.loewis.de>
parents:
21959
diff
changeset
|
141 } |
|
0bc3a41d4e40
Forward port of patch # 500311: Work around for buggy https servers.
Martin v. Löwis <martin@v.loewis.de>
parents:
21959
diff
changeset
|
142 default: |
|
24086
86dfb96a1831
Repair badly formatted code.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
23832
diff
changeset
|
143 p = PY_SSL_ERROR_INVALID_ERROR_CODE; |
|
23190
0bc3a41d4e40
Forward port of patch # 500311: Work around for buggy https servers.
Martin v. Löwis <martin@v.loewis.de>
parents:
21959
diff
changeset
|
144 errstr = "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
|
145 } |
|
0bc3a41d4e40
Forward port of patch # 500311: Work around for buggy https servers.
Martin v. Löwis <martin@v.loewis.de>
parents:
21959
diff
changeset
|
146 n = PyInt_FromLong((long) p); |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
147 if (n == NULL) |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
148 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
|
149 v = PyTuple_New(2); |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
150 if (v == NULL) { |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
151 Py_DECREF(n); |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
152 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
|
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 |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
155 s = PyString_FromString(errstr); |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
156 if (s == NULL) { |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
157 Py_DECREF(v); |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
158 Py_DECREF(n); |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
159 } |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
160 PyTuple_SET_ITEM(v, 0, n); |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
161 PyTuple_SET_ITEM(v, 1, s); |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
162 PyErr_SetObject(PySSLErrorObject, v); |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
163 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
|
164 } |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
165 |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
166 static PySSLObject * |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
167 newPySSLObject(PySocketSockObject *Sock, char *key_file, char *cert_file) |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
168 { |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
169 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
|
170 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
|
171 int ret; |
|
27557
5eefec94a784
SF patch 676472 by Geoff Talvola, reviewed by Ben Laurie.
Guido van Rossum <guido@python.org>
parents:
27430
diff
changeset
|
172 int err; |
|
5eefec94a784
SF patch 676472 by Geoff Talvola, reviewed by Ben Laurie.
Guido van Rossum <guido@python.org>
parents:
27430
diff
changeset
|
173 int timedout; |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
174 |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
175 self = PyObject_New(PySSLObject, &PySSL_Type); /* Create new object */ |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
176 if (self == NULL){ |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
177 errstr = "newPySSLObject error"; |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
178 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
|
179 } |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
180 memset(self->server, '\0', sizeof(char) * X509_NAME_MAXLEN); |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
181 memset(self->issuer, '\0', sizeof(char) * X509_NAME_MAXLEN); |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
182 self->server_cert = NULL; |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
183 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
|
184 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
|
185 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
|
186 |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
187 if ((key_file && !cert_file) || (!key_file && cert_file)) { |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
188 errstr = "Both the key & certificate files must be specified"; |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
189 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
|
190 } |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
191 |
|
24398
c7ed925c75b3
Patch #575827: allow threads inside SSL creation.
Martin v. Löwis <martin@v.loewis.de>
parents:
24280
diff
changeset
|
192 Py_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
|
193 self->ctx = SSL_CTX_new(SSLv23_method()); /* Set up context */ |
|
24398
c7ed925c75b3
Patch #575827: allow threads inside SSL creation.
Martin v. Löwis <martin@v.loewis.de>
parents:
24280
diff
changeset
|
194 Py_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
|
195 if (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
|
196 errstr = "SSL_CTX_new error"; |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
197 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
|
198 } |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
199 |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
200 if (key_file) { |
|
24398
c7ed925c75b3
Patch #575827: allow threads inside SSL creation.
Martin v. Löwis <martin@v.loewis.de>
parents:
24280
diff
changeset
|
201 Py_BEGIN_ALLOW_THREADS |
|
c7ed925c75b3
Patch #575827: allow threads inside SSL creation.
Martin v. Löwis <martin@v.loewis.de>
parents:
24280
diff
changeset
|
202 ret = SSL_CTX_use_PrivateKey_file(self->ctx, key_file, |
|
c7ed925c75b3
Patch #575827: allow threads inside SSL creation.
Martin v. Löwis <martin@v.loewis.de>
parents:
24280
diff
changeset
|
203 SSL_FILETYPE_PEM); |
|
c7ed925c75b3
Patch #575827: allow threads inside SSL creation.
Martin v. Löwis <martin@v.loewis.de>
parents:
24280
diff
changeset
|
204 Py_END_ALLOW_THREADS |
|
c7ed925c75b3
Patch #575827: allow threads inside SSL creation.
Martin v. Löwis <martin@v.loewis.de>
parents:
24280
diff
changeset
|
205 if (ret < 1) { |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
206 errstr = "SSL_CTX_use_PrivateKey_file error"; |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
207 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
|
208 } |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
209 |
|
24398
c7ed925c75b3
Patch #575827: allow threads inside SSL creation.
Martin v. Löwis <martin@v.loewis.de>
parents:
24280
diff
changeset
|
210 Py_BEGIN_ALLOW_THREADS |
|
c7ed925c75b3
Patch #575827: allow threads inside SSL creation.
Martin v. Löwis <martin@v.loewis.de>
parents:
24280
diff
changeset
|
211 ret = SSL_CTX_use_certificate_chain_file(self->ctx, |
|
c7ed925c75b3
Patch #575827: allow threads inside SSL creation.
Martin v. Löwis <martin@v.loewis.de>
parents:
24280
diff
changeset
|
212 cert_file); |
|
c7ed925c75b3
Patch #575827: allow threads inside SSL creation.
Martin v. Löwis <martin@v.loewis.de>
parents:
24280
diff
changeset
|
213 Py_END_ALLOW_THREADS |
|
c7ed925c75b3
Patch #575827: allow threads inside SSL creation.
Martin v. Löwis <martin@v.loewis.de>
parents:
24280
diff
changeset
|
214 if (ret < 1) { |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
215 errstr = "SSL_CTX_use_certificate_chain_file error"; |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
216 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
|
217 } |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
218 } |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
219 |
|
24398
c7ed925c75b3
Patch #575827: allow threads inside SSL creation.
Martin v. Löwis <martin@v.loewis.de>
parents:
24280
diff
changeset
|
220 Py_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
|
221 SSL_CTX_set_verify(self->ctx, |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
222 SSL_VERIFY_NONE, NULL); /* set verify lvl */ |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
223 self->ssl = SSL_new(self->ctx); /* New ssl struct */ |
|
24398
c7ed925c75b3
Patch #575827: allow threads inside SSL creation.
Martin v. Löwis <martin@v.loewis.de>
parents:
24280
diff
changeset
|
224 Py_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
|
225 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
|
226 |
| 30723 | 227 /* 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
|
228 * 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
|
229 */ |
|
5eefec94a784
SF patch 676472 by Geoff Talvola, reviewed by Ben Laurie.
Guido van Rossum <guido@python.org>
parents:
27430
diff
changeset
|
230 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
|
231 /* 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
|
232 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
|
233 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
|
234 } |
|
5eefec94a784
SF patch 676472 by Geoff Talvola, reviewed by Ben Laurie.
Guido van Rossum <guido@python.org>
parents:
27430
diff
changeset
|
235 |
|
24398
c7ed925c75b3
Patch #575827: allow threads inside SSL creation.
Martin v. Löwis <martin@v.loewis.de>
parents:
24280
diff
changeset
|
236 Py_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
|
237 SSL_set_connect_state(self->ssl); |
|
27557
5eefec94a784
SF patch 676472 by Geoff Talvola, reviewed by Ben Laurie.
Guido van Rossum <guido@python.org>
parents:
27430
diff
changeset
|
238 Py_END_ALLOW_THREADS |
|
24398
c7ed925c75b3
Patch #575827: allow threads inside SSL creation.
Martin v. Löwis <martin@v.loewis.de>
parents:
24280
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 /* Actually negotiate SSL connection */ |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
241 /* XXX If SSL_connect() returns 0, it's also a failure. */ |
|
27557
5eefec94a784
SF patch 676472 by Geoff Talvola, reviewed by Ben Laurie.
Guido van Rossum <guido@python.org>
parents:
27430
diff
changeset
|
242 timedout = 0; |
|
5eefec94a784
SF patch 676472 by Geoff Talvola, reviewed by Ben Laurie.
Guido van Rossum <guido@python.org>
parents:
27430
diff
changeset
|
243 do { |
|
5eefec94a784
SF patch 676472 by Geoff Talvola, reviewed by Ben Laurie.
Guido van Rossum <guido@python.org>
parents:
27430
diff
changeset
|
244 Py_BEGIN_ALLOW_THREADS |
|
5eefec94a784
SF patch 676472 by Geoff Talvola, reviewed by Ben Laurie.
Guido van Rossum <guido@python.org>
parents:
27430
diff
changeset
|
245 ret = SSL_connect(self->ssl); |
|
5eefec94a784
SF patch 676472 by Geoff Talvola, reviewed by Ben Laurie.
Guido van Rossum <guido@python.org>
parents:
27430
diff
changeset
|
246 err = SSL_get_error(self->ssl, ret); |
|
5eefec94a784
SF patch 676472 by Geoff Talvola, reviewed by Ben Laurie.
Guido van Rossum <guido@python.org>
parents:
27430
diff
changeset
|
247 Py_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
|
248 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
|
249 goto fail; |
|
a4d6bc71f091
Patch #751916: Check for signals, fix some refcounting errors.
Martin v. Löwis <martin@v.loewis.de>
parents:
27594
diff
changeset
|
250 } |
|
27557
5eefec94a784
SF patch 676472 by Geoff Talvola, reviewed by Ben Laurie.
Guido van Rossum <guido@python.org>
parents:
27430
diff
changeset
|
251 if (err == SSL_ERROR_WANT_READ) { |
|
5eefec94a784
SF patch 676472 by Geoff Talvola, reviewed by Ben Laurie.
Guido van Rossum <guido@python.org>
parents:
27430
diff
changeset
|
252 timedout = wait_for_timeout(Sock, 0); |
|
5eefec94a784
SF patch 676472 by Geoff Talvola, reviewed by Ben Laurie.
Guido van Rossum <guido@python.org>
parents:
27430
diff
changeset
|
253 } else if (err == SSL_ERROR_WANT_WRITE) { |
|
5eefec94a784
SF patch 676472 by Geoff Talvola, reviewed by Ben Laurie.
Guido van Rossum <guido@python.org>
parents:
27430
diff
changeset
|
254 timedout = wait_for_timeout(Sock, 1); |
|
5eefec94a784
SF patch 676472 by Geoff Talvola, reviewed by Ben Laurie.
Guido van Rossum <guido@python.org>
parents:
27430
diff
changeset
|
255 } |
|
5eefec94a784
SF patch 676472 by Geoff Talvola, reviewed by Ben Laurie.
Guido van Rossum <guido@python.org>
parents:
27430
diff
changeset
|
256 if (timedout) { |
|
29629
a4d6bc71f091
Patch #751916: Check for signals, fix some refcounting errors.
Martin v. Löwis <martin@v.loewis.de>
parents:
27594
diff
changeset
|
257 errstr = "The connect operation timed out"; |
|
a4d6bc71f091
Patch #751916: Check for signals, fix some refcounting errors.
Martin v. Löwis <martin@v.loewis.de>
parents:
27594
diff
changeset
|
258 goto fail; |
|
27557
5eefec94a784
SF patch 676472 by Geoff Talvola, reviewed by Ben Laurie.
Guido van Rossum <guido@python.org>
parents:
27430
diff
changeset
|
259 } |
|
5eefec94a784
SF patch 676472 by Geoff Talvola, reviewed by Ben Laurie.
Guido van Rossum <guido@python.org>
parents:
27430
diff
changeset
|
260 } 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
|
261 if (ret <= 0) { |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
262 PySSL_SetError(self, ret); |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
263 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
|
264 } |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
265 self->ssl->debug = 1; |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
266 |
|
24398
c7ed925c75b3
Patch #575827: allow threads inside SSL creation.
Martin v. Löwis <martin@v.loewis.de>
parents:
24280
diff
changeset
|
267 Py_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
|
268 if ((self->server_cert = SSL_get_peer_certificate(self->ssl))) { |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
269 X509_NAME_oneline(X509_get_subject_name(self->server_cert), |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
270 self->server, X509_NAME_MAXLEN); |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
271 X509_NAME_oneline(X509_get_issuer_name(self->server_cert), |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
272 self->issuer, X509_NAME_MAXLEN); |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
273 } |
|
24398
c7ed925c75b3
Patch #575827: allow threads inside SSL creation.
Martin v. Löwis <martin@v.loewis.de>
parents:
24280
diff
changeset
|
274 Py_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
|
275 self->Socket = Sock; |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
276 Py_INCREF(self->Socket); |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
277 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
|
278 fail: |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
279 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
|
280 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
|
281 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
|
282 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
|
283 } |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
284 |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
285 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
|
286 PySocket_ssl(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
|
287 { |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
288 PySSLObject *rv; |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
289 PySocketSockObject *Sock; |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
290 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
|
291 char *cert_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
|
292 |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
293 if (!PyArg_ParseTuple(args, "O!|zz:ssl", |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
294 PySocketModule.Sock_Type, |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
295 (PyObject*)&Sock, |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
296 &key_file, &cert_file)) |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
297 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
|
298 |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
299 rv = newPySSLObject(Sock, key_file, cert_file); |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
300 if (rv == NULL) |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
301 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
|
302 return (PyObject *)rv; |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
303 } |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
304 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23295
diff
changeset
|
305 PyDoc_STRVAR(ssl_doc, |
|
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23295
diff
changeset
|
306 "ssl(socket, [keyfile, certfile]) -> 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
|
307 |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
308 /* 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
|
309 |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
310 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
|
311 PySSL_server(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
|
312 { |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
313 return PyString_FromString(self->server); |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
314 } |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
315 |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
316 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
|
317 PySSL_issuer(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
|
318 { |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
319 return PyString_FromString(self->issuer); |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
320 } |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
321 |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
322 |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
323 static void PySSL_dealloc(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
|
324 { |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
325 if (self->server_cert) /* Possible not to have one? */ |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
326 X509_free (self->server_cert); |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
327 if (self->ssl) |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
328 SSL_free(self->ssl); |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
329 if (self->ctx) |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
330 SSL_CTX_free(self->ctx); |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
331 Py_XDECREF(self->Socket); |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
332 PyObject_Del(self); |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
333 } |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
334 |
|
27430
1ae0b142370e
Support socket timeout in SSL, by Geoff Talvola.
Guido van Rossum <guido@python.org>
parents:
24471
diff
changeset
|
335 /* If the socket has a timeout, do a select() on the socket. |
|
1ae0b142370e
Support socket timeout in SSL, by Geoff Talvola.
Guido van Rossum <guido@python.org>
parents:
24471
diff
changeset
|
336 The argument writing indicates the direction. |
|
1ae0b142370e
Support socket timeout in SSL, by Geoff Talvola.
Guido van Rossum <guido@python.org>
parents:
24471
diff
changeset
|
337 Return non-zero if the socket timed out, zero otherwise. |
|
1ae0b142370e
Support socket timeout in SSL, by Geoff Talvola.
Guido van Rossum <guido@python.org>
parents:
24471
diff
changeset
|
338 */ |
|
1ae0b142370e
Support socket timeout in SSL, by Geoff Talvola.
Guido van Rossum <guido@python.org>
parents:
24471
diff
changeset
|
339 static int |
|
1ae0b142370e
Support socket timeout in SSL, by Geoff Talvola.
Guido van Rossum <guido@python.org>
parents:
24471
diff
changeset
|
340 wait_for_timeout(PySocketSockObject *s, int writing) |
|
1ae0b142370e
Support socket timeout in SSL, by Geoff Talvola.
Guido van Rossum <guido@python.org>
parents:
24471
diff
changeset
|
341 { |
|
1ae0b142370e
Support socket timeout in SSL, by Geoff Talvola.
Guido van Rossum <guido@python.org>
parents:
24471
diff
changeset
|
342 fd_set fds; |
|
1ae0b142370e
Support socket timeout in SSL, by Geoff Talvola.
Guido van Rossum <guido@python.org>
parents:
24471
diff
changeset
|
343 struct timeval tv; |
|
1ae0b142370e
Support socket timeout in SSL, by Geoff Talvola.
Guido van Rossum <guido@python.org>
parents:
24471
diff
changeset
|
344 int rc; |
|
1ae0b142370e
Support socket timeout in SSL, by Geoff Talvola.
Guido van Rossum <guido@python.org>
parents:
24471
diff
changeset
|
345 |
|
1ae0b142370e
Support socket timeout in SSL, by Geoff Talvola.
Guido van Rossum <guido@python.org>
parents:
24471
diff
changeset
|
346 /* Nothing to do unless we're in timeout mode (not non-blocking) */ |
|
1ae0b142370e
Support socket timeout in SSL, by Geoff Talvola.
Guido van Rossum <guido@python.org>
parents:
24471
diff
changeset
|
347 if (s->sock_timeout <= 0.0) |
|
1ae0b142370e
Support socket timeout in SSL, by Geoff Talvola.
Guido van Rossum <guido@python.org>
parents:
24471
diff
changeset
|
348 return 0; |
|
1ae0b142370e
Support socket timeout in SSL, by Geoff Talvola.
Guido van Rossum <guido@python.org>
parents:
24471
diff
changeset
|
349 |
|
1ae0b142370e
Support socket timeout in SSL, by Geoff Talvola.
Guido van Rossum <guido@python.org>
parents:
24471
diff
changeset
|
350 /* Guard against closed socket */ |
|
1ae0b142370e
Support socket timeout in SSL, by Geoff Talvola.
Guido van Rossum <guido@python.org>
parents:
24471
diff
changeset
|
351 if (s->sock_fd < 0) |
|
1ae0b142370e
Support socket timeout in SSL, by Geoff Talvola.
Guido van Rossum <guido@python.org>
parents:
24471
diff
changeset
|
352 return 0; |
|
1ae0b142370e
Support socket timeout in SSL, by Geoff Talvola.
Guido van Rossum <guido@python.org>
parents:
24471
diff
changeset
|
353 |
|
1ae0b142370e
Support socket timeout in SSL, by Geoff Talvola.
Guido van Rossum <guido@python.org>
parents:
24471
diff
changeset
|
354 /* Construct the arguments to select */ |
|
1ae0b142370e
Support socket timeout in SSL, by Geoff Talvola.
Guido van Rossum <guido@python.org>
parents:
24471
diff
changeset
|
355 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
|
356 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
|
357 FD_ZERO(&fds); |
|
1ae0b142370e
Support socket timeout in SSL, by Geoff Talvola.
Guido van Rossum <guido@python.org>
parents:
24471
diff
changeset
|
358 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
|
359 |
|
1ae0b142370e
Support socket timeout in SSL, by Geoff Talvola.
Guido van Rossum <guido@python.org>
parents:
24471
diff
changeset
|
360 /* See if the socket is ready */ |
|
27557
5eefec94a784
SF patch 676472 by Geoff Talvola, reviewed by Ben Laurie.
Guido van Rossum <guido@python.org>
parents:
27430
diff
changeset
|
361 Py_BEGIN_ALLOW_THREADS |
|
27430
1ae0b142370e
Support socket timeout in SSL, by Geoff Talvola.
Guido van Rossum <guido@python.org>
parents:
24471
diff
changeset
|
362 if (writing) |
|
1ae0b142370e
Support socket timeout in SSL, by Geoff Talvola.
Guido van Rossum <guido@python.org>
parents:
24471
diff
changeset
|
363 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
|
364 else |
|
1ae0b142370e
Support socket timeout in SSL, by Geoff Talvola.
Guido van Rossum <guido@python.org>
parents:
24471
diff
changeset
|
365 rc = select(s->sock_fd+1, &fds, NULL, NULL, &tv); |
|
27557
5eefec94a784
SF patch 676472 by Geoff Talvola, reviewed by Ben Laurie.
Guido van Rossum <guido@python.org>
parents:
27430
diff
changeset
|
366 Py_END_ALLOW_THREADS |
|
27430
1ae0b142370e
Support socket timeout in SSL, by Geoff Talvola.
Guido van Rossum <guido@python.org>
parents:
24471
diff
changeset
|
367 |
|
1ae0b142370e
Support socket timeout in SSL, by Geoff Talvola.
Guido van Rossum <guido@python.org>
parents:
24471
diff
changeset
|
368 /* Return 1 on timeout, 0 otherwise */ |
|
1ae0b142370e
Support socket timeout in SSL, by Geoff Talvola.
Guido van Rossum <guido@python.org>
parents:
24471
diff
changeset
|
369 return rc == 0; |
|
1ae0b142370e
Support socket timeout in SSL, by Geoff Talvola.
Guido van Rossum <guido@python.org>
parents:
24471
diff
changeset
|
370 } |
|
1ae0b142370e
Support socket timeout in SSL, by Geoff Talvola.
Guido van Rossum <guido@python.org>
parents:
24471
diff
changeset
|
371 |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
372 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
|
373 { |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
374 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
|
375 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
|
376 int count; |
|
27430
1ae0b142370e
Support socket timeout in SSL, by Geoff Talvola.
Guido van Rossum <guido@python.org>
parents:
24471
diff
changeset
|
377 int timedout; |
|
27557
5eefec94a784
SF patch 676472 by Geoff Talvola, reviewed by Ben Laurie.
Guido van Rossum <guido@python.org>
parents:
27430
diff
changeset
|
378 int err; |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
379 |
|
30795
9da537167b74
Patch #803998: Correctly check for error in SSL_write.
Martin v. Löwis <martin@v.loewis.de>
parents:
30723
diff
changeset
|
380 if (!PyArg_ParseTuple(args, "s#: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
|
381 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
|
382 |
|
27430
1ae0b142370e
Support socket timeout in SSL, by Geoff Talvola.
Guido van Rossum <guido@python.org>
parents:
24471
diff
changeset
|
383 timedout = wait_for_timeout(self->Socket, 1); |
|
1ae0b142370e
Support socket timeout in SSL, by Geoff Talvola.
Guido van Rossum <guido@python.org>
parents:
24471
diff
changeset
|
384 if (timedout) { |
|
1ae0b142370e
Support socket timeout in SSL, by Geoff Talvola.
Guido van Rossum <guido@python.org>
parents:
24471
diff
changeset
|
385 PyErr_SetString(PySSLErrorObject, "The write operation timed out"); |
|
1ae0b142370e
Support socket timeout in SSL, by Geoff Talvola.
Guido van Rossum <guido@python.org>
parents:
24471
diff
changeset
|
386 return NULL; |
|
1ae0b142370e
Support socket timeout in SSL, by Geoff Talvola.
Guido van Rossum <guido@python.org>
parents:
24471
diff
changeset
|
387 } |
|
27557
5eefec94a784
SF patch 676472 by Geoff Talvola, reviewed by Ben Laurie.
Guido van Rossum <guido@python.org>
parents:
27430
diff
changeset
|
388 do { |
|
5eefec94a784
SF patch 676472 by Geoff Talvola, reviewed by Ben Laurie.
Guido van Rossum <guido@python.org>
parents:
27430
diff
changeset
|
389 err = 0; |
|
5eefec94a784
SF patch 676472 by Geoff Talvola, reviewed by Ben Laurie.
Guido van Rossum <guido@python.org>
parents:
27430
diff
changeset
|
390 Py_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
|
391 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
|
392 err = SSL_get_error(self->ssl, len); |
|
5eefec94a784
SF patch 676472 by Geoff Talvola, reviewed by Ben Laurie.
Guido van Rossum <guido@python.org>
parents:
27430
diff
changeset
|
393 Py_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
|
394 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
|
395 return NULL; |
|
a4d6bc71f091
Patch #751916: Check for signals, fix some refcounting errors.
Martin v. Löwis <martin@v.loewis.de>
parents:
27594
diff
changeset
|
396 } |
|
27557
5eefec94a784
SF patch 676472 by Geoff Talvola, reviewed by Ben Laurie.
Guido van Rossum <guido@python.org>
parents:
27430
diff
changeset
|
397 if (err == SSL_ERROR_WANT_READ) { |
|
5eefec94a784
SF patch 676472 by Geoff Talvola, reviewed by Ben Laurie.
Guido van Rossum <guido@python.org>
parents:
27430
diff
changeset
|
398 timedout = wait_for_timeout(self->Socket, 0); |
|
5eefec94a784
SF patch 676472 by Geoff Talvola, reviewed by Ben Laurie.
Guido van Rossum <guido@python.org>
parents:
27430
diff
changeset
|
399 } else if (err == SSL_ERROR_WANT_WRITE) { |
|
5eefec94a784
SF patch 676472 by Geoff Talvola, reviewed by Ben Laurie.
Guido van Rossum <guido@python.org>
parents:
27430
diff
changeset
|
400 timedout = wait_for_timeout(self->Socket, 1); |
|
5eefec94a784
SF patch 676472 by Geoff Talvola, reviewed by Ben Laurie.
Guido van Rossum <guido@python.org>
parents:
27430
diff
changeset
|
401 } |
|
5eefec94a784
SF patch 676472 by Geoff Talvola, reviewed by Ben Laurie.
Guido van Rossum <guido@python.org>
parents:
27430
diff
changeset
|
402 if (timedout) { |
|
5eefec94a784
SF patch 676472 by Geoff Talvola, reviewed by Ben Laurie.
Guido van Rossum <guido@python.org>
parents:
27430
diff
changeset
|
403 PyErr_SetString(PySSLErrorObject, "The write operation timed out"); |
|
5eefec94a784
SF patch 676472 by Geoff Talvola, reviewed by Ben Laurie.
Guido van Rossum <guido@python.org>
parents:
27430
diff
changeset
|
404 return NULL; |
|
5eefec94a784
SF patch 676472 by Geoff Talvola, reviewed by Ben Laurie.
Guido van Rossum <guido@python.org>
parents:
27430
diff
changeset
|
405 } |
|
5eefec94a784
SF patch 676472 by Geoff Talvola, reviewed by Ben Laurie.
Guido van Rossum <guido@python.org>
parents:
27430
diff
changeset
|
406 } 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
|
407 if (len > 0) |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
408 return PyInt_FromLong(len); |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
409 else |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
410 return PySSL_SetError(self, len); |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
411 } |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
412 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23295
diff
changeset
|
413 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
|
414 "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
|
415 \n\ |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
416 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
|
417 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
|
418 |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
419 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
|
420 { |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
421 PyObject *buf; |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
422 int count = 0; |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
423 int len = 1024; |
|
27430
1ae0b142370e
Support socket timeout in SSL, by Geoff Talvola.
Guido van Rossum <guido@python.org>
parents:
24471
diff
changeset
|
424 int timedout; |
|
27557
5eefec94a784
SF patch 676472 by Geoff Talvola, reviewed by Ben Laurie.
Guido van Rossum <guido@python.org>
parents:
27430
diff
changeset
|
425 int err; |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
426 |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
427 if (!PyArg_ParseTuple(args, "|i:read", &len)) |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
428 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
|
429 |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
430 if (!(buf = PyString_FromStringAndSize((char *) 0, len))) |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
431 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
|
432 |
|
27430
1ae0b142370e
Support socket timeout in SSL, by Geoff Talvola.
Guido van Rossum <guido@python.org>
parents:
24471
diff
changeset
|
433 timedout = wait_for_timeout(self->Socket, 0); |
|
1ae0b142370e
Support socket timeout in SSL, by Geoff Talvola.
Guido van Rossum <guido@python.org>
parents:
24471
diff
changeset
|
434 if (timedout) { |
|
1ae0b142370e
Support socket timeout in SSL, by Geoff Talvola.
Guido van Rossum <guido@python.org>
parents:
24471
diff
changeset
|
435 PyErr_SetString(PySSLErrorObject, "The read operation timed out"); |
|
29695
d0dc956467bf
Fix SF #754870, SSL crash interpreter when remote side closes during connect
Neal Norwitz <nnorwitz@gmail.com>
parents:
29629
diff
changeset
|
436 Py_DECREF(buf); |
|
27430
1ae0b142370e
Support socket timeout in SSL, by Geoff Talvola.
Guido van Rossum <guido@python.org>
parents:
24471
diff
changeset
|
437 return NULL; |
|
1ae0b142370e
Support socket timeout in SSL, by Geoff Talvola.
Guido van Rossum <guido@python.org>
parents:
24471
diff
changeset
|
438 } |
|
27557
5eefec94a784
SF patch 676472 by Geoff Talvola, reviewed by Ben Laurie.
Guido van Rossum <guido@python.org>
parents:
27430
diff
changeset
|
439 do { |
|
5eefec94a784
SF patch 676472 by Geoff Talvola, reviewed by Ben Laurie.
Guido van Rossum <guido@python.org>
parents:
27430
diff
changeset
|
440 err = 0; |
|
5eefec94a784
SF patch 676472 by Geoff Talvola, reviewed by Ben Laurie.
Guido van Rossum <guido@python.org>
parents:
27430
diff
changeset
|
441 Py_BEGIN_ALLOW_THREADS |
|
5eefec94a784
SF patch 676472 by Geoff Talvola, reviewed by Ben Laurie.
Guido van Rossum <guido@python.org>
parents:
27430
diff
changeset
|
442 count = SSL_read(self->ssl, PyString_AsString(buf), len); |
|
5eefec94a784
SF patch 676472 by Geoff Talvola, reviewed by Ben Laurie.
Guido van Rossum <guido@python.org>
parents:
27430
diff
changeset
|
443 err = SSL_get_error(self->ssl, count); |
|
5eefec94a784
SF patch 676472 by Geoff Talvola, reviewed by Ben Laurie.
Guido van Rossum <guido@python.org>
parents:
27430
diff
changeset
|
444 Py_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
|
445 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
|
446 Py_DECREF(buf); |
|
a4d6bc71f091
Patch #751916: Check for signals, fix some refcounting errors.
Martin v. Löwis <martin@v.loewis.de>
parents:
27594
diff
changeset
|
447 return NULL; |
|
a4d6bc71f091
Patch #751916: Check for signals, fix some refcounting errors.
Martin v. Löwis <martin@v.loewis.de>
parents:
27594
diff
changeset
|
448 } |
|
27557
5eefec94a784
SF patch 676472 by Geoff Talvola, reviewed by Ben Laurie.
Guido van Rossum <guido@python.org>
parents:
27430
diff
changeset
|
449 if (err == SSL_ERROR_WANT_READ) { |
|
5eefec94a784
SF patch 676472 by Geoff Talvola, reviewed by Ben Laurie.
Guido van Rossum <guido@python.org>
parents:
27430
diff
changeset
|
450 timedout = wait_for_timeout(self->Socket, 0); |
|
5eefec94a784
SF patch 676472 by Geoff Talvola, reviewed by Ben Laurie.
Guido van Rossum <guido@python.org>
parents:
27430
diff
changeset
|
451 } else if (err == SSL_ERROR_WANT_WRITE) { |
|
5eefec94a784
SF patch 676472 by Geoff Talvola, reviewed by Ben Laurie.
Guido van Rossum <guido@python.org>
parents:
27430
diff
changeset
|
452 timedout = wait_for_timeout(self->Socket, 1); |
|
5eefec94a784
SF patch 676472 by Geoff Talvola, reviewed by Ben Laurie.
Guido van Rossum <guido@python.org>
parents:
27430
diff
changeset
|
453 } |
|
5eefec94a784
SF patch 676472 by Geoff Talvola, reviewed by Ben Laurie.
Guido van Rossum <guido@python.org>
parents:
27430
diff
changeset
|
454 if (timedout) { |
|
5eefec94a784
SF patch 676472 by Geoff Talvola, reviewed by Ben Laurie.
Guido van Rossum <guido@python.org>
parents:
27430
diff
changeset
|
455 PyErr_SetString(PySSLErrorObject, "The read operation timed out"); |
|
29629
a4d6bc71f091
Patch #751916: Check for signals, fix some refcounting errors.
Martin v. Löwis <martin@v.loewis.de>
parents:
27594
diff
changeset
|
456 Py_DECREF(buf); |
|
27557
5eefec94a784
SF patch 676472 by Geoff Talvola, reviewed by Ben Laurie.
Guido van Rossum <guido@python.org>
parents:
27430
diff
changeset
|
457 return NULL; |
|
5eefec94a784
SF patch 676472 by Geoff Talvola, reviewed by Ben Laurie.
Guido van Rossum <guido@python.org>
parents:
27430
diff
changeset
|
458 } |
|
5eefec94a784
SF patch 676472 by Geoff Talvola, reviewed by Ben Laurie.
Guido van Rossum <guido@python.org>
parents:
27430
diff
changeset
|
459 } 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
|
460 if (count <= 0) { |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
461 Py_DECREF(buf); |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
462 return PySSL_SetError(self, count); |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
463 } |
|
23295
6fa76b4e59fe
Repair widespread misuse of _PyString_Resize. Since it's clear people
Tim Peters <tim.peters@gmail.com>
parents:
23190
diff
changeset
|
464 if (count != len) |
|
6fa76b4e59fe
Repair widespread misuse of _PyString_Resize. Since it's clear people
Tim Peters <tim.peters@gmail.com>
parents:
23190
diff
changeset
|
465 _PyString_Resize(&buf, 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
|
466 return buf; |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
467 } |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
468 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23295
diff
changeset
|
469 PyDoc_STRVAR(PySSL_SSLread_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
|
470 "read([len]) -> string\n\ |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
471 \n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23295
diff
changeset
|
472 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
|
473 |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
474 static PyMethodDef PySSLMethods[] = { |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
475 {"write", (PyCFunction)PySSL_SSLwrite, METH_VARARGS, |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
476 PySSL_SSLwrite_doc}, |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
477 {"read", (PyCFunction)PySSL_SSLread, METH_VARARGS, |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
478 PySSL_SSLread_doc}, |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
479 {"server", (PyCFunction)PySSL_server, 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
|
480 {"issuer", (PyCFunction)PySSL_issuer, 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
|
481 {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
|
482 }; |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
483 |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
484 static PyObject *PySSL_getattr(PySSLObject *self, char *name) |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
485 { |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
486 return Py_FindMethod(PySSLMethods, (PyObject *)self, name); |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
487 } |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
488 |
|
24280
1598a1e473e2
staticforward bites the dust.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24086
diff
changeset
|
489 static PyTypeObject 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
|
490 PyObject_HEAD_INIT(NULL) |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
491 0, /*ob_size*/ |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
492 "socket.SSL", /*tp_name*/ |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
493 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
|
494 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
|
495 /* methods */ |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
496 (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
|
497 0, /*tp_print*/ |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
498 (getattrfunc)PySSL_getattr, /*tp_getattr*/ |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
499 0, /*tp_setattr*/ |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
500 0, /*tp_compare*/ |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
501 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
|
502 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
|
503 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
|
504 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
|
505 0, /*tp_hash*/ |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
506 }; |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
507 |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
508 #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
|
509 |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
510 /* 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
|
511 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
|
512 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
|
513 { |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
514 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
|
515 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
|
516 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
|
517 |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
518 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
|
519 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
|
520 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
|
521 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
|
522 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
|
523 } |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
524 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23295
diff
changeset
|
525 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
|
526 "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
|
527 \n\ |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
528 Mix string into the OpenSSL PRNG state. entropy (a float) is a lower\n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23295
diff
changeset
|
529 bound on the entropy contained in string."); |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
530 |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
531 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
|
532 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
|
533 { |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
534 return PyInt_FromLong(RAND_status()); |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
535 } |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
536 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23295
diff
changeset
|
537 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
|
538 "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
|
539 \n\ |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
540 Returns 1 if the OpenSSL PRNG has been seeded with enough data and 0 if not.\n\ |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
541 It is necessary to seed the PRNG with RAND_add() on some platforms before\n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23295
diff
changeset
|
542 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
|
543 |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
544 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
|
545 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
|
546 { |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
547 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
|
548 |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
549 if (!PyString_Check(arg)) |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
550 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
|
551 "RAND_egd() expected string, found %s", |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
552 arg->ob_type->tp_name); |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
553 bytes = RAND_egd(PyString_AS_STRING(arg)); |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
554 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
|
555 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
|
556 "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
|
557 "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
|
558 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
|
559 } |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
560 return PyInt_FromLong(bytes); |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
561 } |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
562 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23295
diff
changeset
|
563 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
|
564 "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
|
565 \n\ |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
566 Queries the entropy gather daemon (EGD) on socket path. Returns number\n\ |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
567 of bytes read. Raises socket.sslerror if connection to EGD fails or\n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23295
diff
changeset
|
568 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
|
569 |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
570 #endif |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
571 |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
572 /* 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
|
573 |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
574 static PyMethodDef PySSL_methods[] = { |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
575 {"ssl", PySocket_ssl, |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
576 METH_VARARGS, ssl_doc}, |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
577 #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
|
578 {"RAND_add", PySSL_RAND_add, METH_VARARGS, |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
579 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
|
580 {"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
|
581 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
|
582 {"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
|
583 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
|
584 #endif |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
585 {NULL, NULL} /* Sentinel */ |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
586 }; |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
587 |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
588 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23295
diff
changeset
|
589 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
|
590 "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
|
591 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
|
592 |
|
24471
f66b3a3509c7
Excise DL_EXPORT/DL_IMPORT from Modules/*. Required adding a prototype
Mark Hammond <mhammond@skippinet.com.au>
parents:
24398
diff
changeset
|
593 PyMODINIT_FUNC |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
594 init_ssl(void) |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
595 { |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
596 PyObject *m, *d; |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
597 |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
598 PySSL_Type.ob_type = &PyType_Type; |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
599 |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
600 m = Py_InitModule3("_ssl", PySSL_methods, module_doc); |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
601 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
|
602 |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
603 /* Load _socket module and its C API */ |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
604 if (PySocketModule_ImportModuleAndAPI()) |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
605 return; |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
606 |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
607 /* 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
|
608 SSL_load_error_strings(); |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
609 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
|
610 |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
611 /* Add symbols to module dict */ |
|
31790
29da8bdfeb4e
Make socket.sslerror a subclass of socket.error .
Brett Cannon <bcannon@gmail.com>
parents:
30795
diff
changeset
|
612 PySSLErrorObject = PyErr_NewException("socket.sslerror", |
|
29da8bdfeb4e
Make socket.sslerror a subclass of socket.error .
Brett Cannon <bcannon@gmail.com>
parents:
30795
diff
changeset
|
613 PySocketModule.error, |
|
29da8bdfeb4e
Make socket.sslerror a subclass of socket.error .
Brett Cannon <bcannon@gmail.com>
parents:
30795
diff
changeset
|
614 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
|
615 if (PySSLErrorObject == NULL) |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
616 return; |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
617 PyDict_SetItemString(d, "sslerror", PySSLErrorObject); |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
618 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
|
619 (PyObject *)&PySSL_Type) != 0) |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
620 return; |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
621 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
|
622 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
|
623 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
|
624 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
|
625 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
|
626 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
|
627 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
|
628 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
|
629 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
|
630 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
|
631 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
|
632 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
|
633 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
|
634 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
|
635 /* 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
|
636 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
|
637 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
|
638 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
|
639 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
|
640 |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
641 } |
