Skip to content

Commit 7928494

Browse files
committed
validate TlsCipherPref
1 parent 8016d9d commit 7928494

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

awsiot/mqtt5_client_builder.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,8 @@ def _builder(
248248
cipher_pref=awscrt.io.TlsCipherPref.DEFAULT,
249249
**kwargs):
250250

251+
assert isinstance(cipher_pref, awscrt.io.TlsCipherPref)
252+
251253
username = _get(kwargs, 'username', '')
252254
if _get(kwargs, 'enable_metrics_collection', True):
253255
username += _get_metrics_str(username)
@@ -348,8 +350,7 @@ def _builder(
348350
elif ca_filepath or ca_dirpath:
349351
tls_ctx_options.override_default_trust_store_from_path(ca_dirpath, ca_filepath)
350352

351-
if cipher_pref is not None:
352-
tls_ctx_options.cipher_pref = cipher_pref
353+
tls_ctx_options.cipher_pref = cipher_pref
353354

354355
if client_options.port is None:
355356
# prefer 443, even for direct MQTT connections, since it's less likely to be blocked by firewalls

awsiot/mqtt_connection_builder.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,8 @@ def _builder(
186186
cipher_pref=awscrt.io.TlsCipherPref.DEFAULT,
187187
**kwargs):
188188

189+
assert isinstance(cipher_pref, awscrt.io.TlsCipherPref)
190+
189191
ca_bytes = _get(kwargs, 'ca_bytes')
190192
ca_filepath = _get(kwargs, 'ca_filepath')
191193
ca_dirpath = _get(kwargs, 'ca_dirpath')
@@ -205,8 +207,7 @@ def _builder(
205207
if port == 443 and awscrt.io.is_alpn_available() and use_custom_authorizer is False:
206208
tls_ctx_options.alpn_list = ['http/1.1'] if use_websockets else ['x-amzn-mqtt-ca']
207209

208-
if cipher_pref != awscrt.io.TlsCipherPref.DEFAULT:
209-
tls_ctx_options.cipher_pref = cipher_pref
210+
tls_ctx_options.cipher_pref = cipher_pref
210211

211212
socket_options = awscrt.io.SocketOptions()
212213
socket_options.connect_timeout_ms = _get(kwargs, 'tcp_connect_timeout_ms', 5000)

0 commit comments

Comments
 (0)