public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Rasmus Villemoes <ravi@prevas.dk>
To: "Rosenschild, Klaus" <Klaus.Rosenschild@hilti.com>
Cc: "u-boot@lists.denx.de" <u-boot@lists.denx.de>
Subject: Re: AW: secure boot, mkimage with external signing server
Date: Thu, 23 Jan 2025 00:27:23 +0100	[thread overview]
Message-ID: <87v7u6v38k.fsf@prevas.dk> (raw)
In-Reply-To: <VI1PR07MB997209D177C705DD5371F0D6F7E12@VI1PR07MB9972.eurprd07.prod.outlook.com> (Klaus Rosenschild's message of "Wed, 22 Jan 2025 21:13:56 +0000")

On Wed, Jan 22 2025, "Rosenschild, Klaus" <Klaus.Rosenschild@hilti.com> wrote:

> Hi Rasmus,
> thank you for pointing to this solution.
> I think this is the best way to do this.
>
> However, our signing server is very well protected and making changes there is a long and complex process.
> Right now, it only provides the following two functions:
>
>   1.
> generation of a signature of a sha256 hash using the private key
>   2.
> providing the public key, the pure key, not the certificate
>
> I found a workaround to determine the hash that mkimage uses to create the signature of the configuration without re-implementing the internal algorithm that mkimage uses:
>
>   1.
> create a temporary rsa private and public key
>   2.
> run mkimage to create a FIT image with signature: mkimage -k keys-f fitImage-sign-orig.its -r fitImage-sign
>   3.
> extract the signature from the FIT image
>   4.
> re-generate the hash from the signature and the public key: openssl pkeyutl -verifyrecover -in signFile.hash.sign.bin -pubin -inkey ../keys/build.pub -asn1parse
>   5.
> now, I can send the hash to the signing server, get the correct signature back and re-enter it into the FIT image (e.g. via python libfdt)
>

Urgh, it shouldn't be that complicated, and I would consider it quite
reasonable if mkimage could be instructed to emit the hash it actually
signs along with the signature.

But, I do think you should be able to create a pkcs#11 module which
simply takes that sha256 as input from the higher layers and does
whatever it needs to do to talk to the server, getting the signature
back.

> However, there is now another problem. I also need to put the public key into the device tree file. So, I have to run a slightly different mkimage command (with  -K option):
> mkimage -k keys -f fitImage-sign-orig.its -r -K bcm2711-rpi-4-b.dtb fitImage-sign
>
> However, the -K options requires a certificate and not just the
> public.

Yeah, that is a fundamental design flaw of mkimage; one shouldn't need
to sign any image in order to get the public key data embedded in
u-boot's control dtb.

Fortunately, you can ignore what most tutorials tell you about that -K
option. There is a simple script in the u-boot repo, tools/key2dtsi.py,
which you can apply to just the public key, and you get a .dtsi fragment
that you can include when you build u-boot's control dtb. Either you can
use the CONFIG_DEVICE_TREE_INCLUDES mechanism for making sure that .dtsi
gets picked up during build, or you can simply copy-paste the contents
into your board's .dts file.

Rasmus

  reply	other threads:[~2025-01-22 23:27 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <VI1PR07MB9972394B8A364AC9A18495F6F7192@VI1PR07MB9972.eurprd07.prod.outlook.com>
     [not found] ` <VI1PR07MB9972E22550B1514AD604D399F7192@VI1PR07MB9972.eurprd07.prod.outlook.com>
2025-01-20 17:43   ` secure boot, mkimage with external signing server Rosenschild, Klaus
2025-01-21  9:28     ` Rasmus Villemoes
2025-01-21 17:47       ` AW: " Rosenschild, Klaus
2025-01-22 21:13       ` Rosenschild, Klaus
2025-01-22 23:27         ` Rasmus Villemoes [this message]
2025-01-23  9:00           ` AW: " Rosenschild, Klaus
2025-01-25 17:11           ` Simon Glass

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=87v7u6v38k.fsf@prevas.dk \
    --to=ravi@prevas.dk \
    --cc=Klaus.Rosenschild@hilti.com \
    --cc=u-boot@lists.denx.de \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox