paho.mqtt.python icon indicating copy to clipboard operation
paho.mqtt.python copied to clipboard

How can I set PEM password?

Open mofywong opened this issue 7 years ago • 3 comments

Hi, I use PEM file with password. In C language,It's provide a function callback to set the pem password (int tls_set(const char *cafile, const char *capath=NULL, const char *certfile=NULL, const char *keyfile=NULL, int (*pw_callback)(char *buf, int size, int rwflag, void *userdata)=NULL);)with libmosquitto. But I didn't find any function like that in paho.mqtt.python.Can it support that? If yes, how can I do? Thank you very much.

mofywong avatar Sep 16 '19 08:09 mofywong

It doesn't seem to support it.

Per the docs at pypi under certfile, keyfile:

Note that if either of these files in encrypted and needs a password to decrypt it, Python will ask for the password at the command line. It is not currently possible to define a callback to provide the password.

velosol avatar Dec 31 '19 21:12 velosol

Hi, it seems that the context which is used by loading the certificates, has an optional parameter for the password: client.py

        context = ssl.SSLContext(tls_version)

        # Configure context
        if certfile is not None:
            context.load_cert_chain(certfile, keyfile)

And in the SSLContext: https://docs.python.org/3/library/ssl.html#ssl.SSLContext.load_cert_chain New parameter password in version 3.3

    def load_cert_chain(
        self, certfile: StrPath, keyfile: Optional[StrPath] = ..., password: Optional[_PasswordType] = ...
    ) -> None: ...

tzahari avatar Jun 14 '21 14:06 tzahari

I created a pull request #576

tzahari avatar Jun 14 '21 15:06 tzahari