Skip to contentSkip to conversation

Bluetooth: Add support for handling signature resolving keys

PATCH Applied Marcel Holtmann 2 participants 2 messages Mar 9, 2014

Subsystems (2)
lore
Share & tools
lore

Marcel Holtmann

author maintainer
#0 lore raw

PATCH 1/1 Bluetooth: Add support for handling signature resolving keys

The connection signature resolving key (CSRK) is used for attribute protocol signed write procedures. This change generates a new local key during pairing and requests the peer key as well.

Newly generated key and received key will be provided to userspace using the New Signature Resolving Key management event.

The Master CSRK can be used for verification of remote signed write PDUs and the Slave CSRK can be used for sending signed write PDUs to the remote device.

---
 include/net/bluetooth/hci_core.h |  8 +++++
 include/net/bluetooth/mgmt.h     | 12 +++++++
 net/bluetooth/mgmt.c             | 30 ++++++++++++++++++
 net/bluetooth/smp.c              | 67 +++++++++++++++++++++++++++++++++++++---
 net/bluetooth/smp.h              |  2 ++
 5 files changed, 114 insertions(+), 5 deletions(-)
include/net/bluetooth/hci_core.h +8 -0
index dbb788e4f265..e869884fbfa9 100644
@@ -91,6 +91,13 @@ struct bt_uuid {
 	u8 svc_hint;
 };
 
+struct smp_csrk {
+	bdaddr_t bdaddr;
+	u8 bdaddr_type;
+	u8 master;
+	u8 val[16];
+};
+
 struct smp_ltk {
 	struct list_head list;
 	bdaddr_t bdaddr;
@@ -1265,6 +1272,7 @@ int mgmt_device_blocked(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 type);
 int mgmt_device_unblocked(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 type);
 void mgmt_new_ltk(struct hci_dev *hdev, struct smp_ltk *key);
 void mgmt_new_irk(struct hci_dev *hdev, struct smp_irk *irk);
+void mgmt_new_csrk(struct hci_dev *hdev, struct smp_csrk *csrk);
 void mgmt_reenable_advertising(struct hci_dev *hdev);
 void mgmt_smp_complete(struct hci_conn *conn, bool complete);
 
include/net/bluetooth/mgmt.h +12 -0
index 0326648fd799..d4b571c2f9fd 100644
@@ -551,3 +551,15 @@ struct mgmt_ev_new_irk {
 	bdaddr_t rpa;
 	struct mgmt_irk_info irk;
 } __packed;
+
+struct mgmt_csrk_info {
+	struct mgmt_addr_info addr;
+	__u8 master;
+	__u8 val[16];
+} __packed;
+
+#define MGMT_EV_NEW_CSRK		0x0019
+struct mgmt_ev_new_csrk {
+	__u8 store_hint;
+	struct mgmt_csrk_info key;
+} __packed;
net/bluetooth/mgmt.c +30 -0
index f2397e7ad385..9c7788914b4e 100644
@@ -108,6 +108,7 @@ static const u16 mgmt_events[] = {
 	MGMT_EV_DEVICE_UNPAIRED,
 	MGMT_EV_PASSKEY_NOTIFY,
 	MGMT_EV_NEW_IRK,
+	MGMT_EV_NEW_CSRK,
 };
 
 #define CACHE_TIMEOUT	msecs_to_jiffies(2 * 1000)
@@ -5072,6 +5073,35 @@ void mgmt_new_irk(struct hci_dev *hdev, struct smp_irk *irk)
 	mgmt_event(MGMT_EV_NEW_IRK, hdev, &ev, sizeof(ev), NULL);
 }
 
+void mgmt_new_csrk(struct hci_dev *hdev, struct smp_csrk *csrk)
+{
+	struct mgmt_ev_new_csrk ev;
+
+	memset(&ev, 0, sizeof(ev));
+
+	/* Devices using resolvable or non-resolvable random addresses
+	 * without providing an indentity resolving key don't require
+	 * to store signature resolving keys. Their addresses will change
+	 * the next time around.
+	 *
+	 * Only when a remote device provides an identity address
+	 * make sure the signature resolving key is stored. So allow
+	 * static random and public addresses here.
+	 */
+	if (csrk->bdaddr_type == ADDR_LE_DEV_RANDOM &&
+	    (csrk->bdaddr.b[5] & 0xc0) != 0xc0)
+		ev.store_hint = 0x00;
+	else
+		ev.store_hint = 0x01;
+
+	bacpy(&ev.key.addr.bdaddr, &csrk->bdaddr);
+	ev.key.addr.type = link_to_bdaddr(LE_LINK, csrk->bdaddr_type);
+	ev.key.master = csrk->master;
+	memcpy(ev.key.val, csrk->val, sizeof(csrk->val));
+
+	mgmt_event(MGMT_EV_NEW_CSRK, hdev, &ev, sizeof(ev), NULL);
+}
+
 static inline u16 eir_append_data(u8 *eir, u16 eir_len, u8 type, u8 *data,
 				  u8 data_len)
 {
net/bluetooth/smp.c +62 -5

106 lines not on this page · raw message

net/bluetooth/smp.h +2 -0
index f55d83617218..f223b9d38b61 100644
@@ -136,6 +136,8 @@ struct smp_chan {
 	bdaddr_t	id_addr;
 	u8		id_addr_type;
 	u8		irk[16];
+	struct smp_csrk	*csrk;
+	struct smp_csrk	*slave_csrk;
 	struct smp_ltk	*ltk;
 	struct smp_ltk	*slave_ltk;
 	struct smp_irk	*remote_irk;
Signature · 1 line
1.8.5.3
#1 lore raw

Hi Marcel,

Quoted 11 lines · Marcel Holtmann

The connection signature resolving key (CSRK) is used for attribute protocol signed write procedures. This change generates a new local key during pairing and requests the peer key as well.

Newly generated key and received key will be provided to userspace using the New Signature Resolving Key management event.

The Master CSRK can be used for verification of remote signed write PDUs and the Slave CSRK can be used for sending signed write PDUs to the remote device.

Quoted 8 lines
---
 include/net/bluetooth/hci_core.h |  8 +++++
 include/net/bluetooth/mgmt.h     | 12 +++++++
 net/bluetooth/mgmt.c             | 30 ++++++++++++++++++
 net/bluetooth/smp.c              | 67 +++++++++++++++++++++++++++++++++++++---
 net/bluetooth/smp.h              |  2 ++
 5 files changed, 114 insertions(+), 5 deletions(-)

Applied to bluetooth-next. Thanks.

Johan