Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp1607711ybl; Fri, 6 Dec 2019 22:13:29 -0800 (PST) X-Google-Smtp-Source: APXvYqxWNWgoDkFuz4Rze5F2BEc+ehJx64OVDOqnbCueapw7bxZbNs5J74vckgj07xfZgRPNDtyq X-Received: by 2002:a05:6808:98d:: with SMTP id a13mr16089292oic.7.1575699209134; Fri, 06 Dec 2019 22:13:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1575699209; cv=none; d=google.com; s=arc-20160816; b=BPQKpnLEiNvke7Kd/7rxZWm8zX/6Ewre4xEfKBAogeXfh3J8PMb6u5l5/HX+m7hddh qoeMYJQi9yaxeXBmtRs8WbKoxiBZFxUC2Ei00VhTiP1FSlBwwUczP1qQNKHExdjzNuEf yqpyRcFf2vwnyyCfqNRLWgu02NgdqaKxRbzeoX3QDmJktU3J5bHJHzzDyPm74Q024b5M k+vO1blbNAUxIBMNMKP1FoBSuwVgrcNtai99UEc9j5cYUlEynSDEwjsQJbDszyT31OnR dOEmYcqNObSPjRtPvOqP+nJgOI72T6rVm24LjNXO6/dQCLanRGv55ZrUitpVR5g6BIZH BtZQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=DIywe58pqIXexXEyRla6d7KeUtkw3aWSH+3uluK1y1k=; b=KJenKEFlMmJ4ZRURvl+TO0AwzOb/rU45SZ3IPmltMx5bIdjQqpVyOqTq3Rj/8ZlehY w8Nwiskx/bWpy1mn9l90tkzlpM7JIROpjEA3vscLYzhpG1OV6b+yApgtdqgf0H6INQfw eYgFwyuU3jPSU/a1vjzpC8yCB9XXNhpOI0ITAJABxYyqHXiOjwaQEXeFSjXORC+zLNTF 4Z3fBana5rBtTT4ECXqwCm0L0JEX/TR2IdZUlgUcbStXwoNO8QWUGrvJh5RMFP808BPM f3mJeyY08qUmlT1sWRobmEsE36lj359S5qUHouhe2IszHFRzfD7ATydcimt+Ar5v+lF+ lfuQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-bluetooth-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l131si8687925oig.120.2019.12.06.22.12.56; Fri, 06 Dec 2019 22:13:29 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-bluetooth-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-bluetooth-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726196AbfLGGMw (ORCPT + 99 others); Sat, 7 Dec 2019 01:12:52 -0500 Received: from mga03.intel.com ([134.134.136.65]:58465 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725869AbfLGGMw (ORCPT ); Sat, 7 Dec 2019 01:12:52 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 06 Dec 2019 22:12:52 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.69,286,1571727600"; d="scan'208";a="386714185" Received: from aishii-mobl1.gar.corp.intel.com (HELO ingas-nuc1.sea.intel.com) ([10.252.128.120]) by orsmga005.jf.intel.com with ESMTP; 06 Dec 2019 22:12:52 -0800 From: Inga Stotland To: linux-bluetooth@vger.kernel.org Cc: brian.gix@intel.com, Inga Stotland Subject: [PATCH BlueZ] tools/mesh-cfgclient: Disallow sending a non-existing key Date: Fri, 6 Dec 2019 22:12:45 -0800 Message-Id: <20191207061245.6845-1-inga.stotland@intel.com> X-Mailer: git-send-email 2.21.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-bluetooth-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org Prior to sending either NetKeyAdd or AppKeyAdd message to a remote node, check if the key exists locally. --- tools/mesh-cfgclient.c | 14 +++++++++++++- tools/mesh/keys.c | 8 ++++++++ tools/mesh/keys.h | 1 + 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/tools/mesh-cfgclient.c b/tools/mesh-cfgclient.c index 200eb5b84..b4d76de93 100644 --- a/tools/mesh-cfgclient.c +++ b/tools/mesh-cfgclient.c @@ -316,8 +316,20 @@ static bool send_key(void *user_data, uint16_t dst, uint16_t key_idx, const char *method_name = (!is_appkey) ? "AddNetKey" : "AddAppKey"; net_idx = remote_get_subnet_idx(dst); - if (net_idx == NET_IDX_INVALID) + if (net_idx == NET_IDX_INVALID) { + bt_shell_printf("Node %4.4x not found\n", dst); return false; + } + + if (!is_appkey && !keys_subnet_exists(key_idx)) { + bt_shell_printf("Local NetKey %u not found\n", key_idx); + return false; + } + + if (is_appkey && (keys_get_bound_key(key_idx) == NET_IDX_INVALID)) { + bt_shell_printf("Local AppKey %u not found\n", key_idx); + return false; + } req = l_new(struct key_data, 1); req->ele_path = user_data; diff --git a/tools/mesh/keys.c b/tools/mesh/keys.c index 7d2058294..0ce8ce811 100644 --- a/tools/mesh/keys.c +++ b/tools/mesh/keys.c @@ -173,3 +173,11 @@ void keys_print_keys(void) { l_queue_foreach(net_keys, print_netkey, NULL); } + +bool keys_subnet_exists(uint16_t idx) +{ + if (!l_queue_find(net_keys, net_idx_match, L_UINT_TO_PTR(idx))) + return false; + + return true; +} diff --git a/tools/mesh/keys.h b/tools/mesh/keys.h index 2a9faede6..71c3bb390 100644 --- a/tools/mesh/keys.h +++ b/tools/mesh/keys.h @@ -23,4 +23,5 @@ void keys_del_net_key(uint16_t net_idx); void keys_add_app_key(uint16_t net_idx, uint16_t app_idx); void keys_del_app_key(uint16_t app_idx); uint16_t keys_get_bound_key(uint16_t app_idx); +bool keys_subnet_exists(uint16_t idx); void keys_print_keys(void); -- 2.21.0