From patchwork Wed Nov 3 09:02:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Archie Pusaka X-Patchwork-Id: 12600447 X-Patchwork-Delegate: luiz.dentz@gmail.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2C68DC433F5 for ; Wed, 3 Nov 2021 09:03:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0F1B6611C9 for ; Wed, 3 Nov 2021 09:03:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231755AbhKCJFl (ORCPT ); Wed, 3 Nov 2021 05:05:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39890 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231709AbhKCJFk (ORCPT ); Wed, 3 Nov 2021 05:05:40 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7EAB3C061714 for ; Wed, 3 Nov 2021 02:03:04 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id h185-20020a256cc2000000b005bdce4db0easo3131178ybc.12 for ; Wed, 03 Nov 2021 02:03:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:message-id:mime-version:subject:from:to:cc; bh=bIe43DMC+hVNx274dZvwV5NiQPHCOMhtMi2x8daakaQ=; b=AVcdizCpSpMltW+Xut7W/8Irq/gOAvqCgt0LOINzK9fS2/lSmreNX1MjyvVnspq18E U2FSkApiD5zgsNjfBAPKaElaM1uW4/cKKn1bYEaMnEe7IkVXiL1YhxVZjO+YVNjz152T dsYk32ZlDHsbGiHvbBw10lpEy+eIFnlYGqRonE4HBIATYof+axhfpBK82C9xTZYkYfiC eGedDsA3Z/jiXuaNwsZfXB6zjAVr7EUn5U2160kaLtakAXbTX+lK3p6yhE1CVUeHLAI+ /ramtb0M1viDtCChJoZJWUy+RXtIQS7olK/I3RBIvXMonujG3R9cR1hwXeKtjrqjNp3G mpyQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=bIe43DMC+hVNx274dZvwV5NiQPHCOMhtMi2x8daakaQ=; b=feQJfGYcgAAeI46PBTcUHT0jfbPScMGYLyx+eO5ivzFhTdesc43xCWDmHCs+dWMoNF 6BuqBNeDg6GcQ+pambxFBaxqluHDAXXZPlL6oGmcnFFBPsH/bBlC/NP+Q6E+jMdlCUDZ WRxbCUbKtR+O6YQiOHBp8+7VMyCPOKLtokb7CZWzkzedPWCrBsPbRZzdU/ClTXU0Jj3Z oa+TEUshbQQwdUhWvZG/X916b4qRihaKKO2nvXfN7tKXiPQvZg7J4/c/aRpcxC+4f/7N tf+cLh0Fl3T2QurFimxjeG44xGldYnQ1mUD0ek9xuM183WjAeFu1mwLHC8KUTQynRI1B DGcg== X-Gm-Message-State: AOAM532cEXtIG+aFG3tGpXzN3JqegvaznBuYsUWyg0RUgCKFuG/VUC7s z74qwD2LFF/zVj+6lUXxmxAjsl+GQdw7RQlkQTsZ6Sk6f6KDtpcMpLSCIIEVSQZVLuLzwx4KPzj IuKcc7XWFsT+cDRVTbj8QaA8Dx/4yq50GTP6YxCFnbBI1Rjqx54sr7mHBLnhDg+io0bSeqoVBak 6b X-Google-Smtp-Source: ABdhPJx8gsKPIhWShNSrImJpq4Bf/u4PHiLnczpAtBssuvzQDAAblcynhdtNXz7/03LvAfNEGKZ9Qv3k1FGO X-Received: from apusaka-p920.tpe.corp.google.com ([2401:fa00:1:10:7af7:a937:5810:b542]) (user=apusaka job=sendgmr) by 2002:a25:b9cd:: with SMTP id y13mr7266461ybj.407.1635930183482; Wed, 03 Nov 2021 02:03:03 -0700 (PDT) Date: Wed, 3 Nov 2021 17:02:53 +0800 Message-Id: <20211103170206.Bluez.v2.1.I515833d2764b8ec2ac2bb1f87313de80ebb497cd@changeid> Mime-Version: 1.0 X-Mailer: git-send-email 2.33.1.1089.g2158813163f-goog Subject: [Bluez PATCH v2 1/3] adapter: Use PeripheralLongTermKey to store LTK From: Archie Pusaka To: linux-bluetooth , Luiz Augusto von Dentz , Marcel Holtmann Cc: CrosBT Upstreaming , Archie Pusaka , Sonny Sasaka Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Archie Pusaka 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 --- 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) { From patchwork Wed Nov 3 09:02:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Archie Pusaka X-Patchwork-Id: 12600449 X-Patchwork-Delegate: luiz.dentz@gmail.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7B232C433F5 for ; Wed, 3 Nov 2021 09:03:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 66C42611F0 for ; Wed, 3 Nov 2021 09:03:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232011AbhKCJFr (ORCPT ); Wed, 3 Nov 2021 05:05:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39918 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231986AbhKCJFp (ORCPT ); Wed, 3 Nov 2021 05:05:45 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 53165C061205 for ; Wed, 3 Nov 2021 02:03:09 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id b126-20020a251b84000000b005bd8aca71a2so3206416ybb.4 for ; Wed, 03 Nov 2021 02:03:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=1ba15R92iDLtdAosS9I3xgQG4qhaOlyBbyIkYWCKw8I=; b=LF8jocn0iekS/C3t/RX1cGOuwesZ4e8To2amBbMwtKK+r23hpXu6AEDfYDASEKa4iP 9bqn+bBZ0bSrN7guhv3IJI9MRzAIguRm0KDDHqMMpzlK4oATvxXNcpy/spiNxk4ULZU2 wHVtRAIyQ1cXPVtsUVHhum+Bs7vaUiWDicMSK5QIUo9zc+IzqsG5fOuVt3YuMdq3Es7W ZY2+jJAoK7E58EtckMUD1XBxtjqriEYddAaN+mqt7LcEpgrgYdLC2wQUZESQSql6WVL7 gqzRwWNaiRIsktMOTPWtxJvrtM/7iPntfnxG9XIUsTPmGP/G/ejK9wY1utdOZHK/wn4n Hopw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=1ba15R92iDLtdAosS9I3xgQG4qhaOlyBbyIkYWCKw8I=; b=eAm9iPJMzCKpQVJp2xLyKla8qd5OJ/cvkv+xRHVHY5lozeF8TzNbTz62N+OiFVUj3x KAJVCkoGpou5VPNRfz32MKOCpvEBQeAnWaYdCt4HxF8oZ3ojViX33G3DmQ9vS76SPDOd dOuJREG6JV2b9n/RJCtCWJ79CKDy8toiRDC6ll0Z0rfCR4HsZYIO+k7522n5A2HXur8o fcbyrMmcFt7SoI+i5ml00+0pWWwXaQzDqyQIQvjl8eL7A1M72F9qY843EQCOarFYSAhS BRJixUvcB5QsIehZGlec3sRtOy/Kdp4ozS05xpfWZTOx76L/VtSpaTjx4P7blTDkNiN3 6vpA== X-Gm-Message-State: AOAM531n0lyQegxL7ldzgYsx8DkAmSMD/9chSbyyfjDL+FV56OeIQ1iK W33PG5RPOtkzXaAgR9kKg7OT2AbOGMUtIpjhtSVsDq1NJcr/JHHtzmlasDlAXBpn4I8J27DkXIF TBdnXNq4TmAsOtkkG16hLjeELdQD2MqTtgKx2N4UOi1TBL9roINl7Q7zEyJ6HnaxPHSQKLd6dy8 ML X-Google-Smtp-Source: ABdhPJwgIuRMrKckuisCSKiBQPxntjEDm8ekiRE3+ZcnlK3+BU6U1SOVrLZFCDsU5UdaGA9aFc7gSnlMSMJ9 X-Received: from apusaka-p920.tpe.corp.google.com ([2401:fa00:1:10:7af7:a937:5810:b542]) (user=apusaka job=sendgmr) by 2002:a25:a268:: with SMTP id b95mr44659568ybi.35.1635930188549; Wed, 03 Nov 2021 02:03:08 -0700 (PDT) Date: Wed, 3 Nov 2021 17:02:54 +0800 In-Reply-To: <20211103170206.Bluez.v2.1.I515833d2764b8ec2ac2bb1f87313de80ebb497cd@changeid> Message-Id: <20211103170206.Bluez.v2.2.I1e75e215e52ece8017840d4df309c4ba4ac84510@changeid> Mime-Version: 1.0 References: <20211103170206.Bluez.v2.1.I515833d2764b8ec2ac2bb1f87313de80ebb497cd@changeid> X-Mailer: git-send-email 2.33.1.1089.g2158813163f-goog Subject: [Bluez PATCH v2 2/3] doc: Add PeripheralLongTermKey for storing LTK From: Archie Pusaka To: linux-bluetooth , Luiz Augusto von Dentz , Marcel Holtmann Cc: CrosBT Upstreaming , Archie Pusaka , Sonny Sasaka Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Archie Pusaka Update doc to reflect update in adapter.c. Reviewed-by: Sonny Sasaka --- (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: From patchwork Wed Nov 3 09:02:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Archie Pusaka X-Patchwork-Id: 12600451 X-Patchwork-Delegate: luiz.dentz@gmail.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2924CC433EF for ; Wed, 3 Nov 2021 09:03:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1637861101 for ; Wed, 3 Nov 2021 09:03:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232077AbhKCJF6 (ORCPT ); Wed, 3 Nov 2021 05:05:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39990 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232095AbhKCJFy (ORCPT ); Wed, 3 Nov 2021 05:05:54 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0AC2DC061228 for ; Wed, 3 Nov 2021 02:03:15 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id g36-20020a25ae64000000b005c1f46f7ee6so3145586ybe.8 for ; Wed, 03 Nov 2021 02:03:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=qO4nWP74PgUYZ6ku/F35jiPU7Ia3HjCxnhp1F2jmYls=; b=JfNgJBf8+g6NhFNfAtdkHw9ACZfdgVKx8b+QcKTyxKchfDwFEqsEAefTMwF0b2Cpzq ybRDT9RH0fllh52jPENHmjjq4aArWzHfkON5xYA/pRrbJwDA4MoZxnVTOmUEhKrDMIOZ 52/pIUs6C2bOdDdJayTK//RtL79vKHz2BzMaq4FoUP9s1tC3N92FNzE1bBb2KoJjLjpk 30wkO2DPxgI7CBB563C69nLRhSleIAnVqO6GjRo+HEsHpsEbcf7XLKhSctHUcJV6Bm8o GHC7O8GS45L3M9KIjNpO5uVzeNBzGaqGdWTWi1xOuhMM8Fpd5NYea7YPheDmT5htrAAT n/nQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=qO4nWP74PgUYZ6ku/F35jiPU7Ia3HjCxnhp1F2jmYls=; b=PwXWJBVasB8r7un9JXnU42X5DORieVbGAWRZZEU6DHX2pwm+L8Gs1UZTmyImyIUCDi OHdchfW1spklqQWq/MXtxGwmrkbOU0J0hU3hWEx/O9sT85SYe2Tid6SbI8BUzvvsDCeK l8/TawLYPXf/kF3vmANyX0+mt9kfpn4KRKjDF4e/4Sz40xlzGjCQBpiBZ0qKVu0jU2C1 e2WUwPg6GykUu8jdGTQ7McfGqqvq6Y3fTSZuG2Vlpm7GA2NAYbE+gNnKuBecaMTQgvX2 fQ0k12kU9tKsKYkEHWWxLD8avPBI7TR7KVFHcMT/l9RD1jwPTtYMXA6UmQt510q/tiQq HsQw== X-Gm-Message-State: AOAM531IYW5lkWVvFRql+limUr8z02qCex47DMJ0vh0+YimQrR5BDS/X uicfStSq9GRXxPDkdrytV/hOzvltraQZwj4gU3xHcfdxAJRuqUg/TY+cvwjAQd32LWY7yrcficy C0ccnC9DNcUoDz0BUvpbxd20QaNxFBt8J+xADz7E7i4GFkMJUjzdBDuho5Drh3Z1flEHCGpwmRL 5i X-Google-Smtp-Source: ABdhPJwkfNjYZCpWboNtttkY2mOVvL3/1702/9cHQqtEPGKK8i+DLsrRWuD2BYrs4OqHs1uvN9ViimA5s4X8 X-Received: from apusaka-p920.tpe.corp.google.com ([2401:fa00:1:10:7af7:a937:5810:b542]) (user=apusaka job=sendgmr) by 2002:a05:6902:100b:: with SMTP id w11mr18971055ybt.64.1635930194158; Wed, 03 Nov 2021 02:03:14 -0700 (PDT) Date: Wed, 3 Nov 2021 17:02:55 +0800 In-Reply-To: <20211103170206.Bluez.v2.1.I515833d2764b8ec2ac2bb1f87313de80ebb497cd@changeid> Message-Id: <20211103170206.Bluez.v2.3.Idb95ae18113225915b97a4f06983e1e41a7f7a2e@changeid> Mime-Version: 1.0 References: <20211103170206.Bluez.v2.1.I515833d2764b8ec2ac2bb1f87313de80ebb497cd@changeid> X-Mailer: git-send-email 2.33.1.1089.g2158813163f-goog Subject: [Bluez PATCH v2 3/3] adapter: Remove "Master" entry from LTK storage From: Archie Pusaka To: linux-bluetooth , Luiz Augusto von Dentz , Marcel Holtmann Cc: CrosBT Upstreaming , Archie Pusaka Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Archie Pusaka The entry has been deprecated since 2014 and it's time to remove them altogether. Signed-off-by: Archie Pusaka --- (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]);