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

NoConnectionException with Authentication example #3

Closed
ffbfh opened this issue Jul 13, 2020 · 15 comments
Closed

NoConnectionException with Authentication example #3

ffbfh opened this issue Jul 13, 2020 · 15 comments

Comments

@ffbfh
Copy link

ffbfh commented Jul 13, 2020

I'm not sure what I doing wrong but when I'm using the example for authentication with my specific Broker, I always get the following exception:

mqtt-client::NoConnectionException:` The maximum allowed connection attempts ({3}) were exceeded. The broker is not responding to the connection request message

As you can see in the log, my Broker replies to the connection message but the Client does nothing with the authentication message. Instead, he tries to connect again, until he reached the maximum attempts.
So the part (client.authentication.listen((final authMessage) { ... }) where I should do the stuff and send back an authentication message, will never reached.

EXAMPLE::Mqtt5 client connecting....
2020-07-13 16:58:22.719785 -- SynchronousMqttServerConnectionHandler::internalConnect entered
2020-07-13 16:58:22.737769 -- SynchronousMqttServerConnectionHandler::internalConnect - initiating connection try 0
2020-07-13 16:58:22.738770 -- SynchronousMqttServerConnectionHandler::internalConnect - insecure TCP selected
2020-07-13 16:58:22.987339 -- MqttServerConnection::_startListening
2020-07-13 16:58:23.001331 -- SynchronousMqttServerConnectionHandler::internalConnect - connection complete
2020-07-13 16:58:23.001331 -- SynchronousMqttServerConnectionHandler::internalConnect sending connect message
2020-07-13 16:58:23.021320 -- MqttConnectionHandlerBase::sendMessage - SENDING MESSAGE -> MQTTMessage of type MqttMessageType.connect
MessageType = MqttMessageType.connect Duplicate = false Retain = false Qos = atMostOnce Size = 0
ProtocolName = MQTT
ProtocolVersion = 5
ConnectFlags = CleanStart=true, WillFlag=false, WillQos=atMostOnce, WillRetain=false, PasswordFlag=false, UserNameFlag=false
KeepAlive = 0
Properties = Identifier : authenticationMethod, value : SMOKER
Identifier MqttPropertyIdentifier.authenticationData, value [97, 52, 101, 48, 97, 55, 51, 55, 98, 97, 57, 52, 52, 98, 49, 100, 101, 56, 99, 56, 54, 56, 97, 100, 51, 101, 49, 48, 50, 101, 49, 55, 51, 54, 55, 53, 99, 53, 52, 50, 57, 97, 97, 57, 50, 49, 56, 49, 53, 56, 97, 52, 57, 51, 50, 52, 50, 102, 100, 48, 50, 56, 52, 53]
Will topic = null
User name = not set
Password = not set

2020-07-13 16:58:23.063296 -- SynchronousMqttServerConnectionHandler::internalConnect - pre sleep, state = Connection status is connecting with return code of notSet and a disconnection origin of none
2020-07-13 16:58:23.076311 -- MqttServerConnection::_onData
2020-07-13 16:58:23.076311 -- MqttServerConnection::_ondata - adding incoming data, data length is 48, message stream length is 0, message stream position is 0
2020-07-13 16:58:23.116266 -- MqttServerConnection::_onData - MESSAGE RECEIVED -> MQTTMessage of type MqttMessageType.auth
MessageType = MqttMessageType.auth Duplicate = false Retain = false Qos = atMostOnce Size = 46

Reason Code  = continueAuthentication
Properties = Identifier : authenticationMethod, value : SMOKER
Identifier MqttPropertyIdentifier.authenticationData, value [36, 147, 111, 51, 59, 190, 190, 215, 60, 205, 131, 231, 229, 73, 70, 78, 174, 96, 40, 162, 180, 138, 222, 108, 70, 183, 193, 245, 31, 211, 221, 246]


2020-07-13 16:58:23.134256 -- MqttServerConnection::_onData - message processed
2020-07-13 16:58:23.139252 -- MqttAuthenticationManager::handleAuthentication - Authentication message received
2020-07-13 16:58:28.084758 -- SynchronousMqttServerConnectionHandler::internalConnect - post sleep, state = Connection status is connecting with return code of notSet and a disconnection origin of none
2020-07-13 16:58:28.085734 -- SynchronousMqttServerConnectionHandler::internalConnect - initiating connection try 1
2020-07-13 16:58:28.085734 -- SynchronousMqttServerConnectionHandler::internalConnect - insecure TCP selected
2020-07-13 16:58:28.095972 -- MqttServerConnection::_startListening
2020-07-13 16:58:28.096937 -- SynchronousMqttServerConnectionHandler::internalConnect - connection complete
2020-07-13 16:58:28.096937 -- SynchronousMqttServerConnectionHandler::internalConnect sending connect message
2020-07-13 16:58:28.097936 -- MqttConnectionHandlerBase::sendMessage - SENDING MESSAGE -> MQTTMessage of type MqttMessageType.connect

...

2020-07-13 16:58:33.411130 -- MqttServerConnection::_onData - message processed
2020-07-13 16:58:33.411130 -- MqttAuthenticationManager::handleAuthentication - Authentication message received
2020-07-13 16:58:38.417570 -- SynchronousMqttServerConnectionHandler::internalConnect - post sleep, state = Connection status is connecting with return code of notSet and a disconnection origin of none
2020-07-13 16:58:38.418475 -- SynchronousMqttServerConnectionHandler::internalConnect failed
EXAMPLE::client exception - mqtt-client::NoConnectionException: The maximum allowed connection attempts ({3}) were exceeded. The broker is not responding to the connection request message (Missing Connection Acknowledgement?
2020-07-13 16:58:38.430500 -- SynchronousMqttServerConnectionHandler::disconnect
EXAMPLE::OnDisconnected client callback - Client disconnection
EXAMPLE::OnDisconnected callback is solicited, this is correct

Did I forget something?

@shamblett
Copy link
Owner

Are you listening for the incoming auth message on the authenticated message stream?

/// post connecting.
  client.authentication.listen((final authMessage) {
    print('EXAMPLE:: Authentication Message received - $authMessage');

You need to send your reply here or the broker will not send a connect ack, hence the client will keep trying to connect.

@ffbfh
Copy link
Author

ffbfh commented Jul 13, 2020

yes. But in my case this code will never be reached as you can see in the full output log below.

My authenticate message stream:

  client.authentication.listen((final authMessage) {
    print('EXAMPLE:: Authentication Message received - $authMessage');

    /// Authentication message received, do what you need to do here, we simply tell the broker the sequence has ended.
    authMessage.withReasonCode(MqttAuthenticateReasonCode.continueAuthentication);
    authMessage.withAuthenticationMethod('SMOKER');
    authMessage.withAuthenticationData(Uint8Buffer()..addAll([1, 2, 3, 4]));
    client.sendAuthenticate(authMessage);
  });

(this AuthenticationData is just an example, But the Broker would respond to this)
and the full log:

EXAMPLE::Mqtt5 client connecting....
2020-07-13 22:18:54.451261 -- SynchronousMqttServerConnectionHandler::internalConnect entered
2020-07-13 22:18:54.464263 -- SynchronousMqttServerConnectionHandler::internalConnect - initiating connection try 0
2020-07-13 22:18:54.464263 -- SynchronousMqttServerConnectionHandler::internalConnect - insecure TCP selected
2020-07-13 22:18:54.974961 -- MqttServerConnection::_startListening
2020-07-13 22:18:54.994956 -- SynchronousMqttServerConnectionHandler::internalConnect - connection complete
2020-07-13 22:18:54.994956 -- SynchronousMqttServerConnectionHandler::internalConnect sending connect message
2020-07-13 22:18:55.020935 -- MqttConnectionHandlerBase::sendMessage - SENDING MESSAGE -> MQTTMessage of type MqttMessageType.connect
MessageType = MqttMessageType.connect Duplicate = false Retain = false Qos = atMostOnce Size = 0
ProtocolName = MQTT
ProtocolVersion = 5
ConnectFlags = CleanStart=true, WillFlag=false, WillQos=atMostOnce, WillRetain=false, PasswordFlag=false, UserNameFlag=false
KeepAlive = 0
Properties = Identifier : authenticationMethod, value : SMOKER
Identifier MqttPropertyIdentifier.authenticationData, value [97, 52, 101, 48, 97, 55, 51, 55, 98, 97, 57, 52, 52, 98, 49, 100, 101, 56, 99, 56, 54, 56, 97, 100, 51, 101, 49, 48, 50, 101, 49, 55, 51, 54, 55, 53, 99, 53, 52, 50, 57, 97, 97, 57, 50, 49, 56, 49, 53, 56, 97, 52, 57, 51, 50, 52, 50, 102, 100, 48, 50, 56, 52, 53]
Will topic = null
User name = not set
Password = not set

2020-07-13 22:18:55.089896 -- SynchronousMqttServerConnectionHandler::internalConnect - pre sleep, state = Connection status is connecting with return code of notSet and a disconnection origin of none
2020-07-13 22:18:55.151869 -- MqttServerConnection::_onData
2020-07-13 22:18:55.151869 -- MqttServerConnection::_ondata - adding incoming data, data length is 48, message stream length is 0, message stream position is 0
2020-07-13 22:18:55.221820 -- MqttServerConnection::_onData - MESSAGE RECEIVED -> MQTTMessage of type MqttMessageType.auth
MessageType = MqttMessageType.auth Duplicate = false Retain = false Qos = atMostOnce Size = 46

Reason Code  = continueAuthentication
Properties = Identifier : authenticationMethod, value : SMOKER
Identifier MqttPropertyIdentifier.authenticationData, value [173, 209, 97, 122, 141, 195, 123, 192, 203, 121, 158, 4, 225, 145, 22, 108, 193, 184, 248, 136, 195, 8, 195, 93, 195, 120, 219, 151, 233, 200, 158, 227]


2020-07-13 22:18:55.240810 -- MqttServerConnection::_onData - message processed
2020-07-13 22:18:55.253802 -- MqttAuthenticationManager::handleAuthentication - Authentication message received
2020-07-13 22:19:00.097229 -- SynchronousMqttServerConnectionHandler::internalConnect - post sleep, state = Connection status is connecting with return code of notSet and a disconnection origin of none
2020-07-13 22:19:00.097229 -- SynchronousMqttServerConnectionHandler::internalConnect - initiating connection try 1
2020-07-13 22:19:00.098221 -- SynchronousMqttServerConnectionHandler::internalConnect - insecure TCP selected
2020-07-13 22:19:00.150309 -- MqttServerConnection::_startListening
2020-07-13 22:19:00.150309 -- SynchronousMqttServerConnectionHandler::internalConnect - connection complete
2020-07-13 22:19:00.150309 -- SynchronousMqttServerConnectionHandler::internalConnect sending connect message
2020-07-13 22:19:00.151310 -- MqttConnectionHandlerBase::sendMessage - SENDING MESSAGE -> MQTTMessage of type MqttMessageType.connect
MessageType = MqttMessageType.connect Duplicate = false Retain = false Qos = atMostOnce Size = 145
ProtocolName = MQTT
ProtocolVersion = 5
ConnectFlags = CleanStart=true, WillFlag=false, WillQos=atMostOnce, WillRetain=false, PasswordFlag=false, UserNameFlag=false
KeepAlive = 0
Properties = Identifier : authenticationMethod, value : SMOKER
Identifier MqttPropertyIdentifier.authenticationData, value [97, 52, 101, 48, 97, 55, 51, 55, 98, 97, 57, 52, 52, 98, 49, 100, 101, 56, 99, 56, 54, 56, 97, 100, 51, 101, 49, 48, 50, 101, 49, 55, 51, 54, 55, 53, 99, 53, 52, 50, 57, 97, 97, 57, 50, 49, 56, 49, 53, 56, 97, 52, 57, 51, 50, 52, 50, 102, 100, 48, 50, 56, 52, 53]
Will topic = null
User name = not set
Password = not set

2020-07-13 22:19:00.154307 -- SynchronousMqttServerConnectionHandler::internalConnect - pre sleep, state = Connection status is connecting with return code of notSet and a disconnection origin of none
2020-07-13 22:19:00.165311 -- MqttServerConnection::_onData
2020-07-13 22:19:00.165311 -- MqttServerConnection::_ondata - adding incoming data, data length is 48, message stream length is 0, message stream position is 0
2020-07-13 22:19:00.166301 -- MqttServerConnection::_onData - MESSAGE RECEIVED -> MQTTMessage of type MqttMessageType.auth
MessageType = MqttMessageType.auth Duplicate = false Retain = false Qos = atMostOnce Size = 46

Reason Code  = continueAuthentication
Properties = Identifier : authenticationMethod, value : SMOKER
Identifier MqttPropertyIdentifier.authenticationData, value [117, 182, 57, 250, 206, 189, 112, 86, 105, 52, 44, 45, 142, 22, 200, 238, 59, 149, 122, 28, 132, 155, 181, 203, 249, 49, 9, 54, 192, 27, 44, 21]


2020-07-13 22:19:00.167308 -- MqttServerConnection::_onData - message processed
2020-07-13 22:19:00.167308 -- MqttAuthenticationManager::handleAuthentication - Authentication message received
2020-07-13 22:19:05.168217 -- SynchronousMqttServerConnectionHandler::internalConnect - post sleep, state = Connection status is connecting with return code of notSet and a disconnection origin of none
2020-07-13 22:19:05.168217 -- SynchronousMqttServerConnectionHandler::internalConnect - initiating connection try 2
2020-07-13 22:19:05.169225 -- SynchronousMqttServerConnectionHandler::internalConnect - insecure TCP selected
2020-07-13 22:19:05.367845 -- MqttServerConnection::_startListening
2020-07-13 22:19:05.367845 -- SynchronousMqttServerConnectionHandler::internalConnect - connection complete
2020-07-13 22:19:05.367845 -- SynchronousMqttServerConnectionHandler::internalConnect sending connect message
2020-07-13 22:19:05.367845 -- MqttConnectionHandlerBase::sendMessage - SENDING MESSAGE -> MQTTMessage of type MqttMessageType.connect
MessageType = MqttMessageType.connect Duplicate = false Retain = false Qos = atMostOnce Size = 145
ProtocolName = MQTT
ProtocolVersion = 5
ConnectFlags = CleanStart=true, WillFlag=false, WillQos=atMostOnce, WillRetain=false, PasswordFlag=false, UserNameFlag=false
KeepAlive = 0
Properties = Identifier : authenticationMethod, value : SMOKER
Identifier MqttPropertyIdentifier.authenticationData, value [97, 52, 101, 48, 97, 55, 51, 55, 98, 97, 57, 52, 52, 98, 49, 100, 101, 56, 99, 56, 54, 56, 97, 100, 51, 101, 49, 48, 50, 101, 49, 55, 51, 54, 55, 53, 99, 53, 52, 50, 57, 97, 97, 57, 50, 49, 56, 49, 53, 56, 97, 52, 57, 51, 50, 52, 50, 102, 100, 48, 50, 56, 52, 53]
Will topic = null
User name = not set
Password = not set

2020-07-13 22:19:05.371842 -- SynchronousMqttServerConnectionHandler::internalConnect - pre sleep, state = Connection status is connecting with return code of notSet and a disconnection origin of none
2020-07-13 22:19:05.374842 -- MqttServerConnection::_onData
2020-07-13 22:19:05.374842 -- MqttServerConnection::_ondata - adding incoming data, data length is 48, message stream length is 0, message stream position is 0
2020-07-13 22:19:05.376840 -- MqttServerConnection::_onData - MESSAGE RECEIVED -> MQTTMessage of type MqttMessageType.auth
MessageType = MqttMessageType.auth Duplicate = false Retain = false Qos = atMostOnce Size = 46

Reason Code  = continueAuthentication
Properties = Identifier : authenticationMethod, value : SMOKER
Identifier MqttPropertyIdentifier.authenticationData, value [67, 105, 76, 1, 17, 12, 92, 77, 128, 162, 93, 173, 20, 170, 82, 23, 106, 58, 77, 50, 162, 194, 105, 162, 47, 166, 96, 32, 211, 153, 53, 154]


2020-07-13 22:19:05.376840 -- MqttServerConnection::_onData - message processed
2020-07-13 22:19:05.376840 -- MqttAuthenticationManager::handleAuthentication - Authentication message received
2020-07-13 22:19:10.387770 -- SynchronousMqttServerConnectionHandler::internalConnect - post sleep, state = Connection status is connecting with return code of notSet and a disconnection origin of none
2020-07-13 22:19:10.388770 -- SynchronousMqttServerConnectionHandler::internalConnect failed
EXAMPLE::client exception - mqtt-client::NoConnectionException: The maximum allowed connection attempts ({3}) were exceeded. The broker is not responding to the connection request message (Missing Connection Acknowledgement?
2020-07-13 22:19:10.403759 -- SynchronousMqttServerConnectionHandler::disconnect
EXAMPLE::OnDisconnected client callback - Client disconnection
EXAMPLE::OnDisconnected callback is solicited, this is correct

@shamblett
Copy link
Owner

Ah yes I see, the client mustn't re-send the connect message while you are awaiting authentication, I've updated the code to try and fix this, could you update your pubscpec.yaml to pull the package from the development branch of the repo and re-test -

dependencies:
  mqtt5_clients:
    git:
      url: https://github.com/shamblett/mqtt5_client
      ref: development

Although I have an MQTT5 broker to test against I've not yet set it up to support authentication so I've not tested this outside of unit testing.

@ffbfh
Copy link
Author

ffbfh commented Jul 14, 2020

ok. I updated my code and now, I'am in a endless loop of awaiting end of authentication sequence.

EXAMPLE::Mqtt5 client connecting....
2020-07-14 10:53:30.750026 -- SynchronousMqttServerConnectionHandler::internalConnect entered
2020-07-14 10:53:30.757021 -- SynchronousMqttServerConnectionHandler::internalConnect - authentication requested
2020-07-14 10:53:30.757021 -- SynchronousMqttServerConnectionHandler::internalConnect - initiating connection try 0
2020-07-14 10:53:30.757021 -- SynchronousMqttServerConnectionHandler::internalConnect - insecure TCP selected
2020-07-14 10:53:30.939875 -- MqttServerConnection::_startListening
2020-07-14 10:53:30.954857 -- SynchronousMqttServerConnectionHandler::internalConnect - connection complete
2020-07-14 10:53:30.954857 -- SynchronousMqttServerConnectionHandler::internalConnect sending connect message
2020-07-14 10:53:30.971881 -- MqttConnectionHandlerBase::sendMessage - SENDING MESSAGE -> MQTTMessage of type MqttMessageType.connect
MessageType = MqttMessageType.connect Duplicate = false Retain = false Qos = atMostOnce Size = 0
ProtocolName = MQTT
ProtocolVersion = 5
ConnectFlags = CleanStart=true, WillFlag=false, WillQos=atMostOnce, WillRetain=false, PasswordFlag=false, UserNameFlag=false
KeepAlive = 0
Properties = Identifier : authenticationMethod, value : SMOKER
Identifier MqttPropertyIdentifier.authenticationData, value [97, 52, 101, 48, 97, 55, 51, 55, 98, 97, 57, 52, 52, 98, 49, 100, 101, 56, 99, 56, 54, 56, 97, 100, 51, 101, 49, 48, 50, 101, 49, 55, 51, 54, 55, 53, 99, 53, 52, 50, 57, 97, 97, 57, 50, 49, 56, 49, 53, 56, 97, 52, 57, 51, 50, 52, 50, 102, 100, 48, 50, 56, 52, 53]
Will topic = null
User name = not set
Password = not set

2020-07-14 10:53:31.020825 -- SynchronousMqttServerConnectionHandler::internalConnect - pre sleep, state = Connection status is connecting with return code of notSet and a disconnection origin of none
2020-07-14 10:53:31.138703 -- MqttServerConnection::_onData
2020-07-14 10:53:31.139704 -- MqttServerConnection::_ondata - adding incoming data, data length is 48, message stream length is 0, message stream position is 0
2020-07-14 10:53:31.230648 -- MqttServerConnection::_onData - MESSAGE RECEIVED -> MQTTMessage of type MqttMessageType.auth
MessageType = MqttMessageType.auth Duplicate = false Retain = false Qos = atMostOnce Size = 46

Reason Code  = continueAuthentication
Properties = Identifier : authenticationMethod, value : SMOKER
Identifier MqttPropertyIdentifier.authenticationData, value [212, 79, 162, 146, 0, 104, 209, 55, 101, 11, 239, 21, 90, 16, 242, 184, 170, 240, 30, 249, 34, 125, 246, 139, 187, 177, 49, 238, 21, 127, 173, 221]


2020-07-14 10:53:31.238644 -- MqttServerConnection::_onData - message processed
2020-07-14 10:53:31.250636 -- MqttAuthenticationManager::handleAuthentication - Authentication message received
2020-07-14 10:53:36.033008 -- SynchronousMqttServerConnectionHandler::internalConnect - awaiting end of authentication sequence
2020-07-14 10:53:37.045080 -- SynchronousMqttServerConnectionHandler::internalConnect - awaiting end of authentication sequence
2020-07-14 10:53:38.049077 -- SynchronousMqttServerConnectionHandler::internalConnect - awaiting end of authentication sequence
2020-07-14 10:53:39.063579 -- SynchronousMqttServerConnectionHandler::internalConnect - awaiting end of authentication sequence
2020-07-14 10:53:40.077029 -- SynchronousMqttServerConnectionHandler::internalConnect - awaiting end of authentication sequence
2020-07-14 10:53:41.078210 -- SynchronousMqttServerConnectionHandler::internalConnect - awaiting end of authentication sequence
2020-07-14 10:53:42.094588 -- SynchronousMqttServerConnectionHandler::internalConnect - awaiting end of authentication sequence
2020-07-14 10:53:43.101283 -- SynchronousMqttServerConnectionHandler::internalConnect - awaiting end of authentication sequence

My Client does not send an continue authentication package to the Broker. I only see the connect package from the Client to the Broker and the authentication continue package from the Broker to the Client.

Maybe I can provide a MQTT5 Broker which supports authentication. I will have a look.

Edit2:
A public Mosquitto MQTT5 Broker is reachable here:
smokitto.app.microfast.ch:31247

For this Broker you need a EdDSA KeyPair and to use the 'SMOKER' authentication method.
SMOKER method is described here https://arxiv.org/abs/1904.00389.

@shamblett
Copy link
Owner

From the log you are receiving an authentication message -

MqttAuthenticationManager::handleAuthentication - Authentication message received

You should be picking this up in your listening callback and responding to it as appropriate, eventually sending back an authentication message with a reason code of 'success', this should trigger the broker to send the CONNACK.

The client won't do this for you, it can't know when your authentication sequence is complete, so it will just loop waiting for a CONNACK which is what you are seeing.

If you can't see the authentication message in your listener callback then we have another problem.

@ffbfh
Copy link
Author

ffbfh commented Jul 14, 2020

yes. I added a continue authentication package to the listener where I will send a proof to the Broker (here the proof is just an example). The Broker then would answer with a CONNACK if the proof will be accepted.

My listener:

client.authentication.listen((final authMessage) {
    print('EXAMPLE:: Authentication Message received - $authMessage');

    /// Authentication message received, do what you need to do here, we simply tell the broker the sequence has ended.
    authMessage.withReasonCode(MqttAuthenticateReasonCode.continueAuthentication);
    authMessage.withAuthenticationMethod('SMOKER');
    authMessage.withAuthenticationData(Uint8Buffer()..addAll([1, 2, 3, 4]));
    client.sendAuthenticate(authMessage);
  });

But this package will never be sent to the Broker, when I run the code. You also will never see the print EXAMPLE:: Authentication Message received - $authMessage in the output log. So whatever I write into this callback, it will never be executed.
If I understand your example correct, I just have to handle the authentication message inside the listener callback and send back a packege (e.g. success or continue authentication) to the Broker like above, right?

@shamblett
Copy link
Owner

OK, what you are doing is correct, you are not receiving the authenticate message on the stream, I think I know why, I've updated the code, could you pub get and retry please.

@ffbfh
Copy link
Author

ffbfh commented Jul 14, 2020

I updated the code and tried again but the same result.

@shamblett
Copy link
Owner

OK, when are you actually listening in your code? You should do this after you call client.connect, you probably are, just checking this.

@ffbfh
Copy link
Author

ffbfh commented Jul 14, 2020

after the client.connect. I used your example and changed only the broker, auth_method, auth_data and the listener as you can see above.

@shamblett
Copy link
Owner

Yes OK, I can't see why this doesn't at least put the authenticate message on the listening stream. I'll have to set up a broker I can authenticate against to get any further. Thanks for your feedback I'll update this issue as soon as I can.

@ffbfh
Copy link
Author

ffbfh commented Jul 14, 2020

Ok. Thank you.

@shamblett
Copy link
Owner

OK, I may have got this now, please pull the latest code and update your code to listen for auth messages before you call connect, I've updated the example to show this. If it doesn't work could you please supply a log.

@ffbfh
Copy link
Author

ffbfh commented Jul 15, 2020

Now it works as expected. Thanks.

Here to log (without the re-authentication):

EXAMPLE::Mqtt5 client connecting....
2020-07-15 13:45:42.228033 -- SynchronousMqttServerConnectionHandler::internalConnect entered
2020-07-15 13:45:42.242027 -- SynchronousMqttServerConnectionHandler::internalConnect - authentication requested
2020-07-15 13:45:42.242027 -- SynchronousMqttServerConnectionHandler::internalConnect - initiating connection try 0
2020-07-15 13:45:42.243026 -- SynchronousMqttServerConnectionHandler::internalConnect - insecure TCP selected
2020-07-15 13:45:42.371953 -- MqttServerConnection::_startListening
2020-07-15 13:45:42.392950 -- SynchronousMqttServerConnectionHandler::internalConnect - connection complete
2020-07-15 13:45:42.400939 -- SynchronousMqttServerConnectionHandler::internalConnect sending connect message
2020-07-15 13:45:42.419925 -- MqttConnectionHandlerBase::sendMessage - SENDING MESSAGE -> MQTTMessage of type MqttMessageType.connect
MessageType = MqttMessageType.connect Duplicate = false Retain = false Qos = atMostOnce Size = 0
ProtocolName = MQTT
ProtocolVersion = 5
ConnectFlags = CleanStart=true, WillFlag=false, WillQos=atMostOnce, WillRetain=false, PasswordFlag=false, UserNameFlag=false
KeepAlive = 0
Properties = Identifier : authenticationMethod, value : SMOKER
Identifier MqttPropertyIdentifier.authenticationData, value [53, 50, 57, 99, 101, 50, 52, 52, 54, 54, 98, 100, 102, 52, 51, 102, 102, 55, 102, 50, 101, 97, 57, 50, 49, 49, 57, 51, 55, 102, 55, 55, 54, 102, 97, 57, 101, 54, 49, 100, 55, 98, 100, 52, 51, 54, 98, 52, 100, 97, 56, 55, 48, 97, 48, 57, 57, 102, 102, 49, 54, 48, 56, 54]
Will topic = null
User name = not set
Password = not set

2020-07-15 13:45:42.484888 -- SynchronousMqttServerConnectionHandler::internalConnect - pre sleep, state = Connection status is connecting with return code of notSet and a disconnection origin of none
2020-07-15 13:45:42.548857 -- MqttServerConnection::_onData
2020-07-15 13:45:42.549859 -- MqttServerConnection::_ondata - adding incoming data, data length is 48, message stream length is 0, message stream position is 0
2020-07-15 13:45:42.593826 -- MqttServerConnection::_onData - MESSAGE RECEIVED -> MQTTMessage of type MqttMessageType.auth
MessageType = MqttMessageType.auth Duplicate = false Retain = false Qos = atMostOnce Size = 46

Reason Code  = continueAuthentication
Properties = Identifier : authenticationMethod, value : SMOKER
Identifier MqttPropertyIdentifier.authenticationData, value [37, 95, 152, 182, 61, 88, 43, 238, 148, 129, 126, 173, 58, 85, 46, 29, 132, 128, 186, 23, 38, 102, 100, 171, 82, 213, 245, 242, 71, 105, 80, 208]


2020-07-15 13:45:42.601858 -- MqttServerConnection::_onData - message processed
2020-07-15 13:45:42.612824 -- MqttAuthenticationManager::handleAuthentication - Authentication message received
EXAMPLE:: Authentication Message received - MQTTMessage of type MqttMessageType.auth
MessageType = MqttMessageType.auth Duplicate = false Retain = false Qos = atMostOnce Size = 46

Reason Code  = continueAuthentication
Properties = Identifier : authenticationMethod, value : SMOKER
Identifier MqttPropertyIdentifier.authenticationData, value [37, 95, 152, 182, 61, 88, 43, 238, 148, 129, 126, 173, 58, 85, 46, 29, 132, 128, 186, 23, 38, 102, 100, 171, 82, 213, 245, 242, 71, 105, 80, 208]


2020-07-15 13:45:42.783716 -- MqttConnectionHandlerBase::sendMessage - SENDING MESSAGE -> MQTTMessage of type MqttMessageType.auth
MessageType = MqttMessageType.auth Duplicate = false Retain = false Qos = atMostOnce Size = 46

Reason Code  = continueAuthentication
Properties = Identifier : authenticationMethod, value : SMOKER
Identifier MqttPropertyIdentifier.authenticationData, value [103, 72, 5, 89, 1, 101, 34, 226, 171, 35, 129, 42, 33, 213, 187, 144, 21, 50, 225, 255, 6, 97, 128, 7, 154, 13, 180, 21, 117, 133, 97, 104, 246, 123, 133, 189, 8, 120, 192, 97, 196, 23, 129, 143, 202, 141, 137, 94, 123, 105, 147, 45, 223, 235, 47, 214, 79, 243, 217, 51, 194, 80, 51, 8, 37, 95, 152, 182, 61, 88, 43, 238, 148, 129, 126, 173, 58, 85, 46, 29, 132, 128, 186, 23, 38, 102, 100, 171, 82, 213, 245, 242, 71, 105, 80, 208]


2020-07-15 13:45:42.786714 -- MqttAuthenticationManager::send - Authentication message sent
2020-07-15 13:45:42.939628 -- MqttServerConnection::_onData
2020-07-15 13:45:42.939628 -- MqttServerConnection::_ondata - adding incoming data, data length is 17, message stream length is 0, message stream position is 0
2020-07-15 13:45:42.955626 -- MqttServerConnection::_onData - MESSAGE RECEIVED -> MQTTMessage of type MqttMessageType.connectAck
MessageType = MqttMessageType.connectAck Duplicate = false Retain = false Qos = atMostOnce Size = 15
Session Present = false
Connect Reason Code = success
Session Expiry Interval = 0
Receive Maximum = 65535
Maximum QoS = 2
Retain Available = false
Maximum Packet Size = 0
Assigned client Identifier = null
Topic Alias Maximum = 10
Reason String = null
Wildcard Subscription Available = true
Subscription Identifiers Available = true
Shared Subscription Available = true
broker Keep Alive = 0
Response Information = null
broker Reference = null
Authentication Method = SMOKER
Properties = Identifier : topicAliasMaximum, value : 10
Identifier : authenticationMethod, value : SMOKER


2020-07-15 13:45:42.956625 -- MqttServerConnection::_onData - message processed
2020-07-15 13:45:42.958618 -- SynchronousMqttServerConnectionHandler::_connectAckProcessor
2020-07-15 13:45:42.959618 -- SynchronousMqttServerConnectionHandler::_connectAckProcessor - state = connected
EXAMPLE::OnConnected client callback - Client connection was successful
2020-07-15 13:45:42.960617 -- SynchronousMqttServerConnectionHandler:: cancelling connect timer
2020-07-15 13:45:42.961615 -- SynchronousMqttServerConnectionHandler::internalConnect - awaiting end of authentication sequence
2020-07-15 13:45:43.977032 -- SynchronousMqttServerConnectionHandler::internalConnect - post sleep, state = Connection status is connected with return code of success and a disconnection origin of none
2020-07-15 13:45:43.978032 -- SynchronousMqttServerConnectionHandler::internalConnect exited with state Connection status is connected with return code of success and a disconnection origin of none
EXAMPLE::Mqtt5 server client connected, return code is success
EXAMPLE::Disconnecting
2020-07-15 13:46:04.008115 -- SynchronousMqttServerConnectionHandler::disconnect
2020-07-15 13:46:04.011114 -- MqttConnectionHandlerBase::sendMessage - SENDING MESSAGE -> MQTTMessage of type MqttMessageType.disconnect
MessageType = MqttMessageType.disconnect Duplicate = false Retain = false Qos = atMostOnce Size = 0

Reason Code  = normalDisconnection
Properties = No properties set
EXAMPLE::OnDisconnected client callback - Client disconnection
EXAMPLE::OnDisconnected callback is solicited, this is correct
2020-07-15 13:46:04.148618 -- MqttConnectionBase::_onDone - calling disconnected callback
EXAMPLE::OnDisconnected client callback - Client disconnection

If you would like to test this authentication method ('SMOKER') by yourself, let me know and I can share my example.

@shamblett
Copy link
Owner

Thanks for the testing. I've re published the package at version 1.1.0. Please raise any other issues you may encounter.

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