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
588 stars 739 forks source link

Linking issues of iothub_auth_client #2336

Closed jorunv closed 2 years ago

jorunv commented 2 years ago

Hi,

First of all, apologies if this counts as a duplicate bug report, but i'm not sure if a comment on a closed issue gets noticed or picked up.

I'm currently working on a minimal MQTT IoThub implementation that does exactly the same as described in #598 .

Similarly I get the following linking issues when not adding the 'prov_auth_client' and 'hsm_security_client' as target link libraries.

/usr/bin/ld: CMakeFiles/cloud.dir/home/jorun/Documents/Linux/sb-linux/nano-esp32/components/cloud/cloud.c.o: in function init_connection: /home/jorun/Documents/Linux/sb-linux/nano-esp32/components/cloud/cloud.c:652: undefined reference to MQTT_WebSocket_Protocol 
/usr/bin/ld: /home/jorun/local/lib/libiothub_client_mqtt_transport.a(iothub_client_authorization.c.o): in function IoTHubClient_Auth_CreateFromDeviceAuth: /home/jorun/Documents/Linux/azure-iot-sdk-c/iothub_client/src/iothub_client_authorization.c:181: undefined reference to iothub_device_auth_create 
/usr/bin/ld: /home/jorun/Documents/Linux/azure-iot-sdk-c/iothub_client/src/iothub_client_authorization.c:192: undefined reference to iothub_device_auth_get_type 
/usr/bin/ld: /home/jorun/local/lib/libiothub_client_mqtt_transport.a(iothub_client_authorization.c.o): in function IoTHubClient_Auth_Destroy: /home/jorun/Documents/Linux/azure-iot-sdk-c/iothub_client/src/iothub_client_authorization.c:217: undefined reference to iothub_device_auth_destroy 
/usr/bin/ld: /home/jorun/local/lib/libiothub_client_mqtt_transport.a(iothub_client_authorization.c.o): in function IoTHubClient_Auth_Set_xio_Certificate: /home/jorun/Documents/Linux/azure-iot-sdk-c/iothub_client/src/iothub_client_authorization.c:275: undefined reference to iothub_device_auth_generate_credentials 
/usr/bin/ld: /home/jorun/local/lib/libiothub_client_mqtt_transport.a(iothub_client_authorization.c.o): in function IoTHubClient_Auth_Get_x509_info: /home/jorun/Documents/Linux/azure-iot-sdk-c/iothub_client/src/iothub_client_authorization.c:323: undefined reference to iothub_device_auth_generate_credentials 
/usr/bin/ld: /home/jorun/local/lib/libiothub_client_mqtt_transport.a(iothub_client_authorization.c.o): in function IoTHubClient_Auth_Get_SasToken: /home/jorun/Documents/Linux/azure-iot-sdk-c/iothub_client/src/iothub_client_authorization.c:402: undefined reference to iothub_device_auth_generate_credentials 

However when I do add these libraries, as shown below, I encounter a lot of issues with linking the hsm_security_client. Did anyone encounter this issue as well or is there a workaround or fix for this?

# adding the extra link libraries
target_link_libraries(cloud
    iothub_client
    iothub_client_mqtt_transport
    iothub_client_mqtt_ws_transport
    iothub_client_http_transport
    iothub_client_amqp_transport
    iothub_client_amqp_ws_transport
    prov_auth_client
    hsm_security_client
    parson
    aziotsharedutil
    umqtt
    uhttp
    uamqp)

These are the issues that followed when adding both libraries:

/usr/bin/ld: /home/jorun/local/lib/libhsm_security_client.a(hsm_client_tpm.c.o): in function GetEkTemplate: /home/jorun/Documents/Linux/azure-iot-sdk-c/provisioning_client/adapters/hsm_client_tpm.c:79: undefined reference to ToTpmaObject 
/usr/bin/ld: /home/jorun/local/lib/libhsm_security_client.a(hsm_client_tpm.c.o): in function GetSrkTemplate: /home/jorun/Documents/Linux/azure-iot-sdk-c/provisioning_client/adapters/hsm_client_tpm.c:96: undefined reference to ToTpmaObject 
/usr/bin/ld: /home/jorun/local/lib/libhsm_security_client.a(hsm_client_tpm.c.o): in function dps_umarshal_array: /home/jorun/Documents/Linux/azure-iot-sdk-c/provisioning_client/adapters/hsm_client_tpm.c:140: undefined reference to UINT32_Unmarshal /usr/bin/ld: /home/jorun/local/lib/libhsm_security_client.a(hsm_client_tpm.c.o): in function unmarshal_array: /home/jorun/Documents/Linux/azure-iot-sdk-c/provisioning_client/adapters/hsm_client_tpm.c:160: undefined reference to UINT32_Unmarshal 
/usr/bin/ld: /home/jorun/local/lib/libhsm_security_client.a(hsm_client_tpm.c.o): in function marshal_array_values: /home/jorun/Documents/Linux/azure-iot-sdk-c/provisioning_client/adapters/hsm_client_tpm.c:192: undefined reference to UINT32_Unmarshal /usr/bin/ld: /home/jorun/Documents/Linux/azure-iot-sdk-c/provisioning_client/adapters/hsm_client_tpm.c:199: undefined reference to UINT32_Unmarshal 
/usr/bin/ld: /home/jorun/Documents/Linux/azure-iot-sdk-c/provisioning_client/adapters/hsm_client_tpm.c:206: undefined reference to UINT32_Unmarshal
/usr/bin/ld: /home/jorun/Documents/Linux/azure-iot-sdk-c/provisioning_client/adapters/hsm_client_tpm.c:213: undefined reference to TPM2B_PUBLIC_Unmarshal
/usr/bin/ld: /home/jorun/Documents/Linux/azure-iot-sdk-c/provisioning_client/adapters/hsm_client_tpm.c:220: undefined reference to UINT16_Unmarshal 
/usr/bin/ld: /home/jorun/Documents/Linux/azure-iot-sdk-c/provisioning_client/adapters/hsm_client_tpm.c:227: undefined reference to TPM2B_PRIVATE_Unmarshal 
/usr/bin/ld: /home/jorun/local/lib/libhsm_security_client.a(hsm_client_tpm.c.o): in function create_tpm_session: /home/jorun/Documents/Linux/azure-iot-sdk-c/provisioning_client/adapters/hsm_client_tpm.c:244: undefined reference to TSS_StartAuthSession /usr/bin/ld: /home/jorun/Documents/Linux/azure-iot-sdk-c/provisioning_client/adapters/hsm_client_tpm.c:249: undefined reference to TSS_PolicySecret 
/usr/bin/ld: /home/jorun/local/lib/libhsm_security_client.a(hsm_client_tpm.c.o): in function insert_key_in_tpm: /home/jorun/Documents/Linux/azure-iot-sdk-c/provisioning_client/adapters/hsm_client_tpm.c:286: undefined reference to TPM2B_ID_OBJECT_Unmarshal 
/usr/bin/ld: /home/jorun/Documents/Linux/azure-iot-sdk-c/provisioning_client/adapters/hsm_client_tpm.c:287: undefined reference to TPM2B_ENCRYPTED_SECRET_Unmarshal' 
/usr/bin/ld: /home/jorun/Documents/Linux/azure-iot-sdk-c/provisioning_client/adapters/hsm_client_tpm.c:288: undefined reference to TPM2B_PRIVATE_Unmarshal 
/usr/bin/ld: /home/jorun/Documents/Linux/azure-iot-sdk-c/provisioning_client/adapters/hsm_client_tpm.c:289: undefined reference to TPM2B_ENCRYPTED_SECRET_Unmarshal 
/usr/bin/ld: /home/jorun/Documents/Linux/azure-iot-sdk-c/provisioning_client/adapters/hsm_client_tpm.c:290: undefined reference to TPM2B_PUBLIC_Unmarshal 
/usr/bin/ld: /home/jorun/Documents/Linux/azure-iot-sdk-c/provisioning_client/adapters/hsm_client_tpm.c:295: undefined reference to UINT16_Unmarshal 
/usr/bin/ld: /home/jorun/Documents/Linux/azure-iot-sdk-c/provisioning_client/adapters/hsm_client_tpm.c:297: undefined reference to TPM2_ActivateCredential 
/usr/bin/ld: /home/jorun/Documents/Linux/azure-iot-sdk-c/provisioning_client/adapters/hsm_client_tpm.c:303: undefined reference to TPM2_Import 
/usr/bin/ld: /home/jorun/Documents/Linux/azure-iot-sdk-c/provisioning_client/adapters/hsm_client_tpm.c:323: undefined reference to ToTpmaObject
/usr/bin/ld: /home/jorun/Documents/Linux/azure-iot-sdk-c/provisioning_client/adapters/hsm_client_tpm.c:331: undefined reference to TSS_Create 
/usr/bin/ld: /home/jorun/Documents/Linux/azure-iot-sdk-c/provisioning_client/adapters/hsm_client_tpm.c:336: undefined reference to TPM2_Load 
/usr/bin/ld: /home/jorun/Documents/Linux/azure-iot-sdk-c/provisioning_client/adapters/hsm_client_tpm.c:344: undefined reference to TPM2_EvictControl
/usr/bin/ld: /home/jorun/Documents/Linux/azure-iot-sdk-c/provisioning_client/adapters/hsm_client_tpm.c:346: undefined reference to TPM2_EvictControl 
/usr/bin/ld: /home/jorun/Documents/Linux/azure-iot-sdk-c/provisioning_client/adapters/hsm_client_tpm.c:351: undefined reference to TPM2_FlushContext 
/usr/bin/ld: /home/jorun/local/lib/libhsm_security_client.a(hsm_client_tpm.c.o): in function decrypt_data: /home/jorun/Documents/Linux/azure-iot-sdk-c/provisioning_client/adapters/hsm_client_tpm.c:377: undefined reference to TSS_GetTpmProperty 
/usr/bin/ld: /home/jorun/Documents/Linux/azure-iot-sdk-c/provisioning_client/adapters/hsm_client_tpm.c:396: undefined reference to TPM2B_ID_OBJECT_Unmarshal
/usr/bin/ld: /home/jorun/Documents/Linux/azure-iot-sdk-c/provisioning_client/adapters/hsm_client_tpm.c:397: undefined reference to TPM2B_ENCRYPTED_SECRET_Unmarshal 
/usr/bin/ld: /home/jorun/Documents/Linux/azure-iot-sdk-c/provisioning_client/adapters/hsm_client_tpm.c:398: undefined reference to TPM2B_PRIVATE_Unmarshal 
/usr/bin/ld: /home/jorun/Documents/Linux/azure-iot-sdk-c/provisioning_client/adapters/hsm_client_tpm.c:399: undefined reference to TPM2B_ENCRYPTED_SECRET_Unmarshal
/usr/bin/ld: /home/jorun/Documents/Linux/azure-iot-sdk-c/provisioning_client/adapters/hsm_client_tpm.c:400: undefined reference to TPM2B_PUBLIC_Unmarshal 
/usr/bin/ld: /home/jorun/Documents/Linux/azure-iot-sdk-c/provisioning_client/adapters/hsm_client_tpm.c:405: undefined reference to UINT16_Unmarshal 
/usr/bin/ld: /home/jorun/Documents/Linux/azure-iot-sdk-c/provisioning_client/adapters/hsm_client_tpm.c:423: undefined reference to TPM2_ActivateCredential 
/usr/bin/ld: /home/jorun/local/lib/libhsm_security_client.a(hsm_client_tpm.c.o): in function initialize_tpm_device: /home/jorun/Documents/Linux/azure-iot-sdk-c/provisioning_client/adapters/hsm_client_tpm.c:445: undefined reference to TSS_CreatePwAuthSession 
/usr/bin/ld: /home/jorun/Documents/Linux/azure-iot-sdk-c/provisioning_client/adapters/hsm_client_tpm.c:450: undefined reference to Initialize_TPM_Codec 
/usr/bin/ld: /home/jorun/Documents/Linux/azure-iot-sdk-c/provisioning_client/adapters/hsm_client_tpm.c:455: undefined reference to TSS_CreatePersistentKey 
/usr/bin/ld: /home/jorun/Documents/Linux/azure-iot-sdk-c/provisioning_client/adapters/hsm_client_tpm.c:460: undefined reference to TSS_CreatePersistentKey 
/usr/bin/ld: /home/jorun/local/lib/libhsm_security_client.a(hsm_client_tpm.c.o): in function hsm_client_tpm_destroy: /home/jorun/Documents/Linux/azure-iot-sdk-c/provisioning_client/adapters/hsm_client_tpm.c:499: undefined reference to Deinit_TPM_Codec 
/usr/bin/ld: /home/jorun/local/lib/libhsm_security_client.a(hsm_client_tpm.c.o): in function hsm_client_tpm_get_endorsement_key: /home/jorun/Documents/Linux/azure-iot-sdk-c/provisioning_client/adapters/hsm_client_tpm.c:561: undefined reference to TPM2B_PUBLIC_Marshal 
/usr/bin/ld: /home/jorun/local/lib/libhsm_security_client.a(hsm_client_tpm.c.o): in function hsm_client_tpm_get_storage_key: /home/jorun/Documents/Linux/azure-iot-sdk-c/provisioning_client/adapters/hsm_client_tpm.c:603: undefined reference to TPM2B_PUBLIC_Marshal
/usr/bin/ld: /home/jorun/local/lib/libhsm_security_client.a(hsm_client_tpm.c.o): in function hsm_client_tpm_sign_data: /home/jorun/Documents/Linux/azure-iot-sdk-c/provisioning_client/adapters/hsm_client_tpm.c:639: undefined reference to SignData 
danewalton commented 2 years ago

it looks like you might be missing the linking for utpm?

So try something like

target_link_libraries(cloud
    iothub_client
    iothub_client_mqtt_transport
    iothub_client_mqtt_ws_transport
    iothub_client_http_transport
    iothub_client_amqp_transport
    iothub_client_amqp_ws_transport
    prov_auth_client
    hsm_security_client
    parson
    aziotsharedutil
    utpm
    umqtt
    uhttp
    uamqp)
ericwolz commented 2 years ago

yes, these should be defined in utpm.

For example TPM2_EvictControl() is here

https://github.com/Azure/azure-utpm-c/blob/bf5e782c6a37431beec3cf2baa199d52e127a2bf/src/tpm_codec.c#L848

jorunv commented 2 years ago

Hi, thank you for your feedback! Utmp is indeed what was missing in my cmake target link libraries. Adding it resolved my issues.