Skip to contentSkip to conversation

Bluetooth: Add MITM protection to LE-SMP

PATCH Superseded Brian Gix 2 participants 6 messages Dec 21, 2011

Subsystems (2)

v8 of 9 Superseded Latest is v9 →

lore
Share & tools
lore

Brian Gix

author
#0 lore raw

v8 cover Bluetooth: Add MITM protection to LE-SMP

Made modifications as suggested by Marcel. (Patch 1) Added Marcel's Ack (Patch 2)

Signature · 4 lines
Brian Gix
[email protected]
Employee of Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum
author
#1 lore raw

PATCH v8 1/2 Bluetooth: Add MITM mechanism to LE-SMP

To achive Man-In-The-Middle (MITM) level security with Low Energy, we have to enable User Passkey Comparison. This commit modifies the hard-coded JUST-WORKS pairing mechanism to support query via the MGMT interface of Passkey comparison and User Confirmation.

---
 include/net/bluetooth/hci_core.h |    1 +
 include/net/bluetooth/smp.h      |    6 +
 net/bluetooth/smp.c              |  226 ++++++++++++++++++++++++++++++++++----
 3 files changed, 211 insertions(+), 22 deletions(-)
include/net/bluetooth/hci_core.h +1 -0
index 25c161a..295cd90 100644
@@ -314,6 +314,7 @@ struct hci_conn {
 	struct hci_dev	*hdev;
 	void		*l2cap_data;
 	void		*sco_data;
+	void		*smp_conn;
 
 	struct hci_conn	*link;
 
include/net/bluetooth/smp.h +6 -0
index 15b97d5..aeaf5fa 100644
@@ -115,6 +115,10 @@ struct smp_cmd_security_req {
 #define SMP_MIN_ENC_KEY_SIZE		7
 #define SMP_MAX_ENC_KEY_SIZE		16
 
+#define SMP_FLAG_TK_VALID	1
+#define SMP_FLAG_CFM_PENDING	2
+#define SMP_FLAG_MITM_AUTH	3
+
 struct smp_chan {
 	struct l2cap_conn *conn;
 	u8		preq[7]; /* SMP Pairing Request */
@@ -124,6 +128,7 @@ struct smp_chan {
 	u8		pcnf[16]; /* SMP Pairing Confirm */
 	u8		tk[16]; /* SMP Temporary Key */
 	u8		smp_key_size;
+	unsigned long	smp_flags;
 	struct crypto_blkcipher	*tfm;
 	struct work_struct confirm;
 	struct work_struct random;
@@ -134,6 +139,7 @@ struct smp_chan {
 int smp_conn_security(struct l2cap_conn *conn, __u8 sec_level);
 int smp_sig_channel(struct l2cap_conn *conn, struct sk_buff *skb);
 int smp_distribute_keys(struct l2cap_conn *conn, __u8 force);
+int smp_user_confirm_reply(struct hci_conn *conn, u16 mgmt_op, __le32 passkey);
 
 void smp_chan_destroy(struct l2cap_conn *conn);
 
net/bluetooth/smp.c +204 -22

370 lines not on this page · raw message

Signature · 7 lines
1.7.8

-- 
Brian Gix
[email protected]
Employee of Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum 
maintainer Acked-by on v8 1/2
#2 lore raw

Re: [PATCH-v8 1/2] Bluetooth: Add MITM mechanism to LE-SMP

Hi Brian,

Quoted 1 line

+static const u8 gen_method[5][5] = {

can the tab between u8 and gen_method please go away.

net/bluetooth/smp.c static void smp_failure(struct l2cap_conn *conn, u8 reason, u8 send) · line 283

Quoted 6 lines
net/bluetooth/smp.c +6 -0
+	{ JUST_WORKS, JUST_CFM, REQ_PASSKEY, JUST_WORKS, REQ_PASSKEY     },
+	{ JUST_WORKS, JUST_CFM, REQ_PASSKEY, JUST_WORKS, REQ_PASSKEY     },
+	{ CFM_PASSKEY, CFM_PASSKEY, REQ_PASSKEY, JUST_WORKS, CFM_PASSKEY },
+	{ JUST_WORKS, JUST_CFM, JUST_WORKS, JUST_WORKS, JUST_CFM         },
+	{ CFM_PASSKEY, CFM_PASSKEY, REQ_PASSKEY, JUST_WORKS, OVERLAP     },
+};

Can you make sure all elements are aligned like you had it before. So the table becomes readable. If you go over 80 chars here then that is fine. So be it.

For the rest I am happy with it.

Regards

Marcel

author
#3 lore raw

Re: [PATCH-v8 1/2] Bluetooth: Add MITM mechanism to LE-SMP

Hi Marcel,

Quoted 6 lines · Marcel Holtmann

Hi Brian,

Quoted 1 line

+static const u8 gen_method[5][5] = {

can the tab between u8 and gen_method please go away.

Quoted 11 lines

net/bluetooth/smp.c static void smp_failure(struct l2cap_conn *conn, u8 reason, u8 send) · line 283

Quoted 6 lines
net/bluetooth/smp.c +6 -0
+	{ JUST_WORKS, JUST_CFM, REQ_PASSKEY, JUST_WORKS, REQ_PASSKEY     },
+	{ JUST_WORKS, JUST_CFM, REQ_PASSKEY, JUST_WORKS, REQ_PASSKEY     },
+	{ CFM_PASSKEY, CFM_PASSKEY, REQ_PASSKEY, JUST_WORKS, CFM_PASSKEY },
+	{ JUST_WORKS, JUST_CFM, JUST_WORKS, JUST_WORKS, JUST_CFM         },
+	{ CFM_PASSKEY, CFM_PASSKEY, REQ_PASSKEY, JUST_WORKS, OVERLAP     },
+};

Can you make sure all elements are aligned like you had it before. So the table becomes readable. If you go over 80 chars here then that is fine. So be it.

Sure. Sorry, I misunderstood which tab you were referring to last time.

Quoted 4 lines

For the rest I am happy with it.

Signature · 4 lines
Brian Gix
[email protected]
Employee of Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum
author
#4 lore raw

PATCH v8 2/2 Bluetooth: Add SMP to User Passkey and Confirm

In reply to Brian Gix

Low Energy pairing is performed through the SMP (Security Manager Protocol) mechanism rather than HCI.

---
 net/bluetooth/mgmt.c |   10 +++++++++-
 1 files changed, 9 insertions(+), 1 deletions(-)
net/bluetooth/mgmt.c +9 -1
index fbcbef6..2540944 100644
@@ -30,6 +30,7 @@
 #include <net/bluetooth/bluetooth.h>
 #include <net/bluetooth/hci_core.h>
 #include <net/bluetooth/mgmt.h>
+#include <net/bluetooth/smp.h>
 
 #define MGMT_VERSION	0
 #define MGMT_REVISION	1
@@ -1642,8 +1643,15 @@ static int user_pairing_resp(struct sock *sk, u16 index, bdaddr_t *bdaddr,
 		}
 
 		/* Continue with pairing via SMP */
+		err = smp_user_confirm_reply(conn, mgmt_op, passkey);
+
+		if (!err)
+			err = cmd_status(sk, index, mgmt_op,
+							MGMT_STATUS_SUCCESS);
+		else
+			err = cmd_status(sk, index, mgmt_op,
+							MGMT_STATUS_FAILED);
 
-		err = cmd_status(sk, index, mgmt_op, MGMT_STATUS_SUCCESS);
 		goto done;
 	}
 
Signature · 7 lines
1.7.8

-- 
Brian Gix
[email protected]
Employee of Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum 
maintainer
#5 lore raw

Re: [PATCH-v8 2/2] Bluetooth: Add SMP to User Passkey and Confirm

Hi Brian,

Quoted 5 lines

Low Energy pairing is performed through the SMP (Security Manager Protocol) mechanism rather than HCI.

so actually your signed-off-by should come first, then my ack and then eventually Gustavo's signed-off-by once he merged the patches.

I am always fine if you guys carry my ack around. Even if minor modifications were needed. No need to complicate things here.

Regards

Marcel