Skip to content

Commit ab0cd00

Browse files
Paweł SzulikStephenSorriaux
authored andcommitted
feat(utils): extend create_tcp_connection utility (#568)
Add parameters to setup SSL context options and ciphers when playing with secure connection. It can be set via a handler: ``` class MySequentialThreadingHandler(SequentialThreadingHandler): def create_connection(self, *args, **kwargs): return create_tcp_connection(socket, options=MY_OPTIONS, ciphers=MY_CIPHERS, *args, **kwargs) ```
1 parent 88b657a commit ab0cd00

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

kazoo/handlers/utils.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ def create_tcp_socket(module):
191191
def create_tcp_connection(module, address, timeout=None,
192192
use_ssl=False, ca=None, certfile=None,
193193
keyfile=None, keyfile_password=None,
194-
verify_certs=True):
194+
verify_certs=True, options=None, ciphers=None):
195195
end = None
196196
if timeout is None:
197197
# thanks to create_connection() developers for
@@ -211,8 +211,16 @@ def create_tcp_connection(module, address, timeout=None,
211211
if use_ssl:
212212
# Disallow use of SSLv2 and V3 (meaning we require TLSv1.0+)
213213
context = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
214-
context.options |= ssl.OP_NO_SSLv2
215-
context.options |= ssl.OP_NO_SSLv3
214+
215+
if options is not None:
216+
context.options = options
217+
else:
218+
context.options |= ssl.OP_NO_SSLv2
219+
context.options |= ssl.OP_NO_SSLv3
220+
221+
if ciphers:
222+
context.set_ciphers(ciphers)
223+
216224
# Load default CA certs
217225
context.load_default_certs(ssl.Purpose.SERVER_AUTH)
218226
context.verify_mode = (

0 commit comments

Comments
 (0)