<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: jason goose</title>
    <description>The latest articles on DEV Community by jason goose (@jusgoose).</description>
    <link>https://dev.to/jusgoose</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1849709%2F899b35e1-bc6d-4d7a-a1c7-08a2c052e6e0.png</url>
      <title>DEV Community: jason goose</title>
      <link>https://dev.to/jusgoose</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/jusgoose"/>
    <language>en</language>
    <item>
      <title>Emulating USB Protocol over BLE for Data Transfer</title>
      <dc:creator>jason goose</dc:creator>
      <pubDate>Sun, 28 Jul 2024 02:12:49 +0000</pubDate>
      <link>https://dev.to/jusgoose/emulating-usb-protocol-over-ble-for-data-transfer-2hn3</link>
      <guid>https://dev.to/jusgoose/emulating-usb-protocol-over-ble-for-data-transfer-2hn3</guid>
      <description>&lt;p&gt;&lt;em&gt;article from &lt;a href="https://tosdn.com" rel="noopener noreferrer"&gt;tosdn.com&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;As the Internet of Things (IoT) continues to grow, the need for efficient and reliable data transfer between devices has become increasingly important. One approach to achieve this is by emulating the Universal Serial Bus (USB) protocol over Bluetooth Low Energy (BLE) technology. In this blog, we will explore the concept of emulating USB protocol over BLE and provide a detailed implementation guide for computer enthusiasts.&lt;/p&gt;

&lt;p&gt;Introduction to BLE and USB&lt;/p&gt;

&lt;p&gt;BLE is a wireless personal area network technology that allows devices to communicate with each other over short distances. It is commonly used in IoT devices, wearables, and other low-power applications. USB, on the other hand, is a widely used interface standard for connecting devices to a computer.&lt;/p&gt;

&lt;p&gt;Emulating USB Protocol over BLE&lt;/p&gt;

&lt;p&gt;To emulate the USB protocol over BLE, we need to create a virtual USB device on the BLE device and configure it to communicate with the computer as if it were a physical USB device. This involves creating a BLE service that mimics the USB device's behavior, including its interface, endpoints, and device class.&lt;/p&gt;

&lt;p&gt;Hardware and Software Requirements&lt;/p&gt;

&lt;p&gt;To implement this project, you will need the following hardware and software components:&lt;/p&gt;

&lt;p&gt;A BLE module (e.g., nRF52832 or CC2541)&lt;br&gt;
A microcontroller (e.g., STM32 or Arduino)&lt;br&gt;
A USB device (e.g., USB storage device or USB serial device)&lt;br&gt;
BLE module's SDK (e.g., nRF5 SDK or CC2541 SDK)&lt;br&gt;
Microcontroller's development environment (e.g., Keil µVision or Arduino IDE)&lt;br&gt;
USB device's driver program (e.g., USB storage device driver or USB serial device driver)&lt;br&gt;
Implementation Steps&lt;br&gt;
Step 1: Create a BLE Service&lt;/p&gt;

&lt;p&gt;Create a BLE service on the BLE module that mimics the USB device's behavior. This service should include characteristics that emulate the USB device's interface, endpoints, and device class.&lt;/p&gt;

&lt;p&gt;Using the nRF5 SDK, you can create a BLE service as follows:&lt;/p&gt;

&lt;h1&gt;
  
  
  include 
&lt;/h1&gt;

&lt;h1&gt;
  
  
  include 
&lt;/h1&gt;

&lt;h1&gt;
  
  
  define SERVICE_UUID 0x180F // USB device service UUID
&lt;/h1&gt;

&lt;h1&gt;
  
  
  define CHARACTERISTIC_UUID 0x2902 // USB device characteristic UUID
&lt;/h1&gt;

&lt;p&gt;void create_service(void)&lt;br&gt;
{&lt;br&gt;
    uint16_t service_handle;&lt;br&gt;
    uint16_t characteristic_handle;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Create a BLE service
ble_gap_service_add(&amp;amp;service_handle, &amp;amp;SERVICE_UUID);

// Create a BLE characteristic
ble_gatts_characteristic_add(&amp;amp;characteristic_handle, &amp;amp;CHARACTERISTIC_UUID, BLE_GATT_CHAR_PROPERTIES_READ | BLE_GATT_CHAR_PROPERTIES_WRITE, &amp;amp;service_handle);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;}&lt;br&gt;
Step 2: Implement a Virtual USB Device Class&lt;/p&gt;

&lt;p&gt;Implement a virtual USB device class on the microcontroller that emulates the behavior of a physical USB device. This class should provide a virtual USB interface and endpoints for data transfer.&lt;/p&gt;

&lt;p&gt;Using the Arduino IDE, you can implement a virtual USB storage device class as follows:&lt;/p&gt;

&lt;h1&gt;
  
  
  include 
&lt;/h1&gt;

&lt;p&gt;class USBStorageDevice {&lt;br&gt;
public:&lt;br&gt;
    USBStorageDevice() {&lt;br&gt;
        // Initialize the USB device&lt;br&gt;
        USB.begin();&lt;br&gt;
    }&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;void write_data(uint8_t* data, uint16_t length) {
    // Write data to the virtual USB storage device
    USB.write(data, length);
}

uint16_t read_data(uint8_t* data) {
    // Read data from the virtual USB storage device
    return USB.read(data);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;};&lt;br&gt;
Step 3: Implement Data Transfer Mechanism&lt;/p&gt;

&lt;p&gt;Implement a data transfer mechanism on the BLE module that allows data to be transferred between the BLE device and the computer. This mechanism should use the GATT protocol's write and read operations to transfer data.&lt;/p&gt;

&lt;p&gt;Using the nRF5 SDK, you can implement a data transfer mechanism as follows:&lt;/p&gt;

&lt;p&gt;void write_data(uint8_t* data, uint16_t length) {&lt;br&gt;
    // Write data to the BLE characteristic&lt;br&gt;
    ble_gatts_characteristic_write(&amp;amp;characteristic_handle, data, length);&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;uint16_t read_data(uint8_t* data) {&lt;br&gt;
    // Read data from the BLE characteristic&lt;br&gt;
    return ble_gatts_characteristic_read(&amp;amp;characteristic_handle, data);&lt;br&gt;
}&lt;br&gt;
Step 4: Connect to the Computer&lt;/p&gt;

&lt;p&gt;Connect the BLE device to the computer and use the virtual USB device class and data transfer mechanism to transfer data between the devices.&lt;/p&gt;

&lt;p&gt;Using the Arduino IDE, you can connect to the computer as follows:&lt;/p&gt;

&lt;h1&gt;
  
  
  include 
&lt;/h1&gt;

&lt;p&gt;USBStorageDevice usb_device;&lt;/p&gt;

&lt;p&gt;void setup() {&lt;br&gt;
    // Initialize the USB device&lt;br&gt;
    usb_device.begin();&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;void loop() {&lt;br&gt;
    // Wait for the computer to connect&lt;br&gt;
    if (usb_device.isConnected()) {&lt;br&gt;
        // Read data from the computer&lt;br&gt;
        uint8_t data[256];&lt;br&gt;
        uint16_t length = usb_device.read_data(data);&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    // Write data to the BLE device
    write_data(data, length);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;}&lt;br&gt;
Step 5: Test Data Transfer&lt;/p&gt;

&lt;p&gt;Test the data transfer mechanism by writing data to the BLE device and reading data from the computer.&lt;/p&gt;

&lt;p&gt;Using the serial terminal, you can test the data transfer as follows:&lt;/p&gt;

&lt;h1&gt;
  
  
  Write data to the BLE device
&lt;/h1&gt;

&lt;p&gt;echo "Hello, world!" &amp;gt; /dev/ttyUSB0&lt;/p&gt;

&lt;h1&gt;
  
  
  Read data from the BLE device
&lt;/h1&gt;

&lt;p&gt;cat /dev/ttyUSB0&lt;br&gt;
If everything is working correctly, you should see the data being transferred between the devices.&lt;/p&gt;

&lt;p&gt;Conclusion&lt;/p&gt;

&lt;p&gt;Emulating the USB protocol over BLE provides a convenient and efficient way to transfer data between devices. By following the implementation guide outlined in this blog, you can create a BLE device that communicates with a computer as if it were a physical USB device. This technology has numerous applications in IoT, wearables, and other low-power devices, and can enable new use cases and possibilities in the field of computer engineering.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Publication Survey: Security Considerations For Bluetooth Smart Devices</title>
      <dc:creator>jason goose</dc:creator>
      <pubDate>Sun, 28 Jul 2024 01:54:24 +0000</pubDate>
      <link>https://dev.to/jusgoose/publication-survey-security-considerations-for-bluetooth-smart-devices-1a4l</link>
      <guid>https://dev.to/jusgoose/publication-survey-security-considerations-for-bluetooth-smart-devices-1a4l</guid>
      <description>&lt;p&gt;&lt;em&gt;article from &lt;a href="https://tosdn.com" rel="noopener noreferrer"&gt;tosdn&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Bluetooth Smart is an emerging short range wireless technology aimed for low power devices. Bluetooth 4.2 core specification provides various methods to secure the communication between devices and establish trusted connections. This paper describes the design considerations to secure the Bluetooth smart devices.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Introduction&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Bluetooth smart (also known as Bluetooth low energy or BLE) is introduced in the legacy Bluetooth 4.0 specification by Bluetooth special interest group. Bluetooth smart is primarily designed for low power embedded devices with limited computation capabilities. With expeditious growth in the IoT technology, Bluetooth Low Energy Module has become substantiate criterion for the smart devices.&lt;/p&gt;

&lt;p&gt;Bluetooth specification supports the asymmetrical architecture of the LE devices. Memory and processing power requirements of peripheral devices are much lower than the central. This will be a great advantage in case of single mode - peripheral only devices. Device that acts always as peripheral can be designed with low memory, longer battery life and low power consumption. Low power smart wearable devices available in market such as Bluetooth heart rate monitors, blood pressure monitors, fitness kit, smart watches etc. run on a small coin cell battery for years.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Low energy, Low security&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Like any other wireless technology, BLE is no exception from security threats. While Bluetooth LE beacons bring lots of potential in the IOT design, security threats such as device tracking, eaves dropping, and man in the middle attack are increasing significantly. BLE devices are designed to broadcast MAC, UUID and service information’s at a predefined interval. Due to continuous advertisement, hackers can easily track the device and decode the broadcasting information using a sniffers or even smart phone. Below Figure 1 indicates how a LE device can be tracked by the hacker and steal sensitive data over a period of time across various geographical locations.&lt;/p&gt;

&lt;p&gt;With hacking and cybercrime reported enormously all over the world, people are extremely concerned about the privacy. Sensitive data getting in to the hands of the wrong people without user consent may lead to significant damages. For example, if such devices with serious security flaws are deployed in military, it can reveal the secrets to the rivals.&lt;/p&gt;

&lt;p&gt;Figure 1 – LE devices without privacy&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Threats for Bluetooth Smart&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Passive Eavesdropping:&lt;/p&gt;

&lt;p&gt;Passive eavesdropping is secretly listening to the private communication between two devices in real-time by un-authenticated third party devices (eavesdropping equipment). Using a 2.4GHZ channel sniffer, one can listen to all the communication between BLE devices without the consent of communicating devices. Since eavesdropping does not affect the normal communication between the devices, chances of user noticing eavesdropping attempt are extremely low. If unencrypted message or unsigned messages are used in communication, hacker can get direct access to all the confidential data exchanged between the devices. Pairing procedures are the well-known techniques to avoid the eavesdropping issues and encrypt the messages before exchange. But, if the attacker is listening to the devices during the pairing process itself, then pairing methods can’t assure the safety against the attack!&lt;/p&gt;

&lt;p&gt;Man in the Middle (MITM):&lt;/p&gt;

&lt;p&gt;In MITM, attacker secretly reads and interprets the messages from the sender and delivers the message to the reader after interpreting it. Since the attacker is actively involved in the communication between the devices, this attack is also known as active eavesdropping. During the course of attack, attacker may insert his own messages or corrupt the data before delivering it to the reader. Devices participating in the connection will assume that they are communicating with each other directly. But an intermediate MITM attacker has complete control over the communication of these devices. Public key cryptography can provide needed protection against MITM. But this method will fail, if an active MITM attacker listens to the shared public key during the initial pairing process and shares his own public Key instead of actual public key. A device which received the public key from attacker has no knowledge about the source of the key and hence it will encrypt and send the next message with the public key shared by the attacker. Now, the attacker can easily decrypt the messages and interpret it. Also, he may optionally decide to encrypt the message using the original public key and deliver to the initiator to keep the communication intact. Below figure-2 indicates how a hacker can attack the communication between two devices in MITM.&lt;/p&gt;

&lt;p&gt;Figure 2 – MITM&lt;/p&gt;

&lt;p&gt;Identity Tracking:&lt;/p&gt;

&lt;p&gt;Bluetooth Low Energy 4.0 devices are designed for periodic advertisement of the status or its existence. Advertisement packet contains the MAC address of the broadcaster and unique service formation. It also contains information about the proximity of the device in terms of the signal strength. Using publicly available advertisement data and characteristics, attacker can extract large amount of information which may help him to track the devices based on these unique information.&lt;/p&gt;

&lt;p&gt;Duplicate device:&lt;/p&gt;

&lt;p&gt;An attacker with the knowledge of MAC address can make a dummy device with the same MAC address, which runs the dummy service. Such kind of attack is more dangerous in business and may lead to huge loss since customers will not be able to get the intended service.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Security architecture:&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Security in Host:&lt;/p&gt;

&lt;p&gt;Unlike classic Bluetooth, Bluetooth low energy sensors and devices implement the key management and security manager on host instead of controller. All the key generation and distributions of key are taken care by SMP running on host. This approach introduced by Bluetooth specification helps the host to be flexible and reduces the cost and complexity of LE-only controllers. Security manager:&lt;/p&gt;

&lt;p&gt;Figure 3 – Security Manager&lt;/p&gt;

&lt;p&gt;Bluetooth specification mandates a security manager in the protocol stack implementation. Security manger defines the authentication, pairing, encryption and signing between the Bluetooth low energy devices. This is responsible for all the security and privacy implementations of the BLE stack such as generation and storing various keys, generating random address and address resolution for the privacy feature. Security manager uses the services provided by the L2CAP layer to manage the security. Each device can generate its own key without any external influence and strength of the key is proportional to the algorithm implemented in the device&lt;/p&gt;

&lt;p&gt;LE security modes:&lt;/p&gt;

&lt;p&gt;Bluetooth Security requirements of the device and services are expressed in terms of security modes and security levels. Each service and device may have separate security requirement. A physical connection between two devices always operates in a single security mode. With wide adoption of 4.2 specifications, secure simple pairing methods have become de-facto requirement for the LE device to ensure security.&lt;/p&gt;

&lt;p&gt;LE security mode 1:&lt;/p&gt;

&lt;p&gt;Security level-1 and level-2 in these modes supports LE communication without security and encryption without pairing respectively. Level 3 and level 4 provides more security to the system than prior levels. LE secure connection (Level-4) introduced in Bluetooth SIG 4.2 specifications, brings in high security to the LE communication via Elliptic Curve Diffie-Hellman (ECDH) public key cryptography technique.&lt;/p&gt;

&lt;p&gt;LE security mode 2:&lt;/p&gt;

&lt;p&gt;Devices conform to security mode-2 supports both authenticated and unauthenticated pairing along with mandatory data signing. Data can be signed using various techniques including public key cryptography to ensure the data integrity and security.&lt;/p&gt;

&lt;p&gt;Mixed Security mode:&lt;/p&gt;

&lt;p&gt;For the devices which need both mode-1 and mode-2 security shall use mixed security mode. This enables the devices to use combination of multiple security modes such as data signing along with ECDH to provide enormous security to the smart devices.&lt;/p&gt;

&lt;p&gt;Secure Connection Only mode:&lt;/p&gt;

&lt;p&gt;When LE smart devices operates in secure connection only mode they shall use authenticated connection and pairing with encryption. Device shall only accept outgoing and incoming connections for services that use security mode-1, level 4. With this restriction, devices operating in this mode should use ECDH, introduced in 4.2 specifications.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Securing Bluetooth Smart: Pairing:&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The association is done in three phases, which includes device capability exchange, LTK generation for secure Connection and transport specific key distribution. For legacy devices, STK is used instead of LTK.&lt;/p&gt;

&lt;p&gt;Figure 4 - Pairing Process&lt;/p&gt;

&lt;p&gt;Phase-1 (capability exchange):&lt;/p&gt;

&lt;p&gt;The first step of pairing process is to exchange the identity and capability information to establish a trusted link between LE devices. Master initiates the pairing procedure by sending a pairing request to slaves. If security procedures are not initiated by the master, slave can request master for initiating it. Once the security requests are received by the slave, master re-initiates the pairing process.&lt;/p&gt;

&lt;p&gt;Phase-2 (Secure Key Generation):&lt;/p&gt;

&lt;p&gt;Selection of pairing method depends on capabilities exchanged in phase-1. Short Term Keys (STK) are generated based on selected pairing method such as just works, passkey entry and out of band. Generated secure key pairs (STK) will be used to establish a secure channel between the participating devices.&lt;/p&gt;

&lt;p&gt;In legacy 2.0 standards, PIN based pairing method was introduced. In this method, users must enter the predefined 4-digit PIN code on both the devices. Devices will be paired on successful authentication of the PIN on both ends. These predefined PINs cannot be changed unless the next firmware upgrade. Since it is a fixed number, it is relatively easy for the hackers to interpret the messages and break the security of the system. Later in 2.1 specifications, Secure Simple Pairing (SSP) methods introduced to ensure both security and simplicity&lt;/p&gt;

&lt;p&gt;Just Works:&lt;/p&gt;

&lt;p&gt;In Just Work method, no key exchange between the devices and no user interaction required. This method is well suited if at-least one of the devices participating in the communication doesn’t have the user interface. This method provides no MITM protection.&lt;/p&gt;

&lt;p&gt;Numeric comparison:&lt;/p&gt;

&lt;p&gt;If both devices participating in the BLE connection have a display and at-least has Yes/No Key, then numeric comparison method can be used. A 6-digit randomly generated code will be displayed on each device. User need to press Yes/No after manually verifying the key’s displayed.&lt;/p&gt;

&lt;p&gt;Pass Key Entry:&lt;/p&gt;

&lt;p&gt;This method may be used for the devices with a display and other with the keypad or both devices with at-least numeric keypad. In first case, one device shows the 6-digit number and other receives the 6-digit input from user and in later case both devices receives 6-digit numeric input from the user. On successful authentication devices will be paired and provides MITM protection.&lt;/p&gt;

&lt;p&gt;Out of Band:&lt;/p&gt;

&lt;p&gt;Out of band pairing method is adopted by Bluetooth standards for the scenarios where both the devices participating in the communication have enabled out of band communication channel. All secret information’s and cryptographic keys will be exchanged out of the Bluetooth band. With the rapid growth of the NFC technology, NFC has become de-facto technology for Bluetooth OOB communications. Since NFC works at 13.56 MHz, Bluetooth sniffers on 2.4GHz bandwidth can’t listen to the information exchanged in the pairing process. Also, NFC is designed to operate over a very small distance up to 10cm, which makes it more suitable for security critical applications to avoid any MITM attacks.&lt;/p&gt;

&lt;p&gt;Phase-3 (Transport Specific Key Distribution):&lt;/p&gt;

&lt;p&gt;After STK generation and encrypting the links, transport specific keys are distributed. Keys to be distributed are determined by the parameters of pairing request and response. Keys exchanged in this phase may include LTK, IRK, the signature key etc.&lt;/p&gt;

&lt;p&gt;Bonding:&lt;/p&gt;

&lt;p&gt;Bonding is the process of creating the long term trusted relationship between the devices based on link key generated during pairing process. Long term key’s (LTK) are generated and stored on both the initiator and responder. These LTK’s must be used for all the subsequent communication between the same devices to ensure the data security.&lt;/p&gt;

&lt;p&gt;Key Generation:&lt;/p&gt;

&lt;p&gt;Host implements the necessary API’s on LE devices to generate the keys such as STK, LTK, IRK, CSRK etc. Unlike classic Bluetooth, controller is not involved any key generation methods in case of BLE. The host generates Private and Public key pair and secure connection will be created by taking the factors from both the devices participating creating the communication. Master and Slave exchanges Identity resolving Key (IRK) for device Identity and Connection Signature Resolving Key (CSRK) for Authentication of unencrypted data.&lt;/p&gt;

&lt;p&gt;Encryption:&lt;/p&gt;

&lt;p&gt;LE controller uses the keys generated by the host and encrypts the messages. Legacy controllers are designed to support to FIPS compliant 128-bit AES. Latest 4.2 LE specifications introduce Elliptic Curve Diffie-Hellman (ECDH) cryptography over earlier 128-bit AES. ECDH initially exchanges the keys over public insecure channel and then enables the secure channel communication between the devices participating in the process.&lt;/p&gt;

&lt;p&gt;Signed Data:&lt;/p&gt;

&lt;p&gt;BLE specification supports sending signed data over an unencrypted channel with trusted relationship. Even though devices are not paired, BLE devices can still maintain the privacy of data by signing it. The sender uses CSRK to sign the data and receiver verifies the signature. On successful verification of the signature, the receiver assumes that a message has arrived from a trusted source.&lt;/p&gt;

&lt;p&gt;Privacy feature:&lt;/p&gt;

&lt;p&gt;Devices are identified by a 48-bit MAC address compliant to IEEE. It is optional for the devices to implement either or both public address and private address. Public device address is broadcasted by the BLE device and hence increases the risk of security. Bluetooth devices provide the privacy feature to reduce the risk of device tracking based on identifier of the device. In legacy BLE systems, host implements the address generation and resolution. According to BLE 4.2 specification, private address generation and resolution are implemented in the controller. Privacy enabled devices are expected to support at-least one of the static device address or private address.&lt;/p&gt;

&lt;p&gt;Static device address:&lt;/p&gt;

&lt;p&gt;The static device address is randomly generated 48-bit address compliant to Bluetooth SIG specifications. Static address will be changed on every power cycle, and hence reduced the risk of tracking over power cycles. But the devices which are not power cycled for a long time may face higher security risk.&lt;/p&gt;

&lt;p&gt;Private address:&lt;/p&gt;

&lt;p&gt;Bluetooth SIG compliant private address is the recommended way of providing security to BLE devices. BLE specification supports resolvable private address and non-resolvable private address. Only requirement to have the non-resolvable private address is address shall not be equal to public address of the device. Non resolvable private addresses are typically used for beacons. To generate resolvable private address, devices needs to be paired, exchange the private address and IRK during the pairing process. Only paired devices can resolve this random address and thus possibilities of tracking the device over period of time is nullified. Private address is changed periodically based on a timer event and only a trusted device can resolve this address.&lt;/p&gt;

&lt;p&gt;Directed advertising:&lt;/p&gt;

&lt;p&gt;In directed advertising devices indicates both MAC address of the advertising device and MAC address of the devices it is advertising to. Advertiser invites the specific trusted device to re-connect, if required. Address used by the advertiser a special private address called as reconnect address. In legacy Bluetooth standards, reconnect address can be changed only based on user actions such as connect, disconnect, device power cycle etc. Latest 4.2 specifications supports timer based update of the reconnect address.&lt;/p&gt;

&lt;p&gt;Authentication over proximity:&lt;/p&gt;

&lt;p&gt;Received Signal Strength Indicator (RSSI) is the indication of beacon signal strength observed by the receiver. RSSI is a factor of transmitting power of broadcaster and the distance between broadcaster and receiver. As an additional safety measure for the BLE devices, signal strength monitor can be used to extract the distance between the broadcaster and the receiver and BLE devices with predefined range of RSSI only can be selected for communication. This method will reduce the risk of a being tracked or monitored or misleading by a hacker over a long distance. Since RSSI can vary greatly&lt;/p&gt;

&lt;p&gt;depending on the usage conditions and environment, this method is specific to the usage conditions and deployment of the products.&lt;/p&gt;

&lt;p&gt;Hidden MAC:&lt;/p&gt;

&lt;p&gt;Bluetooth SIG introduced 4.2 standards with improved data exchange rate as well as security. Most of the major security features of the classic Bluetooth are adapted to Low Energy specifications. This specification hides the unique MAC address of the devices. Advertising LE devices need not broadcast their MAC address for identification purpose.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Conclusion&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Compared to Legacy LE standards, 4.2 specifications introduce a new security model along with Secure Simple pairing. Security techniques like MAC address hiding, Elliptic Curve Diffie-Hellman based key exchange and LE secure connections ensures industry standards security for the LE device. Thus Bluetooth SIG 4.2 specifications ensured the smarter privacy approaches for the LE devices and now Bluetooth smart is more secure than ever.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Bluetooth Mesh Security Overview</title>
      <dc:creator>jason goose</dc:creator>
      <pubDate>Sun, 28 Jul 2024 01:51:57 +0000</pubDate>
      <link>https://dev.to/jusgoose/bluetooth-mesh-security-overview-7ci</link>
      <guid>https://dev.to/jusgoose/bluetooth-mesh-security-overview-7ci</guid>
      <description>&lt;p&gt;&lt;em&gt;article from &lt;a href="https://tosdn.com" rel="noopener noreferrer"&gt;tosdn&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The Criticality of Security&lt;br&gt;
One of the most discussed issues related to the Internet of Things (IoT) is security. From agriculture to hospitals, from residential smart homes to commercial smart buildings, and from power stations to traffic management systems, IoT systems and technologies will touch many parts of the world we live in. Security breaches in IoT systems could have catastrophic consequences.&lt;/p&gt;

&lt;p&gt;Bluetooth® mesh networking was designed with security as its number one priority and from the ground up. In this article, you’ll get an overview of the key security features and the security issues addressed. Further articles in the series will examine aspects of Bluetooth mesh networking security in more detail.&lt;/p&gt;

&lt;p&gt;Security in Bluetooth Mesh Networking is Mandatory&lt;br&gt;
Bluetooth® Low Energy (LE) GATT devices may implement a range of security measures as defined in the Bluetooth core specification. It’s the responsibility of the product designer to decide what security measures are required and it’s permissible to decide to adopt none of the available security features at all. In other words, security in Bluetooth Low Energy GATT is optional. This makes sense if we’re talking about the security of a single device and its connection with one other device, provided the product designer performs their risk assessment correctly. However, security in Bluetooth mesh networking is concerned with the security of more than individual devices or connections between peer devices; it’s concerned with the security of an entire network of devices and of various groupings of devices in the network.&lt;/p&gt;

&lt;p&gt;Consequently, security in Bluetooth mesh networking is mandatory.&lt;/p&gt;

&lt;p&gt;Bluetooth Mesh Networking Security Fundamentals&lt;br&gt;
The following fundamental security statements apply to all Bluetooth mesh networks:&lt;/p&gt;

&lt;p&gt;Encryption and Authentication&lt;/p&gt;

&lt;p&gt;All Bluetooth mesh messages are encrypted and authenticated.&lt;/p&gt;

&lt;p&gt;Separation of Concerns&lt;/p&gt;

&lt;p&gt;Network security, application security, and device security are addressed independently. See Separation of Concerns below.&lt;/p&gt;

&lt;p&gt;Area Isolation&lt;/p&gt;

&lt;p&gt;A Bluetooth mesh network can be divided into subnets, each cryptographically distinct and secure from the others.&lt;/p&gt;

&lt;p&gt;Key Refresh&lt;/p&gt;

&lt;p&gt;Security keys can be changed during the life of the Bluetooth mesh network via a Key Refresh procedure.&lt;/p&gt;

&lt;p&gt;Message Obfuscation&lt;/p&gt;

&lt;p&gt;Message obfuscation makes it difficult to track messages sent within the network and, as such, provides a privacy mechanism to make it difficult to track nodes.&lt;/p&gt;

&lt;p&gt;Replay Attack Protection&lt;/p&gt;

&lt;p&gt;Bluetooth mesh security protects the network against replay attacks.&lt;/p&gt;

&lt;p&gt;Trashcan Attack Protection&lt;/p&gt;

&lt;p&gt;Nodes can be removed from the network securely, in a way which prevents trashcan attacks.&lt;/p&gt;

&lt;p&gt;Secure Device Provisioning&lt;/p&gt;

&lt;p&gt;The process by which devices are added to the Bluetooth mesh network to become nodes is a secure process.&lt;/p&gt;

&lt;p&gt;Separation of Concerns and Security Keys&lt;br&gt;
At the heart of Bluetooth® mesh security are three types of security keys. These keys provide security to different aspects of the Bluetooth mesh network and achieve a critical capability in Bluetooth mesh networking security called a separation of concerns.&lt;/p&gt;

&lt;p&gt;Consider a mesh light which acts as a relay. In its capacity as a relay, it may find itself handling messages relating to the building’s Bluetooth mesh door and window security system. A light has no business accessing and processing the details of these messages, but it does need to relay them to other nodes.&lt;/p&gt;

&lt;p&gt;To deal with this potential conflict of interest, Bluetooth mesh uses different security keys called AppKeys for securing messages at the network layer from those used to secure data relating to specific applications, such as lighting, physical security, heating, etc.&lt;/p&gt;

&lt;p&gt;All nodes in a Bluetooth mesh network possess one or more Network Keys (NetKey), each corresponding to a subnet which may be the primary subnet. It’s possession of a network key which makes a node a member of the network. Network Encryption Keys and Privacy Keys are derived directly from the NetKey.&lt;/p&gt;

&lt;p&gt;Being in possession of a NetKey allows a node to decrypt and authenticate up to the Network Layer so that network functions, such as relaying, can be carried out. It does not allow application data to be decrypted.&lt;/p&gt;

&lt;p&gt;Each node also has a unique security key called the Device Key or DevKey. The DevKey is used in the provisioning and configuration of the node.&lt;/p&gt;

&lt;p&gt;Area Isolation&lt;br&gt;
Possession of the primary NetKey defines membership of and grants access to the Bluetooth® mesh network. But it’s also possible to divide the network into distinct subnets, each with its own subnet key. This means that only devices in possession of a given subnet key can communicate with other devices that are members of that subnet. Subnet keys can be created and assigned on an adhoc basis too. A great example is isolating nodes in different hotel rooms from each other.&lt;/p&gt;

&lt;p&gt;Node Removal, Key Refresh, and Trashcan Attacks&lt;br&gt;
As described above, nodes contain various Bluetooth® mesh security keys. Should a node become faulty and need to be disposed of, or if the owner decides to sell the node to another owner, it’s important that the device and the keys it contains cannot be used to mount an attack on the network the node was taken from.&lt;/p&gt;

&lt;p&gt;Bluetooth mesh networking ensures devices can be disposed of securely&lt;br&gt;
A procedure for removing a node from a network is defined. The Provisioner application is used to add the node to a reject list and then a Key Refresh Procedure is initiated.&lt;/p&gt;

&lt;p&gt;The Key Refresh Procedure issues all nodes in the network, except those which are members of the reject list, new network keys, application keys, and all related, derived data. In other words, the entire set of security keys which form the basis for network and application security are replaced.&lt;/p&gt;

&lt;p&gt;As such, a node which was removed from the network, and which contains an old NetKey and old set of AppKeys, is no longer a member of the network and poses no threat.&lt;/p&gt;

&lt;p&gt;Privacy&lt;br&gt;
A Privacy Key, derived from the NetKey, is used to obfuscate network PDU header values, such as the source address. Obfuscation ensures that casual, passive eavesdropping cannot be used to track nodes and the people using them. It also makes attacks based upon traffic analysis difficult.&lt;/p&gt;

&lt;p&gt;Replay Attacks&lt;br&gt;
In network security, a replay attack is a technique whereby an eavesdropper intercepts and captures one or more messages and simply retransmits them later, with the goal of tricking the recipient into carrying out something which the attacking device is not authorized to do. A commonly cited example is a car’s keyless entry system being compromised by an attacker who intercepts the authentication sequence between the car’s owner and the car, later replaying those messages to gain entry to the car and steal it.&lt;/p&gt;

&lt;p&gt;Bluetooth® mesh networking protects against replay attacks by using two network PDU fields called the Sequence Number (SEQ) and IV Index. Elements increment the SEQ value every time they publish a message. A node which receives a message from an element containing an SEQ value less than or equal to that of the last valid message will discard it since it likely relates to a replay attack. Similarly, IV Index is a separate field considered alongside SEQ. IV Index values within messages from a given element must always be equal to or greater than the last valid message from that element.&lt;/p&gt;

&lt;p&gt;Cryptography Toolbox&lt;br&gt;
Most of the security features of Bluetooth mesh networking rely upon industry-standard cryptographic algorithms and procedures. Reference will be made to them in other security-related articles in this series, but we’ll explain the most important ones here.&lt;/p&gt;

&lt;p&gt;There are two key security functions used in the Bluetooth mesh stack: AES-CMAC and AES-CCM. These are fundamental encryption and authentication functions, and all other functions used for key generation are based upon them.&lt;/p&gt;

&lt;p&gt;AES-CMAC&lt;br&gt;
Cipher-based Message Authentication Code (CMAC) is an algorithm which can generate a fixed length, 128-bit message authentication value for any variable length input. The formula for generating a message authentication code MAC using the AES-CMAC algorithm is written as:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    MAC = AES-CMACk(m)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The inputs to AES-CMAC are:&lt;/p&gt;

&lt;p&gt;k – the 128-bit key.&lt;br&gt;
m – the variable length data to be authenticated.&lt;/p&gt;

&lt;p&gt;AES-CMAC has excellent error-detection capabilities. Other techniques, involving the verification of a checksum or use of an error-detecting code, may detect only accidental modifications of the data. AES-CMAC is designed to detect intentional, unauthorized modifications of the data, as well as accidental modifications. If you are interested in learning more about this function, please refer to RFC4493 which defines it. &lt;/p&gt;

&lt;p&gt;AES-CCM&lt;br&gt;
AES-CCM is a generic, authenticated encryption algorithm, intended for use with cryptographic block ciphers. In the Bluetooth mesh specification, AES-CCM is used as the basic encryption and authentication function in all cases. The formula for its use is as follows:&lt;/p&gt;

&lt;p&gt;ciphertext , MIC = AES-CCMk (n,m,a)&lt;/p&gt;

&lt;p&gt;There are four inputs to AES-CCM:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;          k – the 128-bit key.

          n – a 104-bit nonce.

          m – the variable length data to be encrypted and authenticated.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;a – the variable length data to be authenticated but not encrypted, also known as Additional Data. This input parameter may be zero bytes in length.&lt;/p&gt;

&lt;p&gt;There are two outputs from AES-CCM:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;          ciphertext – the variable length data after it has been encrypted.

          MIC – the Message Integrity Check value of m and a.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Figure 1 shows a plain-text payload, which may be from the Bluetooth® mesh network layer or upper transport layer, being processed by AES-CCM with an input encryption key, nonce, and plaintext payload. An encrypted payload and MIC is output.&lt;/p&gt;

&lt;p&gt;Figure 1 – AES-CCM used for packet payload encryption and authentication&lt;br&gt;
SALT Generation&lt;br&gt;
Bluetooth® mesh security defines a SALT generation function known as s1, which uses the AES-CMAC function. As explained above, AES-CMAC has two input parameters: k and m. When used for SALT generation though, only the input parameter m varies. k is always set to the 128-bit value: 0x0000 0000 0000 0000 0000 0000 0000 0000, which is referred to as ZERO in the Bluetooth mesh specification.&lt;/p&gt;

&lt;p&gt;Figure 2 – The SALT generation function&lt;br&gt;
The input to the SALT generation function is:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;          m – a non-zero length octet array or ASCII encoded string.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The output is a 128-bit MAC value and the s1 formula is written as:&lt;/p&gt;

&lt;p&gt;s1(m) = AES-CMACZERO(m)&lt;/p&gt;

&lt;p&gt;Other security functions&lt;br&gt;
In the Bluetooth mesh networking specification section 3.8.2, Security Toolbox, you will find other security functions defined, such as various key derivation functions. All of them are based on AES-CMAC and the SALT generation function, s1 (the SALT generation function is also based on AES-CMAC).&lt;/p&gt;

&lt;p&gt;Onwards!&lt;br&gt;
Security is an important issue for Bluetooth, and the topic will come up repeatedly in our series on Bluetooth mesh networking. After reading this article, you should have a good understanding of the primary Bluetooth® mesh networking security features and some of the underlying cryptography techniques involved. You’re now ready to take a deeper dive into Bluetooth mesh network security when we cover the subject in future articles.&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
