-
Notifications
You must be signed in to change notification settings - Fork 34
Fenrir fixes (2026-06-23) #70
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
Open
julek-wolfssl
wants to merge
8
commits into
wolfSSL:master
Choose a base branch
from
julek-wolfssl:fenrir/20260623
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
c29eb67
Fix DTLS server example consuming the ClientHello before handshake (F…
julek-wolfssl 41561e7
Map WANT_READ from SSLSocket.write() to SSLWantReadError (F-3905)
julek-wolfssl d0bb56e
Map WANT_WRITE from SSLSocket.read() to SSLWantWriteError (F-3906)
julek-wolfssl 65aaef9
Map WANT_WRITE from SSLSocket.recv_into() to SSLWantWriteError (F-3907)
julek-wolfssl 99a4416
Drive DTLS handshake only until complete in I/O methods (F-4136)
julek-wolfssl 9c26572
Enable hostname verification in client example (F-5621)
julek-wolfssl 3dd1b90
Send bytes-like data verbatim in SSLSocket.write (F-5622)
julek-wolfssl 93954c9
Return None from getpeercert when peer has no certificate (F-5623)
julek-wolfssl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| # -*- coding: utf-8 -*- | ||
| # | ||
| # test_client_example.py | ||
| # | ||
| # Copyright (C) 2006-2020 wolfSSL Inc. | ||
| # | ||
| # This file is part of wolfSSL. (formerly known as CyaSSL) | ||
| # | ||
| # wolfSSL is free software; you can redistribute it and/or modify | ||
| # it under the terms of the GNU General Public License as published by | ||
| # the Free Software Foundation; either version 2 of the License, or | ||
| # (at your option) any later version. | ||
| # | ||
| # wolfSSL is distributed in the hope that it will be useful, | ||
| # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| # GNU General Public License for more details. | ||
| # | ||
| # You should have received a copy of the GNU General Public License | ||
| # along with this program; if not, write to the Free Software | ||
| # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA | ||
|
|
||
| # pylint: disable=missing-docstring, invalid-name, import-error | ||
|
|
||
| import os | ||
| import sys | ||
|
|
||
| import wolfssl | ||
|
|
||
| sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "examples")) | ||
| import client as client_example # noqa: E402 | ||
|
|
||
|
|
||
| def _args(argv): | ||
| return client_example.build_arg_parser().parse_args(argv) | ||
|
|
||
|
|
||
| def _ctx(): | ||
| return wolfssl.SSLContext(wolfssl.PROTOCOL_TLSv1_2) | ||
|
|
||
|
|
||
| def test_verification_enables_hostname_check_by_default(): | ||
| """ | ||
| F-5621: with cert verification on (the default), the client must also | ||
| verify the peer's hostname and pass server_hostname to wrap_socket. | ||
| """ | ||
| args = _args(["-h", "example.com"]) | ||
| ctx = _ctx() | ||
|
|
||
| server_hostname = client_example.configure_verification(ctx, args) | ||
|
|
||
| assert ctx.verify_mode == wolfssl.CERT_REQUIRED | ||
| assert ctx.check_hostname is True | ||
| assert server_hostname == "example.com" | ||
|
|
||
|
|
||
| def test_disable_cert_check_skips_hostname(): | ||
| args = _args(["-d"]) | ||
| ctx = _ctx() | ||
| # Simulate a reused context that previously had hostname checking on: | ||
| # -d must clear it, not leave it dangling against CERT_NONE. | ||
| ctx.verify_mode = wolfssl.CERT_REQUIRED | ||
| ctx.check_hostname = True | ||
|
|
||
| server_hostname = client_example.configure_verification(ctx, args) | ||
|
|
||
| assert ctx.verify_mode == wolfssl.CERT_NONE | ||
| assert ctx.check_hostname is False | ||
| assert server_hostname is None | ||
|
|
||
|
|
||
| def test_hostname_check_can_be_opted_out(): | ||
| """An explicit opt-out is provided for IP literals / test certs.""" | ||
| args = _args(["-n"]) | ||
| ctx = _ctx() | ||
| # Reused context with hostname checking previously enabled: -n must | ||
| # actively turn it back off. | ||
| ctx.verify_mode = wolfssl.CERT_REQUIRED | ||
| ctx.check_hostname = True | ||
|
|
||
| server_hostname = client_example.configure_verification(ctx, args) | ||
|
|
||
| assert ctx.verify_mode == wolfssl.CERT_REQUIRED | ||
| assert ctx.check_hostname is False | ||
| assert server_hostname is None |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| # -*- coding: utf-8 -*- | ||
| # | ||
| # test_dtls_handshake_once.py | ||
| # | ||
| # Copyright (C) 2006-2020 wolfSSL Inc. | ||
| # | ||
| # This file is part of wolfSSL. (formerly known as CyaSSL) | ||
| # | ||
| # wolfSSL is free software; you can redistribute it and/or modify | ||
| # it under the terms of the GNU General Public License as published by | ||
| # the Free Software Foundation; either version 2 of the License, or | ||
| # (at your option) any later version. | ||
| # | ||
| # wolfSSL is distributed in the hope that it will be useful, | ||
| # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| # GNU General Public License for more details. | ||
| # | ||
| # You should have received a copy of the GNU General Public License | ||
| # along with this program; if not, write to the Free Software | ||
| # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA | ||
|
|
||
| # pylint: disable=missing-docstring, invalid-name, import-error | ||
| # pylint: disable=protected-access | ||
|
|
||
| """ | ||
| F-4136: for DTLS, write()/read()/recv_into() used to call do_handshake() on | ||
| every single call. Once the handshake has completed, re-running it is wasteful | ||
| and, on a non-blocking socket, wolfSSL_accept/connect can raise | ||
| SSLWantReadError and abort an otherwise valid I/O. The handshake must only be | ||
| driven until it completes. | ||
| """ | ||
|
|
||
| from types import SimpleNamespace | ||
|
|
||
| import pytest | ||
| import wolfssl | ||
|
|
||
|
|
||
| class _OkLib: | ||
| """_lib stub whose I/O calls always succeed.""" | ||
|
|
||
| def wolfSSL_write(self, ssl, data, length): | ||
| return length | ||
|
|
||
| def wolfSSL_read(self, ssl, data, length): | ||
| return length | ||
|
|
||
| def wolfSSL_get_error(self, ssl, ret): # pragma: no cover | ||
| return 0 | ||
|
|
||
|
|
||
| def _make_dtls_socket(handshake_complete): | ||
| sock = wolfssl.SSLSocket.__new__(wolfssl.SSLSocket) | ||
| sock.native_object = object() | ||
| sock._connected = True | ||
| sock._server_side = True | ||
| sock._context = SimpleNamespace(protocol=wolfssl.PROTOCOL_DTLSv1_2) | ||
| sock._handshake_complete = handshake_complete | ||
| sock._release_native_object = lambda: None | ||
| return sock | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def spy_handshake(monkeypatch): | ||
| monkeypatch.setattr(wolfssl, "_lib", _OkLib()) | ||
| calls = [] | ||
|
|
||
| def _record(sock): | ||
| calls.append(True) | ||
| sock._handshake_complete = True | ||
|
|
||
| return calls, _record | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("op", ["write", "read", "recv_into"]) | ||
| def test_dtls_io_does_not_redrive_completed_handshake(spy_handshake, op): | ||
| calls, record = spy_handshake | ||
| sock = _make_dtls_socket(handshake_complete=True) | ||
| sock.do_handshake = lambda block=False: record(sock) | ||
|
|
||
| if op == "write": | ||
| sock.write(b"payload") | ||
| elif op == "read": | ||
| sock.read(8) | ||
| else: | ||
| sock.recv_into(bytearray(8)) | ||
|
|
||
| assert calls == [], "do_handshake() must not run once the handshake is done" | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("op", ["write", "read", "recv_into"]) | ||
| def test_dtls_io_drives_handshake_until_complete(spy_handshake, op): | ||
| calls, record = spy_handshake | ||
| sock = _make_dtls_socket(handshake_complete=False) | ||
| sock.do_handshake = lambda block=False: record(sock) | ||
|
|
||
| if op == "write": | ||
| sock.write(b"payload") | ||
| elif op == "read": | ||
| sock.read(8) | ||
| else: | ||
| sock.recv_into(bytearray(8)) | ||
|
|
||
| assert calls == [True], "first DTLS I/O must drive the handshake once" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| # -*- coding: utf-8 -*- | ||
| # | ||
| # test_dtls_server_example.py | ||
| # | ||
| # Copyright (C) 2006-2020 wolfSSL Inc. | ||
| # | ||
| # This file is part of wolfSSL. (formerly known as CyaSSL) | ||
| # | ||
| # wolfSSL is free software; you can redistribute it and/or modify | ||
| # it under the terms of the GNU General Public License as published by | ||
| # the Free Software Foundation; either version 2 of the License, or | ||
| # (at your option) any later version. | ||
| # | ||
| # wolfSSL is distributed in the hope that it will be useful, | ||
| # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| # GNU General Public License for more details. | ||
| # | ||
| # You should have received a copy of the GNU General Public License | ||
| # along with this program; if not, write to the Free Software | ||
| # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA | ||
|
|
||
| # pylint: disable=missing-docstring, invalid-name, import-error | ||
|
|
||
| import os | ||
| import sys | ||
| import socket | ||
|
|
||
| import pytest | ||
|
|
||
| sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "examples")) | ||
| import server as server_example # noqa: E402 | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def udp_pair(): | ||
| srv = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) | ||
| srv.bind(("localhost", 0)) | ||
| cli = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) | ||
| try: | ||
| yield srv, cli, srv.getsockname() | ||
| finally: | ||
| srv.close() | ||
| cli.close() | ||
|
|
||
|
|
||
| def test_peek_peer_address_returns_source(udp_pair): | ||
| srv, cli, srv_addr = udp_pair | ||
| cli.bind(("localhost", 0)) | ||
| cli.sendto(b"clienthello-payload", srv_addr) | ||
|
|
||
| addr = server_example.peek_peer_address(srv) | ||
|
|
||
| assert addr == cli.getsockname() | ||
|
|
||
|
|
||
| def test_peek_peer_address_does_not_consume_datagram(udp_pair): | ||
| """ | ||
| Regression test for F-3481: peeking the client's address before the | ||
| DTLS handshake must leave the ClientHello datagram intact. The previous | ||
| example used recvfrom(1), which consumed the datagram and discarded | ||
| everything past the first byte, breaking the handshake. | ||
| """ | ||
| srv, cli, srv_addr = udp_pair | ||
| payload = b"X" * 256 # stand-in for a DTLS ClientHello record | ||
| cli.sendto(payload, srv_addr) | ||
|
|
||
| server_example.peek_peer_address(srv) | ||
|
|
||
| # The datagram must still be fully available for wolfSSL_accept(). | ||
| srv.settimeout(2) | ||
| data, _ = srv.recvfrom(4096) | ||
| assert data == payload |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟠 [Medium] Client example default host is an IP literal but hostname verification is now on by default
F-5621 enables hostname verification whenever cert checking is on (the default). But the client's default host is the IP literal
-h 127.0.0.1(line 46), andconfigure_verificationreturnsargs.hasserver_hostnameand setscheck_hostname = Truefor that default.__init__then callswolfSSL_check_domain_name(ssl, "127.0.0.1").wolfSSL_check_domain_nameperforms DNS/CN-style domain matching; the bundledcerts/server-cert.pemcarries127.0.0.1only as anIP AddressSAN (SAN isDNS:example.com, IP Address:127.0.0.1), not a DNS-type entry. If wolfSSL's domain-name check does not match IP-type SANs, the out-of-the-boxpython client.pyrun will now fail with a hostname/domain mismatch and require the new-nflag — a behavior change for the example's default invocation. The function's own docstring even states IP literals need-n, which is exactly the default host. Additionally, sending an IP literal via SNI (use_sni("127.0.0.1")) is not RFC-6066 conformant.Fix: Confirm that a default
python client.py(host 127.0.0.1) still completes the handshake against the bundled certs with hostname verification enabled. If wolfSSL_check_domain_name does not match the IP-type SAN, either auto-disable the hostname check for IP-literal hosts, document that-nis required for the default host, or change the example default host to a DNS name in the cert SAN.