summaryrefslogtreecommitdiff
path: root/Lib/asyncio/sslproto.py
diff options
context:
space:
mode:
authorNeil Aspinall <mail@neilaspinall.co.uk>2017-12-19 19:45:42 +0000
committerAndrew Svetlov <andrew.svetlov@gmail.com>2017-12-19 21:45:42 +0200
commitf7686c1f5553b24e3307506a18e18f6544de94d3 (patch)
treeeb732724e966a23a7837e824d39a2f7181183798 /Lib/asyncio/sslproto.py
parent4b965930e8625f77cb0e821daf5cc40e85b45f84 (diff)
downloadcpython-git-f7686c1f5553b24e3307506a18e18f6544de94d3.tar.gz
bpo-29970: Add timeout for SSL handshake in asyncio
10 seconds by default.
Diffstat (limited to 'Lib/asyncio/sslproto.py')
-rw-r--r--Lib/asyncio/sslproto.py14
1 files changed, 13 insertions, 1 deletions
diff --git a/Lib/asyncio/sslproto.py b/Lib/asyncio/sslproto.py
index 8da8570d66..8bcc6cc043 100644
--- a/Lib/asyncio/sslproto.py
+++ b/Lib/asyncio/sslproto.py
@@ -6,6 +6,7 @@ except ImportError: # pragma: no cover
ssl = None
from . import base_events
+from . import constants
from . import protocols
from . import transports
from .log import logger
@@ -400,7 +401,8 @@ class SSLProtocol(protocols.Protocol):
def __init__(self, loop, app_protocol, sslcontext, waiter,
server_side=False, server_hostname=None,
- call_connection_made=True):
+ call_connection_made=True,
+ ssl_handshake_timeout=constants.SSL_HANDSHAKE_TIMEOUT):
if ssl is None:
raise RuntimeError('stdlib ssl module not available')
@@ -434,6 +436,7 @@ class SSLProtocol(protocols.Protocol):
# transport, ex: SelectorSocketTransport
self._transport = None
self._call_connection_made = call_connection_made
+ self._ssl_handshake_timeout = ssl_handshake_timeout
def _wakeup_waiter(self, exc=None):
if self._waiter is None:
@@ -561,9 +564,18 @@ class SSLProtocol(protocols.Protocol):
# the SSL handshake
self._write_backlog.append((b'', 1))
self._loop.call_soon(self._process_write_backlog)
+ self._handshake_timeout_handle = \
+ self._loop.call_later(self._ssl_handshake_timeout,
+ self._check_handshake_timeout)
+
+ def _check_handshake_timeout(self):
+ if self._in_handshake is True:
+ logger.warning("%r stalled during handshake", self)
+ self._abort()
def _on_handshake_complete(self, handshake_exc):
self._in_handshake = False
+ self._handshake_timeout_handle.cancel()
sslobj = self._sslpipe.ssl_object
try: