Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TLS no validation #553

Open
spartakos87 opened this issue Jul 22, 2024 · 2 comments
Open

TLS no validation #553

spartakos87 opened this issue Jul 22, 2024 · 2 comments

Comments

@spartakos87
Copy link

spartakos87 commented Jul 22, 2024

Hello, 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

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 achieve to connect to this broker with this Python script


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()

Any idea how to solve this problem?
Thanks

@spartakos87
Copy link
Author

spartakos87 commented Jul 23, 2024

I also try to use the defaultContext

final context = SecurityContext.defaultContext;
    client!.secure = false;
    client!.securityContext = context;

And the result was,

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

@shamblett
Copy link
Owner

If you are using secure sockets the 'secure' flag needs to be set to true, as per the API docs, you are setting it to false -

client!.secure = false;

This won't work, set it to true.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants