-
Notifications
You must be signed in to change notification settings - Fork 7.4k
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
Certificate bundle upgrade (IDFGH-12148) #13204
Conversation
…/esp-idf into crt_bundle_upgrade # Conflicts: # components/mbedtls/esp_crt_bundle/esp_crt_bundle.c # components/mbedtls/esp_crt_bundle/gen_crt_bundle.py
👋 Hello BitsForPeople, we appreciate your contribution to this project! 📘 Please review the project's Contributions Guide for key guidelines on code, documentation, testing, and more. 🖊️ Please also make sure you have read and signed the Contributor License Agreement for this project. Click to see more instructions ...
Review and merge process you can expect ...
|
Hello @BitsForPeople, It looks like you have made some changes in the |
Hello @Harshal5 . |
@BitsForPeople Also I think we could squash the three commits into one. You could follow the below steps:
Let me know in case you feel this is a bit complicated, I would be happy to help you by carrying this out myself. |
@Harshal5, thank you for providing the steps. Didn't work unfortunately, been having issues with git on my (Windows) machine for some time. |
sha=c38b75fa31b2861ff8a037597c7abd2b05a5b7e1 |
// Issuers are in DER encoding, with lengths encoded in the content; if valid DER, differing lengths | ||
// are reflected in differing content. | ||
// Still, we won't try to memcmp beyond the given length: | ||
int cmp_res = memcmp(issuer, esp_crt_get_name(cert), min(issuer_len, cert_name_len) ); | ||
|
||
if ( unlikely( cmp_res == 0 ) ) { | ||
cmp_res = (int)issuer_len - cert_name_len; | ||
if( likely( cmp_res >= 0 ) ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @BitsForPeople, could you please explain why we allow the issuer name to be longer than the found certificate name? Do you have any example wherein this would be needed?
We think due to this, an incorrect certificate could get matched if the name of another certificate is a prefix of the name of the certificate we're looking for. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @Harshal5.
I'm actually not sure anymore why I did a >= 0 here, t.b.h. Specifically, I can't remember seeing a case where this would be needed.
Reviewing it now, I believe you are right: If one cert's name would be a prefix of another cert's name in a bundle, we might (in theory) pick the wrong cert.
I think changing it to == 0 should work.
Sorry for seemingly not getting back to this PR until now. I spent a few hours trying to fix the issue of the unrelated mbedtls files in the PR but could not for the life of me get my working tree back to a consistent state with a clean PR.
Is there something you can do with the PR on your end?
Modified gen_crt_bundle.py and esp_crt_bundle.c to build/use a static 'index' of the certificates in a bundle and include this index data in the bundle data.
This obviates the need for esp_crt_bundle.c to allocate heap memory and build the index at runtime, saving ~120x4 bytes of heap for the full/'unfiltered' bundle.
Changed "mbedtls_x509_crt parent" in esp_crt_check_signature() to "mbedtls_pk_context pubkey" to save some 200 bytes of stack requirement.