Commit Graph

3672 Commits

Author SHA1 Message Date
Tobias Brunner e92d8a56b3 ikev1: First do PSK lookups based on identities then fallback to IPs
This provides a solution for configs where there is e.g. a catch-all %any
PSK, while more specific PSKs would be found by the identities of configs
that e.g. use FQDNs as local/remote addresses.

Fixes #2223.
2017-03-20 10:17:56 +01:00
Thomas Egerer 11c40012a3 ike-sa-manager: Remove superfluous assignment
Memory is allocated with calloc, hence set to zero, thus assigning the
numerical value 0 is not required.

Signed-off-by: Thomas Egerer <thomas.egerer@secunet.com>
2017-03-16 08:41:43 +01:00
Tobias Brunner 1e0040ec45 ike: Log remote IP when deleting half-open IKE_SAs 2017-03-15 16:24:25 +01:00
Tobias Brunner d8f0d9c284 quick-mode: Correctly prepare NAT-OA payloads as responder
The initiator's address was sent back twice previously.

Fixes #2268.
2017-03-06 15:10:35 +01:00
Tobias Brunner df9e512523 controller: Don't listen for CHILD_SA state changes when terminating IKE_SAs
We actually want to wait until the IKE_SA is destroyed, not any of the
CHILD_SAs (even though there might not be that much of a difference
depending on the number of CHILD_SAs).

Fixes #2261.
2017-03-02 09:10:48 +01:00
Tobias Brunner 6d86d0f516 kernel: Make range of SPIs for IPsec SAs configurable 2017-03-02 08:52:56 +01:00
Martin Willi d536b94e0d addrblock: Use dynamic TS narrowing instead of rejecting the whole CHILD_SA
Previously, the client had to propose no wider selectors than the certificate
permits, otherwise the complete CHILD_SA was rejected. However, with IKEv2
we can dynamically narrow the selectors to what the certificate allows. This
makes client and gateway configurations very simple by just proposing 0.0.0.0/0,
narrowed to selectors the client is permitted to route into the network.
2017-03-02 08:24:02 +01:00
Martin Willi d1317adb9a addrblock: Support an optional non-strict mode accepting certs without addrblock
This allows a gateway to enforce the addrblock policy on certificates that
actually have the extension only. For (legacy) certificates not having the
extension, traffic selectors are validated/narrowed by other means, most
likely by the configuration.
2017-03-02 08:24:02 +01:00
Tobias Brunner da82786b2d child-cfg: Always apply hosts to traffic selectors if proposing transport mode
Usually, %dynamic is used as traffic selector for transport mode SAs,
however, if wildcard traps are used then the remote TS will be a subnet.
With strongSwan at the remote end that usually works fine as the local
%dynamic TS narrows the proposed TS appropriately.  But some
implementations reject non-host TS for transport mode SAs.
Another problem could be if several distinct subnets are configured for a
wildcard trap, as we'd then propose unrelated subnets on that transport
mode SA, which might be problematic even for strongSwan (switch to tunnel
mode and duplicate policies).

Closes strongswan/strongswan#61.
2017-02-27 18:23:56 +01:00
Tobias Brunner f15c85a487 ikev1: Respond to DPDs for rekeyed IKE_SAs
Some devices always use the oldest IKE_SA to send DPDs and will delete
all IKE_SAs when there is no response. If uniqueness is not enforced
rekeyed IKE_SAs might not get deleted until they expire so we should
respond to DPDs.

References #2090.
2017-02-17 11:37:24 +01:00
Martin Willi 597e8c9e00 ike-sa: Optionally try to migrate to the best path on routing priority changes
When multihomed, a setup might prefer to dynamically stay on the cheapest
available path by using MOBIKE migrations. If the cheapest path goes away and
comes back, we currently stay on the more expensive path to reduce noise and
prevent potential migration issues. This is usually just fine for links not
generating real cost.

If we have more expensive links in the setup, it can be desirable to always
migrate to the cheapest link available. By setting charon.prefer_best_path,
charon tries to migrate to the path using the highest priority link, allowing
an external application to update routes to indirectly control MOBIKE behavior.
This option has no effect if MOBIKE is unavailable.
2017-02-17 11:19:38 +01:00
Tobias Brunner be27e76869 ikev2: Ignore roam events without MOBIKE but static local address
Disabling MOBIKE and statically configuring a local address should be
enough indication that the user doesn't want to roam to a different
address.  There might not be any routes that indicate we can use the
current address but it might still work (e.g. if the address is on an
interface that is not referenced in any routes and the address itself
is neither).  This way we avoid switching to another address for routes
that might be available on the system.

We currently don't make much use of COND_STALE anyway when MOBIKE is not
enabled, e.g. to avoid sending DPDs if the connection is seemingly down.
With MOBIKE enabled we don't exactly check that state but we do don't
send DPDs if there is no route/source address available.
2017-02-17 10:52:21 +01:00
Tobias Brunner 5a7a17b777 ike-cfg: Add helper function to determine if a given IP address was configured 2017-02-17 10:52:21 +01:00
Tobias Brunner 8bd8dcd522 vici: Only log messages if there actually is a listener 2017-02-16 19:24:09 +01:00
Tobias Brunner fa5f6ba26c vici: Let has_event_listeners() actually check if clients are registered
Fixes: 8d96f90a79 ("vici: Add function to test if an event should be
generated")
2017-02-16 19:24:09 +01:00
Tobias Brunner f927ba975b vici: Add support for mediation extension 2017-02-16 19:24:09 +01:00
Tobias Brunner ed96fe72cf peer-cfg: Store mediated_by as name and not peer-cfg reference
This way updates to the mediation config are respected and the order in
which configs are configured/loaded does not matter.

The SQL plugin currently maintains the strong relationship between
mediated and mediation connection (we could theoretically change that to a
string too).
2017-02-16 19:24:09 +01:00
Tobias Brunner ec5f127a45 vici: Include uniqueness policy in list-conns 2017-02-16 19:24:09 +01:00
Tobias Brunner 808472c9f9 vici: Add command to initiate SA rekeying 2017-02-16 19:24:08 +01:00
Tobias Brunner 04c0219e55 vici: Use unique names for CHILD_SAs in the list-sas command
The original name is returned in the new "name" attribute.

This fixes an issue with bindings that map VICI messages to
dictionaries.  For instance, in roadwarrior scenarios where every
CHILD_SA has the same name only the information of the last CHILD_SA
would end up in the dictionary for that name.
2017-02-16 19:24:08 +01:00
Tobias Brunner bd6ef6be7e vici: Add support to load CA certificates from tokens and paths in authority sections 2017-02-16 19:24:08 +01:00
Tobias Brunner 2f8354ca6c vici: Add support to load certificates from file paths
Probably not that useful via swanctl.conf but could be when used via VICI.
2017-02-16 19:24:08 +01:00
Tobias Brunner 00bf6a2a49 vici: Add support to load certificates from tokens 2017-02-16 19:24:08 +01:00
Tobias Brunner 2ceeb96db5 vici: Add command to load a private key from a token
PINs are stored in a "hidden" credential set, so that its shared
secrets are not exposed via VICI.  Since they are not explicitly loaded as
shared secrets via VICI a client might consider them as removed secrets and
remove them.
2017-02-16 19:24:07 +01:00
Tobias Brunner b657740e16 vici: List namespace/peer-cfg name with policies and allow filtering
The two names are also transmitted in separate keys.
2017-02-16 19:24:07 +01:00
Tobias Brunner 7627f5f9c7 vici: Explicitly use peer name when uninstalling trap and shunt policies
Also adds an `ike` parameter to the `uninstall` command.
2017-02-16 19:24:07 +01:00
Tobias Brunner 02767e4309 stroke: Use peer name as namespace for shunt policies
The same goes for the start-action-job.  When unrouting, we search for
the first policy with a matching child-cfg.
2017-02-16 19:24:07 +01:00
Tobias Brunner 7a0fdbab42 shunt-manager: Add an optional namespace for each shunt
This will allow us to reuse the names of child configs e.g. when they
are defined in different connections.
2017-02-16 19:24:07 +01:00
Tobias Brunner ed105f45af vici: Add support for NT Hash secrets
Fixes #1002.
2017-02-16 19:23:51 +01:00
Tobias Brunner 3bedf10b25 vici: Add support for IPv6 Transport Proxy Mode 2017-02-16 19:23:50 +01:00
Tobias Brunner e00bc9f6b2 vici: Add support for certificate policies 2017-02-16 19:23:50 +01:00
Tobias Brunner 44fcc83310 vici: Add missing dscp setting for IKE_SAs
Fixes #2170.
2017-02-16 19:23:31 +01:00
Tobias Brunner cf57d9a98f vici: Add possibility to remove shared keys by a unique identifier
This identifier can be set when adding/replacing a secret.  The unique
identifiers of all secrets may be enumerated.
2017-02-16 19:21:13 +01:00
Tobias Brunner 2a56acf501 vici: Add commands to enumerate and remove private keys
They are identified by their SHA-1 key identifier.
2017-02-16 19:21:12 +01:00
Tobias Brunner d20bf50e04 vici: Update get_pools() in Python and Ruby bindings 2017-02-16 19:21:12 +01:00
Tobias Brunner 71fa1224ec vici: Add option to query a specific pool 2017-02-16 19:21:12 +01:00
Tobias Brunner c2129d1cbe bypass-lan: Don't use interfaces in policies
After an interface disappeared we can't remove the policies correctly as
the name doesn't resolve to the previous index anymore.
And making the policies so specific might not provide that much benefit.

To handle the interfaces on the policies correctly would require some
changes to the child-cfg, kernel-interface etc. so they'd take interface
indices directly so we could target the policies correctly even if an
interface disappeared (or reappeared and got a new index).
2017-02-16 19:20:18 +01:00
Eyal Birger 067fd2c69c child-sa: Do not install mark on inbound kernel SA
The SA ID (src, dst, proto, spi) is unique on ingress.

As such, explicit inbound marking is not needed to match an SA.

On the other hand, requiring inbound SAs to use marks forces the
installation of a mechanism for marking traffic (e.g. iptables) based
on some criteria.

Defining the criteria becomes complicated, for example when required to
support multiple SAs from the same src, especially when traffic is UDP
encapsulated.

This commit removes the assignment of the child_sa mark_in to the inbound SA.

Policies can be arbitrated by existing means - e.g, via netfilter policy
matching or using VTI interfaces - without the need to classify the flows prior
to state matching.

Since the reqid allocator regards the mark value, there is no risk of matching
the wrong policy.

And as explicit marking was required for route-based VPN to work before this
change, it should not cause regressions in existing setups.

Closes strongswan/strongswan#59.
2017-02-14 18:34:15 +01:00
Martin Willi 395500b8c1 kernel-netlink: Use RTA_SRC to specify route source in kernel-based lookups
For table dumps the kernel accepts RTA_PREFSRC to filter the routes, which is
what we do when doing userspace route calculations. For kernel-based route
lookups, however, the RTA_PREFSRC attribute is ignored and we must specify
RTA_SRC for policy based route lookups.
2017-02-13 15:11:20 +01:00
Martin Willi 558691b3b0 kernel-netlink: Use kernel-based route lookup if we do not install routes
For gateways with many connections, installing routes is often disabled,
as we can use a static route configuration to achieve proper routing with
a single rule. If this is the case, there is no need to dump all routes and
do userspace route lookups, as there is no need to exclude routes we installed
ourself.

Doing kernel-based route lookups is not only faster with may routes, but also
can use the full power of Linux policy based routing; something we can hardly
rebuild in userspace when calculating routes.
2017-02-13 15:11:20 +01:00
Martin Willi 0b4e539cb3 vici: Include the Netfilter marks in listed CHILD_SAs 2017-02-13 15:11:20 +01:00
Martin Willi 22f08609f1 vici: Explicitly set the Python encoding type
When using vici over RPyC and its (awesome) splitbrain, encoding and decoding
strings fails in vici, most likely because of the Monkey-Patch magic splitbrain
uses.

When specifying the implicit UTF-8 as encoding scheme explicitly, Python uses
the correct method to encode/decode the string, making vici useable in
splitbrain contexts.
2017-02-13 15:04:44 +01:00
Tobias Brunner 2f6ec15dff unit-tests: Add test cases for MID sync exchanges 2017-02-08 15:11:00 +01:00
Tobias Brunner cbb6885e9b ikev2: Ignore IKEV2_MESSAGE_ID_SYNC notifies if extension is disabled
If this is the first message by the peer, i.e. we expect MID 0, the
message is not pre-processed in the task manager so we ignore it in the
task.

We also make sure to ignore such messages if the extension is disabled
and the peer already sent us one INFORMATIONAL, e.g. a DPD (we'd otherwise
consider the message with MID 0 as a retransmit).
2017-02-08 15:10:51 +01:00
Tobias Brunner c3d98d298e ikev2: Don't increase expected MID after handling MID sync message
If the responder never sent a message the expected MID is 0.  While
the sent MID (M1) SHOULD be increased beyond the known value, it's
not necessarily the case.
Since M2 - 1 would then equal UINT_MAX setting that MID would get ignored
and while we'd return 0 in the notify we'd actually expect 1 afterwards.
2017-02-08 15:03:26 +01:00
Tobias Brunner fb57904cbf ikev2: Don't cache response to MID sync request 2017-02-08 15:03:25 +01:00
Tobias Brunner 3abc104f7e ikev2: Accept INFORMATIONAL messages with MID 0 if used to sync MIDs
We are very picky to only allow MID 0 for these messages (while we
currently don't support IPSEC_REPLAY_COUNTER_SYNC notifies we accept
them).
2017-02-08 15:03:25 +01:00
Tobias Brunner d6ffa85fea ikev2: Negotiate support for IKE message ID synchronisation during IKE_AUTH 2017-02-08 15:03:25 +01:00
Tobias Brunner 5ab59221d2 ikev2: Add task to handle IKEV2_MESSAGE_ID_SYNC notifies as responder 2017-02-08 15:03:25 +01:00
Tobias Brunner 347c403cf6 ike: Publish getter for the current message ID on IKE_SA 2017-02-08 15:03:25 +01:00