Skip to content

Commit

Permalink
[patch] add caFile: '_os_' as a way to use OS/python truststore (#214)
Browse files Browse the repository at this point in the history
Co-authored-by: Jon Levell <[email protected]>
  • Loading branch information
jonquark and Jon Levell authored Oct 14, 2024
1 parent 592368c commit 3d60611
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion docs/application/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Application configuration can be broken down into required and optional configur
- `options.mqtt.cleanStart` A boolean value indicating whether to discard any previous state when reconnecting to the service. Defaults to `False`.
- `options.mqtt.sessionExpiry` When cleanStart is disabled, defines the maximum age of the previous session (in seconds). Defaults to `False`.
- `options.mqtt.keepAlive` Control the frequency of MQTT keep alive packets (in seconds). Details to `60`.
- `options.mqtt.caFile` A String value indicating the path to a CA file (in pem format) to use in verifying the server certificate. Defaults to `messaging.pem` inside this module.
- `options.mqtt.caFile` A String value indicating the path to a CA file (in pem format) to use in verifying the server certificate. Defaults to `messaging.pem` inside this module. Use the special string `"_os_"` to use default python/OS truststore.


The config parameter when constructing an instance of `wiotp.sdk.application.ApplicationClient` expects to be passed a dictionary containing this configuration:
Expand Down
2 changes: 1 addition & 1 deletion docs/device/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Device configuration can be broken down into required and optional configuration
- `options.mqtt.cleanStart` A boolean value indicating whether to discard any previous state when reconnecting to the service. Defaults to `False`.
- `options.mqtt.sessionExpiry` When cleanStart is disabled, defines the maximum age of the previous session (in seconds). Defaults to `False`.
- `options.mqtt.keepAlive` Control the frequency of MQTT keep alive packets (in seconds). Details to `60`.
- `options.mqtt.caFile` A String value indicating the path to a CA file (in pem format) to use in verifying the server certificate. Defaults to `messaging.pem` inside this module.
- `options.mqtt.caFile` A String value indicating the path to a CA file (in pem format) to use in verifying the server certificate. Defaults to `messaging.pem` inside this module. Use the special string `"_os_"` to use default python/OS truststore.


The config parameter when constructing an instance of `wiotp.sdk.device.DeviceClient` expects to be passed a dictionary containing this configuration:
Expand Down
2 changes: 1 addition & 1 deletion docs/gateway/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Gateway configuration can be broken down into required and optional configuratio
- `options.mqtt.cleanStart` A boolean value indicating whether to discard any previous state when reconnecting to the service. Defaults to `False`.
- `options.mqtt.sessionExpiry` When cleanStart is disabled, defines the maximum age of the previous session (in seconds). Defaults to `False`.
- `options.mqtt.keepAlive` Control the frequency of MQTT keep alive packets (in seconds). Details to `60`.
- `options.mqtt.caFile` A String value indicating the path to a CA file (in pem format) to use in verifying the server certificate. Defaults to `messaging.pem` inside this module.
- `options.mqtt.caFile` A String value indicating the path to a CA file (in pem format) to use in verifying the server certificate. Defaults to `messaging.pem` inside this module. Use the special string `"_os_"` to use default python/OS truststore.


The config parameter when constructing an instance of `wiotp.sdk.gateway.GatewayClient` expects to be passed a dictionary containing this configuration:
Expand Down
3 changes: 3 additions & 0 deletions src/wiotp/sdk/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,9 @@ def __init__(
# Path to default CA certificate if none provided
if caFile is None:
caFile = os.path.dirname(os.path.abspath(__file__)) + "/messaging.pem"
elif caFile == "_os_":
self.logger.debug("Using OS trust store for certification verification")
caFile=None

self.client.tls_set(
ca_certs=caFile,
Expand Down

0 comments on commit 3d60611

Please sign in to comment.