All of lore.kernel.org
 help / color / mirror / Atom feed
From: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
To: Claudius Heine <ch@denx.de>, Tim Harvey <tharvey@gateworks.com>,
	Marek Vasut <marex@denx.de>
Cc: Peng Fan <peng.fan@nxp.com>, Fabio Estevam <festevam@denx.de>,
	open list <u-boot@lists.denx.de>,
	"NXP i.MX U-Boot Team" <uboot-imx@nxp.com>
Subject: Re: [PATCH] imx: hab: add documentation about the required keys/certs
Date: Thu, 16 May 2024 11:50:11 +0200	[thread overview]
Message-ID: <aa29ae8a-ca23-4139-8d8b-e56ae0e6b8eb@prevas.dk> (raw)
In-Reply-To: <ac57d92f-5f75-47fe-b2d5-5f633290b030@denx.de>

On 16/05/2024 10.25, Claudius Heine wrote:
> Hi Tim and Marek,
> 
> On 2024-05-16 12:46 am, Tim Harvey wrote:
>> On Tue, May 14, 2024 at 11:50 AM Tim Harvey <tharvey@gateworks.com>
>> wrote:
>>> On Sun, May 12, 2024 at 10:08 PM Marek Vasut <marex@denx.de> wrote:
>>>> On 5/8/24 9:23 AM, Claudius Heine wrote:
>>>>> On 2024-05-07 3:28 pm, Marek Vasut wrote:
>>>>>> It would be good to mention the DT properties which govern the crypto
>>>>>> material paths -- nxp,srk-table, nxp,csf-crt, nxp,img-crt --
>>>>>> somewhere
>>>>>> around this sentence.
>>>>>
>>>>> This is something that should be documented with the changes where
>>>>> that
>>>>> code was added, IMO. I only documented here what I found out and have
>>>>> used myself, I haven't used those.
>>>>>
>>>>> I would be interested in reading how to best overwrite those paths and
>>>>> the image structured from board u-boot.dtsi files myself.
>>>>>
>>>>> If you want to can pickup my patch and integrate it into your
>>>>> series and
>>>>> extend it.
>>>>
>>>> I'll keep it in mind for V3.
>>
>> Hi Marek,
>>
>> The documentation patch here by Claudius does resolve my issues
>> discussed in the other thread and I can confirm symlinks work fine so
>> I think something like the following should be added:
>>
>> CST_DIR=/usr/src/cst-3.3.2/
>> ln -s $CST_DIR/crts .
>> ln -s $CST_DIR/keys .
> 
> `keys` and `crts` are very short and generic names, and putting them
> into the build directory might cause issues at some point. But I would
> not be against putting them into a sub directory (`imx-hab/{keys,crts}`?).

It is probably useful to be aware of the quality of the cst code. For
reference, I quote get_key_file()

int32_t get_key_file(const char* cert_file, char* key_file)
{
    /* Algorithm to locate key file from given cert file  */
    /* for now just assume the key to present in the      */
    /* same folder as cert file. The crt in the name will */
    /* will be replaced with key */
    char * folder;
    int32_t i = strlen(cert_file);  /**< Index into key filename,
initialized
                                         to filename length */

    strcpy(key_file, cert_file);
    key_file[i] = 0;

    key_file[i-5] = 'y';
    key_file[i-6] = 'e';
    key_file[i-7] = 'k';

    /* Search for folder name "certs" in the file and replace it with
"keys" */
    /* Keys are found in "keys" folder and certs are in "certs" folder
    */

    folder = strstr(key_file, "crts");
    if(folder)
    {
        folder[0] = 'k';
        folder[1] = 'e';
        folder[2] = 'y';
        folder[3] = 's';
    }
    return CAL_SUCCESS;
}

Ignoring the inconsistencies in the comments, obviously there are a lot
of implicit assumptions on file names and paths. First, the assumption
that the filename of they key corresponding to the certificate can be
obtained by replacing [-7:-5] by "key". Second, and much more egregious,
is the use of strstr() on key_file searching for "crts", and just
blindly replacing the first such with "keys", and ignoring it if not
found. So if that string appears anywhere in the path (say, my homedir
is /home/dcrts/ and I have the key material somewhere below that) this
will replace the wrong occurrence (and look in /home/dkeys/ ....).

And of course it was unthinkable that this could have been written using
the much shorter memcpy(..., "keys", 4) so that one could actually `git
grep 'keys'` and figure out what was going on.

Rasmus


  reply	other threads:[~2024-05-16  9:50 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-03  1:05 [PATCH v2 1/4] binman: Add nxp_imx8mcst etype for i.MX8M flash.bin signing Marek Vasut
2024-05-03  1:05 ` [PATCH v2 2/4] ARM: dts: imx: Introduce SPL and FIT labels to i.MX8M DTs binman nodes Marek Vasut
2024-05-03  1:05 ` [PATCH v2 3/4] ARM: dts: imx: Wrap i.MX8M binman SPL and FIT nodes in CST node if IMX_HAB enabled Marek Vasut
2024-05-03  1:05 ` [PATCH v2 4/4] imx: hab: Use nxp_imx8mcst etype for i.MX8M flash.bin signing Marek Vasut
2024-05-14 18:34   ` Tim Harvey
2024-05-14 20:23     ` Marek Vasut
2024-05-15 22:16       ` Tim Harvey
2024-05-15 22:31       ` Tim Harvey
2024-05-16  1:53         ` Marek Vasut
2024-05-16 15:31           ` Tim Harvey
2024-05-06 11:52 ` [PATCH v2 1/4] binman: Add " Francesco Dolcini
2024-05-06 15:21   ` Marek Vasut
2024-05-07 13:06 ` [PATCH] imx: hab: add documentation about the required keys/certs Claudius Heine
2024-05-07 13:28   ` Marek Vasut
2024-05-08  7:23     ` Claudius Heine
2024-05-13  3:46       ` Marek Vasut
2024-05-14 18:50         ` Tim Harvey
2024-05-15 22:46           ` Tim Harvey
2024-05-16  8:25             ` Claudius Heine
2024-05-16  9:50               ` Rasmus Villemoes [this message]
2024-05-16 11:27                 ` Claudius Heine
2024-05-16  8:36   ` [PATCH v2] " Claudius Heine
2024-05-18  8:30     ` Heinrich Schuchardt
2024-05-24 16:27     ` Fabio Estevam

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=aa29ae8a-ca23-4139-8d8b-e56ae0e6b8eb@prevas.dk \
    --to=rasmus.villemoes@prevas.dk \
    --cc=ch@denx.de \
    --cc=festevam@denx.de \
    --cc=marex@denx.de \
    --cc=peng.fan@nxp.com \
    --cc=tharvey@gateworks.com \
    --cc=u-boot@lists.denx.de \
    --cc=uboot-imx@nxp.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.