From patchwork Mon Nov 1 06:06:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Archie Pusaka X-Patchwork-Id: 12595891 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 CBDD4C43217 for ; Mon, 1 Nov 2021 06:07:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A8B6461101 for ; Mon, 1 Nov 2021 06:07:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229865AbhKAGKJ (ORCPT ); Mon, 1 Nov 2021 02:10:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55344 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231176AbhKAGKB (ORCPT ); Mon, 1 Nov 2021 02:10:01 -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 C2059C061A0E for ; Sun, 31 Oct 2021 23:06:34 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id z2-20020a254c02000000b005b68ef4fe24so24612213yba.11 for ; Sun, 31 Oct 2021 23:06:34 -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=Zoa2fAXM28rUtlN/ISSvLdAbfkRTXQYLDwy+ZQkaVpU=; b=JanpAjZ54bDdYnwxbmStfu/fWjIk9VlZip/2ICVrA5Fu4NYCpGT9xjQEXL8X01ZcqC KywLcBzUYB9JWZH7ehuY07ydf93/K1Vi9BSefOdID86G5r7bZiv6VMffCIo69EqWpwFD fB99JfRqdQEL8R5L9jXjmR++ZBtfolLf6iP2hEvdW/YDBd25QetwWMP8HcHzAx2Au5Md GyEaKwNALvHi6+/yfKtbMBNwfeibcnPqyYG0WJfkFzNB83kgj60QR9gvzAfEIz0Q6h0c tCxKZwQtyO0shYWgeYU0q1l5orRGFu3mHBIimnsgaH1J3TNL4qGB6bYZetZjPIf6sAsb pXcQ== 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=Zoa2fAXM28rUtlN/ISSvLdAbfkRTXQYLDwy+ZQkaVpU=; b=KTk8dypuqfQc+I+pkelSADUrl7K95QQCJ0O9ZR/gUh7mBp8D9k3yBno1U3Wcj2dK/P pBg5b/in92bflqqCg0rxQbQvWEkiUXb0r46jndw+C+FyMNL2gTRRvR6VuC7Aq1Sn70nB qEH7KBqK4gV9atkbIkC1bIOGjpv1lrOH3Wakowo4szPEArHLHIT1FTlnNddxUlfc9Oqw CYfKg7x3w3zAbNrVlN7Qwu/c11diDfJIDyFBj+bFZ78PhFB1NttSaKSSSeghsuF8vd3B 5jrU9AsZ7hOEbu1JxUyJ/cfVQRJcF1s69kwleoPp2hL7UTHXQSTiXGU3Sj5C+D4mH5kN ZGow== X-Gm-Message-State: AOAM531Z2VvLwkWq1jJIqoLIVFaf6Sk3sPkgELEzJWC8rqIMk2JHIW6o GvpbA1Hmz7kDDOrRmO1MpYNLkZwQAJLePLPX4XpPltlaaEvLsqFSFROOypd+sroN6NW7AdA5agV qoLxdXuQweHroaG9qTfN27faCwFpwDaoLv78nFBBdQvtwUlppkM8PKvvsMl4tolN5ELzp70s/V6 09 X-Google-Smtp-Source: ABdhPJxuiv1u5QlziHNRW3ip4TMax+nO8Xlwh8Irov/00oSHRChEwcLF/NNDApft/rVdq3g/bBjsMJUAxv9J X-Received: from apusaka-p920.tpe.corp.google.com ([2401:fa00:1:10:93ab:332e:48e3:1733]) (user=apusaka job=sendgmr) by 2002:a25:6152:: with SMTP id v79mr28722879ybb.400.1635746793861; Sun, 31 Oct 2021 23:06:33 -0700 (PDT) Date: Mon, 1 Nov 2021 14:06:24 +0800 Message-Id: <20211101140544.Bluez.1.I515833d2764b8ec2ac2bb1f87313de80ebb497cd@changeid> Mime-Version: 1.0 X-Mailer: git-send-email 2.33.1.1089.g2158813163f-goog Subject: [Bluez PATCH 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 --- src/adapter.c | 41 ++++++++++++++++++++++++++++++++--------- 1 file changed, 32 insertions(+), 9 deletions(-) diff --git a/src/adapter.c b/src/adapter.c index d0d38621b8..6b12c9e793 100644 --- a/src/adapter.c +++ b/src/adapter.c @@ -3868,7 +3868,11 @@ static struct smp_ltk_info *get_peripheral_ltk_info(GKeyFile *key_file, DBG("%s", peer); - ltk = get_ltk(key_file, peer, bdaddr_type, "SlaveLongTermKey"); + /* Read from both entries. Later we should deprecate Slave. */ + 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 +8419,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 +8434,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 +8473,31 @@ 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 { + /* Store duplicates for now. Later we should deprecate Slave. */ + 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 Mon Nov 1 06:06:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Archie Pusaka X-Patchwork-Id: 12595889 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 2B2CCC433FE for ; Mon, 1 Nov 2021 06:07:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 137CC6108D for ; Mon, 1 Nov 2021 06:07:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230396AbhKAGKI (ORCPT ); Mon, 1 Nov 2021 02:10:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55252 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229865AbhKAGKB (ORCPT ); Mon, 1 Nov 2021 02:10:01 -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 6A332C079780 for ; Sun, 31 Oct 2021 23:06:43 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id t24-20020a252d18000000b005c225ae9e16so6681078ybt.15 for ; Sun, 31 Oct 2021 23:06:43 -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=3WCSek+fSEuef/uAOlirtzAUfYn/NYrk6+zSO/47qkE=; b=OoG9kmaMhdvHBx91i8jiyLz+pmrxktc88yu0taQm2sgIB8lT1dmPAQOVWiwqk487kq K3KvzsPHbS3YjjcSPrWmqyeFg0YXK5p1F5VOrambLeL8dwIEnZtWAJUZEMGxDCYuUdr5 t5tLHxi0OXhE3eQivkl7NKhGxlREJ7V0AWBrpPInpfLhHrqIJ7MbS3+cZdFeqURq/ofS ObxruVTbpcmtYRWB4opsaOShSd7eAiIu7F8aBcTTP7k36LN2QxSwN9v2kGcExbDnHH5u /WkKCDW4Lx8Wg+DJlvnZVaqd5fUxqZwWegNQQqSEJrqpY/pgf/8zXEhLVgMfPBtboWgO a0JA== 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=3WCSek+fSEuef/uAOlirtzAUfYn/NYrk6+zSO/47qkE=; b=IzkU2UjMMC28U+0E2sFjzzHL7YXj7MSKO1ba6XvkDrz11iKpHa5ekoNdC5MvRHEFj1 BdpP/91MN85wLQ90Jayw8/AZThFvqwAZcOsztBLb/iB6eJd7uEcHtBLPZfj9trMlUVdv n4ZmbjK62otMcoviDUNe9Z2ZHvP7SCJLVyNhKExs6Piv4SXqcHhKZ+q+o+qXJ/0p3U8n A3gafR2d/Kg489rwwzIHNKMT+s1aspbZMPrugbaxWy8CnHRtRYknibBAGTNeWhtpNfy9 xHJGWBCnIvFi4Embt3KS46nAfeJGRVKa8joL6Th2jb1CMT7L9SXfHlqmvupELlyDe7xn 73hg== X-Gm-Message-State: AOAM531pkL6bFhb54flpWu6ppEI7HWL/i4tACoDRK9gjaFj2m9Nw+0Qo KDF7nmbvdO7KmpW8PAThTvtXE6ACQ9bHHPZ3lJjsXgcRRO0h4wkeZGWO2INZJzKq12l0+OuRKdE +qhAxrU2b2Dl/WKNA7zskPKSaC86ivOOUqNfLQ3B/TwGVNbfm0AzdQp+2m2/osXLjJBJCC9HQu1 QN X-Google-Smtp-Source: ABdhPJw+ihWwEiFZGremkPLCEWzHOJ9qjSuOcu+kjNeaHdpSd8Jv2HpaZeyGxuJ/OpMX9sBlyu1rzu0o+jln X-Received: from apusaka-p920.tpe.corp.google.com ([2401:fa00:1:10:93ab:332e:48e3:1733]) (user=apusaka job=sendgmr) by 2002:a25:c344:: with SMTP id t65mr27729922ybf.340.1635746802640; Sun, 31 Oct 2021 23:06:42 -0700 (PDT) Date: Mon, 1 Nov 2021 14:06:25 +0800 In-Reply-To: <20211101140544.Bluez.1.I515833d2764b8ec2ac2bb1f87313de80ebb497cd@changeid> Message-Id: <20211101140544.Bluez.2.I1e75e215e52ece8017840d4df309c4ba4ac84510@changeid> Mime-Version: 1.0 References: <20211101140544.Bluez.1.I515833d2764b8ec2ac2bb1f87313de80ebb497cd@changeid> X-Mailer: git-send-email 2.33.1.1089.g2158813163f-goog Subject: [Bluez PATCH 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 --- 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 Mon Nov 1 06:06:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Archie Pusaka X-Patchwork-Id: 12595887 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 0AE15C433EF for ; Mon, 1 Nov 2021 06:07:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DBBBF6108F for ; Mon, 1 Nov 2021 06:07:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230451AbhKAGKG (ORCPT ); Mon, 1 Nov 2021 02:10:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55338 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229949AbhKAGKB (ORCPT ); Mon, 1 Nov 2021 02:10:01 -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 A34BAC079781 for ; Sun, 31 Oct 2021 23:06:49 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id v133-20020a25c58b000000b005c20153475dso13729587ybe.17 for ; Sun, 31 Oct 2021 23:06:49 -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=v0aCId91YUIOcgru+L1HRukGZnNCqeqwEdd8IkAfGUw=; b=qjY14zW0WJR//wl9IPRAJzMc6CYtSdTqhE2PFiDodr5iuk8E6PGbPAdejPN9qUrYAk 78POFcJjeHQjpvrF/zNmZ+PkDwamlYKRPJXFhedN+k3ve/h1Ybc4PIDllekcwItB5AYl 6jBNRs01Pso3Vr65PoANwa4Kod5yMwFgK2Z/K/W+LTxOVqfF9Dqw2rZjjAG7WGijv2Qq NERvT/dqIn9j/d56yT2TXgOxVomvknbGNNh+7eyowTyR2KftZccYTnnvDsMJHoBMUR6r kkNsAcMNyXUKPPhJ+/ZrPiPAdNa9QHAf/f5nwG6I0V+LaZnacLuNoMcZXCRixEhqOuFf olQQ== 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=v0aCId91YUIOcgru+L1HRukGZnNCqeqwEdd8IkAfGUw=; b=OfTwaAeSeGFCZB1yeGy+RgQeKiqOZHNSg1QWvHTEmLAHwn/qGb01GYhYiqmsvb9EyR pOwMqDFo94xoOjQ2VshtgDniuayhZwbmBpDDkMFbrng/4V4Wwh4ag5LDLOqAX0YRJ6s6 P/zuNnvr53FQUvxNQpUwdlxHEix24rp2eFtkvL4Dk46kgtXpWX049qtjwgM1FIvJQaok qpk7gSVvHni+EhOGPCF6CABy+HjaGQuzCGqB4DPClOy2wrjzgqRapYF/REPxa5rKnJYB IQsKAiUTFMVBVoBrgAdsJBZvHK+V/sTlZ3pJAJg+FR/nroQPuBwJKsFwkpCrJtIwzHYn HoJw== X-Gm-Message-State: AOAM530u1JbXidhcFfkOku9YgXG2jaN80EUs9UBzyFUz2n8kAAuWFZCW kBLuDexJTDJTmMXkX3i4tFQojenj02r9X1Mw+DWxTlIPFw4jnUu6DeB/zf3pmu8YleHULsIbYSu 6QgWRFnRhOQ3BXWPRZOqo8rRB96pC5kX4faXXbqPLPnQPDZDO+cWfi2bKm6Tkf85E0DKJK46G9Z 41 X-Google-Smtp-Source: ABdhPJy7+aVgAAt82mmjlLV1jmpSysO3aBiBjBwkDw5EAZqidd/2pPel7WARLLiE+2WRB6XMxf/+79ULEHYe X-Received: from apusaka-p920.tpe.corp.google.com ([2401:fa00:1:10:93ab:332e:48e3:1733]) (user=apusaka job=sendgmr) by 2002:a25:328b:: with SMTP id y133mr16589670yby.233.1635746808821; Sun, 31 Oct 2021 23:06:48 -0700 (PDT) Date: Mon, 1 Nov 2021 14:06:26 +0800 In-Reply-To: <20211101140544.Bluez.1.I515833d2764b8ec2ac2bb1f87313de80ebb497cd@changeid> Message-Id: <20211101140544.Bluez.3.Idb95ae18113225915b97a4f06983e1e41a7f7a2e@changeid> Mime-Version: 1.0 References: <20211101140544.Bluez.1.I515833d2764b8ec2ac2bb1f87313de80ebb497cd@changeid> X-Mailer: git-send-email 2.33.1.1089.g2158813163f-goog Subject: [Bluez PATCH 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. --- Hi maintainers, While cleaning this entry, I found that this entry is involved in some kind of storage file conversion, probably when upgrading BlueZ 4 to 5. Should we also remove the file conversion too, since it's dated to 2014 as well? src/adapter.c | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/src/adapter.c b/src/adapter.c index 6b12c9e793..3a3c957a6c 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); @@ -5904,7 +5896,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); @@ -8445,9 +8436,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]);