Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How Bluetooth Low Energy security works between Android app and BLE devices?

I'm studying the Bluetooth Low Energy (BLE) protocol (v4.2), and in particular its security features. I'm trying to understand how the encryption of data transmitted between a mobile App and a BLE device works.

The official documentation (v4.2) specifies the methods to encrypt data, authenticate the devices, generate the keys used in the encryption and pairing phase, etc..

First doubt (I want to be sure to have understood some concepts): all these functions are implemented in the host level, so if I want to encrypt data transmitted between an App (Android) and a BLE device (like a fitness tracker), do I have to implement (or enable) these methods on the BLE device? In this way, the developer should only care about the implementation of these features on the BLE device, since the Android Bluetooth stack just support these features. Am I right? If I'm wrong, what is the right way to implement these features (on both mobile app and BLE device)?

Second doubt: Why some BLE devices, implement their own cryptography, on top the GATT protocol, instead using the security features provided by the SIG?

Third and last doubt: Are the security features specified by the SIG mandatory or are optional?

As you can see I have some doubts, and maybe some questions could be silly, so if someone could clarify how the security mechanisms (like encryption) can be implemented between an App and a BLE device, and at which levels these features are implemented (OS or application level), I will appreciate a lot.

like image 384
d3llafr33 Avatar asked Jun 10 '17 10:06

d3llafr33


People also ask

How do Android apps communicate with custom BLE?

Create a new project Open Android Studio and you should be greeted with the following screen. Select Import an Android code sample. On the next screen select the sample Bluetooth Le Gatt under Connectivity. This project will set us up with a framework to build off of for our application.

How does Bluetooth low energy works?

BLE devices are discovered through the broadcasting of advertising packets over 3 separate frequencies to reduce interference. A BLE device sends out a repetitive packet of information over one of three channels with random delays of up to 10 milliseconds.

How does BLE encryption work?

The encryption in Bluetooth LE is based on 128-bit Advanced Encryption Standard — Counter with CBC-MAC (AES-CCM). LTK is used with this algorithm to create the 128-bit “shared secret” key. Authentication is provided in Bluetooth (LE) by digitally signing the data using the connection Signature Resolving Key (CSRK).

What is Bluetooth low energy in Android?

Bluetooth Low Energy (BLE), available in Android 4.3 and later, creates short connections between devices to transfer bursts of data. BLE remains in sleep mode when not connected. This lets BLE provide lower bandwidth and reduced power consumption compared to Classic Bluetooth.


1 Answers

If you use the standard BLE encryption, it is actually the link layer at the controller that does the encryption/decryption/verifying auth tags. But it's the host layer (SMP) that defines how two devices pair, bond and exchange keys. It's also that layer that tells the link layer to start encryption using the exchanged keys. On Android and iOS, it's the OS that manages the pairing and bonding and implements the SMP. Whether or not Bluetooth pairing/bonding/encryption is used is fully up to the device, and is optional. If it's not supported it must still support to send the error code "Pairing Not Supported"

The Bluetooth standard only has one "use case". This use case is to provide a method for securing the link between two devices so that, after bonding, no one should be able to impersonate a device or be able to manipulate or decrypt the traffic. As you might know, the "LE Legacy Pairing" which is the only pairing method specified up to Bluetooth v4.1, has several flaws that makes it unsecure if the attacker sniffs the traffic during pairing (both for "Just works" and "MITM/passkey entry", but not OOB). The new "LE Secure Connections" defined by Bluetooth v4.2 however uses Diffie Hellman to make it more secure.

Even though Bluetooth pairing itself provides security, there are some flaws in both the Android API and the iOS API that still may not be enough for an app developer if good security is needed. Notably, iOS does not provide any API whatsoever to detect if a given device is actually bonded or if a link is encrypted. It does however show a popup to the user when the pairing starts, but the app knows nothing about that pairing. So, from an iOS app's point of view, you don't know:

  1. If you have paired to the device.
  2. If you talk to a genuine device or a chinese copy.
  3. The security level, i.e. if the pairing used Just Works, MITM legacy pairing or LE Secure Connections.
  4. If the current link is encrypted.

Android is a little bit better. There the app can at least know if the device is bonded or not (but not the other three). There is also an API "createBond" to start the bonding process. The Windows API is much better here, since you can enforce encrypted link when doing GATT operations.

Any of these reasons may be enough for a developer to implement the security from scratch on top of GATT instead. In particular one often common use case is that the developer wants the use case "log in to the peripheral" with a PIN or password. The Bluetooth standard does not support that use case in any way (and no, using "MITM protected pairing with static passkey" doesn't work, since that protocol by design reveals the passkey after one or a few tries).

Anyway, if you develop your own peripheral with your own hardware and want to use the Bluetooth standard's pairing/bonding/encryption, the SDKs by the manufacturers of the BLE chips have usually already implemented this. However, you still need to set it up correctly for it to work. Usually you only have to configure some parameters (like if you have a display or the user can enter a passkey) and then the rest is automatically handled internally by their SDK.

UPDATE:

Source code for Android can be found at https://android.googlesource.com/platform/system/bt/, https://android.googlesource.com/platform/packages/apps/Bluetooth/ and https://android.googlesource.com/platform/frameworks/base/+/master/core/java/android/bluetooth.

like image 118
Emil Avatar answered Oct 18 '22 08:10

Emil