Commit Graph

3539 Commits

Author SHA1 Message Date
Tobias Brunner fab4c845ec ikev1: Send NAT-D payloads after vendor ID payloads in Aggressive Mode messages
Some implementations might otherwise not recognize the NAT-D payload
type.  Also moves SIG and HASH payloads last in these messages.

Fixes #1239.
2016-03-07 14:13:12 +01:00
Thomas Egerer d8adcb8ff9 ike-sa-manager: Log a checkin/failure message for every checkout
Signed-off-by: Thomas Egerer <thomas.egerer@secunet.com>
2016-03-07 11:16:52 +01:00
Tobias Brunner ec9566ae24 ike-sa-manager: Log some additional details like SPIs when checking out SAs 2016-03-04 18:43:27 +01:00
Tobias Brunner 67e28a3afa smp: Correctly return IKE SPIs stored in network order 2016-03-04 18:43:26 +01:00
Tobias Brunner e32504352d vici: Correctly return IKE SPIs stored in network order 2016-03-04 18:43:26 +01:00
Tobias Brunner db00982dad stroke: Correctly print IKE SPIs stored in network order 2016-03-04 18:43:26 +01:00
Tobias Brunner 1ecec95dff vici: Add support for pubkey constraints with EAP-TLS
This is a feature currently supported by stroke.
2016-03-04 16:19:54 +01:00
Tobias Brunner 3c23a75120 auth-cfg: Make IKE signature schemes configurable
This also restores the charon.signature_authentication_constraints
functionality, that is, if no explicit IKE signature schemes are
configured we apply all regular signature constraints as IKE constraints.
2016-03-04 16:19:54 +01:00
Tobias Brunner e37e6d6dca ikev2: Always store signature scheme in auth-cfg
As we use a different rule we can always store the scheme.
2016-03-04 16:19:53 +01:00
Thomas Egerer c8a0781334 ikev2: Diversify signature scheme rule
This allows for different signature schemes for IKE authentication and
trustchain verification.

Signed-off-by: Thomas Egerer <thomas.egerer@secunet.com>
2016-03-04 16:19:53 +01:00
Tobias Brunner 47701e1178 ike-init: Verify REDIRECT notify before processing IKE_SA_INIT message
An attacker could blindly send a message with invalid nonce data (or none
at all) to DoS an initiator if we just destroy the SA.  To prevent this we
ignore the message and wait for the one by the correct responder.
2016-03-04 16:03:00 +01:00
Tobias Brunner fb7cc16d67 ikev2: Allow tasks to verify request messages before processing them 2016-03-04 16:03:00 +01:00
Tobias Brunner 4b83619310 ikev2: Allow tasks to verify response messages before processing them 2016-03-04 16:03:00 +01:00
Tobias Brunner b4968a952e task: Add optional pre_process() method
This will eventually allow tasks to pre-process and verify received
messages.
2016-03-04 16:03:00 +01:00
Tobias Brunner 9282bc39a7 ike-init: Ignore notifies related to redirects during rekeying
Also don't query redirect providers in this case.
2016-03-04 16:03:00 +01:00
Tobias Brunner c6ebd0332e ike-sa: Add limit for the number of redirects within a defined time period 2016-03-04 16:03:00 +01:00
Tobias Brunner 7505fb8d45 ike-sa: Reauthenticate to the same addresses we currently use
If the SA got redirected this would otherwise cause a reauthentication with
the original gateway.  Reestablishing the SA to the original gateway, if e.g.
the new gateway is not reachable makes sense though.
2016-03-04 16:03:00 +01:00
Tobias Brunner c13eb73719 vici: Don't redirect all SAs if no selectors are given
This avoid confusion and redirecting all SAs can now easily be done
explicitly (e.g. peer_ip=0.0.0.0/0).
2016-03-04 16:03:00 +01:00
Tobias Brunner 27074f3155 vici: Match subnets and ranges against peer IP in redirect command 2016-03-04 16:03:00 +01:00
Tobias Brunner bef4518de7 vici: Match identity with wildcards against remote ID in redirect command 2016-03-04 16:02:59 +01:00
Tobias Brunner 43b46b26ea vici: Add redirect command
This allows redirecting IKE_SAs by multiple different selectors, if none
are given all SAs are redirected.
2016-03-04 16:02:59 +01:00
Tobias Brunner 0d424d2107 redirect-job: Add job to redirect an active IKE_SA 2016-03-04 16:02:59 +01:00
Tobias Brunner 71c7070588 ike-sa: Add redirect() method to actively redirect an IKE_SA 2016-03-04 16:02:59 +01:00
Tobias Brunner 0840385b27 ike-redirect: Add task to redirect active IKE_SAs 2016-03-04 16:02:59 +01:00
Tobias Brunner f5a9025ce9 ike-auth: Handle REDIRECT notifies during IKE_AUTH 2016-03-04 16:02:59 +01:00
Tobias Brunner f20e00fe54 ike-sa: Handle redirect requests for established SAs as reestablishment
We handle this similar to how we do reestablishing IKE_SAs with all CHILD_SAs,
which also includes the one actively queued during IKE_AUTH.

To delete the old SA we use the recently added ike_reauth_complete task.
2016-03-04 16:02:59 +01:00
Tobias Brunner 19233ef980 ike-auth: Send REDIRECT notify during IKE_AUTH if requested by providers
To prevent the creation of the CHILD_SA we set a condition on the
IKE_SA.  We also schedule a delete job in case the client does not
terminate the IKE_SA (which is a SHOULD in RFC 5685).
2016-03-04 16:02:59 +01:00
Tobias Brunner fdc4b82728 ike-config: Do not assign attributes for redirected IKE_SAs 2016-03-04 16:02:59 +01:00
Tobias Brunner b6fcb91762 child-create: Don't create CHILD_SA if the IKE_SA got redirected in IKE_AUTH 2016-03-04 16:02:59 +01:00
Tobias Brunner d68c05d269 ike-sa: Add a condition to mark redirected IKE_SAs 2016-03-04 16:02:58 +01:00
Tobias Brunner 3d074bce00 ike-init: Handle REDIRECTED_FROM similar to REDIRECT_SUPPORTED as server 2016-03-04 16:02:58 +01:00
Tobias Brunner 6cde9875e1 ike-init: Send REDIRECTED_FROM instead of REDIRECT_SUPPORTED if appropriate 2016-03-04 16:02:58 +01:00
Tobias Brunner e4af6e6b7a ike-sa: Keep track of the address of the gateway that redirected us 2016-03-04 16:02:58 +01:00
Tobias Brunner 489d154e63 ikev2: Add option to disable following redirects as client 2016-03-04 16:02:58 +01:00
Tobias Brunner c126ddd048 ikev2: Handle REDIRECT notifies during IKE_SA_INIT 2016-03-04 16:02:58 +01:00
Tobias Brunner dd2b335b79 ike-init: Send REDIRECT notify during IKE_SA_INIT if requested by providers 2016-03-04 16:02:58 +01:00
Tobias Brunner 2beb26b948 redirect-manager: Add helper function to create and parse REDIRECT notify data
The same encoding is also used for the REDIRECT_FROM notifies.
2016-03-04 16:02:58 +01:00
Tobias Brunner fa5cfbdcbf redirect-manager: Verify type of returned gateway ID 2016-03-04 16:02:58 +01:00
Tobias Brunner 10009b2954 ike-init: Send REDIRECT_SUPPORTED as initiator 2016-03-04 16:02:58 +01:00
Tobias Brunner 099c0b12b6 ike-init: Enable redirection extension if client sends REDIRECT_SUPPORTED notify 2016-03-04 16:02:58 +01:00
Tobias Brunner c6aa749c28 ike-sa: Add new extension for IKEv2 redirection (RFC 5685) 2016-03-04 16:02:58 +01:00
Tobias Brunner 32ba44424d daemon: Create global redirect manager instance 2016-03-04 16:02:58 +01:00
Tobias Brunner 4a6e054122 redirect-manager: Add manager for redirect providers 2016-03-04 16:02:58 +01:00
Tobias Brunner dbb3f7f921 redirect-provider: Add interface to redirect clients during initial messages
This will allow e.g. plugins to decide whether a connecting client is
redirected to a different gateway using RFC 5685.
2016-03-04 16:02:57 +01:00
Andreas Steffen ad82c95f0a Set PLUTO port variables to 0 in the case of no port restrictions 2016-03-04 12:52:35 +01:00
Andreas Steffen 0d7202c7c5 Port range support in updown script 2016-03-04 09:52:34 +01:00
Andreas Steffen 6abae81f86 Implemented port ranges in kernel_netlink interface 2016-03-04 09:52:34 +01:00
Tobias Brunner 28649f6d91 libhydra: Remove empty unused library 2016-03-03 17:36:11 +01:00
Tobias Brunner 8394ea2a42 libhydra: Move kernel interface to libcharon
This moves hydra->kernel_interface to charon->kernel.
2016-03-03 17:36:11 +01:00
Tobias Brunner dec9e1957f libhydra: Move all kernel plugins to libcharon 2016-03-03 17:36:11 +01:00
Tobias Brunner 91d80298f9 ikev1: Send and verify IPv6 addresses correctly
According to the mode-config draft there is no prefix sent for
IPv6 addresses in IKEv1.  We still accept 17 bytes long addresses for
backwards compatibility with older strongSwan releases.

Fixes #1304.
2016-03-03 17:32:03 +01:00
Tobias Brunner 2f3c08d268 ikev1: Allow immediate deletion of rekeyed CHILD_SAs
When charon rekeys a CHILD_SA after a soft limit expired, it is only
deleted after the hard limit is reached.  In case of packet/byte limits
this may not be the case for a long time since the packets/bytes are
usually sent using the new SA.  This may result in a very large number of
stale CHILD_SAs and kernel states.  With enough connections configured this
will ultimately exhaust the memory of the system.

This patch adds a strongswan.conf setting that, if enabled, causes the old
CHILD_SA to be deleted by the initiator after a successful rekeying.

Enabling this setting might create problems with implementations that
continue to use rekeyed SAs (e.g. if the DELETE notify is lost).
2016-03-03 17:28:03 +01:00
Tobias Brunner 904f93f655 ikev1: Avoid modifying local auth config when detecting pubkey method
If it was necessary to pass the local certificates we could probably
clone the config (but we don't do that either when later looking for the
key to actually authenticate).
Passing auth adds the same subject cert to the config over and over
again (I guess we could also try to prevent that by searching for
duplicates).
2016-03-03 17:26:14 +01:00
Tobias Brunner 444565325a forecast: Fix alignment when adding rules
Basically the same issue as with the connmark plugin.

Fixes #1212.
2016-03-03 17:20:37 +01:00
Tobias Brunner c4cb652a56 connmark: Fix alignment when adding rules
The structs that make up a message sent to the kernel have all to be
aligned with XT_ALIGN.  That was not necessarily the case when
initializing the complete message as struct.

Fixes #1212.
2016-03-03 17:20:09 +01:00
Tobias Brunner efd7fa7be1 ike: Keep track of send keepalive jobs to avoid scheduling more than one per IKE_SA 2016-03-03 17:15:37 +01:00
Tobias Brunner 34f7d3b7ae ike: Don't send NAT keepalives if we have no path to the other peer
If there is no path to the other peer there is no point in trying to
send a NAT keepalive.

If the condition changes back and forth within the keepalive interval there
is a chance that multiple jobs get queued.
2016-03-03 17:15:37 +01:00
Tobias Brunner 35d0b8b152 vici: Provide ports of local and remote IKE endpoints 2016-03-03 17:13:35 +01:00
Denis Volpato Martins 337cf81aef duplicheck: Include required headers for FreeBSD
Closes strongswan/strongswan#34.
2016-03-03 09:34:03 +01:00
Thomas Egerer 2080c7e1e2 charon: Add custom logger to daemon
This logger can be used to easily register custom logging instances
using __attribute__((constructor)) benefiting from the global reload
mechanism (with reset of log levels).

Note that this is not intended to be used from plugins, which are loaded
after loggers have already been initialized.

Signed-off-by: Thomas Egerer <thomas.egerer@secunet.com>
2016-03-01 11:48:52 +01:00
Tobias Brunner fedb16236c vici: Correctly document 'up' key for updown events
Instead of sending 'no' it is omitted when an SA goes down.
2016-03-01 11:05:34 +01:00
Thomas Egerer 7823393926 ikev2: Use config value for sending of vendor IDs
Signed-off-by: Thomas Egerer <thomas.egerer@secunet.com>
2016-03-01 10:52:59 +01:00
Tobias Brunner c674233804 ike-sa-manager: Store a reference to the thread that checked out an IKE_SA
This could be helpful when debugging deadlocks that manifest around
wait_for_entry(), as it helps identifying other involved threads (the
thread object is seen in the thread_main() call in each thread's backtrace).
2016-02-17 11:21:42 +01:00
Andreas Steffen 4d83c5b4a6 Fix of the mutual TNC measurement use case
If the IKEv2 initiator acting as a TNC server receives invalid TNC measurements
from the IKEv2 responder acting as a TNC clienti, the exchange of PB-TNC batches
is continued until the IKEv2 responder acting as a TNC server has also finished
its TNC measurements.

In the past if these measurements in the other direction were correct
the IKEv2 responder acting as EAP server declared the IKEv2 EAP authentication
successful and the IPsec connection was established even though the TNC
measurement verification on the EAP peer side failed.

The fix adds an "allow" group membership on each endpoint if the corresponding
TNC measurements of the peer are successful. By requiring a "allow" group
membership in the IKEv2 connection definition the IPsec connection succeeds
only if the TNC measurements on both sides are valid.
2016-02-16 18:00:27 +01:00
Tobias Brunner 10c5981d3b utils: Add enum name for pseudo log group 'any' 2016-02-05 15:41:39 +01:00
Tobias Brunner e8140531fc libipsec: Pass the same data to del_policy() as to add_policy()
We already do this for the other kernel interfaces.

Fixes e1e88d5add ("libipsec: Don't attempt deletion of any non-IPsec policies")
2016-02-04 11:02:59 +01:00
Thomas Egerer 3d15269af9 ikev2: Add debug message about failed IKE authentication
Signed-off-by: Thomas Egerer <thomas.egerer@secunet.com>
2016-02-02 16:16:49 +01:00
Thomas Egerer beb4a07ea8 ikev1: Log successful authentication with signature scheme
Output is now identical to that of the IKEv2 pubkey authenticator.

Signed-off-by: Thomas Egerer <thomas.egerer@secunet.com>
2016-02-01 15:58:53 +01:00
Tobias Brunner b4ae9e81f5 peer-cfg: Set DPD timeout to at least DPD delay
If DPD timeout is set but to a value smaller than the DPD delay the code
in task_manager_v1.c:queue_liveliness_check will run into an integer
underrun.
2016-02-01 15:29:25 +01:00
Tobias Brunner 24ab8530e5 ikev1: Always enable charon.reuse_ikesa
With IKEv1 we have to reuse IKE_SAs as otherwise the responder might
detect the new SA as reauthentication and will "adopt" the CHILD_SAs of
the original IKE_SA, while the initiator will not do so.  This could
cause CHILD_SA rekeying to fail later.

Fixes #1236.
2016-02-01 11:37:41 +01:00
Tobias Brunner db57f5702b load-tester: Register kernel-ipsec implementation as plugin feature
Otherwise, libcharon's dependency on kernel-ipsec can't be satisfied.

This changed with db61c37690 ("kernel-interface: Return bool for
kernel interface registration") as the registration of further
kernel-ipsec implementations now fails and therefore even if other
plugins are loaded the dependency will not be satisfied anymore.

References #953.
2016-02-01 11:22:56 +01:00
Tobias Brunner 7f2a20a4f4 child-rekey: Suppress updown event when deleting redundant CHILD_SAs
When handling a rekey collision we might have to delete an already
installed redundant CHILD_SA (or expect the other peer to do so).
We don't want to trigger updown events for these as neither do we do
so for successfully rekeyed CHILD_SAs.

Fixes #853.
2016-02-01 11:04:16 +01:00
Tobias Brunner 9c773f8d11 ha: Properly sync IKEv1 IV if gateway is initiator
To handle Phase 2 exchanges on the other HA host we need to sync the last
block of the last Phase 1 message (or the last expected IV).  If the
gateway is the initiator of a Main Mode SA the last message is an
inbound message.  When handling such messages the expected IV is not
updated until it is successfully decrypted so we can't sync the IV
when processing the still encrypted (!plain) message.  However, as responder,
i.e. if the last message is an outbound message, the reverse applies, that
is, we get the next IV after successfully encrypting the message, not
while handling the plain message.

Fixes #1267.
2016-02-01 10:51:02 +01:00
Tobias Brunner b5c2ed5016 ha: Add DH group to CHILD_ADD message
References #1267.
2016-02-01 10:50:53 +01:00
Tobias Brunner f1e908837a ha: Add DH group to IKE_ADD message
It is required for IKEv1 to determine the DH group of the CHILD SAs
during rekeying. It also fixes the status output for HA SAs, which so
far haven't shown the DH group on the passive side.

Fixes #1267.
2016-02-01 10:50:41 +01:00
Tobias Brunner e663d8e2bf ike-sa-manager: Don't update entries for init messages after unlocking segment
If the retransmit of an initial message is processed concurrently with the
original message it might not have been handled as intended as the
thread processing the retransmit might not have seen the correct value
of entry->processing set by the thread handling the original request.

For IKEv1, i.e. without proper message IDs, there might still be races e.g.
when receiving a retransmit of the initial IKE message while processing the
initiator's second request.

Fixes #1269.
2016-02-01 10:39:29 +01:00
Andreas Steffen ffd29ab30a vici: Support multiple named raw ublic keys 2016-01-10 00:12:57 +01:00
Andreas Steffen abe6d07463 swanctl: Load pubkeys with load-creds 2016-01-09 07:23:30 +01:00
Andreas Steffen 4c38c79452 vici: list-cert sends subject, not-before and not-after attributes for pubkeys 2016-01-09 07:23:30 +01:00
Andreas Steffen 87371460f6 vici: Support of raw public keys 2016-01-09 07:23:29 +01:00
Andreas Steffen 9121f6cce1 vici: Enable transport encoding of CERT_TRUSTED_PUBKEY objects 2016-01-03 06:28:49 +01:00
Tobias Brunner 5d7049b427 stroke: List DH groups for CHILD_SA proposals
Closes strongswan/strongswan#23.
2015-12-21 12:14:12 +01:00
Tobias Brunner a1dfbb7557 vici: Use correct constant when checking for integrity algorithm
Currently both have the value 1024 so no real harm done.
2015-12-21 12:14:12 +01:00
Tobias Brunner ade20d06c6 vici: CHILD_SA proposals never contain a PRF 2015-12-21 12:14:12 +01:00
Andreas Steffen 92b051bd4a vici: allow legacy shortcuts in cert queries 2015-12-19 10:30:17 +01:00
Andreas Steffen f553aea2c2 Use 128 bit security in README.pod examples 2015-12-18 15:08:33 +01:00
Andreas Hofmeister a073e4c95e Improvements to the VICI Perl bindings by Andreas Hofmeister
- Switch.pm, which was implemented as a source filter, has been deprecated in
  Perl 5.10 and was later removed from the core modules in Perl 5.14 or so.

  Unfortunately, its replacement, the given/when/default construct, has since
  been downgraded to "experimental" status because of problems with the underlying
  "smart-match" operator.

  Thus, as of Perl 5.22, Perl still has no actually usable "switch"-like construct.

  So just use boring, old and ugly "if/elsif/else" constructs instead, which are
  compatible with almost any Perl version.

- None of the Perl modules here does anything that would require "AutoLoader".

- "Exporter" can be used to export plain functions into another modules name
  space. But the things that were exported here are meant to be called as
  methods.  In this case, it is neither necessary nor advisable to export those
  symbols.

  Just export nothing (the POD documentation already said so).

- It is usually the calling script that enables (or does not enable) warnings
  globally. When a module says "use warnings;" however, the caller looses control
  over what warnings should be enabled in that module.
2015-12-18 14:25:59 +01:00
Andreas Steffen cc874350b8 Apply pubkey and signature constraints in vici plugin 2015-12-17 17:49:48 +01:00
Andreas Steffen a78e1c3b11 128 bit default security strength for IKE and ESP algorithms
The default ESP cipher suite is now
    AES_CBC-128/HMAC_SHA2_256_128
and requires SHA-2 HMAC support in the Linux kernel (correctly implemented
since 2.6.33).

The default IKE cipher suite is now
   AES_CBC-128/HMAC_SHA2_256_128/PRF_HMAC_SHA2_256/ECP_256
if the openssl plugin is loaded or
   AES_CBC-128/HMAC_SHA2_256_128/PRF_HMAC_SHA2_256/MODP_3072
if ECC is not available.

The use of the SHA-1 hash algorithm and the MODP_2048 DH group has been
deprecated and ENCR_CHACHA20_POLY1305 has been added to the default
IKE AEAD algorithms.
2015-12-17 17:49:48 +01:00
Andreas Steffen 02d431022c Refactored certificate management for the vici and stroke interfaces 2015-12-12 00:19:24 +01:00
Andreas Steffen 4df09fe563 Modified vici_cert_info class for use with load_creds and vici_cred 2015-12-11 22:14:38 +01:00
Andreas Steffen 44d3b02b57 Removed VICI protocol versioning 2015-12-11 18:26:55 +01:00
Andreas Steffen 334119b843 Share vici_cert_info.c with vici_cred.c 2015-12-11 18:26:55 +01:00
Andreas Steffen fad851e2d3 Use VICI 2.0 protocol version for certificate queries 2015-12-11 18:26:54 +01:00
Andreas Steffen 5d909303d8 Sort certificate types during enumeration 2015-12-11 18:26:54 +01:00
Andreas Steffen 75749971e1 Define VICI protocol versions 2015-12-11 18:26:54 +01:00
Tobias Brunner 74270c8c86 vici: Don't report memory usage via leak-detective
This slowed down the `swanctl --stats` calls in the test scenarios
significantly, with not much added value.
2015-12-11 18:26:53 +01:00
Andreas Steffen 3317d0e77b Standardized printing of certificate information
The certificate_printer class allows the printing of certificate
information to a text file (usually stdout). This class is used
by the pki --print and swanctl --list-certs commands as well as
by the stroke plugin.
2015-12-11 18:26:53 +01:00
Martin Willi 1a8a420c1c vici: Fix documentation about the initiate/terminate timeout 2015-12-07 10:28:45 +01:00
Martin Willi eaca77d03e vici: Honor an optionally passed IKE configuration name in initiate/install
If two IKE configurations have CHILD configurations with the same name,
we have no control about the CHILD_SA that actually gets controlled. The
new "ike" parameter specifies the peer config name to find the "child" config
under.
2015-12-07 10:28:45 +01:00
Martin Willi 5e79ae2d65 vici: Support completely asynchronous initiating and termination
In some situations the vici client is not interested in waiting for a
timeout at all, so don't register a logging callback if the timeout argument
is negative.
2015-12-07 10:28:45 +01:00
Martin Willi 1db918c4f8 vici: Use an empty local auth round if none given
While it hardly makes sense to use none for negotiated SAs, it actually does
when installing shunt policies.
2015-12-07 10:05:07 +01:00
Martin Willi b26ba1b4a4 vici: Limit start action undoing to IKE_SAs using the base peer config name
If two peer configs use the same child config names, potentailly delete
the wrong CHILD_SA. Check the peer config name as well to avoid that.
2015-12-07 10:05:07 +01:00
Martin Willi 23b1f71372 vici: Close empty IKE_SAs after undoing CHILD_SA start actions 2015-12-07 10:05:07 +01:00
Martin Willi 2facf18833 vici: Use value based array to store CHILD_SA ids during restart
The previous approach stored a pointer to a volatile stack variable, which
works for a single ID, but not for multiple.
2015-12-07 10:05:07 +01:00
Martin Willi f3b2d4a9d8 vici: Undo start actions when unloading configs 2015-12-07 10:05:07 +01:00
Tobias Brunner 63a778a25d vici: Fix clean-local target for Perl bindings if they were not built
This is called when running `make distclean` (or indirectly via `make
distcheck`).
2015-12-04 12:10:57 +01:00
Andreas Steffen 7d24aa0624 Extended and refactored vici perl implementation 2015-12-01 14:52:43 +01:00
Andreas Steffen a17b6d469c Built the CPAN file structure for the Vici::Session perl module 2015-12-01 14:52:43 +01:00
Andreas Steffen a101bce862 Implement vici Perl binding 2015-12-01 14:52:43 +01:00
Tobias Brunner de34defcd0 vici: Add get-algorithms command to query loaded algorithms and implementations 2015-11-30 10:55:55 +01:00
Thom Troy ac36ede93c eap-radius: Add ability to configure RADIUS retransmission behavior
Closes strongswan/strongswan#19.
2015-11-17 14:25:08 +01:00
Tobias Brunner f9c5c80553 eap-mschapv2: Keep internal state to prevent authentication from succeeding prematurely
We can't allow a client to send us MSCHAPV2_SUCCESS messages before it
was authenticated successfully.

Fixes CVE-2015-8023.
2015-11-16 13:19:36 +01:00
Tobias Brunner 176c24b8e1 vici: Attribute certificates are not trusted 2015-11-12 14:45:43 +01:00
Tobias Brunner e5e352e631 vici: Properly add CRLs to the credential set
add_crl() ensures that old CLRs are not stored in the credential set.
2015-11-12 14:45:42 +01:00
Tobias Brunner 322a11ccbb mode-config: Reassign migrated virtual IP if client requests %any
If we mistakenly detect a new IKE_SA as a reauthentication the client
won't request the previous virtual IP, but since we already migrated
it we already triggered the assign_vips() hook, so we should reassign
the migrated virtual IP.

Fixes #1152.
2015-11-12 14:42:36 +01:00
Tobias Brunner fdfbd401c3 eap-radius: Compare address family when handing out virtual IPs
This also ensures that the actually released virtual IP is removed from
the list of claimed IPs.

Fixes #1199.
2015-11-12 14:32:11 +01:00
Tobias Brunner 1d4b767275 eap-mschapv2: Report username if different from EAP-Identity (or IKE identity) 2015-11-12 14:21:06 +01:00
Tobias Brunner 8f5e481953 eap-mschapv2: Provide EAP-MSCHAPv2 username as EAP-Identity 2015-11-12 14:21:06 +01:00
Tobias Brunner 85af8400df android: Fix build after updating Linux headers
Since we don't use the kernel-netlink plugin anymore and the headers
in the NDK are reasonably recent, we don't need this anymore (at least
when building the app).

Fixes #1172.
2015-11-12 14:09:25 +01:00
Tobias Brunner ee09094899 ike-sa-manager: Allow plugins to provide IKE SPIs via a callback
Plugins must depend on `libcharon-sa-managers` to ensure the manager
exists.
2015-11-11 15:39:45 +01:00
Tobias Brunner 301ccbe0a3 libcharon: Publish IKE_SA/CHILD_SA managers as custom plugin feature 2015-11-11 15:39:08 +01:00
Tobias Brunner 7b5dcc9f27 ikev1: Also use message hashes for Quick Mode for the early retransmission check
We already did so during Phase 1 but because all three Quick Mode
message have the same message ID we occasionally dropped the third
message as retransmit, so we do it there too.  For INFORMATIONAL
and TRANSACTION exchanges we don't expect more than one inbound message
with the same message ID so we still use them there.

Fixes #1198.
2015-11-11 11:01:56 +01:00
Tobias Brunner a6e0f14fd2 kernel-interface: Pass the same data to del_policy() that was passed to add_policy()
The additional data can be helpful to identify the exact policy to
delete.
2015-11-10 16:42:52 +01:00
Tobias Brunner e8f2c13f9a trap-manager: Also clean up remote address in error cases
Fixes #1201.
2015-11-10 14:00:11 +01:00
Tobias Brunner ebeb8c87c5 traffic-selector: Don't end printf'ed list of traffic selectors with a space 2015-11-10 12:13:06 +01:00
Tobias Brunner f4641f9e45 vici: Add option to query leases of pools
We could later perhaps add filter parameters similar to those of the
`ipsec leases` command (pool name/virtual IP).
2015-11-10 10:43:25 +01:00
Tobias Brunner bdb8b76515 vici: Return local and remote virtual IPs when listing SAs 2015-11-10 10:43:24 +01:00
Tobias Brunner 0ddec0760a socket-dynamic: Refactor setting source address when sending messages
Basically the same change as the one for the socket-default plugin.
2015-11-09 16:44:22 +01:00
Tobias Brunner 47e113a639 socket-default: Refactor setting source address when sending messages
This ensures we don't pass data (via msg_control) defined in a different
scope to sendmsg().  Actually, some compilers (e.g. GCC 5.2.1) might
optimize the memcpy() call away causing the packets not to get sent from
the intended source address.

It also makes the code clearer than with all these ifdefs.

Fixes #1171.
2015-11-09 16:43:21 +01:00
Tobias Brunner 99747bed8f socket-default: Refactor retrieval of destination address of received packets
This makes the code a bit clearer than with the interleaved ifdefs.
2015-11-09 16:42:20 +01:00
Tobias Brunner 548b993488 file-logger: Add option to print milliseconds within the current second after timestamp
For this to look right time_format should end with %S or %T.

Closes strongswan/strongswan#18.
2015-11-09 16:30:00 +01:00
Tobias Brunner 8484d2b01d ike-natd: Create fake NAT-D payloads in a more static way
In some scenarios an IKE_SA might get restarted multiple times (e.g.
due to retransmits and delayed INVALID_KE_PAYLOAD notifies) so that
two IKE_SA_INIT messages might be sent that only differ in the
previously randomly generated NAT_DETECTION_SOURCE_IP payload.
This could cause an authentication failure on the responder if the two
peers don't use the same IKE_SA_INIT message in their InitiatorSignedOctets.

While the payload is generated in a reproducible way it will still change
when the daemon is restarted, which should make detecting the payloads
as fake a bit harder (compared to e.g. just using 0.0.0.0:0 as address).

Fixes #1131.
2015-11-09 16:25:59 +01:00
Tobias Brunner 4ae2919518 mediation: Reschedule initiate mediation job if SA is not yet found
If the job gets queued for a newly created IKE_SA it might not yet be
checked in when the job is running, reschedule the job in that case.

This should fix the two p2pnat test scenarios, which occasionally
failed because one of the peers did not initiate the connection to
the mediation server.
2015-11-09 15:18:38 +01:00
Tobias Brunner 0ea16f6b15 ike-sa-manager: Signal entries that we don't actually check out
In some cases we call wait_for_entry() but don't actually check out the
entry afterwards (e.g. because it doesn't match certain criteria).  So
there won't be a call to checkin() for such entries causing waiting
threads to get signaled.  Instead, such threads would be blocked until
another thread properly checks out/in the entry (or does a blocking
enumeration).
2015-11-09 15:18:37 +01:00
Tobias Brunner 1d528cfb8d ike-sa-manager: Signal waiting threads after check out/in for uniqueness check
Fixes 758b1caa0e ("ikev1: Prevent deadlock when checking for duplicate IKEv1 SAs")
2015-11-09 15:18:37 +01:00
Tobias Brunner 747b64875f ikev1: Fix calculation of DPD timeout
A DPD timeout job is queued whenever a DPD is sent, i.e. after the
DPD delay already has elapsed, so we have to compensate for that.
2015-11-09 15:18:34 +01:00
Tobias Brunner bd5084ae25 xauth: Call authorize() hook also when xauth-noauth is used
Fixes #1138.
2015-11-09 14:44:53 +01:00
Tobias Brunner 04f22cdabc vici: Add NAT information when listing IKE_SAs
The `nat-local` and `nat-remote` keys contain information on the NAT
status of the local and remote IKE endpoints, respectively.  If a
responder did not detect a NAT but is configured to fake a NAT situation
this is indicated by `nat-fake` (if an initiator fakes a NAT situation
`nat-local` is set).  If any NAT is detected or faked `nat-any` is set.

Closes strongswan/strongswan#16.
2015-11-09 11:55:51 +01:00
Tobias Brunner 7b95688124 stroke: Make down-nb actually non-blocking
Fixes #1191.
2015-11-09 10:55:46 +01:00
Andreas Steffen a88d958933 Explicitly mention SHA2 algorithm in BLISS OIDs and signature schemes 2015-11-06 14:55:31 +01:00
Tobias Brunner 0af13d2849 ikev2: Fix size of key material for CAMELLIA-CTR
Like AES in CTR mode it includes a 4 byte nonce.
2015-10-30 11:04:42 +01:00
Tobias Brunner 72cc029e24 ike-mobike: Send retransmits to the current local and remote addresses
These might have changed by a peer-initiated MOBIKE address update.

Fixes #1125.
2015-10-30 10:51:07 +01:00
Tobias Brunner 25863fe1c7 ikev1: Handle queued INFORMATIONAL message after receiving the last AM request 2015-10-30 10:30:30 +01:00
Tobias Brunner 1c8dfa30d0 ikev1: Queue INFORMATIONAL request if AM is not complete yet 2015-10-30 10:30:30 +01:00
Tobias Brunner 3805880c8a ikev1: Handle queued TRANSACTION messages only after processing replies 2015-10-30 10:30:07 +01:00
Tobias Brunner 3f56f73159 ikev1: Extract queueing of TRANSACTIONAL requests when MM is not complete yet 2015-10-30 10:27:09 +01:00
Tobias Brunner b0b0c9137d ikev1: Drop TRANSACTION/QUICK_MODE requests until we received the last AM message 2015-10-30 10:27:09 +01:00
Tobias Brunner 0cb8752b85 ikev1: Make maximum number of IKEv1 phase 2 exchanges we keep state about configurable
Fixes #1128.
2015-10-30 10:16:35 +01:00
Tobias Brunner 37a22a166b ikev1: Avoid fourth QM message if third QM messages of multiple exchanges are handled delayed
If we haven't received the third QM message for multiple exchanges the
return value of NEED_MORE for passive tasks that are not responsible for
a specific exchange would trigger a fourth empty QM message.

Fixes: 4de361d92c ("ikev1: Fix handling of overlapping Quick Mode exchanges")

References #1076.
2015-10-29 16:03:15 +01:00
Tobias Brunner 758b1caa0e ikev1: Prevent deadlock when checking for duplicate IKEv1 SAs
Previously, the current segment was held while checking for duplicate
SAs, which requires acquiring all segments.  If multiple threads did this
concurrently this resulted in a deadlock as they couldn't acquire the
segments held by the other threads attempting to do the same.  With the
default configuration only one segment is used, which prevents the problem
as only one thread can check in an IKE SA concurrently.

Fixes: a064eaa8a6 ("Handling of initial contact")
2015-10-29 15:59:41 +01:00
Tobias Brunner 08afc33e52 shunt-manager: Resolve %dynamic to %any4/6 before installing policies
left|rightsubnet default to %dynamic, which is basically 0.0.0.0/0 until an
address is assigned to it.  So if only one side was undefined and the other
traffic selector was IPv6 an address family mismatch would occur.

References #595.
2015-09-16 15:01:05 +02:00
Tobias Brunner 65978f08f4 shunt-manager: Don't install policies in case of an address family or IP protocol mismatch
References #595.
2015-09-16 15:00:46 +02:00
Tobias Brunner 00c2c87b06 eap-radius: Fix creation of host_t objects based on Framed-IPv6-Address attributes
Fixes ec490e68ae ("eap-radius: Add support for some basic IPv6-specific RADIUS attributes").
References #1001.
2015-08-28 16:52:57 +02:00
Tobias Brunner fbb593092e eap-ttls: Limit maximum length of tunneled EAP packet to EAP-TTLS packet 2015-08-27 15:29:16 +02:00
Tobias Brunner 03024f4ca8 trap-manager: Cleanup local address in error cases 2015-08-27 14:45:11 +02:00
Tobias Brunner e3e208fb9f ha: Close control FIFO if it is not valid 2015-08-27 14:31:42 +02:00
Tobias Brunner c605a96d7f Fix some Doxygen issues 2015-08-27 12:03:11 +02:00
Tobias Brunner df62141362 ike: Fix half-open count for initiating SAs when initially checked in 2015-08-27 11:21:01 +02:00
Tobias Brunner 735f929ca7 ike: Only consider number of half-open SAs as responder when deciding whether COOKIEs are sent 2015-08-27 11:18:51 +02:00
Evan Broder 78ed330099 vici: Handle closed sockets in the Ruby gem
From recvfrom(2) (which UDPSocket#recv backs into):

  The return value will be 0 when the peer has performed an orderly
  shutdown.

(i.e. it will return an empty string)

Previously in this scenario, Vici::Transport#recv_all would spin
forever trying to pull more data off the socket. I'm not entirely
clear what happened that caused strongSwan to shutdown the socket, but
it probably should not cause vici Ruby apps to spin.

Closes strongswan/strongswan#13.
2015-08-24 11:24:05 +02:00
Tobias Brunner 256e666d22 vici: Optionally check limits when initiating connections
If the init-limits parameter is set (disabled by default) init limits
will be checked and might prevent new SAs from getting initiated.
2015-08-21 18:21:13 +02:00
Tobias Brunner b9d7319fb3 vici: Add get_bool() convenience getter for VICI messages 2015-08-21 18:21:13 +02:00
Tobias Brunner ff0abde9ed controller: Optionally adhere to init limits also when initiating IKE_SAs 2015-08-21 18:21:13 +02:00
Tobias Brunner 471a996a3e ike: Also track initiating IKE_SAs as half-open 2015-08-21 18:21:13 +02:00
Tobias Brunner ffa20bad63 stroke: Allow %any as local address
Actually, resolving addresses in `left` might be overkill as we'll assume
left=local anyway (the only difference is the log message).
2015-08-21 18:19:26 +02:00
Tobias Brunner 8212f3d9a4 stroke: Add an option to disable side-swapping of configuration options
In some scenarios it might be preferred to ensure left is always local
and no unintended swaps occur.
2015-08-21 18:19:26 +02:00
Tobias Brunner a5c07be058 ikev1: Assign different job priorities for inbound IKEv1 messages 2015-08-21 18:11:44 +02:00
Tobias Brunner 105365eabe child-rekey: Don't add a REKEY_SA notify if the child-create task is deleting the SA 2015-08-21 16:14:07 +02:00
Tobias Brunner f91bd4b92c child-create: Cache proposed IPsec protocol
This allows us to DELETE CHILD_SAs on failures that occur before we
retrieved the selected proposal.
2015-08-21 16:14:07 +02:00
Tobias Brunner ffe0889acd child-create: Don't attempt to delete the SA if we don't have all the information
Since we only support single protocols we could probably guess it and always
send a DELETE.
2015-08-21 16:14:07 +02:00
Tobias Brunner 70c5f1d40d child-rekey: Remove redundant migrate() call for child-create sub-task
When retrying due to a DH group mismatch this is already done by the
child-create task itself.  And in other cases where the task returns
NEED_MORE we actually will need access to a possible proposal to properly
delete it.
2015-08-21 16:14:07 +02:00
Tobias Brunner 1729df9275 child-create: Fix crash when retrying CHILD_SA rekeying due to a DH group mismatch
If the responder declines our KE payload during a CHILD_SA rekeying migrate()
is called to reuse the child-create task.  But the child-rekey task then
calls the same method again.

Fixes: 32df0d81fb ("child-create: Destroy nonceg in migrate()")
2015-08-21 16:14:07 +02:00
Tobias Brunner 517cc501ef stroke: Change how CA certificates are stored
Since 11c14bd2f5 CA certificates referenced in ca sections were
enumerated by two credential sets if they were also stored in
ipsec.d/cacerts.  This caused duplicate certificate requests to
get sent.  All CA certificates, whether loaded automatically or
via a ca section, are now stored in stroke_ca_t.

Certificates referenced in ca sections are now also reloaded
when `ipsec rereadcacerts` is used.
2015-08-20 19:33:41 +02:00
Tobias Brunner 01d3ecbaf0 stroke: Combine CA certificate load methods
Also use the right credential set for CA cert references loaded from
stroke_ca_t.
2015-08-20 19:19:38 +02:00
Tobias Brunner 99610f406d stroke: Atomically replace CA and AA certificates when reloading them
Previously it was possible that certificates were not found between the
time the credential sets were cleared and the certificates got readded.
2015-08-20 19:19:37 +02:00
Tobias Brunner 4de361d92c ikev1: Fix handling of overlapping Quick Mode exchanges
In some cases the third message of a Quick Mode exchange might arrive
after the first message of a subsequent Quick Mode exchange.  Previously
these messages were handled incorrectly and the second Quick Mode
exchange failed.

Some implementations might even try to establish multiple Quick Modes
simultaneously, which is explicitly allowed in RFC 2409.  We don't fully
support that, though, in particular in case of retransmits.

Fixes #1076.
2015-08-20 19:13:45 +02:00
Tobias Brunner 5fee79d854 ikev2: Compare initiator flag again, partially reverts 17ec1c74de
We should ignore messages that have the flag set incorrectly.
This restores RFC compliance which was broken since the mentioned commit.
2015-08-20 16:58:09 +02:00
Tobias Brunner 47a340e1f7 ikev2: Drop IKE_SA_INIT messages that don't have the initiator flag set
While this doesn't really create any problems it is not 100% correct to
accept such messages because, of course, the sender of an IKE_SA_INIT
request is always the original initiator of an IKE_SA.

We currently don't check the flag later, so we wouldn't notice if the
peer doesn't set it in later messages (ike_sa_id_t.equals doesn't
compare it anymore since we added support for IKEv1, in particular since
17ec1c74de).
2015-08-20 16:05:02 +02:00
Tobias Brunner 47ee60177e ikev1: Pass current auth-cfg when looking for key to determine auth method
If multiple certificates use the same subjects we might choose the wrong
one otherwise. This way we use the one referenced with leftcert and
stored in the auth-cfg and we actually do the same thing later in the
pubkey authenticator.

Fixes #1077.
2015-08-19 17:39:01 +02:00
Tobias Brunner 49a20ef019 ikev2: Store outer EAP method used to authenticate remote peer in auth-cfg
This allows symmetric configuration of EAP methods (i.e. the same value
in leftauth and rightauth) when mutual EAP-only authentication is used.
Previously the client had to configure rightauth=eap or rightauth=any,
which prevented it from using this same config as responder.
2015-08-19 16:19:05 +02:00
Tobias Brunner 2d14cb4d6c ike: Use the original port when remote resolves to %any
When reestablishing the IKE_SA we should still use the original port
when right resolves to %any as some implementations might not like
initial IKE messages on port 4500 (especially for IKEv1).
2015-08-19 11:34:25 +02:00
Tobias Brunner 301a0bad09 trap-manager: Enable auto=route with right=%any for transport mode connections
Fixes #196.
2015-08-19 11:31:58 +02:00
Tobias Brunner 6927d6224e sql: Also do a reversed ID match
This is required for the case where IDr is not sent (i.e. is %any).
The backend manager does the same.

Fixes #1044.
2015-08-17 18:58:14 +02:00
Tobias Brunner fffee7c759 ha: Recreate the control FIFO if the file exists but is not a FIFO
This may happen if something like `echo ... > /path/to/fifo` is used
before the plugin was able to create the FIFO. In that case we'd end
up in a loop always reading the same values from the static file.
2015-08-17 17:51:20 +02:00
Tobias Brunner 636b2e9b2a ikev1: Assume a default key length of 128-bit for AES-CBC
Some implementations don't send a Key Length attribute for AES-128.
This was allowed for IKE in early drafts of RFC 3602, however, some
implementations also seem to do it for ESP, where it never was allowed.
And the final version of RFC 3602 demands a Key Length attribute for both
phases so they shouldn't do it anymore anyway.

Fixes #1064.
2015-08-17 17:13:50 +02:00
Tobias Brunner 9322e5b398 vici: Add option to disable policy installation for CHILD_SAs 2015-08-17 12:01:36 +02:00
Tobias Brunner 3665adef19 child-sa: Fix refcounting of allocated reqids
During a rekeying we want to reuse the current reqid, but if the new SA
does not allocate it via kernel-interface the state there will disappear
when the old SA is destroyed after the rekeying.  When the IKE_SA is
later reauthenticated with make-before-break reauthentication the new
CHILD_SAs there will get new reqids as no existing state is found in the
kernel-interface, breaking policy installation in the kernel.

Fixes: a49393954f ("child-sa: Use any fixed reqid configured on the CHILD_SA config")
2015-08-17 11:59:15 +02:00
Tobias Brunner d6f70ff689 plugin-feature: Add vendor specific EAP method registration macros
Vendor specific EAP methods may be registered with:

    PLUGIN_CALLBACK(eap_method_register, <constructor>),
        PLUGIN_PROVIDE(EAP_SERVER_VENDOR, <type>, <vendor>),

Same for client implementations via EAP_PEER_VENDOR.

References #969.
2015-08-17 11:28:08 +02:00
Tobias Brunner 39afe6e9d0 eap-radius: Use Framed-IPv6-Address attributes to send IPv6 VIPs in accounting messages
This attribute is more appropriate for single IPv6 virtual IPs than the
Framed-IPv6-Prefix attribute.

Fixes #1001.
2015-08-17 11:23:41 +02:00
Tobias Brunner ec490e68ae eap-radius: Add support for some basic IPv6-specific RADIUS attributes
These are defined in RFC 6911.

Fixes #1001.
2015-08-17 11:23:33 +02:00
Tobias Brunner b3d91cc64e vici: Add listen methods to receive arbitrary events in Python library 2015-08-17 11:12:18 +02:00
Tobias Brunner cf4cefee42 vici: Move event (un-)registration to a helper method in Python library
Also make sure events are unregistered in case of exceptions in
streamed_request().
2015-08-17 11:12:17 +02:00
Tobias Brunner 65ac0851c0 vici: Add ike/child-rekey events 2015-08-17 11:12:17 +02:00
Tobias Brunner 7f21363ee5 vici: Document the ike/child-updown events 2015-08-17 11:12:17 +02:00
Tobias Brunner 22842cce0d vici: Don't include a child-sas section in ike-updown event
This makes it clearer that only the data concerning the IKE_SA is
transmitted (there could be CHILD_SAs e.g. during IKEv1
reauthentication).
2015-08-17 11:12:17 +02:00
Tobias Brunner 085b8f4fb0 vici: Explicitly notify listeners of the type of ike/child-updown event 2015-08-17 11:12:12 +02:00
Andreas Steffen a330f72ecf Fixed AR identities in mutual TNC measurements case 2015-08-15 22:46:21 +02:00
Tobias Brunner 98c09357d5 load-tester: Include string.h for strcmp() on some platforms 2015-08-13 15:12:42 +02:00
Tobias Brunner 6967948241 Initialize variables that some compilers seem to warn about 2015-08-13 15:12:38 +02:00
Tobias Brunner f809e485fb Fixed some typos 2015-08-13 15:12:34 +02:00
Tobias Brunner 6fe8fe0cfd whitelist: Use hash() method so DNs with different string types match
strongSwan uses PrintableString when encoding DNs from strings (if the
character set permits it, otherwise T61String is currently used) but
certificates might be encoded with UTF8String even for simple ASCII strings.
By ignoring this string type when hashing RDNs we make sure the same hash
results in this case as long as the actual string values are the same.

Fixes #991.
2015-08-06 17:24:04 +02:00
Tobias Brunner 1de31bcc2b updown: Pass virtual IPs assigned to a peer to the updown script
Previously only received virtual IPs were available.

References #1008.
2015-08-06 16:30:08 +02:00
Tobias Brunner d04b093374 eap-radius: Don't send RADIUS Accounting Start messages twice
If a client does Mode Config during reauthentication the assign_vips()
event might be triggered twice, we should not send another Start message
in that case.

Fixes #937.
2015-08-06 14:57:47 +02:00
Tobias Brunner 186d25cbe6 eap-radius: Change trigger for Accounting Start messages for IKEv1
Some clients won't do Mode Config or XAuth during reauthentication.
Because Start messages previously were triggered by TRANSACTION exchanges
none were sent for new SAs of such clients, while Stop messages were still
sent for the old SAs when they were destroyed.  This resulted in an
incorrect state on the RADIUS server.

Since 31be582399 the assign_vips() event is also triggered during
reauthentication if the client does not do a Mode Config exchange.
So instead of waiting for a TRANSACTION exchange we trigger the Start
message when a virtual IP is assigned to a client.

With this the charon.plugins.eap-radius.accounting_requires_vip option
would not have any effect for IKEv1 anymore.  However, it previously also
only worked if the client did an XAuth exchange, which is probably
rarely used without virtual IPs, so this might not be much of a
regression.

Fixes #937.
2015-08-06 14:57:26 +02:00
Tobias Brunner a7f381ef00 ha: Properly initialize algo variables when installing CHILD_SAs
If AEAD algorithms are used no integrity algorithm will be received from
the other HA node.  But since AUTH_UNDEFINED is 1024 and not 0 this value
was incorrectly added to the proposal, resulting in a failure during key
derivation.  The variables are now explicitly initialized to 0, as already
was the case for the IKE SAs.

Fixes #1051.
2015-08-04 11:23:27 +02:00
Thomas Egerer 3434709460 ha: Sync remote address in HA_IKE_ADD, too
When the IKE_SA is synced without the remote address, after a
reauthentication charon is not able to find it in its connected_peers
table since the destination host will be %any (it's missing in the
message, hence the default from the newly created ike_sa_t -- %any --
will be used).
By adding the value to the HA_IKE_ADD message, we should be able to
solve this problem.

Signed-off-by: Thomas Egerer <thomas.egerer@secunet.com>
2015-08-04 11:21:54 +02:00
Thomas Egerer e095d87bb6 jobs: Don't execute rekey CHILD_SA job on passive IKE_SAs
Signed-off-by: Thomas Egerer <thomas.egerer@secunet.com>
2015-08-04 11:16:13 +02:00
Thomas Egerer edaba56ec7 ike: Disable NAT keepalives in state PASSIVE
Signed-off-by: Thomas Egerer <thomas.egerer@secunet.com>
2015-08-04 11:16:13 +02:00
Tobias Brunner 93caf23e1b ha: Use the same init values for jhash() as Linux 4.1 2015-07-31 12:34:44 +02:00
Tobias Brunner 36bc52b441 sql: Fix memory leak in SQL logger 2015-07-28 15:35:11 +02:00
Tobias Brunner faebdeac8e ike: Fix memory leak if remote address is kept 2015-07-27 19:38:59 +02:00
Tobias Brunner 81f1aa8dc3 ike-rekey: Fix cleanup() call 2015-07-27 15:20:01 +02:00
Tobias Brunner 2efcc95867 ike-rekey: Reset IKE_SA on bus before sending CREATE_CHILD_SA response
Even when there is no error the CREATE_CHILD_SA response should be sent
in the context of the existing IKE_SA.
2015-07-27 14:45:00 +02:00
Tobias Brunner 86d20b0b40 ike-rekey: Reset IKE_SA on the bus after destroying new IKE_SA
The destroy() method sets the IKE_SA on the bus to NULL, we reset it to
the current IKE_SA so any events and log messages that follow happen in
the correct context.

A practical example where this is problematic is a DH group mismatch,
which causes the first CREATE_CHILD_SA exchange to fail.  Because the SA
was not reset previously, the message() hook for the CREATE_CHILD_SA
response, for instance, was triggered outside the context of an IKE_SA,
that is, the ike_sa parameter was NULL, which is definitely not expected
by several plugins.

Fixes #862.
2015-07-27 14:44:32 +02:00
Tobias Brunner c04345d5ed daemon: Flush shunts before unloading plugins 2015-07-27 13:51:17 +02:00
Tobias Brunner bc36530670 shunt-manager: Add flush() method to properly uninstall shunts
This will allow us to uninstall shunts before unloading the
kernel-interface plugins.
2015-07-27 13:51:10 +02:00
Tobias Brunner 616ff9a236 shunt-manager: Remove stored entries if installation fails 2015-07-27 13:51:07 +02:00
Tobias Brunner f3d39666e0 shunt-manager: Add a lock to safely access the list of shunt policies 2015-07-27 13:50:52 +02:00
Tobias Brunner 12b3cdba76 trap-manager: Resolve race conditions between flush() and install()
When flush() is called there might be threads in install() waiting for
trap policies to get installed (without holding the lock).  We have to
wait until they updated the entries with the respective CHILD_SAs before
destroying the list.

We also have to prevent further trap policy installations (and wait until
threads in install() are really finished), otherwise we might end up
destroying CHILD_SA objects after the kernel interface implementations
have already been unloaded (avoiding this is the whole point of calling
flush() before unloading the plugins).
2015-07-27 13:50:19 +02:00
Tobias Brunner a229bdce62 trap-manager: Changed how acquires we acted on are tracked
This fixes potential race conditions in case complete() or flush() is
executed before or concurrently with a thread that handles an acquire.
It will also simplify tracking multiple acquires created for the same
trap policy in the future.

Also fixes the behavior in some error situations.
2015-07-27 13:50:09 +02:00
Tobias Brunner 773fcb1605 trap-manager: Properly check-in IKE_SA if initiating fails
This basically reverts f4e822c1b4 ("trap-manager: don't check-in
nonexisting IKE_SA if acquire fails").  As checkout_by_config() could
return an already existing and established IKE_SA we have to properly
destroy it, for instance, in case other threads are waiting to check
it out.  checkin_and_destroy() should handle the case of a new SA
properly (it produces a log message on level 1, though).
2015-07-27 13:49:26 +02:00
Tobias Brunner 6f7a3b33bc ike: Fall back to the current remote IP if it resolves to %any
In some situations it might be valid for a host that configures
right=%any to reestablish or reauthenticate an IKE_SA. Using %any would
immediately abort the initiation causing the new SA to fail (which
might already have the existing CHILD_SAs assigned).

Fixes #1027.
2015-07-27 13:45:16 +02:00
Tobias Brunner a11048adee ike: Use address family of local address when resolving remote host
If static local addresses are configured we should use their address family
as a hint when resolving the remote address.
We don't do this if %any is configured as this might break existing
configurations (%any4 and %any6 are however used as hint).
2015-07-27 12:09:41 +02:00
Tobias Brunner 834bf7ca5f ike-cfg: Add unit tests for ike_cfg_get_family() helper 2015-07-27 12:08:45 +02:00
Tobias Brunner 6bfa660693 ike-cfg: Add helper function to determine address family of IP addresses
All configured static addresses (hostnames, ranges or subnets are not
considered) must be of the same family, otherwise AF_UNSPEC is returned.
2015-07-27 11:59:37 +02:00
Andreas Steffen 63d370387d vici: Certification Authority support added.
CDP and OCSP URIs for a one or multiple certification authorities
can be added via the VICI interface. swanctl allows to read
definitions from a new authorities section.
2015-07-21 13:02:30 +02:00
Andreas Steffen e194349148 vici: Compute rekey_bytes and rekey_packets if life_bytes and life_packets are defined 2015-07-20 21:34:09 +02:00
Tobias Brunner 390ae7a2c2 ike-sa-manager: Safely access the RNG instance with an rwlock
Threads might still be allocating SPIs (e.g. triggered by an acquire or
an inbound message) while the main thread calls flush().  If there is a
context switch right after such a thread successfully checked this->rng
in get_spi() and the main thread destroys the RNG instance right then,
that worker thread will cause a segmentation fault when it continues and
attempts to call get_bytes().

Fixes #1014.
2015-07-14 15:25:23 +02:00
Martin Willi 856ea64129 vici: Asynchronize debug logging
The vici logger uses the listener_t.log() callback to raise vici events.

When doing so, it holds the bus lock as reader while acquiring the vici socket
mutex (1). If at the same time the vici socket enables a writer, that thread
tries to lock the watcher mutex (2). The watcher thread uses debugging while
holding the lock, i.e. acquires the bus read lock (3).

(1) bus.rlock -> vici.lock!
(2) vici.lock -> watcher.lock!
(3) watcher.lock -> bus.rlock!

This all actually would resolve just fine, as we have a shared read lock on the
bus. However, under Windows we seem to have a strict writer preference when
acquiring the rwlock (4). This results in blocking read locks until any pending
write lock can be fulfilled, and makes the constellation deadlock. The relevant
threads are:

Thread (1)
6  0x71313d25 in wait_ at threading/windows/mutex.c:137
7  0x7054c8a2 in find_entry at vici_socket.c:201
8  0x7054d690 in send_ at vici_socket.c:624
9  0x7054f6c1 in send_op at vici_dispatcher.c:119
10 0x705502c1 in raise_event at vici_dispatcher.c:469
12 0x704c3878 in log_cb at bus/bus.c:332
13 0x712c7c3a in invoke_function at collections/linked_list.c:414
14 0x704c3a63 in vlog at bus/bus.c:400
15 0x704c3b36 in log_ at bus/bus.c:430
18 0x70508f1f in process_response at sa/ikev2/task_manager_v2.c:664
20 0x704f5430 in process_message at sa/ike_sa.c:1369
21 0x704e3823 in execute at processing/jobs/process_message_job.c:74
22 0x712e629f in process_job at processing/processor.c:235

Thread (2)
4  0x71313b61 in lock at threading/windows/mutex.c:66
5  0x712e81fd in add at processing/watcher.c:441
6  0x712e1ab9 in add_watcher at networking/streams/stream.c:213
7  0x712e1b4d in on_write at networking/streams/stream.c:237
8  0x7054d606 in _cb_enable_writer at vici_socket.c:609
9  0x712e5e34 in execute at processing/jobs/callback_job.c:77
10 0x712e629f in process_job at processing/processor.c:235

Thread (3)
3  0x71313f38 in read_lock at threading/windows/rwlock.c:74
4  0x704c3971 in vlog at bus/bus.c:373
5  0x704cc156 in dbg_bus at daemon.c:126
6  0x712e7bf9 in watch at processing/watcher.c:316
7  0x712e5e34 in execute at processing/jobs/callback_job.c:77
8  0x712e629f in process_job at processing/processor.c:235

Thread (4)
3  0x71313f70 in write_lock at threading/windows/rwlock.c:82
4  0x704c378b in remove_logger at bus/bus.c:290
5  0x704cb284 in listener_unregister at control/controller.c:166
6  0x713136cd in thread_cleanup_pop at threading/windows/thread.c:558
8  0x704cb94e in initiate at control/controller.c:435
9  0x70553996 in _cb_initiate at vici_control.c:187
12 0x7054d200 in _cb_process_queue at vici_socket.c:508
13 0x712e5e34 in execute at processing/jobs/callback_job.c:77
14 0x712e629f in process_job at processing/processor.c:235

To avoid such a situation, we dissolve the (1) lock sequence. It's actually
never good practice to acquire shared locks during bus hooks, as it is
problematic if we raise bus events while holding the lock. We do so by
raising vici events for log message asynchronously, but of curse must keep
log order as is using a synchronized queue.
2015-07-12 13:57:48 +02:00
Martin Willi 98aa6aa344 unit-tests: Add a IKEv2 message encryption test case
It uses the ChaCha20Poly1305 test vectors from
draft-ietf-ipsecme-chacha20-poly1305-06.
2015-07-12 13:54:03 +02:00
Martin Willi ee9f691915 unit-tests: Forward variable argument list in TEST_SUITE_DEPEND
For some plugin features, such as crypters or AEADs, we have some additional
feature arguments, such as the key size.
2015-07-12 13:25:50 +02:00
Martin Willi 88d90c7b4b unit-tests: Load libstrongswan plugins in libcharon tests 2015-07-12 13:25:50 +02:00
Martin Willi 6ffaa8626e ikev2: Derive additional 4 byte CHILD_SA nonce keymat for ChaCha20-Poly1305 2015-06-29 17:32:13 +02:00
Martin Willi bbcb76e260 ikev2: Use four byte salt for ChaCha20-Poly1305 AEAD 2015-06-29 17:32:13 +02:00
Martin Willi 61d6cdb926 osx-attr: Optionally replace existing DNS server instead of appending them 2015-06-18 10:36:04 +02:00
Martin Willi 0020b25a45 ikev2: Enforce remote authentication config before proceeding with own authentication
Previously the constraints in the authentication configuration of an
initiator were enforced only after all authentication rounds were
complete.  This posed a problem if an initiator used EAP or PSK
authentication while the responder was authenticated with a certificate
and if a rogue server was able to authenticate itself with a valid
certificate issued by any CA the initiator trusted.

Because any constraints for the responder's identity (rightid) or other
aspects of the authentication (e.g. rightca) the initiator had were not
enforced until the initiator itself finished its authentication such a rogue
responder was able to acquire usernames and password hashes from the client.
And if a client supported EAP-GTC it was even possible to trick it into
sending plaintext passwords.

This patch enforces the configured constraints right after the responder's
authentication successfully finished for each round and before the initiator
starts with its own authentication.

Fixes CVE-2015-4171.
2015-06-05 13:44:42 +02:00
Martin Willi a49393954f child-sa: Use any fixed reqid configured on the CHILD_SA config
Global reqid allocation (94eb09ac) broke fixed reqid allocation. Resupport them
by bypassing allocation in the kernel if a fixed reqid has been configured.

Fixes #976.
2015-06-05 13:44:42 +02:00
Tobias Brunner 541543dbfe message: Log message if unknown/disallowed payload received 2015-06-01 09:42:11 +02:00
Tobias Brunner e67161fe9e message: Log original message type of unknown payloads 2015-06-01 09:42:11 +02:00
Tobias Brunner 1507647434 unknown-payload: Use a new private payload type and make original type available
This fixes a DoS and potential remote code execution vulnerability that was
caused because the original payload type that was returned previously was
used to cast such payload objects to payloads of the indicated type (e.g.
when logging notify payloads with a payload type for the wrong IKE version).

Fixes CVE-2015-3991.
2015-06-01 09:42:11 +02:00
Martin Willi 62e0abe759 ikev2: Include fragment number into message ID passed to IV gen
When using a cipher with sequential IVs, we never must pass an identical IV
to the IV generator. To avoid it when using IKEv2 fragmentation, use the lower
bits of the 64-bit message ID as the fragment number.
2015-06-01 09:42:11 +02:00
Martin Willi 823a8a9b46 message: Show the fragmentation numbers in message stringification 2015-06-01 09:42:10 +02:00
Tobias Brunner 711cb586fa ha: Document tunnel parameter 2015-05-27 12:59:39 +02:00
Tobias Brunner 06a5b0e2e8 ha: Skip SA for sync messages when resyncing HA segments 2015-05-26 15:43:46 +02:00
Tobias Brunner 0de116cadc ha: Move plugin initialization from constructor to plugin callback
This fixes support for the secret option, as otherwise the kernel interface
is not registered yet when the trap policy is installed.
2015-05-26 12:47:17 +02:00
Tobias Brunner e94aae83d3 vici: Explicitly disable --user-install when installing Ruby Gem
Only one of `--user-install` and `--install-dir` may be set and if
`--user-install` is the default on a system installation will fail
unless we disable it explicitly.

Fixes #914.
2015-05-21 17:22:11 +02:00
Tobias Brunner f16f792e17 vici: Make installation of Ruby Gem and Python Egg optional
Installing them might not work well when building distro packages (e.g.
with DESTDIR installs).  It might be easier to install them later with a
script in the distro package.

When building from source on the local system it could still be useful to
install the packages directly, which can be enabled with separate configure
options.

The main problem with DESTDIR installations of the Python Egg is that
easy_install creates or modifies a file called easy-install.pth in the
installation directory.  So it's not actually possible to simply copy
the results in DESTDIR over to the actual system as that file would have
to be merged with any existing one.

Fixes #914.
2015-05-21 17:22:01 +02:00
Tobias Brunner 5a817407bc vici: Support out-of-tree build of Python Egg
We also don't require setup.py to exist during cleanup, as e.g. with
make distcheck the source directory is not writable when the build directory
is cleaned, so setup.py can't be created (to just get removed again anyway
if VICI and the Python Eggs haven't been enabled previously).
2015-05-21 17:19:09 +02:00
Tobias Brunner 4112ebad4a ikev1: When a reauth is detected explicitly delete the old IKE_SA
Instead of just implicitly destroying the old SA we properly delete it to
notify the other peer (if the other peer keeps the SA up after the
reauthentication and sends DPDs it might consider us dead even though the
new SA is up, that seems to be the case with racoon).  We delay the DELETE
a bit to give the other peer time to get the new SA fully established.

Since DELETE messages are not retransmitted it is still possible that
the other peer misses that we deleted the SA.
2015-05-21 16:00:39 +02:00