Received: by 2002:a05:7412:5112:b0:fa:6e18:a558 with SMTP id fm18csp577193rdb; Tue, 23 Jan 2024 08:14:14 -0800 (PST) X-Google-Smtp-Source: AGHT+IFXbZWSc/wFWZJ9Xva8BDdFKtVEAPiS5RVnIxtp+B9rHA2P9GjfawKz0jqTvMjgmrN21Mi0 X-Received: by 2002:a05:6359:4599:b0:176:5990:f3e4 with SMTP id no25-20020a056359459900b001765990f3e4mr3143194rwb.14.1706026453892; Tue, 23 Jan 2024 08:14:13 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706026453; cv=pass; d=google.com; s=arc-20160816; b=0bdyssFL0YqmG6uinpVaa6Clzdve9DPfjmQV1NXFSnXGWnPQKNh20J+l62zsOuTlda nzFP7denXRYjvygyKnNUumgdlhBkULOBLAbfll0znTJyqI9mLDJij6QLIs1aEeB7YImp 43BG0PZLz0H4TlfmJno41D/FXkxp0IDyFSZLcJriZDvENbPOSD7cxwlwsFVnz6EnpG3Y HFOiR0dgRJKtUCiUaW8RQmbQFlf/+jkR2oyAb7Zee4IrFmOAydMkseG4L43iyxqr77w7 fLuoi6biMn+VexDeabnqTl4wMAnzbpgbXOSmw14IhyAtIf4/m1+9ZmpYDXXE3WRtnMN+ pnNw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature; bh=irGiUxBcrbzngz5dWNXcyo0l7+ovu4Mix6wGrVDO9K0=; fh=v4Z3N2Htbr8NtGqMLkQjkIE/EbeUcf6lhEWEAm07n3g=; b=l4ASVgOSCEWv6jrZ/V+GK2+gOi/tWKKdmsLV3qh+KKCtHx5AejFgPeqbsvVDnB8RrX zS1Ow7p1IBTjjiASairT36JbR+wtD6NwJkhzdffbCeLX28H2wOWUmq7EJrvildAbIarY 8gCPYadXJYixEX1kS930RnVBJ8GFMBQMzV7CJSJ/cdVEBTQHv0PVeLQMIfedmuAY9Z26 MIJW1kf5lyUcF3Ht9VDV97TtxLUeQ56FO4DQ6Jx+wbf4COL8a8EsKnA8rrGeHjxa+nB3 SHk2AS5TxnCr2oksG14diFWjFT8rDcG9+t66Mun20SjGgdGnQHPvZBjrkCu7nfH4HU14 uuIg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=f7LZyE6u; arc=pass (i=1 spf=pass spfdomain=collabora.com dkim=pass dkdomain=collabora.com dmarc=pass fromdomain=collabora.com); spf=pass (google.com: domain of linux-bluetooth+bounces-1275-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-bluetooth+bounces-1275-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id f11-20020a6547cb000000b005cdf7b05f36si9911968pgs.615.2024.01.23.08.14.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Jan 2024 08:14:13 -0800 (PST) Received-SPF: pass (google.com: domain of linux-bluetooth+bounces-1275-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=f7LZyE6u; arc=pass (i=1 spf=pass spfdomain=collabora.com dkim=pass dkdomain=collabora.com dmarc=pass fromdomain=collabora.com); spf=pass (google.com: domain of linux-bluetooth+bounces-1275-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-bluetooth+bounces-1275-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 5F050B2B381 for ; Tue, 23 Jan 2024 15:48:15 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 436B362A02; Tue, 23 Jan 2024 15:40:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b="f7LZyE6u" X-Original-To: linux-bluetooth@vger.kernel.org Received: from madrid.collaboradmins.com (madrid.collaboradmins.com [46.235.227.194]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 093EB60263 for ; Tue, 23 Jan 2024 15:40:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=46.235.227.194 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706024423; cv=none; b=kD99wXNu1Gho4IeQw01IQnWp3Y8U2x8RYHE653KQ9xq5XTJOa7/U1hpeizIeKMp0kwltqEZo0FFP1dW4bCvUS6zQEFUWQfhiphUUozxDrcSNtp3P2AoXIWAGN8aB4KcJ4U4akkXDD/oUgrwz++QnPKnbEgGKl72unXF5Z2iGktc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706024423; c=relaxed/simple; bh=I+g3+7Vv9sTkicD20vWVXQ6MB89PYUm0C+IEWrGMI3k=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=TKus9j5LW5ToyMU7max9S6D+I/wSfi4vq4GXd90J5Id47jA+5FgjWPQ/lB9lIjhhSonNsdTGY5aksvEaljsJlnGaAqCfN/jASqZcOcZt58PLfdpy6ALOnLA4ui8+GmgoOx/EK2VTgde0VxtkHVVipPNFeIIS8gge1ATAnNMe7qI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=collabora.com; spf=pass smtp.mailfrom=collabora.com; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b=f7LZyE6u; arc=none smtp.client-ip=46.235.227.194 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=collabora.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=collabora.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1706024420; bh=I+g3+7Vv9sTkicD20vWVXQ6MB89PYUm0C+IEWrGMI3k=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=f7LZyE6umI12yYRqYvMC4HlOMgxix49aSyZDrE7ERdDFc2ndESM1IFAW0T8KlHgVW JbLS1vsRiEarI2inOQI+wECA/M7jw8lvcqPBC1yq83nnjdCpHbDXj3GbZgvP7ML2y8 G2W2OTy7e7OkB197WsmSAcXOaAXiqOSOGKeHZlf7BocBOammGYQuuVpA8VSi1OMfsU aC9rzQ/PrR2FoBk8Ba39rUf0Mx+b8D2c+KqbMW3l5oBRye9YFVYE99PSkkWusNEym3 ipU/qy+r489hTtOcCFpOBzhPy/45cSfKE7nCvn+npz8RGCWnF3lWvugsUw752sVF1m 4I3DzebnR6ckA== Received: from [100.72.96.248] (cola.collaboradmins.com [195.201.22.229]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: fdanis) by madrid.collaboradmins.com (Postfix) with ESMTPSA id 0AFEE37820B0; Tue, 23 Jan 2024 15:40:20 +0000 (UTC) Message-ID: <603f93c2-0ed3-4416-b407-30e8d7511d82@collabora.com> Date: Tue, 23 Jan 2024 16:40:19 +0100 Precedence: bulk X-Mailing-List: linux-bluetooth@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH BlueZ 2/2] device: Update local and remote CSRK on management event Content-Language: en-US To: Luiz Augusto von Dentz Cc: linux-bluetooth@vger.kernel.org References: <20240123121519.523735-1-frederic.danis@collabora.com> <20240123121519.523735-2-frederic.danis@collabora.com> <741ff02f-596c-4c50-b809-d5fd39b77244@collabora.com> From: =?UTF-8?Q?Fr=C3=A9d=C3=A9ric_Danis?= In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Hi Luiz, On 23/01/2024 16:14, Luiz Augusto von Dentz wrote: > Hi Frédéric, > > On Tue, Jan 23, 2024 at 10:00 AM Frédéric Danis > wrote: >> Hi Luiz, >> >> On 23/01/2024 14:53, Luiz Augusto von Dentz wrote: >>> Hi Frédéric, >>> >>> On Tue, Jan 23, 2024 at 7:15 AM Frédéric Danis >>> wrote: >>>> The local and remote CSRK keys are only loaded from storage during start. >>>> >>>> Those keys should be updated on MGMT_EV_NEW_CSRK event to be able to >>>> perform signed write for GAP/SEC/CSIGN/BV-02-C. >>>> --- >>>> src/adapter.c | 2 ++ >>>> src/device.c | 16 ++++++++++++++++ >>>> src/device.h | 2 ++ >>>> 3 files changed, 20 insertions(+) >>>> >>>> diff --git a/src/adapter.c b/src/adapter.c >>>> index 022390f0d..fb71ef83e 100644 >>>> --- a/src/adapter.c >>>> +++ b/src/adapter.c >>>> @@ -8882,6 +8882,8 @@ static void new_csrk_callback(uint16_t index, uint16_t length, >>>> return; >>>> } >>>> >>>> + device_set_csrk(device, key->val, key->type & 0x01); >>>> + >>>> if (!ev->store_hint) >>>> return; >>>> >>>> diff --git a/src/device.c b/src/device.c >>>> index 17bcfbc49..34f64ca5b 100644 >>>> --- a/src/device.c >>>> +++ b/src/device.c >>>> @@ -1955,6 +1955,22 @@ bool btd_device_get_ltk(struct btd_device *device, uint8_t key[16], >>>> return true; >>>> } >>>> >>>> +void device_set_csrk(struct btd_device *device, const uint8_t val[16], >>>> + bool remote) >>>> +{ >>>> + if (remote) { >>>> + g_free(device->remote_csrk); >>>> + device->remote_csrk = g_new0(struct csrk_info, 1); >>>> + memcpy(device->remote_csrk->key, val, >>>> + sizeof(device->remote_csrk->key)); >>>> + } else { >>>> + g_free(device->local_csrk); >>>> + device->local_csrk = g_new0(struct csrk_info, 1); >>>> + memcpy(device->local_csrk->key, val, >>>> + sizeof(device->local_csrk->key)); >>>> + } >>>> +} >>>> + >>>> static bool match_sirk(const void *data, const void *match_data) >>>> { >>>> const struct sirk_info *sirk = data; >>>> diff --git a/src/device.h b/src/device.h >>>> index 8bb38669d..d00c002c3 100644 >>>> --- a/src/device.h >>>> +++ b/src/device.h >>>> @@ -134,6 +134,8 @@ void device_set_ltk(struct btd_device *device, const uint8_t val[16], >>>> bool central, uint8_t enc_size); >>>> bool btd_device_get_ltk(struct btd_device *device, uint8_t val[16], >>>> bool *central, uint8_t *enc_size); >>>> +void device_set_csrk(struct btd_device *device, const uint8_t val[16], >>>> + bool remote); >>> Looks like there is only one use of this function and it is always set >>> for the remote, actually the fact that this is on the device object >>> already means it is for the remote so I wonder if we really need to >>> store the local as well? >> As device is able to store and load both keys from storage I think it >> could be better to keep them in sync, no? > Don't we have the CSRK stored at adapter level though? Or we have to > generate a pair of local/remote CSRK for each device, if we do I'm not > seeing when we store the local CSRK. Afaiu both CSRK are stored in //info from adapter on mgmt event (https://github.com/bluez/bluez/blob/master/src/adapter.c#L8888) and from device when store_device_info_cb() (https://github.com/bluez/bluez/blob/master/src/device.c#L423) is called. Key and Authenticated values are saved from adapter (with Counter set to 0), while Key and Counter are saved from device. Both counter for local and remote are managed in device, so I wonder if both CSRK shouldn't be stored only from device. What's your opinion? >>>> bool btd_device_add_set(struct btd_device *device, bool encrypted, >>>> uint8_t sirk[16], uint8_t size, uint8_t rank); >>>> void device_store_svc_chng_ccc(struct btd_device *device, uint8_t bdaddr_type, >>>> -- >>>> 2.34.1 >>>> >>>> >> -- >> Frédéric Danis >> Senior Software Engineer >> >> Collabora Ltd. >> Platinum Building, St John's Innovation Park, Cambridge CB4 0DS, United Kingdom >> Registered in England & Wales, no. 5513718 >> > -- Frédéric Danis Senior Software Engineer Collabora Ltd. Platinum Building, St John's Innovation Park, Cambridge CB4 0DS, United Kingdom Registered in England & Wales, no. 5513718