Skip to content

Commit 875c57a

Browse files
committed
Add disabling tls mqtt for local dev
1 parent 55a32a4 commit 875c57a

2 files changed

Lines changed: 17 additions & 9 deletions

File tree

api/MQTT/MqttService.cs

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,25 @@ IManagedMqttClient mqttClient
5050
_maxRetryAttempts = mqttConfig.GetValue<int>("MaxRetryAttempts");
5151
_shouldFailOnMaxRetries = mqttConfig.GetValue<bool>("ShouldFailOnMaxRetries");
5252

53-
var tlsOptions = new MqttClientTlsOptions
54-
{
55-
UseTls = true,
56-
/* Currently disabled to use self-signed certificate in the internal broker communication */
57-
//if (_notProduction)
58-
IgnoreCertificateChainErrors = true,
59-
};
53+
bool allowInsecure = mqttConfig.GetValue<bool>("AllowInsecureLocalConnections");
54+
6055
var builder = new MqttClientOptionsBuilder()
6156
.WithTcpServer(_serverHost, _serverPort)
62-
.WithTlsOptions(tlsOptions)
6357
.WithCredentials(username, password);
6458

59+
if (allowInsecure)
60+
{
61+
_logger.LogWarning(
62+
"MQTT TLS disabled — insecure connections allowed. Do NOT use in production."
63+
);
64+
}
65+
else
66+
{
67+
builder.WithTlsOptions(
68+
new MqttClientTlsOptions { UseTls = true, IgnoreCertificateChainErrors = true }
69+
);
70+
}
71+
6572
_options = new ManagedMqttClientOptionsBuilder()
6673
.WithAutoReconnectDelay(_reconnectDelay)
6774
.WithClientOptions(builder.Build())

api/appsettings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@
4141
"isar/+/inspection_value"
4242
],
4343
"MaxRetryAttempts": 5,
44-
"ShouldFailOnMaxRetries": false
44+
"ShouldFailOnMaxRetries": false,
45+
"AllowInsecureLocalConnections": false
4546
},
4647
"Analysis": {
4748
"Analyses": {

0 commit comments

Comments
 (0)