Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp170272pxb; Wed, 3 Nov 2021 02:03:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwQrznAmwo2yCAYH4MFdmGSy2Ddbh3PffTWhZBAKYvH5UOwBoxGPLx+KsVSwIo8KtCDdIlF X-Received: by 2002:a05:6e02:14d3:: with SMTP id o19mr30510197ilk.156.1635930224411; Wed, 03 Nov 2021 02:03:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635930224; cv=none; d=google.com; s=arc-20160816; b=U463xloLuXTJH7zs/L1FfKeYoIq2uLRZpGo6ZBgz2UXTb6yNttHtEIPKb5wNV/Rc65 e9KqcrYU4R2RtmnQfKc14ARLVYFsFUPv8tIlY2TlslyEUl9SKzmbx5jFs0MRmkhGngYF xLeW3CYPGQzxEAB3KXosNjNLuUYTwDjm4SlAG1EAkQwQ8qykdipW6C8RShJPENV4MjYz xVBDhyEa4uscNUya5I+vp2y5ith0ycIhfGQY4ezoiHH8dt3APBq7hVpUasxJpQKmPUqN gImNsOTHfYctvZRKD+Ng9t2qL7A7oM0FfF6a5z/ZkZPI3V7MPZJ7dzgsogas96gZyLqP egdA== 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=bIe43DMC+hVNx274dZvwV5NiQPHCOMhtMi2x8daakaQ=; b=pwiyl3ktS4HdN7cssy2c3sj2P8H3b6AzYqBXRw/Ku7BbU5hhSM8p/1u2A9b4tz2N5/ wMzIsl1J7qU7JBlb/V+nzOesBtWeAEB/nEF0SgUbvxcZ/IwwCrukBDevwY4EzBif9x1v WuSLYARrlyg93FPhuUXrlo/CJHqPBdZIHQJMnQC1T34X3QbhHKHSN1KpyjloEsNY5lDZ MspUt2kxN0WN6pA0Wb5PzrMpFJyuNlGY8BaISsw5ULwIzbJtjisOlxFBH5BLUBmW8oe8 vdLyTk+uBg/kDIRMPSOf/IjbM9tb98C4vaB+H6Jg4xc3DGcnNwiBDEmz2jRJok1vR1tj seMA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=AVcdizCp; 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 g18si3186843iow.34.2021.11.03.02.03.28; Wed, 03 Nov 2021 02:03:44 -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=AVcdizCp; 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 S231740AbhKCJFl (ORCPT + 99 others); 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-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 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 --- 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