Commit Graph

1243 Commits

Author SHA1 Message Date
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 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 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
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 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 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
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
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 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 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 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
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 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 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 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 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 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 03024f4ca8 trap-manager: Cleanup local address in error cases 2015-08-27 14:45: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
Tobias Brunner 471a996a3e ike: Also track initiating IKE_SAs as half-open 2015-08-21 18:21:13 +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 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 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 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 6967948241 Initialize variables that some compilers seem to warn about 2015-08-13 15:12:38 +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 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 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 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 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 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 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
Tobias Brunner 6a9a69ae58 ikev1: Trigger children_migrate event if CHILD_SAs are adopted 2015-05-21 15:38:31 +02:00
Tobias Brunner 32df0d81fb child-create: Destroy nonceg in migrate()
Since another nonce gets allocated later (if any was allocated already)
this would have resulted in a leaked nonce context ID when used in charon-tkm.
2015-05-05 10:55:14 +02:00
Tobias Brunner 252f2ef885 child-create: Fix error handling if nonceg can't be created
As with ike-init we can't return NULL in the task constructor.
2015-05-05 10:55:14 +02:00
Tobias Brunner 59565ebf60 ike-init: Fix error handling if nonceg can't be created
Returning FAILED in the constructor is wrong, but returning NULL doesn't work
either as it's currently assumed tasks always can be created.
Therefore, delay this check until we actually try to allocate a nonce.
2015-05-05 10:55:13 +02:00
Tobias Brunner d648d61375 ike-init: Fix compiler warning 2015-05-05 10:55:13 +02:00
Reto Buerki 0b308faf6d ike-init: Make nonceg a member of ike_init struct
This allows to control the life-cycle of a nonce in the context of the
ike init task. In the TKM use-case the nonce generator cannot be
destroyed before the ike init task is finalized, otherwise the created
nonce is detected as stale.
2015-05-04 18:07:51 +02:00
Reto Buerki 72376234cb child-create: Make nonceg a member of child_create struct
This allows to control the life-cycle of a nonce in the context of the
child create task. In the TKM use-case, it is required to reset the
nonce context if the created nonce is not consumed. This happens if the
child SA negotiation fails and it is detected before the SA is
established via the TKM kernel plugin (i.e. rekey collision).
2015-05-04 18:07:51 +02:00
Adrian-Ken Rueegsegger 8262be3cdc Add bool param to ALERT_KEEP_ON_CHILD_SA_FAILURE alert
The parameter indicates if the alert is raised upon failure to establish
the first CHILD SA of an IKE SA.
2015-05-04 18:07:29 +02:00
Tobias Brunner c5a41c9162 ike-vendor: Add some Microsoft vendor IDs 2015-04-21 15:30:51 +02:00
Martin Willi 161a015782 utils: Use chunk_equals_const() for all cryptographic purposes 2015-04-14 12:02:51 +02:00
Martin Willi 3c81cb6fc3 aead: Create AEAD using traditional transforms with an explicit IV generator
Real AEADs directly provide a suitable IV generator, but traditional crypters
do not. For some (stream) ciphers, we should use sequential IVs, for which
we pass an appropriate generator to the AEAD wrapper.
2015-04-13 15:06:15 +02:00
Tobias Brunner a2ec3b0546 Fixed some typos, courtesy of codespell 2015-03-25 12:00:20 +01:00
Tobias Brunner 70728eb1b6 child-sa: Add a new state to track rekeyed IKEv1 CHILD_SAs
This is needed to handle DELETEs properly, which was previously done via
CHILD_REKEYING, which we don't use anymore since 5c6a62ceb6 as it prevents
reauthentication.
2015-03-25 12:00:20 +01:00
Martin Willi 66147ef670 ikev1: Inverse check when applying received KE value during Quick Mode
Fixes Quick Mode negotiation when PFS is in use.
2015-03-24 09:37:38 +01:00
Martin Willi a777155ffe diffie-hellman: Add a bool return value to set_other_public_value() 2015-03-23 17:54:03 +01:00
Martin Willi 42431690e0 diffie-hellman: Add a bool return value to get_my_public_value() 2015-03-23 17:54:03 +01:00
Martin Willi 520d58e010 encoding: Allow ke_payload_create_from_diffie_hellman() to fail 2015-03-23 17:54:02 +01:00
Martin Willi bace1d6479 diffie-hellman: Use bool instead of status_t as get_shared_secret() return value
While such a change is not unproblematic, keeping status_t makes the API
inconsistent once we introduce return values for the public value operations.
2015-03-23 17:54:02 +01:00
Tobias Brunner a7172ddaff ikev1: Make sure SPIs in an IKEv1 DELETE payload match the current SA
OpenBSD's isakmpd uses the latest ISAKMP SA to delete other expired SAs.
This caused strongSwan to delete e.g. a rekeyed SA even though isakmpd
meant to delete the old one.

What isakmpd does might not be standard compliant. As RFC 2408 puts
it:

  Deletion which is concerned with an ISAKMP SA will contain a
  Protocol-Id of ISAKMP and the SPIs are the initiator and responder
  cookies from the ISAKMP Header.

This could either be interpreted as "copy the SPIs from the ISAKMP
header of the current message to the DELETE payload" (which is what
strongSwan assumed, and the direction IKEv2 took it, by not sending SPIs
for IKE), or as clarification that ISAKMP "cookies" are actually the
SPIs meant to be put in the payload (but that any ISAKMP SA may be
deleted).
2015-03-23 17:23:57 +01:00
Tobias Brunner 7fa03b308c trap-manager: Add option to ignore traffic selectors from acquire events
The specific traffic selectors from the acquire events, which are derived
from the triggering packet, are usually prepended to those from the
config.  Some implementations might not be able to handle these properly.

References #860.
2015-03-23 15:55:28 +01:00
Tobias Brunner 31be582399 ikev1: Adopt virtual IPs on new IKE_SA during re-authentication
Some clients like iOS/Mac OS X don't do a mode config exchange on the
new SA during re-authentication.  If we don't adopt the previous virtual
IP Quick Mode rekeying will later fail.

If a client does do Mode Config we directly reassign the VIPs we migrated
from the old SA, without querying the attributes framework.

Fixes #807, #810.
2015-03-19 10:32:06 +01:00
Tobias Brunner 5c6a62ceb6 ikev1: Mark rekeyed CHILD_SAs as INSTALLED
Since we keep them around until they finally expire they otherwise would block
IKE_SA rekeying/reauthentication.
2015-03-19 10:24:15 +01:00
Tobias Brunner 46188b0eb0 child-sa: Remove policies before states to avoid acquire events for untrapped policies 2015-03-19 09:54:03 +01:00
Martin Willi b8ecdfd895 ikev2: Migrate MOBIKE additional peer addresses to new SA after IKE_SA rekeying 2015-03-18 13:32:27 +01:00
Martin Willi 80a1ebb1d9 ikev2: Immediately initiate queued tasks after establishing rekeyed IKE_SA
If additional tasks get queued before/while rekeying an IKE_SA, these get
migrated to the new IKE_SA. We previously did not trigger initiation of these
tasks, though, leaving the task unexecuted until a new task gets queued.
2015-03-18 13:28:34 +01:00
Martin Willi 799f4c5db9 ikev2: Don't set old IKE_SA to REKEYING state during make-before-break reauth
We are actually not in rekeying state, but just trigger a separate, new IKE_SA
as a replacement for the current IKE_SA. Switching to the REKEYING state
disables the invocation of both IKE and CHILD_SA updown hooks as initiator,
preventing the removal of any firewall rules.

Fixes #885.
2015-03-11 14:48:08 +01:00
Martin Willi 942797a5b5 kernel-interface: Add a separate "update" flag to add_sa()
The current "inbound" flag is used for two purposes: To define the actual
direction of the SA, but also to determine the operation used for SA
installation. If an SPI has been allocated, an update operation is required
instead of an add.

While the inbound flag normally defines the kind of operation required, this
is not necessarily true in all cases. On the HA passive node, we install inbound
SAs without prior SPI allocation.
2015-03-09 18:18:20 +01:00
Martin Willi acad5e9f51 Revert "child-sa: Remove the obsolete update logic"
While the the meaning of the "inbound" flag on the kernel_interface->add_sa()
call is not very clear, we still need that update logic to allow installation of
inbound SAs without SPI allocation. This is used in the HA plugin as a passive
node.

This reverts commit 698ed656.
2015-03-09 18:18:20 +01:00
Tobias Brunner 708dff0700 ikev2: Move code in pubkey authenticator's build() method into separate functions 2015-03-09 16:59:07 +01:00
Tobias Brunner 03a340c6c6 ikev2: Try all eligible signature schemes
Previously, we failed without recovery if a private key did not support
a selected signature scheme (based on key strength and the other peer's
supported hash algorithms).
2015-03-09 16:59:07 +01:00
Tobias Brunner 9fda0bf007 ikev1: Set protocol ID and SPIs in INITIAL-CONTACT notification payloads
The payload we sent before is not compliant with RFC 2407 and thus some
peers might abort negotiation (e.g. with an INVALID-PROTOCOL-ID error).

Fixes #819.
2015-03-06 16:50:13 +01:00
Tobias Brunner 4e6f102842 ikev2: Try all RSA signature schemes if none is configured 2015-03-04 13:54:12 +01:00
Tobias Brunner 1d94b7950b ikev2: Consider signature schemes in rightauth when sending hash algorithms 2015-03-04 13:54:12 +01:00
Tobias Brunner f9e0caab6d keymat: Use hash algorithm set 2015-03-04 13:54:11 +01:00
Tobias Brunner b67ae0f89c ikev2: Add an option to disable constraints against signature schemes
If this is disabled the schemes configured in `rightauth` are only
checked against signature schemes used in the certificate chain and
signature schemes used during IKEv2 are ignored.

Disabling this could be helpful if existing connections with peers that
don't support RFC 7427 use signature schemes in `rightauth` to verify
certificate chains.
2015-03-04 13:54:11 +01:00
Tobias Brunner cc048f0c50 ikev2: Fall back to SHA-1 signatures for RSA
This is really just a fallback to "classic" IKEv2 authentication if the other
peer supports no stronger hash algorithms.
2015-03-04 13:54:10 +01:00
Tobias Brunner 0bdc79b5f9 ikev2: Select a signature scheme appropriate for the given key
By enumerating hashes we'd use SHA-1 by default.  This way stronger
signature schemes are preferred.
2015-03-04 13:54:10 +01:00
Tobias Brunner 0b14ce5802 ikev2: Log the actual signature scheme used for RFC 7427 authentication 2015-03-04 13:54:09 +01:00
Tobias Brunner a7bbe59f85 ikev2: Store signature scheme used to verify peer in auth_cfg
This enables late connection switching based on the signature scheme used
for IKEv2 and allows to enforce stronger signature schemes.

This may break existing connections with peers that don't support RFC 7427
if signature schemes are currently used in `rightauth` for certificate chain
validation and if the configured schemes are stronger than the default used
for IKE (e.g. SHA-1 for RSA).
2015-03-04 13:54:09 +01:00
Tobias Brunner fff3576b6b ikev2: Add a global option to disable RFC 7427 signature authentication
This is mostly for testing.
2015-03-04 13:54:09 +01:00
Tobias Brunner 6a2a9bfb48 ikev2: Remove private AUTH_BLISS method
We use the new signature authentication instead for this.  This is not
backward compatible but we only released one version with BLISS support,
and the key format will change anyway with the next release.
2015-03-04 13:54:09 +01:00
Tobias Brunner 295e37ab66 ikev2: Handle RFC 7427 signature authentication in pubkey authenticator 2015-03-04 13:54:09 +01:00
Tobias Brunner f6329cae9c ikev2: Enable signature authentication by transmitting supported hash algorithms 2015-03-04 13:54:08 +01:00
Tobias Brunner 828e71bd43 keymat: Add facility to store supported hash algorithms 2015-03-04 13:54:08 +01:00
Tobias Brunner 7cd8371da2 ikev2: Add new authentication method defined by RFC 7427 2015-03-04 13:54:08 +01:00
Tobias Brunner dd0ebb5483 ikev2: Only accept initial messages in specific states
The previous code allowed an attacker to slip in an IKE_SA_INIT with
both SPIs and MID 1 set when an IKE_AUTH would be expected instead.

References #816.
2015-03-04 13:47:53 +01:00
Tobias Brunner 650a3ad515 ike-sa-manager: Make sure the message ID of initial messages is 0
It is mandated by the RFCs and it is expected by the task managers.

Initial messages with invalid MID will be treated like regular messages,
so no IKE_SA will be created for them.  Instead, if the responder SPI is 0
no SA will be found and the message is rejected with ALERT_INVALID_IKE_SPI.
If an SPI is set and we do find an SA, then we either ignore the message
because the MID is unexpected, or because we don't allow initial messages
on established connections.

There is one exception, though, if an attacker can slip in an IKE_SA_INIT
with both SPIs set before the client's IKE_AUTH is handled by the server,
it does get processed (see next commit).

References #816.
2015-03-04 13:47:53 +01:00
Tobias Brunner eb25190629 ikev2: Don't destroy the SA if an IKE_SA_INIT with unexpected MID is received
This reverts 8f727d8007 ("Clean up IKE_SA state if IKE_SA_INIT request
does not have message ID 0") because it allowed to close any IKE_SA by
sending an IKE_SA_INIT with an unexpected MID and both SPIs set to those
of that SA.

The next commit will prevent SAs from getting created for IKE_SA_INIT messages
with invalid MID.

Fixes #816.
2015-03-04 13:47:53 +01:00