-
-
Notifications
You must be signed in to change notification settings - Fork 8.2k
multi_net: Increase asyncio tests timeouts. #12370
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
Conversation
3eb2115
to
0789e15
Compare
Codecov Report
@@ Coverage Diff @@
## master #12370 +/- ##
==========================================
- Coverage 98.38% 98.38% -0.01%
==========================================
Files 158 158
Lines 20900 20933 +33
==========================================
+ Hits 20563 20595 +32
- Misses 337 338 +1
|
It may be a certificate time validation issue? Does any test sync/check device local time? To figure out verification failure reason could you test #11897? with |
Yes I set the time from ntp on both nodes, still no luck. |
Weird, well here are the current x509 verify codes: in /**
* \name X509 Verify codes
* \{
*/
/* Reminder: update x509_crt_verify_strings[] in library/x509_crt.c */
#define MBEDTLS_X509_BADCERT_EXPIRED 0x01 /**< The certificate validity has expired. */
#define MBEDTLS_X509_BADCERT_REVOKED 0x02 /**< The certificate has been revoked (is on a CRL). */
#define MBEDTLS_X509_BADCERT_CN_MISMATCH 0x04 /**< The certificate Common Name (CN) does not match with the expected CN. */
#define MBEDTLS_X509_BADCERT_NOT_TRUSTED 0x08 /**< The certificate is not correctly signed by the trusted CA. */
#define MBEDTLS_X509_BADCRL_NOT_TRUSTED 0x10 /**< The CRL is not correctly signed by the trusted CA. */
#define MBEDTLS_X509_BADCRL_EXPIRED 0x20 /**< The CRL is expired. */
#define MBEDTLS_X509_BADCERT_MISSING 0x40 /**< Certificate was missing. */
#define MBEDTLS_X509_BADCERT_SKIP_VERIFY 0x80 /**< Certificate verification was skipped. */
#define MBEDTLS_X509_BADCERT_OTHER 0x0100 /**< Other reason (can be used by verify callback) */
#define MBEDTLS_X509_BADCERT_FUTURE 0x0200 /**< The certificate validity starts in the future. */
#define MBEDTLS_X509_BADCRL_FUTURE 0x0400 /**< The CRL is from the future */
#define MBEDTLS_X509_BADCERT_KEY_USAGE 0x0800 /**< Usage does not match the keyUsage extension. */
#define MBEDTLS_X509_BADCERT_EXT_KEY_USAGE 0x1000 /**< Usage does not match the extendedKeyUsage extension. */
#define MBEDTLS_X509_BADCERT_NS_CERT_TYPE 0x2000 /**< Usage does not match the nsCertType extension. */
#define MBEDTLS_X509_BADCERT_BAD_MD 0x4000 /**< The certificate is signed with an unacceptable hash. */
#define MBEDTLS_X509_BADCERT_BAD_PK 0x8000 /**< The certificate is signed with an unacceptable PK alg (eg RSA vs ECDSA). */
#define MBEDTLS_X509_BADCERT_BAD_KEY 0x010000 /**< The certificate is signed with an unacceptable key (eg bad curve, RSA too short). */
#define MBEDTLS_X509_BADCRL_BAD_MD 0x020000 /**< The CRL is signed with an unacceptable hash. */
#define MBEDTLS_X509_BADCRL_BAD_PK 0x040000 /**< The CRL is signed with an unacceptable PK alg (eg RSA vs ECDSA). */
#define MBEDTLS_X509_BADCRL_BAD_KEY 0x080000 /**< The CRL is signed with an unacceptable key (eg bad curve, RSA too short). */
/** \} name X509 Verify codes */ It will be interesting to see which ones of these are |
I can enable the verbose output and double check, will get around to it later. |
Increase asyncio tests timeouts to account for different WiFi modules and CPU clocks on different boards. Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
0789e15
to
3637252
Compare
I tested this on PYBD's for 30 minutes and all there were no failures (disregarding SSL and UDP tests). |
@Carglglz the |
@iabdalkader did you try #11897 ? The macro is only useful there. It should enable additional error info when the error is @@ -394,8 +533,29 @@ STATIC mp_obj_t ssl_socket_make_new(mp_obj_ssl_context_t *ssl_context, mp_obj_t
return MP_OBJ_FROM_PTR(o);
cleanup:
+ #ifdef MICROPY_SSL_MBEDTLS_EXTRAS
+ if (ret == MBEDTLS_ERR_X509_CERT_VERIFY_FAILED) {
+ flags = mbedtls_ssl_get_verify_result(&o->ssl);
+ }
+ #endif
+
o->sock = MP_OBJ_NULL;
mbedtls_ssl_free(&o->ssl);
+
+ #ifdef MICROPY_SSL_MBEDTLS_EXTRAS
+ if (ret == MBEDTLS_ERR_X509_CERT_VERIFY_FAILED) {
+ char xcbuf[512];
+ ret = mbedtls_x509_crt_verify_info(xcbuf, sizeof(xcbuf), "\n", flags);
+ // The length of the string written (not including the terminated nul byte),
+ // or a negative err code.
+ if (ret > 0) {
+ mp_raise_ValueError(MP_ERROR_TEXT(xcbuf));
+ } else {
+ mbedtls_raise_error(ret);
+ }
+ }
+ #endif
+
mbedtls_raise_error(ret);
}
The functions are cleanup:
if (ret == MBEDTLS_ERR_X509_CERT_VERIFY_FAILED) {
uint32_t flags = mbedtls_ssl_get_verify_result(&o->ssl);
}
o->sock = MP_OBJ_NULL;
mbedtls_ssl_free(&o->ssl);
if (ret == MBEDTLS_ERR_X509_CERT_VERIFY_FAILED) {
char xcbuf[512];
ret = mbedtls_x509_crt_verify_info(xcbuf, sizeof(xcbuf), "\n", flags);
// The length of the string written (not including the terminated nul byte),
// or a negative err code.
if (ret > 0) {
mp_raise_ValueError(MP_ERROR_TEXT(xcbuf));
}
}
mbedtls_raise_error(ret); |
This reminds me of this at #11896
mbedtls expects UNIX epoch time, but I guess that's already fixed in 0bc2968 Also the error only happens with |
No only With your patches I see that it's a certificate time validation issue:
Could it simply be that the certificate in the test did actually expire ? It's supposed to be valid for 1 year. |
Yep, if I set the time to ntp (year -1) it passes the test 🤦🏼 |
Ah that would be it, actually @dpgeorge bumped into the same issue , I did update the certs in #11897 to be at least 5 years I think 😓 here is the new version 👍🏼 https://github.com/micropython/micropython/blob/f1bee31dc8d2ecdbf125af5905c7f1c676c0f162/tests/multi_net/ssl_cert_rsa.py |
@Carglglz Thank you! Can you please also fix those typos: diff --git a/tests/multi_net/ssl_cert_rsa.py b/tests/multi_net/ssl_cert_rsa.py
index 872855edb..7e4b2ec05 100644
--- a/tests/multi_net/ssl_cert_rsa.py
+++ b/tests/multi_net/ssl_cert_rsa.py
@@ -14,11 +14,11 @@ PORT = 8000
# testing/demonstration only. You should always generate your own key/cert.
# To generate a new self-signed key/cert pair with openssl do:
-# $ openssl req -x509 -newkey rsa:4096 -keyout rsa_key.pem -out rsa_cert.pem -days 365 -node
+# $ openssl req -x509 -newkey rsa:4096 -keyout rsa_key.pem -out rsa_cert.pem -days 365 -nodes
#
# Convert them to DER format:
# $ openssl rsa -in rsa_key.pem -out rsa_key.der -outform DER
-# $ openssl x509 -in rsa_cert.pem -out rsa_key.der -outform DER
+# $ openssl x509 -in rsa_cert.pem -out rsa_cert.der -outform DER
#
# Then convert to hex format, eg using binascii.hexlify(data).``` |
@iabdalkader Done in #12387 , Thanks! |
Increase asyncio tests timeouts to account for different WiFi modules and CPU clocks on different boards.
This improves the tests pass rate, however
multi_net/asyncio_tcp_readall.py
still occasionally fail with a timeout:Also
ssl_cert_rsa.py
fails withMBEDTLS_ERR_X509_CERT_VERIFY_FAILED
I tested with multiple combinations of boards, Arduino Portenta-H7, C33 and PYBD_SF2.