Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bootutil: Refactor encrypted.c to have the same logic as image_validate #1658

Conversation

RaphaelDupont
Copy link
Contributor

Currently encrypted.c contains all the implementation of the functions inside enc_key.h for each configuration (RSA, EC256 and X25519).

The purpose of this pr is to adopt a logic similar to the file organization of image_validate to make it easier to add other configurations.

Note:
I'm not satisfied with the current state of fake_rng because it loses its static attribute.
I think putting it in encrypted_priv.h could solve this issue but I'm not sure if it is a good way to solve it.

@RaphaelDupont RaphaelDupont marked this pull request as ready for review March 28, 2023 06:46
@RaphaelDupont RaphaelDupont force-pushed the bootutil-refacto-crypto-usage branch 3 times, most recently from 18ff956 to 77271c3 Compare April 25, 2023 06:58
@de-nordic de-nordic added the crypto Encryption support label May 4, 2023
@RaphaelDupont RaphaelDupont force-pushed the bootutil-refacto-crypto-usage branch 2 times, most recently from 966c014 to 83a3dca Compare May 11, 2023 07:02
Copy link
Collaborator

@davidvincze davidvincze left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for this patch. I think it's really useful.

A few initial comments and:
May I ask you to add the MCUBOOT_ENC_IMAGES and MCUBOOT_ENCRYPT_<...> config macros to the samples/mcuboot_config/mcuboot_config.template.h file with a short description? Thanks.
This is a bit out of the scope of this PR but it kind of belongs here.

boot/bootutil/src/encrypted_priv.h Outdated Show resolved Hide resolved
boot/bootutil/src/encrypted_priv.h Outdated Show resolved Hide resolved
boot/bootutil/src/encrypt_kw.c Outdated Show resolved Hide resolved
boot/bootutil/src/encrypt_misc.c Outdated Show resolved Hide resolved
boot/bootutil/src/encrypt_misc.c Show resolved Hide resolved
boot/bootutil/src/encrypted_priv.h Outdated Show resolved Hide resolved
boot/bootutil/src/encrypted_priv.h Outdated Show resolved Hide resolved
boot/bootutil/src/encrypted.c Outdated Show resolved Hide resolved
boot/bootutil/src/encrypted_priv.h Outdated Show resolved Hide resolved
boot/bootutil/src/encrypt_ec256.c Show resolved Hide resolved
boot/bootutil/src/encrypted_priv.h Show resolved Hide resolved
boot/bootutil/src/encrypt_kw.c Outdated Show resolved Hide resolved
@RaphaelDupont RaphaelDupont force-pushed the bootutil-refacto-crypto-usage branch from 1431ed7 to b64726d Compare June 5, 2023 07:46
Copy link
Collaborator

@davidvincze davidvincze left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the updates!

There is a type in your last commit message, can you update that with a force push?
And please rebase your patches if required.
Sorry, I didn't intend the previous comment as a separate one, but as part of the review.

samples/mcuboot_config/mcuboot_config.template.h Outdated Show resolved Hide resolved
@RaphaelDupont RaphaelDupont force-pushed the bootutil-refacto-crypto-usage branch 2 times, most recently from 43e1315 to 3ec049c Compare June 5, 2023 10:01
Copy link
Collaborator

@davidvincze davidvincze left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the updates.

@davidvincze
Copy link
Collaborator

@nvlsianpu , @de-nordic, espressif and zephyr related files are directly affected (new files introoduced) in this change, could you approve this change if you think it won't cause any build issues?

@de-nordic
Copy link
Collaborator

@nvlsianpu , @de-nordic, espressif and zephyr related files are directly affected (new files introoduced) in this change, could you approve this change if you think it won't cause any build issues?

Let me test that with our code for Zephyr.
We lack espressif expert voice, but this is not unique to this PR, and I do not really know how to address this issue.

@davidvincze
Copy link
Collaborator

@nvlsianpu , @de-nordic, espressif and zephyr related files are directly affected (new files introoduced) in this change, could you approve this change if you think it won't cause any build issues?

Let me test that with our code for Zephyr. We lack espressif expert voice, but this is not unique to this PR, and I do not really know how to address this issue.

I guess we'll definitely have at least some kind of espressif voice if it breaks. 😅

@davidvincze
Copy link
Collaborator

@RaphaelDupont may I ask you to rebase the PR?
New patches have been merged recently and there are conflicting modifications in boot/bootutil/src/encrypted.c.

@RaphaelDupont RaphaelDupont force-pushed the bootutil-refacto-crypto-usage branch 2 times, most recently from 2ef7d40 to d9f6c93 Compare June 12, 2023 14:33
@RaphaelDupont
Copy link
Contributor Author

@RaphaelDupont may I ask you to rebase the PR? New patches have been merged recently and there are conflicting modifications in boot/bootutil/src/encrypted.c.

The branch is now up-to-date.
Do you have other suggestions to make ?
Regarding the way some files are included for example.

@de-nordic de-nordic self-requested a review June 15, 2023 15:44
Copy link
Collaborator

@de-nordic de-nordic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is some squashing needed.
I do not think that we need "bootutil : Reformat code according to suggestions" commits that look like review fixes on main.

@RaphaelDupont RaphaelDupont force-pushed the bootutil-refacto-crypto-usage branch 2 times, most recently from 573b6ce to ae793d4 Compare June 15, 2023 16:12
@RaphaelDupont
Copy link
Contributor Author

There is some squashing needed. I do not think that we need "bootutil : Reformat code according to suggestions" commits that look like review fixes on main.

Done

@RaphaelDupont RaphaelDupont force-pushed the bootutil-refacto-crypto-usage branch 2 times, most recently from 9a3b8e6 to 3e4179a Compare June 28, 2023 08:57
@RaphaelDupont RaphaelDupont force-pushed the bootutil-refacto-crypto-usage branch from 3e4179a to 60ac9d2 Compare July 3, 2023 09:27
@RaphaelDupont
Copy link
Contributor Author

Did you find other issues with this PR ?

@de-nordic
Copy link
Collaborator

I have run encryption and signature tests for ECDSA, RSA and 25519 against latest Zephyr and they seem to boot fine.
I am still trying to run test against sdk-nrf.


if ((rc = mbedtls_asn1_get_tag(p, end, &len,
MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != 0) {
return -1;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No hardcoded errors. Give them defines that can be used by caller.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it can be a subject for an all other PR.
The error values of parse_ec256_enckey are hardcoded but they are also not used.

    rc = parse_ec256_enckey(&cp, cpend, private_key);
    if (rc) {
        return -1;
    }

The EC256 configuration is not the only one affected by this problem.

It would be a good opportinunity to discuss if MCUBoot should define its own error values or just propagate the one
it receives from the crypto module it uses (for example : Mbedtls).

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be a good opportinunity to discuss if MCUBoot should define its own error values or just propagate the one it receives from the crypto module it uses (for example : Mbedtls).

The entire IT industry should figure it out, it is really annoying to be forced to debug where did the -EINVAL comes from, because everything returns it for some reason or an other.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked how parse_ec256_enckey return value is handled on the main branch and the error is propagated when there is one.
So it is a change I made when I did the refactoring...
I reverted this.

Currently encrypted.c contains all the implementation of the
functions inside enc_key.h for each configuration (RSA, EC256
and X25519).

The purpose of this pr is to adopt a logic similar to the
file organization of image_validate to make it easier to
add other confifurations.

Signed-off-by: Raphael Dupont <raphael7dup@gmail.com>
Signed-off-by: Raphael Dupont <raphael7dup@gmail.com>
Signed-off-by: Raphael Dupont <raphael7dup@gmail.com>
@d3zd3z d3zd3z self-requested a review December 14, 2023 15:18
Copy link

This pull request has been marked as stale because it has been open (more than) 60 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this pull request will automatically be closed in 14 days. Note, that you can always re-open a closed pull request at any time.

@github-actions github-actions bot added the stale label Jun 12, 2024
@github-actions github-actions bot closed this Jun 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
crypto Encryption support stale
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants