I am trying to subscribe to a specific topic in MQTT broker which use TLS with no validation. But I failed because of certification failed to validation
my flutter code
<code>client = MqttServerClient.withPort(broker, clientId, port);
final context = SecurityContext(withTrustedRoots: false);
client!.secure = false;
client!.securityContext = context;
client!.logging(on: true);
</code>
<code>client = MqttServerClient.withPort(broker, clientId, port);
final context = SecurityContext(withTrustedRoots: false);
client!.secure = false;
client!.securityContext = context;
client!.logging(on: true);
</code>
client = MqttServerClient.withPort(broker, clientId, port);
final context = SecurityContext(withTrustedRoots: false);
client!.secure = false;
client!.securityContext = context;
client!.logging(on: true);
On the other hand, I have already achieved to connect to this broker with this Python script
<code>client = mqtt.Client(client_id=client_id)
client.username_pw_set(username, password)
def on_connect(client, userdata, flags, rc):
print(f"Connected with result code {rc}")
client.subscribe(topic)
def on_message(client, userdata, msg):
print(f"Received message '{msg.payload.decode()}' on topic '{msg.topic}'")
client.on_connect = on_connect
client.on_message = on_message
client.tls_set(cert_reqs=ssl.CERT_NONE, tls_version=ssl.PROTOCOL_TLS)
client.connect(broker, port)
client.loop_forever()
</code>
<code>client = mqtt.Client(client_id=client_id)
client.username_pw_set(username, password)
def on_connect(client, userdata, flags, rc):
print(f"Connected with result code {rc}")
client.subscribe(topic)
def on_message(client, userdata, msg):
print(f"Received message '{msg.payload.decode()}' on topic '{msg.topic}'")
client.on_connect = on_connect
client.on_message = on_message
client.tls_set(cert_reqs=ssl.CERT_NONE, tls_version=ssl.PROTOCOL_TLS)
client.connect(broker, port)
client.loop_forever()
</code>
client = mqtt.Client(client_id=client_id)
client.username_pw_set(username, password)
def on_connect(client, userdata, flags, rc):
print(f"Connected with result code {rc}")
client.subscribe(topic)
def on_message(client, userdata, msg):
print(f"Received message '{msg.payload.decode()}' on topic '{msg.topic}'")
client.on_connect = on_connect
client.on_message = on_message
client.tls_set(cert_reqs=ssl.CERT_NONE, tls_version=ssl.PROTOCOL_TLS)
client.connect(broker, port)
client.loop_forever()
I also try to use the defaultContext
<code>final context = SecurityContext.defaultContext;
client!.secure = false;
client!.securityContext = context;
</code>
<code>final context = SecurityContext.defaultContext;
client!.secure = false;
client!.securityContext = context;
</code>
final context = SecurityContext.defaultContext;
client!.secure = false;
client!.securityContext = context;
And the result was,
<code>I/flutter (16544): 1-2024-07-23 07:31:10.430226 -- SynchronousMqttServerConnectionHandler::internalConnect failed, attempt 3
I/flutter (16544): 1-2024-07-23 07:31:10.430684 -- SynchronousMqttServerConnectionHandler::internalConnect failed
I/flutter (16544): MQTT::NoConnectionException - mqtt-client::NoConnectionException: The maximum allowed connection attempts ({3}) were exceeded. The broker is not responding to the connection request message (Missing Connection Acknowledgement?
I/flutter (16544): 1-2024-07-23 07:31:10.438501 -- MqttConnectionHandlerBase::disconnect - entered
I/flutter (16544): 1-2024-07-23 07:31:10.439620 -- MqttConnectionHandlerBase::_performConnectionDisconnect entered
I/flutter (16544): MQTT::Disconnected
</code>
<code>I/flutter (16544): 1-2024-07-23 07:31:10.430226 -- SynchronousMqttServerConnectionHandler::internalConnect failed, attempt 3
I/flutter (16544): 1-2024-07-23 07:31:10.430684 -- SynchronousMqttServerConnectionHandler::internalConnect failed
I/flutter (16544): MQTT::NoConnectionException - mqtt-client::NoConnectionException: The maximum allowed connection attempts ({3}) were exceeded. The broker is not responding to the connection request message (Missing Connection Acknowledgement?
I/flutter (16544): 1-2024-07-23 07:31:10.438501 -- MqttConnectionHandlerBase::disconnect - entered
I/flutter (16544): 1-2024-07-23 07:31:10.439620 -- MqttConnectionHandlerBase::_performConnectionDisconnect entered
I/flutter (16544): MQTT::Disconnected
</code>
I/flutter (16544): 1-2024-07-23 07:31:10.430226 -- SynchronousMqttServerConnectionHandler::internalConnect failed, attempt 3
I/flutter (16544): 1-2024-07-23 07:31:10.430684 -- SynchronousMqttServerConnectionHandler::internalConnect failed
I/flutter (16544): MQTT::NoConnectionException - mqtt-client::NoConnectionException: The maximum allowed connection attempts ({3}) were exceeded. The broker is not responding to the connection request message (Missing Connection Acknowledgement?
I/flutter (16544): 1-2024-07-23 07:31:10.438501 -- MqttConnectionHandlerBase::disconnect - entered
I/flutter (16544): 1-2024-07-23 07:31:10.439620 -- MqttConnectionHandlerBase::_performConnectionDisconnect entered
I/flutter (16544): MQTT::Disconnected
Any idea how to solve this problem?
Thanks