<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Restricting some GATT characteristics to a bonded device</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/112036/restricting-some-gatt-characteristics-to-a-bonded-device</link><description>Hi, 
 I&amp;#39;m implementing a BLE GATT peripheral that has no display but it does have a button. 
 I&amp;#39;d like to make some characteristics only available to devices that are BONDED but all of the docs I&amp;#39;ve read so far talk about pairing, or what I think are</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 19 Jun 2024 08:19:16 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/112036/restricting-some-gatt-characteristics-to-a-bonded-device" /><item><title>RE: Restricting some GATT characteristics to a bonded device</title><link>https://devzone.nordicsemi.com/thread/489429?ContentTypeID=1</link><pubDate>Wed, 19 Jun 2024 08:19:16 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:64babc30-e2a1-49cb-a7e8-f59658651711</guid><dc:creator>BillB</dc:creator><description>&lt;p&gt;Hi Hieu,&lt;/p&gt;
&lt;p&gt;I really appreciate your time, thank you.&lt;/p&gt;
&lt;p&gt;Some of this isn&amp;#39;t adding up with experience I&amp;#39;ve had in other protos (I&amp;#39;m new to BLE, but have just enough experience with crypto to be skeptical/terrified of everything ;-) )&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Anyway I tried out &lt;span&gt;pairing_accept() and it seems to do roughly the right thing,&amp;nbsp;so I think I&amp;#39;m going hope this is all implemented correctly and close this ticket off for now.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Then later in the project&amp;nbsp;I&amp;#39;ll&amp;nbsp;&lt;/span&gt;decide if I care enough and if so do the deep dive,&amp;nbsp;if I find anything I can post again.&lt;/p&gt;
&lt;p&gt;Cheers!&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;P.S.&amp;nbsp;the things still scaring me are:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;In my mind there&amp;#39;s a huge difference between&amp;nbsp;a MITM attacker injecting themselves in possibly controlled conditions during the bond procedure (which I agree can&amp;#39;t be helped in JustWorks) vs the attacker following the victim around 24/7 to keep up the charade (which could be detected as soon as they screw up)&lt;br /&gt;So the question is &amp;quot;Would it be detected?&amp;quot; and I think the answer might turn out to be &amp;quot;only&amp;nbsp;if the stack enforces &lt;span&gt;Diffie-Hellman&lt;/span&gt; and does some additional checks&amp;quot;&lt;/li&gt;
&lt;li&gt;Right now I don&amp;#39;t think the attacker needs the IRK to connect - they can just try connecting to every device in range - but there could be&amp;nbsp;a detail in the proto I&amp;#39;m missing&lt;/li&gt;
&lt;li&gt;It&amp;#39;s hard to be sure that the stack is always going to call the API hooks in the right way no matter what tricks they&amp;#39;re pulling, need to read the code&lt;/li&gt;
&lt;/ul&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Restricting some GATT characteristics to a bonded device</title><link>https://devzone.nordicsemi.com/thread/489310?ContentTypeID=1</link><pubDate>Tue, 18 Jun 2024 12:43:21 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:fe2cc616-6a56-4f5a-bde1-00c766c97e30</guid><dc:creator>Hieu</dc:creator><description>&lt;p&gt;Hi Bill,&lt;/p&gt;
[quote user="BillB"]What&amp;#39;s harder to fake (especially in LE secure connections) is the actual encryption key in use, but&amp;nbsp;I haven&amp;#39;t read anything that says the stack is checking that key matches the one in the bond list and the links you&amp;#39;ve given don&amp;#39;t have a way for me to check that in my own app.[/quote]
&lt;p&gt;But if your device is advertising with&amp;nbsp;Resolvable Random Private Address, then only the bonded peer with the agreed Identity Resolving Key can identify it and initiate a connection.&lt;/p&gt;
[quote user="BillB"]I.e. I can&amp;#39;t see anything that would prevent an attacker (that wasn&amp;#39;t present at the initial bonding) from just spoofing the MAC and then negotiating a new key for the session.[/quote]
&lt;p&gt;Using Just Works, there is also nothing stopping a MITM from getting the agreed key. They don&amp;#39;t even have to fake being the device and getting a new key.&lt;/p&gt;
&lt;p&gt;At the end of the day,&amp;nbsp;vulnerability to MITM is an inherent issue when you use Just Works pairing. There is simply no way around it. Some secrets must be agreed on a different physical channel to defend against the MITM.&lt;/p&gt;
&lt;p&gt;I discussed some alternatives in a recent ticket:&amp;nbsp;&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/111964/using-just-works-mode-with-mitm-protection"&gt;Using Just Works mode with MITM protection&lt;/a&gt;.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Restricting some GATT characteristics to a bonded device</title><link>https://devzone.nordicsemi.com/thread/488974?ContentTypeID=1</link><pubDate>Mon, 17 Jun 2024 03:50:51 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8c4eda34-cea1-46f6-a56d-b1e1b26adb7a</guid><dc:creator>BillB</dc:creator><description>&lt;p&gt;Hi Hieu,&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&lt;span&gt;E.g. I&amp;#39;ve been experimenting with&amp;nbsp;&lt;/span&gt;&lt;span&gt;struct&lt;/span&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;span&gt;bt_conn_auth_cb but not sure which is the best&lt;/span&gt;&lt;br /&gt;I&lt;span&gt;t actually seems like the best option to me.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Just that there&amp;#39;s a lot of callbacks in the structs and which ones are set seems to determine the IO capabilities and therefore the auth procedure and I find the wording in the doc a but vague on the implications.&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;I think maybe&amp;nbsp;pairing_accept() is the right one, but&amp;nbsp;pairing_confirm() seems interesting too?&lt;br /&gt;And then there&amp;#39;s the&amp;nbsp;&lt;/span&gt;BT_CONN_CB_DEFINE() ones, if I can rely on only one device being connected at a time.&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Anyway I&amp;#39;ll do some more experiments in the next couple of days and get back to you.&lt;/span&gt;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&lt;span&gt;but&amp;nbsp;does it have any other IO capabilities for an Out-of-Band method&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Nothing obvious that I can see, e.g. there&amp;#39;s no NFC or other way to talk to a phone except something crazy like pointing the phone camera at a LED. But I&amp;#39;ll have a think.&lt;/span&gt;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&lt;span&gt;You can check if the current&amp;nbsp;peer address is in the list of bonded devices.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;But that&amp;#39;s the key question that&amp;#39;s driving this - the doc is only talking about addresses, which can be faked easily.&lt;br /&gt;&lt;/span&gt;&lt;span&gt;What&amp;#39;s harder to fake (especially in LE secure connections) is the actual encryption key in use, but&amp;nbsp;I haven&amp;#39;t read anything that says the stack is checking that key matches the one in the bond list and the links you&amp;#39;ve given don&amp;#39;t have a way for me to check that in my own app.&lt;br /&gt;I.e. I can&amp;#39;t see anything that would prevent an attacker (that wasn&amp;#39;t present at the initial bonding) from just spoofing the MAC and then negotiating a new key for the session.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;The only thing I can think of is that key negotiation is probably considered a &amp;quot;pair&amp;quot; and might still trigger one or more of the&amp;nbsp;bt_conn_auth_cb calls even in JustWorks, and it those calls are _not_ triggered when a bonded device reuses the bond key (i.e. if a previously bonded device coming back in range is not a &amp;quot;pair&amp;quot;) then we might be OK. But the doc isn&amp;#39;t explicit on this so I&amp;#39;ll still be nervous about it even if my experiments look good.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;I might end up having to read the full BLE spec, stack source, and maybe pentesting it, but it just feels like what I&amp;#39;m trying to do here must have been done before and that if it was actually a problem there&amp;#39;d be papers written on it already. I mean the UI is basically the BLE equivalent of one of the Bluetooth Classic dongles or hands-free and those _do_ have issues but I thought BLE was supposed to have fixed them?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Restricting some GATT characteristics to a bonded device</title><link>https://devzone.nordicsemi.com/thread/488753?ContentTypeID=1</link><pubDate>Thu, 13 Jun 2024 21:14:28 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:06e275e7-9fcd-48aa-b0a9-203547f2fd72</guid><dc:creator>Hieu</dc:creator><description>&lt;p&gt;Hi Bill,&lt;/p&gt;
[quote user="BillB"]&lt;span&gt;Well I thought that would also prevent a previously bonded device from reconnecting, e.g. if it was out of range and comes back?&lt;/span&gt;&lt;span&gt;&lt;br /&gt;This is why I was looking at whitelisting, but best I can tell that&amp;#39;s only looking at the MAC, which is spoofable (IRK doesn&amp;#39;t prevent that).&lt;/span&gt;[/quote]
&lt;p&gt;Right, if you want the bonded peer to&amp;nbsp;always be able to reconnect, it&amp;#39;s best to have white-list advertising after the &amp;quot;pairable&amp;quot; window.&lt;/p&gt;
[quote user="BillB"]I can tell that&amp;#39;s only looking at the MAC, which is spoofable (IRK doesn&amp;#39;t prevent that).[/quote]
&lt;p&gt;Yes, this is true but only with Just Works pairing.&amp;nbsp;You mentioned the device not having a display, but&amp;nbsp;does it have any other IO capabilities for an Out-of-Band method? Refer to Bluetooth spec, Vol 3, Part H, Section 2.3.5.1, Selecting key generation method:&lt;/p&gt;
&lt;p&gt;&lt;img style="max-height:240px;max-width:320px;" alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/Screenshot-2024_2D00_06_2D00_13-225309.png" /&gt;&lt;/p&gt;
[quote user="BillB"]&lt;span&gt;Definitely open to trying ideas like this though - what is the usual way to block all pairing?&lt;br /&gt;E.g. I&amp;#39;ve been experimenting with&amp;nbsp;&lt;/span&gt;&lt;span&gt;struct&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;bt_conn_auth_cb but not sure which is the best option.&lt;/span&gt;[/quote]
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;It actually seems like the best option to me.&amp;nbsp;Do you find&amp;nbsp;something unfitting about it?&lt;/p&gt;
[quote user="BillB"]Yeah, I wondered if there might be a way to check the connection state (is it bonded) during the callback, I&amp;#39;ll look into it some more.[/quote]
&lt;p&gt;There is. You can check if the current&amp;nbsp;peer address is in the list of bonded devices.&lt;/p&gt;
&lt;p&gt;See:&lt;/p&gt;
&lt;p&gt;&lt;a href="https://docs.nordicsemi.com/bundle/ncs-2.6.1/page/zephyr/connectivity/bluetooth/api/connection_mgmt.html#c.bt_conn_get_dst"&gt;https://docs.nordicsemi.com/bundle/ncs-2.6.1/page/zephyr/connectivity/bluetooth/api/connection_mgmt.html#c.bt_conn_get_dst&lt;br /&gt;&lt;/a&gt;&lt;a href="https://docs.nordicsemi.com/bundle/ncs-2.6.1/page/zephyr/connectivity/bluetooth/api/gap.html#c.bt_foreach_bond"&gt;https://docs.nordicsemi.com/bundle/ncs-2.6.1/page/zephyr/connectivity/bluetooth/api/gap.html#c.bt_foreach_bond&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Restricting some GATT characteristics to a bonded device</title><link>https://devzone.nordicsemi.com/thread/488579?ContentTypeID=1</link><pubDate>Thu, 13 Jun 2024 00:01:18 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3b2b8c37-1597-4309-8d69-d0dc4518bbfd</guid><dc:creator>BillB</dc:creator><description>&lt;p&gt;Hi Hieu,&lt;/p&gt;
&lt;p&gt;Thanks for the response. Yes I did wonder if I was overthinking this, seems like something that should be solved already.&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&lt;span&gt;I am a little confused why you don&amp;#39;t limit&amp;nbsp;connection establishment and pairing entirely, but just bonding.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Well I thought that would also prevent a previously bonded device from reconnecting, e.g. if it was out of range and comes back?&lt;/span&gt;&lt;span&gt;&lt;br /&gt;This is why I was looking at whitelisting, but best I can tell that&amp;#39;s only looking at the MAC, which is spoofable (IRK doesn&amp;#39;t prevent that).&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Definitely open to trying ideas like this though - what is the usual way to block all pairing?&lt;br /&gt;E.g. I&amp;#39;ve been experimenting with&amp;nbsp;&lt;/span&gt;&lt;span&gt;struct&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;bt_conn_auth_cb but not sure which is the best option.&lt;/span&gt;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&lt;span&gt;Can you not also setup the device to ask for user&amp;#39;s explicit permission before accepting a pairing request?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Well there&amp;#39;s no display or other output that seems usable to inform the user that there&amp;#39;s a pairing request.&amp;nbsp;&lt;br /&gt;So ideally I&amp;#39;d like to let the bonded device back in without user interaction.&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&lt;span&gt;try using the read and write callbacks&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Yeah, I wondered if there might be a way to check the connection state (is it bonded) during the callback, I&amp;#39;ll look into it some more.&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Restricting some GATT characteristics to a bonded device</title><link>https://devzone.nordicsemi.com/thread/488569?ContentTypeID=1</link><pubDate>Wed, 12 Jun 2024 21:29:37 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8df516aa-65b7-4859-ae27-a08edff04d50</guid><dc:creator>Hieu</dc:creator><description>&lt;p&gt;Hi Bill,&lt;/p&gt;
[quote user=""]&lt;p&gt;So really I only care whether whether I&amp;#39;m currently connected to the phone&amp;nbsp;(or potentially MITM) the nRF was bonded to. Plan is to use JustWorks but only allow a bonding to occur for a short period after the button was pressed.&lt;/p&gt;
&lt;p&gt;But let&amp;#39;s say I&amp;#39;ve already been through the bonding process with some phone but that phone&amp;#39;s now out of range and disconnected. If another device comes along I believe it could initiate a pair and create a link with encryption (but not authentication) but stop before bonding without the user even knowing it happened.&lt;/p&gt;[/quote]
&lt;p&gt;I am a little confused why you don&amp;#39;t limit&amp;nbsp;connection establishment and pairing entirely, but just bonding.&lt;/p&gt;
&lt;p&gt;Also,&amp;nbsp;can you not also setup the device to ask for user&amp;#39;s explicit permission before accepting a pairing request?&lt;/p&gt;
&lt;p&gt;A GATT characteristic&amp;nbsp;permission can only limit read/write access on the basis of whether pairing has happened or not, and what level of security such pairing achieves. It doesn&amp;#39;t care if the paired peer is also bonded.&lt;/p&gt;
&lt;p&gt;If your device really needs to allow that scenario where a rogue&amp;nbsp;device can pair with it, then perhaps you can see if you can reject an attempt to read/write an attribute based on whether the device is in the&amp;nbsp;list of bonded device or not.&lt;/p&gt;
&lt;p&gt;I haven&amp;#39;t checked to be sure, but you can try using the read and write callbacks field when declaring your Characteristic with&amp;nbsp;&lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/2.6.1/zephyr/connectivity/bluetooth/api/gatt.html#c.BT_GATT_CHARACTERISTIC"&gt;BT_GATT_CHARACTERISTIC&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Refer to LBS implementation:&amp;nbsp;&lt;a href="https://github.com/nrfconnect/sdk-nrf/blob/v2.6.1/subsys/bluetooth/services/lbs.c"&gt;https://github.com/nrfconnect/sdk-nrf/blob/v2.6.1/subsys/bluetooth/services/lbs.c&lt;/a&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Hieu&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>