Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp6068367ybv; Wed, 12 Feb 2020 05:30:00 -0800 (PST) X-Google-Smtp-Source: APXvYqzl+tmgWtuM8eVROvynco4jrbB5nNoSek4LAu6XAf6Yk2sH4+0irnpTRgcW0bL8j7xpEKMJ X-Received: by 2002:a05:6830:1047:: with SMTP id b7mr9765595otp.77.1581514200470; Wed, 12 Feb 2020 05:30:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581514200; cv=none; d=google.com; s=arc-20160816; b=n/BUsC8HZ5leqcxuGwxs+Xd5X+5uG8GHrEZqsfeEx8dAsiefMrFixB5qZmRTS8d74/ aoVqy5IoudEdADQsnTddQZtmPqRMWnC9C/Dj5m13vhUZ1j9J4umtK+soUwShZ9ZNqpjw ImQZ/a0sW3fl5Y4bV/LE9xCBGEPhynvbVqi3rGYrcDoCP/xg7EaW3goKSnRt3ibjSYCC +G0QUsqwR1BhdaQm7ZFH3TPtceVDJosMNQnOAcT+9hMzsAcBEK956D3H+D6d99b8raIA Lzo3n4dz5i/A5XIp+h7ja+AIUSBLrZFnEY68wnYvOLz42NG6jv8D74eIubinCX5OT7Vn 0tQg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:from:subject:mime-version :message-id:date:dkim-signature; bh=a0w08ijI1bBuSp26GAvfYQVAuoXdK5WuLwYaVgwyb70=; b=JGVnMBh3xGcURLRbOKVBOq/TPf6s71d8IVS1npzn0JVRblG1Y9EMxmPRDIO4Dh4mSk M8kUeveooYtsizyMVOwMu/j1jqsLvvoD8gqO2zogFY1q7csxGBS+T/z8KQSe53ayQZJX XcPYN0BF16nysm7LFdRj46F93ErQCckej6GBJB+baJYFOHHsct/bmqE133T6kFopoNVC zUJlI1Bnq0G4Bts4tgonKYE1LI6PFH56c4ksrSI/EFwTwC3YW40XZ7ZG3XT588A2xNWo Hj7ysIyLpWwD1SRfSq+ncHkryJEwgrT5Z7ELMGaHov1ZM6+3fd8r0ysSEeWHIVy01HAa bLHQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=Y6hBqDKa; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c4si281609ots.107.2020.02.12.05.29.47; Wed, 12 Feb 2020 05:30:00 -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; dkim=pass header.i=@google.com header.s=20161025 header.b=Y6hBqDKa; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726728AbgBLN3n (ORCPT + 99 others); Wed, 12 Feb 2020 08:29:43 -0500 Received: from mail-pl1-f202.google.com ([209.85.214.202]:33341 "EHLO mail-pl1-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725887AbgBLN3n (ORCPT ); Wed, 12 Feb 2020 08:29:43 -0500 Received: by mail-pl1-f202.google.com with SMTP id bd7so1176700plb.0 for ; Wed, 12 Feb 2020 05:29:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:message-id:mime-version:subject:from:to:cc; bh=a0w08ijI1bBuSp26GAvfYQVAuoXdK5WuLwYaVgwyb70=; b=Y6hBqDKaID5ACQjZ1rK2pigmKkBLsv2O8MuWwaVpFjrP5Sns00XE04+sEIVpycZqFO RwvesdCOY47WPoGFw9QfHfuvKlFjWs2PkZ2CgWY/33I4EBL4VYRblX2gYSiLUD62YV8C CbPWNyQbm3VbjofIgS99vdD5aW8L1D6geRWVKiZ8BNCNJRY0DzYEUhHBFVdKPmGy889U uqRwGi5tMueAMzeoJG205i6dyXYNQclDusffZuMHh2IM0Q4ob8W0Anu6cEloyyM8uP4c Jxghkd+0jTwL0lHDSP57ihshfHDXpGLX3/KUkBUkwFzEuLTkRuwkr80hDkoxTUKwFMHf 2ANA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=a0w08ijI1bBuSp26GAvfYQVAuoXdK5WuLwYaVgwyb70=; b=OIFlyLORwSrFx1JClFYfQkz88Ck5ssYKCcRnZiEqZM666RQjR/n/6CNpJwZF4j9lWn bR8rYP6FjSBioK6TEhTln2thpZkM0bD8ph2rtstAoyzCCgV3Tj5y7mdEoxVlfz7EyeTc RF5j0wG3NUnbxIcrYghGO8ISzO7DC1+7260bY5TNBtfKtBdt3g8RChLvtId8FZmY8v2r WUiILgFbDOyV1QMME4oBUZRi9g/D1vtWF+6wYb5i8Sdf7av2JYmtROnV3HAIr7TgVNly Z5LgrNQsYw1HyUAWGO2aH/DKj2QBxF1/AoVFLMRWzJ0xs5KLLZPohzSoIKB8dtiwyZcp pgRg== X-Gm-Message-State: APjAAAXHUMhy9g3fpxJKeU/LGjrL7AEtdraAIEyd9j3YpEWyhIBSxlQr iiR22+AoE6JIYP4D+8GZPQIU6bwT6MzLrp3Il4slufURuEJe6l8GlhM5eMrIrsE2KGkvRHiJheu xunzM27XrvxE78IGtmX5r8n5GKO4vN4H/EmON2g+RYPH6APfGIH7Ky/i+cd71VOQNWZVkcfyC9i hbI6fvGWX9hv8= X-Received: by 2002:a63:705e:: with SMTP id a30mr12119424pgn.182.1581514182022; Wed, 12 Feb 2020 05:29:42 -0800 (PST) Date: Wed, 12 Feb 2020 21:29:33 +0800 Message-Id: <20200212212729.Bluez.v2.1.I333a90ad3c75882c6f008c94a28ca7d3e8f6c76e@changeid> Mime-Version: 1.0 X-Mailer: git-send-email 2.25.0.225.g125e21ebc7-goog Subject: [Bluez PATCH v2] core: Add new policy for Just-Works repairing From: Howard Chung To: linux-bluetooth@vger.kernel.org, luiz.von.dentz@intel.com Cc: chromeos-bluetooth-upstreaming@chromium.org, "howardchung@google.com" Content-Type: text/plain; charset="UTF-8" Sender: linux-bluetooth-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: "howardchung@google.com" When kernel find out that the incoming Just-Works pairing is initiated by a paired device, it is user space's responsibility to decide the next action. This patch includes the following: - add JustWorksRepairing policy as an option in main.conf - handle the confirmation request from kernel --- The Just-Works repairing policy could be one of the following: - never: default; reject the repairing immediately. - confirm: prompt a confirmation dialog to user. - always: always accept the repairing. Changes in v2: - let RequestAuthorization handle the situation - remove the changes in client/ src/agent.c | 16 ++++++++++++++++ src/hcid.h | 8 ++++++++ src/main.c | 27 +++++++++++++++++++++++++++ src/main.conf | 5 +++++ 4 files changed, 56 insertions(+) diff --git a/src/agent.c b/src/agent.c index e0ffcd22f..e013ec85f 100644 --- a/src/agent.c +++ b/src/agent.c @@ -773,12 +773,28 @@ int agent_request_authorization(struct agent *agent, struct btd_device *device, GDestroyNotify destroy) { struct agent_request *req; + DBusError dbus_err; int err; err = agent_has_request(agent, device, AGENT_REQUEST_AUTHORIZATION); if (err) return err; + /* Just-Works repairing policy */ + if (device_is_paired(device, BDADDR_BREDR) || + device_is_paired(device, BDADDR_LE_PUBLIC)) { + if (main_opts.jw_repairing == JW_REPAIRING_NEVER) { + dbus_error_init(&dbus_err); + dbus_set_error_const(&dbus_err, + ERROR_INTERFACE ".Rejected", NULL); + cb(agent, &dbus_err, user_data); + return 0; + } else if (main_opts.jw_repairing == JW_REPAIRING_ALWAYS) { + cb(agent, NULL, user_data); + return 0; + } + } + DBG("Calling Agent.RequestAuthorization: name=%s, path=%s", agent->owner, agent->path); diff --git a/src/hcid.h b/src/hcid.h index adea85ce2..bcd2b9fa1 100644 --- a/src/hcid.h +++ b/src/hcid.h @@ -35,6 +35,12 @@ typedef enum { BT_GATT_CACHE_NO, } bt_gatt_cache_t; +enum { + JW_REPAIRING_NEVER, + JW_REPAIRING_CONFIRM, + JW_REPAIRING_ALWAYS, +} jw_repairing_t; + struct main_opts { char *name; uint32_t class; @@ -58,6 +64,8 @@ struct main_opts { uint16_t gatt_mtu; uint8_t key_size; + + jw_repairing_t jw_repairing; }; extern struct main_opts main_opts; diff --git a/src/main.c b/src/main.c index 1a6ab36a3..d67f469f1 100644 --- a/src/main.c +++ b/src/main.c @@ -93,6 +93,7 @@ static const char *supported_options[] = { "MultiProfile", "FastConnectable", "Privacy", + "JustWorksRepairing", NULL }; @@ -193,6 +194,20 @@ static bt_gatt_cache_t parse_gatt_cache(const char *cache) } } +static jw_repairing_t parse_jw_repairing(const char *jw_repairing) +{ + if (!strcmp(jw_repairing, "never")) { + return JW_REPAIRING_NEVER; + } else if (!strcmp(jw_repairing, "confirm")) { + return JW_REPAIRING_CONFIRM; + } else if (!strcmp(jw_repairing, "always")) { + return JW_REPAIRING_ALWAYS; + } else { + return JW_REPAIRING_NEVER; + } +} + + static void check_options(GKeyFile *config, const char *group, const char **options) { @@ -331,6 +346,18 @@ static void parse_config(GKeyFile *config) g_free(str); } + str = g_key_file_get_string(config, "General", + "JustWorksRepairing", &err); + if (err) { + DBG("%s", err->message); + g_clear_error(&err); + main_opts.jw_repairing = JW_REPAIRING_NEVER; + } else { + DBG("just_works_repairing=%s", str); + main_opts.jw_repairing = parse_jw_repairing(str); + g_free(str); + } + str = g_key_file_get_string(config, "General", "Name", &err); if (err) { DBG("%s", err->message); diff --git a/src/main.conf b/src/main.conf index 40687a755..bb5ff5b15 100644 --- a/src/main.conf +++ b/src/main.conf @@ -72,6 +72,11 @@ # Defaults to "off" # Privacy = off +# Specify the policy to the JUST-WORKS repairing initiated by peer +# Possible values: "never", "confirm", "always" +# Defaults to "never" +#JustWorksRepairing = never + [GATT] # GATT attribute cache. # Possible values: -- 2.25.0.225.g125e21ebc7-goog