Merge lp:~seb128/ubuntu-system-settings/bluetooth-simple-secure into lp:ubuntu-system-settings

Proposed by Sebastien Bacher
Status: Merged
Approved by: Charles Kerr
Approved revision: 1292
Merged at revision: 1297
Proposed branch: lp:~seb128/ubuntu-system-settings/bluetooth-simple-secure
Merge into: lp:ubuntu-system-settings
Prerequisite: lp:~seb128/ubuntu-system-settings/bluetooth-correct-signature
Diff against target: 234 lines (+134/-12)
5 files modified
plugins/bluetooth/CMakeLists.txt (+1/-0)
plugins/bluetooth/DisplayPasskeyDialog.qml (+56/-0)
plugins/bluetooth/PageComponent.qml (+25/-0)
plugins/bluetooth/agent.cpp (+49/-11)
plugins/bluetooth/agent.h (+3/-1)
To merge this branch: bzr merge lp:~seb128/ubuntu-system-settings/bluetooth-simple-secure
Reviewer Review Type Date Requested Status
Michael Zanetti (community) Abstain
PS Jenkins bot continuous-integration Needs Fixing
Charles Kerr (community) Approve
Review via email: mp+248578@code.launchpad.net

Commit message

bluetooth: implement simple secure pairing dialog

Description of the change

bluetooth: implement simple secure pairing dialog

To post a comment you must log in.
Revision history for this message
Sebastien Bacher (seb128) wrote :

note that there is no design for that mode at the moment, the current UI is inspired from what the desktop is doing

Revision history for this message
Charles Kerr (charlesk) wrote :

I can't do a real-world test with this because I don't have a bluetooth device that triggers this, but wrt reviewing the code, LGTM

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Michael Zanetti (mzanetti) wrote :

Tested this on the tablet, seems not to completely work yet. The pin isn't displayed properly.

review: Needs Fixing
Revision history for this message
Sebastien Bacher (seb128) wrote :

I had a look at Michael's issue, on that device bluez DisplayPasskey() gives us a random value for "entered" (number of chars already typed) as soon as pairing starts (got 79 and 105 on the most recent runs) where it should be 0, not really a problem in the settings

Revision history for this message
Michael Zanetti (mzanetti) wrote :

ok, seems it's indeed not this branch's fault.

review: Abstain

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'plugins/bluetooth/CMakeLists.txt'
2--- plugins/bluetooth/CMakeLists.txt 2013-10-22 14:44:44 +0000
3+++ plugins/bluetooth/CMakeLists.txt 2015-02-04 16:40:34 +0000
4@@ -3,6 +3,7 @@
5 set(QML_SOURCES
6 ProvidePinCodeDialog.qml
7 ConfirmPasskeyDialog.qml
8+DisplayPasskeyDialog.qml
9 ProvidePasskeyDialog.qml
10 PageComponent.qml
11 )
12
13=== added file 'plugins/bluetooth/DisplayPasskeyDialog.qml'
14--- plugins/bluetooth/DisplayPasskeyDialog.qml 1970-01-01 00:00:00 +0000
15+++ plugins/bluetooth/DisplayPasskeyDialog.qml 2015-02-04 16:40:34 +0000
16@@ -0,0 +1,56 @@
17+/*
18+ * This file is part of ubuntu-system-settings
19+ *
20+ * Copyright (C) 2013 Canonical Ltd.
21+ *
22+ * This program is free software: you can redistribute it and/or modify it
23+ * under the terms of the GNU General Public License version 3, as published
24+ * by the Free Software Foundation.
25+ *
26+ * This program is distributed in the hope that it will be useful, but
27+ * WITHOUT ANY WARRANTY; without even the implied warranties of
28+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
29+ * PURPOSE. See the GNU General Public License for more details.
30+ *
31+ * You should have received a copy of the GNU General Public License along
32+ * with this program. If not, see <http://www.gnu.org/licenses/>.
33+ */
34+
35+
36+import QtQuick 2.0
37+import Ubuntu.Components 0.1
38+import Ubuntu.Components.Popups 0.1
39+
40+Dialog {
41+ id: root
42+ title: i18n.tr("Bluetooth Pairing Request")
43+
44+ property string name: "Unknown"
45+ property string passkey: "000000"
46+ property string entered: "0"
47+
48+ signal canceled
49+
50+ // TRANSLATORS: %1 is the name of the bluetooth device being paired
51+ text: i18n.tr("Please enter the following PIN on %1 and press “Enter” on the keyboard:").arg(root.name)
52+
53+ Label {
54+ /* display the number of chars that remain to be typed */
55+ text: root.passkey.slice(entered)+"⏎"
56+ fontSize: "x-large"
57+ verticalAlignment: Text.AlignVCenter
58+ horizontalAlignment: Text.AlignHCenter
59+ }
60+
61+ Row {
62+ spacing: units.gu(1)
63+ Button {
64+ text: i18n.tr("Cancel")
65+ onClicked: {
66+ root.canceled()
67+ PopupUtils.close(root)
68+ }
69+ width: (parent.width - parent.spacing)
70+ }
71+ }
72+}
73
74=== modified file 'plugins/bluetooth/PageComponent.qml'
75--- plugins/bluetooth/PageComponent.qml 2014-12-10 20:55:12 +0000
76+++ plugins/bluetooth/PageComponent.qml 2015-02-04 16:40:34 +0000
77@@ -32,6 +32,8 @@
78 title: i18n.tr("Bluetooth")
79 objectName: "bluetoothPage"
80
81+ property var dialogPopupId
82+
83 UbuntuBluetoothPanel { id: backend }
84
85 Component {
86@@ -49,6 +51,11 @@
87 ProvidePinCodeDialog { }
88 }
89
90+ Component {
91+ id: displayPasskeyDialog
92+ DisplayPasskeyDialog { }
93+ }
94+
95 Connections {
96 target: backend.agent
97 onPasskeyConfirmationNeeded: {
98@@ -69,6 +76,24 @@
99 popup.canceled.connect(function() {target.providePinCode(request_tag, false, "")})
100 popup.provided.connect(function(pinCode) {target.providePinCode(request_tag, true, pinCode)})
101 }
102+ onDisplayPasskeyNeeded: {
103+ if (!root.dialogPopupId)
104+ {
105+ var request_tag = tag
106+ root.dialogPopupId = PopupUtils.open(displayPasskeyDialog, root, {passkey: passkey, name: device.name,
107+ entered: entered})
108+ root.dialogPopupId.canceled.connect(function() {root.dialogPopupId = null;
109+ target.displayPasskeyCallback(request_tag)})
110+ }
111+ else
112+ {
113+ root.dialogPopupId.entered = entered
114+ }
115+ }
116+ onPairingDone: {
117+ if (root.dialogPopupId)
118+ PopupUtils.close(root.dialogPopupId)
119+ }
120 }
121
122 function getDisplayName(type, displayName) {
123
124=== modified file 'plugins/bluetooth/agent.cpp'
125--- plugins/bluetooth/agent.cpp 2015-02-04 16:40:34 +0000
126+++ plugins/bluetooth/agent.cpp 2015-02-04 16:40:34 +0000
127@@ -22,7 +22,6 @@
128
129 #include <cassert>
130
131-
132 /***
133 ****
134 ***/
135@@ -54,7 +53,7 @@
136 */
137 void Agent::Release()
138 {
139- Q_EMIT(onPairingDone());
140+ Q_EMIT(pairingDone());
141 }
142
143 /***
144@@ -219,20 +218,59 @@
145 }
146 }
147
148-/***
149-****
150-***/
151+/** This method gets called when the service daemon
152+ * needs to display a passkey for an authentication.
153+ * The entered parameter indicates the number of already
154+ * typed keys on the remote side.
155+ * An empty reply should be returned. When the passkey
156+ * needs no longer to be displayed, the Cancel method
157+ * of the agent will be called.
158+ * During the pairing process this method might be
159+ * called multiple times to update the entered value.
160+ * Note that the passkey will always be a 6-digit number,
161+ * so the display should be zero-padded at the start if
162+ * the value contains less than 6 digits.
163+ */
164
165 void Agent::DisplayPasskey(const QDBusObjectPath &objectPath, uint passkey, ushort entered)
166 {
167- Q_UNUSED(objectPath);
168- Q_UNUSED(passkey);
169- Q_UNUSED(entered);
170-
171- // unimplemented -- unneeded for headsets
172+ auto device = m_devices.getDeviceFromPath(objectPath.path());
173+ if (device) {
174+ const uint tag = m_tag++;
175+
176+ setDelayedReply(true);
177+ assert(!m_delayedReplies.contains(tag));
178+ m_delayedReplies[tag] = message();
179+
180+ QString passkeyStr = QString("%1").arg(passkey, 6, 10, QChar('0'));
181+ Q_EMIT(displayPasskeyNeeded(tag, device.data(), passkeyStr, entered));
182+ } else { // confirmation requested for an unknown device..?!
183+ reject(message(), __func__);
184+ }
185 }
186
187+/**
188+ * This method gets called to indicate that the agent
189+ * request failed before a reply was returned.
190+ */
191 void Agent::Cancel()
192 {
193- // unimplemented -- companion function for DisplayPasskey
194+ qWarning() << "Cancel callback called";
195+}
196+
197+/**
198+ * Invoked by the user-facing code after it prompts the user to cancel
199+ * the passkey passed from an Agent::displayPasskeyNeeded signal.
200+ *
201+ * @param tag: the tag from the Agent::displayPasskeyNeeded signal
202+ */
203+void Agent::displayPasskeyCallback(uint tag)
204+{
205+ if (m_delayedReplies.contains(tag)) {
206+ QDBusMessage message = m_delayedReplies[tag];
207+
208+ cancel(message, __func__);
209+
210+ m_delayedReplies.remove(tag);
211+ }
212 }
213
214=== modified file 'plugins/bluetooth/agent.h'
215--- plugins/bluetooth/agent.h 2015-02-04 16:40:34 +0000
216+++ plugins/bluetooth/agent.h 2015-02-04 16:40:34 +0000
217@@ -41,6 +41,7 @@
218 Q_INVOKABLE void confirmPasskey(uint tag, bool confirmed);
219 Q_INVOKABLE void providePasskey(uint tag, bool provided, uint passkey);
220 Q_INVOKABLE void providePinCode(uint tag, bool provided, QString pinCode);
221+ Q_INVOKABLE void displayPasskeyCallback(uint tag);
222
223 public Q_SLOTS: // received from the system's bluez service
224 void Cancel();
225@@ -54,7 +55,8 @@
226 void pinCodeNeeded(int tag, Device* device);
227 void passkeyNeeded(int tag, Device* device);
228 void passkeyConfirmationNeeded(int tag, Device* device, QString passkey);
229- void onPairingDone();
230+ void displayPasskeyNeeded(int tag, Device* device, QString passkey, ushort entered);
231+ void pairingDone();
232
233 private:
234 Q_DISABLE_COPY(Agent)

Subscribers

People subscribed via source and target branches