Commit Graph
409 Commits
Author SHA1 Message Date
Tobias Brunner 8e020bc9e3 vici-config: Same order for default ESP proposals if unset or set to "default"
The order was different when not setting `esp_proposals` or explicitly
configuring `default`.

Fixes: 33412158f5 ("ike: Send AEAD ESP default proposal first")
2024-10-02 10:33:05 +02:00
Tobias Brunner a4a3dcf6c2 vici-config: Consider queued tasks when terminating IKE/CHILD_SAs
This is particularly important for IKE_SAs that are not yet established,
which would get terminated as they have no established CHILD_SAs yet.

Fixes: 72f9a21b22 ("Merge branch 'vici-reload-actions'")
2024-09-18 11:53:17 +02:00
Andreas Steffen d4fb07911f vici: Increase maximum proposal length 2024-08-07 16:20:18 +02:00
Andreas SteffenandTobias Brunner 355f917532 vici: List additional key exchanges
Co-authored-by: Tobias Brunner <tobias@strongswan.org>
2024-08-07 16:20:18 +02:00
Tobias Brunner 7bfaa9acb6 vici: Improve handling of start action when reloading configs
The previous code had some issues because it handled each child config
separately.  Not only was this quite inefficient because all IKE_SAs had
to be enumerated for every config, it also caused problems with the check
for other CHILD_SAs in order to decide whether to delete the IKE_SA or
not.  Because CHILD_SAs are deleted with an INFORMATIONAL exchange, they
are not immediately gone.  This caused a race condition and with more
than one child config and SAs the IKE_SA could be kept because it
could appear as if other, unrelated CHILD_SAs were still there.

Another race condition, which is fixed by the previous commit, occurred
when only changing child configs.  Then it could happen that the code
deemed the IKE_SA empty and a delete for it was queued.  If that happened
while the IKE_SA was deleting one of the CHILD_SAs (or was busy with some
other exchange), the IKE_SA was not switched to IKE_DELETING.  So it
looked usable and create-child tasks for the updated configs might have
gotten queued.  Unfortunately, once the ike-delete task is eventually
executed, these tasks would be gone and the replacement CHILD_SAs never
created.  This commit additionally avoids actually deleting the IKE_SA
even if all child configs change or get removed if any new CHILD_SAs are
to be initiated.
2024-07-26 16:40:57 +02:00
Tobias Brunner 9acd90575a ike-cfg: Change how OCSP certificate requests are enabled
The previous option caused such requests to be enabled if not explicitly
disabled, which only the vici plugin did, for all other backends requests
would have been sent.

References strongswan/strongswan#2016
2024-03-15 15:38:19 +01:00
Jean-François HrenandTobias Brunner 15612b3a42 Add support for IKEv2 OCSP extensions (RFC 4806)
Closes strongswan/strongswan#2016

Co-authored-by: Tobias Brunner <tobias@strongswan.org>
2024-03-13 15:10:50 +01:00
Tobias Brunner 6dee8587f0 Remove obvious empty statements (i.e. stray semicolons) 2024-02-29 15:30:40 +01:00
Tobias Brunner 7550463d51 Replace some other mentions of "Linux strongSwan" 2023-12-14 11:27:19 +01:00
Tobias Brunner 0bff5c98bc vici: Fix connecting to socket in Python bindings on Windows
socket.connect() takes a single argument with the address that depends
on the address family, for TCP it's a tuple with IP and port.

Fixes: 00a75e332f ("vici: Create default TCP socket on Windows in Python bindings")
Closes strongswan/strongswan#1874
2023-08-31 11:39:52 +02:00
Tobias Brunner e0eece0465 vici: Fix build with DEBUG_LEVEL < 2 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 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
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 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 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 2b8f26308f vici: Update offloading configuration for full packet HW offloading 2023-02-16 13:25:34 +01:00
Tobias Brunner 55719d7de5 kernel-netlink: Add support for full packet and policy HW offloading 2023-02-16 13:25:34 +01:00
Thomas Egerer 5e9f5fb32e Make format string a string literal in some debug statements
Signed-off-by: Thomas Egerer <thomas.egerer@secunet.com>
2022-12-21 17:33:37 +01:00
Tobias Brunner da0d0ecc45 vici: Add Python 3.10 and 3.11 2022-12-12 16:57:01 +01:00
Martin Willi 484c0f8dd0 vici: Gracefully consume/ignore incoming events in Python event deregistration
When issuing a deregistration message, some last events may still be sent
by the daemon before deregistration completes. Ignore such event messages
silently during deregistration, avoiding exceptions like:

  vici.exception.SessionException:
    Unexpected response type 7, expected '5' (EVENT_CONFIRM)
2022-12-12 14:38:09 +01:00
Martin Willi 254d4075fe vici: Add some initial session level unit-tests 2022-12-12 14:38:09 +01:00
Martin Willi aa0da01fde vici: Add simple Python transport layer tests, including timeout 2022-12-12 14:38:09 +01:00
Martin Willi 248a188d21 vici: Allow the Python event listen() operation to optionally time out
The architecture of the Python client is completely blocking, which is fine
for many simple scripts. For more complex applications that do other I/O
and listen for vici events, the most feasible way to integrate the client is
to use a dedicated thread.

Unfortunately, Python has no simple support for thread cancellation. And
having that thread in a blocking recv() does not allow to terminate the
thread gracefully with an Event or the like.

As a way out, add a timeout to the listen() call, so the thread can
periodically do other things, like checking for termination Event and
react on it. Returning from listen() on timeout can be suboptimal, though,
as it involves registration/deregistration for events, including the risk
for missing events while not registered. So return a (None, None) tuple
instead on timeout, allowing the caller to periodically do other things
while staying registered for the events and continue in listen().

The timeout applies to the socket recv() for the start of the header, only,
so a message is either read in full or times out, avoiding the risk
of breaking message framing on the stream with partial reads.
2022-12-12 14:38:09 +01:00
Martin Willi 11b18f65b1 vici: Remove support for Python 2
Python 2 is dead and unmaintained for a while now. Time to stop carrying
on its support.
2022-12-12 14:38:09 +01:00
Tobias Brunner a2b1e06f07 vici: Base default soft lifetime on hard lifetime if configured
Depending on the configured hard lifetime the default soft lifetime
might not make sense and could even cause rekeying to get disabled.
To avoid that, derive the soft lifetime from the hard lifetime so it's
10% higher than the soft lifetime.

References strongswan/strongswan#1414
2022-12-12 14:24:50 +01:00
Tobias Brunner 9efd7d7e90 eap: Print vendor (PEN) names for vendor-specific EAP methods 2022-09-21 13:53:44 +02:00
Tobias Brunner f21ef43b0c vici: Ignore NULL message in raise_event()
There are a lot of calls like this:

  this->dispatcher->raise_event(this->dispatcher, "...", 0,
                                b->finalize(b));

However, if finalize() fails, e.g. because a previous call to add()
failed due to the size limit, it returns NULL.  This then caused a
segmentation fault in raise_event() when it interacted with that value.

Closes strongswan/strongswan#1278
2022-09-20 10:15:13 +02:00
Tobias Brunner 8a57c2ab52 configure: Add an option to build with AddressSanitizer 2022-09-15 18:23:57 +02:00
Tobias Brunner 3af7c6db87 Rename diffie_hellman_t to key_exchange_t and change the interface etc.
This makes it more generic so we can use it for QSKE methods.
2022-06-29 10:28:50 +02:00
Tobias Brunner df18934d20 Replace or remove wiki.strongswan.org URLs 2022-06-28 13:33:51 +02:00
Tobias Brunner 19ef2aec15 Update copyright headers after acquisition by secunet 2022-06-28 10:22:56 +02:00
Tobias Brunner c9d471091f Use mallinfo2() if available
mallinfo() is deprecated because it uses `int` for the members of the
returned struct, whereas mallinfo2() uses `size_t`.  It's available
since glibc 2.33.
2022-04-25 14:16:20 +02:00
Tobias Brunner ec17fa2fef vici: Report registered KDFs 2022-04-14 18:54:24 +02:00
Tobias Brunner b1c7fac768 vici: Add options to only return specific CHILD_SAs in list-sas() 2022-04-14 18:42:01 +02:00
Tobias Brunner 2994347d18 vici: Report security label on CHILD_SA, policies and configs 2022-04-14 18:42:01 +02:00
Tobias Brunner 7cf6f29ac5 vici: Make security labels and mode configurable 2022-04-14 18:42:01 +02:00
Tobias Brunner c00c5e5a35 vici: Make combination of 'trap' and 'start' configurable 2022-04-14 18:42:01 +02:00
Tobias Brunner 4f4d4021b4 ike: Treat action_t as flags so 'start' and 'trap' can be combined
While combining the actions could cause duplicates (while the SA is
initiated, traffic might trigger the trap and the initiation of another
CHILD_SA), the previous commit should avoid most duplicates.  If reuse_ikesa
is disabled, duplicates can't be prevented, though.
2022-04-14 18:42:01 +02:00
Tobias Brunner e43052893d vici: Fix check before applying identity to public keys 2021-11-23 16:15:41 +01:00
Tobias Brunner b9aafa7ebf vici: Clear all request messages in case they contain secrets 2021-10-04 11:30:03 +02:00
Tobias Brunner 4bea9e8b60 vici: Clear cached strings in case the message contained shared secrets 2021-10-04 11:30:03 +02:00
Tobias Brunner a415761a8e vici: Update supported Python versions 2021-09-09 12:30:17 +02:00
Noel Kuntze fbd4930323 vici: Add DBG4 messages that print loaded shared keys and PINs
Closes strongswan/strongswan#217
2021-09-02 10:42:41 +02:00
Tobias Brunner de5609b297 vici: Use the more generic BUILD_BLOB to parse certificates/public keys 2021-08-23 17:59:39 +02:00
Andreas Steffen a09a905e1d vici: Suppress trailing nul character 2021-07-06 12:06:23 +02:00