Tobias Brunner [Fri, 12 Dec 2025 07:10:13 +0000 (08:10 +0100)]
ip-packet: Fix compiler warning seen on FreeBSD 15
We explicitly use untoh16() so this warning isn't relevant:
ip_packet.c:313:42: error: taking address of packed member 'ip_len' of class or structure 'ip' may result in an unaligned pointer value [-Werror,-Waddress-of-packed-member]
Tobias Brunner [Thu, 11 Dec 2025 16:25:12 +0000 (17:25 +0100)]
Use Botan 3.10.0 for tests
Clean up leak-detective whitelist for newer Botan versions but add
`botan_private_key_load` as `botan_privkey_load*` won't show up anymore
without bfd-backtraces due to inlining if we don't call it directly.
Tobias Brunner [Thu, 4 Dec 2025 12:56:31 +0000 (13:56 +0100)]
nm: Pass back the username auth-dialog runs as to access ssh-agent socket
This ensures we access the socket as user who NM ran the auth-dialog for,
especially for system-wide connections where the connection does not
mention a user.
We also make sure we don't use the cached socket and user of a previous
connection attempt, because system-wide connections might be used by
different users.
Tobias Brunner [Tue, 2 Dec 2025 15:17:36 +0000 (16:17 +0100)]
charon-nm: Pass configured user when connecting to SSH/GPG agent
This prevents an attack similar to the one fixed previously where a
user passes the path to credentials of another user, in this case the
path to the agent socket of that user.
Tobias Brunner [Wed, 26 Nov 2025 12:55:54 +0000 (13:55 +0100)]
nm: Create safe copies of files for user-specific connections
This ensures that only certificates/private keys accessible by the
configured user are accessed and prevents attackers from misusing
other user's credentials.
Also removed setting NM_VERSION_MIN_REQUIRED, which suppresses deprecation
warnings that were added with newer API versions, and
NM_VERSION_MAX_ALLOWED, which warns if using functions added in newer
API versions, so we always build against the latest API available.
But we check explicitly for the required function so this works with
older NM versions and automatically will use it if the function is
backported.
Note that we can't use BUILD_FROM_FILE to read the temporary files as that
uses mmap() which SELinux policies prevent us from using at the location
these files are stored ([/var]/run/NetworkManager/cert/).
Tobias Brunner [Mon, 24 Nov 2025 11:24:21 +0000 (12:24 +0100)]
child-rekey: Prevent crash if peer rekeys a Child SA twice before sending a delete
Some (Windows) peers have been seen to initiate a second rekeying for the
same Child SA. Presumably, this happens if a rekey request from us for
the same old Child SA arrives while it waits for the response to its
first rekey request. Once we receive the delete for the old SA, we
conclude the rekeying with the second replacement. However, the first
replacement remained linked to the old SA. So this change prevents a
crash once the peer sends a delete for that first replacement (which it
seems to do after about 5 minutes).
Tobias Brunner [Wed, 3 Dec 2025 10:40:17 +0000 (11:40 +0100)]
testing: Make per-CPU SAs scenarios more predictable by pinning IRQs to vCPUs
This ensures that packets on sun are processed on a particular CPU and
not randomly on one, which causes expected SAs not to get created or
other weird things.
Tobias Brunner [Fri, 21 Nov 2025 09:49:18 +0000 (10:49 +0100)]
Use wolfSSL 5.8.4 for tests
Also remove the --enable-md4 option. We never supported MD4 via wolfSSL,
as it's not available via the hash API we use (would require explicit
MD4-specific functions and structures).
Tobias Brunner [Thu, 20 Nov 2025 14:54:57 +0000 (15:54 +0100)]
Merge branch 'swanctl-names'
Increases buffers in settings and swanctl to allow longer connection
names (up to the limit of 256 characters imposed by VICI). The limit
for names is now also enforced when generating VICI messages.
Tobias Brunner [Wed, 19 Nov 2025 09:33:39 +0000 (10:33 +0100)]
settings: Increase buffer size for key patterns/parts when looking up settings
The buffer size for individual parts of a key now match the maximum length
of names in VICI. The full pattern should accommodate several long names
(e.g. for connections and child connections in swanctl) even if no
printf-specifiers are used.
Tobias Brunner [Thu, 13 Nov 2025 17:51:11 +0000 (18:51 +0100)]
Merge branch 'revocation-fetcher'
Combines concurrent requests for the same CRL URI by multiple threads.
So only the first thread actually fetches it, the others wait for that
result. This is particularly helpful if the CRL can currently not
be fetched due to DNS or HTTP/LDAP timeouts as it prevents each thread
from having to wait for the complete timeouts, which reduces the number
of SAs that can concurrently be established.
A negative result is cached for a while (currently 3 times the fetch
timeout, i.e. 30 seconds by default) so requests can fail quickly and
threads can continue establishing SAs if they use a relaxed revocation
policy.
Martin Willi [Wed, 29 Oct 2025 09:35:10 +0000 (10:35 +0100)]
revocation: Block only one thread per URL after a previous CRL fetch failed
If a CRL server is unresponsive, all threads trying to fetch this CRL will
block execution. If a recent previous attempt to fetch the CRL failed, it
is likely that it will fail again. While it makes sense to retry fetching
the CRL on demand with one thread, it hardly does to block additional
threads while the first one is blocked during the fetch.
So remember the timestamp of the last CRL fetch failure per URL, and do
not block more than one thread in the CRL fetch for some time. This time
is a multiple of the configured fetch timeout, so that it works well for
any configured value. With the default configuration, a failing CRL fetch
will impact concurrent CRL fetches for the same URL for 30s.
Martin Willi [Wed, 29 Oct 2025 08:48:31 +0000 (09:48 +0100)]
revocation: Synchronize CRL fetches of multiple threads to the same URL
When handling many connection attempts from peers using the same CA, a slow
or non-responsive CRL distribution point can lead to concurrent fetches of
the same CRL by multiple threads. This is not only inefficient, but results
in all threads blocking for the full fetch timeout, potentially blocking
all threads in the pool.
As a first step, synchronize CRL fetches using a global mutex and a per-URL
condvar, so threads can wait for the CRL if another is already fetching it.
This reduces the number of useless concurrent CRL fetches, and allows threads
joining the party late to get blocked only until the first fetch completes
or times out.
The URL entry is preserved in the hashtable after completing the fetch.
This will allow subsequent optimizations to store the last fetch result
and act accordingly. The CRL itself is not, as CRLs can be rather large
and caching them can be done using existing mechanisms controlled via
corresponding options.
Martin Willi [Wed, 29 Oct 2025 06:49:49 +0000 (07:49 +0100)]
revocation: Move CRL/OCSP fetch operations to a dedicated fetcher helper
Before adding stateful CRL fetching extensions, refactor CRL fetching to
a helper class for better separation. While there are currently no plans
to extend OCSP fetching, move it as well for consistency.
Martin Willi [Thu, 30 Oct 2025 13:47:29 +0000 (14:47 +0100)]
revocation: Pass "this" parameter along CRL/OCSP verification functions
As future commits will require shared state during fetch operations, a common
context is required. So pass along the "this" parameter in various revocation
functions.
Tobias Brunner [Thu, 30 Oct 2025 15:36:45 +0000 (16:36 +0100)]
android: Fix edge-to-edge layout issues with settings and app selection
Using FrameLayout for the settings instead of the recommended
FragmentContainerView because the latter makes handling insets more
complicated (fitsSystemWindows doesn't work as the fragment is responsible
for handling insets but how that should work with PreferenceFragmentCompat
is unclear).
Fixes: 2404b2bee632 ("android: Apply UI changes for edge-to-edge views in Android 15+")
Tobias Brunner [Mon, 27 Oct 2025 14:36:49 +0000 (15:36 +0100)]
Merge branch 'android-updates'
This fixes the vulnerability in the eap-mschapv2 plugin and an issue
with the filename of log files. In the released app, the OpenSSL version
is also increased in order to support ML-KEM.
Tobias Brunner [Thu, 9 Oct 2025 09:33:45 +0000 (11:33 +0200)]
eap-mschapv2: Fix length check for Failure Request packets on the client
For message lengths between 6 and 8, subtracting HEADER_LEN (9) causes
`message_len` to become negative, which is then used in calls to malloc()
and memcpy() that both take size_t arguments, causing an integer
underflow.
For 6 and 7, the huge size requested from malloc() will fail (it exceeds
PTRDIFF_MAX) and the returned NULL pointer will cause a segmentation
fault in memcpy().
However, for 8, the allocation is 0, which succeeds. But then the -1
passed to memcpy() causes a heap-based buffer overflow (and possibly a
segmentation fault when attempting to read/write that much data).
Fortunately, if compiled with -D_FORTIFY_SOURCE=3 (the default on e.g.
Ubuntu), the compiler will use __memcpy_chk(), which prevents that buffer
overflow and causes the daemon to get aborted immediately instead.
Fixes: f98cdf7a4765 ("adding plugin for EAP-MS-CHAPv2") Fixes: CVE-2025-62291
Tobias Brunner [Fri, 3 Oct 2025 08:59:03 +0000 (10:59 +0200)]
vici: Provide a way to stop listening and re-connect in Python bindings
This allows re-connecting to a new session in a disconnect listener and
continue listening without having to return from listen(). The exception
can also be used to stop listening after some condition (e.g. to wait
until a specific SA got created and then stop).
Martin Willi [Wed, 24 Sep 2025 13:15:03 +0000 (15:15 +0200)]
child-create: Raise an ALERT_TS_MISMATCH when receiving TS_UNACCEPTABLE
When sending a TS_UNACCEPTABLE notify, a ALERT_TS_MISMATCH is sent, but
not when receiving one. This seems inconsistent compared to proposal
mismatch handling, so extend the child_create task to raise such an alert.
Martin Willi [Tue, 23 Sep 2025 11:01:52 +0000 (13:01 +0200)]
vici: Raise alert events from the bus alert listener hook
The bus alert infrastructure is currently exposed through the error-notify
plugin using a dedicated socket using a rather archaic message format.
Vici clients would need a dedicated socket connection just to receive such
alert messages, making their implementation more complex.
With vici, it is rather trivial to expose bus alerts through a dedicated
event message that vici clients may subscribe to. Add such an "alert"
event type to vici. Alert names are mapped to strings for simple consumption by
clients.
For now, the error-notify string message is omitted from events, as it mostly
contains static information without much value; instead add the IKE_SA details
for alerts associated to an IKE_SA. Other alert specific data may be added in
the future if needed; preferably using a structured format instead of the
arbitrary string messages used by error-notify. To allow future extensions,
wrap IKE_SA details under a dedicated "ike-sa" property.
Tobias Brunner [Thu, 2 Oct 2025 06:47:34 +0000 (08:47 +0200)]
github: Use OpenSSL 3 for macOS builds and enable additional plugins
The Homebrew formula has been using OpenSSL 3 for a while. The eap-peap
and pkcs11 plugins also have been enabled in the formula. The dhcp plugin
is enabled to test the port (the farp plugin was already enabled since
its port to FreeBSD/macOS). The drbg plugin is enabled to run the ML-KEM
test vectors.
Tobias Brunner [Wed, 1 Oct 2025 13:52:45 +0000 (15:52 +0200)]
github: Build on macOS 14 instead of the deprecated macOS 13
While macos-13 was running on Intel, both macos-latest (macOS 15) and
macos-14 run on ARM64. While there are Intel-based images for 14 and 15,
they will only be available until August 2027 (and there aren't any Intel
devices anymore anyway).
Tobias Brunner [Wed, 1 Oct 2025 13:19:18 +0000 (15:19 +0200)]
Merge branch 'android-updates'
This fixes GUI-related compatibility issues with Android 16 and allows
(pre-)selecting on-device certificates/keys with managed profiles. Also
fixes a typo in the managed config description that prevented
split-tunneling settings from working.
android: Make a certificate alias pre-selectable in managed profiles
This allows associating a pre-installed certificate/key with a VPN
profile. For instance, one locally generated on the device via
SCEP/ETS by the MDM. It only works if the app is granted access to the
certificate/key (alias) by the MDM.
For now, users may still select a different certificate if one is
available (since this requires the certificate to be installed as
user-selectable there might not be).
android: Explicitly pull in androidx.localbroadcastmanager
Seems to not get pulled in automatically anymore. This has actually been
deprecated for years apparently. Unfortunately, it's not that easy to
replace, so keep it for now.
Tobias Brunner [Mon, 4 Aug 2025 12:35:11 +0000 (14:35 +0200)]
android: Apply UI changes for edge-to-edge views in Android 15+
When targeting Android 15, edge-to-edge is the default and when targeting
Android 16, apps can't opt-out from this anymore. So we update our views
and enable edge-to-edge also for older versions (avoids the black bar
behind the system UI at the bottom). For most views we just use automatic
margins via android:fitsSystemWindows (or programmatically via
setDecorFitsSystemWindows). However, for the profile lists and log views,
we take some extra measures that allow the lists to go behind the bottom
system UI. Appropriate padding is applied at the bottom of the lists so
the last item(s) can be scrolled into full view.
No part of IKE/IPsec or X.509 uses MD2 anymore, so there really is no
reason to still support it (unlike MD4 that is used in EAP-MSCHAPv2,
MD5 that's used in EAP-MD5, or SHA-1 that's used for e.g. NAT-D hashes).
It caused test vectors to fail on systems where OpenSSL is built with
MD2 support but has it disabled at runtime.
Tobias Brunner [Fri, 15 Aug 2025 16:32:24 +0000 (18:32 +0200)]
testing: Add option to run tests without leak detective
This new option allows to disable leak detective to reduce the runtime
during development. Either only for the command line (swanctl, pki etc.)
or optionally also for the daemon(s).
Disabling leak detective only for the CLI tools already brings a
considerable reduction in runtime (from 48m to 38m on my dev host) as
there are many such calls in the post-test stage. Any leaks in those
tools are also a lot less of an issue than leaks in the daemon. So using
this during development should be fine as long as a full test run is done
regularly (in particular before releases). Disabling leak detective
completely further reduces the runtime (to 30m on my dev host). But that
should probably only be used for functional regression tests after
verifying new code didn't introduce new leaks.
This also fixes the service script which is used for charon-tkm since 16fcdb460afd ("charon-tkm: Don't use starter/stroke with charon-tkm anymore").
Tobias Brunner [Fri, 15 Aug 2025 12:48:49 +0000 (14:48 +0200)]
testing: Increase memory for guest hosts to run Debian trixie
While some increase was necessary anyway because the idle system requires
about 5-10 MiB more memory, the main issue is resolving the code line and
function name in case of a memory leak. Calling addr2line requires a lot
more memory than before. Using backtraces via libbfd doesn't help either
because the trigger is the bfd_find_nearest_line() call we use as well.
And because we'd try to resolve all symbols that way (for whitelisting),
the memory overhead would be even higher and affect every shutdown, even
if no leak occurred. It also causes a significant time overhead (running
all tests took 75m instead of 48m).
I also tested switching to ASAN/LSAN. The peak memory usage is slightly
higher than when using libbfd, but enabling it also increased the runtime
overhead a lot (the daemon and swanctl both required about 10-20 MiB more
memory, not just during the shutdown).
Tobias Brunner [Fri, 15 Aug 2025 12:45:13 +0000 (14:45 +0200)]
testing: Install required packages in venv of updated strongTNC
Update revision for some dependency updates. While python3-setuptools is
installed on the system, the venv apparently can't use it. legacy-cgi is
required to use that old Django version with newer Python releases.
Tobias Brunner [Fri, 15 Aug 2025 12:40:38 +0000 (14:40 +0200)]
testing: Use newer version of TKM on trixie
The API for libgmpada has change with 1.6 in a way that's not
backwards-compatible. So we use a different revision that includes
the required changes depending on the Debian version.
This also adds support for esa_select(), to support seamless rekeyings,
which requires updating xfrm-ada as well.