sm: don't store info for signed writes without ENABLE_LE_SIGNED_WRITE

This commit is contained in:
Matthias Ringwald 2017-02-11 22:26:34 +01:00
parent 2d7d53414a
commit eda85fbfc3
4 changed files with 29 additions and 3 deletions

View File

@ -60,6 +60,7 @@ typedef struct le_device_memory_db {
uint8_t authenticated;
uint8_t authorized;
#ifdef ENABLE_LE_SIGNED_WRITE
// Signed Writes by remote
sm_key_t remote_csrk;
uint32_t remote_counter;
@ -67,6 +68,7 @@ typedef struct le_device_memory_db {
// Signed Writes by us
sm_key_t local_csrk;
uint32_t local_counter;
#endif
} le_device_memory_db_t;
@ -145,10 +147,12 @@ static void le_device_db_store(void) {
write_value(wFile, le_devices[i].key_size, 1);
write_value(wFile, le_devices[i].authenticated, 1);
write_value(wFile, le_devices[i].authorized, 1);
#ifdef ENABLE_LE_SIGNED_WRITE
write_hex(wFile, le_devices[i].remote_csrk, 16);
write_value(wFile, le_devices[i].remote_counter, 2);
write_hex(wFile, le_devices[i].local_csrk, 16);
write_value(wFile, le_devices[i].local_counter, 2);
#endif
fwrite("\n", 1, 1, wFile);
}
fclose(wFile);
@ -206,10 +210,12 @@ static void le_device_db_read(void){
le_devices[i].key_size = read_value(wFile, 1);
le_devices[i].authenticated = read_value(wFile, 1);
le_devices[i].authorized = read_value(wFile, 1);
#ifdef ENABLE_LE_SIGNED_WRITE
read_hex(wFile, le_devices[i].remote_csrk, 16);
le_devices[i].remote_counter = read_value(wFile, 2);
read_hex(wFile, le_devices[i].local_csrk, 16);
le_devices[i].local_counter = read_value(wFile, 2);
#endif
// read newling
fgetc(wFile);
}
@ -266,8 +272,9 @@ int le_device_db_add(int addr_type, bd_addr_t addr, sm_key_t irk){
le_devices[index].addr_type = addr_type;
memcpy(le_devices[index].addr, addr, 6);
memcpy(le_devices[index].irk, irk, 16);
#ifdef ENABLE_LE_SIGNED_WRITE
le_devices[index].remote_counter = 0;
#endif
le_device_db_store();
return index;
@ -307,6 +314,8 @@ void le_device_db_encryption_get(int index, uint16_t * ediv, uint8_t rand[8], sm
if (authorized) *authorized = device->authorized;
}
#ifdef ENABLE_LE_SIGNED_WRITE
// get signature key
void le_device_db_remote_csrk_get(int index, sm_key_t csrk){
if (index < 0 || index >= LE_DEVICE_MEMORY_SIZE){
@ -367,6 +376,7 @@ void le_device_db_local_counter_set(int index, uint32_t counter){
le_device_db_store();
}
#endif
void le_device_db_dump(void){
log_info("Central Device DB dump, devices: %d", le_device_db_count());
@ -376,7 +386,9 @@ void le_device_db_dump(void){
log_info("%u: %u %s", i, le_devices[i].addr_type, bd_addr_to_str(le_devices[i].addr));
log_info_key("ltk", le_devices[i].ltk);
log_info_key("irk", le_devices[i].irk);
#ifdef ENABLE_LE_SIGNED_WRITE
log_info_key("local csrk", le_devices[i].local_csrk);
log_info_key("remote csrk", le_devices[i].remote_csrk);
#endif
}
}

View File

@ -121,6 +121,8 @@ void le_device_db_encryption_set(int index, uint16_t ediv, uint8_t rand[8], sm_k
*/
void le_device_db_encryption_get(int index, uint16_t * ediv, uint8_t rand[8], sm_key_t ltk, int * key_size, int * authenticated, int * authorized);
#ifdef ENABLE_LE_SIGNED_WRITE
/**
* @brief set local signing key for this device
* @param index
@ -177,6 +179,8 @@ uint32_t le_device_db_local_counter_get(int index);
*/
void le_device_db_local_counter_set(int index, uint32_t counter);
#endif
/**
* @brief free device
* @param index

View File

@ -60,6 +60,7 @@ typedef struct le_device_memory_db {
uint8_t authenticated;
uint8_t authorized;
#ifdef ENABLE_LE_SIGNED_WRITE
// Signed Writes by remote
sm_key_t remote_csrk;
uint32_t remote_counter;
@ -67,6 +68,7 @@ typedef struct le_device_memory_db {
// Signed Writes by us
sm_key_t local_csrk;
uint32_t local_counter;
#endif
} le_device_memory_db_t;
@ -119,8 +121,9 @@ int le_device_db_add(int addr_type, bd_addr_t addr, sm_key_t irk){
le_devices[index].addr_type = addr_type;
memcpy(le_devices[index].addr, addr, 6);
memcpy(le_devices[index].irk, irk, 16);
#ifdef ENABLE_LE_SIGNED_WRITE
le_devices[index].remote_counter = 0;
#endif
return index;
}
@ -156,6 +159,8 @@ void le_device_db_encryption_get(int index, uint16_t * ediv, uint8_t rand[8], sm
if (authorized) *authorized = device->authorized;
}
#ifdef ENABLE_LE_SIGNED_WRITE
// get signature key
void le_device_db_remote_csrk_get(int index, sm_key_t csrk){
if (index < 0 || index >= LE_DEVICE_MEMORY_SIZE){
@ -209,6 +214,8 @@ void le_device_db_local_counter_set(int index, uint32_t counter){
le_devices[index].local_counter = counter;
}
#endif
void le_device_db_dump(void){
log_info("Central Device DB dump, devices: %d", le_device_db_count());
int i;
@ -216,7 +223,9 @@ void le_device_db_dump(void){
if (le_devices[i].addr_type == INVALID_ENTRY_ADDR_TYPE) continue;
log_info("%u: %u %s", i, le_devices[i].addr_type, bd_addr_to_str(le_devices[i].addr));
log_info_key("irk", le_devices[i].irk);
#ifdef ENABLE_LE_SIGNED_WRITE
log_info_key("local csrk", le_devices[i].local_csrk);
log_info_key("remote csrk", le_devices[i].remote_csrk);
#endif
}
}

View File

@ -1322,6 +1322,7 @@ static void sm_key_distribution_handle_all_received(sm_connection_t * sm_conn){
if (le_db_index >= 0){
#ifdef ENABLE_LE_SIGNED_WRITE
// store local CSRK
if (setup->sm_key_distribution_send_set & SM_KEYDIST_FLAG_SIGNING_IDENTIFICATION){
log_info("sm: store local CSRK");
@ -1335,7 +1336,7 @@ static void sm_key_distribution_handle_all_received(sm_connection_t * sm_conn){
le_device_db_remote_csrk_set(le_db_index, setup->sm_peer_csrk);
le_device_db_remote_counter_set(le_db_index, 0);
}
#endif
// store encryption information for secure connections: LTK generated by ECDH
if (setup->sm_use_secure_connections){
log_info("sm: store SC LTK (key size %u, authenticatd %u)", sm_conn->sm_actual_encryption_key_size, sm_conn->sm_connection_authenticated);