<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://test-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>decoupling the placement of public key in mcuboot and signing the image</title><link>https://test-devzone.nordicsemi.com/f/nordic-q-a/88105/decoupling-the-placement-of-public-key-in-mcuboot-and-signing-the-image</link><description>Hi Nordic providers of solutions to problems great and small. 
 Good mornings. 
 We have been going through the OTA/DFU process for a signed image as the final step of our product and noticed some awkwardness in the nRF Connect SDK work flow for image</description><dc:language>en-US</dc:language><generator>Telligent Community 13 Non-Production</generator><lastBuildDate>Wed, 11 May 2022 14:43:23 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://test-devzone.nordicsemi.com/f/nordic-q-a/88105/decoupling-the-placement-of-public-key-in-mcuboot-and-signing-the-image" /><item><title>RE: decoupling the placement of public key in mcuboot and signing the image</title><link>https://test-devzone.nordicsemi.com/thread/368668?ContentTypeID=1</link><pubDate>Wed, 11 May 2022 14:43:23 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:520e870c-e2c9-4be0-8b52-2af44f9222d4</guid><dc:creator>user72692</dc:creator><description>[quote user="daviddedwin"]&lt;span style="text-decoration:underline;"&gt;A. Question&lt;/span&gt; : We should be able use imgtool,py to get the C struct for the ECDSA key type, Is that correct ?[/quote]
&lt;p&gt;Yes, take a look at&amp;nbsp;&lt;a title="https://developer.nordicsemi.com/nrf_connect_sdk/doc/1.9.1/mcuboot/imgtool.html" href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/1.9.1/mcuboot/imgtool.html" rel="noopener noreferrer" target="_blank"&gt;./scripts/imgtool.py getpub -k filename.pem&lt;/a&gt;&amp;nbsp;and my colleagues &lt;a href="https://github.com/hellesvik-nordic/samples_for_nrf_connect_sdk/tree/main/bootloader_samples/mcuboot_manual_sign"&gt;sample and guide&lt;/a&gt;. In the last link, it generates an RSA key type, but as you can see, imgtool supports&amp;nbsp;ecdsa types as well:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;Simon@Simons_PC MINGW64 /c/v1.8.0/bootloader/mcuboot/scripts ((v1.8.99-ncs1))
$ python imgtool.py keygen -h
Usage: imgtool.py keygen [OPTIONS]

  Generate pub/private keypair

Options:
  -k, --key filename  [required]
  -t, --type type     One of: rsa-2048, rsa-3072, ecdsa-p256, ecdsa-p224,
                      ed25519, x25519  [required]

  -p, --password      Prompt for password to protect key
  -h, --help          Show this message and exit.&lt;/pre&gt;&lt;/p&gt;
[quote user="daviddedwin"]&lt;span style="text-decoration:underline;"&gt;B. Question&lt;/span&gt;: How do we manually place this in the build and ensure that it is not overwritten by the existing work flow which is autogenerating the keys ?[/quote]
&lt;p&gt;There are many ways to do this. If you follow the approach here &lt;a href="https://test-devzone.nordicsemi.com/f/nordic-q-a/80629/decouple-mcuboot-public-key-storage-and-image-signing-nrf9160-mcuboot"&gt;https://devzone.nordicsemi.com/f/nordic-q-a/80629/decouple-mcuboot-public-key-storage-and-image-signing-nrf9160-mcuboot&lt;/a&gt;,you will remove the code that places the public key C struct in the build, and replace it with your own (which uses your custom API to get the ), so it will not be overwritten by the work flow.&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;Another approach (that is a little cleaner) I just thought of now is the following:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Modify these lines &lt;a href="https://github.com/nrfconnect/sdk-mcuboot/blob/v1.8.99-ncs1/boot/zephyr/keys.c#L34"&gt;https://github.com/nrfconnect/sdk-mcuboot/blob/v1.8.99-ncs1/boot/zephyr/keys.c#L34&lt;/a&gt;&amp;nbsp;and &lt;a href="https://github.com/nrfconnect/sdk-mcuboot/blob/v1.8.99-ncs1/boot/zephyr/keys.c#L58-L59"&gt;https://github.com/nrfconnect/sdk-mcuboot/blob/v1.8.99-ncs1/boot/zephyr/keys.c#L58-L59&lt;/a&gt;&amp;nbsp;and swap &lt;code&gt;ecdsa_pub_key&lt;/code&gt; with &lt;code&gt;my_custom_ecdsa_pub_key&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;&lt;/code&gt;Modify the CMakeLists.txt of you application to include src/my_custom_pub_key.c&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;Check out &lt;a href="https://test-devzone.nordicsemi.com/guides/nrf-connect-sdk-guides/b/getting-started/posts/nrf-connect-sdk-tutorial---part-2-ncs-v1-4-0#h9skdynelh91f6vt6g1cw90uq4xtu0j"&gt;https://devzone.nordicsemi.com/guides/nrf-connect-sdk-guides/b/getting-started/posts/nrf-connect-sdk-tutorial---part-2-ncs-v1-4-0#h9skdynelh91f6vt6g1cw90uq4xtu0j&lt;/a&gt;&amp;nbsp; how to do this&lt;/li&gt;
&lt;li&gt;Don&amp;#39;t create my_custom_pub_key.c, since this will be generated when asking for it&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Then get the public key, using your custom API, and place it into &amp;lt;your sample&amp;gt;/src
&lt;ul&gt;
&lt;li&gt;It should be named my_custom_pub_key.c (same as the one used in CMakeLists.txt)&lt;/li&gt;
&lt;li&gt;It should contain a struct containing the public key, of the name my_custom_ecdsa_pub_key&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Then you build your sample, and your public key should be used&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;There might be better ways of going about it, so please share if you find a better/cleaner approach&lt;/p&gt;
[quote user="daviddedwin"]&lt;span style="text-decoration:underline;"&gt;C. Question&lt;/span&gt; : How do we manually sign the unsigned image with imgtool to get a signed image and what are the options to be used for it. The ECDSA keys also seem to have padding issues to be dealt with. The correct options to give to imgtool appear important.[/quote]
&lt;p&gt;To be honest, I have not worked too much with this before (keys, encryption and so on), my expertise&amp;nbsp;lies in mcuboot/dfu updates.&amp;nbsp;However, have you taken a look at&amp;nbsp;&lt;a href="https://github.com/nrfconnect/sdk-nrf/blob/v1.9.1/modules/mcuboot/CMakeLists.txt#L291-L300"&gt;https://github.com/nrfconnect/sdk-nrf/blob/v1.9.1/modules/mcuboot/CMakeLists.txt#L291-L300&lt;/a&gt;&amp;nbsp;and tried using the same arguments. If you don&amp;#39;t get this to work,&amp;nbsp;please let me know, and I will take a deeper look&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Simon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: decoupling the placement of public key in mcuboot and signing the image</title><link>https://test-devzone.nordicsemi.com/thread/368667?ContentTypeID=1</link><pubDate>Tue, 10 May 2022 18:46:36 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:bc8f25fb-1726-4be3-9009-bac702fa5e91</guid><dc:creator>user72692</dc:creator><description>&lt;p&gt;Okay, I understand. I will look into and try to answer your questions tomorrow.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Simon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: decoupling the placement of public key in mcuboot and signing the image</title><link>https://test-devzone.nordicsemi.com/thread/368666?ContentTypeID=1</link><pubDate>Tue, 10 May 2022 15:14:00 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a5e70e12-099b-4a44-aa63-f365feb92c2d</guid><dc:creator>user84049</dc:creator><description>&lt;p&gt;Yes, your understanding is reasonable. I broke it out iinto specific questions where additional input was requested.&lt;/p&gt;
&lt;p&gt;Thanks&lt;br /&gt;David&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: decoupling the placement of public key in mcuboot and signing the image</title><link>https://test-devzone.nordicsemi.com/thread/368665?ContentTypeID=1</link><pubDate>Mon, 09 May 2022 14:02:26 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:df85dec1-36b8-4003-b4bf-e4da85ad2dc1</guid><dc:creator>user72692</dc:creator><description>[quote user="daviddedwin"]We cannot use the automated key gen in the nRF connect SDK environment as that puts the private key into the build and increases the probability of a leak.[/quote]
&lt;p&gt;If you follow the steps in&amp;nbsp;the referred ticket,&amp;nbsp;this will not be the case. Before answering your questions, let me make sure we&amp;#39;re on the same page. If you follow the steps in&amp;nbsp;&lt;a href="https://test-devzone.nordicsemi.com/f/nordic-q-a/80629/decouple-mcuboot-public-key-storage-and-image-signing-nrf9160-mcuboot"&gt;Decouple MCUBoot public key storage and image signing (nrf9160 + MCUBoot)&lt;/a&gt;, you will end up with this:&lt;/p&gt;
&lt;p&gt;&lt;img alt=" " src="https://test-devzone.nordicsemi.com/resized-image/__size/600x450/__key/communityserver-discussions-components-files/4/key_5F00_decoupling.png" /&gt;&lt;/p&gt;
&lt;p&gt;This seems exactly what you&amp;#39;re asking for. The key generation is decoupled from the application development, and the public key will be put in the correct location automatically.&lt;/p&gt;
&lt;p&gt;Could you clarify if I have misunderstood something&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Simon&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: decoupling the placement of public key in mcuboot and signing the image</title><link>https://test-devzone.nordicsemi.com/thread/368664?ContentTypeID=1</link><pubDate>Wed, 04 May 2022 14:06:11 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6efc5f78-6cd4-4bbe-a113-f677fac71302</guid><dc:creator>user84049</dc:creator><description>&lt;p&gt;&lt;span style="font-size:150%;"&gt;We cannot use the automated key gen in the nRF connect SDK environment as that puts the private key into the build and increases the probability of a leak.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size:150%;text-decoration:underline;"&gt;This is what I have proposed for the decoupling:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size:150%;"&gt;1. The core team will generate a private key and public key pair.&amp;nbsp;&lt;br /&gt;The resulting key file with the public key will be used&amp;nbsp; to generate the C Struct for the public key.&lt;br /&gt;I guess we will have to manually place this C struct in the right location and also modify the build so that it does not get overwritten. &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size:150%;"&gt;&lt;span style="text-decoration:underline;"&gt;A. Question&lt;/span&gt; : We should be able use imgtool,py to get the C struct for the ECDSA key type, Is that correct ?&lt;br /&gt;&lt;br /&gt;&lt;span style="text-decoration:underline;"&gt;B. Question&lt;/span&gt;: How do we manually place this in the build and ensure that it is not overwritten by the existing work flow which is autogenerating the keys ?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size:150%;"&gt;==&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size:150%;"&gt;2. The C struct file containing the public key is delivered by the core team to the development team.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size:150%;"&gt;3. The C struct file is placed in the mcuboot build manually and the hex file is delivered to the factory for programming.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size:150%;"&gt;4. The updates to the product are built by the development team&amp;nbsp; and an unsigned image(bin) is generated and delivered to the core team.&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size:150%;"&gt;5. The core team signs the image and delivers a signed image to the update process through the mobile apps for OTA to the products on the field.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size:150%;"&gt;&lt;span style="text-decoration:underline;"&gt;C. Question&lt;/span&gt; : How do we manually sign the unsigned image with imgtool to get a signed image and what are the options to be used for it. The ECDSA keys also seem to have padding issues to be dealt with. The correct options to give to imgtool appear important.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size:150%;"&gt;Guidance on questions A, B and C are useful.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size:150%;"&gt;Thanks for the support&lt;br /&gt;David&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size:150%;"&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: decoupling the placement of public key in mcuboot and signing the image</title><link>https://test-devzone.nordicsemi.com/thread/368663?ContentTypeID=1</link><pubDate>Wed, 04 May 2022 12:28:59 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3a672fb6-fb69-4242-81cf-f9582b4df436</guid><dc:creator>user72692</dc:creator><description>[quote user=""]&lt;p&gt;&lt;span style="font-size:150%;"&gt;I did look at the case below but its solution was a bit hazy.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size:150%;"&gt;&lt;strong&gt;&lt;a href="https://test-devzone.nordicsemi.com/f/nordic-q-a/80629/decouple-mcuboot-public-key-storage-and-image-signing-nrf9160-mcuboot"&gt;https://devzone.nordicsemi.com/f/nordic-q-a/80629/decouple-mcuboot-public-key-storage-and-image-signing-nrf9160-mcuboot&lt;/a&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size:150%;"&gt;Placing the C struct of the public key into the keys.c&lt;/span&gt;&lt;/p&gt;[/quote]
&lt;p&gt;This happens automatically by the current build system. What I wrote under &amp;quot;&lt;span style="text-decoration:underline;"&gt;How it currently works&lt;/span&gt;&amp;quot; is how the build system automatically signs images (and generates the public key and places it inside keys.c). What I wrote under &amp;quot;&lt;span style="text-decoration:underline;"&gt;How to modify it to get signed externally&lt;/span&gt;&amp;quot; is what you have to do in order to decouple the image signing.&lt;/p&gt;
&lt;p&gt;This was written 7 months ago, so keep in mind that there may have happen some changes since then.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Simon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>