Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp5127786ybc; Fri, 15 Nov 2019 15:17:59 -0800 (PST) X-Google-Smtp-Source: APXvYqzLgTYf6K645rwXghN9aUp1gMmJQ1EwGLtJIyqlJpHSfkZzICx364AtzVJPkVkfFqOvW4oj X-Received: by 2002:a17:906:95c4:: with SMTP id n4mr4671057ejy.39.1573859879824; Fri, 15 Nov 2019 15:17:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573859879; cv=none; d=google.com; s=arc-20160816; b=njul8O+IRQ2YESC4FHf0SvvzeV5UVXfGXD+G5DhDn/pxFQv0w3pmo8zuG6UgS9GLMk 2QEpSQt7/ZH9dCShLpYpD2xx+OBGuf9tBla0Au4HFV/vBzg+vKgE7dwd+I8FmzD8CQF2 48Tqow8V6W1Zlp1Mkf0b84UFGdPTp1pJFbQ1Yd9GEfYV6rujqt9KSg19OI4F+fWhh3nj ob+1raIQi2hpzRi57FSGvHeTIbDrEpWH8pE7xf9tTGeid4pV50IAk9bYBZ3Fg2M7NeGd QixNRkWzYCHgTYJsYCCnLrmoBxnSyniK6krD1XRpSWYmges+hfVg4nOrCMmUmluZcWyG W3zA== 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; bh=uU7r7l7xIXastQ+SUF8+isRLKuOpEtmmesN/U0l4OZ4=; b=c3pKlMiMbSZmibYKEoQWqhXg3WekgP7uhgsEhTyIIP3pg+W05cjRpEvxw5k6OF7ske z6YrpTt+gPAqnZm1rA1RRcSJyNdhqlSxRev1qDFyhRBaoAEyyiqW/qlwWrbqWNffh+NF Nu87EjLqvV6Y3E1O3Q+KPmwd4cmCRtrFodwBmKfNa5hU84bdS70lEj7Wew5BzCyRCHw/ 0uOH1COTfET6Y9RnlZ0ZozoTY3UfCq9wOhym2St6rAMESzw8m+RJIVcTNPnR6ziCy1zg dBePmo+Oe5JOAWmlaDWesOjIOEpFQQlgEQuDfeo31rD/z4nJC5PV7zhDhKxwVzj9rn1P FCwQ== 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 92si8839764edh.321.2019.11.15.15.17.33; Fri, 15 Nov 2019 15:17:59 -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 S1727053AbfKOXRZ (ORCPT + 99 others); Fri, 15 Nov 2019 18:17:25 -0500 Received: from mga12.intel.com ([192.55.52.136]:62385 "EHLO mga12.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727020AbfKOXRY (ORCPT ); Fri, 15 Nov 2019 18:17:24 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 15 Nov 2019 15:17:15 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.68,310,1569308400"; d="scan'208";a="288694608" Received: from bgi1-mobl2.amr.corp.intel.com ([10.252.205.168]) by orsmga001.jf.intel.com with ESMTP; 15 Nov 2019 15:17:15 -0800 From: Brian Gix To: linux-bluetooth@vger.kernel.org Cc: brian.gix@intel.com, inga.stotland@intel.com, aurelien@aurel32.net Subject: [PATCH BlueZ v2 1/2] mesh: Fix inOOB and outOOB agent handling on prov initiate Date: Fri, 15 Nov 2019 15:17:04 -0800 Message-Id: <20191115231705.5596-2-brian.gix@intel.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20191115231705.5596-1-brian.gix@intel.com> References: <20191115231705.5596-1-brian.gix@intel.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 code fixes the Provisioner Initiator role so that the following Out-of-Band agent calls are made correctly, and their results handled properly: "push", "twist", "blink", "beep", "vibrate", "in-numeric", "out-numeric", "in-alpha", "out-alpha" --- mesh/agent.c | 12 ++++---- mesh/prov-initiator.c | 69 ++++++++++++++++++++++++++++++++++++------- 2 files changed, 65 insertions(+), 16 deletions(-) diff --git a/mesh/agent.c b/mesh/agent.c index 4f99bad7b..623f2faf0 100644 --- a/mesh/agent.c +++ b/mesh/agent.c @@ -363,7 +363,7 @@ static void key_reply(struct l_dbus_message *reply, void *user_data) mesh_agent_key_cb_t cb; struct l_dbus_message_iter iter_array; uint32_t n = 0, expected_len = 0; - uint8_t buf[64]; + uint8_t *buf; int err; if (!l_queue_find(agents, simple_match, agent) || !agent->req) @@ -376,13 +376,13 @@ static void key_reply(struct l_dbus_message *reply, void *user_data) if (err != MESH_ERROR_NONE) goto done; - if (!l_dbus_message_get_arguments(reply, "au", &iter_array)) { + if (!l_dbus_message_get_arguments(reply, "ay", &iter_array)) { l_error("Failed to retrieve key input"); err = MESH_ERROR_FAILED; goto done; } - if (!l_dbus_message_iter_get_fixed_array(&iter_array, buf, &n)) { + if (!l_dbus_message_iter_get_fixed_array(&iter_array, &buf, &n)) { l_error("Failed to retrieve key input"); err = MESH_ERROR_FAILED; goto done; @@ -390,7 +390,7 @@ static void key_reply(struct l_dbus_message *reply, void *user_data) if (req->type == MESH_AGENT_REQUEST_PRIVATE_KEY) expected_len = 32; - else if (MESH_AGENT_REQUEST_PUBLIC_KEY) + else if (req->type == MESH_AGENT_REQUEST_PUBLIC_KEY) expected_len = 64; else expected_len = 16; @@ -402,13 +402,13 @@ static void key_reply(struct l_dbus_message *reply, void *user_data) } done: - l_dbus_message_unref(req->msg); - if (req->cb) { cb = req->cb; cb(req->user_data, err, buf, n); } + l_dbus_message_unref(req->msg); + l_free(req); agent->req = NULL; } diff --git a/mesh/prov-initiator.c b/mesh/prov-initiator.c index 5e45d6813..96be00cdc 100644 --- a/mesh/prov-initiator.c +++ b/mesh/prov-initiator.c @@ -433,6 +433,54 @@ failure: /* TODO: Call Complete Callback (Fail)*/ } +static void get_random_key(struct mesh_prov_initiator *prov, uint8_t action, + uint8_t size) +{ + uint32_t oob_key; + int i; + + if (action >= PROV_ACTION_IN_ALPHA) { + uint8_t alpha; + char tmp[17]; + + memset(tmp, 0, sizeof(tmp)); + + if (size > 16) + size = 16; + + /* Create random alphanumeric string made of 0-9, a-z, A-Z */ + for (i = 0; i < size; i++) { + l_getrandom(&alpha, sizeof(alpha)); + alpha %= (10 + 26 + 26); + + if (alpha < 10) + alpha += '0'; + else if (alpha < 10 + 26) + alpha += 'a' - 10; + else + alpha += 'A' - 10 - 26; + + tmp[i] = (char) alpha; + } + memcpy(prov->rand_auth_workspace + 16, tmp, size); + memcpy(prov->rand_auth_workspace + 32, tmp, size); + return; + } + + l_getrandom(&oob_key, sizeof(oob_key)); + + if (action <= PROV_ACTION_TWIST) + oob_key %= size; + else + oob_key %= digit_mod(size); + + if (!oob_key) + oob_key = size; + + /* Save two copies, for two confirmation values */ + l_put_be32(oob_key, prov->rand_auth_workspace + 28); + l_put_be32(oob_key, prov->rand_auth_workspace + 44); +} static void int_prov_rx(void *user_data, const uint8_t *data, uint16_t len) { @@ -591,22 +639,22 @@ static void int_prov_rx(void *user_data, const uint8_t *data, uint16_t len) case 3: /* Auth Type 3b - input OOB */ - l_getrandom(&oob_key, sizeof(oob_key)); - oob_key %= digit_mod(prov->conf_inputs.start.auth_size); + get_random_key(prov, + prov->conf_inputs.start.auth_action, + prov->conf_inputs.start.auth_size); + oob_key = l_get_be32(prov->rand_auth_workspace + 28); - /* Save two copies, for two confirmation values */ - l_put_be32(oob_key, prov->rand_auth_workspace + 28); - l_put_be32(oob_key, prov->rand_auth_workspace + 44); - prov->material |= MAT_RAND_AUTH; - /* Ask Agent to Display U32 */ + /* Ask Agent to Display random key */ if (prov->conf_inputs.start.auth_action == PROV_ACTION_IN_ALPHA) { - /* TODO: Construst NUL-term string to pass */ + fail_code[1] = mesh_agent_display_string( - prov->agent, NULL, NULL, prov); + prov->agent, + (char *) prov->rand_auth_workspace + 16, + NULL, prov); } else { fail_code[1] = mesh_agent_display_number( - prov->agent, false, + prov->agent, true, prov->conf_inputs.start.auth_action, oob_key, NULL, prov); } @@ -625,6 +673,7 @@ static void int_prov_rx(void *user_data, const uint8_t *data, uint16_t len) case PROV_INP_CMPLT: /* Provisioning Input Complete */ /* TODO: Cancel Agent prompt */ + prov->material |= MAT_RAND_AUTH; send_confirm(prov); break; -- 2.21.0