doc/gatt-api: Add encryption flags
Luiz Augusto von Dentz
maintainerPATCH 1/4 doc/gatt-api: Add encryption flags
From: Luiz Augusto von Dentz <[email protected]>
This add encryption flags which can be used when registering a service to require encryption when accessing a characteristic.
--- doc/gatt-api.txt | 4 ++++ 1 file changed, 4 insertions(+)
doc/gatt-api.txt +4 -0
@@ -148,6 +148,10 @@ Properties string UUID [read-only] "authenticated-signed-writes" "reliable-write" "writable-auxiliaries" + "encrypt-read" + "encrypt-write" + "encrypt-authenticated-read" + "encrypt-authenticated-write" array{object} Descriptors [read-only]
Signature · 1 line
2.1.0
Luiz Augusto von Dentz
maintainerPATCH 2/4 core/gatt: Add support for encryption flags
From: Luiz Augusto von Dentz <[email protected]>
This adds support to encryption related flags as defined in the documentation.
--- src/gatt-database.c | 28 ++++++++++++++++++++++++++-- src/shared/att-types.h | 30 ++++++++++++++++++++++-------- 2 files changed, 48 insertions(+), 10 deletions(-)
src/gatt-database.c +26 -2
@@ -1241,6 +1241,14 @@ static bool parse_flags(GDBusProxy *proxy, uint8_t *props, uint8_t *ext_props) *ext_props |=BT_GATT_CHRC_EXT_PROP_RELIABLE_WRITE ; else if (!strcmp("writable-auxiliaries", flag)) *ext_props |=BT_GATT_CHRC_EXT_PROP_WRITABLE_AUX ; + else if (!strcmp("encrypt-read", flag)) + *ext_props |=BT_GATT_CHRC_EXT_PROP_ENC_READ ; + else if (!strcmp("encrypt-write", flag)) + *ext_props |=BT_GATT_CHRC_EXT_PROP_ENC_WRITE ; + else if (!strcmp("encrypt-authenticated-read", flag)) + *ext_props |=BT_GATT_CHRC_EXT_PROP_AUTH_READ ; + else if (!strcmp("encrypt-authenticated-write", flag)) + *ext_props |=BT_GATT_CHRC_EXT_PROP_AUTH_WRITE ; else {error ("Invalid characteristic flag: %s" , flag);return false;
@@ -1668,12 +1676,28 @@ static uint32_t permissions_from_props(uint8_t props, uint8_t ext_props)if (props &BT_GATT_CHRC_PROP_WRITE || props &BT_GATT_CHRC_PROP_WRITE_WITHOUT_RESP || - ext_props &BT_GATT_CHRC_EXT_PROP_RELIABLE_WRITE ) + ext_props &BT_GATT_CHRC_EXT_PROP_RELIABLE_WRITE || + ext_props &BT_GATT_CHRC_EXT_PROP_ENC_WRITE || + ext_props &BT_GATT_CHRC_EXT_PROP_AUTH_WRITE ) perm |=BT_ATT_PERM_WRITE ; -if (props &BT_GATT_CHRC_PROP_READ ) +if (props &BT_GATT_CHRC_PROP_READ || + ext_props &BT_GATT_CHRC_EXT_PROP_ENC_READ || + ext_props &BT_GATT_CHRC_EXT_PROP_AUTH_READ ) perm |=BT_ATT_PERM_READ ; +if (ext_props &BT_GATT_CHRC_EXT_PROP_ENC_READ ) + perm |=BT_ATT_PERM_READ_ENCRYPT ; + +if (ext_props &BT_GATT_CHRC_EXT_PROP_ENC_WRITE ) + perm |=BT_ATT_PERM_WRITE_ENCRYPT ; + +if (ext_props &BT_GATT_CHRC_EXT_PROP_AUTH_READ ) + perm |=BT_ATT_PERM_READ_AUTHEN ; + +if (ext_props &BT_GATT_CHRC_EXT_PROP_AUTH_WRITE ) + perm |=BT_ATT_PERM_WRITE_AUTHEN ; +return perm; }
src/shared/att-types.h +22 -8
@@ -106,12 +106,18 @@ struct bt_att_pdu_error_rsp {* "Access", "Encryption", "Authentication", and "Authorization". A bitmask of * permissions is a byte that encodes a combination of these. */ -#define BT_ATT_PERM_READ 0x01 -#define BT_ATT_PERM_WRITE 0x02 -#define BT_ATT_PERM_ENCRYPT 0x04 -#define BT_ATT_PERM_AUTHEN 0x08 -#define BT_ATT_PERM_AUTHOR 0x10 -#define BT_ATT_PERM_NONE 0x20 +#define BT_ATT_PERM_READ 0x01 +#define BT_ATT_PERM_WRITE 0x02 +#define BT_ATT_PERM_READ_ENCRYPT 0x04 +#define BT_ATT_PERM_WRITE_ENCRYPT 0x08 +#define BT_ATT_PERM_ENCRYPT BT_ATT_PERM_READ_ENCRYPT | \ + BT_ATT_PERM_WRITE_ENCRYPT +#define BT_ATT_PERM_READ_AUTHEN 0x10 +#define BT_ATT_PERM_WRITE_AUTHEN 0x20 +#define BT_ATT_PERM_AUTHEN BT_ATT_PERM_READ_AUTHEN | \ + BT_ATT_PERM_WRITE_AUTHEN +#define BT_ATT_PERM_AUTHOR 0x40 +#define BT_ATT_PERM_NONE 0x80/* GATT Characteristic Properties Bitfield values */ #define BT_GATT_CHRC_PROP_BROADCAST 0x01
@@ -124,5 +130,13 @@ struct bt_att_pdu_error_rsp {#define BT_GATT_CHRC_PROP_EXT_PROP 0x80/* GATT Characteristic Extended Properties Bitfield values */ -#define BT_GATT_CHRC_EXT_PROP_RELIABLE_WRITE 0x01 -#define BT_GATT_CHRC_EXT_PROP_WRITABLE_AUX 0x02 +#define BT_GATT_CHRC_EXT_PROP_RELIABLE_WRITE 0x01 +#define BT_GATT_CHRC_EXT_PROP_WRITABLE_AUX 0x02 +#define BT_GATT_CHRC_EXT_PROP_ENC_READ 0x04 +#define BT_GATT_CHRC_EXT_PROP_ENC_WRITE 0x08 +#define BT_GATT_CHRC_EXT_PROP_ENC BT_GATT_CHRC_EXT_PROP_ENC_READ | \ + BT_GATT_CHRC_EXT_PROP_ENC_WRITE +#define BT_GATT_CHRC_EXT_PROP_AUTH_READ 0x10 +#define BT_GATT_CHRC_EXT_PROP_AUTH_WRITE 0x20 +#define BT_GATT_CHRC_EXT_PROP_AUTH BT_GATT_CHRC_EXT_PROP_AUTH_READ | \ + BT_GATT_CHRC_EXT_PROP_AUTH_WRITE
Signature · 1 line
2.1.0
Luiz Augusto von Dentz
maintainerPATCH 3/4 shared/att: Add own security definitions
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
This defines security level at ATT level so it is not necessary to use transport specific defines.
--- src/shared/att-types.h | 5 +++++ src/shared/att.c | 2 +- unit/test-gatt.c | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-)
src/shared/att-types.h +5 -0
@@ -27,6 +27,11 @@#define __packed __attribute__((packed))#endif +#define BT_ATT_SECURITY_NONE 0 +#define BT_ATT_SECURITY_LOW 1 +#define BT_ATT_SECURITY_MEDIUM 2 +#define BT_ATT_SECURITY_HIGH 3 +#define BT_ATT_DEFAULT_LE_MTU 23#define BT_ATT_MAX_LE_MTU 517#define BT_ATT_MAX_VALUE_LEN 512
src/shared/att.c +1 -1
@@ -1364,7 +1364,7 @@ bool bt_att_set_sec_level(struct bt_att *att, int level) {struct bt_security sec; -if (!att || level <BT_SECURITY_LOW || level >BT_SECURITY_HIGH ) +if (!att || level <BT_ATT_SECURITY_LOW || level >BT_ATT_SECURITY_HIGH )return false;if (!att->io_on_l2cap) {
unit/test-gatt.c +1 -1
@@ -1002,7 +1002,7 @@ static void test_signed_write_seclevel(struct context *context)g_assert (bt_att_set_local_key (context->att, key, local_counter, context)); -g_assert (bt_att_set_sec_level (context->att,BT_SECURITY_MEDIUM )); +g_assert (bt_att_set_sec_level (context->att,BT_ATT_SECURITY_MEDIUM )); g_assert(bt_gatt_client_write_without_response(context->client, step->handle,
Signature · 1 line
2.1.0
Luiz Augusto von Dentz
maintainerPATCH 4/4 shared/gatt-server: Check attribute permissions
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
--- src/shared/att-types.h | 16 ++++----- src/shared/gatt-server.c | 93 ++++++++++++++++++++++++++---------------------- 2 files changed, 58 insertions(+), 51 deletions(-)
src/shared/att-types.h +8 -8
@@ -115,12 +115,12 @@ struct bt_att_pdu_error_rsp {#define BT_ATT_PERM_WRITE 0x02#define BT_ATT_PERM_READ_ENCRYPT 0x04#define BT_ATT_PERM_WRITE_ENCRYPT 0x08 -#define BT_ATT_PERM_ENCRYPT BT_ATT_PERM_READ_ENCRYPT | \ - BT_ATT_PERM_WRITE_ENCRYPT +#define BT_ATT_PERM_ENCRYPT (BT_ATT_PERM_READ_ENCRYPT | \ + BT_ATT_PERM_WRITE_ENCRYPT)#define BT_ATT_PERM_READ_AUTHEN 0x10#define BT_ATT_PERM_WRITE_AUTHEN 0x20 -#define BT_ATT_PERM_AUTHEN BT_ATT_PERM_READ_AUTHEN | \ - BT_ATT_PERM_WRITE_AUTHEN +#define BT_ATT_PERM_AUTHEN (BT_ATT_PERM_READ_AUTHEN | \ + BT_ATT_PERM_WRITE_AUTHEN)#define BT_ATT_PERM_AUTHOR 0x40#define BT_ATT_PERM_NONE 0x80
@@ -139,9 +139,9 @@ struct bt_att_pdu_error_rsp {#define BT_GATT_CHRC_EXT_PROP_WRITABLE_AUX 0x02#define BT_GATT_CHRC_EXT_PROP_ENC_READ 0x04#define BT_GATT_CHRC_EXT_PROP_ENC_WRITE 0x08 -#define BT_GATT_CHRC_EXT_PROP_ENC BT_GATT_CHRC_EXT_PROP_ENC_READ | \ - BT_GATT_CHRC_EXT_PROP_ENC_WRITE +#define BT_GATT_CHRC_EXT_PROP_ENC (BT_GATT_CHRC_EXT_PROP_ENC_READ | \ + BT_GATT_CHRC_EXT_PROP_ENC_WRITE)#define BT_GATT_CHRC_EXT_PROP_AUTH_READ 0x10#define BT_GATT_CHRC_EXT_PROP_AUTH_WRITE 0x20 -#define BT_GATT_CHRC_EXT_PROP_AUTH BT_GATT_CHRC_EXT_PROP_AUTH_READ | \ - BT_GATT_CHRC_EXT_PROP_AUTH_WRITE +#define BT_GATT_CHRC_EXT_PROP_AUTH (BT_GATT_CHRC_EXT_PROP_AUTH_READ | \ + BT_GATT_CHRC_EXT_PROP_AUTH_WRITE)
src/shared/gatt-server.c +50 -43
164 lines not on this page · raw message
Signature · 1 line
2.1.0
Hi Luiz,
Quoted 14 lines · Luiz Augusto von Dentz
From: Luiz Augusto von Dentz <[email protected]>
This add encryption flags which can be used when registering a service to require encryption when accessing a characteristic.
--- doc/gatt-api.txt | 4 ++++ 1 file changed, 4 insertions(+)doc/gatt-api.txt +0
-0
doc/gatt-api.txt Properties string UUID [read-only] · line 154
Quoted 7 lines
doc/gatt-api.txt +4
-0@@ -148,6 +148,10 @@ Properties string UUID [read-only] "authenticated-signed-writes" "reliable-write" "writable-auxiliaries" + "encrypt-read" + "encrypt-write" + "encrypt-authenticated-read" + "encrypt-authenticated-write"
So I guess you decided not to go with a "Permissions" property? I guess that's fine but we need to handle this for descriptors as well. So probably add a "Flags" property to GattDescriptor1 also. There we'll want read, write, encrypt-*, and encrypt-authenticated-*.
Quoted 10 lines
doc/gatt-api.txt +0
-1array{object} Descriptors [read-only] --2.1.0
--
To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Can you also update test/example-gatt-server with new characteristics and descriptors that demonstrate the permissions feature? You can add them as new vendor-specific test characteristics (there's a vendor-specific test service in there) and/or modify one of the other two example services (HR and Battery). Let's get that into this patch set so we know we have some way to test it.
Thanks,
Arman
Luiz Augusto von Dentz
maintainerHi Arman,
Quoted 20 lines · Arman Uguray
Hi Luiz,
Quoted 18 lines · Luiz Augusto von Dentz
From: Luiz Augusto von Dentz <[email protected]>
This add encryption flags which can be used when registering a service to require encryption when accessing a characteristic.
--- doc/gatt-api.txt | 4 ++++ 1 file changed, 4 insertions(+)doc/gatt-api.txt +1
-0@@ -148,6 +148,10 @@ Properties string UUID [read-only] "authenticated-signed-writes" "reliable-write" "writable-auxiliaries" + "encrypt-read"
Quoted 8 lines
doc/gatt-api.txt Properties string UUID [read-only] · line 154
Quoted 3 lines
doc/gatt-api.txt +3
-0+ "encrypt-write" + "encrypt-authenticated-read" + "encrypt-authenticated-write"So I guess you decided not to go with a "Permissions" property? I guess that's fine but we need to handle this for descriptors as well. So probably add a "Flags" property to GattDescriptor1 also. There we'll want read, write, encrypt-*, and encrypt-authenticated-*.
Sure, will do that in the next set. What is more important now is getting feedback if the API is good enough, I have been debating in using secure instead of encrypt, what do you think?
Quoted 11 lines
Quoted 10 lines
doc/gatt-api.txt +0
-1array{object} Descriptors [read-only] --2.1.0
--
To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 6 lines
Can you also update test/example-gatt-server with new characteristics and descriptors that demonstrate the permissions feature? You can add them as new vendor-specific test characteristics (there's a vendor-specific test service in there) and/or modify one of the other two example services (HR and Battery). Let's get that into this patch set so we know we have some way to test it.
Yep, I was thinking about that just now, will add this in the next version.
Signature · 1 line
Luiz Augusto von Dentz
Hi Luiz,
Quoted 33 lines · Luiz Augusto von Dentz
Hi Arman,
Quoted 20 lines · Arman Uguray
Hi Luiz,
Quoted 18 lines · Luiz Augusto von Dentz
From: Luiz Augusto von Dentz <[email protected]>
This add encryption flags which can be used when registering a service to require encryption when accessing a characteristic.
--- doc/gatt-api.txt | 4 ++++ 1 file changed, 4 insertions(+)doc/gatt-api.txt +1
-0@@ -148,6 +148,10 @@ Properties string UUID [read-only] "authenticated-signed-writes" "reliable-write" "writable-auxiliaries" + "encrypt-read"Quoted 8 lines
doc/gatt-api.txt Properties string UUID [read-only] · line 154
Quoted 3 lines
doc/gatt-api.txt +3
-0+ "encrypt-write" + "encrypt-authenticated-read" + "encrypt-authenticated-write"So I guess you decided not to go with a "Permissions" property? I guess that's fine but we need to handle this for descriptors as well. So probably add a "Flags" property to GattDescriptor1 also. There we'll want read, write, encrypt-*, and encrypt-authenticated-*.
Quoted 4 lines
Sure, will do that in the next set. What is more important now is getting feedback if the API is good enough, I have been debating in using secure instead of encrypt, what do you think?
I'm fine with encrypt, I think staying closer to the GATT spec lingo will be less confusing for developers. "secure" is somewhat unclear whereas encrypt is very explicit and it has a matching ATT protocol error that a developer can immediately associate this permission with.
Looking through some of the other platform APIs, I see these:
iOS:
typedef enum {
CBAttributePermissionsReadable = 0x01,
CBAttributePermissionsWriteable = 0x02,
CBAttributePermissionsReadEncryptionRequired = 0x04,
CBAttributePermissionsWriteEncryptionRequired = 0x08,
} CBAttributePermissions;and Android has READ_ENCRYPTED, READ_ENCRYPTED_MITM, etc as you already know. So "encrypt" should sound familiar to developers.
Quoted 10 lines
Quoted 10 lines
Quoted 9 lines
doc/gatt-api.txt +0
-1array{object} Descriptors [read-only] --2.1.0
--
To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 9 lines
Quoted 6 lines
Can you also update test/example-gatt-server with new characteristics and descriptors that demonstrate the permissions feature? You can add them as new vendor-specific test characteristics (there's a vendor-specific test service in there) and/or modify one of the other two example services (HR and Battery). Let's get that into this patch set so we know we have some way to test it.
Yep, I was thinking about that just now, will add this in the next version.
Cool, thanks.
Quoted 3 lines
--
Luiz Augusto von Dentz
-Arman