Skip to content

Commit

Permalink
Fix file upload openssl options with x509 authentication (#2635)
Browse files Browse the repository at this point in the history
Signed-off-by: Mohit Malhotra <[email protected]>
Co-authored-by: Mohit Malhotra <[email protected]>
  • Loading branch information
ewertons and MOHIT51196 authored Jul 17, 2024
1 parent 9c6512f commit 4f17558
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 4 deletions.
4 changes: 2 additions & 2 deletions iothub_client/src/iothub_client_ll_uploadtoblob.c
Original file line number Diff line number Diff line change
Expand Up @@ -1315,7 +1315,7 @@ IOTHUB_CLIENT_RESULT IoTHubClient_LL_UploadToBlob_SetOption(IOTHUB_CLIENT_LL_UPL
}
else if (strcmp(OPTION_OPENSSL_PRIVATE_KEY_TYPE, optionName) == 0)
{
if (upload_data->cred_type != IOTHUB_CREDENTIAL_TYPE_X509)
if (upload_data->cred_type != IOTHUB_CREDENTIAL_TYPE_X509 && upload_data->cred_type != IOTHUB_CREDENTIAL_TYPE_X509_ECC)
{
LogError("trying to set a x509 private key type while the authentication scheme is not x509");
result = IOTHUB_CLIENT_INVALID_ARG;
Expand Down Expand Up @@ -1347,7 +1347,7 @@ IOTHUB_CLIENT_RESULT IoTHubClient_LL_UploadToBlob_SetOption(IOTHUB_CLIENT_LL_UPL
}
else if (strcmp(OPTION_OPENSSL_ENGINE, optionName) == 0)
{
if (upload_data->cred_type != IOTHUB_CREDENTIAL_TYPE_X509)
if (upload_data->cred_type != IOTHUB_CREDENTIAL_TYPE_X509 && upload_data->cred_type != IOTHUB_CREDENTIAL_TYPE_X509_ECC)
{
LogError("trying to set an openssl engine while the authentication scheme is not x509");
result = IOTHUB_CLIENT_INVALID_ARG;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2266,7 +2266,7 @@ TEST_FUNCTION(IoTHubClient_LL_UploadToBlob_SetOption_x509_cert_succeeds)
IoTHubClient_LL_UploadToBlob_Destroy(h);
}

TEST_FUNCTION(IoTHubClient_LL_UploadToBlob_SetOption_openssl_private_key_type_succeeds)
TEST_FUNCTION(IoTHubClient_LL_UploadToBlob_SetOption_x509_openssl_private_key_type_succeeds)
{
int privateKeyType = 1;
//arrange
Expand All @@ -2286,7 +2286,27 @@ TEST_FUNCTION(IoTHubClient_LL_UploadToBlob_SetOption_openssl_private_key_type_su
IoTHubClient_LL_UploadToBlob_Destroy(h);
}

TEST_FUNCTION(IoTHubClient_LL_UploadToBlob_SetOption_openssl_engine_type_succeeds)
TEST_FUNCTION(IoTHubClient_LL_UploadToBlob_SetOption_x509_ecc_openssl_private_key_type_succeeds)
{
int privateKeyType = 1;
//arrange
setExpectedCallsFor_IoTHubClient_LL_UploadToBlob_Create(IOTHUB_CREDENTIAL_TYPE_X509_ECC);
IOTHUB_CLIENT_LL_UPLOADTOBLOB_HANDLE h = IoTHubClient_LL_UploadToBlob_Create(&TEST_CONFIG_SAS, TEST_AUTH_HANDLE);
umock_c_reset_all_calls();

//act
STRICT_EXPECTED_CALL(gballoc_malloc(sizeof(privateKeyType)));
IOTHUB_CLIENT_RESULT result = IoTHubClient_LL_UploadToBlob_SetOption(h, OPTION_OPENSSL_PRIVATE_KEY_TYPE, &privateKeyType);

//assert
ASSERT_ARE_EQUAL(IOTHUB_CLIENT_RESULT, IOTHUB_CLIENT_OK, result);
ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());

//cleanup
IoTHubClient_LL_UploadToBlob_Destroy(h);
}

TEST_FUNCTION(IoTHubClient_LL_UploadToBlob_SetOption_x509_openssl_engine_type_succeeds)
{
const char* engine = "pkcs11";
//arrange
Expand All @@ -2308,6 +2328,28 @@ TEST_FUNCTION(IoTHubClient_LL_UploadToBlob_SetOption_openssl_engine_type_succeed
IoTHubClient_LL_UploadToBlob_Destroy(h);
}

TEST_FUNCTION(IoTHubClient_LL_UploadToBlob_SetOption_x509_ecc_openssl_engine_type_succeeds)
{
const char* engine = "pkcs11";
//arrange
setExpectedCallsFor_IoTHubClient_LL_UploadToBlob_Create(IOTHUB_CREDENTIAL_TYPE_X509_ECC);
IOTHUB_CLIENT_LL_UPLOADTOBLOB_HANDLE h = IoTHubClient_LL_UploadToBlob_Create(&TEST_CONFIG_SAS, TEST_AUTH_HANDLE);

umock_c_reset_all_calls();
STRICT_EXPECTED_CALL(mallocAndStrcpy_s(IGNORED_PTR_ARG, engine));
STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG)); // Within mallocAndStrcpy_s hook.

//act
IOTHUB_CLIENT_RESULT result = IoTHubClient_LL_UploadToBlob_SetOption(h, OPTION_OPENSSL_ENGINE, engine);

//assert
ASSERT_ARE_EQUAL(IOTHUB_CLIENT_RESULT, IOTHUB_CLIENT_OK, result);
ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());

//cleanup
IoTHubClient_LL_UploadToBlob_Destroy(h);
}

TEST_FUNCTION(IoTHubClient_LL_UploadToBlob_SetOption_Network_Interface)
{
//arrange
Expand Down

0 comments on commit 4f17558

Please sign in to comment.