2021-11-03 09:03:44

by Archie Pusaka

[permalink] [raw]
Subject: [Bluez PATCH v2 1/3] adapter: Use PeripheralLongTermKey to store LTK

From: Archie Pusaka <[email protected]>

Introducing PeripheralLongTermKey group for storing LTK info to
replace the less inclusive term. Currently we still need to write/read
from both to ensure smooth transition, but later we should deprecate
the old term.

Reviewed-by: Sonny Sasaka <[email protected]>
---

Changes in v2:
- Add reason to keep duplicates as comment

src/adapter.c | 47 ++++++++++++++++++++++++++++++++++++++---------
1 file changed, 38 insertions(+), 9 deletions(-)

diff --git a/src/adapter.c b/src/adapter.c
index d0d38621b8..114ae84c10 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -3868,7 +3868,14 @@ static struct smp_ltk_info *get_peripheral_ltk_info(GKeyFile *key_file,

DBG("%s", peer);

- ltk = get_ltk(key_file, peer, bdaddr_type, "SlaveLongTermKey");
+ /* Peripheral* is the proper term, but for now read both entries
+ * so it won't break when user up/downgrades. Remove the other
+ * term after a few releases.
+ */
+ ltk = get_ltk(key_file, peer, bdaddr_type, "PeripheralLongTermKey");
+ if (!ltk)
+ ltk = get_ltk(key_file, peer, bdaddr_type, "SlaveLongTermKey");
+
if (ltk)
ltk->central = false;

@@ -8415,13 +8422,12 @@ static void new_link_key_callback(uint16_t index, uint16_t length,
bonding_complete(adapter, &addr->bdaddr, addr->type, 0);
}

-static void store_longtermkey(struct btd_adapter *adapter, const bdaddr_t *peer,
+static void store_ltk_group(struct btd_adapter *adapter, const bdaddr_t *peer,
uint8_t bdaddr_type, const unsigned char *key,
- uint8_t central, uint8_t authenticated,
+ const char *group, uint8_t authenticated,
uint8_t enc_size, uint16_t ediv,
uint64_t rand)
{
- const char *group = central ? "LongTermKey" : "SlaveLongTermKey";
char device_addr[18];
char filename[PATH_MAX];
GKeyFile *key_file;
@@ -8431,11 +8437,6 @@ static void store_longtermkey(struct btd_adapter *adapter, const bdaddr_t *peer,
char *str;
int i;

- if (central != 0x00 && central != 0x01) {
- error("Unsupported LTK type %u", central);
- return;
- }
-
ba2str(peer, device_addr);

snprintf(filename, PATH_MAX, STORAGEDIR "/%s/%s/info",
@@ -8475,6 +8476,34 @@ static void store_longtermkey(struct btd_adapter *adapter, const bdaddr_t *peer,
g_key_file_free(key_file);
}

+static void store_longtermkey(struct btd_adapter *adapter, const bdaddr_t *peer,
+ uint8_t bdaddr_type, const unsigned char *key,
+ uint8_t central, uint8_t authenticated,
+ uint8_t enc_size, uint16_t ediv,
+ uint64_t rand)
+{
+ if (central != 0x00 && central != 0x01) {
+ error("Unsupported LTK type %u", central);
+ return;
+ }
+
+ if (central) {
+ store_ltk_group(adapter, peer, bdaddr_type, key, "LongTermKey",
+ authenticated, enc_size, ediv, rand);
+ } else {
+ /* Peripheral* is the proper term, but for now keep duplicates
+ * so it won't break when user up/downgrades. Remove the other
+ * term after a few releases.
+ */
+ store_ltk_group(adapter, peer, bdaddr_type, key,
+ "PeripheralLongTermKey", authenticated,
+ enc_size, ediv, rand);
+ store_ltk_group(adapter, peer, bdaddr_type, key,
+ "SlaveLongTermKey", authenticated,
+ enc_size, ediv, rand);
+ }
+}
+
static void new_long_term_key_callback(uint16_t index, uint16_t length,
const void *param, void *user_data)
{
--
2.33.1.1089.g2158813163f-goog


2021-11-03 09:04:10

by Archie Pusaka

[permalink] [raw]
Subject: [Bluez PATCH v2 2/3] doc: Add PeripheralLongTermKey for storing LTK

From: Archie Pusaka <[email protected]>

Update doc to reflect update in adapter.c.

Reviewed-by: Sonny Sasaka <[email protected]>
---

(no changes since v1)

doc/settings-storage.txt | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/doc/settings-storage.txt b/doc/settings-storage.txt
index 1d96cd66d9..3c637c3521 100644
--- a/doc/settings-storage.txt
+++ b/doc/settings-storage.txt
@@ -314,9 +314,9 @@ Long term key) related to a remote device.
Rand Integer Randomizer


-[SlaveLongTermKey] group contains:
+[PeripheralLongTermKey] group contains:

- Same as the [LongTermKey] group, except for slave keys.
+ Same as the [LongTermKey] group, except for peripheral keys.


[ConnectionParameters] group contains:
--
2.33.1.1089.g2158813163f-goog

2021-11-03 09:05:29

by Archie Pusaka

[permalink] [raw]
Subject: [Bluez PATCH v2 3/3] adapter: Remove "Master" entry from LTK storage

From: Archie Pusaka <[email protected]>

The entry has been deprecated since 2014 and it's time to remove them
altogether.

Signed-off-by: Archie Pusaka <[email protected]>
---


(no changes since v1)

src/adapter.c | 12 ------------
1 file changed, 12 deletions(-)

diff --git a/src/adapter.c b/src/adapter.c
index 114ae84c10..508917e58d 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -3779,8 +3779,6 @@ static struct smp_ltk_info *get_ltk(GKeyFile *key_file, const char *peer,
uint8_t peer_type, const char *group)
{
struct smp_ltk_info *ltk = NULL;
- GError *gerr = NULL;
- bool central;
char *key;
char *rand = NULL;

@@ -3836,12 +3834,6 @@ static struct smp_ltk_info *get_ltk(GKeyFile *key_file, const char *peer,
NULL);
ltk->ediv = g_key_file_get_integer(key_file, group, "EDiv", NULL);

- central = g_key_file_get_boolean(key_file, group, "Master", &gerr);
- if (gerr)
- g_error_free(gerr);
- else
- ltk->central = central;
-
ltk->is_blocked = is_blocked_key(HCI_BLOCKED_KEY_TYPE_LTK,
ltk->val);

@@ -5907,7 +5899,6 @@ static void convert_ltk_entry(GKeyFile *key_file, void *value)
g_free(str);

g_key_file_set_integer(key_file, "LongTermKey", "Authenticated", auth);
- g_key_file_set_integer(key_file, "LongTermKey", "Master", central);
g_key_file_set_integer(key_file, "LongTermKey", "EncSize", enc_size);
g_key_file_set_integer(key_file, "LongTermKey", "EDiv", ediv);

@@ -8448,9 +8439,6 @@ static void store_ltk_group(struct btd_adapter *adapter, const bdaddr_t *peer,
g_error_free(gerr);
}

- /* Old files may contain this so remove it in case it exists */
- g_key_file_remove_key(key_file, "LongTermKey", "Master", NULL);
-
for (i = 0; i < 16; i++)
sprintf(key_str + (i * 2), "%2.2X", key[i]);

--
2.33.1.1089.g2158813163f-goog

2021-11-03 09:38:49

by bluez.test.bot

[permalink] [raw]
Subject: RE: [Bluez,v2,1/3] adapter: Use PeripheralLongTermKey to store LTK

This is automated email and please do not reply to this email!

Dear submitter,

Thank you for submitting the patches to the linux bluetooth mailing list.
This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/project/bluetooth/list/?series=574639

---Test result---

Test Summary:
CheckPatch PASS 4.46 seconds
GitLint PASS 3.02 seconds
Prep - Setup ELL PASS 49.79 seconds
Build - Prep PASS 0.54 seconds
Build - Configure PASS 9.54 seconds
Build - Make PASS 216.71 seconds
Make Check PASS 9.87 seconds
Make Distcheck PASS 251.91 seconds
Build w/ext ELL - Configure PASS 8.81 seconds
Build w/ext ELL - Make PASS 198.37 seconds



---
Regards,
Linux Bluetooth