Skip to content

Commit

Permalink
Add: support authenticated connection to MQTT broker (#958)
Browse files Browse the repository at this point in the history
If ospd-openvas options `--mqtt-broker-user` and `--mqtt-broker-password are
given (or configured in the ospd.conf configuration file), the connection
will be authenticated.
For this to work, MQTT broker must be configured with valid user and pass.
This is disable per default

SC-917
  • Loading branch information
jjnicola authored Jan 25, 2024
1 parent f3a6eb4 commit caf4329
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
19 changes: 19 additions & 0 deletions ospd/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,25 @@ def __init__(self, description: str) -> None:
'Default %(default)s'
),
)
parser.add_argument(
'--mqtt-broker-username',
default=None,
type=str,
help=(
'Username to connect to MQTT broker for MQTT communication.'
'Default %(default)s'
),
)
parser.add_argument(
'--mqtt-broker-password',
default=None,
type=str,
help=(
'PASSWORD to connect to MQTT broker for MQTT communication.'
'Default %(default)s'
),
)

parser.add_argument(
'--feed-updater',
default="openvas",
Expand Down
7 changes: 7 additions & 0 deletions ospd_openvas/daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,8 @@ def __init__(

self._mqtt_broker_address = mqtt_broker_address
self._mqtt_broker_port = mqtt_broker_port
self._mqtt_broker_username = kwargs.get('mqtt_broker_username')
self._mqtt_broker_password = kwargs.get('mqtt_broker_password')

def init(self, server: BaseServer) -> None:
notus_handler = NotusResultHandler(self.report_results)
Expand All @@ -501,6 +503,11 @@ def init(self, server: BaseServer) -> None:
client = MQTTClient(
self._mqtt_broker_address, self._mqtt_broker_port, "ospd"
)
if self._mqtt_broker_username and self._mqtt_broker_password:
client.username_pw_set(
self._mqtt_broker_username, self._mqtt_broker_password
)

daemon = MQTTDaemon(client)
subscriber = MQTTSubscriber(client)

Expand Down

0 comments on commit caf4329

Please sign in to comment.