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

Fix implementation of GetCertificateStore and GetDeviceCertificate #2095

Merged
merged 1 commit into from
Oct 7, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
9 changes: 6 additions & 3 deletions src/HAL/Include/nanoHAL_ConfigurationManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -186,15 +186,18 @@ extern "C"
HAL_Configuration_Wireless80211 *ConfigurationManager_GetWirelessConfigurationFromId(uint32_t configurationId);

// gets the HAL_Configuration_WirelessAP configuration block that has the specified Id, if that exists
// defined as weak needs to be free to implement the storage of the configuration block as they see fit
// memory is allocated for the configuration block, has to be free by the caller
// defined as weak to allow replacement at platform/target level to allow different storage management
HAL_Configuration_WirelessAP *ConfigurationManager_GetWirelessAPConfigurationFromId(uint32_t configurationId);

// gets the HAL_Configuration_X509CaRootBundle certificate store, if that exists
// defined as weak needs to be free to implement the storage of the configuration block as they see fit
// memory is allocated for the configuration block, has to be free by the caller
// defined as weak to allow replacement at platform/target level to allow different storage management
HAL_Configuration_X509CaRootBundle *ConfigurationManager_GetCertificateStore();

// gets the HAL_Configuration_X509DeviceCertificate device certificate, if that exists
// defined as weak needs to be free to implement the storage of the configuration block as they see fit
// memory is allocated for the configuration block, has to be free by the caller
// defined as weak to allow replacement at platform/target level to allow different storage management
HAL_Configuration_X509DeviceCertificate *ConfigurationManager_GetDeviceCertificate();

#ifdef __cplusplus
Expand Down
62 changes: 58 additions & 4 deletions src/HAL/nanoHAL_ConfigurationManager.c
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,20 @@ __nfweak HAL_Configuration_Wireless80211 *ConfigurationManager_GetWirelessConfig
{
if (g_TargetConfiguration.Wireless80211Configs->Configs[i]->Id == configurationId)
{
return g_TargetConfiguration.Wireless80211Configs->Configs[i];
// need to make a copy
HAL_Configuration_Wireless80211 *configBlock =
(HAL_Configuration_Wireless80211 *)platform_malloc(sizeof(HAL_Configuration_Wireless80211));

// check allocation
if (configBlock)
{
memcpy(
configBlock,
g_TargetConfiguration.Wireless80211Configs->Configs[i],
sizeof(HAL_Configuration_Wireless80211));

return configBlock;
}
}
}

Expand All @@ -237,7 +250,20 @@ __nfweak HAL_Configuration_WirelessAP *ConfigurationManager_GetWirelessAPConfigu
{
if (g_TargetConfiguration.WirelessAPConfigs->Configs[i]->Id == configurationId)
{
return g_TargetConfiguration.WirelessAPConfigs->Configs[i];
// need to make a copy
HAL_Configuration_WirelessAP *configBlock =
(HAL_Configuration_WirelessAP *)platform_malloc(sizeof(HAL_Configuration_WirelessAP));

// check allocation
if (configBlock)
{
memcpy(
configBlock,
g_TargetConfiguration.WirelessAPConfigs->Configs[i],
sizeof(HAL_Configuration_WirelessAP));

return configBlock;
}
}
}

Expand All @@ -249,7 +275,21 @@ __nfweak HAL_Configuration_X509CaRootBundle *ConfigurationManager_GetCertificate
{
if (g_TargetConfiguration.CertificateStore->Count)
{
return g_TargetConfiguration.CertificateStore->Certificates[0];
// need to make a copy
// need to compute size as the cert size is variable
int32_t blockSize = offsetof(HAL_Configuration_X509CaRootBundle, Certificate) +
g_TargetConfiguration.CertificateStore->Certificates[0]->CertificateSize;

HAL_Configuration_X509CaRootBundle *configBlock =
(HAL_Configuration_X509CaRootBundle *)platform_malloc(blockSize);

// check allocation
if (configBlock)
{
memcpy(configBlock, g_TargetConfiguration.CertificateStore->Certificates[0], blockSize);

return configBlock;
}
}

// not found
Expand All @@ -260,7 +300,21 @@ __nfweak HAL_Configuration_X509DeviceCertificate *ConfigurationManager_GetDevice
{
if (g_TargetConfiguration.DeviceCertificates->Count)
{
return g_TargetConfiguration.DeviceCertificates->Certificates[0];
// need to make a copy
// need to compute size as the cert size is variable
int32_t blockSize = offsetof(HAL_Configuration_X509DeviceCertificate, Certificate) +
g_TargetConfiguration.DeviceCertificates->Certificates[0]->CertificateSize;

HAL_Configuration_X509DeviceCertificate *configBlock =
(HAL_Configuration_X509DeviceCertificate *)platform_malloc(blockSize);

// check allocation
if (configBlock)
{
memcpy(configBlock, g_TargetConfiguration.DeviceCertificates->Certificates[0], blockSize);

return configBlock;
}
}

// not found
Expand Down