Skip to content

Commit dd50016

Browse files
committed
added fixes for certificate handling
1 parent 1c0cec7 commit dd50016

File tree

4 files changed

+39
-28
lines changed

4 files changed

+39
-28
lines changed

Diff for: CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,7 @@ Fixed certificate path handling when calling wwt.eda.mqtt from EDA server
1515
## v1.0.4
1616

1717
Added additional logging to wwt.eda.mqtt plugin.
18+
19+
## v1.0.5
20+
21+
Fixed certificate handling with wwt.eda.mqtt to account for EDA server file limitations.

Diff for: README.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,10 @@ A sample rulebook using *wwt.eda.mqtt* plugin is shown below:
3939
port: 8883
4040
username: <username>
4141
password: <password>
42-
cert_path: <cert directory name>
43-
ca_certs: <cert-filename>
42+
ca_certs: |-
43+
-----BEGIN CERTIFICATE-----
44+
<cert contents>
45+
-----END CERTIFICATE-----
4446
validate_certs: false
4547
topic: meraki/v1/mt/#
4648
filters:

Diff for: extensions/eda/plugins/event_source/mqtt.py

+30-25
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,13 @@
66
port: The port where the mqtt server is listening
77
username: The username to connect to the broker
88
password: The password to connect to the broker
9-
cert_path: The directory containing certificate files.
10-
Can be in root of repo or under rulebooks.
11-
ca_certs: The filename of optional certificate authority file containing
9+
ca_certs: Multi-line string containing
1210
certificate used to sign mqtt broker certificates
1311
validate_certs: Disable certificate validation - true/false
14-
certfile: The optional client certificate file name containing
12+
certfile: The optional multi-line string containing
1513
the client certificate, as well as CA certificates needed
1614
to establish the certificate's authenticity
17-
keyfile: The optional client key file name containing the client
15+
keyfile: Multi-line string containing the client
1816
private key
1917
keyfile_password: The optional password to be used when loading the
2018
certificate chain
@@ -25,12 +23,24 @@
2523
import asyncio
2624
import json
2725
import logging
28-
import os
2926
from typing import Any, Dict
3027

3128
import aiomqtt
3229

3330

31+
async def write_certfile(path, content, logger):
32+
"""
33+
Function to write certificate data to a temporary file.
34+
35+
Args:
36+
path (str): Path to temporary file
37+
content (str): Certificate data
38+
logger (object): Logger object
39+
"""
40+
with open(path, "w+", encoding='utf-8') as certfile:
41+
certfile.writelines(content)
42+
logger.info("Cert data written to %s", path)
43+
3444
async def main(queue: asyncio.Queue, args: Dict[str, Any]):
3545
logger = logging.getLogger()
3646

@@ -41,41 +51,36 @@ async def main(queue: asyncio.Queue, args: Dict[str, Any]):
4151
username = args.get("username")
4252
password = args.get("password")
4353

44-
cert_path = args.get("cert_path")
4554
ca_certs = args.get("ca_certs")
4655
validate_certs = bool(args.get("validate_certs"))
4756
certfile = args.get("certfile")
4857
keyfile = args.get("keyfile")
4958
keyfile_password = args.get("keyfile_password")
5059

5160
# Path management for certificate files
52-
# This solves an issue when using EDA server and finding file paths
53-
path_to_certs = None
61+
# EDA Server does not support file handling with decision environments
62+
# We will accept the cert data as strings and write out temporary files
63+
# to pass when configuring TLS.
64+
path_to_certs = "/tmp"
5465
ca_certs_path = None
5566
certfile_path = None
5667
keyfile_path = None
5768

58-
if cert_path:
59-
# Find the absolute path to the ca_certs filename
60-
for root, dirs, _ in os.walk('./', topdown=True):
61-
for dirname in dirs:
62-
if cert_path in dirname:
63-
path_to_certs = os.path.join(root, dirname)
64-
logger.info("Cert path found at %s", path_to_certs)
65-
break
66-
67-
# Build out cert file absolute paths
69+
# Build out cert file and absolute paths
6870
if ca_certs and path_to_certs:
69-
ca_certs_path = f'{path_to_certs}/{ca_certs}'
70-
logger.info("ca_certs path found at %s", ca_certs_path)
71+
# Write Certificate to file
72+
ca_certs_path = f'{path_to_certs}/ca_certs.crt'
73+
await write_certfile(ca_certs_path, ca_certs, logger)
7174

7275
if certfile and path_to_certs:
73-
certfile_path = f'{path_to_certs}/{certfile}'
74-
logger.info("certfile path found at %s", certfile_path)
76+
# Write Certificate to file
77+
certfile_path = f'{path_to_certs}/certfile.crt'
78+
await write_certfile(certfile_path, certfile, logger)
7579

7680
if keyfile and path_to_certs:
77-
keyfile_path = f'{path_to_certs}/{keyfile}'
78-
logger.info("keyfile path found at %s", keyfile_path)
81+
# Write Certificate to file
82+
keyfile_path = f'{path_to_certs}/keyfile.crt'
83+
await write_certfile(keyfile_path, keyfile, logger)
7984

8085
if ca_certs_path or certfile_path or keyfile_path:
8186
logger.info("Certificates provided, setting tls_params...")

Diff for: galaxy.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
namespace: wwt
33
name: eda
4-
version: 1.0.4
4+
version: 1.0.5
55
readme: README.md
66
authors:
77
- Nick Thompson <[email protected]>

0 commit comments

Comments
 (0)