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

Blob upload failing on LTS_08_2024 with MBEDTLS #2658

Open
shekharg987 opened this issue Nov 20, 2024 · 5 comments
Open

Blob upload failing on LTS_08_2024 with MBEDTLS #2658

shekharg987 opened this issue Nov 20, 2024 · 5 comments
Assignees
Labels

Comments

@shekharg987
Copy link

shekharg987 commented Nov 20, 2024

Using ubuntu 18.0 version upgrading SDK to latest LTS release LTS_03_2024

Using X509 based authentication facing blob upload failing from SDK side

Below ae the console logs

[ERROR] Socketio_Failure: Receiving data from endpoint: errno=104.
[ERROR] Error signalled by underlying IO
[ERROR] xio reported error on dowork
[ERROR] Receive header from HTTP failed (result = HTTPAPI_READ_DATA_FAILED (10))
[ERROR] unable to recover sending to a working state
[ERROR] unable to HTTPAPIEX_ExecuteRequest
[ERROR] unable to HTTPAPIEX_ExecuteRequest
[ERROR] error in IoTHubClient_LL_UploadToBlob_GetBlobCredentialsFromIoTHub
[ERROR] Failed initializing upload in IoT Hub
[ERROR] unable to IoTHubClientCore_LL_UploadToBlob
[ERROR] fail to upload blob

SDK side logs
ERROR [dk-c\c-utility\adapters\socketio_win32.c:700 ] Socketio_Failure: Receiving data from endpoint: 10054.
ERROR [k-c\c-utility\adapters\httpapi_compact.c:476 ] Error signalled by underlying IO
ERROR [dk-c\c-utility\adapters\socketio_win32.c:700 ] Socketio_Failure: Receiving data from endpoint: 10054.
[k-c\c-utility\adapters\httpapi_compact.c:566 ] xio reported error on dowork
ERROR [k-c\c-utility\adapters\httpapi_compact.c:1276] Receive header from HTTP failed (result = HTTPAPI_READ_DATA_FAILED (10))
ERROR [zure-iot-sdk-c\c-utility\src\httpapiex.c:551 ] unable to recover sending to a working state
ERROR [ient\src\iothub_client_ll_uploadtoblob.c:156 ] unable to HTTPAPIEX_ExecuteRequest
ERROR [ient\src\iothub_client_ll_uploadtoblob.c:546 ] unable to HTTPAPIEX_ExecuteRequest
ERROR [ient\src\iothub_client_ll_uploadtoblob.c:915 ] error in IoTHubClient_LL_UploadToBlob_GetBlobCredentialsFromIoTHub
ERROR [othub_client\src\iothub_client_core_ll.c:2728] Failed initializing upload in IoT Hub
ERROR [c\iothub_client\src\iothub_client_core.c:2365] unable to IoTHubClientCore_LL_UploadToBlob

[2025-01-21] Important information not previously provided: Customer is using HTTP API with MBED TLS.

@ewertons
Copy link
Contributor

We have tests for verifying this scenario, but here are the results of a manual test:

user@ubuntu1804:/home/user/code/s1/azure-iot-sdk-c/cmake/iothub_client/samples/iothub_client_sample_upload_to_blob_with_retry$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 18.04.6 LTS
Release:        18.04
Codename:       bionic
user@ubuntu1804:/home/user/code/s1/azure-iot-sdk-c/cmake/iothub_client/samples/iothub_client_sample_upload_to_blob_with_retry$ git status
HEAD detached at LTS_08_2024
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

        modified:   ../../../../iothub_client/samples/iothub_client_sample_upload_to_blob_with_retry/iothub_client_sample_upload_to_blob_with_retry.c

no changes added to commit (use "git add" and/or "git commit -a")
user@ubuntu1804:/home/user/code/s1/azure-iot-sdk-c/cmake/iothub_client/samples/iothub_client_sample_upload_to_blob_with_retry$ git log -n 1
commit 9c70f98b7b659e169ae44389a5142f3a386c5791 (HEAD, tag: LTS_08_2024, origin/lts_08_2024)
Author: Ewerton Scaboro da Silva <[email protected]>
Date:   Mon Aug 12 15:03:03 2024 -0700

    Update LTS Schedule for LTS_08_2024
user@ubuntu1804:/home/user/code/s1/azure-iot-sdk-c/cmake/iothub_client/samples/iothub_client_sample_upload_to_blob_with_retry$
user@ubuntu1804:/home/user/code/s1/azure-iot-sdk-c/cmake/iothub_client/samples/iothub_client_sample_upload_to_blob_with_retry$ az storage blob delete -c "upload2blob" --name "user-device-x509-1/subdir/hello_world_mb_with_retry.txt"
user@ubuntu1804:/home/user/code/s1/azure-iot-sdk-c/cmake/iothub_client/samples/iothub_client_sample_upload_to_blob_with_retry$ az storage blob exists -c "upload2blob" --name "user-device-x509-1/subdir/hello_world_mb_with_retry.txt"
{
  "exists": false
}
user@ubuntu1804:/home/user/code/s1/azure-iot-sdk-c/cmake/iothub_client/samples/iothub_client_sample_upload_to_blob_with_retry$ ./iothub_client_sample_upload_to_blob_with_retry
Starting the IoTHub client sample upload to blob...
*   Trying 123.456.789.123...
* TCP_NODELAY set
* Connected to user-iothub1.azure-devices.net (123.456.789.123) port 443 (#0)
* ALPN, offering http/1.1
* successfully set certificate verify locations:
*   CAfile: /etc/ssl/certs/ca-certificates.crt
  CApath: /etc/ssl/certs
* SSL connection using TLSv1.2 / ECDHE-RSA-AES128-GCM-SHA256
* ALPN, server did not agree to a protocol
* Server certificate:
*  subject: C=US; ST=Washington; L=Redmond; O=Microsoft Corporation; CN=*.azure-devices.net
*  start date: Dec  4 00:00:00 2024 GMT
*  expire date: May  4 23:59:59 2025 GMT
*  subjectAltName: host "user-iothub1.azure-devices.net" matched cert's "*.azure-devices.net"
*  issuer: C=US; O=Microsoft Corporation; CN=MSFT RS256 CA-1
*  SSL certificate verify ok.
> POST /devices/user-device-x509-1/files/?api-version=2016-11-14 HTTP/1.1
Host: user-iothub1.azure-devices.net
Content-Type: application/json
Accept: application/json
User-Agent: iothubclient/1.13.0
Content-Length: 54

* upload completely sent off: 54 out of 54 bytes
< HTTP/1.1 200 OK
< content-length: 428
< content-type: application/json
< date: Thu, 19 Dec 2024 22:23:22 GMT
<
* Connection #0 to host user-iothub1.azure-devices.net left intact
*   Trying 123.456.789.123...
* TCP_NODELAY set
* Connected to user-iothub1.azure-devices.net (123.456.789.123) port 443 (#0)
* ALPN, offering http/1.1
* successfully set certificate verify locations:
*   CAfile: /etc/ssl/certs/ca-certificates.crt
  CApath: /etc/ssl/certs
* SSL connection using TLSv1.2 / ECDHE-RSA-AES128-GCM-SHA256
* ALPN, server did not agree to a protocol
* Server certificate:
*  subject: C=US; ST=Washington; L=Redmond; O=Microsoft Corporation; CN=*.azure-devices.net
*  start date: Dec  4 00:00:00 2024 GMT
*  expire date: May  4 23:59:59 2025 GMT
*  subjectAltName: host "user-iothub1.azure-devices.net" matched cert's "*.azure-devices.net"
*  issuer: C=US; O=Microsoft Corporation; CN=MSFT RS256 CA-1
*  SSL certificate verify ok.
> POST /devices/user-device-x509-1/files/notifications/?api-version=2016-11-14 HTTP/1.1
Host: user-iothub1.azure-devices.net
Content-Type: application/json
Accept: application/json
User-Agent: iothubclient/1.13.0
Content-Length: 206

* upload completely sent off: 206 out of 206 bytes
< HTTP/1.1 204 No Content
< date: Thu, 19 Dec 2024 22:23:23 GMT
<
* Connection #0 to host user-iothub1.azure-devices.net left intact
hello world blob has been created
Press any key to continue
user@ubuntu1804:/home/user/code/s1/azure-iot-sdk-c/cmake/iothub_client/samples/iothub_client_sample_upload_to_blob_with_retry$ az storage blob exists -c "upload2blob" --name "user-device-x509-1/subdir/hello_world_mb_with_retry.txt"
{
  "exists": true
}
user@ubuntu1804:/home/user/code/s1/azure-iot-sdk-c/cmake/iothub_client/samples/iothub_client_sample_upload_to_blob_with_retry$ az storage blob download -c "u
pload2blob" --name "user-device-x509-1/subdir/hello_world_mb_with_retry.txt"
Finished[#############################################################]  100.0000%
Hello World from iothub_client_sample_upload_to_blob_with_retry: 0
Hello World from iothub_client_sample_upload_to_blob_with_retry: 1
Hello World from iothub_client_sample_upload_to_blob_with_retry: 2
Hello World from iothub_client_sample_upload_to_blob_with_retry: 3
Hello World from iothub_client_sample_upload_to_blob_with_retry: 4
Hello World from iothub_client_sample_upload_to_blob_with_retry: 5
Hello World from iothub_client_sample_upload_to_blob_with_retry: 6
Hello World from iothub_client_sample_upload_to_blob_with_retry: 7
Hello World from iothub_client_sample_upload_to_blob_with_retry: 8
Hello World from iothub_client_sample_upload_to_blob_with_retry: 9
user@ubuntu1804:/home/user/code/s1/azure-iot-sdk-c/cmake/iothub_client/samples/iothub_client_sample_upload_to_blob_with_retry$

Important points to consider in your setup:

  1. You are using the correct certificate for client authentication, and it's valid and entered correctly.
  2. Please see this temporary branch for reference on how to use the iothub_device_client with x509 logical devices: https://github.com/Azure/azure-iot-sdk-c/blob/ewertons/u2b_x509_sample/iothub_client/samples/iothub_client_sample_upload_to_blob_with_retry/iothub_client_sample_upload_to_blob_with_retry.c#L87
  3. Although you are connecting to the Azure IoT Hub using x509 authentication, the upload to blob part uses SAS tokens when it gets to connect to the Azure Storage, that's mandatory and cannot be changed as per current Azure IoT Hub design.

For reference, this is the storage account configuration we used:

user@ubuntu2404:/home/user/code/s2/azure-iot-sdk-c/cmake/iothub_client/samples/iothub_client_sample_upload_to_blob_with_retry$ az storage account show --name mystorageaccount1
{
  "accessTier": "Hot",
  "accountMigrationInProgress": null,
  "allowBlobPublicAccess": false,
  "allowCrossTenantReplication": false,
  "allowSharedKeyAccess": true,
  "allowedCopyScope": null,
  "azureFilesIdentityBasedAuthentication": null,
  "blobRestoreStatus": null,
  "creationTime": "2024-12-19T19:43:56.981226+00:00",
  "customDomain": null,
  "defaultToOAuthAuthentication": false,
  "dnsEndpointType": "Standard",
  "enableExtendedGroups": null,
  "enableHttpsTrafficOnly": true,
  "enableNfsV3": null,
  "encryption": {
    "encryptionIdentity": null,
    "keySource": "Microsoft.Storage",
    "keyVaultProperties": null,
    "requireInfrastructureEncryption": false,
    "services": {
      "blob": {
        "enabled": true,
        "keyType": "Account",
        "lastEnabledTime": "2024-12-19T19:43:57.559362+00:00"
      },
      "file": {
        "enabled": true,
        "keyType": "Account",
        "lastEnabledTime": "2024-12-19T19:43:57.559362+00:00"
      },
      "queue": null,
      "table": null
    }
  },
  "extendedLocation": null,
  "failoverInProgress": null,
  "geoReplicationStats": null,
  "id": "REDACTED",
  "identity": null,
  "immutableStorageWithVersioning": null,
  "isHnsEnabled": null,
  "isLocalUserEnabled": null,
  "isSftpEnabled": null,
  "isSkuConversionBlocked": null,
  "keyCreationTime": {
    "key1": "2024-12-19T19:43:57.121806+00:00",
    "key2": "2024-12-19T19:43:57.121806+00:00"
  },
  "keyPolicy": null,
  "kind": "StorageV2",
  "largeFileSharesState": "Enabled",
  "lastGeoFailoverTime": null,
  "location": "westus2",
  "minimumTlsVersion": "TLS1_2",
  "name": "mystorageaccount1",
  "networkRuleSet": {
    "bypass": "AzureServices",
    "defaultAction": "Allow",
    "ipRules": [],
    "ipv6Rules": [],
    "resourceAccessRules": null,
    "virtualNetworkRules": []
  },
  "primaryEndpoints": {
	REDACTED
  },
  "primaryLocation": "westus2",
  "privateEndpointConnections": [],
  "provisioningState": "Succeeded",
  "publicNetworkAccess": "Enabled",
  "resourceGroup": "REDACTED",
  "routingPreference": null,
  "sasPolicy": null,
  "secondaryEndpoints": {
	REDACTED
  },
  "secondaryLocation": "westcentralus",
  "sku": {
    "name": "Standard_RAGRS",
    "tier": "Standard"
  },
  "statusOfPrimary": "available",
  "statusOfSecondary": "available",
  "storageAccountSkuConversionStatus": null,
  "tags": {},
  "type": "Microsoft.Storage/storageAccounts"
}
user@ubuntu2404:/home/user/code/s2/azure-iot-sdk-c/cmake/iothub_client/samples/iothub_client_sample_upload_to_blob_with_retry$

@shekharg987
Copy link
Author

shekharg987 commented Jan 8, 2025

Thanks for the update.

But we are facing issue from LTS_08_2023 to LTS_08_2024 on all LTS release all are getting same error.

But it is working fine LTS_01_2023_Ref02 no socket error observed, and blob upload is success.

We are facing socket error while running the blob upload Test case in windows and Linux platform. windows log shared in comment1

**while Linux platform socket error are as follows. **

2024-11-16T14:24:52.5157478Z Sat Nov 16 14:22:50 2024 ERROR [c/c-utility/adapters/socketio_berkeley.c:1114] Socketio_Failure: Receiving data from endpoint: errno=104.
2024-11-16T14:24:52.5158253Z Sat Nov 16 14:22:50 2024 ERROR [k-c/c-utility/adapters/httpapi_compact.c:476 ] Error signalled by underlying IO
2024-11-16T14:24:52.5158970Z Sat Nov 16 14:22:50 2024 ERROR [k-c/c-utility/adapters/httpapi_compact.c:566 ] xio reported error on dowork
2024-11-16T14:24:52.5159789Z Sat Nov 16 14:22:50 2024 ERROR [k-c/c-utility/adapters/httpapi_compact.c:1276] Receive header from HTTP failed (result = HTTPAPI_READ_DATA_FAILED (10))
2024-11-16T14:24:52.5160602Z Sat Nov 16 14:22:50 2024 ERROR [zure-iot-sdk-c/c-utility/src/httpapiex.c:551 ] unable to recover sending to a working state
2024-11-16T14:24:52.5161282Z Sat Nov 16 14:22:50 2024 ERROR [ient/src/iothub_client_ll_uploadtoblob.c:156 ] unable to HTTPAPIEX_ExecuteRequest
2024-11-16T14:24:52.5161850Z Sat Nov 16 14:22:50 2024 ERROR [ient/src/iothub_client_ll_uploadtoblob.c:546 ] unable to HTTPAPIEX_ExecuteRequest
2024-11-16T14:24:52.5162485Z Sat Nov 16 14:22:50 2024 ERROR [ient/src/iothub_client_ll_uploadtoblob.c:915 ] error in IoTHubClient_LL_UploadToBlob_GetBlobCredentialsFromIoTHub
2024-11-16T14:24:52.5163115Z Sat Nov 16 14:22:50 2024 ERROR [othub_client/src/iothub_client_core_ll.c:2728] Failed initializing upload in IoT Hub
2024-11-16T14:24:52.5163719Z Sat Nov 16 14:22:50 2024 ERROR [c/iothub_client/src/iothub_client_core.c:2365] unable to IoTHubClientCore_LL_UploadToBlob

@shekharg987
Copy link
Author

othub_client/samples/iothub_client_sample_upload_to_

As we are running same sample with our connection string, we are getting error in authorization with IOTHUB fill logs are as follows.
LTS version used here LTS_08_2024.

/Documents/sdk/azure-iot-sdk-c/cmake/iothub_client/samples/iothub_client_sample_upload_to_blob_with_retry$ ./iothub_client_sample_upload_to_blob_with_retry
Starting the IoTHub client sample upload to blob...

  • Trying 20.49.109.143...
  • TCP_NODELAY set
  • Connected to sys-ih-intgr.azure-devices.net (20.49.109.143) port 443 (#0)
  • ALPN, offering http/1.1
  • successfully set certificate verify locations:
  • CAfile: /etc/ssl/certs/ca-certificates.crt
    CApath: /etc/ssl/certs
  • SSL connection using TLSv1.2 / ECDHE-RSA-AES128-SHA256
  • ALPN, server did not agree to a protocol
  • Server certificate:
  • subject: C=US; ST=Washington; L=Redmond; O=Microsoft Corporation; CN=*.azure-devices.net
  • start date: Dec 4 00:00:00 2024 GMT
  • expire date: May 4 23:59:59 2025 GMT
  • subjectAltName: host "sys-ih-intgr.azure-devices.net" matched cert's "*.azure-devices.net"
  • issuer: C=US; O=Microsoft Corporation; CN=MSFT RS256 CA-1
  • SSL certificate verify ok.

POST /devices/urn:dev:cer:81d6538c9102666de8369e0f19b2cc7f81b645ea/files/?api-version=2016-11-14 HTTP/1.1
Host: sys-ih-intgr.azure-devices.net
Content-Type: application/json
Accept: application/json
User-Agent: iothubclient/1.13.0
Content-Length: 54

  • upload completely sent off: 54 out of 54 bytes
    < HTTP/1.1 401 Unauthorized
    < Content-Length: 161
    < Content-Type: application/json; charset=utf-8
    < Server: Microsoft-HTTPAPI/2.0
    < x-ms-request-id: a8463ab7-d7a0-4cfa-ae4d-4ef69d3c11e5
    < iothub-errorcode: IotHubUnauthorizedAccess
    < Date: Mon, 20 Jan 2025 09:25:14 GMT
    <
  • Connection #0 to host sys-ih-intgr.azure-devices.net left intact
    Error: Time:Mon Jan 20 01:25:14 2025 File:/home/shekharg/Documents/sdk/azure-iot-sdk-c/c-utility/adapters/httpapi_curl.c Func:HTTPAPI_ExecuteRequest Line:816 Failure in HTTP communication: server reply code is 401
    Info: HTTP Response:{"Message":"ErrorCode:IotHubUnauthorizedAccess;Unauthorized","ExceptionMessage":"Tracking ID:a8463ab7d7a04cfaae4d4ef69d3c11e5-G:0-TimeStamp:01/20/2025 09:25:14"}
    Error: Time:Mon Jan 20 01:25:14 2025 File:/home/shekharg/Documents/sdk/azure-iot-sdk-c/iothub_client/src/iothub_client_ll_uploadtoblob.c Func:send_http_request Line:161 HTTP failed response code was 401
    Error: Time:Mon Jan 20 01:25:14 2025 File:/home/shekharg/Documents/sdk/azure-iot-sdk-c/iothub_client/src/iothub_client_ll_uploadtoblob.c Func:IoTHubClient_LL_UploadToBlob_GetBlobCredentialsFromIoTHub Line:546 unable to HTTPAPIEX_ExecuteRequest
    Error: Time:Mon Jan 20 01:25:14 2025 File:/home/shekharg/Documents/sdk/azure-iot-sdk-c/iothub_client/src/iothub_client_ll_uploadtoblob.c Func:IoTHubClient_LL_UploadToBlob_InitializeUpload Line:915 error in IoTHubClient_LL_UploadToBlob_GetBlobCredentialsFromIoTHub
    Error: Time:Mon Jan 20 01:25:14 2025 File:/home/shekharg/Documents/sdk/azure-iot-sdk-c/iothub_client/src/iothub_client_core_ll.c Func:IoTHubClientCore_LL_InitializeUpload Line:2950 Failed initializing upload in IoT Hub
    failed initializing upload in IoT Hub
    Press any key to continue
    shekharg@ubuntu:~/Documents/sdk/azure-iot-sdk-c/cmake/iothub_client/samples/iothub_client_sample_upload_to_blob_with_retry$

Same sample is not available in sdk LTS_01_2023_Ref02,

@ewertons ewertons changed the title Blob upload failing on LTS_08_2024 Blob upload failing on LTS_08_2024 with MBEDTLS Jan 21, 2025
@ewertons
Copy link
Contributor

Ok, so after our meeting we clarified that you are using the upload to blob feature building the azure-iot-sdk-c with support for mbedtls.

Doing so, I do get the 401 Unauthorized error (on ubuntu 20.04 with mbedtls 2.16, slightly different from your original setup).
It happens to be that curl installed with apt does not have support for mbedtls.
After reinstalling curl with support for mbedtls, the sample does succeed.

Please see the whole output below.

user@ubuntu2004:~$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 20.04.6 LTS
Release:        20.04
Codename:       focal
user@ubuntu2004:~$ dpkg -l | grep -E "curl|mbed"
ii  curl                                     7.68.0-1ubuntu2.25                amd64        command line tool for transferring data with URL syntax
ii  libcurl3-gnutls:amd64                    7.68.0-1ubuntu2.25                amd64        easy-to-use client-side URL transfer library (GnuTLS flavour)
ii  libcurl4:amd64                           7.68.0-1ubuntu2.25                amd64        easy-to-use client-side URL transfer library (OpenSSL flavour)
user@ubuntu2004:~$
user@ubuntu2004:~$ sudo apt-get install -y cmake build-essential libmbedtls-dev pkg-config 
...
user@ubuntu2004:~$ git clone -b ewertons/u2b_x509_sample https://github.com/azure/azure-iot-sdk-c
...
user@ubuntu2004:~$ cd azure-iot-sdk-c/
user@ubuntu2004:~/azure-iot-sdk-c$ git submodule update --init
...
user@ubuntu2004:~/azure-iot-sdk-c$ sudo ./build_all/linux/setup.sh
...
user@ubuntu2004:~/azure-iot-sdk-c$ vi iothub_client/samples/iothub_client_sample_upload_to_blob_with_retry/iothub_client_sample_upload_to_blob_with_retry.c
...
user@ubuntu2004:~/azure-iot-sdk-c$
user@ubuntu2004:~/azure-iot-sdk-c$ mkdir cmake
user@ubuntu2004:~/azure-iot-sdk-c$ cd cmake/
user@ubuntu2004:~/azure-iot-sdk-c/cmake$ cmake -DCMAKE_BUILD_TYPE=Debug -Duse_mbedtls=ON -Duse_openssl=OFF ..
-- The C compiler identification is GNU 9.4.0
-- The CXX compiler identification is GNU 9.4.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- IoT Client SDK Version = 1.13.0
-- Provisioning SDK Version = 1.13.0
-- Looking for include file stdint.h
-- Looking for include file stdint.h - found
-- Looking for include file stdbool.h
-- Looking for include file stdbool.h - found
-- target architecture: x86_64
-- Performing Test CXX_FLAG_CXX11
-- Performing Test CXX_FLAG_CXX11 - Success
-- Found CURL: /usr/lib/x86_64-linux-gnu/libcurl.so (found version "7.68.0")
-- Found CURL: /usr/lib/x86_64-linux-gnu/libcurl.so
-- target architecture: x86_64
-- IoT Hub Architecture: x86_64
-- Configuring done
-- Generating done
-- Build files have been written to: /home/user/azure-iot-sdk-c/cmake
user@ubuntu2004:~/azure-iot-sdk-c/cmake$ make -j
...
user@ubuntu2004:~/azure-iot-sdk-c/cmake$ cd iothub_client/samples/iothub_client_sample_upload_to_blob_with_retry/
user@ubuntu2004:~/azure-iot-sdk-c/cmake/iothub_client/samples/iothub_client_sample_upload_to_blob_with_retry$ ./iothub_client_sample_upload_to_blob_with_retry
Starting the IoTHub client sample upload to blob...
Error: Time:Thu Jan 23 08:33:09 2025 File:/home/user/azure-iot-sdk-c/c-utility/adapters/httpapi_curl.c Func:HTTPAPI_CreateConnection Line:190 curl_sslbackend (1) currently used by cURL does not match TLS platform (mbedTLS) used by C SDK on Linux or OSX. Please configure and compile cURL to use mbedTLS.
*   Trying 11.22.33.44:443...
* TCP_NODELAY set
* Connected to myhub.azure-devices.net (11.22.33.44) port 443 (#0)
* ALPN, offering http/1.1
* successfully set certificate verify locations:
*   CAfile: /etc/ssl/certs/ca-certificates.crt
  CApath: /etc/ssl/certs
* SSL connection using TLSv1.2 / ECDHE-RSA-AES128-GCM-SHA256
* ALPN, server did not agree to a protocol
* Server certificate:
REDACTED
*  issuer: C=US; O=Microsoft Corporation; CN=MSFT RS256 CA-1
*  SSL certificate verify ok.
> POST /devices/mydevice/files/?api-version=2016-11-14 HTTP/1.1
Host: myhub.azure-devices.net
Content-Type: application/json
Accept: application/json
User-Agent: iothubclient/1.13.0
Content-Length: 54

* upload completely sent off: 54 out of 54 bytes
* old SSL session ID is stale, removing
* Mark bundle as not supporting multiuse
< HTTP/1.1 401 Unauthorized
< content-length: 257
< content-type: application/json; charset=utf-8
< iothub-errorcode: IotHubUnauthorizedAccess
< date: Thu, 23 Jan 2025 08:33:09 GMT
<
* Connection #0 to host myhub.azure-devices.net left intact
Error: Time:Thu Jan 23 08:33:09 2025 File:/home/user/azure-iot-sdk-c/c-utility/adapters/httpapi_curl.c Func:HTTPAPI_ExecuteRequest Line:816 Failure in HTTP communication: server reply code is 401
Info: HTTP Response:{"Message":"{\"errorCode\":401002,\"message\":\"Unauthorized access\",\"trackingId\":\"REDACTED-G2:-TimeStamp:2025-01-23T08:33:09.561647177Z\",\"timestampUtc\":\"2025-01-23T08:33:09.561647177Z\",\"info\":null}","ExceptionMessage":""}
Error: Time:Thu Jan 23 08:33:09 2025 File:/home/user/azure-iot-sdk-c/iothub_client/src/iothub_client_ll_uploadtoblob.c Func:send_http_request Line:161 HTTP failed response code was 401
Error: Time:Thu Jan 23 08:33:09 2025 File:/home/user/azure-iot-sdk-c/iothub_client/src/iothub_client_ll_uploadtoblob.c Func:IoTHubClient_LL_UploadToBlob_GetBlobCredentialsFromIoTHub Line:546 unable to HTTPAPIEX_ExecuteRequest
Error: Time:Thu Jan 23 08:33:09 2025 File:/home/user/azure-iot-sdk-c/iothub_client/src/iothub_client_ll_uploadtoblob.c Func:IoTHubClient_LL_UploadToBlob_InitializeUpload Line:915 error in IoTHubClient_LL_UploadToBlob_GetBlobCredentialsFromIoTHub
Error: Time:Thu Jan 23 08:33:09 2025 File:/home/user/azure-iot-sdk-c/iothub_client/src/iothub_client_core_ll.c Func:IoTHubClientCore_LL_InitializeUpload Line:2950 Failed initializing upload in IoT Hub
failed initializing upload in IoT Hub
Press any key to continue
user@ubuntu2004:~/azure-iot-sdk-c/cmake/iothub_client/samples/iothub_client_sample_upload_to_blob_with_retry$
user@ubuntu2004:~/azure-iot-sdk-c/cmake/iothub_client/samples/iothub_client_sample_upload_to_blob_with_retry$ pushd ~
~ ~/azure-iot-sdk-c/cmake/iothub_client/samples/iothub_client_sample_upload_to_blob_with_retry
user@ubuntu2004:~$
user@ubuntu2004:~$ sudo apt-get install -y git cmake libtool autoconf
...
user@ubuntu2004:~$ git clone -b curl-7_81_0 https://github.com/curl/curl.git
...
user@ubuntu2004:~$ cd curl
user@ubuntu2004:~/curl$ autoreconf -fi
...
user@ubuntu2004:~/curl$ ./configure --with-mbedtls
...
  Host setup:       x86_64-pc-linux-gnu
  Install prefix:   /usr/local
  Compiler:         gcc
   CFLAGS:          -Werror-implicit-function-declaration -O2 -Wno-system-headers -pthread
   CPPFLAGS:
   LDFLAGS:
   LIBS:            -lmbedtls -lmbedx509 -lmbedcrypto

  curl version:     7.81.0-DEV
  SSL:              enabled (mbedTLS)
  SSH:              no      (--with-{libssh,libssh2})
  zlib:             no      (--with-zlib)
  brotli:           no      (--with-brotli)
  zstd:             no      (--with-zstd)
  GSS-API:          no      (--with-gssapi)
  GSASL:            no      (libgsasl not found)
  TLS-SRP:          no      (--enable-tls-srp)
  resolver:         POSIX threaded
  IPv6:             enabled
  Unix sockets:     enabled
  IDN:              no      (--with-{libidn2,winidn})
  Build libcurl:    Shared=yes, Static=yes
  Built-in manual:  enabled
  --libcurl option: enabled (--disable-libcurl-option)
  Verbose errors:   enabled (--disable-verbose)
  Code coverage:    disabled
  SSPI:             no      (--enable-sspi)
  ca cert bundle:   /etc/ssl/certs/ca-certificates.crt
  ca cert path:     no
  ca fallback:      no
  LDAP:             no      (--enable-ldap / --with-ldap-lib / --with-lber-lib)
  LDAPS:            no      (--enable-ldaps)
  RTSP:             enabled
  RTMP:             no      (--with-librtmp)
  PSL:              no      (libpsl not found)
  Alt-svc:          enabled (--disable-alt-svc)
  HSTS:             enabled (--disable-hsts)
  HTTP1:            enabled (internal)
  HTTP2:            no      (--with-nghttp2, --with-hyper)
  HTTP3:            no      (--with-ngtcp2, --with-quiche)
  ECH:              no      (--enable-ech)
  Protocols:        DICT FILE FTP FTPS GOPHER GOPHERS HTTP HTTPS IMAP IMAPS MQTT POP3 POP3S RTSP SMB SMBS SMTP SMTPS TELNET TFTP
  Features:         AsynchDNS HSTS IPv6 Largefile NTLM NTLM_WB SSL UnixSockets alt-svc
user@ubuntu2004:~/curl$ make -j
...
user@ubuntu2004:~/curl$ sudo apt-get remove -y curl
...
user@ubuntu2004:~/curl$ sudo make install
...
user@ubuntu2004:~/curl$ dpkg -l | grep -E "curl|mbed"
ii  libcurl3-gnutls:amd64                    7.68.0-1ubuntu2.25                amd64        easy-to-use client-side URL transfer library (GnuTLS flavour)
ii  libcurl4:amd64                           7.68.0-1ubuntu2.25                amd64        easy-to-use client-side URL transfer library (OpenSSL flavour)
ii  libcurl4-openssl-dev:amd64               7.68.0-1ubuntu2.25                amd64        development files and documentation for libcurl (OpenSSL flavour)
ii  libmbedcrypto3:amd64                     2.16.4-1ubuntu2                   amd64        lightweight crypto and SSL/TLS library - crypto library
ii  libmbedtls-dev:amd64                     2.16.4-1ubuntu2                   amd64        lightweight crypto and SSL/TLS library - development files
ii  libmbedtls12:amd64                       2.16.4-1ubuntu2                   amd64        lightweight crypto and SSL/TLS library - tls library
ii  libmbedx509-0:amd64                      2.16.4-1ubuntu2                   amd64        lightweight crypto and SSL/TLS library - x509 certificate library
user@ubuntu2004:~/curl$
user@ubuntu2004:~/curl$ cd ../azure-iot-sdk-c/cmake
user@ubuntu2004:~/azure-iot-sdk-c/cmake$ rm -rf *
user@ubuntu2004:~/azure-iot-sdk-c/cmake$ cmake -DCMAKE_BUILD_TYPE=Debug -Duse_mbedtls=ON -Duse_openssl=OFF ..
...
user@ubuntu2004:~/azure-iot-sdk-c/cmake$ make -j
...
user@ubuntu2004:~/azure-iot-sdk-c/cmake/iothub_client/samples/iothub_client_sample_upload_to_blob_with_retry$ ./iothub_client_sample_upload_to_blob_with_retry
./iothub_client_sample_upload_to_blob_with_retry: /usr/local/lib/libcurl.so.4: no version information available (required by ./iothub_client_sample_upload_to_blob_with_retry)
Starting the IoTHub client sample upload to blob...
*   Trying 11.22.33.44:443...
* Connected to myhub.azure-devices.net (11.22.33.44) port 443 (#0)
* mbedTLS: Connecting to myhub.azure-devices.net:443
* mbedTLS: Set min SSL version to TLS 1.0
* mbedTLS: Handshake complete, cipher is TLS-ECDHE-RSA-WITH-AES-128-GCM-SHA256
* Dumping cert info: * cert. version     : 3
* serial number     : REDACTED
REDACTED
* signed using      : RSA with SHA-256
* RSA key size      : 2048 bits
* basic constraints : CA=false
* subject alt name  : *.azure-devices.net, *.amqpws.azure-devices.net, *.su.management-azure-devices.net, *.mqtt.azure-devices.net, *.privatelink.mqtt.azure-devices.net, *.privatelink.amqp.azure-devices.net
* key usage         : Digital Signature, Key Encipherment
* ext key usage     : TLS Web Server Authentication, TLS Web Client Authentication

* SSL connected
> POST /devices/mydevice/files/?api-version=2016-11-14 HTTP/1.1
Host: myhub.azure-devices.net
Content-Type: application/json
Accept: application/json
User-Agent: iothubclient/1.13.0
Content-Length: 54

* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< content-length: 424
< content-type: application/json
< date: Thu, 23 Jan 2025 08:45:13 GMT
<
* Connection #0 to host myhub.azure-devices.net left intact
*   Trying 11.22.33.44:443...
* Connected to myhub.azure-devices.net (11.22.33.44) port 443 (#0)
* mbedTLS: Connecting to myhub.azure-devices.net:443
* mbedTLS: Set min SSL version to TLS 1.0
* mbedTLS: Handshake complete, cipher is TLS-ECDHE-RSA-WITH-AES-128-GCM-SHA256
* Dumping cert info: * cert. version     : 3
* serial number     : REDACTED
REDACTED
* signed using      : RSA with SHA-256
* RSA key size      : 2048 bits
* basic constraints : CA=false
* subject alt name  : *.azure-devices.net, *.amqpws.azure-devices.net, *.su.management-azure-devices.net, *.mqtt.azure-devices.net, *.privatelink.mqtt.azure-devices.net, *.privatelink.amqp.azure-devices.net
* key usage         : Digital Signature, Key Encipherment
* ext key usage     : TLS Web Server Authentication, TLS Web Client Authentication

* SSL connected
> POST /devices/mydevice/files/notifications/?api-version=2016-11-14 HTTP/1.1
Host: myhub.azure-devices.net
Content-Type: application/json
Accept: application/json
User-Agent: iothubclient/1.13.0
Content-Length: 206

* Mark bundle as not supporting multiuse
< HTTP/1.1 204 No Content
< date: Thu, 23 Jan 2025 08:45:14 GMT
<
* Connection #0 to host myhub.azure-devices.net left intact
hello world blob has been created
Press any key to continue
user@ubuntu2004:~/azure-iot-sdk-c/cmake/iothub_client/samples/iothub_client_sample_upload_to_blob_with_retry$

@shekharg987
Copy link
Author

As you suggested in previous reply
To install curl build from source with support mbedtls. Done

now getting issue as follows while running retry upload blob sample

shekhar@ubuntu:/Documents/ewerton_sdk/azure-iot-sdk-c/cmake$ cd iothub_client/samples/iothub_client_sample_upload_to_blob_with_retry
shekhar@ubuntu:
/Documents/ewerton_sdk/azure-iot-sdk-c/cmake/iothub_client/samples/iothub_client_sample_upload_to_blob_with_retry$ ./iothub_client_sample_upload_to_blob_with_retry
./iothub_client_sample_upload_to_blob_with_retry: /usr/local/lib/libcurl.so.4: no version information available (required by ./iothub_client_sample_upload_to_blob_with_retry)
Starting the IoTHub client sample upload to blob...
Error: Time:Fri Jan 24 04:35:43 2025 File:/home/shekhar/Documents/ewerton_sdk/azure-iot-sdk-c/c-utility/adapters/tlsio_mbedtls.c Func:tlsio_mbedtls_setoption Line:1003 failure calling mbedtls_pk_parse_key
Error: Time:Fri Jan 24 04:35:43 2025 File:/home/shekhar/Documents/ewerton_sdk/azure-iot-sdk-c/iothub_client/src/iothub_client_core_ll.c Func:IoTHubClientCore_LL_SetOption Line:2366 unable to IoTHubTransport_SetOption
Could not set the device x509 private keyError: Time:Fri Jan 24 04:35:43 2025 File:/home/shekhar/Documents/ewerton_sdk/azure-iot-sdk-c/c-utility/src/httpapiex.c Func:HTTPAPIEX_SetOption Line:681 error code = HTTPAPIEX_INVALID_ARG (3)
Error: Time:Fri Jan 24 04:35:43 2025 File:/home/shekhar/Documents/ewerton_sdk/azure-iot-sdk-c/iothub_client/src/iothub_client_ll_uploadtoblob.c Func:createIotHubHttpApiExHandle Line:443 unable to HTTPAPIEX_SetOption for x509 certificate
Error: Time:Fri Jan 24 04:35:43 2025 File:/home/shekhar/Documents/ewerton_sdk/azure-iot-sdk-c/iothub_client/src/iothub_client_ll_uploadtoblob.c Func:IoTHubClient_LL_UploadToBlob_GetBlobCredentialsFromIoTHub Line:516 Failed to create the HTTPAPIEX_HANDLE for Azure IoT Hub
Error: Time:Fri Jan 24 04:35:43 2025 File:/home/shekhar/Documents/ewerton_sdk/azure-iot-sdk-c/iothub_client/src/iothub_client_ll_uploadtoblob.c Func:IoTHubClient_LL_UploadToBlob_InitializeUpload Line:915 error in IoTHubClient_LL_UploadToBlob_GetBlobCredentialsFromIoTHub
Error: Time:Fri Jan 24 04:35:43 2025 File:/home/shekhar/Documents/ewerton_sdk/azure-iot-sdk-c/iothub_client/src/iothub_client_core_ll.c Func:IoTHubClientCore_LL_InitializeUpload Line:2950 Failed initializing upload in IoT Hub
failed initializing upload in IoT Hub
Press any key to continue

Some of the details are as follow
dpkg -l | grep -E "curl|mbed"
ii libavahi-core7:amd64 0.7-4ubuntu7.1 amd64 Avahi's embeddable mDNS/DNS-SD library
ii libcurl3-gnutls:amd64 7.68.0-1ubuntu2.16 amd64 easy-to-use client-side URL transfer library (GnuTLS flavour)
ii libcurl4:amd64 7.68.0-1ubuntu2.25 amd64 easy-to-use client-side URL transfer library (OpenSSL flavour)
ii libcurl4-openssl-dev:amd64 7.68.0-1ubuntu2.25 amd64 development files and documentation for libcurl (OpenSSL flavour)
ii libfontembed1:amd64 1.27.4-1 amd64 OpenPrinting CUPS Filters - Font Embed Shared library
ii libldb2:amd64 2:2.4.4-0ubuntu0.20.04.1 amd64 LDAP-like embedded database - shared library
ii libmbedcrypto3:amd64 2.16.4-1ubuntu2 amd64 lightweight crypto and SSL/TLS library - crypto library
ii libmbedtls-dev:amd64 2.16.4-1ubuntu2 amd64 lightweight crypto and SSL/TLS library - development files
ii libmbedtls12:amd64 2.16.4-1ubuntu2 amd64 lightweight crypto and SSL/TLS library - tls library
ii libmbedx509-0:amd64 2.16.4-1ubuntu2 amd64 lightweight crypto and SSL/TLS library - x509 certificate library

$ curl -V
curl 7.81.0-DEV (x86_64-pc-linux-gnu) libcurl/7.68.0 OpenSSL/1.1.1f zlib/1.2.11 brotli/1.0.7 libidn2/2.2.0 libpsl/0.21.0 (+libidn2/2.2.0) libssh/0.9.3/openssl/zlib nghttp2/1.40.0 librtmp/2.3
Release-Date: [unreleased]
Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtmp rtsp scp sftp smb smbs smtp smtps telnet tftp
Features: AsynchDNS brotli GSS-API HTTP2 HTTPS-proxy IDN IPv6 Kerberos Largefile libz NTLM NTLM_WB PSL SPNEGO SSL TLS-SRP UnixSockets
WARNING: curl and libcurl versions do not match. Functionality may be affected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants