Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp2696493pxb; Sun, 31 Oct 2021 23:08:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz0XU+z6x0yKY1pK6e2ZD3hoVIEYwvfdvpSXaXxlwE0exBxZwqksImAkv+PYcrKSPTbFP7f X-Received: by 2002:a02:6027:: with SMTP id i39mr19514270jac.91.1635746916359; Sun, 31 Oct 2021 23:08:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635746916; cv=none; d=google.com; s=arc-20160816; b=CXTDIouHW80i2pVX3kHKNBFsmZZkT3KyCwlfLhAXDVf6oe6LTsDU3YFurD1Soir1rn mxnn+Fpb9OpZyRWA5pmNDdlTtPgTQyKgPT9D3WySeD2KsH0rv+han39qx3Dv0w75GRtP QWIvU9v7eBCvmDM7syvizuiFmVSqPjaa4tdMRLG+o3UMJXbOjYiX5ad8cyctfDU+aJMg tfs2yms7OhP1l5XAMz/xDKr8iLOwXkJzA+5/A4/5W6KK93w8M5ohDulYrltPKjDBziFv l7A+x2wDSEXX8VDoyQ5fXNo8NDOeKbEqBBm96ZftBxKYtoVDCoaZb4xJINBMx//XLuSi hO/g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:mime-version:message-id:date :dkim-signature; bh=Zoa2fAXM28rUtlN/ISSvLdAbfkRTXQYLDwy+ZQkaVpU=; b=P3leK++QFWgdvWvr42baE+rgmFTtJ4NVbZM0G2JjOg1/ESFrYitXRPtoLO/Kcd2xby eGlMnmKZ6NG/mmnmQQK3WFkLwrbC1VIn8tu74bXce/DJm3LOs519RoAv3kZwTmoYaP5W 6qnyweg0XFY6w7oPdEKU7YpHqoNZsAGGotT2XYPmRYYaL381u5ba0sgRfpWGyQmR13XL chOTXYXai0qepG+qSn9NqWb8Sr0vJ1VFkB+tVnwDsXjSCsOQKq+LzoKm2dYO6MCaSBTf y+FZYIaajVTC//gLsuvmQS07iLFdrPMzyGTT/0Z+u5vInOTKtO4+JV0C4UhApA568VBn T27A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=JanpAjZ5; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g14si25148626ioo.113.2021.10.31.23.08.09; Sun, 31 Oct 2021 23:08:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=JanpAjZ5; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230501AbhKAGKJ (ORCPT + 99 others); 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-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 Content-Type: text/plain; charset="UTF-8" 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) { -- 2.33.1.1089.g2158813163f-goog