<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Signature on BL updated by DFU</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/57946/signature-on-bl-updated-by-dfu</link><description>There doesn&amp;#39;t seem to be any validation of the image when updating the bootloader by secure DFU. nrfutil has no switch to generate any crc or ecdsa_signature. The code uses VALIDATE_CRC, but the expected value is calculated on the received image in boot_validate_extract</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 15 Apr 2020 11:23:41 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/57946/signature-on-bl-updated-by-dfu" /><item><title>RE: Signature on BL updated by DFU</title><link>https://devzone.nordicsemi.com/thread/244691?ContentTypeID=1</link><pubDate>Wed, 15 Apr 2020 11:23:41 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:50b57bfe-e17f-4f4f-8afd-f39b25d9ec80</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Thank you for updating this thread. You are right, this is a bug. I have created an internal ticket and discussed it with the SDK team so that it can be fixed in a future release.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Signature on BL updated by DFU</title><link>https://devzone.nordicsemi.com/thread/243959?ContentTypeID=1</link><pubDate>Tue, 07 Apr 2020 19:52:42 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:503b3834-6087-430b-bd5e-ac6a6f464ced</guid><dc:creator>jlubawy</dc:creator><description>&lt;p&gt;By the way I am using nRF52 SDK v15.3.0, but I checked and the firmware bug mentioned above is still present in v16.0.0.&lt;/p&gt;
&lt;p&gt;I&amp;nbsp;tried updating the SD+BL using nRF Connect on both iOS and Android, all failed due to this firmware bug.&lt;/p&gt;
&lt;p&gt;I believe the only option to workaround this bug is to not use&amp;nbsp;&lt;strong&gt;nrfutil pkg generate&amp;nbsp;--sd-boot-validation VALIDATE_ECDSA_P256_SHA256&lt;/strong&gt; until the bug is fixed in an update version of the bootloader.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Signature on BL updated by DFU</title><link>https://devzone.nordicsemi.com/thread/243778?ContentTypeID=1</link><pubDate>Tue, 07 Apr 2020 02:42:25 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d082d900-544f-4158-9f4d-468467766008</guid><dc:creator>jlubawy</dc:creator><description>&lt;p&gt;Please don&amp;#39;t close this issue yet.&lt;/p&gt;
&lt;p&gt;I ran into&amp;nbsp;this&amp;nbsp;same exact problem, where if I try to update the SD + BL at the same time the call to &amp;quot;boot_validation_extract&amp;quot; passes for SD but fails for BL. This is because as &lt;a href="https://devzone.nordicsemi.com/members/sjerlhagen"&gt;sjerlhagen&lt;/a&gt; pointed out, the code is looking at the wrong index (always looking at index zero).&lt;/p&gt;
&lt;p&gt;The only way I was able to get past this was to implement the fix he suggested where index starts at zero and is incremented.&lt;/p&gt;
&lt;p&gt;Here is what my init packet looks like, index = 0 is for SD, and index = 1 is for BL:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;boot_validation_count = 2,
boot_validation = {
    {
      type = DFU_VALIDATION_TYPE_VALIDATE_ECDSA_P256_SHA256,
      bytes = {
        size = 64, 
        bytes = &amp;quot;&amp;lt;some bytes&amp;gt;&amp;quot;,
      },
    },
    {
      type = DFU_VALIDATION_TYPE_VALIDATE_GENERATED_CRC,
      bytes = {
        size = 0,
        bytes = &amp;#39;\000&amp;#39; &amp;lt;repeats 63 times&amp;gt;
      },
    },
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;I think this bug would be hidden&amp;nbsp;unless &amp;quot;VALIDATE_ECDSA_P256_SHA256&amp;quot; is used for SD, otherwise the SD and BL would end up using the same validation. Can you elaborate on how you determined it &amp;quot;works as expected&amp;quot;? Did you try the same configuration?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Signature on BL updated by DFU</title><link>https://devzone.nordicsemi.com/thread/235195?ContentTypeID=1</link><pubDate>Wed, 19 Feb 2020 13:04:03 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:052861df-9e55-4340-8704-52eb4b4bae66</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;I see. Please revert your change. This works with the unmodified bootloader.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Signature on BL updated by DFU</title><link>https://devzone.nordicsemi.com/thread/235141?ContentTypeID=1</link><pubDate>Wed, 19 Feb 2020 10:56:14 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6a830c76-37c5-46cd-8cb1-1961ed7fa825</guid><dc:creator>sjerlhagen</dc:creator><description>&lt;p&gt;I see, I did not catch this additional whole image hash verification. This is ok.&lt;/p&gt;
&lt;p&gt;In postvalidate_sd_bl I did the following changes:&lt;/p&gt;
&lt;p&gt;Added&amp;nbsp;&amp;nbsp;&lt;strong&gt;&lt;em&gt;uint8_t&amp;nbsp; index = 0;&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Changed the bold parts below in the &lt;span&gt;postvalidate_sd_bl&amp;nbsp;&lt;/span&gt;function:&lt;/p&gt;
&lt;p&gt;&lt;em&gt;if (!boot_validation_extract(&amp;amp;boot_validation_sd, p_init, &lt;strong&gt;index&lt;/strong&gt;, start_addr, p_init-&amp;gt;sd_size, VALIDATE_CRC))&lt;/em&gt;&lt;br /&gt;&lt;em&gt; {&lt;/em&gt;&lt;br /&gt;&lt;em&gt; return false;&lt;/em&gt;&lt;br /&gt;&lt;em&gt; }&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;bl_start += p_init-&amp;gt;sd_size;&lt;/em&gt;&lt;br /&gt;&lt;em&gt; bl_size -= p_init-&amp;gt;sd_size;&lt;/em&gt;&lt;br /&gt;&lt;strong&gt;&lt;em&gt; index++;&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;&lt;em&gt; }&lt;/em&gt;&lt;br /&gt;&lt;em&gt; if (with_bl)&lt;/em&gt;&lt;br /&gt;&lt;em&gt; {&lt;/em&gt;&lt;br /&gt;&lt;em&gt; if (!boot_validation_extract(&amp;amp;boot_validation_bl, p_init, &lt;strong&gt;index&lt;/strong&gt;, bl_start, bl_size, NO_VALIDATION))&lt;/em&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Signature on BL updated by DFU</title><link>https://devzone.nordicsemi.com/thread/235115?ContentTypeID=1</link><pubDate>Wed, 19 Feb 2020 09:59:45 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:da3388ff-ac45-45c3-9bd0-c49640cf07ad</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
[quote user="sjerlhagen"]For a bootloader update I only see the ECDSA signature of the init packet being verified before download, I cant find any verification of the image &lt;br /&gt;(except for verifying CRC for the objects to ensure correct transfer).[/quote]
&lt;p&gt;Yes, the init packet itself is validated before the firmware is downloaded. But the init packet is also used to validate the received firmware before it is activated. In details:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;When a whole firmware image is received&amp;nbsp;on_data_obj_execute_request_sched() in nrf_dfu_req_handler.c calls&amp;nbsp;nrf_dfu_validation_activation_prepare() in dfu_validation.c.&lt;/li&gt;
&lt;li&gt;nrf_dfu_validation_activation_prepare() calls postvalidate(),&lt;/li&gt;
&lt;li&gt;which calls&amp;nbsp;fw_hash_ok(), and this takes both the init packet and received data as input. It uses nrf_dfu_validation_hash_ok() and only returns true if the hash of the received firmware matches the hash in the signed init packet (which was validated at the beginning of the DFU process).&lt;/li&gt;
&lt;li&gt;Subsequently, postvalidate_sd_bl() is called, but at that point, the received firmware is already validated as described above.&lt;/li&gt;
&lt;/ul&gt;
[quote user="sjerlhagen"]Are you saying there is ECDSA signature check for the bootloader code at every startup ?[/quote]
&lt;p&gt;No. (But you can optionally do that for the application.)&lt;/p&gt;
[quote user="sjerlhagen"]My concern is with intentional tampering with the bootloader image in a signed DFU package. Before activating the bootloader image it should be authenticated.[/quote]
&lt;p&gt;Absolutely. That is handled by the bootloader.&lt;/p&gt;
[quote user="sjerlhagen"]boot_validation_extract(... index=0, bl_start, bl_len ...)&amp;nbsp; In this function p_init-&amp;gt;boot_validation[0] is still VALIDATE_ECDSA_P256_SHA256, and the signature of the bootloader image is compared to the expected signature of the SD (boot_validation[0].bytes.bytes). This fails.[/quote]
&lt;p&gt;It should not be so. Can you show all the modifications you have done to the bootloader?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Signature on BL updated by DFU</title><link>https://devzone.nordicsemi.com/thread/234995?ContentTypeID=1</link><pubDate>Tue, 18 Feb 2020 16:12:15 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:af5b98f9-3438-47f0-a0c8-afa2b2182fe7</guid><dc:creator>sjerlhagen</dc:creator><description>&lt;p&gt;For a bootloader update I only see the ECDSA signature of the init packet being verified before download, I cant find any verification of the image &lt;br /&gt;(except for verifying CRC for the objects to ensure correct transfer). Are you saying there is ECDSA signature check for the bootloader code at every startup ? My concern is with intentional tampering with the bootloader image in a signed DFU package. Before activating the bootloader image it should be authenticated.&lt;/p&gt;
&lt;p&gt;When I generate a DFU package with the command:&lt;br /&gt;&lt;em&gt;nrfutil pkg generate --key-file private.key --sd-boot-validation VALIDATE_ECDSA_P256_SHA256 --bootloader-version 2 --hw-version 52 --sd-req 0xB7 --softdevice sd.hex --bootloader bl.hex sd_bl.zip&lt;/em&gt;&lt;br /&gt;The binary consist of first SD then BL.&lt;/p&gt;
&lt;p&gt;The entire image is first transfered. Then the SD part is verified:&lt;/p&gt;
&lt;p&gt;boot_validation_extract(... index=0, sd_start, sd_len ...)&amp;nbsp; p_init-&amp;gt;boot_validation[0] = VALIDATE_ECDSA_P256_SHA256 which is what was specified in the init packet. This succeeds.&lt;/p&gt;
&lt;p&gt;10 lines down the BL the BL part is verified:&lt;/p&gt;
&lt;p&gt;boot_validation_extract(... index=0, bl_start, bl_len ...)&amp;nbsp; In this function p_init-&amp;gt;boot_validation[0] is still VALIDATE_ECDSA_P256_SHA256, and the signature of the bootloader image is compared to the expected signature of the SD (boot_validation[0].bytes.bytes). This fails.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Signature on BL updated by DFU</title><link>https://devzone.nordicsemi.com/thread/234911?ContentTypeID=1</link><pubDate>Tue, 18 Feb 2020 12:50:41 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9deeb25c-6bd8-4529-8d19-90a4ec63b036</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
[quote user=""]There doesn&amp;#39;t seem to be any validation of the image when updating the bootloader by secure DFU. nrfutil has no switch to generate any crc or ecdsa_signature. The code uses VALIDATE_CRC, but the expected value is calculated on the received image in boot_validate_extract, so when this is later verified in nrf_dfu_validation_boot_validate the result is always success.[/quote]
&lt;p&gt;You are right that this is not used for the bootloader. That makes sense, though. The key point is that the validation in&amp;nbsp;nrf_dfu_validation_boot_validate() is &lt;em&gt;not&lt;/em&gt; done during the DFU upgrade, but for every boot. There are several ways the bootloader van check&amp;nbsp;(or not check) the validity of the application before deciding to boot it. But there is no corresponding way for the bootloader to check itself, nor would it make much sense. The bootloader image is still checked and the signature must be valid for an update of the bootloader (same as for SoftDevice and application, unless you use the open bootloader).&lt;/p&gt;
[quote user=""]There is also a bug in postvalidate_sd_bl causing the boot validation of BL to always fail for a combined SD+BL image. The second call to boot_validation_extract should have index=1 if there was also a SD in the image.[/quote]
&lt;p&gt;I do not see a problem with index=0, and also it works as expected. Can you elaborate? Note that the&amp;nbsp;bl_start and&amp;nbsp;bl_size variables are adjusted if there is a SD (line 892-893). Is that what you did not spot?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>