38
38
sslProtocolCiphers = "AECDH-AES256-SHA"
39
39
40
40
41
- class TLSDispatcher (AdvancedDispatcher ):
41
+ class TLSDispatcher (AdvancedDispatcher ): # pylint: disable=too-many-instance-attributes
42
+ """TLS functionality for classes derived from AdvancedDispatcher"""
43
+ # pylint: disable=too-many-arguments, super-init-not-called, unused-argument
42
44
def __init__ (
43
- self , address = None , sock = None , certfile = None , keyfile = None ,
44
- server_side = False , ciphers = sslProtocolCiphers
45
+ self , address = None , sock = None , certfile = None , keyfile = None ,
46
+ server_side = False , ciphers = sslProtocolCiphers
45
47
):
46
48
self .want_read = self .want_write = True
47
49
if certfile is None :
@@ -60,6 +62,11 @@ def __init__(
60
62
self .isSSL = False
61
63
62
64
def state_tls_init (self ):
65
+ """
66
+ Prepare sockets for TLS handshake
67
+ .. todo:: standardize which curves are used.
68
+ """
69
+ # pylint: disable=attribute-defined-outside-init
63
70
self .isSSL = True
64
71
self .tlsStarted = True
65
72
# Once the connection has been established, it's safe to wrap the
@@ -89,10 +96,13 @@ def state_tls_init(self):
89
96
# if hasattr(self.socket, "context"):
90
97
# self.socket.context.set_ecdh_curve("secp256k1")
91
98
92
- def state_tls_handshake (self ):
99
+ @staticmethod
100
+ def state_tls_handshake ():
101
+ """Do nothing while TLS handshake is pending, as during this phase we need to react to callbacks instead"""
93
102
return False
94
103
95
104
def writable (self ):
105
+ """Handle writable checks for TLS-enabled sockets"""
96
106
try :
97
107
if self .tlsStarted and not self .tlsDone and not self .write_buf :
98
108
return self .want_write
@@ -101,6 +111,7 @@ def writable(self):
101
111
return AdvancedDispatcher .writable (self )
102
112
103
113
def readable (self ):
114
+ """Handle readable check for TLS-enabled sockets"""
104
115
try :
105
116
# during TLS handshake, and after flushing write buffer, return status of last handshake attempt
106
117
if self .tlsStarted and not self .tlsDone and not self .write_buf :
@@ -113,7 +124,11 @@ def readable(self):
113
124
except AttributeError :
114
125
return AdvancedDispatcher .readable (self )
115
126
116
- def handle_read (self ):
127
+ def handle_read (self ): # pylint: disable=inconsistent-return-statements
128
+ """
129
+ Handle reads for sockets during TLS handshake. Requires special treatment as during the handshake, buffers must
130
+ remain empty and normal reads must be ignored
131
+ """
117
132
try :
118
133
# wait for write buffer flush
119
134
if self .tlsStarted and not self .tlsDone and not self .write_buf :
@@ -134,7 +149,11 @@ def handle_read(self):
134
149
self .handle_close ()
135
150
return
136
151
137
- def handle_write (self ):
152
+ def handle_write (self ): # pylint: disable=inconsistent-return-statements
153
+ """
154
+ Handle writes for sockets during TLS handshake. Requires special treatment as during the handshake, buffers
155
+ must remain empty and normal writes must be ignored
156
+ """
138
157
try :
139
158
# wait for write buffer flush
140
159
if self .tlsStarted and not self .tlsDone and not self .write_buf :
@@ -156,6 +175,7 @@ def handle_write(self):
156
175
return
157
176
158
177
def tls_handshake (self ):
178
+ """Perform TLS handshake and handle its stages"""
159
179
# wait for flush
160
180
if self .write_buf :
161
181
return False
@@ -175,7 +195,7 @@ def tls_handshake(self):
175
195
if not (self .want_write or self .want_read ):
176
196
raise
177
197
except socket .error as err :
178
- if err .errno in asyncore ._DISCONNECTED :
198
+ if err .errno in asyncore ._DISCONNECTED : # pylint: disable=protected-access
179
199
self .handle_close ()
180
200
else :
181
201
raise
0 commit comments