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

134 Commits

Author SHA1 Message Date
Charlie Vigue
b6b8282d33 Addressed 2nd set of -Wconversion warnings
- Used static_cast instead of direct type conversions in places where
it's safe
- Used numeric_cast where failure is possible
- Changed types of arguments and locals when practical

Signed-off-by: Charlie Vigue <charlie.vigue@openvpn.com>
2023-08-21 13:51:50 +00:00
Antonio Quartulli
193468cd72
ovpn-dco: change control packets flow in order to adapt to dco-v2 logic
With ovpn-co-v2 logic, control packets do not flow through netlink
anymore but they are sent directly via the transport socket.

Signed-off-by: Antonio Quartulli <antonio@openvpn.net>
2023-06-06 13:54:42 +02:00
Antonio Quartulli
9b976d6e2b
ovpn-dco: extend stats in order to retrieve both VPN and transport numbers
Signed-off-by: Antonio Quartulli <antonio@openvpn.net>
2023-06-06 13:54:41 +02:00
Antonio Quartulli
37ae62143d
ovpn-dco: make netlink parsing code a bit more robust
Signed-off-by: Antonio Quartulli <antonio@openvpn.net>
2023-06-06 13:54:41 +02:00
Antonio Quartulli
446558a735
ovpn-dco: include latest UAPI header in codebase
In order to avoid a useless dependency on the ovpn-dco tree, directly
include the ovpn_dco_linuc.h UAPI header in the codebase.

This is the only external requirement to build core with DCO support.

Signed-off-by: Antonio Quartulli <antonio@openvpn.net>
2023-06-05 15:48:34 +02:00
Arne Schwabe
084e6a7e1d
Ensure members of openvpn::TunLinuxSetup::Config are initialised
Reported-By: Trail of Bits (TOB-OVPN3-13)
Signed-off-by: Arne Schwabe <arne@openvpn.net>
(cherry picked from commit da41e7cfdf)
2023-03-03 21:41:21 +01:00
David Sommerseth
dde1574596
Reformatting source code to new coding style
This is the result after running 'clang-format -i' on all C++ files and
headers, with the defined formatting rules in .clang-format.

Only the openvpn/common/unicode-impl.hpp has been excluded, as that is
mostly a copy of an external project.

Signed-off-by: David Sommerseth <davids@openvpn.net>
2023-01-18 19:24:15 +01:00
David Sommerseth
4996c38ed4
Merge lastest changes from Core v3.7.2 2022-12-14 17:34:29 +01:00
Lev Stipakov
6a9b174f21
tunpersist: support for "no retain, no replace"
This is required for dco-win driver support.

Signed-off-by: Lev Stipakov <lev@openvpn.net>
2022-10-13 15:16:24 +02:00
David Sommerseth
8c94a8f774
copyright: Update to 2022
Signed-off-by: David Sommerseth <davids@openvpn.net>
2022-09-29 12:00:26 +02:00
Frank Lichtenheld
2aea7ac4b5
Merge changes from coming OpenVPN 3 Core library v3.7 bugfix update
- test_cpu_time: fix unused variable
  - Allow GIT version to be reported as part of platform (version) string
  - Update OpenSSL to 3.0.5, build fat lib for macos, drop 32 bit on iOS
  - README.rst: some fixes for macOS instructions
  - extpki.hpp: ignore deprecated EC_KEY_* functions
  - mingw: fix OpenSSL on x86_64
  - mingw: fix broken OpenSSL checkout
  - test_ssl: fix ssl.enablelegacyProvider
  - dco/GeNL: ignore message for unrelated interfaces

Signed-off-by: David Sommerseth <davids@openvpn.net>
2022-08-25 15:32:11 +02:00
Arne Schwabe
3710fa106a Implement pushable tun-mtu and tls-mtu-max
OpenVPN 3.x has the same approach/problem for buffer allocation for the
tunnel packets that OpenVPN 2.x uses. Buffers are allocated very early
in the setup, so resizing/reacting to different frame sizes is not
really possible without major refactoring.

Therefore we use the same approach as with OpenVPN 2.x and allow a
MTU of up to 1600 by default and require setting tun-mtu-max in the
configuration file to allow larger values and allocate larger buffers.

Signed-off-by: Arne Schwabe <arne@openvpn.net>
2022-07-13 16:44:31 +02:00
Antonio Quartulli
46b13ec65e
dco/GeNL: ignore message for unrelated interfaces
Some netlink messages are sent as multicast by the kernel and will reach
all listening userspace processes. For this reason, the receiving
handler should discard non-interesting messages to avoid messing up the
local state.

Reported-by: David Sommerseth <davids@openvpn.net>
Signed-off-by: Antonio Quartulli <antonio@openvpn.net>
2022-05-20 10:24:37 +02:00
James Yonan
085836cea9 ovpn3 client: support a new client event containing the data from TunBuilderCapture::to_json()
The event is of type INFO_JSON and is formatted:

  TUN_BUILDER_CAPTURE:{...}

This info is useful to determine the properties of a
VPN client session such as VPN IPs, Gateway IPs,
and DNS resolvers, and can be directly used as
a VPN Connection Profile.

This patch also adds the

  cli --tbc <file>

option to write the TunBuilderCapture JSON to a file.

Signed-off-by: James Yonan <james@openvpn.net>
2022-05-13 19:09:09 -06:00
James Yonan
6f10dfdce9 SITNL: added net_iface_addr() to return the primary address/prefix_len on a given interface
Signed-off-by: James Yonan <james@openvpn.net>
2022-05-13 19:09:09 -06:00
James Yonan
68854ea916 SITNL: added new OPENVPN_LOG_RTNL() call to better understand netlink representation of route list
Signed-off-by: James Yonan <james@openvpn.net>
2022-05-13 19:09:09 -06:00
James Yonan
2d2758b7a8 SITNL: use cleaner and more performant IP::Route construction
When constructing an IP::Route from netlink raw data, avoid
round-trip conversion to string and back.

Signed-off-by: James Yonan <james@openvpn.net>
2022-05-13 19:09:09 -06:00
James Yonan
c6e47099b7 SITNL: allow including programs to define their own version of OPENVPN_LOG_RTNL()
Signed-off-by: James Yonan <james@openvpn.net>
2022-05-13 19:09:09 -06:00
Lev Stipakov
ac15879588 support for default mssfix
Add support for default mssfix, which is calculated
based on upper bound value 1492 minus payload and
encapculation overhead.

Payload overhead includes:

 - compression byte (except for V2, which doesn't add overhead)
 - pktid (in CBC)
 - IPv4 and TCP headers

Encapculation overhead:

 - crypto overhead (for AEAD 16 bytes auth tag, 4 bytes pktid, 4 bytes opcode/peer-id = 24)
 - 2 bytes packet size for TCP transport

Also for CBC we must take padding [1..blocksize] into account.

Signed-off-by: Lev Stipakov <lev@openvpn.net>
2022-05-04 18:15:07 +03:00
James Yonan
7cbac69e3d Linux tun_config(): added a flags parameter to subsume add_bypass_routes and create space for new flags
This change replaces the boolean add_bypass_routes with a new
flags parameter -- set the TunConfigFlags::ADD_BYPASS_ROUTES
flag to achieve the same functionality.

We also add some new flags for finer-grained control over
actions taken by tun_config:

* TunConfigFlags::DISABLE_IFACE_UP -- disable bringing the interface up

* TunConfigFlags::DISABLE_REROUTE_GW -- disable redirect-gateway

Signed-off-by: James Yonan <james@openvpn.net>
2021-11-24 13:18:35 -07:00
Antonio Quartulli
07b85394c8
genl.hpp: implement get_peer() API to retrieve peer data from DCO
The get_peer API allows userspace to retrieve the data about a specific
peer. Implement the userspace counterpart so that OpenVPN can retrieve
the peer data when it needs to updte the client statistics.

Signed-off-by: Antonio Quartulli <antonio@openvpn.net>
2021-06-09 17:23:03 +02:00
Antonio Quartulli
0f264b71e4
genl.hpp: avoid cast for return value of lambda expression
Explicitly specify the return type of lambda expressions
so that we can avoid casting the return value.

Signed-off-by: Antonio Quartulli <antonio@openvpn.net>
2021-06-08 01:42:37 +02:00
Heiko Hund
51bd6d4201 use DCO opportunistically
If DCO support is compiled in, detect if it is available (i.e. Windows driver
or Linux kernel module is loaded) and then use it, if it is.

This changes the default configuration for DCO from off to on, so users of
the library need to set ClientAPI::Config::dco to false in case they do not
want to use dco for a connection.

The change is also reflected in the reference client "ovpncli". If DCO is
enabled in a build, it will detect and use it. The previously available
"ovpncliovpndco" and "ovpncliovpndcowin" clients have thus been removed.

Signed-off-by: Heiko Hund <heiko@openvpn.net>
2021-05-27 17:20:24 +02:00
Antonio Quartulli
99f9049d1f
sitnl: move large memory block from stack to heap
It is not recommended to allocate big blocks on the stack, however
the sitnl sending routine is stacking a 16KB large buffer.

Allocate it using heap memory and avoid using the stack.

Addresses-Coverity: ("Large stack use")
Signed-off-by: Antonio Quartulli <antonio@openvpn.net>
2021-05-24 21:19:57 +02:00
Antonio Quartulli
8d49172321
sitnl: properly assign prefix len of resulting route
When cycling through matching routes, the most specific (i.e. having the
longest prefix) should be selected. To achieve that, we must store the
prefix len of any selected route, so that it can be compared with the
next (if more than one is found).

As result, we return the prefix len of the matching route in the
route_res_t object.

Addresses-Coverity: ("Self assignment")
Signed-off-by: Antonio Quartulli <antonio@openvpn.net>
2021-05-24 18:34:48 +02:00
Heiko Hund
5a85715946 fix potential nullptr deref with redirect-gateway
Signed-off-by: Heiko Hund <heiko@openvpn.net>
2021-05-18 06:13:31 +02:00
Heiko Hund
f228921d71 init several netlink related class members
Signed-off-by: Heiko Hund <heiko@openvpn.net>
2021-05-18 06:13:31 +02:00
Antonio Quartulli
49e1e1748f
dco: restyle source files with clang-format --style=LLVM
We are trying to adhere to the LLVM style as dictated by clang-format.
For this reason reformat all files in the dco/ subfolder with:

clang-fromat --style=LLVM -i $filename

Signed-off-by: Antonio Quartulli <antonio@openvpn.net>
2021-02-23 01:37:43 +01:00
Antonio Quartulli
a25c4d5144
genl: update netlink API implementation to new ovpn-dco format
The ovpn-dco netlink API has been heavily rewritten to accommodate
multi-peer support.

For this reason the genl component in ovpn3-core had to be adapted to
follow the new format and logic.

Signed-off-by: Antonio Quartulli <antonio@openvpn.net>
2021-02-23 01:37:18 +01:00
Antonio Quartulli
8a9067b386
sitnl: fix typ0 in log message
Signed-off-by: Antonio Quartulli <antonio@openvpn.net>
2021-02-23 01:06:31 +01:00
Lev Stipakov
d452518656 ovpn-dco: ipv6 support
Make GeNL code work with both IPv4 and IPv6 peers.

Signed-off-by: Lev Stipakov <lev@openvpn.net>
2020-11-18 18:02:00 +02:00
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