array: RFC: Another approach to fix the remove_at() issue
This is more efficient as it only requires a memcpy if remove_at is
actually called. But is could be problematic if the passed pointer is
assigned to another variable or otherwise passed around before remove_at
is called.
Tobias Brunner [Fri, 29 Aug 2014 07:36:57 +0000 (09:36 +0200)]
array: Fix array_remove_at() for non-pointer arrays
Because array_remove_at() or rather the called array_remove() may move
elements over the element at the currently enumerated position, simply
returning a pointer to that position for non-pointer arrays could result
in the pointer passed to enumerate() pointing to the previous or next
array element after the array_remove_at() call. The caller would thus
operate on the wrong element if the that pointer is accessed again before
calling enumerate().
This had an impact on auth_cfg_t where purge() may optionally keep CA
certificates (which is a feature used during multiple IKEv2 authentication
rounds), but due to this bug such certificates may still have been destroyed
while the pointer to them remained in the array, which then lead to
incorrect reference counts and eventually crashes.
Martin Willi [Mon, 4 Aug 2014 08:38:08 +0000 (10:38 +0200)]
unity: Do not bump TS to 0.0.0.0/0 as initiator when no Split-Include received
When having the unity plugin enabled and both peers send the Unity Vendor ID,
we proposed 0.0.0.0/0 as traffic selector, even if no Split-Include has been
received on the SA. This can break compatibility with some responders, as
they don't narrow the TS themselves, but expect the configured TS.
Martin Willi [Mon, 7 Jul 2014 08:42:11 +0000 (10:42 +0200)]
ikev1: Defer Mode Config push after CHILD adoption and reauth detection
When an initiator starts reauthentication on a connection that uses push
mode to assign a virtual IP, we can't execute the Mode Config before releasing
the virtual IP. Otherwise we would request a new and different lease, which
the client probably can't handle. Defer Mode Config execution, so the same IP
gets first released then reassigned during reauthentication.
Martin Willi [Fri, 11 Jul 2014 09:59:01 +0000 (11:59 +0200)]
ikev1: Accept Quick Mode DELETES while Quick Mode rekeying is active
If a peer immediately sends DELETE messages when completing Quick Mode rekeying,
the third Quick Mode message and the DELETE are sent simultaneously. This
implies that DELETE messages may arrive before the completing third Quick Mode
message.
Handle this case by ignoring the DELETE INFORMATIONAL in Quick Mode and let
the delete task handle it.
Martin Willi [Fri, 11 Jul 2014 12:40:56 +0000 (14:40 +0200)]
starter: Do not close all file descriptors after fork()
As we use libstrongswan and expect that it still works after the fork, we
can't just closefrom() all file descriptors. Watcher, for example, uses
a pipe to notify FDSET changes, which must be kept open.
ike-sa-manager: Use transient hasher for IKE_SA_INIT hash calculation
To check if a received IKE_SA_INIT request is a new request or a
retransmit, charon maintains hashes of the pending IKE_SA_INIT
exchanges.
However, the hash calculation is not reentrant because a single hasher
is used for the whole IKE SA manager. It leads to bogus calculations
under high load and hence dropped messages on responder
(IkeInInvalidSpi incremented).
Don't share a single hasher in the IKE SA manager, create a transient
one whenever a message must be hashed.
Martin Willi [Wed, 16 Jul 2014 14:44:24 +0000 (16:44 +0200)]
diffie-hellman: Explicitly initialize DH exponent sizes during initialization
To avoid any race conditions when multiple threads call and initialize
diffie_hellman_get_params(), explicitly examine the optimum DH exponent size
during library initialization.
Tobias Brunner [Tue, 19 Aug 2014 09:08:33 +0000 (11:08 +0200)]
kernel-pfroute: Fix kernel response handling
The condvar is signaled for every handled message received from the
kernel not only for replies (this changed with 2a2d7a4dc8). This may
cause segfaults because this->reply is not set when the waiting thread is
woken due to an IP address change.
Since this->reply is only set when it is actually the expected reply (and
only one request is sent at a time, thanks to c9a323c1d9) we only have
to make sure the reply is there (and clear it once we handled it).
Using separate condvars could also be an option in the future.
The package/library is called libjson-c on recent distributions.
Some like Ubuntu 14.04 provide symlinks with the old name but these
will eventually disappear. Using pkg-config allows us to easily check
for it (with a fallback) and configure the proper compiler flags.
Adds a DNS proxy feature that uses VPN-protected sockets to resolve the
VPN gateway's hostname while reestablishing the IKE_SA, which is
required because we keep the TUN device up to avoid leaking plaintext
traffic.
The TUN device is recreated without DNS servers before reestablishing in
case the VPN server pushed DNS servers to the client that are only
reachable via VPN.
android: Terminate IKE_SA if initial IKE_SA_INIT fails
Since VpnStateService.disconnect() is now not called until the error
dialog is dismissed the daemon would continue to try connecting.
So while the error dialog is shown the connection might actually be
successfully established in the background, which is not intended.
This way the IKE_SA is destroyed right after sending the IKE_SA_INIT of
the second connection attempt (due to keyingtries=0).
android: Add method to BuilderAdapter to re-establish without DNS-related data
Non-DNS data is cached in the BuilderAdapter so the TUN device can be
recreated easily (since the CHILD_SA is gone we couldn't actually gather
that information).
This class proxies DNS requests over VPN-protected UDP sockets.
It is not really Android specific and might be useful for
kernel-libipsec or libipsec in general too, so we could maybe move it later
to libipsec (might need some portability work).
The GUI reflects the state of the IKE daemon more closely by switching
back to the "connecting" state when the IKE_SA or CHILD_SA is down and
is getting reestablished.
android: Set CHILD_STATE_DOWN whenever the CHILD_SA goes down
No matter what triggers it. We also don't close the TUN device, but we
might handle that differently in the future to allow reestablishing the
IKE_SA if host names have to be re-resolved via DNS.
android: Change to CONNECTING state if CHILD_SA goes down
Unless we are disconnecting. This currently triggers the connecting
dialog, perhaps just updating the status text would do too (when switching
from CONNECTED to CONNECTING, not from DISCONNECTED to CONNECTING).
Adds support to import CA and server certificate directly in the app.
On Android 4.4 and newer the SAF allows users to easily browse for such
files, on older systems they have to open them from file manager or the
download app (only works if the MIME type is correctly detected).
Also adds support for ECDSA keys on recent Android systems.
Tobias Brunner [Thu, 5 Jun 2014 17:06:34 +0000 (19:06 +0200)]
android: Show a confirmation dialog before importing certificates
Since the import activity can be triggered by any other app on the
system we shouldn't just import every certificate we get.
Also, in some situations (e.g. if no passphrase has been set yet for the
system-wide certificate store) we are the only application that can open
certificate files. So if a user clicked on a certificate file she would
just get a confirmation Toast about a successful import, with no indication
whatsoever where the certificate was actually imported. The new dialog
shows the app icon to indicate that strongSwan is involved.
Martin Willi [Thu, 17 Jul 2014 07:32:22 +0000 (09:32 +0200)]
receiver: Send a single INVALID_MAJOR_VERSION notify for IKE version > 2
We sent both a notify using IKEv1 and IKEv2. This is a little more aggressive
than required, RFC 5996 says we "SHOULD send an unauthenticated Notify
message of type INVALID_MAJOR_VERSION containing the highest (closest) version
number it supports".
Martin Willi [Mon, 7 Jul 2014 13:49:04 +0000 (15:49 +0200)]
settings: Be more strict in converting settings to specific data types
As the behavior was inconsistent for empty strings or strings with characters
appended to a number, testing the code failed on some platforms. The new rules
are more strict, returning the default if additional characters or an empty
string was found for a setting.
Martin Willi [Mon, 7 Jul 2014 13:27:19 +0000 (15:27 +0200)]
enumerator: Enumerate glob(3) matches using gl_pathc
While glob should return a NULL terminated gl_pathv when having no matches,
at least on OS X this is not true when using GLOB_DOOFFS. Rely on the
number of matches returned in gl_pathc, which seems to be more reliable in
error cases.
Martin Willi [Fri, 4 Jul 2014 08:14:13 +0000 (10:14 +0200)]
kernel-netlink: Rename algorithm identifier from cast128 to cast5
Even if the XFRM identifier was named cast128 in the kernel before 2.6.31, it
actually never worked, because there is no such crypto algorithm.
The identifier has been changed to cast5 in
https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=245acb87
to make it work, so we should use that.