<?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>pc-ble-driver-py - BLEGapSecStatus.dhkey_failure</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/57036/pc-ble-driver-py---blegapsecstatus-dhkey_failure</link><description>Hi, 
 I&amp;#39;m using an NRF51 Dongle as a central to connect to a BLE peripheral using LE Secure passkey pairing. I&amp;#39;ve got to scanning / connecting successfully, I&amp;#39;m just stuck on the pairing. 
 It gets to the point where it sends the SMP Pairing Public Key</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 04 Feb 2020 17:58:00 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/57036/pc-ble-driver-py---blegapsecstatus-dhkey_failure" /><item><title>RE: pc-ble-driver-py - BLEGapSecStatus.dhkey_failure</title><link>https://devzone.nordicsemi.com/thread/232668?ContentTypeID=1</link><pubDate>Tue, 04 Feb 2020 17:58:00 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9f9fe22f-4fb3-4e08-a1af-753f2d634100</guid><dc:creator>tesc</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I am happy to see that you got there in the end. Thanks for sharing your solution, it is highly appreciated!&lt;/p&gt;
&lt;p&gt;Regards,&lt;br /&gt;Terje&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: pc-ble-driver-py - BLEGapSecStatus.dhkey_failure</title><link>https://devzone.nordicsemi.com/thread/232298?ContentTypeID=1</link><pubDate>Mon, 03 Feb 2020 12:06:45 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:dd5dab61-ee66-4855-beaf-d50e37624e20</guid><dc:creator>frostp</dc:creator><description>&lt;p&gt;Hi again,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I did manage to get it all implemented in the end. It looks like the python bindings for the pc-ble-driver just&amp;nbsp;doesn&amp;#39;t have support for LE Secure pairing, or atleast it&amp;#39;s only half implemented? There isn&amp;#39;t any callback implemented for the&amp;nbsp;&lt;span&gt;BLE_GAP_EVT_LESC_DHKEY_REQUEST&amp;nbsp;for example. &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Fortunately&lt;/span&gt; the guy who answered&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/57036/pc-ble-driver-py---blegapsecstatus-dhkey_failure"&gt;https://devzone.nordicsemi.com/f/nordic-q-a/57036/pc-ble-driver-py---blegapsecstatus-dhkey_failure&lt;/a&gt;&amp;nbsp;had implemented pretty much all of it, apart from his was in python 2 and I&amp;#39;m using python 3 so I had to make some changes there. Also he uses&amp;nbsp;&lt;span&gt;pyelliptic which has been deprecated for some time, so that&amp;#39;s not great but it&amp;#39;s sort of ok just for the testing I&amp;#39;m doing.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;So in the end the authentication function looks like:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="python"&gt;        kdist_own   = BLEGapSecKDist(enc  = 1,
                                     id   = 1,
                                     sign = 0,
                                     link = 0)
                                     
        kdist_peer  = BLEGapSecKDist(enc  = 1,
                                     id   = 1,
                                     sign = 0,
                                     link = 0)
        
        sec_params  = BLEGapSecParams(bond          = True,
                                      mitm          = True,
                                      lesc          = True,
                                      oob           = False,
                                      keypress      = False,
                                      io_caps       = BLEGapIOCaps.keyboard_display,
                                      min_key_size  = 7,
                                      max_key_size  = 16,
                                      kdist_own     = kdist_own,
                                      kdist_peer    = kdist_peer)
        
        self.adapter.driver.ble_gap_authenticate(self.conn_handle, sec_params)
        
        # Wait for gap_evt_sec_params_request
        self.adapter.evt_sync[self.conn_handle].wait(BLEEvtID.gap_evt_sec_params_request)

        pub_key = BLEGapLESCp256pk(pk = self.adapter.driver.ecc_create_keys())
        self.adapter.driver.ble_gap_sec_params_reply(self.conn_handle,
                                                     BLEGapSecStatus.success,
                                                     sec_params = None,
                                                     own_keys = pub_key)

        # Wait for gap_evt_lesc_dhkey_request
        result = self.adapter.evt_sync[self.conn_handle].wait(BLEEvtID.gap_evt_lesc_dhkey_request)

        dhkey = BLEGapLESCdhkey(key = self.adapter.driver.ecc_get_dhkey(result[&amp;#39;p_pk_peer&amp;#39;].pk))
        self.adapter.driver.ble_gap_lesc_dhkey_reply(self.conn_handle, dhkey)

        # Wait for gap_evt_auth_status
        result = self.adapter.evt_sync[self.conn_handle].wait(BLEEvtID.gap_evt_auth_status)

        if result[&amp;#39;auth_status&amp;#39;] ==  BLEGapSecStatus.success:
            self.keyset = adapter.db_conns[self.conn_handle]._keyset
            return True&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;But you have to make some changes in the ble_driver.py and the ble_adapter.py to get to that point.&lt;/p&gt;
&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/4503.ble_5F00_adapter.patch"&gt;devzone.nordicsemi.com/.../4503.ble_5F00_adapter.patch&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/3513.ble_5F00_driver.patch"&gt;devzone.nordicsemi.com/.../3513.ble_5F00_driver.patch&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Thanks,&lt;/p&gt;
&lt;p&gt;Peter&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: pc-ble-driver-py - BLEGapSecStatus.dhkey_failure</title><link>https://devzone.nordicsemi.com/thread/231739?ContentTypeID=1</link><pubDate>Wed, 29 Jan 2020 16:01:34 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:31aaf166-d56a-41e4-9493-dc33877004ba</guid><dc:creator>tesc</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;There are multiple keys involved here, so one can easily get confused. As the logged error message include &amp;quot;BLEGapSecStatus.dhkey_failure&amp;quot;, dhkey related issues is the prime suspect. Computation of the dhkey is the responsibility of the application, so you must perform the computation that in the SDK is performed by nrf_crypto_shared_secret_compute(). I am looking forward to hear how it went.&lt;/p&gt;
&lt;p&gt;Regards,&lt;br /&gt;Terje&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: pc-ble-driver-py - BLEGapSecStatus.dhkey_failure</title><link>https://devzone.nordicsemi.com/thread/231475?ContentTypeID=1</link><pubDate>Tue, 28 Jan 2020 15:47:54 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2c7c0a52-854b-4a3a-b730-5b3258d2ac32</guid><dc:creator>frostp</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Thanks for the reply, I did wonder if the&amp;nbsp;BLE_GAP_EVT_LESC_DHKEY_REQUEST was the issue but that sequence diagram shows it coming after the SMP Pairing Public Key is sent so I assumed it couldn&amp;#39;t be the problem. I&amp;#39;ll put in an implementation for the DHKEY_REQUEST and let you know how it&amp;nbsp;goes.&lt;/p&gt;
&lt;p&gt;Many thanks,&lt;/p&gt;
&lt;p&gt;Peter&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: pc-ble-driver-py - BLEGapSecStatus.dhkey_failure</title><link>https://devzone.nordicsemi.com/thread/231437?ContentTypeID=1</link><pubDate>Tue, 28 Jan 2020 14:19:26 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c8e4d519-56c5-421c-b47c-ced086e3c986</guid><dc:creator>tesc</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Your implementation sets the lesc flag in sec_params, but you seem to still follow &lt;a href="https://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.s130.api.v2.0.1%2Fgroup___b_l_e___g_a_p___c_e_n_t_r_a_l___b_o_n_d_i_n_g___p_k___p_e_r_i_p_h___m_s_c.html"&gt;legacy pairing&lt;/a&gt; and not &lt;a href="https://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.s130.api.v2.0.1%2Fgroup___b_l_e___g_a_p___c_e_n_t_r_a_l___l_e_s_c___b_o_n_d_i_n_g___p_k_e___p_d___m_s_c.html"&gt;LE Secure Connections&lt;/a&gt; pairing for the pairing procedure. Note as part of &amp;quot;LESC Authentication Stage 1&amp;quot; you must answer to the event BLE_GAP_EVT_LESC_DHKEY_REQUEST with a call to sd_ble_gap_lesc_dhkey_reply(). As reference, here is the implementation used in nRF5 SDK v12.3, for the &lt;a href="https://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.sdk5.v12.3.0%2Fble_sdk_app_multirole_lesc.html"&gt;ble_app_multirole_lesc&lt;/a&gt; example (main.c, lines 677 through 685):&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt; 677         case BLE_GAP_EVT_LESC_DHKEY_REQUEST:
 678             NRF_LOG_INFO(&amp;quot;%s: BLE_GAP_EVT_LESC_DHKEY_REQUEST\r\n&amp;quot;, nrf_log_push(roles_str[role]));
 679             peer_pk.p_le_data = &amp;amp;p_ble_evt-&amp;gt;evt.gap_evt.params.lesc_dhkey_request.p_pk_peer-&amp;gt;pk[0];
 680             peer_pk.len = BLE_GAP_LESC_P256_PK_LEN;
 681             err_code = nrf_crypto_shared_secret_compute(NRF_CRYPTO_CURVE_SECP256R1, &amp;amp;m_crypto_key_sk, &amp;amp;peer_pk, &amp;amp;m_crypto_key_dhkey);
 682             APP_ERROR_CHECK(err_code);
 683             err_code = sd_ble_gap_lesc_dhkey_reply(conn_handle, &amp;amp;m_lesc_dhkey);
 684             APP_ERROR_CHECK(err_code);
 685             break;&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Regards,&lt;br /&gt;Terje&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>