All of lore.kernel.org
 help / color / mirror / Atom feed
From: sven.schultschik@siemens.com
To: cip-dev@lists.cip-project.org
Cc: jan.kiszka@siemens.com, Sven Schultschik <sven.schultschik@siemens.com>
Subject: [isar-cip-core][PATCH 8/8] no merge - manually instructions test secure boot
Date: Mon, 24 Oct 2022 14:27:25 +0200	[thread overview]
Message-ID: <20221024122725.383791-9-sven.schultschik@siemens.com> (raw)
In-Reply-To: <20221024122725.383791-1-sven.schultschik@siemens.com>

From: Sven Schultschik <sven.schultschik@siemens.com>

This patch is not ment for merge but shows how to generally test the implementation of the optee and rpmb driven secure boot qemu setup.

Signed-off-by: Sven Schultschik <sven.schultschik@siemens.com>
---
 README.md                                     |  65 ++++++++++++++++++
 keys/helloworld.efi                           | Bin 0 -> 4576 bytes
 recipes-bsp/u-boot/files/secure-boot.cfg.tmpl |   2 +-
 start-qemu.sh                                 |   3 +-
 4 files changed, 68 insertions(+), 2 deletions(-)
 create mode 100644 keys/helloworld.efi

diff --git a/README.md b/README.md
index e30ff3a63..6aa3f7d19 100644
--- a/README.md
+++ b/README.md
@@ -55,6 +55,71 @@ or via bmap-tools
 
     bmaptool copy build/tmp/deploy/images/bbb/cip-core-image-cip-core-buster-bbb.wic.img /dev/<medium-device>
 
+## Running Secure Boot Target Images and test it
+Create a folder named `keys` if not exist and within this folder create the signing keys and db
+
+```bash
+#PK
+openssl req -x509 -sha256 -newkey rsa:2048 -subj /CN=SIEMENS_TEST_PK/ -keyout PK.key -out PK.crt -nodes -days 365
+cert-to-efi-sig-list -g 11111111-2222-3333-4444-123456789abc PK.crt PK.esl
+sign-efi-sig-list -c PK.crt -k PK.key PK PK.esl PK.auth
+
+# KEK
+openssl req -x509 -sha256 -newkey rsa:2048 -subj /CN=SIEMENS_TEST_KEK/ -keyout KEK.key -out KEK.crt -nodes -days 365
+cert-to-efi-sig-list -g 11111111-2222-3333-4444-123456789abc KEK.crt KEK.esl
+sign-efi-sig-list -c PK.crt -k PK.key KEK KEK.esl KEK.auth
+
+# db
+openssl req -x509 -sha256 -newkey rsa:2048 -subj /CN=SIEMENS_TEST_db/ -keyout db.key -out db.crt -nodes -days 365
+cert-to-efi-sig-list -g 11111111-2222-3333-4444-123456789abc db.crt db.esl
+sign-efi-sig-list -c KEK.crt -k KEK.key db db.esl db.auth
+```
+
+Put an bootable `.efi` file in it or use the `helloworld.efi` provided and sign it.
+
+```
+sbsign --key db.key --cert db.crt helloworld.efi
+```
+
+The `start-qemu.sh` has additional `-hdb fat:rw:keys` added with this patch to mount the `keys` folder.
+
+Start the qemu with following command
+
+```
+FIRMWARE_BIN=./build/tmp/deploy/images/qemu-arm64/flash.bin ./start-qemu.sh aarch64
+```
+
+In this test patch there is as well the possibility added to stop in the u-boot. So if you see a 5 sec timer ticking press Enter to stop.
+
+Now add the keys to the environment my typing
+
+```
+fatload virtio 1:1 40000000 PK.auth
+setenv -e -nv -bs -rt -at -i 40000000:$filesize PK
+fatload virtio 1:1 40000000 KEK.auth
+setenv -e -nv -bs -rt -at -i 40000000:$filesize KEK
+fatload virtio 1:1 40000000 db.auth
+setenv -e -nv -bs -rt -at -i 40000000:$filesize db
+```
+> The address 40000000 depends on your DRAM setup. You can check with `bdinfo`
+
+> $filesize is set by fatload
+
+### Boot signed efi binary
+
+```
+fatload virtio 1:1 40000000 helloworld.efi.signed
+  
+bootefi 40000000 ${fdtcontroladdr}
+```
+
+### Try same binary but unsigned
+This should fail with `Image not authenticated. Loading image failed`
+```
+fatload virtio 1:1 40000000 helloworld.efi
+ 
+bootefi 40000000 ${fdtcontroladdr}
+```
 
 ## Community Resources
 
diff --git a/keys/helloworld.efi b/keys/helloworld.efi
new file mode 100644
index 0000000000000000000000000000000000000000..c021d94ae576271f1f472bd2e5f380ed1830a2ff
GIT binary patch
literal 4576
zcmeHKYfKbZ6h1SvJSx^Kg7`w6;o+lE>w`Af8X2%q+e(Xoefa|rRv{uFPz#|cL$D1A
ziD9CqO=~TtHE}mhYK@xOmxv~9Q<GY>r2V(h{ve?bDWy6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ot/files/secure-boot.cfg.tmpl b/recipes-bsp/u-boot/files/secure-boot.cfg.tmpl
index 8e6428238..63d73f70a 100644
--- a/recipes-bsp/u-boot/files/secure-boot.cfg.tmpl
+++ b/recipes-bsp/u-boot/files/secure-boot.cfg.tmpl
@@ -1,5 +1,5 @@
 ### Secure boot config
-CONFIG_BOOTDELAY=-2
+CONFIG_BOOTDELAY=5
 CONFIG_USE_BOOTCOMMAND=y
 CONFIG_BOOTCOMMAND="setenv scan_dev_for_boot 'if test -e ${devtype} ${devnum}:${distro_bootpart} efi/boot/boot${EFI_ARCH}.efi; then load ${devtype} ${devnum}:${distro_bootpart} ${kernel_addr_r} efi/boot/boot${EFI_ARCH}.efi; bootefi ${kernel_addr_r} ${fdtcontroladdr}; fi'; run distro_bootcmd; echo 'EFI Boot failed!'; sleep 1000; reset"
 CONFIG_EFI_VARIABLES_PRESEED=y
diff --git a/start-qemu.sh b/start-qemu.sh
index 18946a6c9..ac73d8d3b 100755
--- a/start-qemu.sh
+++ b/start-qemu.sh
@@ -179,7 +179,8 @@ if [ -n "${SECURE_BOOT}${SWUPDATE_BOOT}" ]; then
 			${QEMU_PATH}${QEMU} \
 				-drive file=${IMAGE_PREFIX}.wic,discard=unmap,if=none,id=disk,format=raw \
 				-bios ${u_boot_bin} \
-				${QEMU_COMMON_OPTIONS} "$@"
+				${QEMU_COMMON_OPTIONS} "$@" \
+				-hdb fat:rw:keys
 			;;
 		*)
 			echo "Unsupported architecture: ${arch}"
-- 
2.30.2



  parent reply	other threads:[~2022-10-24 12:29 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-24 12:27 [isar-cip-core][PATCH 0/8] Secureboot on QEMU with EDK2, OP-TEE and RPBM sven.schultschik
2022-10-24 12:27 ` [isar-cip-core][PATCH 1/8] add recipe for edk2 sven.schultschik
2022-10-25  8:23   ` Su, Bao Cheng
2022-10-26 14:44     ` AW: " Schultschik, Sven
2022-10-27  1:39       ` Su, Bao Cheng
2022-10-27 16:14         ` AW: " Schultschik, Sven
2022-10-27 17:08           ` Jan Kiszka
2022-10-25  8:40   ` Su, Bao Cheng
2022-10-24 12:27 ` [isar-cip-core][PATCH 2/8] add recipe for optee qemu arm64 sven.schultschik
2022-10-24 12:27 ` [isar-cip-core][PATCH 3/8] Include optee into u-boot sven.schultschik
2022-10-26  7:36   ` Su, Bao Cheng
2022-10-26  8:52     ` Jan Kiszka
2022-10-26 15:27       ` AW: " Schultschik, Sven
2022-10-26 16:00         ` Jan Kiszka
2022-11-07 16:57           ` AW: " Schultschik, Sven
2022-11-07 17:50             ` Jan Kiszka
2022-11-10 11:01               ` AW: " Schultschik, Sven
2022-11-10 13:38                 ` Jan Kiszka
2022-10-24 12:27 ` [isar-cip-core][PATCH 4/8] add u-boot patch for qemu to support RPMB sven.schultschik
2022-10-24 12:27 ` [isar-cip-core][PATCH 5/8] add recipe for trusted firmware a qemu arm64 sven.schultschik
2022-10-28  5:50   ` Jan Kiszka
2022-10-28 15:46     ` AW: " Schultschik, Sven
2022-10-28 19:10       ` Jan Kiszka
2022-10-24 12:27 ` [isar-cip-core][PATCH 6/8] add kas files for building qemu secure boot images sven.schultschik
2022-10-27 17:17   ` Jan Kiszka
2022-11-07 10:43     ` AW: " Schultschik, Sven
2022-11-07 12:59       ` Jan Kiszka
2022-10-24 12:27 ` [isar-cip-core][PATCH 7/8] enhance start-qemu.sh for arm64 secure boot sven.schultschik
2022-10-24 12:27 ` sven.schultschik [this message]
2022-10-25  8:36   ` [isar-cip-core][PATCH 8/8] no merge - manually instructions test " Su, Bao Cheng
2022-10-25 15:23     ` AW: " Schultschik, Sven
2022-10-25  8:09 ` [isar-cip-core][PATCH 0/8] Secureboot on QEMU with EDK2, OP-TEE and RPBM Su, Bao Cheng
2022-10-25  8:16   ` Jan Kiszka

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221024122725.383791-9-sven.schultschik@siemens.com \
    --to=sven.schultschik@siemens.com \
    --cc=cip-dev@lists.cip-project.org \
    --cc=jan.kiszka@siemens.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.