Commit Graph
1858 Commits
Author SHA1 Message Date
Tobias Brunner 80f8f5e9d4 key-exchange: Rename function that verifies pubkey lengths
The previous name confused LLMs as they assume it is intended to actually
cryptographically verify the public key.  The new name more clearly
describes what it actually does.
2026-07-24 08:47:37 +02:00
Tobias Brunner 1fbb14884c botan: Remove confusing documentation for DH helper function
This comment only referred to not calling `key_exchange_verify_pubkey()`,
not what Botan does, which will verify the passed public value as needed.
LLMs get confused by this and assume Botan doesn't so that.
2026-07-24 08:47:37 +02:00
Tobias Brunner 11999f1679 mysql: Be more explicit when parsing database URI but don't log password
This avoids logging the password that's potentially contained in the URI
and also gives clearer instructions about what's missing.

Also clears the memory that stores the URI/password.
2026-07-24 08:47:37 +02:00
Tobias Brunner 1487dbb4a3 pgp: Log parsed packet data on level 4 as it may contain a private key 2026-07-24 08:47:37 +02:00
Tobias Brunner 14a811b6af curve25519: Explicitly wipe shared secret when destroying DH object 2026-07-24 08:47:37 +02:00
Tobias Brunner 929065826b sqlite: Fix transaction handling for multiple concurrent threads
Due to the shared database connection, the previous code, while tracking
transaction metadata per thread, didn't actually enforce that separation
on the database level.  Which basically meant the transactions created
by multiple threads were shared.

This change uses an approach similar to the mysql plugin, using a pool of
connections.  However, we always use thread-specific connections, not
only during transactions.  That's because the implicit transactions
that are active in SQLite during queries block further queries from
other connections while enumerating (the pool utility uses such patterns).

It also fixes the issue that calling `rollback()` on the outer-most
transaction didn't have an effect.

Since it's very unlikely SQLite was built in single-thread mode and
handling that properly would require locking the mutex during
transactions, we remove that locking and move the check to the constructor
to refuse initialization.

Fixes: fad11d602d ("sqlite: Implement transaction handling")
2026-07-24 08:47:36 +02:00
Tobias Brunner 2eeb8965ed pkcs11: Fix ECDH derivation
The referenced commit moved the key derivation to `get_shared_secret()`
and broke the handling of ECDH public value as the copied struct now
referred to a buffer allocated on the stack.

Also fixes potential session leaks if generating key pairs fails.

Fixes: 26ca0c9f70 ("pkcs11: Move shared secret calculation to get_shared_secret()")
2026-07-24 08:47:36 +02:00
Tobias Brunner 75baeb9f35 constraints: Fallback to binary OIDs in log messages
Similar to the previous commit.
2026-07-24 08:47:36 +02:00
Tobias Brunner fe6dc7d256 af-alg: Fix output offset if not all data was processed during en-/decryption
If only parts of the total data could be written to the kernel, the result
of the next read chunk would incorrectly get written at the beginning of
the output buffer again.

Also makes sure to close the accepted FD in error cases.

Fixes: 1b5de7ce3b ("Use a generic AF_ALG wrapper for common operations")
2026-07-24 08:47:35 +02:00
Tobias Brunner 7bf9b6bad8 x509: Avoid memory leak if multiple nonce extensions are found in OCSP response 2026-07-23 10:26:08 +02:00
Tobias Brunner 45b2f8d91f revocation: Avoid that a skipped CRL lookup/fetch prevents fetching delta CRLs
If we find a stale CRL in the cache and finding a newer one via
CRLIssuer fails for some reason, the validation state would get
overwritten with VALIDATION_SKIPPED.  This would then prevent
fetching delta CRLs.

Fixes: 7d7beaa1fa ("Use certificate CRLIssuer information to look up cacched CRLs or CDPs")
2026-07-23 10:26:08 +02:00
Tobias Brunner 355d591967 openssl: Fix memory leak if HMAC instantiation fails late
Fixes: db0c53c207 ("openssl: Fixes for HMAC with OpenSSL 3.0")
2026-07-23 10:26:08 +02:00
Tobias Brunner 589a3a6729 curve25519: Reject all-zero shared secrets
While RFC 7748 states implementations MAY perform such a check, e.g.
TLS 1.3 explicitly requires it (RFC 8446, section 7.4.2).

Fixes: 7f9bfacd5a ("curve25519: Add a plugin providing Curve25519 DH using backend drivers")
2026-07-23 10:26:08 +02:00
Tobias Brunner d9cf1b0bff wolfssl: Avoid potential RNG state corruption during RSA/ECDSA operations
The WC_RNG instances are potentially shared between different threads
as private key objects are refcounted.  This may corrupt their internal
state as they are not thread-safe.

For ECDSA, using separate instances for each signing operation has some
performance impact, but for signature operations that should be fine.

The implementation for RSA uses mutexes.  That's due to the weird API.
While RNG instances can be passed for signing and encryption (probably
because they are also required for padding/salt besides blinding), they
can't for verifying and decryption.  The latter use an RNG instance that
has to be set on the key object before calling these operations.  So we
could potentially split the strategy, but to keep this consistent within
the RSA implementation, just continue with the shared RNG but use a
mutex around the API calls.

Fixes: c92eade82c ("wolfssl: Add wolfSSL plugin for cryptographic implementations")
2026-07-23 10:26:07 +02:00
Tobias Brunner 05625acc2a wolfssl: Ensure X25519/X448 public key is valid 2026-07-22 18:20:12 +02:00
Tobias Brunner 1fe813f05e wolfssl: Fix memory leak on failed ICV verification if not using in-place decryption
Fixes: c92eade82c ("wolfssl: Add wolfSSL plugin for cryptographic implementations")
2026-07-22 18:20:12 +02:00
Tobias Brunner 023c626525 openssl: Fix memory leak on failed ICV verification if not using in-place decryption
Fixes: 81f9cd39fd ("openssl: Provide AES-GCM implementation")
2026-07-22 18:20:12 +02:00
Tobias Brunner c6adb20ec7 chapoly: Fix memory leak on failed ICV verification if not using in-place decryption
Fixes: 370fb3feb0 ("chapoly: Provide a generic ChaCha20/Poly1305 AEAD supporting driver backends")
2026-07-22 18:20:12 +02:00
Tobias Brunner 85c02dc16c ccm: Fix memory leak on failed ICV verification if not using in-place decryption
Fixes: 80a93a1335 ("Implemented a ccm plugin providing CCM mode based on CBC crypters")
2026-07-22 18:20:12 +02:00
Tobias Brunner 40aa0a12c4 botan: Fix memory leak on failed ICV verification if not using in-place decryption
Fixes: af26cc4d85 ("botan: Add Botan plugin to libstrongswan")
2026-07-22 18:20:12 +02:00
Tobias Brunner a2f83d3075 aesni: Fix memory leak on failed ICV verification if not using in-place decryption
The `aead_t` interface states that `decrypt()` only allocates a plaintext
buffer if successful, so callers might not free it if the call failed.

Fixes: 313811b72d ("aesni: Add a GCM AEAD based on the AES-NI key schedule")
2026-07-22 18:20:12 +02:00
Tobias Brunner 87bbfe4f5f gcm: Implement block multiplication in constant time 2026-07-21 10:37:43 +02:00
Tobias Brunner b3c0019c84 pgp: Fix validity calculation and potential overflow
The two fields were swapped in the calculation and the new code also
avoids overflowing on 32-bit systems.

Fixes: 4cb0e1bb76 ("Added basic support for PGP certificates (no trust relationships yet)")
2026-07-21 10:37:43 +02:00
Tobias Brunner 24c70db4b9 aesni: Split plugin to avoid potential SIGILL
Because the CFLAGS applied to the whole plugin, the compiler could
"optimize" the boilerplate plugin code, which could then cause a SIGILL
on hardware that doesn't support such instructions.  This change makes
sure only the actual AES implementation is compiled like that, which
would then not get registered depending on the CPU feature detection.
2026-07-21 10:21:51 +02:00
Tobias Brunner 98b133c54c wolfssl: Adapt to removed ML-KEM header
The mlkem.h header that mainly defined aliases for the old wc_Kyber* API
has been removed and its contents moved to the wc_mlkem.h header.
2026-06-26 08:10:16 +02:00
Tobias Brunner 531de4d858 pkcs7: Fail parsing PKCS#7 signed-data if content can't be parsed
This avoids a crash after verifying the signed attributes in the signature
enumerator.
2026-06-01 18:21:43 +02:00
Tobias Brunner bff405c349 oid: Fix confusing identifiers for elliptic curves over prime fields
SECT (indicating a binary field) was incorrectly used in constants for
the SECP (prime field) curves.
2026-05-28 13:30:07 +02:00
Tobias Brunner a26dd3da33 openssl: Check that EC keys don't have explicit params for internally loaded keys
Keys loaded via generic loader (KEY_ANY) or from a PKCS#12 file (or an
engine) don't go through the openssl_ec_private_key_load() constructor
that checks for explicit parameters.
2026-05-19 17:27:33 +02:00
Tobias Brunner ab19f691c7 botan: Fix registration of ECDSA signature/verification plugin features
This was broken since the Botan 3 release, which removed the EMSA1
class and the define.  The "EMSA1()" wrapper when signing/verifying is
technically not necessary anymore since then (it's deprecated but still
accepted).  But to still support Botan 2, we keep that in for now.
2026-05-19 17:27:33 +02:00
Tobias Brunner 8ff3238027 openssl: Prevent OpenSSL from using posix_memalign() if LD is enabled
The leak detective doesn't wrap this function and calling the original
causes unknown memory frees and even segmentation faults.  This is now
triggered with OpenSSL 4 as the implementation of ECP256 uses
OPENSSL_aligned_alloc_array().

Setting a custom memory functions forces OpenSSL to implement aligned
allocations internally, using the registered allocation function.
2026-05-06 10:46:43 +02:00
Tobias Brunner 374b17fe88 openssl: Fix 'const' issues that came up with OpenSSL 4 2026-05-06 10:46:43 +02:00
Tobias Brunner 528e5f07c3 openssl: Use functions for ASN.1 struct members hidden in OpenSSL 4
According to the docs, most ASN.1 types are just typedefs of ASN1_STRING.
2026-05-06 10:46:43 +02:00
Thomas Egerer 82c01b7060 openssl: Use openssl_i2chunk when creating ASN.1 chunks
Using the return value of i2d_* directly as input of chunk_alloc imposes
the risk of creating an invalid chunk when the return value of the i2d_*
function is -1. The openssl_i2chunk macro is meant to avoid this.

Signed-off-by: Thomas Egerer <thomas.egerer@secunet.com>
2026-05-06 10:46:43 +02:00
Tobias Brunner b4ba8a6fb5 openssl: Fix memory leak if ipAddrBlock is non-canonical 2026-04-22 14:12:12 +02:00
Tobias Brunner e2fa67e8fc gmp: Avoid crash and timing leaks in PKCS#1 v1.5 decryption padding validation
This fixes a potential crash due to a null-pointer dereference if rsadp()
returns NULL (e.g. with an all-zero ciphertext).

And it also implements the PKCS#1 v1.5 decryption padding check in
constant time.

The timing leak caused by the previous implementation was measured at
~17.5 μs at 3 GHz, which could allow a Bleichenbacher-like attack in
LAN environments.  However, because of how RSA encryption is used in
strongSwan, this is not that much of an issue in practice.  The mechanism
is only used for two use cases.  One is SCEP/EST via PKCS#7 enveloped
data.  Fortunately, this can not be triggered in significant numbers by
an attacker.  The other use case is TLS as used by EAP methods (EAP-TLS,
EAP-PEAP/TTLS) during the authentication.  While the cipher suites that
use RSA encryption are still enabled by default, the TLS messages are
wrapped in EAP and encrypted by IKE, making any kind of attack difficult.

Note that the gmp plugin isn't enabled anymore by default.  And even
before that, most setups had the openssl plugin enabled, which has
priority over the gmp plugin.  So it's unlikely the plugin was used in
practice.

Fixes: d615ffdcf3 ("implement gmp_rsa_private_key.decrypt()")
Fixes: CVE-2026-35334
2026-04-21 16:48:56 +02:00
Tobias Brunner 8dae5605a7 pkcs7: Avoid NULL pointer dereference when verifying padding in enveloped content
As the previous issue, this can be triggered via IKEv1 CERT payloads.

Fixes: d7aa09104f ("Implement PKCS#7 enveloped-data parsing and decryption")
Fixes: CVE-2026-35329
2026-04-21 16:48:56 +02:00
Tobias Brunner 64130ede5c constraints: Reject excluded directoryName (DN) name constraints
There is an issue similar to the one fixed with the previous commit when
using directoryName (DN) name constraints.  Some RDNs have to be matched
in a case-insensitive manner, which we e.g. do in
`identification.c::rdn_equals`.  By not doing it for name constraints,
a malicious intermediate CA could evade an excluded name constraint
just by modifying the case in such an RDN.

While we could use the mentioned function in `dn_matches`, this doesn't
properly fix the problem because the function is basically too strict.
Especially in regards to RDNs of type UTF8String, which are only compared
binary.  To match these properly, we'd have to implement the string
preparation described in RFC 5280, section 7.1 and the referenced RFCs.
Until that's the case, we reject excluded name constraints of type
directoryName as we are unable to enforce them.

Fixes: a2b340764f ("Implemented NameConstraint matching in constraints plugin")
Fixes: CVE-2026-35331
2026-04-21 16:48:56 +02:00
Tobias Brunner c66143db48 constraints: Match FQDN and email addresses case-insensitively
The case is generally ignored when matching such identities.  So this is
an issue with excluded name constraints where a malicious intermediate
CA could evade the constraints by issuing certificates with names that
just modify the case (e.g. strongSwan.org instead strongswan.org).

Note that it's likely that permitted name constraints are preferred over
excluded name constraints as it might be difficult to come up with a
conclusive list of names to exclude.

Fixes: a2b340764f ("Implemented NameConstraint matching in constraints plugin")
Fixes: CVE-2026-35331
2026-04-21 16:48:56 +02:00
Markus Theil c60a14ba23 botan: Fix typo in algorithm string for SHA3-224 RSA verification
Signed-off-by: Markus Theil <markus.theil@secunet.com>
2026-04-13 15:46:45 +02:00
Markus Theil fdd06d99ec botan: Make RNG types configurable
This allows for usage of ESDM or jitterentropy as Botan RNG without
patching strongSwan.

Signed-off-by: Markus Theil <markus.theil@secunet.com>
2026-04-13 15:12:31 +02:00
Tobias Brunner 05807b1b1b openssl: Handle EdDSA keys from engines special again
Fixes: 052a939553 ("openssl: Add support for Ed25519 via AWS-LC")
2026-04-02 08:17:05 +02:00
Tobias Brunner 7b0190cb26 revocation: Fix memory leak if nonce in OCSP response doesn't match 2026-04-02 08:17:04 +02:00
Tobias Brunner 3c637c7521 openssl: Fix return value if returning EdDSA public key fails 2026-04-01 19:33:09 +02:00
Tobias Brunner 358653d06a gmp: Reject public keys with public exponent e < 3
This ensures that we don't load a key with e=1, which basically renders
RSA into a no-op.  Since keys are universally generated with e=65537 and
no reputable CA will sign keys with e=1, allowing this before didn't have
any real world impact.
2026-03-13 09:28:32 +01:00
Tobias Brunner dd7b0283ef plugin-loader: Add option to change log message if plugin is not found
Distributions like Debian/Ubuntu ship the plugins in multiple packages
that are not all installed by default.  When running tools like pki or
swanctl, which don't use modular loading with config snippets by default,
there are errors in the output if these packages and plugins are
currently not available.  In order to not alarm users, this change adds
a configure option that package maintainers can use.  It causes the log
level of the message to increase and also adds a note that mentions that
plugins are potentially available in other packages (which should be the
case unless the user tried to load a plugin, e.g. via load statement,
that is not actually built and shipped by the package maintainers).
2026-02-06 11:21:34 +01:00
Tobias Brunner f79504994a agent: Fix compiler warning when building with clang
Fixes: 8b467ad39a ("agent: Add option to open socket as specific user")
2025-12-12 15:59:38 +01:00
Tobias Brunner 8b467ad39a agent: Add option to open socket as specific user
This can prevent an attack where user A passes the path to user B's
ssh-agent socket to the daemon that is running as root.
2025-12-10 18:34:19 +01:00
Martin Willi df6977d4cf revocation: Block only one thread per URL after a previous CRL fetch failed
If a CRL server is unresponsive, all threads trying to fetch this CRL will
block execution. If a recent previous attempt to fetch the CRL failed, it
is likely that it will fail again. While it makes sense to retry fetching
the CRL on demand with one thread, it hardly does to block additional
threads while the first one is blocked during the fetch.

So remember the timestamp of the last CRL fetch failure per URL, and do
not block more than one thread in the CRL fetch for some time. This time
is a multiple of the configured fetch timeout, so that it works well for
any configured value. With the default configuration, a failing CRL fetch
will impact concurrent CRL fetches for the same URL for 30s.
2025-11-13 18:15:15 +01:00
Martin Willi 330a7d1963 revocation: Synchronize CRL fetches of multiple threads to the same URL
When handling many connection attempts from peers using the same CA, a slow
or non-responsive CRL distribution point can lead to concurrent fetches of
the same CRL by multiple threads. This is not only inefficient, but results
in all threads blocking for the full fetch timeout, potentially blocking
all threads in the pool.

As a first step, synchronize CRL fetches using a global mutex and a per-URL
condvar, so threads can wait for the CRL if another is already fetching it.
This reduces the number of useless concurrent CRL fetches, and allows threads
joining the party late to get blocked only until the first fetch completes
or times out.

The URL entry is preserved in the hashtable after completing the fetch.
This will allow subsequent optimizations to store the last fetch result
and act accordingly. The CRL itself is not, as CRLs can be rather large
and caching them can be done using existing mechanisms controlled via
corresponding options.
2025-11-13 18:15:15 +01:00
Martin Willi 119dfc2c38 revocation: Move CRL/OCSP fetch operations to a dedicated fetcher helper
Before adding stateful CRL fetching extensions, refactor CRL fetching to
a helper class for better separation. While there are currently no plans
to extend OCSP fetching, move it as well for consistency.
2025-11-13 18:15:15 +01:00