Commit Graph
14601 Commits
Author SHA1 Message Date
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: 5ce1c91b58 ("ikev2: Trigger ike_updown() event after all IKE-specific tasks ran")
2023-11-06 10:41:57 +01:00
Andreas Steffen d6bfdf2b2b cert-enroll: Pack all source files into EXTRA_DIST 2023-10-26 15:15:37 +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 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
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
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: 00a75e332f ("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 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 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 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: b866ee88bf ("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
Tobias Brunner b7d7a6be3a pki: Make sure to wipe decrypted PKCS#7 data 2023-07-26 15:08:33 +02:00
Tobias Brunner bbbd15dd5c pkcs12: Make sure to wipe potentially decrypted PKCS#7 data 2023-07-26 15:08:33 +02:00
Tobias Brunner b4694aef49 pkcs7: Make sure to wipe decrypted content 2023-07-26 15:08:33 +02:00
Tobias Brunner ad8484a6cc aesni: Make sure to wipe salt 2023-07-26 15:08:33 +02:00
Tobias Brunner 9bda4a4415 ccm: Make sure to wipe salt 2023-07-26 15:08:33 +02:00
Tobias Brunner 0abb37b830 gcm: Make sure to wipe salt and H 2023-07-26 15:08:33 +02:00
Tobias Brunner e8f8d32494 charon-nm: Use configured interface name if available
If connection.interface-name is configured, we use that instead of the
randomly generated name.

References strongswan/strongswan#1747
2023-07-26 15:07:36 +02:00
Tobias Brunner 27a7537d10 charon-nm: Also log basic connection details 2023-07-26 15:07:22 +02:00
Tobias Brunner 69e0c1161d charon-nm: Actually use the created XFRM interface
The created XFRM interface was not actually used (no interface IDs on the
SAs, no routes via interface).  It was basically treated like the dummy
TUN device.  To actually install the routes via XFRM interface, we have
to create it before we install the SAs and policies, signal_ip_config()
happens too late.  We also have to mark the ESP packets the same as IKE
the packets to avoid a routing loop if the server's IP is included in
the remote traffic selector (in particular if it's 0.0.0.0/0 or ::/0).

Fixes: 58f278f932 ("charon-nm: Use an XFRM interface if available")
2023-07-26 15:07:22 +02:00
Tobias Brunner 36b1a6d76c Use Botan 3.1.1 for tests
The all-zero Ed25519 public key is rejected by botan_pubkey_check_key()
when the key is loaded.

Note that Botan 3 requires GCC 11 or CLANG 14, i.e. can't easily be built
on Debian bullseye or Ubuntu 20.04.

The thread-local storage function gets flagged via various botan FFI
functions when using Botan 3, whitelist that instead of all of them.
2023-07-26 13:09:22 +02:00
Tobias Brunner 55273157b0 libimcv: Add Debian 12 (bookworm) to database
Because libcrypto and libssl are measured, we need a new group for Debian
versions with OpenSSL 3 (I've rather added a suffix to the old group as
that could eventually get removed, although we might need a 3.1 variant
in the future - maybe we should measure some other files?).
2023-07-13 10:48:53 +02:00
Tobias Brunner fbc25f1c25 leak-detective: Whitelist C++'s __cxa_get_globals() 2023-07-13 10:48:53 +02:00
Tobias Brunner 2e88ab0069 dhcp: Fix warning with newer compilers 2023-06-19 14:56:24 +02:00
Tobias Brunner 8238ad480a resolve: Maintain order of DNS servers also when installing in resolv.conf
This always writes the complete set of DNS servers to make modifications
simpler.
2023-06-19 14:56:24 +02:00
Tobias Brunner 6440975bb4 resolve: Try to maintain the order of DNS servers if using resolvconf
Since 17fd304e60 ("resolve: Don't install individual servers via
resolvconf"), DNS servers were sorted if getting installed via resolvconf.
In some setups the order might be important (even though relying on it
isn't a good idea in general as stub resolvers are free to use all of
the servers as they please).
2023-06-19 14:56:24 +02:00
Tobias Brunner 2d1006963e charon-svc: Add missing closing parenthesis in version output 2023-06-19 14:55:48 +02:00