Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 09c35f7

Browse files
committed
Patch #575827: allow threads inside SSL creation.
1 parent 6c611fa commit 09c35f7

1 file changed

Lines changed: 19 additions & 4 deletions

File tree

Modules/_ssl.c

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -186,47 +186,62 @@ newPySSLObject(PySocketSockObject *Sock, char *key_file, char *cert_file)
186186
goto fail;
187187
}
188188

189+
Py_BEGIN_ALLOW_THREADS
189190
self->ctx = SSL_CTX_new(SSLv23_method()); /* Set up context */
191+
Py_END_ALLOW_THREADS
190192
if (self->ctx == NULL) {
191193
errstr = "SSL_CTX_new error";
192194
goto fail;
193195
}
194196

195197
if (key_file) {
196-
if (SSL_CTX_use_PrivateKey_file(self->ctx, key_file,
197-
SSL_FILETYPE_PEM) < 1) {
198+
Py_BEGIN_ALLOW_THREADS
199+
ret = SSL_CTX_use_PrivateKey_file(self->ctx, key_file,
200+
SSL_FILETYPE_PEM);
201+
Py_END_ALLOW_THREADS
202+
if (ret < 1) {
198203
errstr = "SSL_CTX_use_PrivateKey_file error";
199204
goto fail;
200205
}
201206

202-
if (SSL_CTX_use_certificate_chain_file(self->ctx,
203-
cert_file) < 1) {
207+
Py_BEGIN_ALLOW_THREADS
208+
ret = SSL_CTX_use_certificate_chain_file(self->ctx,
209+
cert_file);
210+
Py_END_ALLOW_THREADS
211+
if (ret < 1) {
204212
errstr = "SSL_CTX_use_certificate_chain_file error";
205213
goto fail;
206214
}
207215
}
208216

217+
Py_BEGIN_ALLOW_THREADS
209218
SSL_CTX_set_verify(self->ctx,
210219
SSL_VERIFY_NONE, NULL); /* set verify lvl */
211220
self->ssl = SSL_new(self->ctx); /* New ssl struct */
221+
Py_END_ALLOW_THREADS
212222
SSL_set_fd(self->ssl, Sock->sock_fd); /* Set the socket for SSL */
223+
Py_BEGIN_ALLOW_THREADS
213224
SSL_set_connect_state(self->ssl);
214225

226+
215227
/* Actually negotiate SSL connection */
216228
/* XXX If SSL_connect() returns 0, it's also a failure. */
217229
ret = SSL_connect(self->ssl);
230+
Py_END_ALLOW_THREADS
218231
if (ret <= 0) {
219232
PySSL_SetError(self, ret);
220233
goto fail;
221234
}
222235
self->ssl->debug = 1;
223236

237+
Py_BEGIN_ALLOW_THREADS
224238
if ((self->server_cert = SSL_get_peer_certificate(self->ssl))) {
225239
X509_NAME_oneline(X509_get_subject_name(self->server_cert),
226240
self->server, X509_NAME_MAXLEN);
227241
X509_NAME_oneline(X509_get_issuer_name(self->server_cert),
228242
self->issuer, X509_NAME_MAXLEN);
229243
}
244+
Py_END_ALLOW_THREADS
230245
self->Socket = Sock;
231246
Py_INCREF(self->Socket);
232247
return self;

0 commit comments

Comments
 (0)