@Rohit, Sorry to open old thread, but I'm having some issues with the security, and you seem to be the go-to man.
I have a peripheral device based on nRF51822, and want to enable encryption, but not necessarily bonding. My device has no IO capabilities so am using the just works model, however the central device (iPhone) is having lots of trouble connecting. I've tried various combinations of security manager settings with enabledBonding and requireMITM,
enableBonding = true, requireMITM = false
connection works ok using Master Control Panel and Nordic dongle, however iPhone will connect and pair and read characterisitics on first connection, then not be able to read any characterisitics on subsequent connections.
enableBonding = false, requireMITM = false
connection works ok using Master Control Panel and Nordic dongle, however iPhone keeps requesting pairing, and won't exit popup unless user cancels pairing operation.
Also, on all of my custom characterisitics, I've set the security requirements to ENCRYPTION_NO_MITM
Do you have any suggestions? Are there more security settings that might be relevant? I'm also searching through Nordic forum but not finding anything specifically helpful.
Andrew
                    
                 
                
             
        
Hi,
I'd like to introduce some APIs to allow link security in BLE.
Encryption/pairing/bonding can be enabled by initializing security-manager module of the BLE stack. Marking characteristics as requiring security will then enforce pairing/bonding during attribute access. I've also added some callbacks to get indications about the progress of the pairing procedure.
These APIs depend on v8 of the Nordic SDK. You can review the proposed extensions at https://github.com/mbedmicro/BLE_API/compare/securityExtensions
I request your feedback.
thanks.
security extensions to BLEDevice.h
/** * Enable the BLE stack's Security Manager. The Security Manager implements * the actual cryptographic algorithms and protocol exchanges that allow two * devices to securely exchange data and privately detect each other. * Calling this API is a prerequisite for encryption and pairing (bonding). */ ble_error_t initializeSecurity(void); /** * Setup a callback for when the security procedure for a link has started. */ void setOnSecuritySetupStarted(Gap::HandleSpecificEvent_t callback); /** * Setup a callback for when the security procedure for a link has * completed. */ void setOnSecuritySetupCompleted(Gap::HandleSpecificEvent_t callback); /** * Setup a callback for when a link with the peer is secured. For bonded * devices, subsequent reconnections with bonded peer will result only in * this callback when the link is secured and setup procedures will not * occur unless the bonding information is either lost or deleted on either * or both sides. */ void setOnLinkSecured(Gap::HandleSpecificEvent_t callback); /** * Setup a callback for bonding; i.e. that link-specific security context * is stored persistently for a peer device. */ void setOnSecurityContextStored(Gap::HandleSpecificEvent_t callback);security extensions to GattCharacteristic.h
enum ble_gatt_char_required_security_t { SECURITY_MODE_ENCRYPTION_OPEN_LINK = 0x00, /**< Set security mode to require no protection, open link. */ SECURITY_MODE_ENCRYPTION_NO_MITM = 0x01, /**< Set security mode to require encryption, but no MITM protection. */ SECURITY_MODE_ENCRYPTION_WITH_MITM = 0x02, /**< Set security mode to require encryption and MITM protection. */ SECURITY_MODE_SIGNED_NO_MITM = 0x04, /**< Set security mode to require signing or encryption, but no MITM protection. */ SECURITY_MODE_SIGNED_WITH_MITM = 0x08, /**< Set security mode to require signing or encryption, and MITM protection. */ }; /** * Setup the minimum security (mode and level) requirements for access to the characteristic's value attribute. * * @param securityMode Can be one of encryption or signing, with or without protection for MITM (man in the middle attacks). */ void requireSecurity(ble_gatt_char_required_security_t securityMode) { _requiredSecurity = securityMode; }