This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

DFU firmware encryption

Hi,

I would like to implement DFU with firmware encryption. I'm aware this isn't present in SDK 12 and would like to modify the secured bootloader to implement it.

As far as I understand, a DFU package is a zip file containing a manifest, and sets of 2 files, a .dat and a .bin . Is it right that the .bin is pure image, and .dat is the header/init packet?

My plan was to encrypt the .bin file, then, in the DFU bootloader, decrypt just before writing to flash. Does this sound like a good approach?

Thanks for your help!

Parents
  • I don't see any problem with this.

    And you are correct, .bin file is the pure image, and .data is the init packet.

    If you going to encrypt the .bin file and decrypt it after you receive it on the bootloader, you need to modify the bootloader so that hash and signature is only validated after the image is decrypted.

  • So this is it, thank you so much guys!

    One more thin I did (and you're welcome to tell me there's a better way): in prevalidate, I set a global variable m_image_encryption depending on the type of image.

    And for reference here's my great encryption/decryption code:

            if (m_image_encryption)
            {
                for (int i = 0; i < m_data_buf_pos; i++)
                {
                    m_data_buf[m_current_data_buffer][i] ^= 0x5A;
                }
            }
    

    It is to be inserted in nrf_dfu_data_req() before each of the 2 calls to nrf_dfu_flash_store(). (And no, don't consider xoring with any key safe)

    Additional tips to whoever would like to do something similar: when using nRF Connect on Android, if something seems to not work, kill the app and restart it.

Reply
  • So this is it, thank you so much guys!

    One more thin I did (and you're welcome to tell me there's a better way): in prevalidate, I set a global variable m_image_encryption depending on the type of image.

    And for reference here's my great encryption/decryption code:

            if (m_image_encryption)
            {
                for (int i = 0; i < m_data_buf_pos; i++)
                {
                    m_data_buf[m_current_data_buffer][i] ^= 0x5A;
                }
            }
    

    It is to be inserted in nrf_dfu_data_req() before each of the 2 calls to nrf_dfu_flash_store(). (And no, don't consider xoring with any key safe)

    Additional tips to whoever would like to do something similar: when using nRF Connect on Android, if something seems to not work, kill the app and restart it.

Children
No Data
Related