Commit Graph

3145 Commits

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Fixes CVE-2015-3991.
2015-06-01 09:42:11 +02:00
Martin Willi 62e0abe759 ikev2: Include fragment number into message ID passed to IV gen
When using a cipher with sequential IVs, we never must pass an identical IV
to the IV generator. To avoid it when using IKEv2 fragmentation, use the lower
bits of the 64-bit message ID as the fragment number.
2015-06-01 09:42:11 +02:00
Martin Willi 823a8a9b46 message: Show the fragmentation numbers in message stringification 2015-06-01 09:42:10 +02:00
Tobias Brunner 711cb586fa ha: Document tunnel parameter 2015-05-27 12:59:39 +02:00