gmqtt
gmqtt copied to clipboard
I can't to use ca.crt, client.crt, client.key (X509 certificate) to connect mqtt broker.
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------
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 https://github.com/wialon/gmqtt/issues/122#issuecomment-762448887