From: Jerome Forissier <jerome.forissier@linaro.org>
To: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Cc: u-boot@lists.denx.de, Tom Rini <trini@konsulko.com>,
Joe Hershberger <joe.hershberger@ni.com>,
Ramon Fried <rfried.dev@gmail.com>,
Simon Glass <sjg@chromium.org>,
Heinrich Schuchardt <xypron.glpk@gmx.de>,
Mattijs Korpershoek <mkorpershoek@baylibre.com>,
Ibai Erkiaga <ibai.erkiaga-elorza@amd.com>,
Michal Simek <michal.simek@amd.com>,
Adriano Cordova <adrianox@gmail.com>
Subject: Re: [PATCH v2 4/6] net: lwip: add support for built-in root certificates
Date: Mon, 10 Mar 2025 14:48:31 +0100 [thread overview]
Message-ID: <db313ea7-8132-4fdd-bd7c-6c42feb03215@linaro.org> (raw)
In-Reply-To: <CAC_iWj+FEusnb8jSkGSyLyjcM8ejJELtc1+swsTK6JKQ1+NG2w@mail.gmail.com>
On 3/10/25 14:04, Ilias Apalodimas wrote:
> On Mon, 10 Mar 2025 at 14:48, Jerome Forissier
> <jerome.forissier@linaro.org> wrote:
>>
>>
>>
>> On 3/10/25 13:38, Ilias Apalodimas wrote:
>>> On Mon, 10 Mar 2025 at 14:13, Jerome Forissier
>>> <jerome.forissier@linaro.org> wrote:
>>>>
>>>>
>>>>
>>>> On 3/10/25 12:52, Ilias Apalodimas wrote:
>>>>> Hi Jerome,
>>>>>
>>>>> [...]
>>>>>
>>>>>
>>>>>>>>
>>>>>>>> +#if CONFIG_IS_ENABLED(WGET_BUILTIN_CACERT)
>>>>>>>> + cacert_initialized = true;
>>>>>>>> +#endif
>>>>>>>> return CMD_RET_SUCCESS;
>>>>>>>> }
>>>>>>>> +
>>>>>>>> +#if CONFIG_IS_ENABLED(WGET_BUILTIN_CACERT)
>>>>>>>> +static int set_cacert_builtin(void)
>>>>>>>> +{
>>>>>>>> + return _set_cacert(builtin_cacert, builtin_cacert_size);
>>>>>>>> +}
>>>>>>>> #endif
>>>>>>>>
>>>>>>>> +#if CONFIG_IS_ENABLED(WGET_CACERT)
>>>>>>>> +static int set_cacert(char * const saddr, char * const ssz)
>>>>>>>> +{
>>>>>>>> + ulong addr, sz;
>>>>>>>> +
>>>>>>>> + addr = hextoul(saddr, NULL);
>>>>>>>> + sz = hextoul(ssz, NULL);
>>>>>>>> +
>>>>>>>> + return _set_cacert((void *)addr, sz);
>>>>>>>> +}
>>>>>>>> +#endif
>>>>>>>> +#endif /* CONFIG_WGET_CACERT || CONFIG_WGET_BUILTIN_CACERT */
>>>>>>>> +
>>>>>>>> static int wget_loop(struct udevice *udev, ulong dst_addr, char *uri)
>>>>>>>> {
>>>>>>>> #if CONFIG_IS_ENABLED(WGET_HTTPS)
>>>>>>>> @@ -373,8 +401,15 @@ static int wget_loop(struct udevice *udev, ulong dst_addr, char *uri)
>>>>>>>> memset(&conn, 0, sizeof(conn));
>>>>>>>> #if CONFIG_IS_ENABLED(WGET_HTTPS)
>>>>>>>> if (is_https) {
>>>>>>>> - char *ca = cacert;
>>>>>>>> - size_t ca_sz = cacert_size;
>>>>>>>> + char *ca;
>>>>>>>> + size_t ca_sz;
>>>>>>>> +
>>>>>>>> +#if CONFIG_IS_ENABLED(WGET_BUILTIN_CACERT)
>>>>>>>> + if (!cacert_initialized)
>>>>>>>> + set_cacert_builtin();
>>>>>>>> +#endif
>>>>>>>
>>>>>>> The code and the rest of the patch seems fine, but the builtin vs
>>>>>>> downloaded cert is a bit confusing here.
>>>>>>> Since the built-in cert always gets initialized in the wget loop it
>>>>>>> would overwrite any certificates that are downloaded in memory?
>>>>>>
>>>>>> The built-in certs are enabled only when cacert_initialized is false.
>>>>>> set_cacert_builtin() will set it to true (via _set_cacert()), so it will
>>>>>> happen only once. Note also that any successful "wget cacert" command
>>>>>> will also do the same. So effectively these two lines enable the
>>>>>> built-in certificates by default, that's all they do.
>>>>>
>>>>> Ok, so if you download a cert in memory and have u-boot with a builtin
>>>>> certificate, then the memory one will be overwritten in the first run.
>>>>
>>>> No, because the downloaded cert must have be made active via "wget cacert
>>>> <addr> <size>", which will set cacert_initialized to true, and thus the
>>>> built-in certs won't overwrite them. Or did I miss something?
>>>
>>> Nop I did, when reading the patch. But should the command that clears
>>> the downloaded cert set cacert_initialized; to false now?
>>
>> It's probably easier if it does not, so that "wget cacert 0 0" really clears
>> the certs. We have a command to restore the built-in ones ("wget cacert
>> builtin").
>
> So right now if a user defines a builtin cert it will be used on the
> first download.
Yes.
> If after that he defines a memory one, that will be
> used on the next download,
Yes.
> but if he unloads it shouldn't the built in
> be restired automatically?
If he unloads with "wget cacert 0 0" then it means clear certificates, so no,
the builtin should not be restored IMO. To restore them one needs to run
"wget cacert builtin".
I think it is cleaner to keep the same meaning for "wget cacert 0 0" whether or
not builtin certificates are enabled. It's a matter of consistency.
Thanks,
--
Jerome
>
> Thanks
> /Ilias
>>
>> Thanks,
>> --
>> Jerome
>>
>>>
>>> Thanks
>>> /Ilias
>>>>
>>>> Cheers,
>>>> --
>>>> Jerome
>>>>
>>>>> This is not easy to solve, I was trying to think of ways to make the
>>>>> functionality clearer to users.
>>>>>
>>>>> Cheers
>>>>> /Ilias
>>>>>>
>>>>>> Cheers,
>>>>>> --
>>>>>> Jerome
>>>>>>
>>>>>>>
>>>>>>> [...]
>>>>>>>
>>>>>>> Cheers
>>>>>>> /Ilias
next prev parent reply other threads:[~2025-03-10 13:48 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-05 14:26 [PATCH v2 0/6] net: lwip: root certificates Jerome Forissier
2025-03-05 14:26 ` [PATCH v2 1/6] net: lwip: extend wget to support CA (root) certificates Jerome Forissier
2025-03-05 15:07 ` Heinrich Schuchardt
2025-03-05 15:13 ` Jerome Forissier
2025-03-09 10:58 ` Ilias Apalodimas
2025-03-09 11:00 ` Ilias Apalodimas
2025-03-10 8:08 ` Jerome Forissier
2025-03-10 11:49 ` Ilias Apalodimas
2025-03-10 12:10 ` Jerome Forissier
2025-03-05 14:26 ` [PATCH v2 2/6] lwip: tls: enforce checking of server certificates based on CA availability Jerome Forissier
2025-03-05 14:26 ` [PATCH v2 3/6] lwip: tls: warn when no CA exists amd log certificate validation errors Jerome Forissier
2025-03-05 14:26 ` [PATCH v2 4/6] net: lwip: add support for built-in root certificates Jerome Forissier
2025-03-09 11:33 ` Ilias Apalodimas
2025-03-10 8:05 ` Jerome Forissier
2025-03-10 11:52 ` Ilias Apalodimas
2025-03-10 12:12 ` Jerome Forissier
2025-03-10 12:38 ` Ilias Apalodimas
2025-03-10 12:48 ` Jerome Forissier
2025-03-10 13:04 ` Ilias Apalodimas
2025-03-10 13:48 ` Jerome Forissier [this message]
2025-03-10 13:57 ` Ilias Apalodimas
2025-03-05 14:26 ` [PATCH v2 5/6] doc: cmd: wget: document cacert subcommand Jerome Forissier
2025-03-09 11:34 ` Ilias Apalodimas
2025-03-05 14:26 ` [PATCH v2 6/6] configs: qemu_arm64_lwip_defconfig: enable WGET_CACERT Jerome Forissier
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=db313ea7-8132-4fdd-bd7c-6c42feb03215@linaro.org \
--to=jerome.forissier@linaro.org \
--cc=adrianox@gmail.com \
--cc=ibai.erkiaga-elorza@amd.com \
--cc=ilias.apalodimas@linaro.org \
--cc=joe.hershberger@ni.com \
--cc=michal.simek@amd.com \
--cc=mkorpershoek@baylibre.com \
--cc=rfried.dev@gmail.com \
--cc=sjg@chromium.org \
--cc=trini@konsulko.com \
--cc=u-boot@lists.denx.de \
--cc=xypron.glpk@gmx.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