Skip to content

Fix Fenrir findings F-3483, F-2136, F-3235, F-2931 and refresh test certs - #74

Open
LinuxJedi wants to merge 5 commits into
wolfSSL:masterfrom
LinuxJedi:fenrir/20261104
Open

LinuxJedi wants to merge 5 commits into
wolfSSL:masterfrom
LinuxJedi:fenrir/20261104

Conversation

@LinuxJedi

Copy link
Copy Markdown
Member

Fixes for four Fenrir findings, one commit each, plus a refresh of the expired test certificates.

Fixes

  • F-3483: reject read-only buffers in SSLSocket.recv_into(). ffi.from_buffer() accepted read-only objects such as bytes, so wolfSSL_read() could write decrypted data into immutable Python objects. It now requires a writable buffer and raises TypeError for read-only ones, as the stdlib does.
  • F-2136: block verify_mode downgrade while check_hostname is set. A context could enable check_hostname and then drop verify_mode to CERT_NONE/CERT_OPTIONAL, which silently disabled the hostname check. That now raises ValueError, as the stdlib does. The client example's -d path clears check_hostname first.
  • F-3235: decode certificate strings as UTF-8. get_subject_cn() and get_next_altname() decoded as strict ASCII, so a valid certificate with a UTF-8 commonName made getpeercert() raise. They now decode as UTF-8 and replace bytes that are not valid UTF-8.
  • F-2931: label subjectAltName entries by their actual type. getpeercert()['subjectAltName'] reported every entry as DNS, including IP addresses, emails and URIs. It now reads the GENERAL_NAME stack through wolfSSL_X509_get_ext_d2i() and uses the stdlib labels and formatting (DNS, IP Address, email, URI). Other types get their stdlib label with the value <unsupported>.

Test certificates

certs/ca-cert.pem, server-cert.pem and client-cert.pem expired on 2026-09-08, which broke the tests that verify the peer. They are replaced with the versions from wolfSSL v5.9.4-stable, valid until 2029-03-07. The CRL is replaced too, because the renewed CA's subject changed. The keys are unchanged.

A new self-signed certs/utf8-san-cert.pem (with its key) covers the UTF-8 and SAN-type tests. The commit message has the command used to generate it.

Testing

Each fix has a regression test, and each test fails without its fix. The full suite passes: 100 passed, 1 skipped.

recv_into() obtained its destination pointer with ffi.from_buffer(buffer),
whose default require_writable=False accepts read-only objects such as
bytes and read-only memoryviews. wolfSSL_read() then wrote decrypted
plaintext directly into that memory, mutating immutable Python objects
that CPython may share elsewhere in the interpreter. Request a writable
buffer and raise TypeError for read-only ones before wolfSSL_read() is
called, matching the stdlib socket/ssl recv_into() contract.
The check_hostname setter requires verify_mode to be CERT_REQUIRED, but the
verify_mode setter did not enforce the reverse. A context could enable
check_hostname and then drop verify_mode to CERT_NONE (or CERT_OPTIONAL),
leaving check_hostname reporting True while wolfSSL no longer verified the
peer, so the domain check set up by wolfSSL_check_domain_name() was
silently ignored. Raise ValueError in that case, as the stdlib ssl module
does, requiring check_hostname to be cleared first.

Update the client example's -d path to clear check_hostname before
lowering verify_mode, which is now the required order.
get_subject_cn() and get_next_altname() decoded the strings returned by
wolfSSL as strict ASCII. X.509 names are routinely UTF8String, so a peer
presenting a valid certificate with an internationalized commonName made
getpeercert() raise UnicodeDecodeError, and a peer could deliberately use
non-ASCII bytes to make any caller inspecting its certificate fail. Decode
as UTF-8 and replace undecodable bytes instead of raising.

Add certs/utf8-san-cert.pem (self-signed P-256, 100 year validity) with a
UTF-8 commonName and DNS, IPv4, IPv6, email and URI subjectAltNames, the
URI containing non-ASCII. It was generated with:

  openssl req -x509 -new -newkey ec -pkeyopt ec_paramgen_curve:P-256 \
    -nodes -keyout utf8-san-key.pem -out utf8-san-cert.pem -days 36500 \
    -utf8 -sha256 -subj "/C=US/O=wolfSSL/CN=<UTF-8 name>" \
    -addext "subjectAltName=DNS:localhost,IP:127.0.0.1,IP:2001:db8::1,email:test@example.com,URI:<UTF-8 URI>" \
    -addext "basicConstraints=critical,CA:FALSE"
Copilot AI balanced review requested due to automatic review settings November 5, 2026 07:56

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

SAN extraction repeatedly traverses the linked list from its head, causing quadratic work on each getpeercert() call for certificates with large SAN lists.

1 open issue
What changed in this PR

This PR addresses four Fenrir findings in wolfSSL’s Python bindings, improving buffer safety, verification settings, and certificate inspection. It also refreshes expired test certificates.

Changes:

  • Reject read-only receive buffers and prevent verification downgrades while hostname checking is enabled.
  • Decode certificate strings as UTF-8 and report subject alternative names by their actual types.
  • Add regression tests, refresh certificates and the CRL, and update the client example.
File Description
wolfssl/​_openssl.py Adds constants for SAN types and extension lookup.
wolfssl/​_build_ffi.py Adds native bindings for typed SAN extraction.
wolfssl/​__init__.py Implements buffer, verification, and certificate-handling fixes.
tests/​test_recv_into.py Tests read-only rejection and writable-buffer reads.
tests/​test_getpeercert.py Tests UTF-8 decoding and SAN type formatting.
tests/​test_context.py Tests verification downgrade guards.
examples/​client.py Disables hostname checking before relaxing verification.
certs/​utf8-san-key.pem Adds the regression certificate’s test key.
certs/​utf8-san-cert.pem Adds a UTF-8 certificate with multiple SAN types.
certs/​server-cert.pem Refreshes the server certificate and bundled CA.
certs/​crl.pem Refreshes the CRL for the renewed CA.
certs/​client-cert.pem Refreshes the client certificate.
certs/​ca-cert.pem Refreshes the test CA certificate.

Review effort: Balanced

Comment thread wolfssl/__init__.py Resolved
get_altnames(), and therefore getpeercert()['subjectAltName'], wrapped
every value returned by wolfSSL_X509_get_next_altname() as ('DNS', ...).
That function returns every SAN type, so iPAddress, rfc822Name and URI
entries were reported as DNS names. Code following the stdlib ssl
contract would never see an 'IP Address' entry and could run DNS
hostname matching against IP, email or URI values.

Build the list from the GENERAL_NAME stack returned by
wolfSSL_X509_get_ext_d2i(NID_subject_alt_name), which carries each entry's
type. Report DNS, IP Address, email and URI values using the stdlib
labels and formatting (IPv6 as eight uppercase hex groups). Other
GeneralName types are reported under their stdlib label with the value
'<unsupported>' so they are never mistaken for a DNS name. Entries keep
the order get_next_altname() returns them in, as before.

The stack is walked node by node with wolfSSL_sk_get_node(node, 1)
rather than by index, because wolfSSL_sk_GENERAL_NAME_value() walks the
linked list from its head on every call, which would make extraction
quadratic in the number of names.
The bundled ca-cert.pem, server-cert.pem and client-cert.pem expired on
2026-09-08, so tests that verify the peer (test_client.py and
test_client_example.py) failed while loading or validating them. Take
the current files from wolfSSL v5.9.4-stable: certs/ca-cert.pem,
certs/server-cert.pem (server certificate plus CA), certs/client-cert.pem
and certs/crl/crl.pem, all valid until 2029-03-07.

The keys are unchanged, so server-key.pem and client-key.pem are kept.
The CRL is replaced as well because the renewed CA's subject differs
(emailAddress), so the old CRL no longer matches its issuer. It still
revokes only serial 02.

@wolfSSL-Fenrir-bot wolfSSL-Fenrir-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Fenrir Automated Review — PR #74

Scan targets checked: wolfssl-py-src, wolfssl-py-bugs
Not reviewed (no scan target covers them): certs/ca-cert.pem, certs/client-cert.pem, certs/crl.pem, certs/server-cert.pem, certs/utf8-san-cert.pem, certs/utf8-san-key.pem, tests/test_context.py, tests/test_getpeercert.py, tests/test_recv_into.py
Coverage: 2 of 4 in-scope changed file(s) opened by the reviewer; not opened: wolfssl/_build_ffi.py, wolfssl/_openssl.py

Fenrir result: Approved ✅

No new issues found in the changed files.

Advisory only — this automated result does not count as a GitHub approval.

Review tier: Lite

This branch has not been deployed

No deployments
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.

4 participants