Skip to content

Commit

Permalink
Fixes ec/rsa key size and public key extraction handling in fetch_dev…
Browse files Browse the repository at this point in the history
…ice_public_key()
  • Loading branch information
avtolstoy authored and m-mcgowan committed Jan 15, 2018
1 parent 49beaa1 commit 84f89bf
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions hal/src/stm32f2xx/ota_flash_hal_stm32f2xx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -540,22 +540,26 @@ const uint8_t* fetch_device_public_key(uint8_t lock)
udp = HAL_Feature_Get(FEATURE_CLOUD_UDP);
#endif
const uint8_t* priv = fetch_device_private_key(1);
int error = 0;
int extracted_length = 0;
#if HAL_PLATFORM_CLOUD_UDP
if (udp)
error = extract_public_ec_key(pubkey, sizeof(pubkey), priv);
if (udp) {
extracted_length = extract_public_ec_key(pubkey, sizeof(pubkey), priv);
}
#endif
#if HAL_PLATFORM_CLOUD_TCP
if (!udp)
extract_public_rsa_key(pubkey, priv);
if (!udp) {
extract_public_rsa_key(pubkey, priv);
extracted_length = DCT_DEVICE_PUBLIC_KEY_SIZE;
}
#endif
fetch_device_private_key(0);

int offset = udp ? DCT_ALT_DEVICE_PUBLIC_KEY_OFFSET : DCT_DEVICE_PUBLIC_KEY_OFFSET;
size_t key_size = udp ? DCT_ALT_DEVICE_PUBLIC_KEY_SIZE : DCT_DEVICE_PUBLIC_KEY_SIZE;
const uint8_t* flash_pub_key = (const uint8_t*)dct_read_app_data_lock(offset);
if (!error && memcmp(pubkey, flash_pub_key, sizeof(pubkey))) {
if ((extracted_length > 0) && memcmp(pubkey, flash_pub_key, sizeof(pubkey))) {
dct_read_app_data_unlock(offset);
dct_write_app_data(pubkey, offset, DCT_DEVICE_PUBLIC_KEY_SIZE);
dct_write_app_data(pubkey, offset, key_size);
flash_pub_key = (const uint8_t*)dct_read_app_data_lock(offset);
}
return flash_pub_key;
Expand Down

0 comments on commit 84f89bf

Please sign in to comment.