eclipse / paho.mqtt.python

paho.mqtt.python
Other
2.19k stars 723 forks source link

Allow password to be set with no username on MQTT 5 #726

Open vishnureddy17 opened 1 year ago

vishnureddy17 commented 1 year ago

MQTT 5 allows for a password to be set in the CONNECT packet without providing a username. However, it seems like this client does not support this. Would be nice if this were possible.

Relevant part of the MQTT spec

MattBrittan commented 9 months ago

Relevant comment from the spec:

Non-normative comment: This version of the protocol allows the sending of a Password with no User Name, where MQTT v3.1.1 did not. This reflects the common use of Password for credentials other than a password.

It looks like client.username_pw_set(None, "foobar") sets things up correctly but _send_connect will not send the password by itself:

if self._username is not None:
            remaining_length += 2 + len(self._username)
            connect_flags |= 0x80
            if self._password is not None:
                connect_flags |= 0x40
                remaining_length += 2 + len(self._password)

Should be a fairly simple enhancement.