Skip to content

Commit

Permalink
Added ability to read and set the trusted cert option for the Nested … (
Browse files Browse the repository at this point in the history
#30)

* Added ability to read and set the trusted cert option for the Nested Edge scenario

* Changed the certificate_path delimeter to edgegateway_cert_path to increase readability.
  • Loading branch information
nihemstr authored Mar 31, 2021
1 parent bbcfb1c commit c026314
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/adu_types/inc/aduc/adu_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ typedef enum tagADUC_AuthType
ADUC_AuthType_NotSet = 0,
ADUC_AuthType_SASToken = 1,
ADUC_AuthType_SASCert = 2,

ADUC_AuthType_NestedEdgeCert = 3,
} ADUC_AuthType;

/**
Expand Down
13 changes: 11 additions & 2 deletions src/agent/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,15 @@ _Bool ADUC_DeviceClient_Create(ADUC_ConnectionInfo* connInfo, const ADUC_LaunchA
Log_Error("Unable to set IotHub certificate, error=%d", iothubResult);
result = false;
}
else if (
connInfo->certificateString != NULL && connInfo->authType == ADUC_AuthType_NestedEdgeCert
&& (iothubResult =
ClientHandle_SetOption(g_iotHubClientHandle, OPTION_TRUSTED_CERT, connInfo->certificateString))
!= IOTHUB_CLIENT_OK)
{
Log_Error("Could not add trusted certificate, error=%d ", iothubResult);
result = false;
}
else if (
connInfo->opensslEngine != NULL && connInfo->authType == ADUC_AuthType_SASCert
&& (iothubResult =
Expand Down Expand Up @@ -628,7 +637,7 @@ _Bool GetConnectionInfoFromADUConfigFile(ADUC_ConnectionInfo* info)

// Optional: The certificate string is needed for Edge Gateway connection.
if (ReadDelimitedValueFromFile(
ADUC_CONF_FILE_PATH, "certificate_path", certificatePath, ARRAY_SIZE(certificatePath)))
ADUC_CONF_FILE_PATH, "edgegateway_cert_path", certificatePath, ARRAY_SIZE(certificatePath)))
{
if (!LoadBufferWithFileContents(certificatePath, certificateString, ARRAY_SIZE(certificateString)))
{
Expand All @@ -642,7 +651,7 @@ _Bool GetConnectionInfoFromADUConfigFile(ADUC_ConnectionInfo* info)
goto done;
}

info->authType = ADUC_AuthType_SASCert;
info->authType = ADUC_AuthType_NestedEdgeCert;
}

succeeded = true;
Expand Down

0 comments on commit c026314

Please sign in to comment.