extmod/modssl_mbedtls: Add SSLContext methods.#13098
Conversation
|
Code size report: |
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## master #13098 +/- ##
==========================================
+ Coverage 98.36% 98.39% +0.02%
==========================================
Files 159 159
Lines 20989 21063 +74
==========================================
+ Hits 20646 20724 +78
+ Misses 343 339 -4 ☔ View full report in Codecov by Sentry. |
|
TODO:
|
a692340 to
df1612d
Compare
|
@dpgeorge checking mbedtls$ rg vrfy_buf
programs/x509/cert_app.c
331: char vrfy_buf[512];
335: mbedtls_x509_crt_verify_info(vrfy_buf, sizeof(vrfy_buf), " ! ", flags);
337: mbedtls_printf("%s\n", vrfy_buf);
programs/ssl/ssl_mail_client.c
195: char vrfy_buf[512];
201: mbedtls_x509_crt_verify_info(vrfy_buf, sizeof(vrfy_buf), " ! ", flags);
203: mbedtls_printf("%s\n", vrfy_buf);
programs/ssl/ssl_client1.c
207: char vrfy_buf[512];
213: mbedtls_x509_crt_verify_info(vrfy_buf, sizeof(vrfy_buf), " ! ", flags);
215: mbedtls_printf("%s\n", vrfy_buf);
programs/ssl/dtls_client.c
236: char vrfy_buf[512];
242: mbedtls_x509_crt_verify_info(vrfy_buf, sizeof(vrfy_buf), " ! ", flags);
244: mbedtls_printf("%s\n", vrfy_buf);
programs/ssl/ssl_server2.c
3431: char vrfy_buf[512];
3434: x509_crt_verify_info(vrfy_buf, sizeof(vrfy_buf), " ! ", flags);
3436: mbedtls_printf("%s\n", vrfy_buf);
3489: char vrfy_buf[512];
3493: x509_crt_verify_info(vrfy_buf, sizeof(vrfy_buf), " ! ", flags);
3494: mbedtls_printf("%s\n", vrfy_buf);
programs/ssl/ssl_client2.c
2347: char vrfy_buf[512];
2350: x509_crt_verify_info(vrfy_buf, sizeof(vrfy_buf),
2353: mbedtls_printf("%s\n", vrfy_buf);Other than this I will consider this PR done so let me know what you think 👍🏼 |
349ec17 to
4c9c285
Compare
|
Regarding the
|
512 bytes is a lot of stack space to allocate. It's not critical for the error message to fit, even if it's truncated at least it gives a good indication of the problem. I suggest using 256. That's a good balance of stack usage and available space for the error. Otherwise, it could be implemented using dynamically allocated memory. |
10b8c29 to
87233ce
Compare
This commit adds: 1) Methods to SSLContext class that match CPython signature: - `SSLContext.load_cert_chain(certfile, keyfile)` - `SSLContext.load_verify_locations(cafile=, cadata=)` - `SSLContext.get_ciphers()` --> ["CIPHERSUITE"] - `SSLContext.set_ciphers(["CIPHERSUITE"])` 2) `sslsocket.cipher()` to get current ciphersuite and protocol version. 3) `ssl.MBEDTLS_VERSION` string constant. 4) Certificate verification errors info instead of `MBEDTLS_ERR_X509_CERT_VERIFY_FAILED`. 5) Tests in `net_inet` and `multi_net` to test these new methods. `SSLContext.load_cert_chain` method allows loading key and cert from disk passing a filepath in `certfile` or `keyfile` options. `SSLContext.load_verify_locations`'s `cafile` option enables the same functionality for ca files. Signed-off-by: Carlos Gil <[email protected]>
Running `./do-esp32.sh` now generates this esp32_mbedtls_errors.c file, with IDF v5.0.4. Signed-off-by: Damien George <[email protected]>
To match other ports that use mbedtls. Signed-off-by: Damien George <[email protected]>
|
This looks good now. I have adjusted some of the tests so they pass on bare-metal targets (tested stm32 and esp32). Thanks @Carglglz for all of your hard work on this, and replying promptly to all of the many code reviews! |
This commit adds:
Methods to SSLContext class that match CPython signature:
SSLContext.load_cert_chain(certfile, keyfile)SSLContext.load_verify_locations(cafile=, cadata=)SSLContext.get_ciphers()--> ["CIPHERSUITE"]SSLContext.set_ciphers(["CIPHERSUITE"])sslsocket.cipher()to get current ciphersuite and protocolversion.
ssl.MBEDTLS_VERSIONstring constantCertificate verification errors info instead of
MBEDTLS_ERR_X509_CERT_VERIFY_FAILEDTests in
net_inetandmulti_netSSLContext.load_cert_chainmethod allows loading key and cert from disk passing a filepath incertfileorkeyfileoptions.SSLContext.load_verify_locations'scafileoption enables the same functionality for ca files.This may close #10832 , #9071 and #8915