@@ -8786,75 +8786,6 @@ static void new_long_term_key_callback(uint16_t index, uint16_t length,
bonding_complete(adapter, &addr->bdaddr, addr->type, 0);
}
-static void store_csrk(struct btd_adapter *adapter, const bdaddr_t *peer,
- uint8_t bdaddr_type, const unsigned char *key,
- uint32_t counter, uint8_t type)
-{
- const char *group;
- char device_addr[18];
- char filename[PATH_MAX];
- GKeyFile *key_file;
- GError *gerr = NULL;
- char key_str[33];
- gsize length = 0;
- gboolean auth;
- char *str;
- int i;
-
- switch (type) {
- case 0x00:
- group = "LocalSignatureKey";
- auth = FALSE;
- break;
- case 0x01:
- group = "RemoteSignatureKey";
- auth = FALSE;
- break;
- case 0x02:
- group = "LocalSignatureKey";
- auth = TRUE;
- break;
- case 0x03:
- group = "RemoteSignatureKey";
- auth = TRUE;
- break;
- default:
- warn("Unsupported CSRK type %u", type);
- return;
- }
-
- ba2str(peer, device_addr);
-
- create_filename(filename, PATH_MAX, "/%s/%s/info",
- btd_adapter_get_storage_dir(adapter), device_addr);
-
- key_file = g_key_file_new();
- if (!g_key_file_load_from_file(key_file, filename, 0, &gerr)) {
- error("Unable to load key file from %s: (%s)", filename,
- gerr->message);
- g_clear_error(&gerr);
- }
-
- for (i = 0; i < 16; i++)
- sprintf(key_str + (i * 2), "%2.2X", key[i]);
-
- g_key_file_set_string(key_file, group, "Key", key_str);
- g_key_file_set_integer(key_file, group, "Counter", counter);
- g_key_file_set_boolean(key_file, group, "Authenticated", auth);
-
- create_file(filename, 0600);
-
- str = g_key_file_to_data(key_file, &length, NULL);
- if (!g_file_set_contents(filename, str, length, &gerr)) {
- error("Unable set contents for %s: (%s)", filename,
- gerr->message);
- g_error_free(gerr);
- }
- g_free(str);
-
- g_key_file_free(key_file);
-}
-
static void new_csrk_callback(uint16_t index, uint16_t length,
const void *param, void *user_data)
{
@@ -8882,13 +8813,7 @@ static void new_csrk_callback(uint16_t index, uint16_t length,
return;
}
- if (!ev->store_hint)
- return;
-
- store_csrk(adapter, &key->addr.bdaddr, key->addr.type, key->val, 0,
- key->type);
-
- btd_device_set_temporary(device, false);
+ device_set_csrk(device, key->val, 0, key->type, ev->store_hint);
}
static void store_irk(struct btd_adapter *adapter, const bdaddr_t *peer,
@@ -169,6 +169,7 @@ struct ltk_info {
struct csrk_info {
uint8_t key[16];
uint32_t counter;
+ bool auth;
};
struct sirk_info {
@@ -400,6 +401,7 @@ static void store_csrk(struct csrk_info *csrk, GKeyFile *key_file,
g_key_file_set_string(key_file, group, "Key", key);
g_key_file_set_integer(key_file, group, "Counter", csrk->counter);
+ g_key_file_set_boolean(key_file, group, "Authenticated", csrk->auth);
}
static void store_sirk(struct sirk_info *sirk, GKeyFile *key_file,
@@ -1955,6 +1957,52 @@ bool btd_device_get_ltk(struct btd_device *device, uint8_t key[16],
return true;
}
+void device_set_csrk(struct btd_device *device, const uint8_t val[16],
+ uint32_t counter, uint8_t type,
+ bool store_hint)
+{
+ struct csrk_info **handle;
+ struct csrk_info *csrk;
+ bool auth;
+
+ switch (type) {
+ case 0x00:
+ handle = &device->local_csrk;
+ auth = FALSE;
+ break;
+ case 0x01:
+ handle = &device->remote_csrk;
+ auth = FALSE;
+ break;
+ case 0x02:
+ handle = &device->local_csrk;
+ auth = TRUE;
+ break;
+ case 0x03:
+ handle = &device->remote_csrk;
+ auth = TRUE;
+ break;
+ default:
+ warn("Unsupported CSRK type %u", type);
+ return;
+ }
+
+ if (!*handle)
+ *handle = g_new0(struct csrk_info, 1);
+
+ csrk = *handle;
+ memcpy(csrk->key, val, sizeof(csrk->key));
+ csrk->counter = counter;
+ csrk->auth = auth;
+
+ if (!store_hint)
+ return;
+
+ store_device_info(device);
+
+ btd_device_set_temporary(device, false);
+}
+
static bool match_sirk(const void *data, const void *match_data)
{
const struct sirk_info *sirk = data;
@@ -135,6 +135,9 @@ void device_set_ltk(struct btd_device *device, const uint8_t val[16],
bool central, uint8_t enc_size);
bool btd_device_get_ltk(struct btd_device *device, uint8_t val[16],
bool *central, uint8_t *enc_size);
+void device_set_csrk(struct btd_device *device, const uint8_t val[16],
+ uint32_t counter, uint8_t type,
+ bool store_hint);
bool btd_device_add_set(struct btd_device *device, bool encrypted,
uint8_t sirk[16], uint8_t size, uint8_t rank);
void device_store_svc_chng_ccc(struct btd_device *device, uint8_t bdaddr_type,