Commit Graph

1214 Commits

Author SHA1 Message Date
Tobias Brunner d9fe0ec712 ikev2: (Re-)Queue tasks used to establish an IKE_SA in reset()
Some tasks might get removed immediately once the IKE_SA_INIT response has
been handled even if there were notifies that require a restart of the
IKE_SA (e.g. COOKIE or INVALID_KE_PAYLOAD).  Such a task is ike_vendor,
which caused vendor IDs not to get sent in a retry.  This change ensures
all required tasks are queued after the reset, which some callers did
already anyway.
2016-09-06 10:09:17 +02:00
Tobias Brunner fd1662cdbd ikev2: Store proposal on IKE_SA before creating DH object
This might be useful for custom implementations of keymat_t.
2016-09-06 09:38:22 +02:00
Tobias Brunner 17ecc104fb ikev1: Ignore the last two bytes of the Cisco Unity vendor ID
These seem to indicate the major and minor version of the protocol, like
e.g. for the DPD vendor ID.  Some implementations seem to send versions
other than 1.0 so we just ignore these for now when checking for known
vendor IDs.

Fixes #2088.
2016-08-24 17:46:05 +02:00
Tobias Brunner 60d0f52fd6 ike1: Flush active queue when queueing a delete of the IKE_SA
By aborting the active task we don't have to wait for potential
retransmits if the other peer does not respond to the current task.
Since IKEv1 has no sequential message IDs and INFORMATIONALs are no real
exchanges this should not be a problem.

Fixes #1537
References #429, #1410
Closes strongswan/strongswan#48
2016-07-19 11:48:17 +02:00
Tobias Brunner 15cea08adc child-rekey: Only rekey installed CHILD_SAs
Depending on the lifetimes a CHILD_SA we rekeyed as responder might
expire shortly afterwards.  We don't want to rekey it again.

When retrying due to an INVALID_KE_PAYLOAD notify the expected state
is CHILD_REKEYING if it is anything else (e.g. due to a collision) we
ignore it.

We also abort the exchange properly if we don't find the CHILD_SA, no
need for an empty INFORMATIONAL exchange anymore.
2016-06-17 18:48:08 +02:00
Tobias Brunner 6d8041d46b child-rekey: Ignore failed colliding CHILD_SA rekeyings
If a passive rekeying fails due to an INVALID_KE_PAYLOAD we don't want
to consider this task later when resolving collisions.  This previously
might have caused the wrong SA to get deleted/installed based on the nonces
in the unsuccessful exchange.
2016-06-17 18:48:08 +02:00
Tobias Brunner b92f11c3bd child-create: Retry creating the CHILD_SA if TEMPORARY_FAILURE is received
We queue a delayed task that is initiated after a while.
2016-06-17 18:48:07 +02:00
Tobias Brunner 208678e6e1 ikev2: Add possibility to delay initiation of a queued task
Such a task is not initiated unless a certain time has passed.  This
allows delaying certain tasks but avoids problems if we'd do this
via a scheduled job (e.g. if the IKE_SA is rekeyed in the meantime).

If the IKE_SA is rekeyed the delay of such tasks is reset when the
tasks are adopted i.e. they get executed immediately on the new IKE_SA.

This hasn't been implemented for IKEv1 yet.
2016-06-17 18:48:07 +02:00
Tobias Brunner 4e2e7d4fec ike: Reduce RETRY_INTERVAL a bit
Retry exchanges between 5 and 15 seconds after a temporary failure.
2016-06-17 18:48:07 +02:00
Tobias Brunner 2045cadc1c ike-rekey: Return TEMPORARY_FAILURE when concurrently creating a CHILD_SA 2016-06-17 18:48:07 +02:00
Tobias Brunner 0a954d6789 ike: Add configuration option to switch to preferring supplied proposals over local ones 2016-06-17 18:48:07 +02:00
Tobias Brunner f2ea230b91 child-cfg: Add option to prefer supplied proposals over locally configured ones 2016-06-17 18:48:07 +02:00
Tobias Brunner 3a40d572c6 ike-cfg: Add option to prefer supplied proposals over locally configured ones 2016-06-17 18:48:07 +02:00
Tobias Brunner 09711198a7 ike-rekey: Make sure to ignore task when detecting collisions if ike-init subtask failed
For instance, if INVALID_KE_PAYLOAD is returned we don't want this task
to affect any active rekeying (no new SA has been established so far).
2016-06-17 18:48:06 +02:00
Tobias Brunner f67199378d ike-rekey: Handle undetected collisions also if delete is delayed
If the peer does not detect the rekey collision and deletes the old
IKE_SA and then receives the colliding rekey request it will respond with
TEMPORARY_FAILURE.  That notify may arrive before the DELETE does, in
which case we may just conclude the rekeying initiated by the peer.

Also, since the IKE_SA is destroyed in any case when we receive a delete
there is no point in storing the delete task in collide() as process_i()
in the ike-rekey task will never be called.
2016-06-17 18:48:06 +02:00
Tobias Brunner 7426576184 ike-rekey: There is no passive reauth task, so it will never collide with one 2016-06-17 18:48:06 +02:00
Tobias Brunner 724d65900c ike-rekey: Ignore colliding rekey tasks that did not create an IKE_SA
This simplifies collision handling and we don't need to know about these
tasks when concluding the rekeying we initiated.
2016-06-17 18:48:06 +02:00
Tobias Brunner 1b989dd4c5 ike-rekey: Properly handle situation if the peer did not notice the rekey collision
We conclude the rekeying before deleting the IKE_SA.  Waiting for the
potential TEMPORARY_FAILURE notify is no good because if that response
does not reach us the peer will not retransmit it upon our retransmits
of the rekey request if it already deleted the IKE_SA after receiving
our response to the delete.
2016-06-17 18:48:06 +02:00
Tobias Brunner 6270bbde6a ike-delete: Handle deletes while rekeying differently if there was a collision
We treat these as if we concluded the rekeying, the active ike-rekey task
will handle the collision afterwards.
2016-06-17 18:48:06 +02:00
Tobias Brunner 13da616118 ike-rekey: Add method to check if there was a rekey collision 2016-06-17 18:48:06 +02:00
Tobias Brunner 1cca20705a ikev2: Check for collisions after handling IKE deletion 2016-06-17 18:48:06 +02:00
Tobias Brunner 144bebe4b2 child-delete: Reply as usual when concurrently rekeying the IKE_SA
As per RFC 7296, 2.25.2 (what we did before was the behavior described
in RFC 4718).
2016-06-17 18:48:06 +02:00
Tobias Brunner 869b7075fc child-create: Respond with TEMPORARY_FAILURE while rekeying/deleting IKE_SA 2016-06-17 18:48:05 +02:00
Tobias Brunner 83191e56b2 ike-rekey: Respond with TEMPORARY_FAILURE if CHILD_SAs are currently rekeyed/deleted/established 2016-06-17 18:48:05 +02:00
Tobias Brunner 8a78e41f29 ike-rekey: Handle TEMPORARY_FAILURE notify 2016-06-17 18:48:05 +02:00
Tobias Brunner c0976a5e01 ike-rekey: Respond with TEMPORARY_FAILURE if we are deleting the SA 2016-06-17 18:48:05 +02:00
Tobias Brunner 78e8152d01 ike-delete: No need to wait for a response in case of concurrent deletes
RFC 7296 explicitly says we SHOULD reply as usual and forget about our
own close request.
2016-06-17 18:48:05 +02:00
Tobias Brunner bb3899739d ikev2: Add a new state to track rekeyed IKE_SAs
This makes handling such IKE_SAs more specifically compared to keeping them
in state IKE_CONNECTING or IKE_ESTABLISHED (which we did when we lost a
collision - even triggering the ike_updown event), or using IKE_REKEYING for
them, which would also be ambiguous.

For instance, we can now reject anything but DELETES for such SAs.
2016-06-17 18:48:05 +02:00
Tobias Brunner d6ac7496e6 ike-rekey: Add the name/ID of the redundant IKE_SAs to the log messages 2016-06-17 18:48:04 +02:00
Tobias Brunner b7fac1d96e ike-sa-manager: Make sure rng is defined before destroying it in flush()
This allows calling flush() multiple times.
2016-06-17 18:48:04 +02:00
Tobias Brunner 851ee4eeb7 ike-rekey: Establish new IKE_SA earlier as responder, but only if no collision
Moving to the new SA only after receiving the DELETE for the old SA was
not ideal as it rendered the new SA unusable (because it simply didn't
exist in the manager) if the DELETE was delayed/got dropped.
2016-06-17 18:48:04 +02:00
Tobias Brunner 7a23226c32 child-delete: Check if the deleted CHILD_SA is the redundant SA of a collision
This happens if the peer deletes the redundant SA before we are able to
handle the response. The deleted SA will be in state CHILD_INSTALLED but
we don't want to trigger the child_updown() event for it or recreate it.
2016-06-17 18:48:04 +02:00
Tobias Brunner 4f1012b3e1 child-rekey: Add method to check for the redundant SA created in a collision 2016-06-17 18:48:04 +02:00
Tobias Brunner 5ef033c53b child-rekey: Don't change state to INSTALLED if it was already REKEYING
This happens if there is a rekey collision and the peers disagree on the
DH group.
2016-06-17 18:48:03 +02:00
Tobias Brunner cdbf942889 ikev2: Use CHILD_REKEYED for replaced CHILD_SAs after rekeying
This allows handling collisions better, in particular with deletions.
2016-06-17 18:48:03 +02:00
Tobias Brunner 5bbb9d703c child-rekey: Use more appropriate error notifies if CHILD_SA is not found or getting deleted
These are the notifies we should return according to RFC 7296.
2016-06-17 18:48:02 +02:00
Tobias Brunner 334b0bc84a child-rekey: Recreate the CHILD_SA if we receive a CHILD_SA_NOT_FOUND notify 2016-06-17 18:48:02 +02:00
Tobias Brunner b7b414463d child-create: Handle TEMPORARY_FAILURE notify as failure
We will later add code to retry creating the CHILD_SA if we are not
rekeying.  Rekeying is already rescheduled as with any other errors.
2016-06-17 18:48:02 +02:00
Tobias Brunner 94012e3f42 child-delete: Remove unnecessary call to destroy_child_sa()
Generally, we will not find the CHILD_SA by searching for it with the
outbound SPI (the initiator of the DELETE sent its inbound SPI) - and if
we found a CHILD_SA it would most likely be the wrong one (one in which
we used the same inbound SPI as the peer used for the one it deletes).

And we don't actually want to destroy the CHILD_SA at this point as we
know we already initiated a DELETE ourselves, which means that task
still has a reference to it and will destroy the CHILD_SA when it
receives the response from the other peer.
2016-06-17 18:48:01 +02:00
Tobias Brunner 9e01d7ca32 quick-mode: Fix reporting lifebytes if lifetime is configured 2016-06-17 11:34:26 +02:00
Tobias Brunner b2abd01048 child-sa: Use non-static variable to store generated unique mark
If two CHILD_SAs with mark=%unique are created concurrently they could
otherwise end up with either the same mark or different marks in both
directions.
2016-06-06 14:17:11 +02:00
Tobias Brunner e35bb6e946 ike: Don't trigger message hook when fragmenting pre-generated messages
This is the case for the IKE_SA_INIT and the initial IKEv1 messages, which
are pre-generated in tasks as at least parts of it are used to generate
the AUTH payload.  The IKE_SA_INIT message will never be fragmented, but
the IKEv1 messages might be, so we can't just call generate_message().

Fixes #1478.
2016-06-06 14:12:48 +02:00
Tobias Brunner bd71ba0ffb task-manager: Add retransmit cleared alert 2016-06-06 14:11:01 +02:00
Thomas Egerer 9da65eaeb9 task-manager: Add retransmit count to retransmit send alert
Signed-off-by: Thomas Egerer <thomas.egerer@secunet.com>
2016-06-06 14:11:01 +02:00
Tobias Brunner 1b4e7fe1e8 ikev1: Queue INFORMATIONAL messages during XAuth
Some peers send an INITIAL_CONTACT notify after they received our XAuth
username.  The XAuth task waiting for the third XAuth message handles
this incorrectly and closes the IKE_SA as no configuration payloads are
contained in the message.  We queue the INFORMATIONAL until the XAuth
exchange is complete to avoid this issue.

Fixes #1434.
2016-06-06 13:52:58 +02:00
Tobias Brunner a6289d9323 ikev2: Handle INITIAL_CONTACT notifies also when peer is authenticated with EAP
Fixes #1380.
2016-06-06 13:49:21 +02:00
Tobias Brunner 979f465113 child-sa: Install "outbound" FWD policy with lower priority
This provides a fix if symmetrically overlapping policies are
installed as e.g. the case in the ikev2/ip-two-pools-db scenario:

  carol 10.3.0.1/32 ----- 10.3.0.0/16, 10.4.0.0/16 moon
  alice 10.4.0.1/32 ----- 10.3.0.0/16, 10.4.0.0/16 moon

Among others, the following FWD policies are installed on moon:

  src 10.3.0.1/32 dst 10.4.0.0/16
    ...
    tmpl ...

  src 10.4.0.0/16 dst 10.3.0.1/32
    ...

  src 10.4.0.1/32 dst 10.3.0.0/16
    ...
    tmpl ...

  src 10.3.0.0/16 dst 10.4.0.1/32
    ...

Because the network prefixes are the same for all of these they all have the
same priority.  Due to that it depends on the install order which policy gets
used.  For instance, a packet from 10.3.0.1 to 10.4.0.1 will match the
first as well as the last policy.  However, when handling the inbound
packet we have to use the first one as the packet will otherwise be
dropped due to a template mismatch.  And we can't install templates with
the "outbound" FWD policies as that would prevent using different
IPsec modes or e.g. IPComp on only one of multiple SAs.

Instead we install the "outbound" FWD policies with a lower priority
than the "inbound" FWD policies so the latter are preferred.  But we use
a higher priority than default drop policies would use (in case they'd
be defined with the same subnets).
2016-05-06 20:27:18 +02:00
Tobias Brunner 9c01e01420 trap-manager: Allow local address to be unspecified
If there is currently no route to reach the other peer we just default
to left=%any.  The local address is only really used to resolve
leftsubnet=%dynamic anyway (and perhaps for MIPv6 proxy transport mode).

Fixes #1375.
2016-05-06 15:56:19 +02:00
Tobias Brunner 612fe5410b ikev1: Activate DELETE tasks before other tasks in state ESTABLISHED
Fixes #1410.
2016-05-06 15:35:16 +02:00
Tobias Brunner bf3bed1cc4 ikev1: Don't use rekeyed CHILD_SAs for rekey detection
An old (already rekeyed) CHILD_SA would get switched back into CHILD_REKEYING
state.  And we actually want to change the currently installed CHILD_SA to
that state and later CHILD_REKEYED and properly call e.g. child_rekey() and
not do this again with an old CHILD_SA.  Instead let's only check installed
or currently rekeying CHILD_SAs (in case of a rekey collision).  It's also
uncommon that there is a CHILD_SA in state CHILD_REKEYED but none in state
CHILD_INSTALLED or CHILD_REKEYING, which could happen if e.g. a peer deleted
and recreated a CHILD_SA after a rekeying.  But in that case we don't want
to treat the new CHILD_SA as rekeying (e.g. in regards to events on the bus).
2016-05-06 15:31:31 +02:00