<?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>Decouple MCUBoot public key storage and image signing (nrf9160 + MCUBoot)</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/80629/decouple-mcuboot-public-key-storage-and-image-signing-nrf9160-mcuboot</link><description>Hi, 
 I&amp;#39;m investigating firmware image signing on the nrf9160 using MCUBoot and the nRF Connect SDK v17. I have configured 
 
 and it seems to work via `west build -b nrf9160dk_nrf9160ns -s myapp` 
 
 For production however I don&amp;#39;t want to keep my private</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 14 Oct 2021 15:56:53 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/80629/decouple-mcuboot-public-key-storage-and-image-signing-nrf9160-mcuboot" /><item><title>RE: Decouple MCUBoot public key storage and image signing (nrf9160 + MCUBoot)</title><link>https://devzone.nordicsemi.com/thread/334223?ContentTypeID=1</link><pubDate>Thu, 14 Oct 2021 15:56:53 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:782f8f5d-2a71-4d47-a0dd-a2d13fcaac63</guid><dc:creator>Simon</dc:creator><description>&lt;p&gt;It does not seem like this is supported at the moment, but you should be able to achieve this by modifying NCS&lt;/p&gt;
&lt;p&gt;&lt;span style="text-decoration:underline;"&gt;How it currently works&lt;/span&gt;&lt;/p&gt;
&lt;div&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span&gt;&lt;span&gt;Assume the following command is used to build the project&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;span&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="text"&gt;west build -b nrf52dk_nrf52840 hello_world -- -DCONFIG_BOOTLOADER_MCUBOOT=y -Dmcuboot_CONFIG_BOOT_SIGNATURE_KEY_FILE=\&amp;quot;mcuboot_private.pem\&amp;quot; -Dmcuboot_CONFIG_BOOT_ENCRYPT_RSA=n -Dmcuboot_CONFIG_BOOT_SIGNATURE_TYPE_RSA=y -Dmcuboot_CONFIG_BOOT_SIGNATURE_TYPE_ECDSA_P256=n&lt;/pre&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span&gt;app_update.bin is signed &lt;/span&gt;&lt;span&gt;in&lt;/span&gt;&lt;span&gt; nrf/modules/mcuboot/CMakeLists.txt&lt;/span&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="https://github.com/nrfconnect/sdk-nrf/blob/b05e8ab5c4e0fc7531027aaf10c48841dd64d7d0/modules/mcuboot/CMakeLists.txt#L219"&gt;Get CONFIG_BOOT_SIGNATURE_KEY_FILE&lt;/a&gt;&amp;nbsp;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/nrfconnect/sdk-nrf/blob/b05e8ab5c4e0fc7531027aaf10c48841dd64d7d0/modules/mcuboot/CMakeLists.txt#L241-L250"&gt;Sign app_update.bin&lt;/a&gt;&amp;nbsp;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;The public key is generated &lt;span&gt;in&lt;/span&gt;&lt;span&gt; bootloader/mcuboot/boot/zephyr/CMakeLists.txt&lt;/span&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="https://github.com/nrfconnect/sdk-mcuboot/blob/7606d9cad32c95a0d6fb7e872b070c71e85f931d/boot/zephyr/CMakeLists.txt#L275-L281"&gt;Get CONFIG_BOOT_SIGNATURE_KEY_FILE&lt;/a&gt;&amp;nbsp;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/nrfconnect/sdk-mcuboot/blob/7606d9cad32c95a0d6fb7e872b070c71e85f931d/boot/zephyr/CMakeLists.txt#L292-L303"&gt;Generate public key autogen-pubkey.c&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;The key will be placed &lt;span&gt;in&lt;/span&gt;&lt;em&gt; zephyr/samples/hello_world/build/mcuboot/zephyr/autogen-pubkey.c&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;If RSA is used, It looks like this: &lt;code&gt;const unsigned char rsa_pub_key[] = {0x30, 0x82, 0x01...&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;The public key is &lt;span&gt;then&lt;/span&gt;&lt;span&gt; integrated into mcuboot&lt;/span&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a title="'extern const .. rsa_pub_key' is set in bootloader/mcuboot/boot/zephyr/keys.c" href="https://github.com/nrfconnect/sdk-mcuboot/blob/7606d9cad32c95a0d6fb7e872b070c71e85f931d/boot/zephyr/keys.c#L34"&gt;&lt;code&gt;extern const .. rsa_pub_key&lt;/code&gt; is &lt;span&gt;set&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;in&lt;/span&gt;&lt;span&gt; bootloader/mcuboot/boot/zephyr/keys.c&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/nrfconnect/sdk-mcuboot/blob/7606d9cad32c95a0d6fb7e872b070c71e85f931d/boot/zephyr/keys.c#L55"&gt;&lt;span&gt;bootutil_keys.key is &lt;/span&gt;&lt;span&gt;set&lt;/span&gt;&lt;span&gt; to rsa_pub_key &lt;/span&gt;&lt;span&gt;in&lt;/span&gt;&lt;span&gt; bootloader/mcuboot/boot/zephyr/keys.c&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;p&gt;&lt;span style="text-decoration:underline;"&gt;How to modify it to get signed externally&lt;/span&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;In nrf/modules/mcuboot/CMakeLists.txt, modify &lt;a href="https://github.com/nrfconnect/sdk-nrf/blob/b05e8ab5c4e0fc7531027aaf10c48841dd64d7d0/modules/mcuboot/CMakeLists.txt#L241-L250"&gt;sign_cmd&lt;/a&gt;, and use a custom python&amp;nbsp;script instead of imgtool.py. The custom python&amp;nbsp;script should connect to the server, provide it with the bin/hex file and get the signed file in return.&lt;/li&gt;
&lt;li&gt;In bootloader/mcuboot/boot/zephyr/CMakeLists.txt, modify &lt;a href="https://github.com/nrfconnect/sdk-mcuboot/blob/7606d9cad32c95a0d6fb7e872b070c71e85f931d/boot/zephyr/CMakeLists.txt#L292-L303"&gt;these lines&lt;/a&gt;. Use a custom python script, that will get the public key from the application folder and generate&amp;nbsp;&lt;span&gt;autogen-pubkey.c&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;I am by no means an expert on CMake, and it will probably be more difficult to implement this than described above. But now you know how it works and where stuff happens, and what files you need to modify&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>