Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp788004ybi; Wed, 3 Jul 2019 04:42:53 -0700 (PDT) X-Google-Smtp-Source: APXvYqwgbNBjw7Wpa8FxA9gHmJw64ylghUR58wCkfUEduvxZ5sovn60Tyh5Cbj4r1r0Ev1eg4hIp X-Received: by 2002:a17:902:968c:: with SMTP id n12mr43954551plp.59.1562154173194; Wed, 03 Jul 2019 04:42:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562154173; cv=none; d=google.com; s=arc-20160816; b=vXWyLB8b7zSLOor1FUyvotwM1ryWwJ71d4kn1vEB0AwZGV5BGoyUiqzr5i/L4WuYGz tL8gQXOtMX3QJFbp6bjvEJhBjYgDMu2uemUrC3Y4VmS3ly+Ln+jQLrBkmuCnu48YU/c8 eCrjFhlQ45zBUB9gqMjghGI3klbjNKMyzevA2jOu+GR++CEwaDn0XlXkmu3HHJsPIaPP mxkviL1U8ado1gmgJJ+acjtUFFWvrvZTiub1runc1ripAFgLqdWeDgXnsK7foVzSsOT7 FDArV9GyKwUDv8ez1MEqjV+8Wr4gqlMPh/Ae5ttzhLw4og6+ikbKic2jrxQiNDsSQRg2 AXTA== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=xhESnKSExKhKw/fCbska+2T2xmvmk2WlAUqxOKty/zw=; b=DOv5Gu9POxmGNgjmF4Yj1LlqUI/YRNvCkwT/VqApNoN6IorBGtLLWx3lr0lVYKjxDz BrdgxONXjVARQbWDyI0YpYJGv3Dhhg4M6GaxfKkbrvcucM3MyP+UsWI3CX2yEulda+ca VSc3AfuH7JUb1DryL0qmApoyimE8fJhBsRjv9ERdCrTwVBD+7cj5q2XMnJtJhg+yo4OZ up7kDegF/DQT5kfk+govY+UTg5HBZl+jLonHtaOhuCg1wf+m0O+pMyDXmG8Qu2quO914 1Eali8KOQefbwtbpuOaAvZ3ib4oQGFVpxV5OrcO8R2e7dLQJzMP+V6lPKZUvTvhy/e2C eFmw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@silvair-com.20150623.gappssmtp.com header.s=20150623 header.b=F3mXuU2D; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f17si1766273pjq.14.2019.07.03.04.42.29; Wed, 03 Jul 2019 04:42:53 -0700 (PDT) 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; dkim=pass header.i=@silvair-com.20150623.gappssmtp.com header.s=20150623 header.b=F3mXuU2D; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727012AbfGCLm0 (ORCPT + 99 others); Wed, 3 Jul 2019 07:42:26 -0400 Received: from mail-wm1-f65.google.com ([209.85.128.65]:51668 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726628AbfGCLmZ (ORCPT ); Wed, 3 Jul 2019 07:42:25 -0400 Received: by mail-wm1-f65.google.com with SMTP id 207so1877030wma.1 for ; Wed, 03 Jul 2019 04:42:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=silvair-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=xhESnKSExKhKw/fCbska+2T2xmvmk2WlAUqxOKty/zw=; b=F3mXuU2Da9sSXjf9woAmnenM5kUH8zkLjKI9QPWruXPKKw+gmnVUPB3tivXCGgc/vt R93zcX38SM5H0X8cMe9pHgRqggcoo+6LoNxm1vdqyFZHDVGj/RzZlyPkgSAIaFytlxu7 Ysoo1jIa0DbAr4Z79CMpcz2LZA9xWLLRYbvsZAW5I3I5sW2UKdWXSdob5pAP2NyUJtEC QA/0l2TVK4vbedMx9unJBgtflcsdSX16IRyBXrzv9vaPVop0ugg1lL5ivllRMuuWRcaG vdql9GPaenaF5kFd4yXw2a8/fEafqWN4iXNKxoiv6b1bt0wwl+uX5eP1u5Eyi3r7bIKz YT1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=xhESnKSExKhKw/fCbska+2T2xmvmk2WlAUqxOKty/zw=; b=frIyrtbMhlfUB8D+kKd2gOjw3v+DenbIbDZr/1nmgIiIpmL0tJR/+/gNuxss6ZOyTw +kGKwjGOK90SkK6JC8KxMdXef5Z+Y50+e/QKFCCOeAGKnzkz5rzp3h+2kowmOnr7QodE 0VFh6SUgoX8SGz14vA23wwrc64qkhyWaCHjNkhwdDkByyKgKoWuwJSt0uBaaqOG9ffXV uhFskawMyARX02VeFn6IRyv+EockrSwRymCgU1Wk+y+9pkNXcsTyFCyEtnKuN8BDy0Mp z0cM7aeg5HcIq/L1lU9n33QaoUi1RLD3rDBjIhMZ4vLfMsAAbtNHAXTAE17hx6nVbTtW F9ew== X-Gm-Message-State: APjAAAXaLTQfJH6i6hMakb8CaI+TqEOw7qKQjqIgqkhHtwZ7SXzHKa+W qiSGPVnXiF+fVXjaXGAT5Lhow4KdzNg= X-Received: by 2002:a1c:1bc1:: with SMTP id b184mr8359991wmb.42.1562154142665; Wed, 03 Jul 2019 04:42:22 -0700 (PDT) Received: from mlowasrzechonek2133.silvair.lan ([217.153.94.18]) by smtp.gmail.com with ESMTPSA id x6sm2556816wru.0.2019.07.03.04.42.21 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 03 Jul 2019 04:42:21 -0700 (PDT) From: =?UTF-8?q?Micha=C5=82=20Lowas-Rzechonek?= To: linux-bluetooth@vger.kernel.org Cc: Inga Stotland Subject: [PATCH BlueZ v4 2/3] mesh: Implement DevKeySend() method on Node interface Date: Wed, 3 Jul 2019 13:42:13 +0200 Message-Id: <20190703114214.22320-3-michal.lowas-rzechonek@silvair.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190703114214.22320-1-michal.lowas-rzechonek@silvair.com> References: <20190703114214.22320-1-michal.lowas-rzechonek@silvair.com> 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 This patch implements D-Bus DevKeySend() method of org.bluez.mesh.Node1 interface, allowing the application to send messages encrypted using a known remote device key. At the moment the call ignores net_index argument and sends messages using the primary subnet. Also, it's no longer possible to use 'magic' key_index value 0x7fff (denoting local device key) when calling regular Send(). Applications should use DevKeySend() instead. --- mesh/model.c | 9 +++++++- mesh/node.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 65 insertions(+), 3 deletions(-) diff --git a/mesh/model.c b/mesh/model.c index 598615c5e..aae913d92 100644 --- a/mesh/model.c +++ b/mesh/model.c @@ -39,6 +39,7 @@ #include "mesh/dbus.h" #include "mesh/util.h" #include "mesh/model.h" +#include "mesh/keyring.h" /* Divide and round to ceiling (up) to calculate segment count */ #define CEILDIV(val, div) (((val) + (div) - 1) / (div)) @@ -941,6 +942,7 @@ bool mesh_model_send(struct mesh_node *node, uint16_t src, uint16_t target, const void *msg, uint16_t msg_len) { uint8_t key_id; + uint8_t dev_key[16]; const uint8_t *key; /* print_packet("Mod Tx", msg, msg_len); */ @@ -959,7 +961,12 @@ bool mesh_model_send(struct mesh_node *node, uint16_t src, uint16_t target, if (!key) return false; - l_debug("(%x)", app_idx); + key_id = APP_ID_DEV; + } else if (app_idx == APP_IDX_DEV_REMOTE) { + if (!keyring_get_remote_dev_key(node, target, dev_key)) + return false; + + key = dev_key; key_id = APP_ID_DEV; } else { key = appkey_get_key(node_get_net(node), app_idx, &key_id); diff --git a/mesh/node.c b/mesh/node.c index 1dcb74b4f..7133f5b2d 100644 --- a/mesh/node.c +++ b/mesh/node.c @@ -1974,7 +1974,11 @@ static struct l_dbus_message *send_call(struct l_dbus *dbus, return dbus_error(msg, MESH_ERROR_INVALID_ARGS, "Incorrect data"); - if (!mesh_model_send(node, src, dst, app_idx, + if ((app_idx & APP_IDX_MASK) != app_idx) + return dbus_error(msg, MESH_ERROR_INVALID_ARGS, + "Invalid key_index"); + + if (!mesh_model_send(node, src, dst, app_idx & APP_IDX_MASK, mesh_net_get_default_ttl(node->net), data, len)) return dbus_error(msg, MESH_ERROR_FAILED, NULL); @@ -1984,6 +1988,53 @@ static struct l_dbus_message *send_call(struct l_dbus *dbus, return reply; } +static struct l_dbus_message *dev_key_send_call(struct l_dbus *dbus, + struct l_dbus_message *msg, + void *user_data) +{ + struct mesh_node *node = user_data; + const char *sender, *ele_path; + struct l_dbus_message_iter iter_data; + struct node_element *ele; + uint16_t dst, net_idx, src; + uint8_t *data; + uint32_t len; + struct l_dbus_message *reply; + + l_debug("DevKeySend"); + + sender = l_dbus_message_get_sender(msg); + + if (strcmp(sender, node->owner)) + return dbus_error(msg, MESH_ERROR_NOT_AUTHORIZED, NULL); + + if (!l_dbus_message_get_arguments(msg, "oqqay", &ele_path, &dst, + &net_idx, &iter_data)) + return dbus_error(msg, MESH_ERROR_INVALID_ARGS, NULL); + + ele = l_queue_find(node->elements, match_element_path, ele_path); + if (!ele) + return dbus_error(msg, MESH_ERROR_NOT_FOUND, + "Element not found"); + + src = node_get_primary(node) + ele->idx; + + if (!l_dbus_message_iter_get_fixed_array(&iter_data, &data, &len) || + !len || len > MESH_MAX_ACCESS_PAYLOAD) + return dbus_error(msg, MESH_ERROR_INVALID_ARGS, + "Incorrect data"); + + /* TODO: use net_idx */ + if (!mesh_model_send(node, src, dst, APP_IDX_DEV_REMOTE, + mesh_net_get_default_ttl(node->net), data, len)) + return dbus_error(msg, MESH_ERROR_NOT_FOUND, NULL); + + reply = l_dbus_message_new_method_return(msg); + l_dbus_message_set_arguments(reply, ""); + + return reply; +} + static struct l_dbus_message *publish_call(struct l_dbus *dbus, struct l_dbus_message *msg, void *user_data) @@ -2089,7 +2140,11 @@ static void setup_node_interface(struct l_dbus_interface *iface) { l_dbus_interface_method(iface, "Send", 0, send_call, "", "oqqay", "element_path", "destination", - "key", "data"); + "key_index", "data"); + l_dbus_interface_method(iface, "DevKeySend", 0, dev_key_send_call, + "", "oqqay", "element_path", + "destination", "net_index", + "data"); l_dbus_interface_method(iface, "Publish", 0, publish_call, "", "oqay", "element_path", "model_id", "data"); l_dbus_interface_method(iface, "VendorPublish", 0, vendor_publish_call, -- 2.19.1