summaryrefslogtreecommitdiffstatshomepage
path: root/tests/multi_net
Commit message (Collapse)AuthorAge
* tests/multi_net: Add test for DTLS server and client.Damien George2025-02-14
| | | | | | | | | | | | | This adds a multi-test for DTLS server and client behaviour. It works on all ports that enable this feature (eg unix, esp32, rp2, stm32), but bare-metal ports that use lwIP are not reliable as the DTLS server because the lwIP bindings only support queuing one UDP packet at a time (that needs to be fixed). Also, to properly implement a DTLS server sockets need to support `socket.recvfrom(n, MSG_PEEK)`. That can be implemented in the future. Signed-off-by: Damien George <damien@micropython.org>
* tests/multi_net: Update TLS test certificates and keys.Damien George2025-01-14
| | | | | | They expired in early January 2025. Signed-off-by: Damien George <damien@micropython.org>
* tests/multi_net: Fix skipping of SSLContext tests when .der don't exist.Damien George2024-07-25
| | | | | | | | | The `sslcontext_server_client_ciphers.py` test was using stat to test for the .der files after it already tried to open them for reading. That is now fixed. And `sslcontext_server_client.py` is adjusted to use the same pattern for skipping the test. Signed-off-by: Damien George <damien@micropython.org>
* extmod/modtls_mbedtls: Implement cert verification callback for mbedtls.Felix Dörre2024-02-07
| | | | | | | This is a useful alternative to .getpeercert() when the certificate is not stored to reduce RAM usage. Signed-off-by: Felix Dörre <felix@dogcraft.de>
* extmod/modtls: Move the native ssl module to tls.Felix Dörre2024-02-07
| | | | | | | | | | | | | The current `ssl` module has quite a few differences to the CPython implementation. This change moves the MicroPython variant to a new `tls` module and provides a wrapper module for `ssl` (in micropython-lib). Users who only rely on implemented comparible behavior can continue to use `ssl`, while users that rely on non-compatible behavior should switch to `tls`. Then we can make the facade in `ssl` more strictly adhere to CPython. Signed-off-by: Felix Dörre <felix@dogcraft.de>
* all: Update bindings, ports and tests for mbedtls v3.5.1.Carlosgg2024-01-30
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | Changes include: - Some mbedtls source files renamed or deprecated. - Our `mbedtls_config.h` files are renamed to `mbedtls_config_port.h`, so they don't clash with mbedtls's new default configuration file named `mbedtls_config.h`. - MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_KEY_EXCHANGE is deprecated. - MBEDTLS_HAVE_TIME now requires an `mbedtls_ms_time` function to be defined but it's only used for TLSv1.3 (currently not enabled in MicroPython so there is a lazy implementation, i.e. seconds * 1000). - `tests/multi_net/ssl_data.py` is removed (due to deprecation of MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_KEY_EXCHANGE), there are the existing `ssl_cert_rsa.py` and `sslcontext_server_client.py` tests which do very similar, simple SSL data transfer. - Tests now use an EC key by default (they are smaller and faster), and the RSA key has been regenerated due to the old PKCS encoding used by openssl rsa command, see https://stackoverflow.com/questions/40822328/openssl-rsa-key-pem-and-der-conversion-does-not-match (and `tests/README.md` has been updated accordingly). Signed-off-by: Carlos Gil <carlosgilglez@gmail.com>
* tests/multi_net: Generate smaller certs with 2048-bit RSA.Damien George2024-01-05
| | | | | | | | | Otherwise running the tests can take a long time when the server is a slow target (RP2040 takes 23 seconds for a handshake when using 4096-bit RSA). Also add instructions on how to generate elliptic curve key/certs. Signed-off-by: Damien George <damien@micropython.org>
* tests/run-multitests.py: Change to dir of test script when running it.Damien George2024-01-05
| | | | | | | | | | | This matches the behaviour of run-tests.py, which sets cwd to the directory containing the test script, which helps to isolate the filesystem. It means that the SSL tests no longer need to know the name of their containing directory to find the certificate files, and helps to run these tests on bare-metal. Signed-off-by: Damien George <damien@micropython.org>
* extmod/asyncio: Add ssl support with SSLContext.Carlosgg2023-12-14
| | | | | | | | | | | | | | This adds asyncio ssl support with SSLContext and the corresponding tests in `tests/net_inet` and `tests/multi_net`. Note that not doing the handshake on connect will delegate the handshake to the following `mbedtls_ssl_read/write` calls. However if the handshake fails when a client certificate is required and not presented by the peer, it needs to be notified of this handshake error (otherwise it will hang until timeout if any). Finally at MicroPython side raise the proper mbedtls error code and message. Signed-off-by: Carlos Gil <carlosgilglez@gmail.com>
* extmod/modssl_mbedtls: Make SSLSocket.getpeercert() optional.Damien George2023-12-12
| | | | | | | | | | And only enable this method when the relevant feature is available in mbedtls. Otherwise, if mbedtls doesn't support getting the peer certificate, this method always returns None and it's confusing why it does that. It's better to remove the method altogether, so the error trying to use it is more obvious. Signed-off-by: Damien George <damien@micropython.org>
* extmod/modssl_mbedtls: Add SSLContext certificate methods.Carlosgg2023-12-12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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 <carlosgilglez@gmail.com>
* tests/multi_net/ssl_cert_rsa.py: Update test certificate.Carlosgg2023-09-29
| | | | | | | Update expired certificate, increase time validity period to five years and fix command arguments typos in commentaries. Signed-off-by: Carlos Gil <carlosgilglez@gmail.com>
* tests/multi_net: Increase asyncio tests timeouts.iabdalkader2023-09-06
| | | | | | | Increase asyncio tests timeouts to account for different WiFi modules and CPU clocks on different boards. Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
* tests: Rename uasyncio to asyncio.Jim Mussared2023-06-19
| | | | | | This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
* tests: Replace umodule with module everywhere.Jim Mussared2023-06-08
| | | | | | This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
* top: Update Python formatting to black "2023 stable style".Jim Mussared2023-02-02
| | | | | | See https://black.readthedocs.io/en/stable/the_black_code_style/index.html Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
* extmod/modussl_mbedtls: Implement cert_reqs and cadata arguments.Carlosgg2022-07-20
| | | | | | | | | | | | | | | | | Add cert_reqs and cadata keyword-args to ssl.wrap_socket() and ssl.CERT_NONE, ssl.CERT_OPTIONAL, ssl.CERT_REQUIRED constants to allow certificate validation. CPython doesn't accept cadata in ssl.wrap_socket(), but it does in SSLContext.load_verify_locations(), so we use this name to at least match the same name in load_verify_locations(). Add docs for these new arguments, as well as docs for the existing server_hostname argument which is important for certificate validation. Tests are added as well. Signed-off-by: Carlos Gil <carlosgilglez@gmail.com>
* extmod/uasyncio: Implement stream read(-1) to read all data up to EOF.Damien George2022-06-24
| | | | | | Fixes issue #6355. Signed-off-by: Damien George <damien@micropython.org>
* tests/multi_net: Fix TCP accept test when using system error numbers.iabdalkader2022-05-24
| | | | | | If a port is not using internal error numbers, which match both lwIP and Linux error numbers, ENTOCONN from standard libraries errno.h equals 128, not 107.
* tests/multi_net: Skip SSL test if relevant modules aren't available.Damien George2022-05-17
| | | | Signed-off-by: Damien George <damien@micropython.org>
* extmod/modusocket: Implement optional socket.listen backlog argument.Jon Bjarni Bjarnason2022-04-11
| | | | | | | | This follows the CPython change: https://bugs.python.org/issue21455 Socket listen backlog defaults to 2 if not given, based on most bare metal targets not having many resources for a large backlog. On UNIX it defaults to SOMAXCONN or 128, whichever is less.
* tests/multi_net/udp_data.py: Make UDP test more reliable.iabdalkader2022-02-09
| | | | | | | | The current test depends on a specific number and order of packets to pass, which can't be reproduced every run due to the unreliable UDP protocol. This patch adds simple packets sequencing, retransmits with timeouts, and a packet loss threshold, to make the test more tolerant to UDP protocol packet drops and reordering.
* tests/multi_net/udp_data.py: Allow reusing port before bind.iabdalkader2022-01-21
|
* tests/multi_net: Close accepted sockets when tests are done.iabdalkader2022-01-21
| | | | | gc_sweep_all() cleans up sockets via the finaliser, but tests should cleanly free resources they use.
* tests/multi_net: Add testing key/cert to SSL server/client test.Damien George2022-01-17
| | | | | | So that this tests works with mbedtls. Signed-off-by: Damien George <damien@micropython.org>
* extmod/modlwip: Fix close and clean up of UDP and raw sockets.Damien George2021-08-13
| | | | | | | The correct callback-deregister functions must be called dependent on the socket type, otherwise resources may not be freed correctly. Signed-off-by: Damien George <damien@micropython.org>
* extmod/uasyncio: Add readinto() method to Stream class.Mike Teachman2021-06-15
| | | | | | | | | With docs and a multi-test using TCP server/client. This method is a MicroPython extension, although there is discussion of adding it to CPython: https://bugs.python.org/issue41305 Signed-off-by: Mike Teachman <mike.teachman@gmail.com>
* tests: Use .errno instead of .args[0] for OSError exceptions.Damien George2021-04-23
| | | | Signed-off-by: Damien George <damien@micropython.org>
* extmod/uasyncio: Add StreamReader.readexactly(n) method.Damien George2020-07-25
| | | | | | | | | | | It raises on EOFError instead of an IncompleteReadError (which is what CPython does). But the latter is derived from EOFError so code compatible with MicroPython and CPython can be written by catching EOFError (eg see included test). Fixes issue #6156. Signed-off-by: Damien George <damien@micropython.org>
* tests/multi_net: Add uasyncio test for TCP server and client.Damien George2020-03-26
| | | | | | Includes a test where the (non uasyncio) client does a RST on the connection, as a simple TCP server/client test where both sides are using uasyncio, and a test for TCP stream close then write.
* tests/multi_net: Add initial set of multi-instance tests for network.Damien George2020-03-10