close
Skip to content

Add TLS and HTTPS support#3545

Merged
eXpl0it3r merged 3 commits into
masterfrom
feature/tls
Dec 19, 2025
Merged

Add TLS and HTTPS support#3545
eXpl0it3r merged 3 commits into
masterfrom
feature/tls

Conversation

@binary1248

Copy link
Copy Markdown
Member

This change adds support for Transport Layer Security to sf::TcpSocket using Mbed TLS.

Because HTTPS is just HTTP over a TLS stream, support for HTTPS was also added.

All of the existing sf::TcpSocket interfaces stayed the same. After a connection is established on either client or server, the corresponding setup function has to be called. For clients setupTlsClient has to be called and for servers setupTlsServer has to be called. The arguments that have to be supplied are those typical of setting up any TLS stream.

For a usage example, the Sockets example was modified to give the user a choice of enabling TLS. Additionally, since HTTPS is also supported with this change, a HTTP example was added that can be used to connect to websites using HTTP/HTTPS.

Finally, connection tests were added for TLS and non-TLS TCP streams.

Since CI passes with the tests enabled on almost all platforms, it means the implementation including loading certificates from the system certificate store works on all those platforms. The only platform that is currently unsupported is iOS since Apple deliberately chose not to provide the same Security framework APIs as it does on macOS. After searching for a while I gave up thinking of how to load system certificates on iOS. If there are any iOS experts out there, they can try their luck adding a working implementation for it.

@Bambo-Borris

Copy link
Copy Markdown
Contributor

Dang! Another great feature so soon. Looking forward to seeing this merged

Comment thread include/SFML/Network/TcpSocket.hpp Outdated
Comment thread examples/sockets/TCP.cpp Outdated
Comment thread src/SFML/Network/TcpSocket.cpp Outdated
Comment thread src/SFML/Network/TcpSocket.cpp
Comment thread src/SFML/Network/TcpSocket.cpp
Comment thread src/SFML/Network/TcpSocket.cpp
Comment thread include/SFML/Network/TcpSocket.hpp Outdated
Comment thread examples/http/Http.cpp
Comment thread examples/http/Http.cpp Outdated
Comment thread examples/http/Http.cpp Outdated
Comment thread examples/http/Http.cpp
Comment thread examples/http/Http.cpp
Comment thread examples/http/Http.cpp Outdated
Comment thread include/SFML/Network/Http.hpp Outdated
Comment thread src/SFML/Network/TcpSocket.cpp
Comment thread src/SFML/Network/TcpSocket.cpp
Comment thread src/SFML/Network/TcpSocket.cpp
@binary1248 binary1248 force-pushed the feature/tls branch 2 times, most recently from 97835e7 to ded9123 Compare August 23, 2025 13:55
@eXpl0it3r eXpl0it3r added this to the 3.1 milestone Oct 1, 2025
@github-project-automation github-project-automation Bot moved this to Planned in SFML 3.1.0 Oct 1, 2025
@eXpl0it3r eXpl0it3r moved this from Planned to In Review in SFML 3.1.0 Oct 1, 2025
@binary1248

Copy link
Copy Markdown
Member Author

Rebased onto master.

@github-actions

Copy link
Copy Markdown

Pull Request Test Coverage Report for Build 18615251839

Details

  • 309 of 412 (75.0%) changed or added relevant lines in 3 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+1.5%) to 59.647%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/SFML/Network/Http.cpp 7 8 87.5%
src/SFML/Network/TcpSocket.cpp 301 403 74.69%
Totals Coverage Status
Change from base Build 18483127964: 1.5%
Covered Lines: 13291
Relevant Lines: 21467

💛 - Coveralls

@eXpl0it3r eXpl0it3r left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great! 🥳

I added some questions and minor code structure comments, nothing to really block this PR further.

Comment thread src/SFML/Network/TcpSocket.cpp
Comment thread src/SFML/Network/TcpSocket.cpp
Comment thread src/SFML/Network/TcpSocket.cpp
Comment thread src/SFML/Network/TcpSocket.cpp
Comment thread src/SFML/Network/TcpSocket.cpp
Comment thread src/SFML/Network/TcpSocket.cpp Outdated
@binary1248

Copy link
Copy Markdown
Member Author

Rebased onto master.

@binary1248 binary1248 force-pushed the feature/tls branch 4 times, most recently from d7b1526 to b4f4691 Compare December 6, 2025 17:36
@binary1248 binary1248 force-pushed the feature/tls branch 10 times, most recently from ca14ae7 to ca90dbd Compare December 7, 2025 05:26

@learn-more learn-more left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some notes / questions I had while reviewing the code.

Comment thread examples/sockets/TCP.cpp Outdated
Comment thread examples/sockets/TCP.cpp
Comment thread include/SFML/Network/TcpSocket.hpp
Comment thread include/SFML/Network/TcpSocket.hpp
Comment thread include/SFML/Network/TcpSocket.hpp
Comment thread src/SFML/Network/TcpSocket.cpp
Comment thread src/SFML/Network/TcpSocket.cpp
Comment thread examples/http/Http.cpp
Comment thread src/SFML/Network/TcpSocket.cpp Outdated
Comment thread src/SFML/Network/Http.cpp
@binary1248

Copy link
Copy Markdown
Member Author

Updated.

@binary1248

Copy link
Copy Markdown
Member Author

@eXpl0it3r eXpl0it3r merged commit 31ff201 into master Dec 19, 2025
192 checks passed
@eXpl0it3r eXpl0it3r deleted the feature/tls branch December 19, 2025 15:52
@github-project-automation github-project-automation Bot moved this from In Review to Done in SFML 3.1.0 Dec 19, 2025
@eXpl0it3r

Copy link
Copy Markdown
Member

Another long awaited feature has landed in SFML! 🥳

Thank you for bringing TLS to SFML! ♥️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

No open projects
Status: Done

Development

Successfully merging this pull request may close these issues.

5 participants