<?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>Add security to service Characteristic</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/21605/add-security-to-service-characteristic</link><description>In the BLE Characteristics, a beginner&amp;#39;s tutorial 
 Martin mentions:
Since this is a beginners tutorial we will keep it simple and leave the doors wide open. No security, encryption, or passkey needed. 
 Is there an example to add security?
I have</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 28 Apr 2017 14:50:10 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/21605/add-security-to-service-characteristic" /><item><title>RE: Add security to service Characteristic</title><link>https://devzone.nordicsemi.com/thread/84820?ContentTypeID=1</link><pubDate>Fri, 28 Apr 2017 14:50:10 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:34b55ab2-31a6-49e5-8f26-167f8d084b2d</guid><dc:creator>Renix</dc:creator><description>&lt;p&gt;Bjørn,&lt;/p&gt;
&lt;p&gt;Yes, that is what I found too.&lt;/p&gt;
&lt;p&gt;Page 537 of BLE4.2 states that Attribute Permissions
Readable with no authentication
or authorization.
Writable with authentication
and authorization defined by a
higher layer specification or is
implementation specific.&lt;/p&gt;
&lt;p&gt;Thanks&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Add security to service Characteristic</title><link>https://devzone.nordicsemi.com/thread/84819?ContentTypeID=1</link><pubDate>Fri, 28 Apr 2017 12:54:48 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cbea9bcb-9c90-49af-8525-4420df533aaa</guid><dc:creator>bjorn-spockeli</dc:creator><description>&lt;p&gt;**Q1:**Yes, you should be able configure the CCCD so that you must have an encrypted link, i.e. be paired or bonded in order to write to the CCCD to enable notifications.&lt;/p&gt;
&lt;p&gt;**Q2:**I did some testing with the ble_app_hrs example and I found that if I set the CCCD read permission to open and the write permissions to encrypted with no MITM protection, i.e.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;BLE_GAP_CONN_SEC_MODE_SET_OPEN(&amp;amp;cccd_md.read_perm);
BLE_GAP_CONN_SEC_MODE_SET_ENC_NO_MITM(&amp;amp;cccd_md.write_perm);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;then it should work fine. So it looks like you cannot set the security level of the read permission of a CCCD, which I assume it stted in the BLE spec.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Add security to service Characteristic</title><link>https://devzone.nordicsemi.com/thread/84818?ContentTypeID=1</link><pubDate>Wed, 26 Apr 2017 20:50:53 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:69c4db35-df3d-4d9d-be25-cb2aee79db29</guid><dc:creator>Renix</dc:creator><description>&lt;p&gt;Bjørn
I believe I actually have the security working for the read / write property of the Characteristic, but still have trouble with the Notification side.
Perhaps I do not understand it, or something else is wrong.&lt;/p&gt;
&lt;p&gt;Note: I added read/write properties back to the characteristics.&lt;/p&gt;
&lt;p&gt;I set the security level for the read / write:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;BLE_GAP_CONN_SEC_MODE_SET_ENC_NO_MITM(&amp;amp;attr_md.read_perm);
BLE_GAP_CONN_SEC_MODE_SET_ENC_NO_MITM(&amp;amp;attr_md.write_perm);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Test:
I cannot read or write to the Characteristic using iPhone.
In MCP [10:23:42.3] Received Error Response: INSUFFICIENT_AUTHENTICATION, handle: 0x0020&lt;/p&gt;
&lt;p&gt;Once the iPhone is paired, I can read and write to the Characteristic.
In MCP, If I hit Bond, I can also read / write. All seems GOOD then.&lt;/p&gt;
&lt;p&gt;What was confusing is if I tell iPhone to Forget the device, it does not ask to pair again.
MCP still works as expected, just need to hit Delete bond info&lt;/p&gt;
&lt;p&gt;Question 1)&lt;/p&gt;
&lt;p&gt;Can the Notify property also have this security setting?&lt;/p&gt;
&lt;ol start="2"&gt;
&lt;li&gt;
&lt;p&gt;This is how the Notify security is set? (I have it commented out for now)&lt;/p&gt;
&lt;p&gt;ble_gatts_attr_md_t cccd_md;
memset(&amp;amp;cccd_md, 0, sizeof(cccd_md));
//GvR
//BLE_GAP_CONN_SEC_MODE_SET_ENC_NO_MITM(&amp;amp;cccd_md.read_perm);
//BLE_GAP_CONN_SEC_MODE_SET_ENC_NO_MITM(&amp;amp;cccd_md.write_perm);&lt;/p&gt;
&lt;p&gt;BLE_GAP_CONN_SEC_MODE_SET_OPEN(&amp;amp;cccd_md.read_perm);
BLE_GAP_CONN_SEC_MODE_SET_OPEN(&amp;amp;cccd_md.write_perm);
cccd_md.vloc                = BLE_GATTS_VLOC_STACK;&lt;br /&gt;
char_md.p_cccd_md           = &amp;amp;cccd_md;
char_md.char_props.notify   = 1;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;As soon as I change to ENC_NO_MITM I get the ERROR Fatal output from the UART, and advertising stops.&lt;/p&gt;
&lt;p&gt;Any help appreciated.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Add security to service Characteristic</title><link>https://devzone.nordicsemi.com/thread/84817?ContentTypeID=1</link><pubDate>Wed, 26 Apr 2017 09:39:10 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3a1df1e4-2e18-4c1c-9fd2-68a63e105505</guid><dc:creator>bjorn-spockeli</dc:creator><description>&lt;p&gt;Could you post your IROM and IRAM settings for the application in Keil?&lt;/p&gt;
&lt;p&gt;No, if the characteristic does not have the read or write properties then setting &lt;code&gt;BLE_GAP_CONN_SEC_MODE_SET_ENC_NO_MITM()&lt;/code&gt; will not have any effect as this will never be enforced since there is nothing to write to or read from.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Add security to service Characteristic</title><link>https://devzone.nordicsemi.com/thread/84816?ContentTypeID=1</link><pubDate>Tue, 25 Apr 2017 14:51:08 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d554ecb3-fb82-47c1-8dc7-96572200082d</guid><dc:creator>Renix</dc:creator><description>&lt;p&gt;Bjørn&lt;/p&gt;
&lt;p&gt;code execution does not reach app_error_handler.&lt;/p&gt;
&lt;p&gt;With both     char_md.char_props.read = 1; and  char_md.char_props.write = 1;&lt;/p&gt;
&lt;p&gt;// OUR_JOB: Step 3.A, Configuring Client Characteristic Configuration Descriptor metadata and add to char_md structure
ble_gatts_attr_md_t cccd_md;
memset(&amp;amp;cccd_md, 0, sizeof(cccd_md));
//GvR
BLE_GAP_CONN_SEC_MODE_SET_ENC_NO_MITM(&amp;amp;cccd_md.read_perm);
BLE_GAP_CONN_SEC_MODE_SET_ENC_NO_MITM(&amp;amp;cccd_md.write_perm);&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;//BLE_GAP_CONN_SEC_MODE_SET_OPEN(&amp;amp;cccd_md.read_perm);
//BLE_GAP_CONN_SEC_MODE_SET_OPEN(&amp;amp;cccd_md.write_perm);
cccd_md.vloc                = BLE_GATTS_VLOC_STACK;    
char_md.p_cccd_md           = &amp;amp;cccd_md;
char_md.char_props.notify   = 1;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I see the following on the UART output:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;:ERROR:Fatal
SDH:WARNING:RAM start should be adjusted to 0x20001ff0.
SDH:WARNING:RAM size should be adjusted to 0xe010.
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;In IAR I have&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;define symbol __ICFEDIT_intvec_start__ = 0x1f000;
/*-Memory Regions-*/
define symbol __ICFEDIT_region_ROM_start__ = 0x1f000;
define symbol __ICFEDIT_region_ROM_end__   = 0x7ffff;
define symbol __ICFEDIT_region_RAM_start__ = 0x20002fff;
define symbol __ICFEDIT_region_RAM_end__   = 0x2000ffff;
export symbol __ICFEDIT_region_RAM_start__;
export symbol __ICFEDIT_region_RAM_end__;
/*-Sizes-*/
define symbol __ICFEDIT_size_cstack__ = 0x800;
define symbol __ICFEDIT_size_heap__   = 0x200;
/**** End of ICF editor section. ###ICF###*/
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I guess there is no point in trying to use BLE_GAP_CONN_SEC_MODE_SET_ENC_NO_MITM() if I am not using     //char_md.char_props.read = 1; or    //char_md.char_props.write = 1;&lt;/p&gt;
&lt;p&gt;Since it is the CCCD Notify property being displayed, I assume the MITH bonding is only for the read and write.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Add security to service Characteristic</title><link>https://devzone.nordicsemi.com/thread/84815?ContentTypeID=1</link><pubDate>Tue, 25 Apr 2017 11:40:27 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ecfbee8a-315f-4028-bb6c-17e103eb15be</guid><dc:creator>bjorn-spockeli</dc:creator><description>&lt;p&gt;Can you debug the application and see if you end up in the &lt;code&gt;app_error_handler&lt;/code&gt;? If so, take a look at the call stack and see which function that caused the error and which error code it returned.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>