18914 Commits

Author SHA1 Message Date
Gerardo Ravago
7f1ba3cc68 openssl: Add conditional macros around SHA_CTX for AWS-LC
AWS-LC is a BoringSSL-based libcrypto implementation. SHA_CTX is declared with
the hash data specified as an array rather than as a field in upstream OpenSSL.
Since AWS-LC builds against C99, we are unable to handle this with anonymous
unions like BoringSSL. The workaround I propose is to add these conditional
macros around the accessors within openssl_sha1_prf. After this change,
everything builds successfully with AWS-LC headers.

Closes strongswan/strongswan#2103
2024-02-19 10:01:51 +01:00
Tobias Brunner
a7493ab57d pf-handler: Always free the object even if no socket has been opened yet 2024-02-19 09:49:08 +01:00
Dan James
187c72d1af dhcp: Port the plugin to FreeBSD/macOS
This also refactors the BPF handling so it can be shared between the
dhcp and farp plugins.  The latter is adapted accordingly.

Closes strongswan/strongswan#2047

Co-authored-by: Tobias Brunner <tobias@strongswan.org>
2024-02-19 09:17:53 +01:00
Tobias Brunner
10a876d54c github: Use new property to pass token for sonarcloud
sonar.login is deprecated.
2024-02-16 14:50:16 +01:00
Tobias Brunner
b940ce25e9 Merge branch 'ref-overflows'
Different users in the strongSwan code base use the refcount helpers to
allocate incrementing unique values. So far the risk of overflows for
these unsigned 32-bit values has been considered mostly theoretical, as
it requires a longer uptime and a lot of activity to hit such an overflow.

At least for the Netlink sequence numbers, this is not only theoretical,
though, and an overflow has been hit on a productive setup. Unfortunately,
the consequences are rather unpleasant, as the response with a zero
sequence number can't be matched to the request. This results in the
offending thread to block indefinitely while holding the Netlink mutex.

So add a helper to allocate incrementing unique identifiers that checks
for overflows and never returns 0. Use it for Netlink sequence numbers
and some other potential users affected, namely those allocating
IKE_SA/CHILD_SA unique identifiers, marks and interface identifiers.

Closes strongswan/strongswan#2062
2024-02-16 14:06:17 +01:00
Martin Willi
1a740bf3f3 child-sa: Handle refcount overflow for unique mark/if_id allocation gracefully
The refcount_t for allocating unique marks and interface IDs may overflow or
hit the special value for unique marks/if_ids, in the worst case not setting it
on CHILD_SAs that should have one.

As (potentially two) marks/if_ids are allocated only for newly created CHILD_SAs,
but not for rekeying, this not very likely. Still, if a setup uses
aggressive re-authentication and or re-creates CHILD_SAs every minute,
a gateway with 100'000 tunnels may hit the overflow within a month uptime.
2024-02-16 14:04:17 +01:00
Martin Willi
dde40bcb9e child-sa: Move unique mark allocation to a separate helper function
This aligns the code with unique interface ID allocation, which uses a helper
function for the same purpose and mechanic as well.
2024-02-16 10:42:43 +01:00
Martin Willi
4aac88fadd child-sa: Handle CHILD_SA unique identifier refcount overflow gracefully
CHILD_SA unique identifier allocation starts at 1. If the counter overflows,
a unique ID of 0 is assigned to an CHILD_SA, which may have unclear
consequences.

Overflowing the unique ID counter is theoretical for most setups, but on
a Gateway terminating 100'000 tunnels and rekeying CHILD_SAs every 60s
overflows the counter after a month uptime. So avoid a 0 unique identifier
by using ref_get_nonzero().
2024-02-16 10:11:11 +01:00
Martin Willi
f634a3300c ike-sa: Handle IKE_SA unique identifier refcount overflow gracefully
IKE_SA unique identifier allocation starts at 1. If the counter overflows,
a unique ID of 0 is assigned to an IKE_SA, which may have unclear consequences.

Overflowing the unique ID counter is theoretical for most setups, but on
a Gateway terminating 100'000 tunnels and rekeying the IKE_SA every 60s
overflows the counter after a month uptime. So avoid a 0 unique identifier
by using ref_get_nonzero().
2024-02-16 10:11:11 +01:00
Martin Willi
cdf865e0b8 kernel-netlink: Handle Netlink sequence number counter overflows gracefully
A refcount variable is used to allocate sequential unique identifiers for
Netlink sequence numbers, subject to overflows. The risk of an overflow
has so far not been considered practical, as it requires 2^32 netlink
requests.

It seems that this issue is not only theoretical. A host with thousands
of tunnels doing aggressive rekeying and/or aggressive status checking
(via vici list-sas) may trigger the overflow after a few weeks uptime.

The consequences are rather devastating: Once the refcount overflows, a
Netlink request is sent with sequence number 0. This request is answered
by the kernel, but can't be matched to the request, resulting in the error:
"received unknown netlink seq 0, ignored". Without Netlink timeouts, the
thread indefinitely waits for a response while holding the Netlink mutex,
bringing all threads to a halt.

So at all costs avoid zero sequence numbers. Also, start at sequence number
1 instead of the arbitrary 201, so the same range is used on start and after
an overflow.
2024-02-16 10:11:11 +01:00
Martin Willi
0cd46df377 atomics: Add a ref_get() variant returning non-zero on overflows
This is useful for users using ref_get() for unique identifier allocation,
but the zero value has special meaning.
2024-02-16 10:11:11 +01:00
Gerardo Ravago
31f55ba6e9 openssl: Add missing error checking when encoding ED private key
This applies the same logic found in other private key implementations
like that for ECDSA.

Closes strongswan/strongswan#2097
2024-02-14 17:57:41 +01:00
Florian Bezannier
e6176bf19c auth-cfg: Improve log message for identity constraint mismatch error
Closes strongswan/strongswan#2088
2024-02-12 10:25:23 +01:00
Tobias Brunner
0d61efdf02 github: Use NDK version in build.gradle to build OpenSSL
Also fix the path to the sdkmanager (the old one was removed in the latest
images and the incorrect path caused a weird sudo error) and install
Java 17 as that's necessary for newer versions of the Gradle plugin.
2024-01-16 11:01:01 +01:00
Tobias Brunner
980491ebcd android: Replace PowerMock with mechanism provided by newer Mockito versions
PowerMock isn't maintained anymore and causes issues with newer Java
versions.  We only used it to mock static methods, which Mockito now
supports as well.  Instead of using the try-with-resources construct,
this uses a @Before and @After method so we don't have to change all the
test methods.
2024-01-16 11:00:29 +01:00
Tobias Brunner
1cab544c75 android: Update Gradle plugin and build scripts and dependencies
This also references the NDK via ndkVersion and replaces the custom
ndk-build tasks.  It also replaces the deprecated compileSdkVersion and
increases it because dependencies of updated dependencies require that.

targetSdkVersion is not yet updated because there might be some work
required for Android 14 compatibility.
2024-01-16 11:00:29 +01:00
Tobias Brunner
be832378db github: Also run tests on macOS 13
Uses a newer version of clang and doesn't seem to have the issue with
process_t.
2024-01-16 11:00:29 +01:00
Tobias Brunner
2b74b63691 github: Increase timeout for process_t tests
This seems to be necessary on macOS 12 for some reason (note that handling
timeouts in these test cases doesn't really work).
2024-01-16 11:00:29 +01:00
Tobias Brunner
798e25f313 github: Use newer gperf version on macOS
The gperf version that's already available on the system generates
function declarations with K&R syntax (separate arguments) for which newer
compilers produce a warning as C23 doesn't support that syntax anymore.
2024-01-16 11:00:29 +01:00
Tobias Brunner
fea02fb297 simaka-crypto: Fix constructor declaration
Prototype didn't match the implementation.
2024-01-16 11:00:29 +01:00
Tobias Brunner
cb139ce4b3 cirrus: Use FreeBSD 14.0
FreeBSD 12.4 has been removed.
2024-01-16 11:00:29 +01:00
Tobias Brunner
52d6189892 unit-tests: Use function pointers to test generic return_* helper functions
These functions are declared without arguments, passing arguments to them
causes warnings such as the following with newer compilers:

  passing arguments to 'return_null' without a prototype is deprecated in all versions of C and is not supported in C2x [-Werror,-Wdeprecated-non-prototype]

We only use them via function pointers, which doesn't trigger any warnings
and hopefully continues to work.
2024-01-16 11:00:29 +01:00
Tobias Brunner
bf017a9d17 curl: Fix issue with printf checks in newer curl versions
Newer curl versions (as used on macOS via Homebrew) add attributes like

  __attribute__ ((format(printf, a, b)))

to their `curl_*printf*` functions, which fails if we redefine `printf`
as e.g. `builtin_printf` (pulled in via library.h).  We could disable
these checks via CURL_NO_FMT_CHECKS, but reordering the headers should
do the trick as well.
2024-01-16 11:00:29 +01:00
Tobias Brunner
67f0990530 Suppress compiler warnings with specific bison and compiler combinations
Bison generates code that only increases the yynerrs counter, it's never
read.  This causes a warning in newer compilers (in particular clang).
Newer versions of bison mark yynerrs with __attribute__((unused)), but
at least on FreeBSD 14 that's not yet available.
2024-01-16 11:00:29 +01:00
Tobias Brunner
22fc539edd leak-detective: Add implementation of malloc_usable_size()
systemd seems to use this and if we indirectly use libraries provided
by it, which can e.g. happen via getgrnam_r() and nss-systemd, this may
be called on pointers returned by leak detective's malloc(), which will
not point to the original start of the block and cause a segmentation
fault.

Closes strongswan/strongswan#2045
2024-01-16 10:59:59 +01:00
Tobias Brunner
f3578d3de8 Merge branch 'linux-strongswan'
Closes strongswan/strongswan#2026
2023-12-14 11:30:08 +01:00
Tobias Brunner
fff2996a22 ipsec: Remove mention of NETKEY stack 2023-12-14 11:27:25 +01:00
Tobias Brunner
7550463d51 Replace some other mentions of "Linux strongSwan" 2023-12-14 11:27:19 +01:00
Jose Luis Duran
454069e094 ipsec: strongSwan is not exclusive to Linux kernels
The project is now called "the strongSwan project" rather than "Linux
strongSwan" to better reflect this.
2023-12-09 18:42:27 +00:00
Andreas Steffen
c8ef91c786 Version bump to 5.9.13 5.9.13 2023-12-01 07:26:22 +01:00
Andreas Steffen
04794e703d Version bump to 5.9.13rc1 5.9.13rc1 2023-11-25 17:16:59 +01:00
Tobias Brunner
b4a9058b61 Merge branch 'ocsp-fixes'
Fixes a regression with handling OCSP error responses and adds a new
option to specify the length of nonces in OCSP requests.  Also adds some
other improvements for OCSP handling and fuzzers for OCSP
requests/responses.

Closes strongswan/strongswan#2011
2023-11-24 17:44:45 +01:00
Tobias Brunner
9c4846cdbe x509: Make sure the status in OCSP responses has the correct length 2023-11-24 17:41:18 +01:00
Tobias Brunner
ebf5afcefa fuzz: Add fuzzing targets for OCSP requests/responses 2023-11-24 17:41:18 +01:00
Tobias Brunner
f3af1704d9 x509: Make length of nonces in OCSP requests configurable
Some servers might not support a length of 32 and return a malformed
request error. Lowering the value to the previous default of 16 could
help in that case.
2023-11-24 17:41:18 +01:00
Tobias Brunner
945be4ece5 pki: Generate internal error OCSP response if no signer certificate is found
That can happen if a request is sent to the wrong OCSP server.
2023-11-24 17:41:18 +01:00
Tobias Brunner
05a1f5b9c5 certificate-printer: Add some output for empty OCSP responses 2023-11-24 17:41:18 +01:00
Tobias Brunner
6d345b3dde revocation: Reject OCSP error responses
Otherwise, there is lengthy code that tries to validate such responses,
even though they don't contain any signatures.
2023-11-24 17:41:18 +01:00
Tobias Brunner
b3e66aca5c x509: Add getter for status of OCSP responses 2023-11-24 17:41:18 +01:00
Tobias Brunner
e7a58f46f9 x509: Correctly parse responderId as ASN.1 CHOICE in OCSP response
The two OPTs that were used previously allowed to omit it completely (hence
the fallback to ID_ANY), but that's invalid, so it's better to fail
parsing.
2023-11-24 17:41:18 +01:00
Tobias Brunner
585c40095a x509: Correctly handle missing responder ID when parsing OCSP response errors
The has_issuer() and issued_by() methods relied on it to be defined, so
if the OCSP response wasn't successful (i.e. OCSP status indicates an
error and no OCSP response is parsed), a null-pointer dereference was
caused if the caller checked if the OCSP response was issued by a
specific certificate.

That's a side-effect of the referenced commit.  Previously, error codes
caused the OCSP response to not get parsed successfully, which technically
wasn't correct as it's well formed and successfully parsed, it's just
indicating an error state.

Fixes: 00ab8d62c089 ("x509: Support generation of OCSP responses")
2023-11-24 17:41:18 +01:00
Andreas Steffen
da45cf9f38 cert-enroll: Set the environment variables needed by cert-install-ssl 2023-11-23 19:05:22 +01:00
Andreas Steffen
11dbc8e7f2 Version bumpt to 5.9.12 5.9.12 2023-11-20 12:10:34 +01:00
Tobias Brunner
46aa264430 NEWS: Add info about CVE-2023-41913 2023-11-17 17:24:35 +01:00
Tobias Brunner
96d7937189 charon-tkm: Validate DH public key to fix potential buffer overflow
Seems this was forgotten in the referenced commit and actually could lead
to a buffer overflow.  Since charon-tkm is untrusted this isn't that
much of an issue but could at least be easily exploited for a DoS attack
as DH public values are set when handling IKE_SA_INIT requests.

Fixes: 0356089d0f94 ("diffie-hellman: Verify public DH values in backends")
Fixes: CVE-2023-41913
2023-11-17 17:24:34 +01:00
Tobias Brunner
74ae71d2b8 x509: Ensure extensions are encoded even if others are missing
As with the previous commit, this is probably never an issue in practice
as most certificates contain at least one SAN.
2023-11-15 17:08:46 +01:00
Tobias Brunner
ba08e01b86 x509: Also encode extendedKeyUsage in cert requests if there are no SANs or certificate type
Probably never was an issue in practice as most certificates contain at
least one SAN.
2023-11-15 17:01:02 +01:00
Tobias Brunner
14cc5b845e pki: Mention --index in description 2023-11-15 15:16:51 +01:00
Tobias Brunner
0dbb6867d8 NEWS: Add news for 5.9.12 2023-11-15 14:14:49 +01:00
Tobias Brunner
724e64cac4 Move ocsp_responder_t interface as it's not a certificate 2023-11-14 10:35:47 +01:00