0
0
mirror of https://github.com/OpenVPN/openvpn3.git synced 2024-09-20 12:12:15 +02:00
Commit Graph

72 Commits

Author SHA1 Message Date
Lev Stipakov
9437974b60 ovpn-dco: support for TCP transport
Make client code protocol-agnostic by encapsulating UDP/TCP
differences into ProtoBase/ProtoImpl/TCP/UDP classes.

Slightly change GeNL API to accomodate abovementioned changes.

Signed-off-by: Lev Stipakov <lev@openvpn.net>
2020-11-18 18:02:00 +02:00
Antonio Quartulli
6eb1680099
ovpn-dco: add support for configuring ChaCha20Poly1305 as data channel cipher
Extend the ovpn-dco module to allow the user to specify ChaCha20Poly1305
as data channel cipher.
Same as AES-GCM, it also belongs to the AEAD family and its nonce length
is 12 bytes.

Signed-off-by: Antonio Quartulli <antonio@openvpn.net>
2020-11-17 15:49:36 +01:00
Lev Stipakov
8ce41b76f8
ovpn-dco: remove cbc-hmac crypto
Since modern OpenVPN deployments negotiate AES-GCM,
there is no need to support AES-CBC / HMAC.

ovpn-dco doesn't support it, so clean up core as well.

Signed-off-by: Lev Stipakov <lev@openvpn.net>
2020-11-16 01:24:02 +01:00
Lev Stipakov
9574172560
ovpn-dco: change nonce_tail length to 8 bytes
AES-GCM nonce is 12 bytes. OpenVPN obtains it by concatenating 4 bytes
packet id and rest (nonce_tail) from key material generated during TLS
handshake.

By some reasons ovpn-dco required userspace to provide 12 bytes
nonce_tail and generated 16 bytes nonce, even though kernel crypto API
uses only 12 bytes. This has been fixed in ovpn-dco and therefore has to
be fixed in userspace.

Signed-off-by: Lev Stipakov <lev@openvpn.net>
2020-11-16 01:23:52 +01:00
Lev Stipakov
23d2203ff2 ovpn-dco: send START_VPN command first
ovpn-dco requires START_VPN command come first,
so subscribe for control channel packets after that.

Signed-off-by: Lev Stipakov <lev@openvpn.net>
2020-10-27 20:07:06 +02:00
Lev Stipakov
587b686159 ovpn-dco: proper support for cipher and auth 'none'
Commit cd68ae2740 ("ovpn-dco: support cipher 'none' and auth 'none'")
added initial support. This adds missing parts:

 - do not throw exception in kocryto.hpp when using ovpn-dco
and cipher/auth are 'none'

 - set hmac alg to OVPN_HMAC_ALG_NONE if crypto alg is 'none'

 - pass hmac alg to ovpn-dco also when crypto alg is 'none'

Signed-off-by: Lev Stipakov <lev@openvpn.net>
2020-10-14 11:45:55 +03:00
Lev Stipakov
f24f1fd089 ovpn-dco: handle keepalive
Since userspace doesn't know anything about data
channel traffic, keepalive should be handled in kernel.

Disable keepalive in userspace and implement
OVPN_CMD_SET_PEER ovpn-dco command, which sets
keepalive settings in kernel.

Signed-off-by: Lev Stipakov <lev@openvpn.net>
2020-08-26 14:59:24 +00:00
Lev Stipakov
60e43763a4 ovpn-dco: init data channel keys
Implement OvpnDcoRekey, which parses key info
into format consumed by ovpn-dco.

Use KoRekey abstractions to hook into protocol layer
and get notified about rekeying events.

Pass new key to kernel or swap keys when commanded by
protocol layer.

Implement ovpn-dco netlink commands:

 - OVPN_CMD_NEW_KEY
 - OVPN_CMD_DEL_KEY
 - OVPN_CMD_SWAP_KEYS

Signed-off-by: Lev Stipakov <lev@openvpn.net>
2020-08-26 14:59:24 +00:00
Lev Stipakov
8593c41540 ovpn-dco: basic communication with kernel module
Add dependency to libnl-genl, which is C library
for generic netlink communication.

Implement C++ wrapper for libnl-genl, inspired by
ovpn-cli - a test client for ovpn-dco kernel module.

Implement ovpn-dco netlink commands:

  - OVPN_CMD_START_VPN - pass transport socket,
protocol (UDP) and mode (client).

  - OVPN_CMD_NEW_PEER - pass local and remote
endpoint info.

  - OVPN_CMD_PACKET - move (control channel) packets
between userspace and kernel.

  - OVPN_CMD_DEL_PEER - sent by kernel when peer is deleted
due to keepalive timeout (causes reconnect) or any other
reason (considered as fatal).

This change allows to perform openvpn handshake and
establish connection which doesn't work, since data channel
keys are not passed to kernel yet.

Signed-off-by: Lev Stipakov <lev@openvpn.net>
2020-08-26 14:59:24 +00:00
Lev Stipakov
67988b8883 linux/client/tunsetup.hpp: initial ovpn-dco support
ovpn-dco doesn't have concept of "opening" nor
file descriptor, since communication is handled
via netlink (to be added later).

Signed-off-by: Lev Stipakov <lev@openvpn.net>
2020-08-26 10:53:27 +00:00
Antonio Quartulli
648234cc68 sitnl: implement net_iface_new and net_iface_del
These two new methods can be used to create and delete a tun or an
ovpn-dco interface via RTNL API.

Signed-off-by: Antonio Quartulli <antonio@openvpn.net>
Signed-off-by: Lev Stipakov <lev@openvpn.net>
2020-08-26 10:53:27 +00:00
David Sommerseth
3fbe0a2701
Update copyrights
Signed-off-by: David Sommerseth <davids@openvpn.net>
2020-03-18 19:37:32 +01:00
Arne Schwabe
743a525f16
Fix netlink add_bypass_route not working with IPv6
Signed-off-by: Arne Schwabe <arne@openvpn.net>
2020-02-07 21:12:57 +01:00
Arne Schwabe
3817b8072e Refactor selecting tun methods into a common header file
This fixes DCO client only including iproute and using methods of
TUN_LINUX

Signed-off-by: Arne Schwabe <arne@openvpn.net>
2019-11-27 17:11:50 +01:00
David Sommerseth
1d751ffb7d
Linux/TunMethods: Avoid adding IPv6 routes without an IPv6 config
In some situations, the local6 variable is nullptr but a default IPv6
route has been configured.  This causes a segfault later in the call
chain when add_del_route() is being called.

We already have avoid a similar situation with IPv4, so implement the
same kind of safe guard for IPv6:  If no local IPv6 address has been
configured, don't attempt to add IPv6 routes.

Signed-off-by: David Sommerseth <davids@openvpn.net>
2019-11-07 16:30:03 +01:00
David Sommerseth
0833eb1f76
linux/tunsetup: Fix missing asio/errinfo declaration
When building the clinetcfg test client in openvpn3-linux with DCO support,
the building fails with the following compiler error:

    In file included from ./openvpn3-core/openvpn/common/base64.hpp:31:0,
                     from ./openvpn3-core/openvpn/init/initprocess.hpp:31,
                     from ./openvpn3-core/client/ovpncli.cpp:90,
                     from ./openvpn3-core/test/ovpncli/cli.cpp:58,
                     from src/tests/netcfg/cli.cpp:29:
    ./openvpn3-core/openvpn/tun/linux/client/tunsetup.hpp: In member function ‘int openvpn::TunLinuxSetup::Setup<TUNMETHODS>::establish(const openvpn::TunBuilderCapture&, openvpn::TunBuilderSetup::Config*, openvpn::Stop*, std::ostream&)’:
    ./openvpn3-core/openvpn/tun/linux/client/tunsetup.hpp:145:94: error: there are no arguments to ‘errinfo’ that depend on a template parameter, so a declaration of ‘errinfo’ must be available [-fpermissive]
         OPENVPN_THROW(tun_open_error, "error opening tun device " << node <<": " << errinfo(errno));
                                                                                                  ^
    ./openvpn3-core/openvpn/common/exception.hpp:130:18: note: in definition of macro ‘OPENVPN_THROW’
         _ovpn_exc << stuff; \
                      ^

By including the asioerr.hpp header file in
openvpn/tun/linux/client/tunsetup.hpp, this failure is resolved.

Signed-off-by: David Sommerseth <davids@openvpn.net>
2019-06-03 21:08:21 +02:00
David Sommerseth
e1647eb407
Fix builds with GCC 4.8 compilers
When building on RHEL 7 using the stock compiler (gcc-4.8.5), compiler
errors like this one began to appear after commit 8a502f3b61:

    core/openvpn/tun/linux/client/tunsetup.hpp:61:11: error: conversion from ‘openvpn::ActionList*’ to non-scalar type ‘openvpn::ActionList::Ptr {aka openvpn::RCPtr<openvpn::ActionList>}’ requested
         class Setup : public TunBuilderSetup::Base
               ^
On GCC 8.2 (via devtoolset-8), this error did not occur at all.  This
looks like a compiler bug, as declaring an empty Setup() constructor
resolves this issue.  But we currently want to have GCC 4.8.5 compilers
functional, as it provides native RHEL-7 support without any use of
software collections.

Signed-off-by: David Sommerseth <davids@openvpn.net>
2019-05-14 18:51:55 +02:00
Lev Stipakov
faad8454be sitnl: pick the best gw by longest prefix and lowest metric
Since we now handle multiple replies from Netlink,
we need to pick if the gateway with longest route prefix
and lowest metric.

Signed-off-by: Lev Stipakov <lev@openvpn.net>
2019-05-10 10:48:53 +03:00
Lev Stipakov
8a502f3b61 [OVPN3-354] tun linux: support for round-robin DNS and redirect gw
When profile contains several remotes or single remote which
is resolved into multiple IP addresses AND all traffic is redirected
to the VPN, client will reconnect to the next remote if connection
is broken. Since all traffic is redirected to VPN, except traffic to
current remote, reconnect fails.

Currently this problem is solved by creating bypass routes
to all remotes before establishing connection, so that reconnect
won't go via broken VPN. This solution is sub-optimal, since
it leaks traffic to other remotes.

This patch implements a better approach. Before connecting to
remote, we create a bypass route just for this remote. On reconnect
we replace an old route with a new one for the new remote.
We piggyback on socket_protect() method of OpenVPNClient
which is called before opening connection to remote.

Connection to a new remote usually means a new IP address etc,
so to prevent traffic leakage we first create a new tun interface,
set up routes and then remove old routes and tear down old tun interface.

Signed-off-by: Lev Stipakov <lev@openvpn.net>
2019-05-09 16:40:24 +03:00
Lev Stipakov
c9315c7dc1 gwnetlink.hpp: specify destination when looking for gateway
When creating bypass route for server, it is better
to use gateway for server address instead of 0.0.0.0 or ::0.

Signed-off-by: Lev Stipakov <lev@openvpn.net>
2019-05-09 16:40:24 +03:00
Lev Stipakov
89f091daf0 sitnl: implement interface filtering when looking for gateway
This will be needed to exclude gateway on tun interface when
creating bypass route.

Note that this is required only for sitnl, since iproute-based routines
already ignore tun gateway.

Signed-off-by: Lev Stipakov <lev@openvpn.net>
2019-05-09 16:40:24 +03:00
Lev Stipakov
220de072a2 sitnl: support for multipart messages
Gateways are returned in multipart netlink
message, so we must properly handle those
instead of bailing out after reading first message.

Signed-off-by: Lev Stipakov <lev@openvpn.net>
2019-05-09 16:40:24 +03:00
Lev Stipakov
7150f72e09 tun: remove code duplications in Linux tun implementations
There are two ways how Linux tun can be manipulated -
by using iproute2 or netlink. Both implementations have
defined identical Setup class implementation.

This commit factors out Setup class from tun implementations
and templatizes it, which removes need in duplicated code.

Signed-off-by: Lev Stipakov <lev@openvpn.net>
2019-05-02 21:34:20 +03:00
Lev Stipakov
8112f0cd7c [OVPN3-378] cli: support for TunBuilder API
This enables to use TunBuidler API by test client
on Linux and Mac platforms.

Signed-off-by: Lev Stipakov <lev@openvpn.net>
2019-05-02 21:34:20 +03:00
Antonio Quartulli
5bbfb57c0b
[OVPN3-315] TunLinux::Client: allow user to select netlink at compile time
Signed-off-by: Antonio Quartulli <antonio@openvpn.net>
2018-11-30 08:51:14 +10:00
Antonio Quartulli
e8458a68e5
[OVPN3-315] GW: add netlink support
This new component iretrieves the current default IPv4 and IPv6 GW
through netlink.

Signed-off-by: Antonio Quartulli <antonio@openvpn.net>
2018-11-30 08:51:14 +10:00
Antonio Quartulli
4e77edb9e8
[OVPN3-315] TunLinux: add Netlink implementation for Tun setup methods
Implement component that uses netlink to setup the tunnel
interface.

This new component gets rid of the "ip" commands and replaces
them with direct netlink calls.

Signed-off-by: Antonio Quartulli <antonio@openvpn.net>
2018-11-30 08:51:14 +10:00
Arne Schwabe
fab64ba0f0
Fix clang warning about unused attributes and missing overrides 2018-11-07 20:56:31 +01:00
Lev Stipakov
0a3dd67dac
[OVPN3-190] tun linux: add to/from_json methods
Signed-off-by: Lev Stipakov <lev@openvpn.net>
2018-03-26 23:58:33 +08:00
Lev Stipakov
37ab79fa6e
tun linux: apply changes from 362acf0
Linux tun setup: use LinuxGW46 to obtain gateway info

Signed-off-by: Lev Stipakov <lev@openvpn.net>
2018-03-10 02:28:35 +08:00
Lev Stipakov
6a7aee2c9f
[OVPN3-190] tun: implement persistence
Preserve tun and routes across reconnects. Store tun descriptor in
TunPersist object, which is member of TunClientFactory. Handle
add/remove commands inside TunBuilderSetup::Base instance, which is
owned by TunPersist.

Tunnel is recreated if new tunnel options are different from previous
ones.

Signed-off-by: Lev Stipakov <lev@openvpn.net>
2018-03-10 02:28:35 +08:00
Lev Stipakov
1d2ebb07fc
[OVPN3-190] tun: move tun creation to separate class
Implement TunBuidlerSetup::Base, which takes care of tun creation.

Signed-off-by: Lev Stipakov <lev@openvpn.net>
2018-03-10 02:28:35 +08:00
Lev Stipakov
53e33d634f
[OVPN3-190] tun: move content of tun to tuncli
Signed-off-by: Lev Stipakov <lev@openvpn.net>
2018-03-10 02:28:35 +08:00
Lev Stipakov
85d3377c28
[OVPN3-190] tun: move tun setup methods to separate file
Signed-off-by: Lev Stipakov <lev@openvpn.net>
2018-03-10 02:28:35 +08:00
James Yonan
6e350e9f9f
Linux tun setup: use LinuxGW46 to obtain gateway info
Using LinuxGW46 instead of the obsolete get_default_gateway_v4()
allows us to correctly implement the bypass route for
redirect-gateway ipv6.

Signed-off-by: James Yonan <james@openvpn.net>
2018-03-10 02:28:32 +08:00
David Sommerseth
16b10559f2 [OVPN3-140] Update company names in copyrights
OpenVPN Technologies, Inc. change their name to OpenVPN Inc. during the
autumn of 2017.

Signed-off-by: David Sommerseth <davids@openvpn.net>
2017-12-22 17:59:39 +08:00
David Sommerseth
6caca2c313 [OVPN3-140] Relicense back to AGPLv3
This is essentially a revert of commit 04b2a3c9b7 and commit
ef42e59e05.

Signed-off-by: David Sommerseth <davids@openvpn.net>
2017-12-22 17:59:39 +08:00
James Yonan
691a641a43 Added i/o abstraction layer.
Created a lightweight abstraction layer so that another i/o
reactor can be dropped in place of asio.

The basic approach is to rename all references to asio::xxx
types to openvpn_io::xxx and then make openvpn_io a
preprocessor variable that points to the top-level namespace
of the i/o reactor implementation.

All of the source files that currently include <asio.hpp> now
include <openvpn/io/io.hpp> instead:

This gives us a lightweight abstraction layer that allows us
to define openvpn_io to be something other than asio.

Other changes:

* Inclusion of asio by scripts/build is now optional, and is
  enabled by passing ASIO=1 or ASIO_DIR=<dir>.

* Refactored openvpn/common/socktypes.hpp to no longer
  require asio.

* Refactored openvpn/log/logthread.hpp to no longer require
  asio.

* Added openvpn::get_hostname() method as alternative to
  calling asio directly.

* openvpn/openssl/util/init.hpp will now #error
  if USE_ASIO is undefined.

Signed-off-by: James Yonan <james@openvpn.net>
2017-03-30 15:48:14 -06:00
James Yonan
6e8f2a73f8 Moved openvpn::to_string() to separate source file.
Signed-off-by: James Yonan <james@openvpn.net>
2017-03-18 15:46:45 -06:00
James Yonan
b2cd82a5bf copyright: updated to 2017.
Signed-off-by: James Yonan <james@openvpn.net>
2017-03-18 13:11:09 -06:00
Samuli Seppänen
04b2a3c9b7 Switch from AGPLv3 to GPLv3
Signed-off-by: Samuli Seppänen <samuli@openvpn.net>
2017-03-16 14:43:55 +02:00
James Yonan
971abda88f copyright : updated to 2016 2016-09-03 23:29:23 -06:00
James Yonan
0128b8a98e linux tun : remove "no trunking support" error message. 2016-07-12 22:04:33 -07:00
James Yonan
48928cfd95 linux tun : better IPv6 support. 2016-06-26 22:50:20 -06:00
James Yonan
c847135870 ovpn3 client API : added VPN gateway (IPv4 and IPv6) to
ClientAPI::ConnectionInfo object returned by
ClientAPI::OpenVPNClient::connection_info()
2016-06-26 22:23:08 -06:00
James Yonan
9b99595bdc Linux tuncli : refactor layer var into tun_prop.layer to
follow Windows approach.
2016-04-09 01:35:19 -06:00
James Yonan
d9f2e992a0 linux tuncli : added enable_routes parameter to tun_config()
to allow caller to choose whether or not to process routes.
2016-03-19 01:56:06 -06:00
James Yonan
46d6bdecf3 ovpn3 client : throw an option error if "trunk-table"
directive is given.
2016-03-19 01:54:47 -06:00
James Yonan
57dccf4f9c In tun/linux/client/tuncli.hpp, update TunBuilderCapture::Route
usage to TunBuilderCapture::RouteAddress.
2015-11-20 19:05:09 -07:00
James Yonan
1d855b1ef1 Minimal update to Linux tuncli.hpp to accomodate new
ActionList changes and fix compiler breakage.
2015-10-28 22:37:59 -07:00