File tree Expand file tree Collapse file tree 2 files changed +14
-2
lines changed
crates/common/mqtt_channel/src Expand file tree Collapse file tree 2 files changed +14
-2
lines changed Original file line number Diff line number Diff line change @@ -80,6 +80,14 @@ pub struct BrokerConfig {
8080 pub authentication : Option < AuthenticationConfig > ,
8181}
8282
83+ impl BrokerConfig {
84+ pub fn is_using_tls ( & self ) -> bool {
85+ self . authentication
86+ . as_ref ( )
87+ . is_some_and ( |a| a. is_using_tls ( ) )
88+ }
89+ }
90+
8391/// MQTT certificate authentication configuration.
8492///
8593/// Intended to mirror authentication model found in the [mosquitto] MQTT
@@ -143,6 +151,10 @@ impl AuthenticationConfig {
143151 self . password = Some ( password) ;
144152 }
145153
154+ pub fn is_using_tls ( & self ) -> bool {
155+ !self . cert_store . is_empty ( )
156+ }
157+
146158 pub fn to_rustls_client_config ( & self ) -> Result < Option < rustls:: ClientConfig > , rustls:: Error > {
147159 if self . cert_store . is_empty ( ) {
148160 return Ok ( None ) ;
Original file line number Diff line number Diff line change @@ -219,10 +219,10 @@ impl Connection {
219219 const INSECURE_MQTT_PORT : u16 = 1883 ;
220220 const SECURE_MQTT_PORT : u16 = 8883 ;
221221
222- if config. broker . port == INSECURE_MQTT_PORT && config. broker . authentication . is_some ( ) {
222+ if config. broker . port == INSECURE_MQTT_PORT && config. broker . is_using_tls ( ) {
223223 warn ! ( target: "MQTT" , "Connecting on port 1883 for insecure MQTT using a TLS connection" ) ;
224224 }
225- if config. broker . port == SECURE_MQTT_PORT && config. broker . authentication . is_none ( ) {
225+ if config. broker . port == SECURE_MQTT_PORT && ! config. broker . is_using_tls ( ) {
226226 warn ! ( target: "MQTT" , "Connecting on port 8883 for secure MQTT without a CA file" ) ;
227227 }
228228
You can’t perform that action at this time.
0 commit comments