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

Fail to upload long Blob using mbedtls+compact(Issue #1995) #541

Merged
merged 7 commits into from
Aug 9, 2021
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion adapters/httpapi_compact.c
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ HTTP_HANDLE HTTPAPI_CreateConnection(const char* hostName)
tlsio_config.port = 443;
tlsio_config.underlying_io_interface = NULL;
tlsio_config.underlying_io_parameters = NULL;

tlsio_config.invoke_on_send_complete_callback_for_fragments = true;
http_instance->xio_handle = xio_create(platform_get_default_tlsio(), (void*)&tlsio_config);

/*Codes_SRS_HTTPAPI_COMPACT_21_016: [ If the HTTPAPI_CreateConnection failed to create the connection, it shall return NULL as the handle. ]*/
Expand Down Expand Up @@ -1408,6 +1408,7 @@ HTTPAPI_RESULT HTTPAPI_SetOption(HTTP_HANDLE handle, const char* optionName, con
tlsio_config.port = 443;
tlsio_config.underlying_io_interface = http_proxy_io_get_interface_description();
tlsio_config.underlying_io_parameters = &proxy_config;
tlsio_config.invoke_on_send_complete_callback_for_fragments=true;

http_instance->xio_handle = xio_create(platform_get_default_tlsio(), (void*)&tlsio_config);

Expand Down
12 changes: 8 additions & 4 deletions adapters/tlsio_mbedtls.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ typedef struct TLS_IO_INSTANCE_TAG
mbedtls_ssl_session ssn;
char *trusted_certificates;

bool invoke_on_send_complete_callback_for_fragments;
char *hostname;
mbedtls_x509_crt owncert;
mbedtls_pk_context pKey;
Expand Down Expand Up @@ -373,12 +374,14 @@ static void on_send_complete(void* context, IO_SEND_RESULT send_result)
if (tls_io_instance->send_complete_info.on_send_complete != NULL &&
tls_io_instance->tlsio_state != TLSIO_STATE_CLOSING)
{
// trigger callback always on failure, otherwise call it on last fragment completion
if (send_result != IO_SEND_OK || !tls_io_instance->send_complete_info.is_fragmented_req)
{
// trigger callback always on failure, otherwise call it on last fragment completion
// In case of http communication (ie blob upload), The callback is called with each fragment
if((tls_io_instance->invoke_on_send_complete_callback_for_fragments && tls_io_instance->send_complete_info.is_fragmented_req)||
(send_result != IO_SEND_OK || !tls_io_instance->send_complete_info.is_fragmented_req))
{
void *ctx = tls_io_instance->send_complete_info.on_send_complete_callback_context;
tls_io_instance->send_complete_info.on_send_complete(ctx, send_result);
}
}
}
}
else
Expand Down Expand Up @@ -558,6 +561,7 @@ CONCRETE_IO_HANDLE tlsio_mbedtls_create(void *io_create_parameters)
result->tls_status = TLS_STATE_NOT_INITIALIZED;
mbedtls_init((void*)result);
result->tlsio_state = TLSIO_STATE_NOT_OPEN;
result->invoke_on_send_complete_callback_for_fragments = tls_io_config->invoke_on_send_complete_callback_for_fragments;
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions inc/azure_c_shared_utility/tlsio.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#ifndef TLSIO_H
#define TLSIO_H

#include <stdbool.h>
#include "xio.h"

#ifdef __cplusplus
Expand All @@ -16,6 +17,7 @@ typedef struct TLSIO_CONFIG_TAG
int port;
const IO_INTERFACE_DESCRIPTION* underlying_io_interface;
void* underlying_io_parameters;
bool invoke_on_send_complete_callback_for_fragments;
} TLSIO_CONFIG;

#ifdef __cplusplus
Expand Down
2 changes: 2 additions & 0 deletions tests/tlsio_mbedtls_ut/tlsio_mbedtls_ut.c
Original file line number Diff line number Diff line change
Expand Up @@ -880,6 +880,7 @@ BEGIN_TEST_SUITE(tlsio_mbedtls_ut)
tls_io_config.port = TEST_CONNECTION_PORT;
tls_io_config.underlying_io_interface = TEST_INTERFACE_DESC;
tls_io_config.underlying_io_parameters = NULL;
tls_io_config.invoke_on_send_complete_callback_for_fragments = false;
CONCRETE_IO_HANDLE handle = tlsio_mbedtls_create(&tls_io_config);
(void)tlsio_mbedtls_open(handle, on_io_open_complete, NULL, on_bytes_received, NULL, on_io_error, NULL);
g_open_complete(g_open_complete_ctx, IO_OPEN_OK);
Expand Down Expand Up @@ -923,6 +924,7 @@ BEGIN_TEST_SUITE(tlsio_mbedtls_ut)
tls_io_config.port = TEST_CONNECTION_PORT;
tls_io_config.underlying_io_interface = TEST_INTERFACE_DESC;
tls_io_config.underlying_io_parameters = NULL;
tls_io_config.invoke_on_send_complete_callback_for_fragments = false;
CONCRETE_IO_HANDLE handle = tlsio_mbedtls_create(&tls_io_config);
(void)tlsio_mbedtls_open(handle, on_io_open_complete, NULL, on_bytes_received, NULL, on_io_error, NULL);
g_open_complete(g_open_complete_ctx, IO_OPEN_OK);
Expand Down