Commit Graph
14467 Commits
Author SHA1 Message Date
Andreas Steffen 47e8b21c76 cert_cache: Replace cached stale OCSP responses in-place 2023-04-21 16:04:26 +02:00
Harald Gutmann 5284cecddc pki: Filter whitespace in base64 encoded EST responses
As clarified in RFC 8951, section 3.1 [1].

[1] https://www.rfc-editor.org/rfc/rfc8951#name-white-space-processing

Co-authored-by: Tobias Brunner <[email protected]>
Closes strongswan/strongswan#1616
2023-04-03 15:10:37 +02:00
Harald Gutmann f6dc47f591 pki: Add support for EST server label
As specified in EST RFC 7030, Section 3.1 [1].

[1] https://www.rfc-editor.org/rfc/rfc7030.html#section-3.1
2023-04-03 13:59:48 +02:00
Tobias Brunner b4e1863fa6 pki: Allow specifying signature scheme for PKCS#7 signatures
Also changed the error handling a bit so it is more like in the other
pki commands.
2023-03-31 09:11:20 +02:00
Tobias Brunner e2a2674476 pki: Unify parsing of RSA padding scheme and fix disabling PSS
If PSS padding is enabled by default, not all commands allowed disabling
it explicitly.
2023-03-31 09:11:17 +02:00
Tobias Brunner 47d9590556 openssl: Add support for CMS-style signatures in PKCS#7 (RSA-PSS, ECDSA) 2023-03-30 10:46:46 +02:00
Tobias Brunner 5e76bc1634 pkcs7: Add support for CMS-style signatures (RSA-PSS, ECDSA)
For the legacy schemes with rsaEncryption nothing changes, but if an
actual signature scheme is encoded we use that to find the key and
verify the signature.

The descriptions for the PKCS#7 structure are adapted for CMS.
2023-03-30 10:46:46 +02:00
Tobias Brunner 1326f805a8 asn1: Allow suppressing log messages when parsing algorithm identifiers 2023-03-30 10:46:46 +02:00
Tobias Brunner 4e73e9d3e9 botan: Pass n and e separately for RSA public keys
Some encoders, like those provided by the dnskey and sshkey plugins,
require these separately when encoding keys.

Also fixes the type for the ASN.1 encoding (which is a subjectPublicKeyInfo
structure) depending on the key type.  This worked fine for PEM encoding
as the pem plugin doesn't care what the actual type of the key is (which
is encoded in the SPKI structure), but other plugins do (e.g. the sshkey
plugin).
2023-03-30 10:45:04 +02:00
Tobias Brunner 7be55adf05 ipseckey: Add support for ECDSA and EdDSA public keys 2023-03-30 10:35:09 +02:00
Tobias Brunner 9e17a0ed88 revocation: Suppress some log messages for cached OCSP responses
We don't have any information on the issuer of cached OCSP responses, in
particular if the OCSP response is issued by a dedicated OCSP signer,
whose certificate might not be contained in the response or even signed
by the same CA but could just be locally installed.  So the only way to
determine if a response applies to the current certificate and its CA
is searching for the response's issuer certificate and verifying that.

However, when using multiple CAs that provide revocation checking via
OCSP, in particular with multi-level CAs (e.g. like the
ikev2-multi-ca/ocsp-signers test scenario), we might have unrelated OCSP
responses in the cache when verifying a particular certificate.  In this
case we don't need any confusing

  ocsp response verification failed, no signer certificate '...' found

error messages because the response was for a different CA.

Similarly, if lots of clients of the same CA connect there could be lots
of OCSP responses in the cache that, while being applicable to the current
CA, don't have any information on the certificate we are currently
checking.  In this case all the

  ocsp response correctly signed by "..."
  ocsp response contains no status on our certificate

messages don't provide any value.

In the mentioned test scenario, we suppress the

  ocsp response verification failed, no signer certificate 'C=CH, O=strongSwan Project, OU=Research OCSP Signing Authority, CN=ocsp.research.strongswan.org' found

message from the cached OCSP response for carol's end-entity certificate
when verifying the "Research" intermediate CA certificate that issued
carol's certificate.

Then the

  ocsp response verification failed, no signer certificate 'C=CH, O=strongSwan Project, OU=Research OCSP Signing Authority, CN=ocsp.research.strongswan.org' found
  ocsp response verification failed, no signer certificate 'C=CH, O=strongSwan Project, OU=OCSP Signing Authority, CN=ocsp.strongswan.org' found

messages from the cached OCSP responses for carol's end-entity and
intermediate CA certificates when verifying dave's end-entity certificate.

And finally the

  ocsp response verification failed, no signer certificate 'C=CH, O=strongSwan Project, OU=Research OCSP Signing Authority, CN=ocsp.research.strongswan.org' found
    ocsp response correctly signed by "C=CH, O=strongSwan Project, OU=OCSP Signing Authority, CN=ocsp.strongswan.org"
    ocsp response contains no status on our certificate
  ocsp response verification failed, no signer certificate 'C=CH, O=strongSwan Project, OU=Sales OCSP Signing Authority, CN=ocsp.sales.strongswan.org' found

messages from the cached OCSP responses for carol's end-entity
certificate, the applicable but unrelated response for carol's "Research"
intermediate CA certificate and the response for dave's end-entity
certificate when verifying dave's "Sales" intermediate CA.
2023-03-28 16:26:01 +02:00
Tobias Brunner 01ec54afc9 openssl: Only allow certificates with cRLSign keyUsage to sign CRLs 2023-03-21 16:34:14 +01:00
Tobias Brunner 7d1f221211 x509: Only allow certificates with cRLSign keyUsage to sign CRLs 2023-03-21 16:34:14 +01:00
Tobias Brunner d12a4f5d23 openssl: Set X509_CRL_SIGN for CA certificates without keyUsage extension 2023-03-21 16:34:14 +01:00
Tobias Brunner 7414c06669 x509: Set X509_CRL_SIGN for CA certificates without keyUsage extension 2023-03-21 16:34:14 +01:00
Tobias Brunner c9c76278c3 libradius: Link to winsock32 on Windows 2023-03-21 16:33:03 +01:00
Tobias Brunner 9b391f86fe eap-radius: Don't include socket.h explicitly
We rely on the includes via utils.h so this compiles on Windows.
2023-03-21 16:33:03 +01:00
Tobias Brunner 993dd54c8d windows: Fix compat define for sendto(2) 2023-03-21 16:33:03 +01:00
Tobias Brunner 8c0a67f700 kernel-wfp: Install bypass policies also on FWPM_SUBLAYER_IPSEC_TUNNEL sublayer
This is apparently necessary to bypass tunnel mode SAs/policies.

References strongswan/strongswan#1552
2023-03-21 16:30:09 +01:00
Tobias Brunner 8f5c0c9ca9 windows: Fix invalid pointer dereference when terminating service thread
When running as a service, the libraries are initialized/deinitialized
not by the main thread but by a separate thread that runs the registered
main service procedure.  When the service is stopped, the libraries are
deinitialized by that thread and the thread lock and hashtable are
destroyed.  But afterwards the DllMain callback is also triggered for
that thread so we have to prevent it from accessing these objects again.

References strongswan/strongswan#1567
2023-03-21 16:27:10 +01:00
Tobias Brunner e6a354a996 controller: Immediately return after re-initiating an existing IKE_SA childless
If no CHILD_SA is initiated, we wait for a state change to IKE_ESTABLISHED
but that will never happen for already established IKE_SAs.

References strongswan/strongswan#1553
2023-03-21 16:25:51 +01:00
Tobias Brunner dd79253e2d vici: Fix fallback to remote ID if no mediation peer ID is configured
Also adds error reporting via VICI for issues with mediation settings.

Fixes: 229cdf6bc8 ("vici: Order auth rounds by optional `round` parameter instead of by position in the request")
References strongswan/strongswan#1569
2023-03-21 16:21:48 +01:00
Tobias Brunner 3c8887326a dhcp: Don't use get_source_addr() to determine source address
That method is subject to interface filtering, which isn't ideal for
DHCP traffic that probably uses an internal interface on which the IKE
daemon might be disabled.  In that case `giaddr` is set to an incorrect
public IP, which in turn might prevent the plugin from receiving the
DHCP server's unicast response, in particular if the DHCP socket
is bound to the internal interface.

This new approach connects the client socket and thereby determines the
source address to reach the DHCP server.

Closes strongswan/strongswan#1573
2023-03-21 16:13:22 +01:00
Tobias Brunner 8bf683c469 pki: Fix enum for SCEP CA capabilities
As indicated by the comparisons and the parsing in scep_parse_caps()
this should be a bitmask.

Fixes: 7c7a5a0260 ("pki: Enroll an X.509 certificate with a SCEP server")
Closes strongswan/strongswan#1607
2023-03-21 16:11:49 +01:00
Tobias Brunner 3d0d3f5d02 eap-tls: Fix server implementation with TLS 1.2 and earlier
With 5401a74d36 ("eap-tls: Add support for TLS 1.3") a TLS application
was added to implement TLS 1.3's protected success indication.  For
earlier TLS versions, its build() method simply returned SUCCESS as
there was nothing to send.  However, that had the unintended side-effect
of also not sending the final TLS handshake messages (ChangeCipherSpec
and Finished).

The reason is that the TLS stack first checks for remaining handshake
messages but then also asks the registered application for data to
piggyback to that response (before the commit there was no application,
so that step was skipped).  The problem is that the status returned by
the application is directly forwarded through the TLS stack.  So not
returning INVALID_STATE caused the session to get concluded immediately
instead of resulting in ALREADY_DONE that would trigger sending the
final EAP message instead of an EAP-Success.

Fixes: 5401a74d36 ("eap-tls: Add support for TLS 1.3")
2023-03-21 16:11:49 +01:00
Tobias Brunner db87087fae tls: Only return EAP MSK if TLS handshake is complete
The MSK is generated when the keys are derived.  For TLS 1.3 that's also
when the handshake is complete.  However, for TLS 1.2 it happens when
generating or processing the ClientKeyExchange message, which, on the
client, happens before the final Finished handshake message has been
received from the server.  This caused the EAP-TLS client to accept an
EAP-Success message instead of the server's final TLS handshake
messages, unintentionally allowing servers to cut the exchange short by
two EAP messages (in the regular exchange the response to the server's
final handshake messages is an empty EAP-Response, which is then
followed by the server's EAP-Success).

While this is not correct, it does not seem to pose a security issue.
If DH is used as key exchange, the server signs the ServerKeyExchange
message and the client is sure to communicate with a trusted server
before it derives the MSK.  If RSA encryption is used as key exchange,
the client sends the premaster secret, on which the MSK is based,
encrypted with the server's public key (as extracted from the trusted
certificate).  An attacker won't be able to decrypt this and, therefore,
can't derive the same MSK to generate a valid AUTH payload and the IKE
authentication will fail.
2023-03-21 16:11:49 +01:00
Jean-Tiare Le BigotandTobias Brunner bb6174a4d1 vici: Generalize timeout support in Python bindings
Since 3dd5dc5011 ("Merge branch 'vici-python-timeout'"), any timeout
set directly on the socket is reset by `vici.Transport.receive()` unless
called by `vici.Session.listen()`. This prevents configuring a default
timeout directly on the socket.

However, setting a timeout directly on the socket also had drawbacks
since it can cause `vici.Transport.receive()` to raise a timeout error
while a subset of the data have been received, with no way to recover.

This commit merges both approaches by considering the timeout configured
on the socket by default (when no timeout is explicitly set) and
keeping the switch to blocking receive once the first byte has been
received. When the full expected data have been received, the timeout
configured on the socket is restored.

Co-authored-by: Tobias Brunner <[email protected]>
Signed-off-by: Jean-Tiare Le Bigot <[email protected]>

Closes strongswan/strongswan#1562
2023-03-10 09:10:44 +01:00
Tobias Brunner 8aa13a1797 eap-peap: Initiate Phase 2 immediately for TLS 1.3
Before TLS 1.3, the server sent the last handshake message and had the
option to piggyback the EAP-Identity request directly onto the packet
with the TLS Finished message, or wait for the empty message by the
client that acknowledges the completion of the handshake.  With TLS 1.3,
the client finishes the handshake after the server.  So this option
is irrelevant there and we immediately start with Phase 2.
2023-03-02 09:31:52 +01:00
Tobias Brunner 8e9b2bd27f pki: Add possibility to add/remove flags in requests when issuing certificates 2023-02-23 17:36:38 +01:00
Tobias Brunner 8325eeff06 pki: Allow overriding EKU flags from certificate request via command line
The flags encoded in the PKCS#10 structure (or derived from the encoded
profile name) might not be appropriate in some instances. This allows
overriding them without having to issue a new certificate request.
2023-02-23 16:55:57 +01:00
Tobias Brunner 501483b313 libvici: Fix Doxygen comment for vici_on_close()
Fixes: 9e5533fef9 ("libvici: Add callback invoked if connection is closed by daemon")
2023-02-22 14:33:34 +01:00
Tobias Brunner a5ba701783 swanctl: Fix Windows build of --monitor-sas command
Fixes: 4784c92c55 ("swanctl: Terminate --monitor-sa command if daemon closes connection")
2023-02-22 14:33:34 +01:00
Tobias Brunner 18d73a9a5c utils: Add counterpart to wait_sigint() to explicitly stop waiting 2023-02-22 14:33:34 +01:00
Tobias Brunner 58f278f932 charon-nm: Use an XFRM interface if available
This allows NM more freedom in regards to how it wants to use the passed
device.  In particular, if dnsmasq is used with NM as that binds to the
interface to send requests via VPN.

Installing the VIPs on lo avoids weird address removal/addition events
that happen for IPv6 on the physical interface (which would cause the VIP
to get incorrectly detected as non-VIP address and ignored during
deletion).

We could let NM install routes via XFRM interface, however, that causes
problems with e.g. the bypass-lan plugin (the throw routes in table 220
wouldn't have any effect).  We could let it install regular routes in
the main table, but determining the physical interface would be tricky
as the routes installed by NM, also in the main table, would conflict.

So instead we let the kernel-netlink interface install routes via XFRM
interface and to avoid routing the IKE traffic that way, we set a mark
on the IKE socket and exclude traffic with that mark from our routing
table.
2023-02-22 13:43:17 +01:00
Tobias Brunner 04486507b2 kernel-netlink: Add an option to install routes for SAs with XFRM interfaces
Since these might conflict with IKE traffic, this requires special care.
One option is to install bypass policies for the peer, which install
appropriate (throw) routes.  However, that won't work if the traffic to
the gateway itself should be protected, in particular, for host-to-host
tunnels.  So an alternative is to set a mark for the IKE socket and then
exclude that traffic from table 220 via the kernel-netlink plugin's
fwmark option.
2023-02-22 13:37:45 +01:00
Tobias Brunner 0cc780d317 kernel-netlink: Automatically bring up XFRM interfaces after creation 2023-02-22 13:37:45 +01:00
Tobias Brunner e1ff1eefcf kernel-netlink: Add manager for XFRM interfaces
The manager will allow charon-nm to create XFRM interfaces if supported
by the kernel instead of creating an unused dummy TUN interface.

The xfrmi tool is mostly obsolete nowadays as iproute2 supports creating
XFRM interfaces since 5.1.0 (2019-05).  Older Debians don't ship that and
early versions didn't list the interface IDs.  So there might still be
some uses for this tool.
2023-02-22 13:37:45 +01:00
Tobias Brunner 85d56b1c6a charon-nm: Tie lifetime of dummy TUN device to connection
NM doesn't terminate charon-nm after disconnecting, so the TUN device
previously stayed around even if no connection was established.  This
might be a bit more what users expect.
2023-02-22 13:37:45 +01:00
Tobias Brunner 5401a74d36 eap-tls: Add support for TLS 1.3
As defined in RFC 9190, a "protected success indication" (0x00) is sent
from the server to the client over the TLS connection when using TLS 1.3.

The client responds with an empty EAP message, which is interpreted as
acknowledgement in our stack.

If we ever support session resumption with tunneled methods such as
EAP-TTLS, we'd have to send such an indication there too.
2023-02-22 13:34:53 +01:00
Tobias Brunner 06abdf1d31 tls-crypto: Fix MSK calculation for TLS 1.3
As noted in 121ac4b9e3 ("tls-crypto: Generate MSK for TLS 1.3"), the
calculation was only preliminary.  It is now fixed according to RFC 9190
and draft-ietf-emu-tls-eap-types (soon to become an RFC, currently in
the RFC editor queue).

Fixes: 121ac4b9e3 ("tls-crypto: Generate MSK for TLS 1.3")
2023-02-22 13:34:31 +01:00
Tobias Brunner 346a050c36 kernel-netlink: Increase log level for dumped Netlink messages
Some of these contain key material so they should be logged on level 4.
2023-02-22 13:20:10 +01:00
Tobias Brunner 1138b629fb android: Announce support for TFC padding
Has been supported by libipsec for a long time (since 5.1.1).  UDP encap
is already enforced via config, this just makes the flags the same as
in kernel-libipsec.
2023-02-22 13:20:10 +01:00
Tobias Brunner e21290ec30 kernel-netlink: Read last use time from SA if possible
Since 6.2 the Linux kernel updates the last use time per SA.  In
previous releases the attribute was only updated and reported for
specific outbound IPv6 SAs.

Using this reduces the number of kernel queries per CHILD_SA: for DPDs
from two policy queries (IN/FWD) to a single query of the inbound SA,
and for status reports the three policy queries (IN/FWD/OUT) can be
omitted and only the two SAs have to be queried.  For NAT keepalives the
number of queries doesn't change but a policy query (OUT) is replaced by
a query for the outbound SA.

While we could use the existence of the attribute as indicator for its
support, we don't know this until we queried an SA.  By using a version
check we can announce the feature from the start.
2023-02-22 13:20:10 +01:00
Tobias Brunner 6301b880df child-sa: Query policies only if querying SAs doesn't update the use time 2023-02-22 13:20:10 +01:00
Tobias Brunner b9131c34d3 kernel-interface: Add feature to indicate if query_sa() returns last use time
Currently supported by libipsec and PF_KEY on macOS (FreeBSD, like Linux,
reports the time the SA was first used in sadb_lifetime_usetime - it also
triggers rekeyings based on that, which Linux doesn't, it also triggers
them if an SA is never used).
2023-02-22 13:20:10 +01:00
Tobias Brunner 1efdb0f791 ikev2: Add option to prefer childless IKE_SAs as initiator 2023-02-22 13:19:46 +01:00
Tobias Brunner 4784c92c55 swanctl: Terminate --monitor-sa command if daemon closes connection 2023-02-22 11:44:14 +01:00
Tobias Brunner 9e5533fef9 libvici: Add callback invoked if connection is closed by daemon 2023-02-22 11:44:14 +01:00
Tobias Brunner cbd69ec732 android: Update the README for the build via NDK 2023-02-20 14:11:59 +01:00
Tobias Brunner af93db93e6 android: New release after OpenSSL plugin fix 2023-02-17 16:59:13 +01:00