18395 Commits

Author SHA1 Message Date
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
ebb99484e3 leak-detective: Whitelist selinux_check_access() 2022-04-14 18:42:01 +02:00
Tobias Brunner
2dd60e4946 sec-label: Add enum for security label mode 2022-04-14 18:42:01 +02:00
Tobias Brunner
decfe44433 sec-label: Add class to represent security labels
In accordance with SELinux, we include the null-terminator in the encoding
for now.
2022-04-14 18:42:01 +02:00
Tobias Brunner
fe5f27336d configure: Add option to link against libselinux 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
7137fd96c2 enum: Add helper to parse enum flags from strings
Individual flag names are separated by |.
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
93d8177674 cirrus: Use FreeBSD 12.3
This should fix this error thrown by autoreconf:

ld-elf.so.1: /usr/local/lib/perl5/5.32/mach/CORE/libperl.so.5.32: Undefined symbol "strerror_l@FBSD_1.6"
2022-04-14 18:38:43 +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
Tobias Brunner
d8104b7c69 receiver: Add per-IP cookie threshold
Because the global cookie threshold is higher than the per-IP block
threshold, it was previously possible for an attacker to block a legitimate
user by sending spoofed IKE_SA_INIT packets from that user's IP.

The timespan for requiring cookies is now also not extended anymore with
every IKE_SA_INIT received during the calm down period.  Because this
allowed an attacker, after initially triggering the global cookie threshold,
to force cookies for all clients by sending just a single spoofed
IKE_SA_INIT every 10 seconds.

We keep track of reaching the per-IP threshold in segments of the hashed
IP addresses, so only a (random, due to chunk_hash()'s random key) subset
of clients will receive cookies, if single IPs are targeted.

The default global threshold is increased a bit.
2022-04-14 15:28:07 +02:00
Tobias Brunner
902fbd16e8 receiver: Use a time based limit to switch COOKIE secrets
If we are under attack and there are lots of requests, we might hit
the previous use count limit pretty quickly and may switch secrets multiple
times a second, which renders the 10 second default lifetime of COOKIEs
pointless and prevents legitimate clients from sending requests with valid
COOKIEs.
2022-04-14 15:28:07 +02:00
Tobias Brunner
63260a11ca lgtm: Fix query for chunk_from_chars()
`Block` has apparently been deprecated and renamed to `BlockStmt` a while
ago.  Support for `Block` was recently removed completely.
2022-04-14 15:28:07 +02:00
Tobias Brunner
3c028686de traffic-selector: Avoid out-of-bound array access when calculating range
This happens for `/0` subnet masks.  In practice, it's not an issue because
if `bytes` is 0, then so are `netbits`, `bits` and `mask`.  So the two
incorrectly addressed array elements are not actually modified.  The first
operation is a `&= 0xff` and the second a `|= 0`, so nothing changes.
But some tools might not consider the values and report this as undefined
behavior, which it technically is.
2022-03-16 11:54:34 +01:00
Tobias Brunner
8100f2f255 Merge branch 'pfkey-exclude-routes'
Avoid unnecessary exclude routes on FreeBSD where these can cause problems.

Closes strongswan/strongswan#890
2022-03-15 14:04:19 +01:00
Tobias Brunner
8a76c5af8a kernel-pfkey: Don't install exclude routes for locally connected peers
Such routes with a gateway that equals the peer's address are problematic
on FreeBSD.  And since there is most likely a narrow route for the local
subnet anyway, the exclude routes would be redundant.
2022-03-15 13:52:24 +01:00
Tobias Brunner
5de6ab82a6 kernel-pfkey: Only install exclude route if not routing via outbound interface
When installing routes based on remote traffic selectors, it can be
necessary to install an exclude route for the remote peer to avoid a
routing loop and continue to be able to reach it via IKE/ESP.

However, such routes are only necessary, if the routes we install don't
go via outbound interface.  That's the case when using VIPs and routing
via TUN devices, or when using internal source IPs and routing via
their interfaces.

Installing such exclude routes if not necessary can cause issues on
FreeBSD (EINVAL when sending packets to the peer).
2022-03-15 13:52:24 +01:00
Leon Romanovsky
012e4cd902 kernel-netlink: Remove unimplemented XFRM_OFFLOAD_IPV6 flag
The XFRM_OFFLOAD_IPV6 flag was never implemented in the kernel and there
are no plans to do so.

Kernel patch: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=7c76ecd9c99b6e9a771d813ab1aa7fa428b3ade1

Closes strongswan/strongswan#916
2022-03-14 15:48:21 +01:00
Andreas Steffen
b2cf5af192 README: Added link to docs.strongswan.org 2022-03-02 21:55:43 +01:00
Tobias Brunner
c8045f86a3 testing: Increase memory on winnetou even more 2022-03-01 10:10:37 +01:00
Tobias Brunner
2ade4311bc tls-server: Use correct error alerts if client doesn't send a certificate
TLS 1.3 defines a specific alert for this and for TLS 1.2, RFC 5246,
section 7.4.6 defines handshake_failure as correct response.
2022-03-01 10:05:26 +01:00
Tobias Brunner
3eecd40cec openssl: Don't unload providers
There is a conflict between atexit() handlers registered by OpenSSL and
some executables (e.g. swanctl or pki) to deinitialize libstrongswan.
Because plugins are usually loaded after atexit() has been called, the
handler registered by OpenSSL will run before our handler.  So when the
latter destroys the plugins it's a bad idea to try to access any OpenSSL
objects as they might already be invalid.

Fixes: f556fce16b60 ("openssl: Load "legacy" provider in OpenSSL 3 for algorithms like MD4, DES etc.")
Closes strongswan/strongswan#921
2022-02-24 15:03:09 +01:00
Tobias Brunner
e69438450f Use wolfSSL 5.2.0 for tests 2022-02-22 09:35:01 +01:00
Tobias Brunner
9e3978259e mgf1: Fix Doxygen group for XOF implementation 2022-02-17 16:34:56 +01:00
Tobias Brunner
963adc7637 xof: Fix typo in documentation for set_seed() 2022-02-17 16:34:56 +01:00
Tobias Brunner
eccfd27f03 tls-peer: Simplify identity check for server certificate
has_subject() already matches the identity against the subject DN and
all the SANs (it actually already did when this check was added with
c81147998619 ("Strictly check if the server certificate matches the TLS
server identity")).
2022-02-15 16:54:39 +01:00
Tobias Brunner
42704f6a61 tls-test: Add option to specify a specific remote identity 2022-02-15 16:54:39 +01:00
Tobias Brunner
e4b4aabc49 libtls: Enforce client/server identity when looking for public key
The client already enforces that the server identity is contained in the
received certificate.  But on the server, the referenced commit changed
the lookup from the configured (or adopted if %any was configured) client
identity to the subject DN of the received client certificate.  So any
client with a trusted certificate was accepted.

Fixes: d2fc9b0961c6 ("tls-server: Mutual authentication support for TLS 1.3")
Closes strongswan/strongswan#873
2022-02-15 16:53:25 +01:00
Tobias Brunner
3f7d40d3b5 Merge branch 'natd-fixes'
This adds some modifications to NAT-D in case the source IP can't be
determined before generating NAT-D notifies.  If this happens when using
IPv4, a local NAT is faked (UDP-encap can be disabled later via MOBIKE
if no NAT is actually detected).  If it happens when using IPv6, NAT-T
is disabled completely.

It also removes the old fallbacks for source NAT-D notifies, which were
generally unused but could lead to incorrect results in the above
scenario.

Closes strongswan/strongswan#861
2022-02-15 16:38:31 +01:00
Tobias Brunner
011de0fe0d ike-natd: Queue DPD after faking local NAT to check if UDP-encap can be disabled 2022-02-15 16:09:26 +01:00
Tobias Brunner
90b1d09e42 ike-mobike: Make task a no-op if MOBIKE is not supported
This allows queuing such a task before IKE_AUTH has been processed.
2022-02-15 16:09:26 +01:00
Tobias Brunner
aaa505dbf0 ike-natd: Fake NAT situation or disable NAT-D if source IP is undetermined
This can happen if an IKE_SA is initiated to a static IP before DHCP is
done.  Instead of failing the initiation, we either fake a NAT situation
(for IPv4) or disable NAT-D (for IPv6 where NATs and UDP-encap are not
widely used or supported).

This also removes the old fallbacks to determine the source address(es).
A source address lookup is done in ike_sa_t::resolve_hosts() (wasn't the
case initially) and enumerating local IPs (which was added even earlier)
could still lead to issues if e.g. LAN addresses are available but the
WAN address that's later used is not yet (in which case only the responder
would detect a NAT and UDP-encap would be configured asymmetrically).

To force UDP-encap locally in case there is no actual NAT, we store this
as COND_NAT_HERE instead of COND_NAT_FAKE.  This ensures DPDs will contain
NAT-D notifies and we can later remove the state via MOBIKE.  We trigger
a MOBIKE update after such a DPD by registering a changed NAT mapping after
checking for a disappearing local NAT, which is very unlikely to happen
outside of a MOBIKE update (where that flag is not checked).
2022-02-15 16:09:26 +01:00