Commit Graph
2340 Commits
Author SHA1 Message Date
Tobias Brunner e306fa5f73 kernel-libipsec: Add support to send/receive raw ESP packets
This is currently only supported on Linux and with the appropriate
permissions.

Since it's experimental, it's disabled by default.

The log messages for each sent and received ESP message are logged in NET
like the ones in the socket-default plugin for UDP-encapsulated messages.
2023-05-23 13:19:47 +02:00
Tobias Brunner 29e8cb3f90 libipsec: Move restrictions regarding UDP encapsulation to users 2023-05-23 13:19:47 +02:00
Tobias Brunner 8ddfaf5857 libipsec: Instruct ESP sender whether to use UDP encapsulation 2023-05-23 13:19:47 +02:00
Tobias Brunner a049868d78 kernel-libipsec: Use CALLBACK for libipsec callbacks 2023-05-23 13:19:47 +02:00
Tobias Brunner b0eb88f703 kernel-libipsec: Forward acquires from libipsec to the daemon 2023-05-23 11:53:53 +02:00
Tobias Brunner 6ceb39b1da ike: Use a struct to store retransmission settings
The calculation of the timeout is also shared now and the total
timeout in seconds is corrected in case retransmit_base is <= 1.

This could make it easier in the future to apply different retransmission
settings to messages/exchanges.
2023-05-17 15:58:28 +02:00
Tobias Brunner 72f8794d83 selinux: Fix build with DEBUG_LEVEL < 1 2023-05-08 17:32:18 +02:00
Tobias Brunner 4620f43eba radattr: Fix build with DEBUG_LEVEL < 1 2023-05-08 17:32:18 +02:00
Tobias Brunner 74b2628301 systime-fix: Fix build with DEBUG_LEVEL < 1 2023-05-08 17:32:18 +02:00
Tobias Brunner d0ef504614 kernel-netlink: Fix build with DEBUG_LEVEL < 2 2023-05-08 17:32:18 +02:00
Tobias Brunner b0ce4ef8db ha: Fix build with DEBUG_LEVEL < 1 2023-05-08 17:32:18 +02:00
Tobias Brunner 35716df9bc dhcp: Fix build with DEBUG_LEVEL < 1 2023-05-08 17:32:18 +02:00
Tobias Brunner e72ab6a818 tnc-ifmap: Fix build with DEBUG_LEVEL < 2 2023-05-08 17:32:18 +02:00
Tobias Brunner 68f35b48d8 eap-peap: Fix build with DEBUG_LEVEL < 1 2023-05-08 17:32:18 +02:00
Tobias Brunner e252e1b465 eap-ttls: Fix build with DEBUG_LEVEL < 1 2023-05-08 17:32:18 +02:00
Tobias Brunner cbedbf3ef1 eap-radius: Fix build with DEBUG_LEVEL < 1 2023-05-08 17:32:18 +02:00
Tobias Brunner 2d3967cb4c eap-dynamic: Fix build with DEBUG_LEVEL < 2 2023-05-08 17:32:17 +02:00
Tobias Brunner 65dc1801cf eap-mschapv2: Fix build with DEBUG_LEVEL < 1 2023-05-08 17:32:17 +02:00
Tobias Brunner e0eece0465 vici: Fix build with DEBUG_LEVEL < 2 2023-05-08 17:32:17 +02:00
Tobias Brunner 86aa454c88 forecast: Fix build with DEBUG_LEVEL < 2 2023-05-08 17:32:17 +02:00
Tobias Brunner a7ea181f0d save-keys: Fix build with DEBUG_LEVEL < 0 2023-05-08 17:32:17 +02:00
Tobias Brunner 5e46e101a6 vici: Improve log messages for terminate/rekey() in case of combined filters
As long as any `child*` selector is received, only CHILD_SAs will be
terminated or rekeyed.  Any passed `ike*` selectors will only be used to
filter the IKE_SAs when looking for matching CHILD_SAs.  However, the
previous log messages seemed to indicate that IKE_SAs will also be
terminated/rekeyed.

References strongswan/strongswan#1655
2023-05-01 10:19:29 +02:00
Tobias Brunner 00a75e332f vici: Create default TCP socket on Windows in Python bindings
This uses the same value as VICI_DEFAULT_URI.

References strongswan/strongswan#1655
2023-05-01 10:19:29 +02:00
Tobias Brunner d96d15b588 controller: Add parameter for maximum log level to initiate/terminate_*()
Previously, the logger installed by the controller always announced
LEVEL_PRIVATE(4), which produced completely useless logging calls with
the common clients (vici/stroke) whose default log level is LEVEL_CTRL(1).
This can produce quite some overhead if there are e.g. a lot of concurrent
initiate() calls.
2023-04-27 13:52:34 +02:00
Tobias Brunner 2cb6d144a6 vici: Don't lock connection in write mode when enabling on_write() callback
This should prevent a deadlock that could previously be caused when a
control-log event was raised.  The deadlock looked something like this:

 * Thread A holds the read lock on bus_t and raises the control-log event.
   This requires acquiring the connection entry in write mode to queue the
   outgoing message.  If it is already held by another thread, this blocks
   on a condvar.

 * Thread B is registering the on_write() callback on the same connection's
   stream due to a previous log message.  Before this change, the code
   acquired the entry in write mode as well, thus, blocking thread A.  To
   remove/add the stream, the mutex in watcher_t needs to be acquired.

 * Thread C is in watcher_t's watch() and holds the mutex while logging on
   level 2 or 3.  The latter requires the read lock on bus_t, which should
   usually be acquirable even if thread A holds it.  Unless writers are
   concurrently waiting on the lock and the implementation is blocking
   new readers to prevent writer starvation.

 * Thread D is removing a logger from the bus (e.g. after an initiate()
   call) and is waiting to acquire the write lock on bus_t and is thereby
   blocking thread C.

With this change, thread B should not block thread A anymore.  So thread D
and thread C should eventually be able to proceed as well.

Thread A could be held up a bit if there is a thread already sending
messages for the same connection, but that should only cause a delay, no
deadlock, as on_write() and do_write() don't log (or lock) anything while
keeping the entry locked in write mode.

Closes strongswan/strongswan#566
2023-04-26 15:52:40 +02:00
Tobias Brunner 7be55adf05 ipseckey: Add support for ECDSA and EdDSA public keys 2023-03-30 10:35:09 +02:00
Tobias Brunner 9b391f86fe eap-radius: Don't include socket.h explicitly
We rely on the includes via utils.h so this compiles on Windows.
2023-03-21 16:33:03 +01:00
Tobias Brunner 8c0a67f700 kernel-wfp: Install bypass policies also on FWPM_SUBLAYER_IPSEC_TUNNEL sublayer
This is apparently necessary to bypass tunnel mode SAs/policies.

References strongswan/strongswan#1552
2023-03-21 16:30:09 +01:00
Tobias Brunner dd79253e2d vici: Fix fallback to remote ID if no mediation peer ID is configured
Also adds error reporting via VICI for issues with mediation settings.

Fixes: 229cdf6bc8 ("vici: Order auth rounds by optional `round` parameter instead of by position in the request")
References strongswan/strongswan#1569
2023-03-21 16:21:48 +01:00
Tobias Brunner 3c8887326a dhcp: Don't use get_source_addr() to determine source address
That method is subject to interface filtering, which isn't ideal for
DHCP traffic that probably uses an internal interface on which the IKE
daemon might be disabled.  In that case `giaddr` is set to an incorrect
public IP, which in turn might prevent the plugin from receiving the
DHCP server's unicast response, in particular if the DHCP socket
is bound to the internal interface.

This new approach connects the client socket and thereby determines the
source address to reach the DHCP server.

Closes strongswan/strongswan#1573
2023-03-21 16:13:22 +01:00
Tobias Brunner 3d0d3f5d02 eap-tls: Fix server implementation with TLS 1.2 and earlier
With 5401a74d36 ("eap-tls: Add support for TLS 1.3") a TLS application
was added to implement TLS 1.3's protected success indication.  For
earlier TLS versions, its build() method simply returned SUCCESS as
there was nothing to send.  However, that had the unintended side-effect
of also not sending the final TLS handshake messages (ChangeCipherSpec
and Finished).

The reason is that the TLS stack first checks for remaining handshake
messages but then also asks the registered application for data to
piggyback to that response (before the commit there was no application,
so that step was skipped).  The problem is that the status returned by
the application is directly forwarded through the TLS stack.  So not
returning INVALID_STATE caused the session to get concluded immediately
instead of resulting in ALREADY_DONE that would trigger sending the
final EAP message instead of an EAP-Success.

Fixes: 5401a74d36 ("eap-tls: Add support for TLS 1.3")
2023-03-21 16:11:49 +01:00
Jean-Tiare Le BigotandTobias Brunner bb6174a4d1 vici: Generalize timeout support in Python bindings
Since 3dd5dc5011 ("Merge branch 'vici-python-timeout'"), any timeout
set directly on the socket is reset by `vici.Transport.receive()` unless
called by `vici.Session.listen()`. This prevents configuring a default
timeout directly on the socket.

However, setting a timeout directly on the socket also had drawbacks
since it can cause `vici.Transport.receive()` to raise a timeout error
while a subset of the data have been received, with no way to recover.

This commit merges both approaches by considering the timeout configured
on the socket by default (when no timeout is explicitly set) and
keeping the switch to blocking receive once the first byte has been
received. When the full expected data have been received, the timeout
configured on the socket is restored.

Co-authored-by: Tobias Brunner <tobias@strongswan.org>
Signed-off-by: Jean-Tiare Le Bigot <jt@yadutaf.fr>

Closes strongswan/strongswan#1562
2023-03-10 09:10:44 +01:00
Tobias Brunner 8aa13a1797 eap-peap: Initiate Phase 2 immediately for TLS 1.3
Before TLS 1.3, the server sent the last handshake message and had the
option to piggyback the EAP-Identity request directly onto the packet
with the TLS Finished message, or wait for the empty message by the
client that acknowledges the completion of the handshake.  With TLS 1.3,
the client finishes the handshake after the server.  So this option
is irrelevant there and we immediately start with Phase 2.
2023-03-02 09:31:52 +01:00
Tobias Brunner 501483b313 libvici: Fix Doxygen comment for vici_on_close()
Fixes: 9e5533fef9 ("libvici: Add callback invoked if connection is closed by daemon")
2023-02-22 14:33:34 +01:00
Tobias Brunner 04486507b2 kernel-netlink: Add an option to install routes for SAs with XFRM interfaces
Since these might conflict with IKE traffic, this requires special care.
One option is to install bypass policies for the peer, which install
appropriate (throw) routes.  However, that won't work if the traffic to
the gateway itself should be protected, in particular, for host-to-host
tunnels.  So an alternative is to set a mark for the IKE socket and then
exclude that traffic from table 220 via the kernel-netlink plugin's
fwmark option.
2023-02-22 13:37:45 +01:00
Tobias Brunner 0cc780d317 kernel-netlink: Automatically bring up XFRM interfaces after creation 2023-02-22 13:37:45 +01:00
Tobias Brunner e1ff1eefcf kernel-netlink: Add manager for XFRM interfaces
The manager will allow charon-nm to create XFRM interfaces if supported
by the kernel instead of creating an unused dummy TUN interface.

The xfrmi tool is mostly obsolete nowadays as iproute2 supports creating
XFRM interfaces since 5.1.0 (2019-05).  Older Debians don't ship that and
early versions didn't list the interface IDs.  So there might still be
some uses for this tool.
2023-02-22 13:37:45 +01:00
Tobias Brunner 5401a74d36 eap-tls: Add support for TLS 1.3
As defined in RFC 9190, a "protected success indication" (0x00) is sent
from the server to the client over the TLS connection when using TLS 1.3.

The client responds with an empty EAP message, which is interpreted as
acknowledgement in our stack.

If we ever support session resumption with tunneled methods such as
EAP-TTLS, we'd have to send such an indication there too.
2023-02-22 13:34:53 +01:00
Tobias Brunner 346a050c36 kernel-netlink: Increase log level for dumped Netlink messages
Some of these contain key material so they should be logged on level 4.
2023-02-22 13:20:10 +01:00
Tobias Brunner e21290ec30 kernel-netlink: Read last use time from SA if possible
Since 6.2 the Linux kernel updates the last use time per SA.  In
previous releases the attribute was only updated and reported for
specific outbound IPv6 SAs.

Using this reduces the number of kernel queries per CHILD_SA: for DPDs
from two policy queries (IN/FWD) to a single query of the inbound SA,
and for status reports the three policy queries (IN/FWD/OUT) can be
omitted and only the two SAs have to be queried.  For NAT keepalives the
number of queries doesn't change but a policy query (OUT) is replaced by
a query for the outbound SA.

While we could use the existence of the attribute as indicator for its
support, we don't know this until we queried an SA.  By using a version
check we can announce the feature from the start.
2023-02-22 13:20:10 +01:00
Tobias Brunner b9131c34d3 kernel-interface: Add feature to indicate if query_sa() returns last use time
Currently supported by libipsec and PF_KEY on macOS (FreeBSD, like Linux,
reports the time the SA was first used in sadb_lifetime_usetime - it also
triggers rekeyings based on that, which Linux doesn't, it also triggers
them if an SA is never used).
2023-02-22 13:20:10 +01:00
Tobias Brunner 1efdb0f791 ikev2: Add option to prefer childless IKE_SAs as initiator 2023-02-22 13:19:46 +01:00
Tobias Brunner 9e5533fef9 libvici: Add callback invoked if connection is closed by daemon 2023-02-22 11:44:14 +01:00
Tobias Brunner 15c6360145 kernel-netlink: Offload bypass policies for IKE ports on interfaces
While this uses the same mechanism, it's not necessary to explicitly
enable port_bypass, the regular socket policies work fine to bypass any
software policies.
2023-02-16 14:45:57 +01:00
Tobias Brunner 77a5c9514c kernel-netlink: Use event socket wrapper for XFRM and networking events 2023-02-16 13:25:35 +01:00
Tobias Brunner cb0bdb847d kernel-netlink: Add simple wrapper for Netlink event sockets 2023-02-16 13:25:35 +01:00
Tobias Brunner e323539428 kernel-pfkey: Always register for events
The starter-specific code path isn't necessary anymore since
d8fdd1018e ("starter: Don't flush SAs in the kernel").
2023-02-16 13:25:35 +01:00
Tobias Brunner 30cb3bd4d5 kernel-pfroute: Always listen for events
The starter-specific code path isn't necessary anymore since
d8fdd1018e ("starter: Don't flush SAs in the kernel").
2023-02-16 13:25:35 +01:00
Tobias Brunner d7ccb44354 kernel-netlink: Always register for events
The starter-specific code path isn't necessary anymore since
d8fdd1018e ("starter: Don't flush SAs in the kernel").
2023-02-16 13:25:35 +01:00
Tobias Brunner 68ccb1930c kernel-netlink: Fallback to configured interface when HW offloading policies
This allows offloading bypass and drop policies to a specific interface
by configuring `interface` and `hw_offload=packet` (`auto` works too).
2023-02-16 13:25:34 +01:00