Commit Graph

2213 Commits

Author SHA1 Message Date
Tobias Brunner a3bcbb4c64 stroke: Don't load configs with invalid proposals
References #2347.
2017-07-05 10:08:36 +02:00
Tobias Brunner 1aba82bfd7 eap-aka-3gpp: Add plugin that implements 3GPP MILENAGE algorithm in software
This is similar to the eap-aka-3gpp2 plugin. K (optionally concatenated
with OPc) may be configured as binary EAP secret in ipsec.secrets or
swanctl.conf.

Based on a patch by Thomas Strangert.

Fixes #2326.
2017-07-05 10:03:38 +02:00
Tobias Brunner 8ed3168406 eap-sim-file: Remove redundant enumerator allocation 2017-05-26 16:42:59 +02:00
Tobias Brunner bb494cde03 sql: Remove redundant enumerator allocation
Interestingly, this doesn't show up in the regression tests because the
compiler removes the first assignment (and thus the allocation) due to
-O2 that's included in our default CFLAGS.
2017-05-26 16:39:33 +02:00
Tobias Brunner b2473e94a2 Fixed some typos, courtesy of codespell 2017-05-26 14:44:06 +02:00
Tobias Brunner 2e4d110d1e linked-list: Change return value of find_first() and signature of its callback
This avoids the unportable five pointer hack.
2017-05-26 13:56:44 +02:00
Tobias Brunner 8a2e4d4a8b linked-list: Change interface of callback for invoke_function()
This avoids the unportable five pointer hack.
2017-05-26 13:56:44 +02:00
Tobias Brunner 525cc46cab Change interface for enumerator_create_filter() callback
This avoids the unportable 5 pointer hack, but requires enumerating in
the callback.
2017-05-26 13:56:44 +02:00
Tobias Brunner 95a63bf281 Migrate all enumerators to venumerate() interface change 2017-05-26 13:56:44 +02:00
Tobias Brunner 0afe0eca67 vici: Make 96-bit truncation for SHA-256 configurable 2017-05-26 11:22:28 +02:00
Tobias Brunner 4270c8fcb0 stroke: Make 96-bit truncation for SHA-256 configurable 2017-05-26 11:22:28 +02:00
Tobias Brunner 7b476029e6 android-log: Link against liblog 2017-05-26 09:40:14 +02:00
Tobias Brunner 4989aba822 child-sa: Change API used to set/install policies
This way we only have to pass the traffic selectors once.
2017-05-23 18:41:31 +02:00
Tobias Brunner a9b698f5be tnc-ifmap: Null-terminate buffer to make sscanf()-calls safe 2017-05-23 18:29:13 +02:00
Tobias Brunner 70855696ad kernel-netlink: Use total retransmit timeout as acquire timeout
By using the total retransmit timeout, modifications of timeout settings
automatically reflect on the value of xfrm_acq_expires.  If set, the
value of xfrm_acq_expires configured by the user takes precedence over
the calculated value.
2017-05-23 18:05:58 +02:00
Thomas Egerer d140b3bd3f kernel-netlink: Try to add new inbound SA if update fails
When establishing a traffic-triggered CHILD_SA involves the setup of an
IKE_SA more than one exchange is required. As a result the temporary
acquire state may have expired -- even if the acquire expiration
(xfrm_acq_expires) time is set properly (165 by default).  The expire
message sent by the kernel is not processed in charon since no trap can
be found by the trap manager.
A possible solution could be to track allocated SPIs.  But since this is
a corner case and the tracking introduces quite a bit of overhead, it
seems much more sensible to add a new state if the update of a state
fails with NOT_FOUND.

Signed-off-by: Thomas Egerer <thomas.egerer@secunet.com>
2017-05-23 17:58:51 +02:00
Tobias Brunner bf08e39441 kernel-pfkey: Update SA addresses if supported by the kernel
Upcoming FreeBSD kernels will support updating the addresses of existing
SAs with new SADB_X_EXT_NEW_ADDRESS_SRC|DST extensions for the SADB_UPDATE
message.
2017-05-23 17:58:50 +02:00
Tobias Brunner a080cfece0 kernel-pfkey: Use new encap flag on Mac OS X when updating SAs 2017-05-23 17:58:50 +02:00
Tobias Brunner 48ea655016 kernel-netlink: Update hardware offload attribute when SAs are updated 2017-05-23 16:58:06 +02:00
Tobias Brunner 0b5dfaeb5c kernel-netlink: Base SA update on correct message in multi-message response 2017-05-23 16:58:06 +02:00
Tobias Brunner 7c4f88d4be vici: Make hardware offload configurable 2017-05-23 16:58:00 +02:00
Tobias Brunner 749ac175fa child-cfg: Use flags for boolean options
Makes it potentially easier to add new flags.
2017-05-23 16:51:15 +02:00
Tobias Brunner d42948fc05 kernel-netlink: Enable hardware offloading if configured for an SA 2017-05-23 16:51:03 +02:00
Tobias Brunner 7caec9e4a4 kernel-netlink: Directly handle Netlink messages if thread pool is empty
During initialization of the plugins the thread pool is not yet
initialized so there is no watcher thread that could handle the queued
Netlink message and the main thread will wait indefinitely for a
response.

Fixes #2199.
2017-05-23 16:49:39 +02:00
Martin Willi 9b29003cd9 socket-default: Add an option to force the sending interface via IP_PKTINFO
On Linux, setting the source address is insufficient to force a packet to be
sent over a certain path. The kernel uses the best route to select the outgoing
interface, even if we set a source address of a lower priority interface. This
is not only true for interfaces attaching to the same subnet, but also for
unrelated interfaces; the kernel (at least on 4.7) sends out the packet on
whatever interface it sees fit, even if that network does not expect packets
from the source address we force to.

When a better interface becomes available, strongSwan sends its MOBIKE address
list update using the old source address. But the kernel sends that packet over
the new best interface. If that network drops packets having the unexpected
source address from the old path, the MOBIKE update fails and the SA finally
times out.

To enforce a specific interface for our packet, we explicitly set the interface
index from the interface where the source address is installed. According to
ip(7), this overrules the specified source address to the primary interface
address. As this could have side effects to installations using multiple
addresses on a single interface, we disable the option by default for now.

This also allows using IPv6 link-local addresses, which won't work if
the outbound interface is not set explicitly.
2017-05-23 16:49:39 +02:00
Tobias Brunner 46a3f92a76 Add an option to announce support for IKE fragmentation but not sending fragments 2017-05-23 16:41:57 +02:00
Tobias Brunner 605a98c7ce vici: Return key ID from load-key command
We already do this for load-token and this should simplify client
implementations.
2017-05-23 16:41:02 +02:00
Tobias Brunner a1aede8065 attr-sql: Make release of online leases during startup optional
This cleanup prevents sharing the same DB between multiple VPN gateways.
2017-05-19 15:22:51 +02:00
Andreas Steffen 2fad3460fa eap-simaka-sql: Fixed database column from use to used 2017-04-26 20:38:00 +02:00
odi79 0d66b01a81 vici: Fix type error exception in Python bindings
Line 66 yields "TypeError: can't concat bytes to str" using Python 3.4.
"requestdata" was introduced in 22f08609f1 but is not actually used.
Since the original "request" is not used anywhere else this can be changed
to be similar to the other UTF-8 encoding changes in that commit.

Fixes: 22f08609f1 ("vici: Explicitly set the Python encoding type").
Closes strongswan/strongswan#66.
2017-04-19 10:00:21 +02:00
Jiri Horky 6fe1d78a0d kernel-netlink: Avoid O(n^2) copy operations when concatenating Netlink responses
When constructing the result, all responses from Netlink were concatenated
iteratively, i.e. for each response, the previously acquired result was
copied to newly allocated memory and the current response appended to it.
This results in O(n^2) copy operations. Instead, we now check for the
total final length of the result and copy the individual responses to it
in one pass, i.e. in O(n) copy operations. In particular, this issue caused
very high CPU usage in memcpy() function as the result is copied over and
over. Common way how to hit the issue is when having 1000+ routes and 5+
connecting clients a second. In that case, the memcpy() function can
take 50%+ of one CPU thread on a decent CPU and the whole charon daemon
is stuck just reading routes and concatenating them together (connecting
clients are blocked in that particular case as this is done under mutex).

Closes strongswan/strongswan#65.
References #2055.
2017-03-27 11:05:26 +02:00
Martin Willi 3610d7607e addrblock: Narrow selectors when rekeying a CHILD_SA as original responder
If a the original responder narrows the selectors of its peer in addrblock,
the peer gets a subset of that selectors. However, once the original responder
initiates rekeying of that CHILD_SA, it sends the full selectors to the peer,
and then narrows the received selectors locally for the installation, only.

This is insufficient, as the peer ends up with wider selectors, sending traffic
that the original responder will reject to the stricter IPsec policy. So
additionally narrow the selectors when rekeying CHILD_SAs before sending the
TS list to the peer.
2017-03-24 08:17:01 +01:00
Tobias Brunner 9d240b0761 kernel-wfp: Don't redefine IPPROTO_IP* if already defined 2017-03-23 18:29:18 +01:00
Tobias Brunner 550bd654a7 vici: Don't fall back to uninstalling traps if a matching shunt was found
This is different if `ike` and `child` are provided and uninstall()
fails as we call that without knowing whether a matching shunt exists.
But if `ike` is not provided we explicitly search for a matching shunt
and if found don't need to look for a trap policy.
2017-03-23 18:29:18 +01:00
Tobias Brunner 1003cf2330 Fixed some typos, courtesy of codespell 2017-03-23 18:29:18 +01:00
Martin Willi 46d4d2a71e vici: Document how we pronounce the vici protocol and plugin 2017-03-20 10:39:10 +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 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
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 21df4cc1ed kernel-pfroute: Implement enumeration of local subnets 2017-02-08 10:38:28 +01:00
Tobias Brunner 0aabfe0780 bypass-lan: Allow ignoring or only considering subnets of specific interfaces
The config can also be reloaded by sending a SIGHUP to charon.
2017-02-08 10:38:28 +01:00
Tobias Brunner 62b58a40da bypass-lan: Configure interface on bypass policy
Currently, only the kernel-netlink plugin supports this, the others will
just ignore it.
2017-02-08 10:38:28 +01:00
Tobias Brunner 2406474158 kernel-netlink: Return interface name in local subnet enumerator 2017-02-08 10:38:28 +01:00
Tobias Brunner 46c21e3cc3 kernel-interface: Add interface name to local subnet enumerator 2017-02-08 10:38:28 +01:00
Tobias Brunner f8a362bfbc bypass-lan: Add plugin that installs bypass policies for locally attached subnets 2017-02-08 10:38:28 +01:00
Tobias Brunner eac584a37d kernel-netlink: Implement enumerator for local subnets 2017-02-08 10:38:28 +01:00
Tobias Brunner 3c46ce2834 kernel-pfkey: Use the same priority range for trap and regular policies
Same as the change in the kernel-netlink plugin.
2017-02-08 10:36:38 +01:00
Tobias Brunner 0e9d6c4605 kernel-netlink: Use the same priority range for trap and regular policies
While trap and regular policies now often look the same (mainly because
reqids are kept constant) trap policies still need to have a lower priority
than regular policies to handle unroute/route correctly if e.g. IPComp
is used or the mode changes.  But if we use a completely different
priority range that's lower than that of regular policies it is not possible
to install overlapping trap policies.  By differentiating trap from
regular policies via the priority's LSB this issue is avoided while
still maintaining the proper ordering of trap and regular policies.

Fixes #1243.
2017-02-08 10:36:38 +01:00
Tobias Brunner 6606393b8c kernel-netlink: Fix spacing in log message when policy is unchanged 2017-02-08 10:36:37 +01:00
James Laird-Wah 094a4d15cf forecast: Mark correct port in UDP NAT-T rule
Closes strongswan/strongswan#62.
2017-02-08 09:54:02 +01:00
Tobias Brunner 865fd804ee eap-dynamic: Publish the get_auth() method of the wrapped EAP method
Fixes #2238.
2017-02-07 10:52:24 +01:00
Tobias Brunner b062d3cc44 kernel-netlink: Set NODAD flag for virtual IPv6 addresses
The Optimistic Duplicate Address Detection (DAD) seems to fail in some
cases (`dadfailed` in `ip addr`) rendering the virtual IP address unusable.

Fixes #2183.
2017-02-06 11:10:44 +01:00
Tobias Brunner 7a40162cb7 kernel-netlink: Prefer matching label when selecting IPv6 source addresses
This implements rule 6 of RFC 6724 using the default priority table,
so that e.g. global addresses are preferred over ULAs (which also have
global scope) when the destination is a global address.

Fixes #2138.
2017-02-06 11:06:22 +01:00
Tobias Brunner 965daa1df3 kernel-netlink: Use correct 4 byte alignment for AH with IPv4
By default, the kernel incorrectly uses an 8 byte alignment, which is
mandatory for IPv6 but prohibited for IPv4.  For many algorithms this
doesn't matter but that's not the case for HMAC_SHA2_256_128.
Since 2.6.39 the kernel can be explicitly configured to use a 4 byte
alignment.
2017-01-25 17:51:35 +01:00
Thomas Egerer 8a91729dfe kernel-netlink: Allow change of Netlink socket receive buffer size
Signed-off-by: Thomas Egerer <thomas.egerer@secunet.com>
2017-01-25 17:42:38 +01:00
Tobias Brunner 4ae2209e3d kernel-pfkey: Set state to SADB_SASTATE_MATURE when adding/updating SAs
Picky kernels might otherwise reject our messages as RFC 2367 explicitly
mandates this.

Fixes #2212.
2017-01-25 17:30:57 +01:00
Tobias Brunner da565d9832 kernel-pfroute: Don't set a gateway if it is of a different address family than the destination 2017-01-25 17:29:44 +01:00
Tobias Brunner 69b58e347e stroke: Default to %dynamic if no valid TS are specified in left|rightsubnet
Otherwise, we'd end up with an empty TS list, which is not valid.

Because end->tohost is set to !end->subnets in starter the removed branch was
never used.
2017-01-25 16:56:28 +01:00
Tobias Brunner 83bf6db303 vici: Reload loggers after reloading strongswan.conf via reload-setting command 2017-01-25 14:58:12 +01:00
Tobias Brunner 4e382f5ffc ha: Fix assignment of IP addresses if multiple pools are defined
Fixes #2146.
2017-01-25 12:28:34 +01:00
Tobias Brunner 0e3c8cc4a2 ha: Delete passive IKE_SA on other node after half-open timeout
Fixes #1192.
2017-01-25 12:27:21 +01:00
Thomas Egerer 7085ca68d6 kernel-netlink: Return const pointer from lookup_algorithm()
Signed-off-by: Thomas Egerer <thomas.egerer@secunet.com>
2017-01-23 18:53:58 +01:00
Andreas Steffen bd2f2b11fc stroke: Load general PKCS#8 private keys 2016-12-17 18:06:11 +01:00
Weilu Jia 351179d4dc vici: Check for closed connection in Python bindings
The Python VICI library does not check if the socket is closed.
If the daemon closes the connection, _recvall() spins forever.

Closes strongswan/strongswan#56.
2016-12-14 11:35:31 +01:00
Tobias Brunner 564a199674 kernel-netlink: Add support for AES-CMAC-96 (RFC 4494)
The kernel apparently supports this since 3.10.
2016-12-12 11:43:06 +01:00
Volker Rümelin d17b780eaa farp: Fix BPF jump false offset
Jump to BPF_STMT(BPF_RET+BPF_K, 0) if protocol_size != 4
2016-10-31 14:46:14 +01:00
Tim Kent 87875086d0 connmark: Add CAP_NET_RAW to capabilities keep list
Fix for "Permission denied (you must be root)" error when calling
iptc_init(), which opens a RAW socket to communicate with the kernel,
when built with "--with-capabilities=libcap".

Closes strongswan/strongswan#53.
Fixes #2157.
2016-10-25 09:46:23 +02:00
Christophe Gouault a63a7af197 kernel-netlink: Fix get_route() interface determination
A wrong variable is used (route instead of best), so much that the
returned interface belongs to the last seen route instead of the best
choice route.

get_route() may therefore return mismatching interface and gateway.

Fixes: 66e9165bc6 ("kernel-netlink: Return outbound interface in get_nexthop()")

Signed-off-by: Christophe Gouault <christophe.gouault@6wind.com>
2016-10-12 19:25:31 +02:00
Andreas Steffen 85b5a6ace2 Save both base and delta CRLs to disk 2016-10-11 17:18:22 +02:00
Andreas Steffen 2a2669ee3e vici: strongswan.conf cache_crls = yes saves fetched CRLs to disk 2016-10-11 17:18:22 +02:00
Tobias Brunner bfc595a36a kernel-netlink: Consider RTA_SRC when looking for a source address 2016-10-05 11:44:53 +02:00
Tobias Brunner d5c6a0bac4 vici: Enable IKE fragmentation by default 2016-10-04 10:08:21 +02:00
Tobias Brunner 33d3ffde25 kernel-netlink: Pass zero mark to kernel if mask is set
The kernel will apply the mask to the mark on the packet and then
compare it to the configured mark.  So to match only unmarked packets we
have to be able to set 0/0xffffffff.
2016-09-30 15:35:32 +02:00
Tobias Brunner ac9759a532 kernel-netlink: Support configuring XFRM policy hashing thresholds
If the number of flows over a gateway exceeds the flow cache size of the Linux
kernel, policy lookup gets very expensive. Policies covering more than a single
address don't get hash-indexed by default, which results in wasting most of
the cycles in xfrm_policy_lookup_bytype() and its xfrm_policy_match() use.
Starting with several hundred policies the overhead gets inacceptable.

Starting with Linux 3.18, Linux can hash the first n-bit of a policy subnet
to perform indexed lookup. With correctly chosen netbits, this can completely
eliminate the performance impact of policy lookups, freeing the resources
for ESP crypto.

WARNING: Due to a bug in kernels 3.19 through 4.7, the kernel crashes with a
NULL pointer dereference if a socket policy is installed while hash thresholds
are changed.  And because the hashtable rebuild triggered by the threshold
change that causes this is scheduled it might also happen if the socket
policies are seemingly installed after setting the thresholds.
The fix for this bug - 6916fb3b10b3 ("xfrm: Ignore socket policies when
rebuilding hash tables") - is included since 4.8 (and might get backported).
As a workaround `charon.plugins.kernel-netlink.port_bypass` may be enabled
to replace the socket policies that allow IKE traffic with port specific
bypass policies.
2016-09-30 14:54:52 +02:00
Tobias Brunner 50721a61d8 vici: Make installation of outbound FWD policies configurable 2016-09-28 17:56:43 +02:00
Tobias Brunner 175d78df60 kernel-netlink: Update cached reqid when updating policies 2016-09-28 17:55:01 +02:00
Tobias Brunner 70ac90c552 eap-peap: Fix memory leaks when handling tunneled methods 2016-09-20 15:36:15 +02:00
Tobias Brunner 0b4ba9c53d ipseckey: Properly free enumerated certificates 2016-09-20 15:36:15 +02:00
Tobias Brunner c0c14af8c2 ipseckey: Properly free public key after creating certificate 2016-09-20 15:36:15 +02:00
Tobias Brunner 149b7de35c dnscert: Properly free enumerated certificates 2016-09-20 15:36:15 +02:00
Tobias Brunner d344474b3d vici: Fix indention of flush_certs() method in Python bindings 2016-09-20 15:33:18 +02:00
Tobias Brunner d8f27ba679 maemo: Remove unused plugin 2016-09-15 18:33:52 +02:00
Andreas Steffen 2c7cfe7630 vici: flush-certs command flushes certificate cache
When fresh CRLs are released with a high update frequency (e.g.
every 24 hours) or OCSP is used then the certificate cache gets
quickly filled with stale CRLs or OCSP responses. The new VICI
flush-certs command allows to flush e.g. cached CRLs or OCSP
responses only. Without the type argument all kind of certificates
(e.g. also received end entity and intermediate CA certificates)
are purged.
2016-09-13 17:02:59 +02:00
Andreas Steffen 04208ac5d4 xof: Defined Extended Output Functions 2016-07-29 12:36:14 +02:00
Andreas Steffen 7f65a8c271 vici: Increased various string buffers to BUF_LEN (512 bytes) 2016-07-29 12:34:40 +02:00
Tobias Brunner 4082821964 kernel-netlink: Don't set replay window for outbound SAs
It's not necessary and might waste memory.  However, if ESN is used we set
the window to 1 as the kernel rejects the attribute otherwise.
2016-06-17 18:46:33 +02:00
Tobias Brunner 21aa924233 kernel-pfkey: Only set the replay window for inbound SAs
It is not necessary for outbound SAs and might waste memory when large
window sizes are used.
2016-06-17 18:46:33 +02:00
Tobias Brunner 5947d48fb9 load-tester: Fix load-tester on platforms where plain `char` is signed
fgetc() returns an int and EOF is usually -1 so when this gets casted to
a char the result depends on whether `char` means `signed char` or
`unsigned char` (the C standard does not specify it).  If it is unsigned
then its value is 0xff so the comparison with EOF will fail as that is an
implicit signed int.
2016-06-17 10:22:25 +02:00
Tobias Brunner b1f7d10800 resolve: Add refcounting for installed DNS servers
This fixes DNS server installation if make-before-break reauthentication
is used as there the new SA and DNS server is installed before it then
is removed again when the old IKE_SA is torn down.
2016-06-10 18:40:01 +02:00
Tobias Brunner f1064ca59a resolve: Use process abstraction when calling resolvconf
This allows us to capture output written to stderr/stdout.
2016-06-10 18:39:53 +02:00
Tobias Brunner f4a20b74fd resolve: Make sure to clean up if calling resolvconf failed
If running resolvconf fails handle() fails release() is not called, which
might leave an interface file on the system (or depending on which script
called by resolvconf actually failed even the installed DNS server).
2016-06-10 18:39:21 +02:00
Tobias Brunner b52e540f43 kernel-pfroute: Return interface to reach destination from get_nexthop() 2016-06-10 17:52:26 +02:00
Tobias Brunner b98afc0a37 kernel-pfkey: Install routes with OUT policies 2016-06-10 15:25:46 +02:00
Tobias Brunner aea3c1052e kernel-netlink: Install routes with OUT policies
This is the direction we actually need routes in and makes the code
easier to read.
2016-06-10 15:25:09 +02:00
Tobias Brunner 85fed13c18 kernel-pfkey: Don't install routes for drop policies and if protocol/ports are in the selector 2016-06-10 15:25:05 +02:00
Tobias Brunner e7369a9dc5 kernel-netlink: Don't install routes for drop policies and if protocol/ports are in the selector
We don't need them for drop policies and they might even mess with other
routes we install.  Routes for policies with protocol/ports in the
selector will always be too broad and might conflict with other routes
we install.
2016-06-10 14:01:36 +02:00
Tobias Brunner 50798628c5 kernel-pfkey: Also use interface returned by get_nexthop() for IPsec policies
An exception is if the local address is virtual, in which case we want
the route to be via TUN device.
2016-06-10 13:57:27 +02:00
Tobias Brunner d1f8628420 kernel-netlink: Also use interface returned by get_nexthop() for IPsec policies 2016-06-10 13:57:27 +02:00
Tobias Brunner c158331bfc kernel-pfkey: Use interface to next hop for shunt policies 2016-06-10 13:57:27 +02:00
Tobias Brunner 4ba5ea407b kernel-netlink: Use interface to next hop for shunt policies
Using the source address to determine the interface is not correct for
net-to-net shunts between two interfaces on which the host has IP addresses
for each subnet.
2016-06-10 13:57:27 +02:00
Tobias Brunner 66e9165bc6 kernel-netlink: Return outbound interface in get_nexthop() 2016-06-10 13:54:18 +02:00
Tobias Brunner 99a57aa5ee kernel-net: Let get_nexthop() return an optional interface name
The returned name should be the interface over which the destination
address/net is reachable.
2016-06-10 13:54:18 +02:00
Tobias Brunner ebeaac1f2b kernel-netlink: Let only a single thread work on a specific policy
Other threads are free to add/update/delete other policies.

This tries to prevent race conditions caused by releasing the mutex while
sending messages to the kernel.  For instance, if break-before-make
reauthentication is used and one thread on the responder is delayed in
deleting the policies that another thread is concurrently adding for the
new SA.  This could have resulted in no policies being installed
eventually.

Fixes #1400.
2016-06-10 10:45:35 +02:00
Tobias Brunner 471b907613 kernel-netlink: Add priority and refcount to policy log 2016-06-10 10:34:09 +02:00
Tobias Brunner 25178f4594 kernel-netlink: Consistently print mark in log messages only if set 2016-06-10 10:34:09 +02:00
Tobias Brunner a0178fe26e kernel-netlink: Provide error information for Netlink sockets
#1467.
2016-06-10 10:34:09 +02:00
Tobias Brunner fc21465c66 kernel-netlink: Allow definition of a custom priority calculation function 2016-06-10 10:33:17 +02:00
Tobias Brunner 1ba2b015fa kernel-pfkey: Use ipsec_sa_cfg_equals() 2016-06-08 16:12:52 +02:00
Tobias Brunner 87ed9a5ffb kernel-netlink: Use ipsec_sa_cfg_equals() and compare marks properly 2016-06-08 16:12:52 +02:00
Tobias Brunner 5005325020 eap-simaka-pseudonym: Properly store mappings
If a pseudonym changed a new entry was added to the table storing
permanent identity objects (that are used as keys in the other table).
However, the old mapping was not removed while replacing the mapping in
the pseudonym table caused the old pseudonym to get destroyed.  This
eventually caused crashes when a new pseudonym had the same hash value as
such a defunct entry and keys had to be compared.

Fixes strongswan/strongswan#46.
2016-06-06 14:27:19 +02:00
Thomas Egerer aa6d4a3d54 error-notify: Notify listeners upon IKE retransmit
Signed-off-by: Thomas Egerer <thomas.egerer@secunet.com>
2016-06-06 14:11:02 +02:00
Tobias Brunner 2eb89ee1e3 stroke: Permanently store PINs in credential set
This fixes authentication with tokens that require the PIN for every
signature.

Fixes #1369.
2016-06-06 14:03:23 +02:00
Tobias Brunner 3427e43f4b p-cscf: Remove libhydra reference in Makefile 2016-05-27 18:24:59 +02:00
Tobias Brunner 09328c5210 vici: Put source distribution in the dist dir in the build directory
This fixes the out-of-tree build.
2016-05-11 14:33:08 +02:00
Tobias Brunner 81b9de0126 vici: Add target to build a source package and universal wheel of the Python package 2016-05-11 11:36:51 +02:00
Tobias Brunner fa844a798b vici: Add README.rst to be used as description on PyPI 2016-05-11 11:16:43 +02:00
Tobias Brunner 5d5ecd8e72 vici: Replace dr with dev in version numbers for the Python egg
The versioning scheme used by Python (PEP 440) supports the rcN suffix
but development releases have to be named devN, not drN, which are
not supported and considered legacy versions.
2016-05-10 12:16:13 +02:00
Tobias Brunner 1ff7ff5ac8 vici: Update setup.py 2016-05-10 11:42:29 +02:00
Tobias Brunner 756cd28fb8 vici: Ensure we read exactly the specified amount of bytes from the socket in Python
recv() will return less bytes than specified (as that's the buffer size)
if not as many are ready to be read from the socket.
2016-05-10 11:42:29 +02:00
Tobias Brunner fee991c259 kernel-netlink: Check proper watcher state in parallel mode
After adding the read callback the state is WATCHER_QUEUED and it is
switched to WATCHER_RUNNING only later by an asynchronous job. This means
that a thread that sent a Netlink message shortly after registration
might see the state as WATCHER_QUEUED.  If it then tries to read the
response and the watcher thread is quicker to actually read the message
from the socket, it could block on recv() while still holding the lock.
And the asynchronous job that actually read the message and tries to queue
it will block while trying to acquire the lock, so we'd end up in a deadlock.

This is probably mostly a problem in the unit tests.
2016-05-06 16:00:32 +02:00
Tobias Brunner 3f4cc30b19 kernel-netlink: Order routes by prefix before comparing priority/metric
Metrics are basically defined to order routes with equal prefix, so ordering
routes by metric first makes not much sense as that could prefer totally
unspecific routes over very specific ones.

For instance, the previous code did break installation of routes for
passthrough policies with two routes like these in the main routing table:

  default via 192.168.2.1 dev eth0 proto static
  192.168.2.0/24 dev eth0 proto kernel scope link src 192.168.2.10 metric 1

Because the default route has no metric set (0) it was used, instead of the
more specific other one, to determine src and next hop when installing a route
for a passthrough policy for 192.168.2.0/24.  Therefore, the installed route
in table 220 did then incorrectly redirect all local traffic to "next hop"
192.168.2.1.

The same issue occurred when determining the source address while
installing trap policies.

Fixes 6b57790270 ("kernel-netlink: Respect kernel routing priorities for IKE routes").
Fixes #1416.
2016-05-06 15:48:45 +02:00
Andreas Steffen b1df631212 vici list-conns sends reauthentication and rekeying time information 2016-05-04 18:13:52 +02:00
Tobias Brunner 254726b59e kernel-pfkey: Add support for manual priorities
Also orders policies with equals priorities by their automatic priority.
2016-04-15 10:39:01 +02:00
Tobias Brunner 4e59618382 kernel-pfkey: Update priority calculation formula to the new one in kernel-netlink
Since the selectors are not exactly the same (no port masks, no interface)
some small tweaks have been applied.
2016-04-15 10:39:00 +02:00
Tobias Brunner 869f4e90b1 kernel-netlink: Order policies with equal priorities by their automatic priority
This allows using manual priorities for traps, which have a lower
base priority than the resulting IPsec policies.  This could otherwise
be problematic if, for example, swanctl --install/uninstall is used while
an SA is established combined with e.g. IPComp, where the trap policy does
not look the same as the IPsec policy (which is now otherwise often the case
as the reqids stay the same).

It also orders policies by selector size if manual priorities are configured
and narrowing occurs.
2016-04-15 10:39:00 +02:00
Andreas Steffen d3af3b799f Extended IPsec kernel policy scheme
The kernel policy now considers src and dst port masks as well as
restictions to a given network interface. The base priority is
100'000 for passthrough shunts, 200'000 for IPsec policies,
300'000 for IPsec policy traps and 400'000 for fallback drop shunts.
The values 1..30'000 can be used for manually set priorities.
2016-04-09 16:51:02 +02:00
Andreas Steffen e9704e90cf Include manual policy priorities and restriction to interfaces in vici list-conn command 2016-04-09 16:51:02 +02:00
Andreas Steffen c26e4330e7 Implemented IPsec policies restricted to given network interface 2016-04-09 16:51:02 +02:00
Andreas Steffen 7f57c4f9fb Support manually-set IPsec policy priorities 2016-04-09 16:51:01 +02:00
Tobias Brunner 2ba5dadb12 peer-cfg: Use struct to pass data to constructor 2016-04-09 16:51:01 +02:00
Tobias Brunner 8a00a8452d child-cfg: Use struct to pass data to constructor 2016-04-09 16:51:01 +02:00
Tobias Brunner fd8f1194f3 kernel-pfkey: Prefer policies with reqid over those without 2016-04-09 16:51:01 +02:00
Tobias Brunner 0ff8ce9452 kernel-pfkey: Only install templates for regular IPsec policies with reqid 2016-04-09 16:51:01 +02:00
Tobias Brunner 83312ee5e4 kernel-netlink: Prefer policies with reqid over those without
This allows two CHILD_SAs with reversed subnets to install two FWD
policies each.  Since the outbound policy won't have a reqid set we will
end up with the two inbound FWD policies installed in the kernel, with
the correct templates to allow decrypted traffic.
2016-04-09 16:51:00 +02:00
Tobias Brunner f7e9e6a3fd kernel-netlink: Only associate templates with inbound FWD policies
We can't set a template on the outbound FWD policy (or we'd have to make
it optional).  Because if the traffic does not come from another (matching)
IPsec tunnel it would get dropped due to the template mismatch.
2016-04-09 16:51:00 +02:00
Tobias Brunner c4387e991a kernel-netlink: Associate routes with IN policies instead of FWD policies
This allows us to install more than one FWD policy.  We already do this
in the kernel-pfkey plugin (there the original reason was that not all
kernels support FWD policies).
2016-04-09 16:50:59 +02:00
Tobias Brunner 89da06ace9 kernel: Use structs to pass information to the kernel-ipsec interface 2016-04-09 16:50:59 +02:00
Cameron McCord be41d5cba2 vici: Fix documentation of some dictionary keys of two request messages
Closes strongswan/strongswan#40.
2016-03-31 11:26:44 +02:00
Andreas Steffen b12c53ce77 Use standard unsigned integer types 2016-03-24 18:52:48 +01:00
Shota Fukumori b210369314 updown: Get value for PLUTO_MARK_{IN,OUT} from CHILD_SA
Or the invoked script will get a broken value when `mark=%unique` is
used in a configuration.

Closes strongswan/strongswan#37.
2016-03-23 14:45:04 +01:00
Tobias Brunner b39be996cc connmark: Explicitly include xt_mark.h for older kernels
Fixes #1365.
2016-03-23 14:40:29 +01:00
Thomas Egerer 90a7a68488 ha: Delete cache entry inside the locked mutex
Signed-off-by: Thomas Egerer <thomas.egerer@secunet.com>
2016-03-23 10:34:24 +01:00
Tobias Brunner 0ed9430d10 kernel-netlink: Fix lookup of next hops for destinations with prefix
References #1347.
2016-03-21 12:14:59 +01:00
Tobias Brunner 20df9d315c vici: Don't hold write lock while running or undoing start actions
Running or undoing start actions might require enumerating IKE_SAs,
which in turn might have to enumerate peer configs concurrently, which
requires acquiring a read lock.  So if we keep holding the write lock while
enumerating the SAs we provoke a deadlock.

By preventing other threads from acquiring the write lock while handling
actions, and thus preventing the modification of the configs, we largely
maintain the current synchronous behavior.  This way we also don't need to
acquire additional refs for config objects as they won't get modified/removed.

Fixes #1185.
2016-03-11 08:32:18 +01:00
Andreas Steffen 35babdf43f Initialize ts variable 2016-03-11 08:29:23 +01:00
Tobias Brunner 7d22a75b12 forecast: Compare the complete rules when deleting them
Same as the change in the connmark plugin.

References #1229.
2016-03-10 17:26:38 +01:00
Tobias Brunner c659d369a0 connmark: Don't restore CONNMARK for packets that already have a mark set
This allows e.g. modified versions of xl2tpd to set the mark in
situations where two clients are using the same source port behind the
same NAT, which CONNMARK can't restore properly as only one conntrack entry
will exist with the mark set to that of the client that sent the last packet.

Fixes #1230.
2016-03-10 17:26:26 +01:00
Tobias Brunner 7c9e7eb933 connmark: Compare the complete rules when deleting them
By settings a matchmask that covers the complete rule we ensure that the
correct rule is deleted (i.e. matches and targets with potentially different
marks are also compared).

Since data after the passed pointer is actually dereferenced when
comparing we definitely have to pass an array that is at least as long as
the ipt_entry.

Fixes #1229.
2016-03-10 17:26:09 +01:00
Andreas Steffen 3f1de98678 Support of IP address ranges in traffic selectors 2016-03-10 13:59:37 +01:00
Tobias Brunner 7e854f4d51 attr: Only enumerate attributes matching the IKE version of the current IKE_SA
Numerically configured attributes are currently sent for both versions.
2016-03-10 11:57:39 +01:00
Tobias Brunner 98a3ba8a5a attr: Add p-cscf keyword for P-CSCF server addresses 2016-03-10 11:57:38 +01:00
Tobias Brunner 276acafa2d p-cscf: Make sending requests configurable and disable it by default 2016-03-10 11:57:38 +01:00
Tobias Brunner e8262251e1 p-cscf: Only send requests if virtual IPs of the same family are requested 2016-03-10 11:57:38 +01:00
Tobias Brunner 3d91d013cc p-cscf: Add attribute handler for P-CSCF server addresses 2016-03-10 11:57:38 +01:00
Tobias Brunner 12ac5fac1a p-cscf: Add plugin stub 2016-03-10 11:57:38 +01:00
Tobias Brunner 101abed566 vici: Replace child configs atomically
This also leaves unmodified configs as they are.
2016-03-08 10:21:58 +01:00
Tobias Brunner 229cdf6bc8 vici: Order auth rounds by optional `round` parameter instead of by position in the request 2016-03-08 10:04:55 +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 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
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 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 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
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
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
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 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
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 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 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 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 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 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 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 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 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 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 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 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 9322e5b398 vici: Add option to disable policy installation for CHILD_SAs 2015-08-17 12:01:36 +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
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