-
Notifications
You must be signed in to change notification settings - Fork 832
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
Add wolfSSL esp-tls and Certificate Bundle Support #7936
Add wolfSSL esp-tls and Certificate Bundle Support #7936
Conversation
Jenkins retest this please |
|
||
/* Returns ESP_OK if there are no zero serial numbers in the bundle, | ||
* OR there may be zeros, but */ | ||
static CB_INLINE int wolfssl_found_zero_serial() |
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.
wolfssl_found_zero_serial(void)
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.
good catch. added void
* 0 if the cert has a non-zero serial number | ||
* < 0 for error wolfssl\wolfcrypt\error-crypt.h values */ | ||
static CB_INLINE int wolfssl_is_zero_serial_number(const uint8_t *der_cert, | ||
int sz) { |
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.
Brace on new line
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.
Missed that one; moved and aligned params
{ | ||
char stringVaue[X509_MAX_SUBJECT_LEN]; | ||
#ifdef WOLFSSL_DEBUG_CERT_BUNDLE | ||
char before_str[32]; |
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.
Maybe use CTC_DATE_SIZE
instead of hard coded 32?
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.
Yes, good idea. added.
#endif /* WOLFSSL_DEBUG_CERT_BUNDLE && WOLFSSL_DEBUG_IGNORE_ASN_TIME */ | ||
|
||
#ifdef CONFIG_WOLFSSL_DEBUG_CERT_BUNDLE | ||
void print_cert_subject_and_issuer(WOLFSSL_X509_STORE_CTX* store) { |
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.
Brace new line. Move int i
declaration to top of function
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.
done. Also added NULL check for store
.
* We'll proceed by assiging `cert` to each of the respective items in | ||
* bundle as we attempt to find the desired cert: */ | ||
if (ret == WOLFSSL_SUCCESS) { | ||
_cert_bundled_loaded = 1; |
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.
I see where this is set but not where it is used.
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.
This is intended for end users. Added wolfssl_cert_bundle_loaded()
to file: esp_crt_bundle.h
.
Also renamed removed stray middle 'd' from _cert_bundled_loaded
.
WOLFSSL_X509_STORE_CTX* store) | ||
{ | ||
#ifdef WOLFSSL_DEBUG_CERT_BUNDLE | ||
char before_str[32]; |
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.
Maybe CTC_DATE_SIZE
instead of 32?
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.
Ah yes, good idea. Added.
child = crt; | ||
|
||
#if 0 | ||
/* It's OK for a trusted cert to have a weak signature hash alg. |
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.
Dead code? Does this need to be here still?
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.
No need. Removed.
int middle =0; | ||
size_t name_len = 0; | ||
size_t key_len = 0; | ||
bool crt_found = false; |
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.
Don't use bool
or true/false
. Use int
and 1/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.
Changed.
int ret = -1; | ||
int start = 0; | ||
int end = 0; | ||
int middle =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.
Nit: Space after =
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.
Yes, always appreciated, fixed. I also updated the order.
e478203
to
808cced
Compare
Retest this please. Scan-build timeout |
808cced
to
ac57452
Compare
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.
Approved. Over to PR cap.
Known issues:Here are some key points in addition to the new PlatformIOUpdate / clarification: Although the esp-tls is fully supported in the Espressif ESP-IDF with this PR, including Certificate Bundles, using the PlatformIO with the Certificate Bundles is not supported at this time. Other It appears the problem in the PlatformIO environment is that they have their own build system: similar but different than the build system used in
Here's a similar problem, not involving wolfSSL: https://community.platformio.org/t/esp-idf-new-project-build-error/23858/2 A workaround is to either disable Bundle Support, or select Use the PlatformIO
This is only a problem with PlatformIO. I'll be working on alternatives that will be included in a possible future PR. PlatformIO Python
|
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.
there's one whitespace infraction (inline-commented).
also you might want to fix up some overlong lines:
overlong lines added:
wolfcrypt/src/port/Espressif/esp_crt_bundle/esp_crt_bundle.c:489 ESP_LOGCBI(TAG, "Failed to extract subject or issuer at index %d\n", i);
wolfcrypt/src/port/Espressif/esp_crt_bundle/esp_crt_bundle.c:784 ESP_LOGCBV(TAG, "Item = %d; start: %d, end: %d", middle, start, end );
wolfssl/wolfcrypt/port/Espressif/esp_crt_bundle.h:30 * https://docs.espressif.com/projects/esp-idf/en/stable/esp32/api-reference/protocols/esp_tls.html
wolfssl/wolfcrypt/port/Espressif/esp_crt_bundle.h:62 * Attach and enable use of a bundle for certificate verification through a verification callback.
wolfssl/wolfcrypt/port/Espressif/esp_crt_bundle.h:63 * If no specific bundle has been set through esp_crt_bundle_set() it will default to the
wolfssl/wolfcrypt/port/Espressif/esp_crt_bundle.h:66 * Note this must be visibile for both the regular bundles, as well as the "none" option.
wolfssl/wolfcrypt/port/Espressif/esp_crt_bundle.h:73 * - Other if an error occured or an action must be taken by the calling process.
(the line numbers may not match exactly, because the test was on a rebase.)
|
||
## Getting Started | ||
|
||
Use the `idf.py menuconfig`, |
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.
trailing whitespace on this line
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.
eek. I usually don't need to worry about trailing whitespace. today I needed to edit my "ignore pattern". May have been an added feature in recent update in Visual Studio:
Otherwise, I completely missed the long lines. Good catch! I've updated the code. There's one extra file this time around, oddly a space missing between two words in a different README.md
file.
ac57452
to
fac7cd6
Compare
fac7cd6
to
3f23b17
Compare
I've applied quite a lot of updates since the original PR from a couple of week ago & squashed commits . The changes address some things that came about while testing on various flavors of ESP32. In particular, the entire RSA math HW has been overhauled to have improved. There's also some new metrics. A memory leak was found and corrected. There's still a memory leak with the ESP32-C2 http example as-found in v5.2 that is only manifested in continual loops (see test app). The problem is not in any of the changes in this PR, nor even any part of wolfSSL. This has been tested on the 8 different ESP32 flavors (classic,C2(ESP8684)/C3,C6,S2,S3,S6). There's a known issue with ESP8266 config related to #8015. There's a known problem with the ESP32-C2 WiFi. See espressif/esp-idf#11703 (comment):
|
I've applied code review changes & have tests re-running on all 8 of 9 devices. The ESP8266 remains problematic, somewhat related to these changes, but only with regards to default application settings. Reminder: There's no planned support for wolfSSL in the esp-tls layer of the ESP8266 RTOS Software Development Kit at this time. We could have a fork that supports it if needed. Not sure what the long term plans are for that ESP8266 SDK. Today, there's only full support of wolfSSL in the esp-tls layer in my v5.2.2 fork. I've not yet created an ESP-IDF upstream PR. Lastest PlatformIO release is still v5.2.2.20240904b The Espressif ESP-IDF v5.2.3 was released yesterday. Additional, separate implementations and PRs will be needed for each Espressif ESP-IDF version: 5.0, 5.1, etc. References and NotesMy next planned update is for v5.3.1. Edit: See my_531 See gojimmypi/esp-idf#1 regarding building an ESP-IDF release for PlatformIO. It is not very intuitive. See also my https://github.com/gojimmypi/github-actions/tree/release_idf mentioned in that discussion. Edit: Reminder for PlatformIO release as noted in gojimmypi/esp-idf#1 (comment):
For instance: https://github.com/gojimmypi/esp-idf/releases/tag/v5.3.1.20240925a created with gojimmypi/esp-idf@f656a0c (although it should be ~70 MB, not 1.6 GB) Edit: See gojimmypi/esp-idf#1 (comment) regarding the oversized release. The workflow file needed to be updated like this:
Note in particular it points to Documentation to more clearly explain this process is currently WIP, but should generally be found in the README.md of each respective custom ESP-IDF branch. |
Jenkins retest this please. |
* to be utilized by the Espressif ESP-IDF, specifically the esp-tls layer. | ||
* | ||
* See: | ||
* https://docs.espressif.com/projects/esp-idf/en/stable/esp32/api-reference/protocols/esp_tls.html |
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.
Maybe this link could go in the documentation or manual rather than in the main wolfssl bundle. The site looks hosted in Poland which is okayish for some users, but the certificate on the site has CN listed as the country.
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.
I found 59 instances of docs.espressif.com
in 49 files.
I'll remove or change the links in this PR.
Ok to have a separate PR for the remainder or would you prefer they are included here?
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.
Update: a total of 112 instances in 72 files that reference espressif.com
in a comment.
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.
Update[2]: a total of 206 instances in 102 files, if including README.md
files in addition to *.c
and *.h
files.
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.
separate PR's is ok
Thanks @JacobBarthelmeh for the code review. Some excellent ideas. See my dev branch for these changes. Once Jenkins is happy, I'll squash the commits in this PR. |
dd7d301
to
2a35490
Compare
All ESP32 devices passing wolfssl_test on my test jig. The ESP8266 failure was indeed just a config issue, needing #define FP_MAX_BITS MIN_FFDHE_FP_MAX_BITS. The esp-tls layer is still not supported on the ESP8266, but at least now the project file compiles and works as before. My updates to examples will be in a separate PR. |
…ls-cert-bundle Add wolfSSL esp-tls and Certificate Bundle Support
…ls-cert-bundle Add wolfSSL esp-tls and Certificate Bundle Support
Description
Part of espressif/esp-idf#13966, this PR adds support for Certificate Bundles as used in the Espressif esp-tls layer.
There are currently no local wolfSSL examples that utilize this new functionality. I have an example app as well as required modifications needed to the ESP-IDF in my v5.2.2 branch of the ESP-IDF.
Related to:
Further information can be found in the included
wolfcrypt/src/port/Espressif/esp_crt_bundle/README.md
file.The enclosed
cacrt_all.pem
,cacrt_deprecated.pem
, andcacrt_local.pem
files are copies of those file used by the mbedtls/esp_crt_bundle and should ideally be kept in sync with subsequent updates to the ESP-IDF.Additional PR submissions coming soon will include updates to the
KConfig
andCMakeLists.txt
files for existing wolfSSL examples. See my components/wolfssl for WIP.My intention is to have common component files for all examples with settings controlled primarily by
KConfig
andsdkconfig.default
files. The main reference source will be the template example.Fixes zd#
Does not fix, but see related related tickets including 18469 and 18228.
Testing
How did you test?
Tested only in Espressif environment and a quick
make clean && make
Checklist