Linux bluetooth development
 help / color / mirror / Atom feed
From: Lukasz Rymanowski <lukasz.rymanowski@tieto.com>
To: linux-bluetooth@vger.kernel.org
Cc: szymon.janc@tieto.com, johan.hedberg@gmail.com,
	Lukasz Rymanowski <lukasz.rymanowski@tieto.com>
Subject: [PATCH v3 12/12] android/gatt: Add handling signed write from remote device
Date: Thu, 22 May 2014 21:06:26 +0200	[thread overview]
Message-ID: <1400785586-22710-13-git-send-email-lukasz.rymanowski@tieto.com> (raw)
In-Reply-To: <1400785586-22710-1-git-send-email-lukasz.rymanowski@tieto.com>

---
 android/gatt.c | 42 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 42 insertions(+)

diff --git a/android/gatt.c b/android/gatt.c
index 33e1db9..4c5409a 100644
--- a/android/gatt.c
+++ b/android/gatt.c
@@ -4763,6 +4763,44 @@ static void write_cmd_request(const uint8_t *cmd, uint16_t cmd_len,
 	gatt_db_write(gatt_db, handle, 0, value, vlen, cmd[0], &dev->bdaddr);
 }
 
+static void write_signed_cmd_request(const uint8_t *cmd, uint16_t cmd_len,
+						struct gatt_device *dev)
+{
+	uint8_t value[ATT_DEFAULT_LE_MTU];
+	uint8_t s[ATT_SIGNATURE_LEN];
+	uint16_t handle;
+	uint16_t len;
+	size_t vlen;
+	uint8_t csrk[16];
+	uint32_t sign_cnt;
+
+	if (!bt_get_csrk(&dev->bdaddr, REMOTE_CSRK, csrk, &sign_cnt)) {
+		error("gatt: No valid csrk from remote device");
+		return;
+	}
+
+	len = dec_signed_write_cmd(cmd, cmd_len, &handle, value, &vlen, s);
+	if (len) {
+		uint8_t t[ATT_SIGNATURE_LEN];
+
+		/* Generate signature and verify it */
+		if (!bt_crypto_sign_att(crypto, csrk, value, vlen, sign_cnt,
+									t)) {
+			error("gatt: Error when generating att signature");
+			return;
+		}
+
+		if (memcmp(t, s, ATT_SIGNATURE_LEN)) {
+			error("gatt: signature does not match");
+			return;
+		}
+		/* Signature OK, proceed with write */
+		bt_update_sign_counter(&dev->bdaddr, REMOTE_CSRK);
+		gatt_db_write(gatt_db, handle, 0, value, vlen, cmd[0],
+								&dev->bdaddr);
+	}
+}
+
 static uint8_t write_req_request(const uint8_t *cmd, uint16_t cmd_len,
 						struct gatt_device *dev)
 {
@@ -4876,6 +4914,10 @@ static void att_handler(const uint8_t *ipdu, uint16_t len, gpointer user_data)
 		write_cmd_request(ipdu, len, dev);
 		/* No response on write cmd */
 		return;
+	case ATT_OP_SIGNED_WRITE_CMD:
+		write_signed_cmd_request(ipdu, len, dev);
+		/* No response on write signed cmd */
+		return;
 	case ATT_OP_PREP_WRITE_REQ:
 		status = write_prep_request(ipdu, len, dev);
 		if (!status)
-- 
1.8.4


  parent reply	other threads:[~2014-05-22 19:06 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-05-22 19:06 [PATCH v3 00/12] android/gatt: Add support for write signature command Lukasz Rymanowski
2014-05-22 19:06 ` [PATCH v3 01/12] shared/crypto: Extend bt_crypto_sign_att with sign counter Lukasz Rymanowski
2014-05-22 19:06 ` [PATCH v3 02/12] attrib: Add helpers to enc and dec signed write command Lukasz Rymanowski
2014-05-22 19:06 ` [PATCH v3 03/12] attrib/gatt: Add wrapper to send " Lukasz Rymanowski
2014-05-22 19:06 ` [PATCH v3 04/12] android/bluetooth: Expose API to get CSRK for device Lukasz Rymanowski
2014-05-22 19:06 ` [PATCH v3 05/12] android/bluetooth: Expose API to update sign counter Lukasz Rymanowski
2014-05-22 19:06 ` [PATCH v3 06/12] android/bluetooth: Add support to read CSRK from the kernel Lukasz Rymanowski
2014-05-22 19:06 ` [PATCH v3 07/12] android/bluetooth: Store CSRK Lukasz Rymanowski
2014-05-22 19:06 ` [PATCH v3 08/12] android/bluetooth: Read CSRK from the storage on startup Lukasz Rymanowski
2014-05-22 19:06 ` [PATCH v3 09/12] android/bluetooth: Store sign counter needed for aes-cmac sign Lukasz Rymanowski
2014-05-22 19:06 ` [PATCH v3 10/12] android/gatt: Add crypto needed for sign write Lukasz Rymanowski
2014-05-22 19:06 ` [PATCH v3 11/12] android/gatt: Add support for signed write command Lukasz Rymanowski
2014-05-22 19:06 ` Lukasz Rymanowski [this message]
2014-05-26  8:41 ` [PATCH v3 00/12] android/gatt: Add support for write signature command Szymon Janc

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1400785586-22710-13-git-send-email-lukasz.rymanowski@tieto.com \
    --to=lukasz.rymanowski@tieto.com \
    --cc=johan.hedberg@gmail.com \
    --cc=linux-bluetooth@vger.kernel.org \
    --cc=szymon.janc@tieto.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox