Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

LESC_DEBUG_MODE define in ble_app_multirole_lesc, nRF5 SDK 15.0.0

Device: nRF52832

SDK: nRF5 SDK 15.0.0

SoftDevice 6.0.0

Hello. I'm using using the ble_app_multirole_lesc example with nRF5 SDK 15.0.0. I'm trying to debug using my sniffer, and want to use the debug private key. The following define exists in the main.c code which seems like it should set the private key to the debug key:

#define LESC_DEBUG_MODE 1 /**< Set to 1 to use LESC debug keys, allows you to use a sniffer to inspect traffic. */

The problem, though, is that this define doesn't appear to do anything. The LESC_DEBUG_MODE symbol is not used anywhere else in the code. I went back to the 14.2.0 SDK and found some code in the sample application that made use of the LESC_DEBUG_MODE flag:

#if LESC_DEBUG_MODE

/**@brief Bluetooth SIG debug mode Private Key */
#error Generated private key is not supported.
__ALIGN(4) static const ble_gap_lesc_p256_sk_t m_lesc_private_key =
{{
0xbd,0x1a,0x3c,0xcd,0xa6,0xb8,0x99,0x58,0x99,0xb7,0x40,0xeb,0x7b,0x60,0xff,0x4a,
0x50,0x3f,0x10,0xd2,0xe3,0xb3,0xc9,0x74,0x38,0x5f,0xc5,0xa3,0xd4,0xf6,0x49,0x3f
}};

#else

#endif

Unfortunately, even with the above code I don't quite understand how the debug key works because the m_lesc_private_key structure is not actually used anywhere. I would think that 

In any case, what I really need is to use the private key with SDK 15.0.0, not 14.2.0. From my understanding of the code I would have though that the code related to the debug private key would need to be in ble_lesc.c rather than in the application code (since the key generation and management are handled by that module rather than the application).

Could you please provide guidance for using the debug key?

Thanks.

Parents
  • One way to accomplish this in SDK16/17 is to return the debug key instead of generating a random one. In the case of the Oberon backend that can be done in oberon_backend_ecc.c:

    ret_code_t nrf_crypto_backend_oberon_ecc_secp256r1_rng(uint8_t data[32])
    
    {
    
    #if NRF_MODULE_ENABLED(NRF_CRYPTO_RNG)
    
    #ifdef DEBUG
    
    static const uint8_t LESC_DEBUG_KEY[32] =
    
    {
    
          0x3f, 0x49, 0xf6, 0xd4, 0xa3, 0xc5, 0x5f, 0x38, 0x74, 0xc9, 0xb3, 0xe3, 0xd2, 0x10, 0x3f, 0x50,
    
          0x4a, 0xff, 0x60, 0x7b, 0xeb, 0x40, 0xb7, 0x99, 0x58, 0x99, 0xb8, 0xa6, 0xcd, 0x3c, 0x1a, 0xbd
    
    };
    
     
    
        for (int i=0; i < sizeof(LESC_DEBUG_KEY); i++)
    
        {
    
          data[i] = LESC_DEBUG_KEY[i];
    
        }
    
     
    
        return NRF_SUCCESS;
    
    #else
    
        static const uint8_t min_value[32] =
    
        {
    
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
    
        };
    
        static const uint8_t max_value[32] =
    
        {
    
            0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
    
            0xBC, 0xE6, 0xFA, 0xAD, 0xA7, 0x17, 0x9E, 0x84, 0xF3, 0xB9, 0xCA, 0xC2, 0xFC, 0x63, 0x25, 0x50,
    
        };
    
     
    
        return nrf_crypto_rng_vector_generate_in_range(data, min_value, max_value, 32);
    
    #endif
    
    #else
    
        return NRF_ERROR_CRYPTO_FEATURE_UNAVAILABLE;
    
    #endif
    
    }

    Note that the byte order is reversed compared to m_lesc_private_key in the original question above.

Reply
  • One way to accomplish this in SDK16/17 is to return the debug key instead of generating a random one. In the case of the Oberon backend that can be done in oberon_backend_ecc.c:

    ret_code_t nrf_crypto_backend_oberon_ecc_secp256r1_rng(uint8_t data[32])
    
    {
    
    #if NRF_MODULE_ENABLED(NRF_CRYPTO_RNG)
    
    #ifdef DEBUG
    
    static const uint8_t LESC_DEBUG_KEY[32] =
    
    {
    
          0x3f, 0x49, 0xf6, 0xd4, 0xa3, 0xc5, 0x5f, 0x38, 0x74, 0xc9, 0xb3, 0xe3, 0xd2, 0x10, 0x3f, 0x50,
    
          0x4a, 0xff, 0x60, 0x7b, 0xeb, 0x40, 0xb7, 0x99, 0x58, 0x99, 0xb8, 0xa6, 0xcd, 0x3c, 0x1a, 0xbd
    
    };
    
     
    
        for (int i=0; i < sizeof(LESC_DEBUG_KEY); i++)
    
        {
    
          data[i] = LESC_DEBUG_KEY[i];
    
        }
    
     
    
        return NRF_SUCCESS;
    
    #else
    
        static const uint8_t min_value[32] =
    
        {
    
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
    
        };
    
        static const uint8_t max_value[32] =
    
        {
    
            0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
    
            0xBC, 0xE6, 0xFA, 0xAD, 0xA7, 0x17, 0x9E, 0x84, 0xF3, 0xB9, 0xCA, 0xC2, 0xFC, 0x63, 0x25, 0x50,
    
        };
    
     
    
        return nrf_crypto_rng_vector_generate_in_range(data, min_value, max_value, 32);
    
    #endif
    
    #else
    
        return NRF_ERROR_CRYPTO_FEATURE_UNAVAILABLE;
    
    #endif
    
    }

    Note that the byte order is reversed compared to m_lesc_private_key in the original question above.

Children
No Data
Related