Skip to content
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

fix(tls): Enable IPv6 support in ssl_client connect #9470

Merged

Conversation

sgryphon
Copy link
Contributor

@sgryphon sgryphon commented Apr 9, 2024

Description of Change

Update ssl_client.cpp to support IPv6 addresses. The change is similar to the code in NetworkClient.cpp, checking the family of the passed in address and configure the socket and socket address accordingly, for either IPv6 or IPv4 as specified in the address.

Tests scenarios

Tested with M5Stack Core 2, using the following PlatformIO configuration and the test app from https://github.com/sgryphon/iot-demo-build/tree/main/m5stack/m5unified_wifi_https

platform = https://github.com/sgryphon/platform-espressif32.git#sgryphon/add-esp32-arduino-libs
platform_packages = 
  platformio/framework-arduinoespressif32-libs @ https://github.com/sgryphon/esp32-arduino-libs.git#sgryphon/test-fix-ipv6-lwip-and-config
  platformio/framework-arduinoespressif32 @ https://github.com/sgryphon/arduino-esp32.git#sgryphon/sslclient-ipv6-support

Results work for TLS across all network types and destinations:

Network Dual-Stack IPv6 IPv4 TLS Dual-Stack TLS IPv6 TLS IPv4
IPv4 (Shadow) IPv4 not possible Yes IPv4 not possible Yes
IPv6 disabled, Dual-stack+NAT64 IPv4 not possible Yes IPv4 not possible Yes
Dual-stack+NAT64 (Astral) IPv6 Yes NAT64 IPv6 Yes NAT64
IPv6+NAT64 (Wildspace) IPv6 Yes NAT64 IPv6 Yes NAT64

Example IPv6-only network TLS (HTTPS) connection to IPv4-only server, via NAT64. Device sees the DNS64 address (DNS result), destination server (in the response) sees the IPv4 NAT address.

[ 71996][I][Core2Logger.cpp:198] log(): [Core2Logger] CORE2: Button 3, scenario 2, v0.1.0-159-g493ff2b-dev
[ 72010][I][Core2Logger.cpp:198] log(): [Core2Logger] CORE2: Global IPv6 2407:8800:bc61:1300:a3a:f2ff:fe65:db28
[ 72024][I][Core2Logger.cpp:198] log(): [Core2Logger] CORE2: IPv4 0.0.0.0
*sta: <UP,Wildspace,CH:1,RSSI:-60,N,WPA2_PSK> (DHCPC,GARP,IP_MOD,V6_REP)
      ether 08:3A:F2:65:DB:28
      inet 0.0.0.0 netmask 0.0.0.0 broadcast 255.255.255.255
      gateway 0.0.0.0 dns fd7c:e25e:67e8::1
      inet6 fe80::a3a:f2ff:fe65:db28%st1 type LINK_LOCAL
      inet6 2407:8800:bc61:1300:a3a:f2ff:fe65:db28 type GLOBAL
      inet6 fd7c:e25e:67e8:0:a3a:f2ff:fe65:db28 type UNIQUE_LOCAL
[ 72057][I][Core2Logger.cpp:198] log(): [Core2Logger] CORE2: DNS0 fd7c:e25e:67e8::1
[ 72076][I][Core2Logger.cpp:198] log(): [Core2Logger] CORE2: DNS1 0.0.0.0
[ 72084][I][Core2Logger.cpp:198] log(): [Core2Logger] CORE2: TLS URL: https://v4.ipv6-test.com/api/myip.php
[ 72098][D][HTTPClient.cpp:303] beginInternal(): protocol: https, host: v4.ipv6-test.com port: 443 url: /api/myip.php
[ 72108][D][HTTPClient.cpp:598] sendRequest(): request type: 'GET' redirCount: 0
[ 72158][D][NetworkManager.cpp:82] hostByName(): DNS found IPv6 64:ff9b::334b:4e67
[ 73904][D][HTTPClient.cpp:1170] connect():  connected to v4.ipv6-test.com:443
[ 74517][D][HTTPClient.cpp:1321] handleHeaderResponse(): code: 200
[ 74524][D][HTTPClient.cpp:1328] handleHeaderResponse(): Transfer-Encoding: chunked
[ 74531][D][HTTPClient.cpp:642] sendRequest(): sendRequest code=200
[ 74538][D][HTTPClient.cpp:388] disconnect(): still data in buffer (2), clean up.
[ 74545][D][HTTPClient.cpp:393] disconnect(): tcp keep open for reuse
[ 74551][I][Core2Logger.cpp:198] log(): [Core2Logger] CORE2: response=<220.240.255.134>
[ 74562][I][Core2Logger.cpp:176] success(): [Core2Logger] Success

Alternatively, if the LWIP fix is not available, you can combine this fix and the IPv6 DNS workaround. This also works across all network types and destinations.

platform = https://github.com/sgryphon/platform-espressif32.git#sgryphon/add-esp32-arduino-libs
platform_packages = 
  platformio/framework-arduinoespressif32-libs @ https://github.com/sgryphon/esp32-arduino-libs.git#sgryphon/test-fix-ipv6-config
  platformio/framework-arduinoespressif32 @ https://github.com/sgryphon/arduino-esp32.git#sgryphon/test-fix-dns-and-sslclient

Related links

This is the last part of the issues in #9143; once all of the changes are merged, then IPv6 will work across HTTP and TLS/HTTPS, using the default configuration, for all network types and destination types.

Also see the IPv6 discussion, #9009

First example:

Second example (without LWIP fix):

Similar to NetworkClient, check the family of the passed in address and configure the socket and socket address accordingly, for both IPv6 and IPv4 support.
Copy link
Contributor

github-actions bot commented Apr 9, 2024

Warnings
⚠️

Some issues found for the commit messages in this PR:

  • the commit message "fix(tls): Enable IPv6 support in ssl_client connect":
    • body's lines must not be longer than 100 characters

Please fix these commit messages - here are some basic tips:

  • follow Conventional Commits style
  • correct format of commit message should be: <type/action>(<scope/component>): <summary>, for example fix(esp32): Fixed startup timeout issue
  • allowed types are: change,ci,docs,feat,fix,refactor,remove,revert,test
  • sufficiently descriptive message summary should be between 20 to 72 characters and start with upper case letter
  • avoid Jira references in commit messages (unavailable/irrelevant for our customers)

TIP: Install pre-commit hooks and run this check when committing (uses the Conventional Precommit Linter).

👋 Hello sgryphon, we appreciate your contribution to this project!


Click to see more instructions ...


This automated output is generated by the PR linter DangerJS, which checks if your Pull Request meets the project's requirements and helps you fix potential issues.

DangerJS is triggered with each push event to a Pull Request and modify the contents of this comment.

Please consider the following:
- Danger mainly focuses on the PR structure and formatting and can't understand the meaning behind your code or changes.
- Danger is not a substitute for human code reviews; it's still important to request a code review from your colleagues.
- Resolve all warnings (⚠️ ) before requesting a review from human reviewers - they will appreciate it.
- To manually retry these Danger checks, please navigate to the Actions tab and re-run last Danger workflow.

Review and merge process you can expect ...


We do welcome contributions in the form of bug reports, feature requests and pull requests.

1. An internal issue has been created for the PR, we assign it to the relevant engineer.
2. They review the PR and either approve it or ask you for changes or clarifications.
3. Once the GitHub PR is approved we do the final review, collect approvals from core owners and make sure all the automated tests are passing.
- At this point we may do some adjustments to the proposed change, or extend it by adding tests or documentation.
4. If the change is approved and passes the tests it is merged into the default branch.

Generated by 🚫 dangerJS against 3d880f1

@me-no-dev me-no-dev merged commit 1788867 into espressif:master Apr 9, 2024
41 checks passed
@sgryphon
Copy link
Contributor Author

sgryphon commented Apr 9, 2024

Thank you. This is really great to get this working.

P-R-O-C-H-Y pushed a commit to P-R-O-C-H-Y/arduino-esp32 that referenced this pull request Apr 16, 2024
Similar to NetworkClient, check the family of the passed in address and configure the socket and socket address accordingly, for both IPv6 and IPv4 support.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants