VSChina / ESP32_AzureIoT_Arduino

The library for ESP32 Azure IoT for Arduino
MIT License
37 stars 43 forks source link

Using x509 - Connection Not Accepted: 0x5: Not Authorized #17

Closed PavelVe closed 4 years ago

PavelVe commented 5 years ago

I would like to connect with x509 certificates. In example is used only SharedAccessKey or SharedAccessSignature. I modified the example by entering certificates, but unfortunately, the authorization is not accepted.

To test Azure setup I used the example from https://github.com/Azure/azure-iot-sdk-c I attached the source file that I compiled and run in the emulator. Validation is successful. Running without a problem.

Then I tried to add this validation to SimpleMQTT (Arduino example). I added:

libraries: #include "az_iot/iothub_client/inc/iothub_client_options.h" #include "az_iot/c-utility/inc/azure_c_shared_utility/shared_util_options.h"

Certificates: x509privatekey, x509certificate

change connection string to: static const char* connectionString = "HostName=fengoo.azure-devices.net;DeviceId=mydevice;x509=true"

and set option for this certificates: Esp32MQTTClient_SetOption(OPTION_TRUSTED_CERT, certificates); if ((Esp32MQTTClient_SetOption(OPTION_X509_CERT, x509certificate) != IOTHUB_CLIENT_OK) || (Esp32MQTTClient_SetOption(OPTION_X509_PRIVATE_KEY, x509privatekey) != IOTHUB_CLIENT_OK)) { printf("failure to set options for x509, aborting\r\n"); }

Is it possible to establish a connection with x509 certificates?

I attached .c file and Arduino file. azure-x509-test.zip

JerryYangKai commented 4 years ago

Hi @PavelVe, unfortunately, the sdk does not support x509 certificates for esp32 devices.