in provisioning_client/src/prov_transport_http_client.c [679:764]
int prov_transport_http_open(PROV_DEVICE_TRANSPORT_HANDLE handle, const char* registration_id, BUFFER_HANDLE ek, BUFFER_HANDLE srk, PROV_DEVICE_TRANSPORT_REGISTER_CALLBACK data_callback, void* user_ctx, PROV_DEVICE_TRANSPORT_STATUS_CALLBACK status_cb, void* status_ctx, PROV_TRANSPORT_CHALLENGE_CALLBACK reg_challenge_cb, void* challenge_ctx)
{
int result;
PROV_TRANSPORT_HTTP_INFO* http_info = (PROV_TRANSPORT_HTTP_INFO*)handle;
if (http_info == NULL || data_callback == NULL || status_cb == NULL || registration_id == NULL)
{
LogError("Invalid parameter specified handle: %p, data_callback: %p, status_cb: %p, registration_id: %p", handle, data_callback, status_cb, registration_id);
result = MU_FAILURE;
}
else if ((http_info->hsm_type == TRANSPORT_HSM_TYPE_TPM || http_info->hsm_type == TRANSPORT_HSM_TYPE_SYMM_KEY) && reg_challenge_cb == NULL)
{
LogError("registration challenge callback must be set");
result = MU_FAILURE;
}
else if (http_info->hsm_type == TRANSPORT_HSM_TYPE_TPM && (ek == NULL || srk == NULL))
{
LogError("Invalid parameter specified ek: %p, srk: %p", ek, srk);
result = MU_FAILURE;
}
else if (ek != NULL && (http_info->ek = BUFFER_clone(ek)) == NULL)
{
LogError("Unable to allocate endorsement key");
result = MU_FAILURE;
}
else if (srk != NULL && (http_info->srk = BUFFER_clone(srk)) == NULL)
{
LogError("Unable to allocate storage root key");
BUFFER_delete(http_info->ek);
http_info->ek = NULL;
result = MU_FAILURE;
}
else if (mallocAndStrcpy_s(&http_info->registration_id, registration_id) != 0)
{
LogError("failure constructing registration Id");
BUFFER_delete(http_info->ek);
http_info->ek = NULL;
BUFFER_delete(http_info->srk);
http_info->srk = NULL;
result = MU_FAILURE;
}
else if ((http_info->hsm_type == TRANSPORT_HSM_TYPE_SYMM_KEY) && (http_info->sas_token = reg_challenge_cb(NULL, 0, KEY_NAME_VALUE, challenge_ctx)) == NULL)
{
LogError("failure constructing challenge value");
BUFFER_delete(http_info->ek);
http_info->ek = NULL;
BUFFER_delete(http_info->srk);
http_info->srk = NULL;
result = MU_FAILURE;
}
else
{
http_info->register_data_cb = data_callback;
http_info->user_ctx = user_ctx;
http_info->status_cb = status_cb;
http_info->status_ctx = status_ctx;
http_info->challenge_cb = reg_challenge_cb;
http_info->challenge_ctx = challenge_ctx;
if (create_connection(http_info) != 0)
{
LogError("Failure creating http connection");
if (http_info->ek != NULL)
{
BUFFER_delete(http_info->ek);
http_info->ek = NULL;
}
if (http_info->srk != NULL)
{
BUFFER_delete(http_info->srk);
http_info->srk = NULL;
}
http_info->register_data_cb = NULL;
http_info->user_ctx = NULL;
http_info->status_cb = NULL;
http_info->status_ctx = NULL;
free(http_info->registration_id);
http_info->registration_id = NULL;
result = MU_FAILURE;
}
else
{
result = 0;
}
}
return result;
}