Commit Graph
4327 Commits
Author SHA1 Message Date
Tobias Brunner 4de8b81dea keymat_v2: Fix error message if KDF can't be created
Fixes: f619b833ac ("keymat_v2: Use plugin-provided KDF_PRF to derive SKEYSEED")
References strongswan/strongswan#1026
2022-05-06 11:45:10 +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 f4d6539b49 ikev2: Maintain labels during make-before-break reauthentication 2022-04-20 14:45:41 +02:00
Tobias Brunner f619b833ac keymat_v2: Use plugin-provided KDF_PRF to derive SKEYSEED 2022-04-14 19:02:56 +02:00
Tobias Brunner 743b486118 unit-tests: Hand out an actual shared secret and pubkey in mock KE implementation
Makes this a bit more realistic and makes key derivation via OpenSSL's
HKDF work during tests.
2022-04-14 19:02:56 +02:00
Tobias Brunner 9cb3c10418 keymat_v1: Derive CHILD_SA keys without using prf_plus_t
We already expand skeyid_e in a similar fashion so do this analogous
without relying on prf_plus_t.
2022-04-14 19:02:56 +02:00
Tobias Brunner 7161c87617 keymat_v2: Use plugin-provided prf+ to derive keys 2022-04-14 19:02:56 +02:00
Tobias Brunner 742134c112 keymat_v2: Refactor CHILD_SA key derivation so it only needs one prf+ call 2022-04-14 18:54:24 +02:00
Tobias Brunner 00cfc05467 keymat_v2: Refactor IKE key derivation so it only needs one prf+ call 2022-04-14 18:54:24 +02:00
Tobias Brunner ec17fa2fef vici: Report registered KDFs 2022-04-14 18:54:24 +02:00
Tobias Brunner 07bf428ad1 stroke: List 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 f52e565ad3 kernel-netlink: Forward labels from acquires 2022-04-14 18:42:01 +02:00
Tobias Brunner 0a673794d8 trap-manager: Add support to handle acquires with security labels 2022-04-14 18:42:01 +02:00
Tobias Brunner 81c362829e kernel-handler: Log security label received with acquire 2022-04-14 18:42:01 +02:00
Tobias Brunner 52a05d7f6c kernel-interface: Optionally pass security label with an acquire 2022-04-14 18:42:01 +02:00
Tobias Brunner 3f3838d1f9 ike-sa: Accept optional security label when initiating CHILD_SAs 2022-04-14 18:42:01 +02:00
Tobias Brunner 92f54e55e9 child-rekey: Maintain security label during rekeying 2022-04-14 18:42:01 +02:00
Tobias Brunner b00a4e778f selinux: Add plugin to install trap policies with generic labels
After establishing an IKE_SA, we check if any of its child configs
define generic SELinux labels and install trap policies for them if
necessary narrowed to the current (virtual) IPs.
2022-04-14 18:42:01 +02:00
Tobias Brunner 065685dde7 ike-sa: Add helper to determine an IKE_SA's dynamic hosts 2022-04-14 18:42:01 +02:00
Tobias Brunner 3c65cf6456 trap-manager: Add facility to install externally managed trap policies
This allows managing trap policies outside of the trap manager.

We'll use this to create trap policies with generic labels if trap policies
can't (or won't) be used (e.g. as responder for roadwarriors).
2022-04-14 18:42:01 +02:00
Tobias Brunner 8f4cfe9669 child-sa: Allocate a new reqid if dynamic traffic selectors are updated
If update_sa() is called and dynamic traffic selectors are changed using
new addresses, this might cause issues if we continue to use a reqid that
doesn't match the updated traffic selectors.  For instance, if the initiator
then uses make-before-break reauth from the new IP.  It's also a particular
problem in the SELinux case where multiple CHILD_SAs with specific labels
all share the same (trap) policy with generic label.  However, SAs created
after the update would not match due to the new reqid.
2022-04-14 18:42:01 +02:00
Tobias Brunner 96ecc39cd0 kernel-netlink: Allow reqid updates for policies again
This was originally added with 1551d8b13d ("kernel-netlink: reject
policy refcount if the reqid differs").  Since then we added code to
allocate constant reqids for the same TS, which pretty much avoids the
previous issues.

However, the reqid might have to be changed due to MOBIKE updates. And
because reqids are allocated for a complete set of traffic selectors and
not individual pairs, this can create a problem with drop policies as
those will use the old reqid (they are installed with the same priority,
reqid etc. to replace the actual IPsec policies), while unmodified
replacement policies will use the new one.  A similar issue exists for
CHILD_SAs with SELinux contexts as those all use duplicate policies (same
generic label) but can't all be updated concurrently.
2022-04-14 18:42:01 +02:00
Tobias Brunner 1b3af3e37d kernel-interface: Add support to change the reqid in update_sa() 2022-04-14 18:42:01 +02:00
Tobias Brunner 1f060357f4 kernel-wfp: Use new UDP ports in update_sa() 2022-04-14 18:42:01 +02:00
Tobias Brunner 9619b1e757 child-sa: Support dynamically updating trap policies 2022-04-14 18:42:01 +02:00
Tobias Brunner f9b895b49f child-create: Add support to handle security labels
With SELinux and without a specific label from an acquire, we abort
establishing the CHILD_SA (for the first one we prefer a childless IKE_SA,
but since that's a separate extension, we fall back to letting the initial
CHILD_SA fail as we won't propose a label).

If trap policies are not installed already (e.g. because it's impossible to
do so like as responder for roadwarriors), this will require installing
them dynamically once the IKE_SA is established.
2022-04-14 18:42:01 +02:00
Tobias Brunner 7a8d110863 child-create: Consider security label when comparing CHILD_SAs 2022-04-14 18:42:01 +02:00
Tobias Brunner 139d655817 child-sa: Add support for security labels
In SELinux mode we install the configured label on the policies and the
negotiated one on the SAs.  This is how it usually is configured where the
policy/configuration has a generic context and the SAs will get the actual
context of the flows assigned (the latter matches the former, so flows
match the policies but will trigger an acquire if no matching SA exists).

In the simple mode we don't pass the label to the kernel and to avoid
duplicate policy errors we also don't use it to acquire unique reqids.
2022-04-14 18:42:01 +02:00
Tobias Brunner 6cb83c305e kernel-interface: Optionally consider security label when allocating reqids 2022-04-14 18:42:01 +02:00
Tobias Brunner 03729958db peer-cfg: Consider security labels when selecting child configs 2022-04-14 18:42:01 +02:00
Tobias Brunner 63d4bd071f child-cfg: Add method to select a security label 2022-04-14 18:42:01 +02:00
Tobias Brunner ef72ac88c3 child-cfg: Add optional security label and mode 2022-04-14 18:42:01 +02:00
Tobias Brunner bf0542c4e1 kernel-netlink: Add support for optional security label on SAs and policies 2022-04-14 18:42:01 +02:00
Tobias Brunner c4e2b7617f encoding: Remove unused TS_TYPE and ADDRESS encodings 2022-04-14 18:42:01 +02:00
Tobias Brunner f4c0ec0b71 ts-payload: Add support for TS of type TS_SECLABEL
The security labels can be retrieved in a separate list from the
regular traffic selectors.  We currently only plan to support a single
security label ourselves, so when generating we don't expect a list.
2022-04-14 18:42:01 +02:00
Tobias Brunner a44de0b957 traffic-selector-substructure: Add support for TS_SECLABEL
Changes how regular address range traffic selectors are parsed as the
IKE parser currently doesn't provide sub-type parsing.

Also removed a lot of unused method definitions.
2022-04-14 18:42:01 +02:00
Tobias Brunner d71d181d28 traffic-selector: Add TS_SECLABEL type 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 927103ece4 enum: Allow specifying the name used when none of the flags are set 2022-04-14 18:42:01 +02:00
Tobias Brunner a5430e1601 child-create: Abort initiating a duplicate CHILD_SA
This could happen if an acquire is triggered while we respond to a
CREATE_CHILD_SA request from the peer, or if an acquire is triggered
while an IKE_SA (with its existing CHILD_SAs) is reestablished (also
with break-before-make reauthentication).  Also catches multiple
manual initiations.

Note that this ignores the traffic selectors from acquires (narrowing to
them seems rare in practice anyway).

Duplicates can still get created if e.g. both peers initiate them
concurrently.
2022-04-14 18:42:01 +02:00
Tobias Brunner 511033b3da child-create: Just abort CREATE_CHILD_SA request if nonce creation fails
No need to send an illegal request with just an error notify.
2022-04-14 18:42:01 +02:00
Tobias Brunner 3b699c720f kernel-listener: Use a struct to pass data from acquires 2022-04-14 18:42:01 +02:00
Tobias Brunner 9983326b20 kernel-netlink: Read protocol of acquire not from template
If a policy with IPComp template triggers an acquire, we get two, one for
an IPComp, one for ESP/AH SA.  However, the triggering template of the trap
policy (where we get the reqid from), will be the same in both acquires,
IPComp, which we ignore, so no acquire was actually forwarded.
2022-04-14 18:42:01 +02:00
Tobias Brunner 7f30e1aea2 ike-sa: Use a struct to pass optional arguments when initiating CHILD_SAs 2022-04-14 18:42:01 +02:00
Tobias Brunner 366ac36a1f ike: Don't reset optional CHILD_SA properties when migrating child-creating tasks
These are set via methods, which are not called again after migration
(e.g. when retrying due to INVALID_KE or when moving queued tasks), so we
don't want to clear these values.
2022-04-14 18:42:01 +02:00
Tobias Brunner b866ee88bf ike: Track unprocessed initial IKE messages like half-open IKE_SAs
This should make the DoS limits (cookie_threshold[_ip] and block_threshold)
more accurate so that it won't be possible to create lots of jobs from
spoofed IP addresses before half-open IKE_SAs are actually created from
these jobs to enforce those limits.

Note that retransmits are tracked as half-open SAs until they are
processed/dismissed as the check only happens in checkout_by_message().

Increasing the count in process_message_job_create() avoids issues with
missing calls to track_init() before calling checkout_by_message() (e.g.
when processing fragmented IKEv1 messages, which are reinjected via a
process message job).
2022-04-14 15:28:07 +02:00