18817 Commits

Author SHA1 Message Date
Tobias Brunner
c923022733 child-delete: Correctly maintain allocated reqid when recreating CHILD_SA
The old CHILD_SA is destroyed even before the new task is queued, this
makes sure we always maintain a reference to the reqid.
2023-11-13 12:02:11 +01:00
Tobias Brunner
c2a4c8e38a ike-sa: Correctly maintain allocated reqid when recreating CHILD_SA
Maintaining the reqid when recreating a CHILD_SA from scratch night not
strictly be necessary as we usually don't have to replace any temporary
states in the kernel.  However, there could be concurrent acquires that
might actually make it necessary (we use the reqid to keep track of
acquires and it's also part of the duplicate check).
2023-11-13 12:02:11 +01:00
Tobias Brunner
f2bc526dbb ikev1: Only set reqid on rekeyed CHILD_SA if it was allocated dynamically 2023-11-13 12:02:11 +01:00
Tobias Brunner
bc39a3aecb child-rekey: Only set reqid on new CHILD_SA if it was allocated dynamically
Keeping a reference ensures that if the old SA expires before the new
one is installed, the previous reqid isn't reallocated to a concurrently
established CHILD_SA with different selectors.
2023-11-13 12:02:11 +01:00
Tobias Brunner
4ea739baf4 quick-mode: Maintain reference to reqid while CHILD_SA is established 2023-11-13 12:02:11 +01:00
Tobias Brunner
4bfd93b8db child-create: Maintain reference to reqid while CHILD_SA is established 2023-11-13 12:02:11 +01:00
Tobias Brunner
ff269f7f1f child-sa: Add method that returns a reference to an allocated reqid 2023-11-13 12:02:11 +01:00
Tobias Brunner
13771206d4 child-sa: Keep a reference to the previous reqid
The reference is kept until the reqid is either confirmed (i.e.
re-allocated) or replaced by a different reqid, which happens only once
we know the final traffic selectors, or the SA is destroyed without
installing it.
2023-11-13 12:02:11 +01:00
Tobias Brunner
e623f5792b kernel-interface: Add method to increase refcount for allocated reqid 2023-11-13 12:02:11 +01:00
Tobias Brunner
02180ae2ff kernel-interface: Remove unnecessary parameters for release_reqid()
These are not included in the initial lookup anymore. Also simplified
the implementation as we always add the same entry to the two hash
tables.
2023-11-13 12:02:11 +01:00
Tobias Brunner
90cf0078e1 kernel-interface: Use reqid as sole key in hash table
Every reqid is allocated once, we don't store the same reqid with e.g.
different marks or interface IDs that would make it necessary to make
them part of the key in that table (that's different in the other table).

To preserve the current behavior, that is, allocating a new reqid if e.g.
the marks are different, the additional selector values (which will
result in an additional policy in the Linux kernel) are compared after
the initial lookup.
2023-11-13 12:02:11 +01:00
Tobias Brunner
04c17ab56a credential-manager: Add option to reject trusted end-entity certificates
This allows preventing peers from authenticating with certificates
that are locally trusted, in particular, our own local certificate (which
safeguards against accidental reuse of certificates on multiple peers).

On the other hand, if this option is enabled, end-entity certificates
for peers can't be configured anymore explicitly (e.g. via remote.certs
in swanctl.conf).
2023-11-13 12:01:41 +01:00
Andreas Steffen
28ccdff692 cert-enroll: Preventing some errors that might occur 2023-11-13 11:57:51 +01:00
Andreas Steffen
f328ef0e04 cert-enroll: Install TLS client/server credentials
Install the generated key, host certificate and associated CA certificates
as credentials for a TLS-protected client-server connection.
2023-11-13 11:57:51 +01:00
Tobias Brunner
b5e4bf4b6c tls-server: Also change DH group when selecting a different EC curve
If we initially selected a group the peer doesn't support (e.g. because
curve25519 is the first ECDH group provided by plugins), then found
a supported curve, we previously still instantiated a DH object for the
original group and might have formatted the parameters incorrectly.
2023-11-06 11:00:51 +01:00
Tobias Brunner
595fa077b6 ike-sa: Fix handling of redirects during IKE_AUTH
Since the referenced commit, the state switch to IKE_ESTABLISHED doesn't
happen immediately after completing the authentication but only after
the remaining tasks have finished.  Due to that redirects during IKE_AUTH
were treated like those during IKE_SA_INIT causing the IKE_SA and task
manager to get reset.  However, unlike the ike-init task, the ike-auth
task returned SUCCESS and, therefore, got destroyed, while a different
task was removed from the array that was modified during the reset.
This later caused a dereference of the freed ike-auth task and a crash.

Fixes: 5ce1c91b58a2 ("ikev2: Trigger ike_updown() event after all IKE-specific tasks ran")
2023-11-06 10:41:57 +01:00
Tobias Brunner
46c012b664 github: Use latest Sonar scanner 2023-11-03 09:28:51 +01:00
Tobias Brunner
eda91911fa Use wolfSSL 5.6.4 for tests 2023-11-03 09:28:51 +01:00
Andreas Steffen
51872a0a0c Version bump to 5.9.12dr2 5.9.12dr2 2023-10-30 22:42:55 +01:00
Andreas Steffen
d6bfdf2b2b cert-enroll: Pack all source files into EXTRA_DIST 2023-10-26 15:15:37 +02:00
Tobias Brunner
b576024387 Merge branch 'reject-explicit-ecdsa'
There is a relatively recent NIAP requirement to reject certificates with
ECDSA keys that explicitly encode the curve parameters (TD0527, Test 8b).

Since explicit encoding is pretty rare (if used at all and e.g. wolfSSL
already rejects it, by default), we should follow that requirement and
just reject such keys/certificates completely.

This currently can be enforced in all crypto plugins except when using
older versions of OpenSSL (< 1.1.1h) and Botan (< 3.2.0).

Closes strongswan/strongswan#1949
References strongswan/strongswan#1796
2023-10-13 09:12:02 +02:00
Tobias Brunner
bb14a28671 unit-tests: Add a test case for explicit ECDSA parameters
Currently only warns about it as older OpenSSL versions (AppVeyor)
don't reject them.
2023-10-13 09:10:46 +02:00
Tobias Brunner
578b561a22 Use Botan 3.2.0 for tests
This includes a change that allows checking EC keys for explicit
param encoding.
2023-10-13 09:10:46 +02:00
Tobias Brunner
0b989c7b20 botan: Reject EC keys with explicitly encoded parameters
This requires a function that will be added in the upcoming Botan 3.2
release.
2023-10-13 09:10:46 +02:00
Tobias Brunner
2bccdefc2c openssl: Reject EC keys with explicitly encoded parameters
EC_KEY_decoded_from_explicit_params() was added with 1.1.1h but has been
deprecated with 3.0.
2023-10-13 09:10:46 +02:00
Tobias Brunner
a69184fb9d wolfssl: Reject EC keys with explicitly encoded parameters
These are not allowed in X.509 certificates according to RFC 5480 and
some newer validations apparently explicitly check for this.

Note that WolfSSL rejects such keys, by default.  Only when compiled with
WOLFSSL_NO_ASN_STRICT are they accepted.
2023-10-13 09:10:46 +02:00
Andreas Steffen
6f0cd19fd6 cert-enroll: Fixed path in cert-install-openxpki 2023-10-12 08:14:38 +02:00
Tobias Brunner
b56c264041 cirrus: Use FreeBSD 12.4
FreeBSD 12.3 is officially EOL.
2023-10-09 15:22:41 +02:00
Tobias Brunner
7e2e463285 cirrus: Use FreeBSD 13.2
This should fix an error thrown by bison:

 ld-elf.so.1: /lib/libc.so.7: version FBSD_1.7 required by /usr/local/bin/bison not found
2023-10-09 15:22:41 +02:00
Andreas Steffen
7dfb88ead2 Version bump to 5.9.12dr2 5.9.12dr1 2023-10-04 08:15:54 +02:00
Andreas Steffen
cbfc12b330 cert-enroll: certificate checking and enrollment
The cert-enroll script handles the initial enrollment of an X.509
host certificate with a PKI server via the EST or SCEP protocols.

Run as a systemd timer or via a crontab entry the script daily
checks the expiration date of the host certificate. When a given
deadline is reached, the host certificate is automatically renewed
via EST or SCEP re-enrollment based on the possession of the old
private key and the matching certificate.
2023-10-03 08:45:22 +02:00
Tobias Brunner
80e27fe9fd ike-sa: Destroy CHILD_SAs in order
This works around an issue that occurs when recreating an IKE_SA with
multiple CHILD_SAs that use dynamically allocated reqids.

We currently try to preserve the reqid when reestablishing, so the
create-child task gets the reqid of the previous CHILD_SA and will try
to reallocate that once the CHILD_SA is installed.  Before that, the old
CHILD_SA is destroyed and the reqid is released and added to the array
of reqids to get reused.  However, because of the reverse order used here,
the first reqid in the array is the one of the last CHILD_SA.

So it can happen that a newly created CHILD_SA gets a reqid reassigned
that a later CHILD_SA will then also claim for itself and get assigned
because an entry with that reqid exists.  So multiple CHILD_SAs with
different traffic selectors could then share the same reqid.

References strongswan/strongswan#1855
2023-09-28 09:41:53 +02:00
Boi Sletterink
190d8cbe19 libipsec: Also install routes without preferred source to forward traffic
Fixes a problem installing policies with source traffic selectors that do
not contain/match any of the local addresses.

When installing a route for a source TS that does contain one or more
local addresses, a preferred source address should be set in the route
(analogous to the `src` option in `ip route add`). This address is used
when the host itself sends traffic via that route (in contrast to
forwarding it).

When the source TS does not encompass any of the local addresses, the
host is not allowed to send traffic via this route and does not need to
set the preferred source address. However, the code would just return a
failure because it could not find a matching local address. This commit
changes this so routes without preferred source IP are installed to
allow non-local traffic to get forwarded via TUN device.

Closes strongswan/strongswan#1766
2023-09-04 16:54:37 +02:00
Antony Antony
cdc34ddea2 configure: Fix in6_pktinfo auto detection
This commit fixes auto detection of in6_pktinfo.
When negotiating an IPv6 IKE session charon reported an error

"Jun 30 16:42:49 03[NET] error reading IP header"

The cause of error was missing in6_pktinfo declaration, which is
auto detected. This auto detection may fail with an error depending
on compiler flags:

configure:19850: checking for in6_pktinfo
configure:19870: gcc -c -g -O0 -Wall -Wno-format -Wno-format-security
-Wno-pointer-sign -Werror -Wfatal-errors -Wno-error=stringop-truncation
conftest.c >&5
conftest.c: In function 'main':
conftest.c:73:11: error: 'pi.ipi6_ifindex' is used uninitialized in this
function [-Werror=uninitialized]
   73 |     if (pi.ipi6_ifindex)
      |         ~~^~~~~~~~~~~~~
compilation terminated due to -Wfatal-errors.
cc1: all warnings being treated as errors

Signed-off-by: Antony Antony <antony.antony@secunet.com>
2023-09-04 14:31:19 +02: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: 00a75e332f29 ("vici: Create default TCP socket on Windows in Python bindings")
Closes strongswan/strongswan#1874
2023-08-31 11:39:52 +02:00
Tobias Brunner
e2bba1e2cf android: New release after updating target SDK to 33 android-2.4.2 2023-08-29 18:35:57 +02:00
Tobias Brunner
dfbafffc45 android: Increase compile-/targetSdkVersion to 33 (Android 13) 2023-08-29 18:03:30 +02:00
Tobias Brunner
ddf84c165d android: Request permission to display notifications on Android 13
Note that displaying the notification for the background service is
apparently not strictly necessary.  So it's fine if the user wants to
hide it.  That the service is running can still be seen in the task
manager (pull down the status drawer twice, there is a bullet with a number
at the bottom if the service is running).

Simply use the system dialog.  If the user denies it twice, it won't show
up again.  The explanation dialog would not show up the first time (i.e.
shouldShowRequestPermissionRationale() returns false), only once the user
denied the permission once.  Currently seems like a bit much work
as we don't need the user to allow notifications.
2023-08-29 18:03:30 +02:00
Tobias Brunner
3839bcfe87 android: Compile OpenSSL with hardware acceleration 2023-08-29 18:03:30 +02:00
Tobias Brunner
6d87a86510 android: Use new sockets to determine source IP
Particularly on Samsung devices, the connect() call to dissolve the
previous connection on an existing socket via AF_UNSPEC does fail in
some situations with ECONNREFUSED:

  [KNL] failed to disconnect socket: Connection refused

While creating a new socket is potentially a bit more overhead, this
should avoid the issue.

Closes strongswan/strongswan#1691
2023-08-29 18:03:30 +02:00
Tobias Brunner
5005c2e4ab testing: Use pip from venv to download dependencies
pip3 isn't installed in the base image anymore since 21bf3e41f94a
("testing: Use venv for strongTNC").
2023-08-28 17:49:26 +02:00
Tobias Brunner
a619356b5f kernel-pfroute: Maintain virtual flag when repopulating interface addrs
When adding a virtual IP on a TUN interface, the interface might get
activated (in terms of receiving the event) after we've already set the
virtual flag for the added address.  As the activation repopulates the
addresses on the interface, this cleared the flag and the address would
no longer be treated as virtual IP when installing routes for CHILD_SAs
that reference it in their local traffic selectors.

Closes strongswan/strongswan#1807
2023-07-27 08:21:26 +02:00
Tobias Brunner
006839b06a Merge branch 'netlink-buf'
Fixes an infinite loop if e.g. Netlink event sockets get too many
packets queued and poll() just returns POLLERR for the socket.  Also
increases the default receive buffer size for Netlink sockets to better
support systems with lots of route updates.

Closes strongswan/strongswan#1757
2023-07-26 15:16:57 +02:00
Tobias Brunner
ba9228ab00 watcher: Change handling of POLLERR and remove WATCHER_EXCEPT
We can't actually explicitly listen for errors by passing POLLERR in
`events` (the man page for poll() clearly states it's ignored).  On the
other hand, POLLERR can be returned for any FD and, even worse, it might
be the only event indicated.

The latter caused an infinite loop as we didn't notify the callback nor
clear the error by calling `getsockopt(..., SOL_SOCKET, SO_ERROR, ...)`.
And while the latter would be able to reset the state to break the loop,
it seems to leave the FD in a defunct state where no further events will
be returned by poll().  Notifying the callback works better (the error
is then reported by e.g. recvfrom()) and automatically happened already
if POLLERR was returned together with e.g. POLLIN.

So we now treat POLLERR like the other error indicators we handle (POLLHUP
and POLLINVAL) and just notify the callbacks.
2023-07-26 15:14:50 +02:00
Tobias Brunner
5971fc36c9 kernel-netlink: Also set the receive buffer size on event sockets
This was weirdly overlooked and could cause issues e.g. on hosts with
lots of route changes.
2023-07-26 15:14:50 +02:00
Tobias Brunner
714c939018 kernel-netlink: Increase the default receive buffer size
Also simplify how we try to exceed the system-wide maximum.  We basically
just try to force the value and simply fall back to the regular call.
The kernel actually won't let the latter fail if the value is too big,
it just caps it at the internal maximum.
2023-07-26 15:14:50 +02:00
Tobias Brunner
0b47357091 ike: Fix untracking IKE_SA_INITs with non-zero MIDs and SPIs as half-open SAs
We track all IKE_SA_INIT requests as half-open IKE_SAs but didn't
correctly untrack them if their message ID or responder SPI was non-zero.

References strongswan/strongswan#1775

Fixes: b866ee88bf54 ("ike: Track unprocessed initial IKE messages like half-open IKE_SAs")
2023-07-26 15:13:43 +02:00
Tobias Brunner
849c2c9707 child-rekey: Correctly encode protocol/SPI in CHILD_SA_NOT_FOUND notify
As specified in RFC 7296, section 2.25:

   The SA that the initiator attempted to rekey is indicated by the SPI
   field in the Notify payload, which is copied from the SPI field in
   the REKEY_SA notification.

So we copy that and the protocol verbatim.
2023-07-26 15:09:49 +02:00
Tobias Brunner
10a3c44a41 notify-payload: Add methods to simplify encoding and retrieving IKE SPIs
The get_spi_data() method is currently not used, so that has been
simplified so it can be used for any protocol type and any SPI length.
Same for set_spi_data(), which is currently used for IKEv1 to encode
two SPIs.
2023-07-26 15:09:49 +02:00
Tobias Brunner
e0e99c1dd3 sha3: Make sure to wipe the internal Keccak state 2023-07-26 15:08:33 +02:00