Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp2122102ybi; Thu, 4 Jul 2019 05:34:30 -0700 (PDT) X-Google-Smtp-Source: APXvYqwpHxvf+SnkJZ9f7TB6F/088griXp/e5ooL+pBKIe4i0SaaNYMHX+I0U6ap5JoikVf8XfuT X-Received: by 2002:a17:90a:2ec1:: with SMTP id h1mr19577264pjs.119.1562243670430; Thu, 04 Jul 2019 05:34:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562243670; cv=none; d=google.com; s=arc-20160816; b=0gTPEKhT6ElQ6JT2vuxyVChDS2wKJHBTKFNB+iJfLAD+S7chABBb8YtoU8O7zbXbMn rYE4JIAZ/pAYpzyQQX/j2OetU1JTe4DCXDPScfvjjkfaSEFUOmzZp6F+K18/o69fAFku 4lLGBsnCC43yW8mzK4+mN6U4YJkaFm/vc39yPg66NcPnehvMoQqkv5qD77/mPCCghpQS Y7b70gFEIZMpJRVbYhtOaXlm8vPyn0xkcK3p1ZXPOc0Oz2LugQ6MVj8kGz5GsX/R941T BkHSO7leRqZcFutP21fYhL4s0fgQXOnnx38no1xtDLRfFxzgjdGdgqV3mKCtYZKccn4U hh6g== 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=4IblZ27iWp+sP4PfHxEl9boVMP0lUZ8fZ2iZGFKJCCM=; b=F578i1E1q5Ro2OkSUXH5WZQXJqUOEwGGksd4NCEwWwm8wHQdDl5rnK1AQmH1GriJIf 3qKDxb6CctmTej1p481e3wjzJ0UjC/maCi9utDZ2bxTBGAR80cPdGRL7tNk810OOa3Uz oxavPXS/sgEHIslbwbg8Skmop1wvgvJbV8ReEdiATIvbGF2Wu5FzHe7VGwU43pXE+cDt CcDhl3CGSRrobGkLFmw1Wr6IM6I7znVlapu8bs1B9Gj4lluY0RaRRVys7nTVj1MHa5aq SPKMOScuUtGx14qsYPL9f8ObN9c/EXkdgaJ2bAUnCK0mq7TZRlGLHFmtwwbOs1Hc6VLr iyIg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@silvair-com.20150623.gappssmtp.com header.s=20150623 header.b="EpPo7/eV"; 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 v16si5625148pfe.39.2019.07.04.05.34.16; Thu, 04 Jul 2019 05:34:30 -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="EpPo7/eV"; 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 S1727772AbfGDMdv (ORCPT + 99 others); Thu, 4 Jul 2019 08:33:51 -0400 Received: from mail-lf1-f67.google.com ([209.85.167.67]:46268 "EHLO mail-lf1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727723AbfGDMdv (ORCPT ); Thu, 4 Jul 2019 08:33:51 -0400 Received: by mail-lf1-f67.google.com with SMTP id z15so4114529lfh.13 for ; Thu, 04 Jul 2019 05:33:49 -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=4IblZ27iWp+sP4PfHxEl9boVMP0lUZ8fZ2iZGFKJCCM=; b=EpPo7/eVuKurJ0XqYfdX0e1VaZ/n8JhNcrPrd+O5rbQI5jlHKX/oKMIvmvRWCv3G7z kblaKRZR2CCD/cAIjwx4RRN1wKJYf6iQXQIXbnI/TcjI5FE+R8jGoxL928L3Quf5JpPN fs9pKLJb/T7dyUukJUlxHswIQ3V+JOlZikAKVE+SrRTHIa1XLyHIfubKmhXWVujn8RC1 a84pliQFwAfa73yfCT+cS0PWBWXTTnYEXflhyhT9Jr6cGwwLyads5uapKE1HbFpmBeUm 9h/s5NasB+Xy0iMx+9S5l01aDUjdLk6ZG9msQbhNyJIJEfGoQV2Ofc6EHPZqraEb3ZpB I/mg== 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=4IblZ27iWp+sP4PfHxEl9boVMP0lUZ8fZ2iZGFKJCCM=; b=ZXCjGuQbCvisS1/EgdLicOEYr4NLuEPjVnW7r1K5/3aEKB1UW08xN6ELYNkORWp3a2 8+cIr2i7NBEb6VJWVbNU2eqO0Egm+uCHsneaFYao3iNYPBlq3280jQ0xgKapsW8hQY/a f9JINcRJiy0nb/K1ZoTmHYHz3pAy0UyJ6+Qh7fpjj5Bmr9mUjcUq/lY+D0vSVs3oU6uG qzEC+7Po5F6tBYCoXhdiEnSak1p0e4NqZqentB5fXJrblISeWpx56/bECxL0YCgjxmBZ KKfQsOfSkjvL2/zI+oKQoIiw5gArj/SSAYtzncORQKegaLZdcnIFjDfIPHAKnVll8hlu 7yzA== X-Gm-Message-State: APjAAAWgCd6Er9Davu8zcry8+iDy0jkX8bdavb/KL/YZNFP+mbn6zlfG G1twVV9f9U7pHhm9LK7AXUhYh4j58ms= X-Received: by 2002:a19:cbd3:: with SMTP id b202mr4852073lfg.185.1562243628445; Thu, 04 Jul 2019 05:33:48 -0700 (PDT) Received: from mlowasrzechonek2133.silvair.lan ([217.153.94.18]) by smtp.gmail.com with ESMTPSA id g68sm1126151ljg.47.2019.07.04.05.33.47 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Thu, 04 Jul 2019 05:33:47 -0700 (PDT) From: =?UTF-8?q?Micha=C5=82=20Lowas-Rzechonek?= To: linux-bluetooth@vger.kernel.org Cc: Inga Stotland Subject: [PATCH BlueZ v5 4/5] mesh: Implement DevKeySend() method on Node interface Date: Thu, 4 Jul 2019 14:33:37 +0200 Message-Id: <20190704123338.5988-5-michal.lowas-rzechonek@silvair.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190704123338.5988-1-michal.lowas-rzechonek@silvair.com> References: <20190704123338.5988-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 | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 61 insertions(+), 3 deletions(-) diff --git a/mesh/model.c b/mesh/model.c index ee26a8105..edb820cc9 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)) @@ -931,6 +932,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); */ @@ -949,7 +951,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 53876ef5a..803bd2f30 100644 --- a/mesh/node.c +++ b/mesh/node.c @@ -1973,13 +1973,60 @@ 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); return l_dbus_message_new_method_return(msg); } +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; + + 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); + + return l_dbus_message_new_method_return(msg); +} + static struct l_dbus_message *publish_call(struct l_dbus *dbus, struct l_dbus_message *msg, void *user_data) @@ -2077,7 +2124,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