-
Notifications
You must be signed in to change notification settings - Fork 513
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
Restores public server key and server address if missing #1300
Conversation
@@ -272,6 +272,16 @@ void HAL_FLASH_Read_ServerAddress(ServerAddress* server_addr) | |||
parseServerAddressData(server_addr, (const uint8_t*)data, DCT_SERVER_ADDRESS_SIZE); | |||
} | |||
|
|||
void HAL_FLASH_Write_ServerAddress(uint8_t *buf) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest that the protocol be part of the call so that the definition is self-defined and unambiguous, rather than defaulting to the current config. It will make application code simpler too, since the app also knows what kind of key is being used.
hal/inc/ota_flash_hal.h
Outdated
/* Length in bytes of DER-encoded 1024-bit RSA private key */ | ||
#define EXTERNAL_FLASH_CORE_PRIVATE_KEY_LENGTH (612) | ||
|
||
void HAL_FLASH_Read_ServerAddress(ServerAddress *server_addr); | ||
void HAL_FLASH_Write_ServerAddress(uint8_t *buf); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you make the pointer const
please :-)
@@ -475,6 +478,24 @@ void SystemEvents(const char* name, const char* data) | |||
System.reset(); | |||
} | |||
} | |||
if (!strncmp(name, KEY_RESTORE_EVENT, strlen(KEY_RESTORE_EVENT))) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the usecase for this? If your key/server address information was corrupted/removed then you won't be able to connect to server at all. And if you are already connected and you are able to receive this event from the server, it means that you probably have valid public key and server address 😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The PSK and server address can be restored in RAM from system flash... so you can connect again. We decided not to automatically restore to DCT/DCD in case of conditions still present that may have caused the first corruption; perhaps they may further corrupt something else during the next flash write. We will track metrics on units reporting corruption, and in the future enable a way for users to send the restore event.
system/inc/system_cloud.h
Outdated
@@ -179,6 +197,58 @@ ProtocolFacade* system_cloud_protocol_instance(void); | |||
|
|||
int spark_set_connection_property(unsigned property_id, unsigned data, void* datap, void* reserved); | |||
|
|||
// minimal udp public server key | |||
const unsigned char backup_udp_public_server_key[] = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These should be defined in a source file instead of a header.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, I'll make that change.
6199308
to
3d66a69
Compare
system/src/system_cloud_internal.cpp
Outdated
@@ -68,7 +68,7 @@ static sock_handle_t sparkSocket = socket_handle_invalid(); | |||
|
|||
ProtocolFacade* sp; | |||
|
|||
static Flags<ParticleKeyErrorFlag> particle_key_errors; | |||
static uint32_t particle_key_errors; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to be on a safe side I would initialize it to 0
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
Problem
There have been a number of community reports of devices losing their Public Server Key and/or Server Address. Typically this is due to a power loss or reset during a critical flash write operation.
Solution
Steps to Test
spark
tospork
and publish PUBLIC eventspork/device/key/restore
to restore PSK and Server Address.Example App
This is an internal system change. No example application.
References
Completeness
Enhancement
[PR #1300]
Restores public server key and server address if missing