Azure / azure-iot-sdk-c

A C99 SDK for connecting devices to Microsoft Azure IoT services
https://azure.github.io/azure-iot-sdk-c
Other
580 stars 738 forks source link

Issue with connecting to iothub over MQTT for Android #328

Closed mahalakshmirathinam closed 6 years ago

mahalakshmirathinam commented 6 years ago

Description of the issue:

Trying to cross-compile Azure C sdk version 1.1.28 to android arm32 bit device. I did it successfully but the ported libraries and samples does not connect to azure iot hub.

Getting the following error. Info: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed Info: Closing tlsio from a state other than TLSIO_STATE_EXT_OPEN or TLSIO_STATE_EXT_ERROR

Can you help me to figure out the issue.

Code sample exhibiting the issue:

Console log of the issue:

root@msm8909:/data/krossbox # ./simplesample_mqtt
WARNING: linker: ./simplesample_mqtt: unused DT entry: type 0x1d arg 0x4d52 Info: IoT Hub SDK for C, version 1.1.28 Error: Time:Thu Dec 14 16:58:02 2017 File:/root/openwrt/sdk/package/new_azure_c_sdk/azure-iot-sdk-c/serializer/src/agenttypesystem.c Func:AgentDataTypes_ToString Line:1309 (result = AGENT_DATA_TYPES_INVALID_ARG) Error: Time:Thu Dec 14 16:58:02 2017 File:/root/openwrt/sdk/package/new_azure_c_sdk/azure-iot-sdk-c/serializer/src/jsonencoder.c Func:JSONEncoder_EncodeTree Line:149 (result = JSON_ENCODER_TOSTRING_FUNCTION_ERROR) Error: Time:Thu Dec 14 16:58:02 2017 File:/root/openwrt/sdk/package/new_azure_c_sdk/azure-iot-sdk-c/serializer/src/datamarshaller.c Func:DataMarshaller_SendData Line:187 (result = DATA_MARSHALLER_JSON_ENCODER_ERROR) Error: Time:Thu Dec 14 16:58:02 2017 File:/root/openwrt/sdk/package/new_azure_c_sdk/azure-iot-sdk-c/serializer/src/datapublisher.c Func:DataPublisher_EndTransaction Line:270 (result = DATA_PUBLISHER_MARSHALLER_ERROR) Error: Time:Thu Dec 14 16:58:02 2017 File:/root/openwrt/sdk/package/new_azure_c_sdk/azure-iot-sdk-c/serializer/src/iotdevice.c Func:Device_EndTransaction Line:226 (result = DEVICE_DATA_PUBLISHER_FAILED) Error: Time:Thu Dec 14 16:58:02 2017 File:/root/openwrt/sdk/package/new_azure_c_sdk/azure-iot-sdk-c/serializer/src/codefirst.c Func:CodeFirst_SendAsync Line:1350 (result = CODEFIRST_DEVICE_PUBLISH_FAILED) Failed to serialize Info: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed Info: Closing tlsio from a state other than TLSIO_STATE_EXT_OPEN or TLSIO_STATE_EXT_ERROR Info: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed Info: Closing tlsio from a state other than TLSIO_STATE_EXT_OPEN or TLSIO_STATE_EXT_ERROR

ewertons commented 6 years ago

Hi @mahalakshmirathinam , could you verify your SSL installation against the Azure IoT Hub please? Follow the instructions in this issue to verify: https://github.com/Azure/azure-iot-sdk-c/issues/198 Also please send back the version of the ssl lib as the other customer did in this issue. Thanks, Azure IoT Team

mahalakshmirathinam commented 6 years ago

Used the openssl version 1.0.2l

I even tried with IoTHubClient_LL_SetOption(iotHubClientHandle, OPTION_TRUSTED_CERT, certificates

with first certificate given in certs.c

I'm getting this error

130|root@msm8909:/data/krossbox # ./iothub_client_sample_mqtt
WARNING: linker: ./iothub_client_sample_mqtt: unused DT entry: type 0x1d arg 0x34d8 Info: IoT Hub SDK for C, version 1.1.28

set trusted cert samples enabled IoTHubClient_LL_SetMessageCallback...successful. IoTHubClient_LL_SendEventAsync accepted message [0] for transmission to IoT Hub. IoTHubClient_LL_SendEventAsync accepted message [1] for transmission to IoT Hub. IoTHubClient_LL_SendEventAsync accepted message [2] for transmission to IoT Hub. IoTHubClient_LL_SendEventAsync accepted message [3] for transmission to IoT Hub. IoTHubClient_LL_SendEventAsync accepted message [4] for transmission to IoT Hub. -> 18:27:01 CONNECT | VER: 4 | KEEPALIVE: 240 | FLAGS: 192 | USERNAME: thiot.azure-devices.net/0/api-version=2016-11-14&DeviceClientType=iothubclient%2f1.1.28%20(native%3b%20Linux%3b%20armv7l) | PWD: XXXX | CLEAN: 0 <- 18:27:01 CONNACK | SESSION_PRESENT: false | RETURN_CODE: 0x5 Error: Time:Fri Dec 15 18:27:01 2017 File:/root/openwrt/sdk/package/new_azure_c_sdk/azure-iot-sdk-c/iothub_client/src/iothubtransport_mqtt_common.c Func:mqtt_operation_complete_callback Line:1352 Connection Not Accepted: 0x5: Not Authorized -> 18:27:01 DISCONNECT -> 18:27:02 CONNECT | VER: 4 | KEEPALIVE: 240 | FLAGS: 192 | USERNAME: thiot.azure-devices.net/0/api-version=2016-11-14&DeviceClientType=iothubclient%2f1.1.28%20(native%3b%20Linux%3b%20armv7l) | PWD: XXXX | CLEAN: 0 <- 18:27:02 CONNACK | SESSION_PRESENT: false | RETURN_CODE: 0x5 Error: Time:Fri Dec 15 18:27:02 2017 File:/root/openwrt/sdk/package/new_azure_c_sdk/azure-iot-sdk-c/iothub_client/src/iothubtransport_mqtt_common.c Func:mqtt_operation_complete_callback Line:1352 Connection Not Accepted: 0x5: Not Authorized -> 18:27:02 DISCONNECT -> 18:27:04 CONNECT | VER: 4 | KEEPALIVE: 240 | FLAGS: 192 | USERNAME: thiot.azure-devices.net/0/api-version=2016-11-14&DeviceClientType=iothubclient%2f1.1.28%20(native%3b%20Linux%3b%20armv7l) | PWD: XXXX | CLEAN: 0 <- 18:27:04 CONNACK | SESSION_PRESENT: false | RETURN_CODE: 0x5 Error: Time:Fri Dec 15 18:27:04 2017 File:/root/openwrt/sdk/package/new_azure_c_sdk/azure-iot-sdk-c/iothub_client/src/iothubtransport_mqtt_common.c Func:mqtt_operation_complete_callback Line:1352 Connection Not Accepted: 0x5: Not Authorized -> 18:27:04 DISCONNECT ^C 130|root@msm8909:/data/krossbox # openssl version OpenSSL 1.0.2l 25 May 2017

Used the connection string HostName=thiot.azure-devices.net;DeviceId=0;SharedAccessKey=Qiunl1STmyQf+hUlVAmfTFmtb6zbKnj7GS4ejvY4Fp0=

Please help me to resolve this issue.

ewertons commented 6 years ago

Did you try checking the openssl authentication against your hub (using the openssl application), like suggested in #198? What is the output?

ewertons commented 6 years ago

Now this is interesting... you are getting responses back from the service (<- CONACK), so the TLS connection was established. When you provided the certificate using "IoTHubClient_LL_SetOption(iotHubClientHandle, OPTION_TRUSTED_CERT" you seem to have passed your initial issue.

Is your connection string correct?

mahalakshmirathinam commented 6 years ago

Yes. My connection string is correct.

ewertons commented 6 years ago

Hi @mahalakshmirathinam , this issue is quite old and we didn't have the details above from your openssl test (2 comments above). If you still face issues please reopen the ticket and we will follow up. Thanks, Azure IoT Team.

yuanjun-123 commented 4 years ago

@mahalakshmirathinam it occurs error when I cross-compile Azure C SDK to android arm32 bit device:

/home/ubuntu/toolchain/bin/../lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin/ld: error: cannot find -lpthread

/home/ubuntu/toolchain/bin/../lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin/ld: error: cannot find -lrt

toolchain.cmake:

INCLUDE(CMakeForceCompiler)

SET(CMAKE_SYSTEM_NAME Linux)     # this one is important
SET(CMAKE_SYSTEM_VERSION 1)     # this one not so much
SET(CMAKE_SYSTEM_PROCESSOR arm)

SET(CMAKE_C_COMPILER /home/ubuntu/toolchain/bin/arm-linux-androideabi-gcc)
# this is the file system root of the target
SET(CMAKE_FIND_ROOT_PATH /home/ubuntu/toolchain/sysroot/usr)
# search for programs in the build host directories
SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
SET(CMAKE_C_COMPILER_WORKS 1)
SET(CMAKE_CXX-COMPILER_WORKS 1)

# for libraries and headers in the target directories
SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)

OS version: 4.4.2 (sdk version 19) Cross compile toolchain: arm-linux-androideabi (generated by NDK,version 4.9)

Have you ever encountered the same problem? What's the toolchain you used? Could you please give me some advices about that?

Thanks so much.