According to the support I received by Dane Walton from the Azure IoT Middleware for Freertos repository on Github, the only reason to use the certificate and private key as a single line string was for the samples provided so the certificate can be configured through Kconfig. Therefore, I tried again with the original certificates in PEM format and the result was just the same...
Azure IoT Middleware for Freertos - Failed to establish MQTT connection, error 0x00000006
Hi, I have a project based on ESP32 and ESP-AZURE that has been working succesfully during the last three years. We are using X.509 certificates (self signed). Now I am facing the challenge of migrating the project from ESP-AZURE to Azure Iot Middleware for Freertos and I took this repo as my reference.
The device certificates are stored in a specific partition but in order to simplify the process at the beginning, I am initially using hardcoded variables as single line strings with the corresponding \n characters. In my original project I store and load the certificate and private key in PEM format but here due to the warning I saw here, I am using those single line strings without the carriage return characters:
const char client_cert[] = "-----BEGIN CERTIFICATE-----\n"
"MIIFmDCCA4CgAwIBAgICAO4wDQYJKoZIhvcNAQELBQAwEDEOMAwGA1UEAwwFb3Zl\n"
"bnMwIBcNMjIxMDEwMDgxODMzWhgPMjA1MjExMjEwODE4MzNaMBsxGTAXBgNVBAMM\n"
"EDEwMDIyMDIxMDAwMDAxNjgwggIiMA0GCSqGSIb3DQEBAQUAA4ICDwAwggIKAoIC\n"
"AQDciLWDxuxawrAHfG67osNVjg3csFO4gda4pcDv2FWVrrqZqibC0mZBC+3zCaQC\n"
etc
I was able to make a good progress but I am now receiving an error in the call to 'AzureIoTHubClient_Connect', this is the log:
MQTT: Connection refused: not authorized.
MQTT: CONNACK recv failed with status = MQTTServerRefused.
MQTT: MQTT connection failed with status = MQTTServerRefused.
AZ IOT: Failed to establish MQTT connection: Server=XXXX.azure-devices.net, MQTT error=0x00000006
All the calls to previous functions complete successfully so I guess the certificate is correct after being used to connect with the DPS:
DPS:
prvConnectToServerWithBackoffRetries --> OK
AzureIoTProvisioningClient_Init --> OK
AzureIoTProvisioningClient_Register --> OK
AzureIoTProvisioningClient_GetDeviceAndHub --> OK
IoT Hub:
prvConnectToServerWithBackoffRetries --> OK
AzureIoTHubClient_OptionsInit --> OK
AzureIoTHubClient_Init --> OK
But it fails in the call to AzureIoTHubClient_Connect with the previous log messages. AzureIoTResult_t value is 1.
Can you please help me?
3 answers
Sort by: Most helpful
-
-
afcec 21 Reputation points
2023-01-20T10:24:39.84+00:00 With respect to the certificates we are using, please see below some information:
- DPS is configured with the Root CA certificate and we have three enrollment groups with the corresponding intermediate certificates (Everything configured and working fine for three years now)
- Device certificates are self signed and created witn OpenSSL
- All the certificates generated are valid for 30 years
- The signature algorithm is sha256WithRSAEncryption
-
QuantumCache 20,271 Reputation points
2023-02-22T21:10:06.96+00:00 hello @afcec Just checking on this.
I was looking into the latest Support ticket interaction and was not able to find any further communication on the case/
Was the below mentioned statement helped in narrowing down the issue?
successfully resolved error by removing the module Id from the config file.