I have implemented an example of KVstore with security with ah simple key set and key get (SD card). After that I have removed the key set part of my code and recompiled to see if the key get code can read the value. But it don’t work. The value is empty. Any idea why?
Another problem is, that I’m not able to find a documentation about how the secure KVstore encrypts and decrypts the keys and values.
Any help is very appreciated!
void kv_store_global_api_example()
{
char kv_value_in[EXAMPLE_KV_VALUE_LENGTH] = {"kvstore_dummy_value_hello_world"};
char kv_key_in[EXAMPLE_KV_KEY_LENGTH] = {"/kv/dummy_key_enc"};
char kv_key_out[EXAMPLE_KV_KEY_LENGTH] = {0};
size_t actual_size = 0;
/* key information container */
kv_info_t info;
int res = MBED_ERROR_NOT_READY;
/* Start By Resetting the KV Storage */
/*
printf("kv_reset\n");
res = kv_reset("/kv/");
printf("kv_reset -> %d\n", err_code(res));
*/
/* Set an authenticated-encrypted 'Dummy' key with Replay protection */
/*
printf("kv_set third key with Confidentiality and Replay Protection flags\n");
res = kv_set(kv_key_in, kv_value_in, strlen(kv_value_in),
KV_REQUIRE_CONFIDENTIALITY_FLAG | KV_REQUIRE_REPLAY_PROTECTION_FLAG);
printf("kv_set -> %d\n", err_code(res));
*/
printf("kv_get_info of first key\n");
res = kv_get_info(kv_key_in, &info);
printf("kv_get_info -> %d\n", err_code(res));
printf("kv_get_info key: %s\n", kv_key_in);
printf("kv_get_info info - size: %u, flags: %u\n", info.size, info.flags);
printf("kv_get first key\n");
char *kv_first_value_out = new char[info.size + 1];
memset(kv_first_value_out, 0, info.size + 1);
res = kv_get(kv_key_in, kv_first_value_out, info.size, &actual_size);
printf("kv_get -> %d\n", err_code(res));
printf("kv_get key: %s\n", kv_key_in);
printf("kv_get value: %s\n", kv_first_value_out);
delete[] kv_first_value_out;
return;
}
I have written a small code example, that sets a key like described above. After that, I have powered off the target, removed the SD card and attached the card to my OS to see, what KVstore has created on it.
SD Card:
Folder kvstore with file dummy_key_enc.
After that I have attached the SD card back to my target, recompiled my code example but without the reset part and the set key part (see code above), to see if I am able to only read the key value of KVstore stored on the SD card. But it does not work!
So, what I want to do:
have a config file on SD card and
the possibility to update the firmware without touch the config file stored on SD card as KVstore.
I have recompiled my code example but without the reset part and the set key part (see code above, the reset part etc. is commented). I don’t understand why a simple read of a existing KVstore (SD card) don’t work!?
Re-check content of the SD card: Folder kvstore and file dummy_key_enc is present. I have also tested to set key without security. Same problem.
What is a content of your mbed_app.json ? I probably missing something.
This moment I have created only kvstore folder on my SD card but no file and also the get_kv at the end of program is empty.