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

I can't to use ca.crt, client.crt, client.key (X509 certificate) to connect mqtt broker. #133

Open
jamwu1991 opened this issue Aug 17, 2021 · 2 comments

Comments

@jamwu1991
Copy link

jamwu1991 commented Aug 17, 2021

Hi everyone

I want to use ca.crt, client.crt, client.key to connect mqtt broker.

My code like following:

    client = MQTTClient(clientId)
    print("Before ", client.is_connected)
    contextInstance = ssl.SSLContext(ssl.PROTOCOL_TLSv1_2)
    contextInstance.load_default_certs()
    contextInstance.load_verify_locations(cafile=tls_CERT_PATH, cadata=None, capath=None)
    contextInstance.verify_mode =ssl.CERT_REQUIRED
    contextInstance.load_cert_chain(certfile=tls_CLIENT_PATH, keyfile=tls_CLIENTKEY_PATH)
    contextInstance.check_hostname=False
    result = await client.connect(host=broker,port=port,ssl=contextInstance)
    print("Result ", result)
    print("client.is_connected ", client.is_connected)

And the execute result is:

Before  False

The execute is stop at the following line code

result = await client.connect(host=broker,port=port,ssl=contextInstance)

Can someone tell me how to fix it?

Thanks for your watching and any idea.

The X509 certificate file content is:
ca.crt -> Just a ca certificate. Content as following

-----BEGIN CERTIFICATE-----
content message
-----END CERTIFICATE-----

client.crt -> Just a client certificate. Content as following

-----BEGIN CERTIFICATE-----
content message
-----END CERTIFICATE-----

client.key -> Just a client key. Content as following

-----BEGIN PRIVATE KEY-----
content message
-----END PRIVATE KEY------
@Mixser
Copy link
Contributor

Mixser commented Oct 9, 2021

Hi, thanks for the issue. Please clarify your env (os, broker version).

By the way we have already faced with a same issue in the past, please try to read and may be it will help you #122 (comment)

@luokui-c12
Copy link

I have the same problem in windows

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

3 participants