]> git.ipfire.org Git - thirdparty/openvpn.git/log
thirdparty/openvpn.git
5 years agowintun: set adapter properties via interactive service
Lev Stipakov [Wed, 18 Dec 2019 06:18:18 +0000 (07:18 +0100)] 
wintun: set adapter properties via interactive service

Since Wintun doesn't do DHCP, use interactive service
calls to set up adapter properties.

This also fixes bug in previously unused IPv4 code of
do_address_service():

 - ipv4 address must be in network byte order
 - prefix length cannot be hardcoded /32 but
 must be calculated from netmask

Signed-off-by: Lev Stipakov <lev@openvpn.net>
Acked-by: Simon Rozman <simon@rozman.si>
Message-Id: <20191218061818.1504-1-simon@rozman.si>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg19253.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
5 years agowintun: interactive service support
Lev Stipakov [Tue, 17 Dec 2019 12:50:41 +0000 (14:50 +0200)] 
wintun: interactive service support

Wintun requires ring buffers registration to be
performed by privileged process. In order to use
openvpn with wintun by non-Administrator, we
need to use interactive service and shared memory
to register buffers.

Openvpn process creates memory mapping object and event
for send and receive ring and passes handles to interactive
service. There handles are duplicated and memory mapped
object is mapped into the address space of service process.
Then address of mapped view and event handle is passed to
wintun kernel driver.

After interactive service preformed registration,
openvpn process maps memory mapped object into
own address space. Thus mapped views in openvpn
and service process represent the same memory region.

Signed-off-by: Lev Stipakov <lev@openvpn.net>
Acked-by: Simon Rozman <simon@rozman.si>
Message-Id: <20191217125041.207-1-lstipakov@gmail.com>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg19244.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
5 years agowintun: ring buffers based I/O
Lev Stipakov [Tue, 17 Dec 2019 12:44:10 +0000 (14:44 +0200)] 
wintun: ring buffers based I/O

Implemented according to Wintun documentation
and reference client code.

Wintun uses ring buffers to communicate between
kernel driver and user process. Client allocates
send and receive ring buffers, creates events
and passes it to kernel driver under LocalSystem
privileges.

When data is available for read, wintun modifies
"tail" pointer of send ring and signals via event.
User process reads data from "head" to "tail" and
updates "head" pointer.

When user process is ready to write, it writes
to receive ring, updates "tail" pointer and signals
to kernel via event.

In openvpn code we add send ring's event to event loop.
Before performing io wait, we compare "head" and "tail"
pointers of send ring and if they're different, we skip
io wait and perform read.

This also adds ring buffers support to tcp and udp
server code.

Signed-off-by: Lev Stipakov <lev@openvpn.net>
Acked-by: Steffan Karger <steffan.karger@fox-it.com>
Acked-by: Simon Rozman <simon@rozman.si>
Message-Id: <20191217124410.81-1-lstipakov@gmail.com>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg19243.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
5 years agoDocument tls-ciphersuites also in --help output
Arne Schwabe [Wed, 4 Dec 2019 11:09:38 +0000 (12:09 +0100)] 
Document tls-ciphersuites also in --help output

Signed-off-by: Arne Schwabe <arne@rfc2549.org>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <20191204110938.6725-1-arne@rfc2549.org>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg19221.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
5 years agoAdd support for OpenSSL TLS 1.3 when using management-external-key
Arne Schwabe [Wed, 4 Dec 2019 11:08:36 +0000 (12:08 +0100)] 
Add support for OpenSSL TLS 1.3 when using management-external-key

For TLS versions 1.0 to 1.2 and OpenSSL 1.1.0 and requires a PKCS1
padded response for the external key implementation.
As TLS 1.3 mandates RSA-PSS padding support and also requires an
TLS 1.3 implementation to support RSA-PSS for older TLS
version, OpenSSL will query us to sign an already RSA-PSS padded
string.

This patch adds an 'unpadded' and 'pkcs1' parameter to the
management-external-key option to signal that the client is
able to support pkcs1 as well as unpadded signature requests.

Since clients that implement the management-external-key interface
are usually rather tightly integrated solutions (OpenVPN Connect in the
past, OpenVPN for Android), it is reasonable to expect that
upgrading the OpenSSL library can be done together with
management interface changes. Therefore we provide no backwards
compatbility for mangement-interface clients not supporting
OpenSSL 1.1.1. Also doing this would require downgrading TLS
to 1.1.

Using the management api client version instead the parameters to
management-external-key might seem like the more logical way
but since we only know that version very late in connection progress,
it would require extra logic and complexity to deal with this asynchronous
behaviour. Instead just give an error early if OpenSSL 1.1.1 and
management-external-key without nopadding is detected.

The interface is prepared for signalling PCKS1 and RSA-PSS support
instead of signalling unpadded support.

Patch v3: fix overlong lines and few other style patches. Note
      two overlong lines concerning mbedtls are not fixed as they
      are removed/shortend by the mbed tls patch to avoid conflicts

Patch v4: Setting minimum TLS version proved to be not enough and
      instead of implementing a whole compability layer we require
      mangement-clients to implement the new feature when they want
      to use OpenSSL 1.1.1

      Add a padding=ALGORITHM argument to pk-sig to indicate the
      algorithm. Drop adding PKCS1 ourselves.

Patch v5: Send the right version of the patch
Patch v6: rebase on master
Patch v7: change style and reword documentation. Make things more
consistent.
Patch v8: fix spellings, grammar.

Signed-off-by: Arne Schwabe <arne@rfc2549.org>
Acked-by: Selva Nair <selva.nair@gmail.com>
Message-Id: <20191204110836.6364-1-arne@rfc2549.org>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg19219.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
5 years agoMake tls_version_max return the actual maximum version
Arne Schwabe [Fri, 22 Nov 2019 14:33:14 +0000 (15:33 +0100)] 
Make tls_version_max return the actual maximum version

Before OpenSSL 1.1.1 there could be no mismatch between
compiled and actual OpenSSL version. With OpenSSL 1.1.1 we need
runtime detection to detect the actual best TLS version supported.

Allowing this runtime detection also allows removing some of the
TLS 1.3/OpenSSL 1.1.1 #ifdefs

Without this patch tls-min-version 1.3 or-highest will actually
downgrade to TLS 1.2 in the "compiled with 1.1.0 and linked against
1.1.1" scenario.

Signed-off-by: Arne Schwabe <arne@rfc2549.org>
Acked-by: Selva Nair <selva.nair@gmail.com>
Message-Id: <20191122143315.8564-1-arne@rfc2549.org>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg19186.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
5 years agotravis: bump clang version
Lev Stipakov [Fri, 29 Nov 2019 10:43:35 +0000 (12:43 +0200)] 
travis: bump clang version

This should fix "suggest braces around initialization of subobject"
warning.

Signed-off-by: Lev Stipakov <lev@openvpn.net>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <20191129104335.4518-1-lstipakov@gmail.com>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg19203.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
5 years agotravis: fix CFLAGS assignment error and add -Werror only when compiling on Linux...
Antonio Quartulli [Sun, 10 Nov 2019 20:17:18 +0000 (21:17 +0100)] 
travis: fix CFLAGS assignment error and add -Werror only when compiling on Linux for Linux

CFLAGS may not resolve to anything and the build-check.sh script would
just fail.

Switch to EXTRA_FLAGS and use proper substitution so that the script won't
error out when EXTRA_FLAGS is uninitialized.

At the same time ensure that such flag is set only when compiling *for*
linux (we use linux to also compile *for* windows)

Signed-off-by: Antonio Quartulli <a@unstable.cc>
Acked-by: Arne Schwabe <arne@rfc2549.org>
Message-Id: <20191110201718.31032-1-a@unstable.cc>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg19109.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
5 years agoFix ACL_CHECK_ADD_COMPILE_FLAGS to work with clang
Selva Nair [Tue, 19 Nov 2019 17:03:43 +0000 (12:03 -0500)] 
Fix ACL_CHECK_ADD_COMPILE_FLAGS to work with clang

Some compilers (e.g., clang) only issue a warning for
unsupported options unless an additional flag such
as -Werror is used to convert the warning to an error.

The behaviour is unchanged when using gcc as it either
errors or ignores unknown options whether or not -Werror
is present.

Signed-off-by: Selva Nair <selva.nair@gmail.com>
Acked-by: David Sommerseth <davids@openvpn.net>
Message-Id: <1574183023-6136-1-git-send-email-selva.nair@gmail.com>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg19170.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
5 years agotravis: compile with -Werror on Linux
Antonio Quartulli [Sun, 10 Nov 2019 13:35:25 +0000 (14:35 +0100)] 
travis: compile with -Werror on Linux

Signed-off-by: Antonio Quartulli <a@unstable.cc>
Acked-by: Arne Schwabe <arne@rfc2549.org>
Message-Id: <20191110133525.6069-3-a@unstable.cc>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg19094.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
5 years agoauth.c: make cast explicit in the crypto API
Antonio Quartulli [Sun, 10 Nov 2019 13:35:24 +0000 (14:35 +0100)] 
auth.c: make cast explicit in the crypto API

mbedtls_md_get_size() returns unsigned char, while EVP_MD_size() returns
int. Results coming from both functions are normally in a uint8_t member
of the key_type struct, because it is known that 8bits are enough (also
for EVP_MD_size()).

This unexpected cast can, however, trigger unsolicited warnings.
Make the cast explicit by changing the return value of our crypto API.

Reported-by: Arne Schwabe <arne@rfc2549.org>
Signed-off-by: Antonio Quartulli <a@unstable.cc>
Acked-by: Arne Schwabe <arne@rfc2549.org>
Message-Id: <20191110133525.6069-2-a@unstable.cc>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg19093.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
5 years agoauth_token_kt: ensure key_type object is initialized
Antonio Quartulli [Sun, 10 Nov 2019 13:35:23 +0000 (14:35 +0100)] 
auth_token_kt: ensure key_type object is initialized

Fixes the following warning:

auth_token.c: In function 'auth_token_init_secret':
auth_token.c:47: warning: 'kt.cipher_length' is used uninitialized in this
function
auth_token.c:34: note: 'kt.cipher_length' was declared here

Signed-off-by: Arne Schwabe <arne@rfc2549.org>
Signed-off-by: Antonio Quartulli <a@unstable.cc>
Acked-by: Arne Schwabe <arne@rfc2549.org>
Message-Id: <20191110133525.6069-1-a@unstable.cc>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg19092.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
5 years agoget rid of 'broadcast' argument when configuring the tun device
Antonio Quartulli [Sun, 10 Nov 2019 12:44:07 +0000 (13:44 +0100)] 
get rid of 'broadcast' argument when configuring the tun device

The broadcast argument is actually useless as every platform will figure
it out and configure it on its own. We even realized that on linux, if
you configure it wrong, nothing wrong will happen.

At this point, let's make the code cleaner and let's get rid of this
useless argument at all.

This patch just removed any occurrence of 'broadcast'.

Signed-off-by: Antonio Quartulli <a@unstable.cc>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <20191110124407.8734-1-a@unstable.cc>
URL: https://www.mail-archive.com/search?l=mid&q=20191110124407.8734-1-a@unstable.cc
Signed-off-by: Gert Doering <gert@greenie.muc.de>
5 years agoUpdate sample configs to use modern cipher, remove static key examples
Steffan Karger [Sat, 9 Nov 2019 17:42:35 +0000 (18:42 +0100)] 
Update sample configs to use modern cipher, remove static key examples

Since these are examples, people might use them as a basis for their own
configs. In the non-push/pull configs, we should specify a decent cipher.

Further, I don't think we should recommend anyone to still use a static key
configuration, so remove the static key config examples.

Signed-off-by: Steffan Karger <steffan@karger.me>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <20191109174235.20511-1-steffan@karger.me>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg19081.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
5 years agoadd -Wno-stringop-truncation to CFLAGS on linux
Antonio Quartulli [Sun, 10 Nov 2019 10:03:23 +0000 (11:03 +0100)] 
add -Wno-stringop-truncation to CFLAGS on linux

GCC>=8 supports truncation checking, however the logic is somewhat
fragile when it comes to evaluating strncpy().

In buffer.h we have implemented a wrapper called strncpynt() which
ensures we always do the right hting in the code and reduce the chance
of having bugs.

This said, it seems that the gcc logic is not able to always understand
if we are doing the right thing and throws a false positive.

Toa void the noise, disable truncation checking on Linux by default.

Signed-off-by: Antonio Quartulli <a@unstable.cc>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <20191110100323.13206-1-a@unstable.cc>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg19085.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
5 years agotravis: bump MSVC to 2019
Lev Stipakov [Sat, 9 Nov 2019 16:40:11 +0000 (18:40 +0200)] 
travis: bump MSVC to 2019

Since we changed MSVC version in project files to 2019,
we have to do the same in travis script.

Signed-off-by: Lev Stipakov <lev@openvpn.net>
Acked-by: Simon Rozman <simon@rozman.si>
Message-Id: <1573317611-6462-1-git-send-email-lstipakov@gmail.com>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg19074.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
5 years agosocks: use the right function when printing struct openvpn_sockaddr
Antonio Quartulli [Sat, 9 Nov 2019 16:37:14 +0000 (17:37 +0100)] 
socks: use the right function when printing struct openvpn_sockaddr

57623b4e introduced a print_sockaddr() call in socks.c to print an
openvpn_sockaddr object.

However, this is not correct because print_sockaddr() expects a sockaddr
object as argument instead of openvpn_sockaddr.

This error did not lead to any issue because the two objects are very
similar in regards to the data accessed by print_sockaddr().

Fix this by replacing print_sockaddr() with print_openvpn_sockaddr().

Signed-off-by: Antonio Quartulli <a@unstable.cc>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <20191109163714.25506-1-a@unstable.cc>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg19073.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
5 years agowintun: implement opening wintun device
Lev Stipakov [Thu, 7 Nov 2019 17:45:25 +0000 (19:45 +0200)] 
wintun: implement opening wintun device

To open wintun device, we cannot use "\\.\Global\Wintun<luid>"
path as before. To get device path which we supply to CreateFile,
we have to use SetupAPI to:

 - enumerate network adapters with "wintun" as component id
 - for each adapter save its guid
 - open device information set
 - for each item in set
   - open corresponding registry key to get net_cfg_instance_id
   - get symbolic link name of device interface by instance id
 - path will be symbolic link name of device instance matched with
adapter's guid

See
https://github.com/OpenVPN/openvpn3/blob/master/openvpn/tun/win/tunutil.hpp
 and
https://github.com/WireGuard/wireguard-go/blob/master/tun/wintun/wintun_win
dows.go for
implementation examples.

Signed-off-by: Lev Stipakov <lev@openvpn.net>
Acked-by: Simon Rozman <simon@rozman.si>
Message-Id: <1573148729-27339-4-git-send-email-lstipakov@gmail.com>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg19029.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
5 years agowintun: add --windows-driver config option
Lev Stipakov [Fri, 8 Nov 2019 17:37:35 +0000 (19:37 +0200)] 
wintun: add --windows-driver config option

This allows to specify which tun driver openvpn should use,
tap-windows6 (default) or wintun.

Note than wintun support will be added in follow-up patches.

Signed-off-by: Lev Stipakov <lev@openvpn.net>
Acked-by: Simon Rozman <simon@rozman.si>
Message-Id: <1573234655-905-1-git-send-email-lstipakov@gmail.com>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg19046.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
5 years agoVisual Studio: upgrade project files to VS2019
Lev Stipakov [Thu, 7 Nov 2019 17:45:23 +0000 (19:45 +0200)] 
Visual Studio: upgrade project files to VS2019

Signed-off-by: Lev Stipakov <lev@openvpn.net>
Acked-by: Simon Rozman <simon@rozman.si>
Message-Id: <1573148729-27339-2-git-send-email-lstipakov@gmail.com>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg19027.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
5 years agoVLAN: add documentation to manpage
Antonio Quartulli [Sat, 9 Nov 2019 09:58:36 +0000 (10:58 +0100)] 
VLAN: add documentation to manpage

This patch adds documentation for all the VLAN related knobs.

Signed-off-by: Fabian Knittel <fabian.knittel@lettink.de>
Signed-off-by: Antonio Quartulli <a@unstable.cc>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <20191109095836.11190-1-a@unstable.cc>
URL: https://www.mail-archive.com/search?l=mid&q=20191109095836.11190-1-a@unstable.cc
Signed-off-by: Gert Doering <gert@greenie.muc.de>
5 years agoVLAN: allow forwarding tagged and untagged packets on the server TAP device
Antonio Quartulli [Wed, 9 Oct 2019 14:34:20 +0000 (16:34 +0200)] 
VLAN: allow forwarding tagged and untagged packets on the server TAP device

This changes allows the user to configure the server TAP interface to
forward both VLAN tagged and untagged packets (i.e. vlan_accept ==
VLAN_ALL).

Untagged packets are marked with the VID configured in the server
configuration file, while tagged packets will keep their header as it
is.

Forwarding is then performed following the standard rules, while
ensuring that pakcets do not leave the VLAN they belong to.

Signed-off-by: Fabian Knittel <fabian.knittel@lettink.de>
Signed-off-by: Antonio Quartulli <a@unstable.cc>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <20191009143422.9419-8-a@unstable.cc>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg18919.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
5 years agoVLAN: implement support for forwarding only pre-tagged VLAN packets
Antonio Quartulli [Wed, 9 Oct 2019 14:34:19 +0000 (16:34 +0200)] 
VLAN: implement support for forwarding only pre-tagged VLAN packets

By building on top of the VLAN basic support, allow the user to configure
the server in VLAN_TAGGED-only mode. This way, only packets that reach
the TAP interface with an 802.1Q header are considered for forwarding -
untagged packets are all dropped.

A VLAN-tagged packet is then treated like any other packet by the
OpenVPN routing engine, with the exception of being allowed to reach
only clients configured with the same VID.

The logic applies to all server-to-client and client-to-client traffic.

Signed-off-by: Fabian Knittel <fabian.knittel@lettink.de>
Signed-off-by: Antonio Quartulli <a@unstable.cc>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <20191009143422.9419-7-a@unstable.cc>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg18918.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
5 years agotravis: add Visual Studio build
Lev Stipakov [Thu, 7 Nov 2019 21:29:34 +0000 (23:29 +0200)] 
travis: add Visual Studio build

Signed-off-by: Lev Stipakov <lev@openvpn.net>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <1573162174-28461-1-git-send-email-lstipakov@gmail.com>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg19035.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
5 years agois_ipv_X: add support for parsing IP header inside a 802.1q frame
Antonio Quartulli [Wed, 9 Oct 2019 14:34:18 +0000 (16:34 +0200)] 
is_ipv_X: add support for parsing IP header inside a 802.1q frame

Extend is_ipv_X() routine by properly parsing 802.1q frame rather than
dropping them.

This change is required in order to allow OpenVPN to accept VLAN tagged
frames, which otherwise would be dropped when trying to access the inner
IP header.

While at it, slightly fix the function style.

Signed-off-by: Fabian Knittel <fabian.knittel@lettink.de>
Signed-off-by: Antonio Quartulli <a@unstable.cc>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <20191009143422.9419-6-a@unstable.cc>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg18916.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
5 years agoVLAN: filter multicast and client-to-client unicast traffic
Antonio Quartulli [Wed, 9 Oct 2019 14:34:17 +0000 (16:34 +0200)] 
VLAN: filter multicast and client-to-client unicast traffic

With this change, client-to-client communications are possible only if
clients were configured with the same PVID.

At the same time also broadcast packets are now forwarded only to hosts
belonging to the originator VLAN.

Signed-off-by: Fabian Knittel <fabian.knittel@lettink.de>
Signed-off-by: Antonio Quartulli <a@unstable.cc>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <20191009143422.9419-5-a@unstable.cc>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg18922.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
5 years agomsvc: Add vlan.c/h
Simon Rozman [Thu, 7 Nov 2019 13:29:01 +0000 (14:29 +0100)] 
msvc: Add vlan.c/h

This upgrades 99f28081477ca325a14b13c38abec2c9b619eb01 to support MSVC
building.

Signed-off-by: Simon Rozman <simon@rozman.si>
Acked-by: Lev Stipakov <lstipakov@gmail.com>
Message-Id: <20191107132901.1280-1-simon@rozman.si>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg19015.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
5 years agomaddr: export VLAN ID from client context to maddr object
Antonio Quartulli [Wed, 9 Oct 2019 14:34:16 +0000 (16:34 +0200)] 
maddr: export VLAN ID from client context to maddr object

When receiving a packet from a client, the associated maddr needs to
carry also the VID associated with that client. This way the VID can be
appended to the packet later, if needed.

This patch adds support for exporting the VID from the client context to
the related per-packet maddr object.

Signed-off-by: Fabian Knittel <fabian.knittel@lettink.de>
Signed-off-by: Antonio Quartulli <a@unstable.cc>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <20191009143422.9419-4-a@unstable.cc>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg18917.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
5 years agoVLAN: add basic VLAN tagging support
Antonio Quartulli [Wed, 9 Oct 2019 14:34:15 +0000 (16:34 +0200)] 
VLAN: add basic VLAN tagging support

This patch introduces basic support for VLAN tagging on the server side.
The introduced functionality consists in allowing the user to assign
a VID to the server TAP device and a VID to each client port.

Client specific VID are assigned by means of files in CCD (like for
other client specific settings).

Once VIDs have been assigned, everything works as before, except that
communications are allowed only between hosts having the same VID.

With this patch all broadcast and client-to-client traffic is yet
separated by VLAN: only client-to-server unicasts are affected.

Signed-off-by: Fabian Knittel <fabian.knittel@lettink.de>
Signed-off-by: Antonio Quartulli <a@unstable.cc>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <20191009143422.9419-3-a@unstable.cc>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg18924.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
5 years agomsvc: OpenSSL 1.1.x support
Lev Stipakov [Thu, 17 Oct 2019 12:23:43 +0000 (15:23 +0300)] 
msvc: OpenSSL 1.1.x support

Since we release Windows client with OpenSSL 1.1.0
(and will switch to 1.1.1 in the next release),
it makes sense to use a newer version in VS build.

This patch adds msvc-specific defines which imply
that underlying OpenSSL is 1.1.x (works with 1.1.0 and 1.1.1).

Also OpenSSL library names in project file are updated.

Signed-off-by: Lev Stipakov <lstipakov@gmail.com>
Acked-by: Simon Rozman <simon@rozman.si>
Message-Id: <1571315023-17044-1-git-send-email-lstipakov@gmail.com>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg18948.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
5 years agoForce combinationation of --socks-proxy and --proto UDP to use IPv4.
Gert Doering [Sun, 20 Oct 2019 15:00:39 +0000 (17:00 +0200)] 
Force combinationation of --socks-proxy and --proto UDP to use IPv4.

Our current socks.c code does not handle IPv6 + UDP mode (socket
negotiated with server is IPv4-only, addresses passed in the
packets are IPv4-only).  If this combination is specified, print
an explanatory message and force IPv4-only.

While at it, extend socks.c code to print address+port of auxiliary
UDP connection to SOCKS server (helps debugging).

Trac: #1221

Signed-off-by: Gert Doering <gert@greenie.muc.de>
Acked-by: Antonio Quartulli <antonio@openvpn.net>
Message-Id: <20191020150039.21516-1-gert@greenie.muc.de>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg18952.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
5 years agoIgnore --pull-filter for --mode server
Richard Bonhomme [Thu, 24 Oct 2019 21:48:32 +0000 (22:48 +0100)] 
Ignore --pull-filter for --mode server

OpenVPN-GUI (For Windows) currently always adds "--pull-filter"
which is a fatal error when also using "--mode server"

Using "--pull-filter" implicitly requires the use of "--pull".
Using "--mode server" and "--pull" is a fatal error which supercedes
"--pull-filter"

Safely ignore "--pull-filter" for "--mode server"

Trac: #1164

v2: Improve commit message, no functional changes.

Signed-off-by: Richard Bonhomme <tincanteksup@gmail.com>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <20191024214832.22737-1-tincanteksup@gmail.com>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg18964.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
5 years agoVisual Studio: make it easier to build with VS
Lev Stipakov [Fri, 11 Oct 2019 09:03:45 +0000 (12:03 +0300)] 
Visual Studio: make it easier to build with VS

This changes default path to openvpn dependencies, so that
openvpn-build and openvpn projects can be cloned from the same
folder:

  c:\Users\Administrator\Projects>git clone
git@github.com:OpenVPN/openvpn-build.git
  c:\Users\Administrator\Projects>git clone
git@github.com:OpenVPN/openvpn.git

This also removes the necessity of copying openvpn-build\msvc\image
to %USERPROFILE%.

To use Visual Studio, clone both projects, install dependencies
(VS2017 Community with SDK 10.0.17143, Strawberry Perl) and run:

  c:\Users\Administrator\Projects\openvpn-build\msvc\build.bat

Then just open solution file:

  c:\Users\Administrator\Projects\openvpn\openvpn.sln

Signed-off-by: Lev Stipakov <lstipakov@gmail.com>
Acked-by: Simon Rozman <simon@rozman.si>
Message-Id: <1570784625-8837-1-git-send-email-lstipakov@gmail.com>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg18930.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
5 years agoFix typo in NTLM proxy debug message
Mykola Baibuz [Mon, 14 Oct 2019 11:21:45 +0000 (14:21 +0300)] 
Fix typo in NTLM proxy debug message

Signed-off-by: Mykola Baibuz <mykola.baibuz@gmail.com>
Acked-by: Antonio Quartulli <antonio@openvpn.net>
Message-Id: <20191014112145.251-1-mykola.baibuz@gmail.com>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg18937.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
5 years agoOpenSolaris/OpenIllumos: use /bin/bash if available for test scripts.
Gert Doering [Wed, 9 Oct 2019 12:00:43 +0000 (14:00 +0200)] 
OpenSolaris/OpenIllumos: use /bin/bash if available for test scripts.

t_client.sh relies on "echo -e" and "echo -n" to produce nicely
looking output, which fails on Solaris /bin/sh - force SHELL=/bin/bash
on recent-enough Solaris variants that have it.

Signed-off-by: Gert Doering <gert@greenie.muc.de>
Acked-by: David Sommerseth <davids@openvpn.net>
Message-Id: <20191009120043.22692-1-gert@greenie.muc.de>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg18914.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
5 years agomaddr: create helper function to populate maddr object from eth_addr
Antonio Quartulli [Wed, 9 Oct 2019 14:34:14 +0000 (16:34 +0200)] 
maddr: create helper function to populate maddr object from eth_addr

Signed-off-by: Antonio Quartulli <a@unstable.cc>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <20191009143422.9419-2-a@unstable.cc>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg18921.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
5 years agoFix IPv6 routes on tap interfaces on OpenSolaris/OpenIndiana
Gert Doering [Wed, 9 Oct 2019 09:52:00 +0000 (11:52 +0200)] 
Fix IPv6 routes on tap interfaces on OpenSolaris/OpenIndiana

The "route add" code always used "metric 0" on OpenSolaris, because
(on tun interfaces) it was required to make the route work on
"non-ethernet" interfaces (connected, no NDP).

This breaks routes via tap interfaces on recent Solaris versions
(tested on OpenIndiana 2019) - there, routes only work if metric
is != 0 (or just not set).  Otherwise it tries to map the gateway
address to a local address and fails.

Signed-off-by: Gert Doering <gert@greenie.muc.de>
Acked-by: Antonio Quartulli <antonio@openvpn.net>
Message-Id: <20191009095200.9337-2-gert@greenie.muc.de>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg18906.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
5 years agorepair tap mode on OpenSolaris/OpenIndiana
Gert Doering [Wed, 9 Oct 2019 09:51:59 +0000 (11:51 +0200)] 
repair tap mode on OpenSolaris/OpenIndiana

commit 611fcbc48 joined the two distinct calls for "add ipv6 address
to tap interface" and "set MTU" for Solaris - but due to peculiarities
on how this platform handles IPv6 addresses ("ifconfig addif" creates
a new "tap0:1" subinterface with the new address - which does not have
a distinct MTU) this does not work.

un-join calls again.

Signed-off-by: Gert Doering <gert@greenie.muc.de>
Acked-by: Antonio Quartulli <antonio@openvpn.net>
Message-Id: <20191009095200.9337-1-gert@greenie.muc.de>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg18905.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
5 years agopush.c: fix Visual Studio build
Lev Stipakov [Tue, 8 Oct 2019 12:52:33 +0000 (15:52 +0300)] 
push.c: fix Visual Studio build

Visual Studio doesn't support empty designated initializers
for C code, so use { 0 }. Also replace existing CLEAR() call with
the new initializers.

Signed-off-by: Lev Stipakov <lev@openvpn.net>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <1570539154-31784-1-git-send-email-lstipakov@gmail.com>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg18904.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
5 years agovcxproj: add missing source files
Lev Stipakov [Tue, 8 Oct 2019 12:52:34 +0000 (15:52 +0300)] 
vcxproj: add missing source files

Commit 1b9a88a has added new C source/header files which
have to be added to VS project file.

Signed-off-by: Lev Stipakov <lev@openvpn.net>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <1570539154-31784-2-git-send-email-lstipakov@gmail.com>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg18903.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
5 years agoImplement unit tests for auth-gen-token
Arne Schwabe [Tue, 17 Sep 2019 12:33:21 +0000 (14:33 +0200)] 
Implement unit tests for auth-gen-token

The unit test is breaking the 80 char limit in some places
but the remaining lines it breaks the limit I feel
forcing the 80 char limit will impair readibility

Patch V2: adapt unit tests to other V2 patches
Patch V4: Resolve rebase conflicts
Patch V5: Add \ lost in rebase that broke compilation
Patch V7: Fix unit test failure, try to stay below 80
Acked-by: David Sommerseth <davids@openvpn.net>
Message-Id: <20190917123321.15993-1-arne@rfc2549.org>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg18821.html

Signed-off-by: Gert Doering <gert@greenie.muc.de>
5 years agoImprove the comments related to auth-token-hmac patches
David Sommerseth [Fri, 27 Sep 2019 22:45:36 +0000 (00:45 +0200)] 
Improve the comments related to auth-token-hmac patches

A couple of places the documentation was not clear enough or not even
correct.  Just improve this to avoid confusion later on.

Signed-off-by: David Sommerseth <davids@openvpn.net>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <20190927224536.27480-4-davids@openvpn.net>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg18874.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
5 years agoauth-token: Fix compiler complaints with --disable-management
David Sommerseth [Fri, 27 Sep 2019 22:45:35 +0000 (00:45 +0200)] 
auth-token: Fix compiler complaints with --disable-management

When building with --disable-management, the compiler complains with
implicit declaration of function â€˜ssl_clean_auth_token’.  This is due to
the ssl_clean_auth_token() function being declared inside an #ifdef
ENABLE_MANAGEMENT fence where it should not be.

Signed-off-by: David Sommerseth <davids@openvpn.net>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <20190927224536.27480-3-davids@openvpn.net>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg18873.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
5 years agoauth-token: Fix building with --disable-server
David Sommerseth [Fri, 27 Sep 2019 22:45:34 +0000 (00:45 +0200)] 
auth-token: Fix building with --disable-server

The final patches of the auth-token hmac support patches had a typo in
the P2MP_SERVER fencing breaking --disable-server builds.  It used #if
instead of #ifdef.

While at it, also fix another missing P2MP_SERVER fencing causing the
compiler to complain about an unused variable in push.c

Signed-off-by: David Sommerseth <davids@openvpn.net>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <20190927224536.27480-2-davids@openvpn.net>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg18875.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
5 years agoSent indication that a session is expired to clients
Arne Schwabe [Tue, 17 Sep 2019 12:11:15 +0000 (14:11 +0200)] 
Sent indication that a session is expired to clients

This allows OpenVPN 3 core to fall back to the original authentication
method.

This commit changes man_def_auth_set_client_reason to
auth_set_client_reason since it now used in more contexts.

Also remove a FIXME about client_reason not being freed, as it is freed
in tls_multi_free with auth_set_client_reason(multi, NULL);

Patch V4: Rebase on master
Patch V7: Rebase on master
Acked-by: David Sommerseth <davids@openvpn.net>
Message-Id: <20190917121115.13966-1-arne@rfc2549.org>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg18820.html

Signed-off-by: Gert Doering <gert@greenie.muc.de>
5 years agoImplement a permanent session id in auth-token
Arne Schwabe [Tue, 17 Sep 2019 12:10:39 +0000 (14:10 +0200)] 
Implement a permanent session id in auth-token

This allows an external authentication method
(e.g. management interface) to track the connection and distinguish a
reconnection from multiple connections.

Addtionally this now also checks to workaround a problem with
OpenVPN 3 core that sometimes uses a username hint from the config
instead of using an empty username if the token would be valid
with an empty username. Accepting such token can be only done
explicitly when the external-auth keyword to auth-gen-token is present.

Patch V2: Add Empty variants to work around behaviour in openvpn 3
Patch V3: document the behaviour of external-auth better in the man page,
          rename 'auth' parameter to 'external-auth'
Patch V4: Rebase on current master
Patch V6: Fix tls_lock_username rejecting clients with empty username
          when explicitly accepting them with external-auth
Patch V7: Fix compiling with disable-server

Acked-by: David Sommerseth <davids@openvpn.net>
Message-Id: <20190917121039.13791-1-arne@rfc2549.org>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg18819.html

Signed-off-by: Gert Doering <gert@greenie.muc.de>
5 years agoRewrite auth-token-gen to be based on HMAC based tokens
Arne Schwabe [Tue, 17 Sep 2019 12:10:04 +0000 (14:10 +0200)] 
Rewrite auth-token-gen to be based on HMAC based tokens

The previous auth-token implementation had a serious problem, especially
when paired with an unpatched OpenVPN client that keeps trying the
auth-token (commit e61b401a).

The auth-token-gen implementation forgot the auth-token on reconnect, this
lead to reconnect with auth-token never working.

This new implementation implements the auth-token in a stateles variant. By
using HMAC to sign the auth-token the server can verify if a token has been
authenticated and by checking the embedded timestamp in the token it can
also verify that the auth-token is still valid.

Using the new config directive auth-gen-token-secret instead of
extending auth-gen-token (--auth-gen-token [lifetime] [secret-key]) was
chosen to allow inlining the secret key.

Patch V2: cleaned up code, use refactored read_pem_key_file function
Patch V3: clarify some design decision in the commit message
Patch V4: Use ephermal_generate_key
Patch V5: Use C99 PRIu64 instead of %lld int printf like statement,
          fix strict aliasing
Patch V6: Rebase on master
Patch V7: fix compiling with --disable-server

Acked-by: David Sommerseth <davids@openvpn.net>
Message-Id: <20190917121004.13685-1-arne@rfc2549.org>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg18818.html

Signed-off-by: Gert Doering <gert@greenie.muc.de>
5 years agotests/t_lpback.sh: Switch sed(1) to POSIX-compatible regex.
Kyle Evans [Fri, 6 Sep 2019 17:44:59 +0000 (19:44 +0200)] 
tests/t_lpback.sh: Switch sed(1) to POSIX-compatible regex.

A test run with FreeBSD PR 229925 'Disallow escaping ordinary
characters in regex(3)' reveals one sed expression that uses the
GNU-extension "\s".

Given that this is the only occurrence and it's a trivial fix,
update it to be POSIX-compatible.

Signed-off-by: Matthias Andree <matthias.andree@gmx.de>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <20190906174458.14975-2-matthias.andree@gmx.de>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg18806.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
5 years agotapctl: add optional 'hardware id' parameter
Lev Stipakov [Mon, 23 Sep 2019 09:08:02 +0000 (12:08 +0300)] 
tapctl: add optional 'hardware id' parameter

If parameter is not specified, default value "root\tap0901"
is used.

This enables tapctl to work with different tun drivers,
like "tapoas" (from OpenVPN Connect) or "wintun".

Signed-off-by: Lev Stipakov <lev@openvpn.net>
Acked-by: Simon Rozman <simon@rozman.si>
Message-Id: <1569229682-9731-1-git-send-email-lstipakov@gmail.com>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg18854.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
5 years agot_net.sh: execute sleep after checking exit code of previous command
Antonio Quartulli [Thu, 19 Sep 2019 20:22:57 +0000 (22:22 +0200)] 
t_net.sh: execute sleep after checking exit code of previous command

Ensure to check the exit code of the mktun command *before* running
sleep, otherwise '$?' will resolve to the exit code of sleep itself,
thus nullifying the check.

Reported-by: Steffan Karger <steffan@karger.me>
Signed-off-by: Antonio Quartulli <a@unstable.cc>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <20190919202257.19405-1-a@unstable.cc>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg18845.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
5 years agot_net.sh: wait for NO-CARRIER bit to settle before starting test
Antonio Quartulli [Thu, 19 Sep 2019 07:28:20 +0000 (09:28 +0200)] 
t_net.sh: wait for NO-CARRIER bit to settle before starting test

Interfaces of type tun are marked as NO-CARRIER when no process is
attached to them. However, this bit gets set with some delay after
creation.

For this reason, it is better to wait for the bit to settle before
starting any test, otherwise any timing influence on the test may lead
to inconsistencies due to the NO-CARRIER bit randomly being or not in
the snapshot output taken by t_net.sh.

This patch add a 'sleep 1' command right after creation of the
interface, to give the NO-CARRIER bit a chance to settle.

This issue has been witnessed on a buildbot that is
apparently slowler than average to run the unit tests.

Signed-off-by: Antonio Quartulli <a@unstable.cc>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <20190919072820.9913-1-a@unstable.cc>
URL: https://www.mail-archive.com/search?l=mid&q=20190919072820.9913-1-a@unstable.cc
Signed-off-by: Gert Doering <gert@greenie.muc.de>
5 years agotun.h: remove TUN_PASS_BUFFER define
Lev Stipakov [Mon, 9 Sep 2019 08:57:16 +0000 (11:57 +0300)] 
tun.h: remove TUN_PASS_BUFFER define

Since the very beginning this define has only
been used together with _WIN32 and code wrapped into it
uses Win32 API, so it could be safely removed and
replaced with _WIN32.

Signed-off-by: Lev Stipakov <lstipakov@gmail.com>
Acked-by: David Sommerseth <davids@openvpn.net>
Message-Id: <1568019436-28527-1-git-send-email-lstipakov@gmail.com>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg18808.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
5 years agotun.h: change tun_set() return value type to void
Lev Stipakov [Fri, 6 Sep 2019 15:40:37 +0000 (18:40 +0300)] 
tun.h: change tun_set() return value type to void

This function's return value is never used, so make it void.

Signed-off-by: Lev Stipakov <lstipakov@gmail.com>
Acked-by: Antonio Quartulli <antonio@openvpn.net>
Acked-by: David Sommerseth <davids@openvpn.net>
Message-Id: <1567784437-25922-1-git-send-email-lstipakov@gmail.com>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg18804.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
5 years agoroute.c: simplify ifdef logic
Antonio Quartulli [Mon, 5 Aug 2019 09:25:29 +0000 (11:25 +0200)] 
route.c: simplify ifdef logic

With the introduction of the new networking API layer on linux, some
ifdefs can be pruned or simplified.

While at it move some variable to improve readability.

Signed-off-by: Antonio Quartulli <antonio@openvpn.net>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <20190805092529.9467-7-a@unstable.cc>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg18724.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
5 years agonetworking_sitnl.c: uncrustify file
Antonio Quartulli [Mon, 5 Aug 2019 09:25:28 +0000 (11:25 +0200)] 
networking_sitnl.c: uncrustify file

Give this file a run under uncrustify to fix a few style glitches here
and there.

Signed-off-by: Antonio Quartulli <antonio@openvpn.net>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <20190805092529.9467-6-a@unstable.cc>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg18727.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
5 years agotun.c: undo_ifconfig_ipv4/6 remove useless gc argument
Antonio Quartulli [Mon, 5 Aug 2019 09:25:27 +0000 (11:25 +0200)] 
tun.c: undo_ifconfig_ipv4/6 remove useless gc argument

With the new networking APIs, each implementation handles garbage
collection internally and therefore does not require a gc object to be
provided by the outer layer.

However, there are a few cases where a garbage collector is still required.
In close_tun() move the declaration and cleanup of gc to the
area where it is used and simplify the surrounding code a bit.

While at it, fix a typo in a nearby ifdef comment.

Signed-off-by: Antonio Quartulli <antonio@openvpn.net>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <20190805092529.9467-5-a@unstable.cc>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg18726.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
5 years agonetworking: extend API for better memory management
Antonio Quartulli [Fri, 16 Aug 2019 20:26:54 +0000 (22:26 +0200)] 
networking: extend API for better memory management

Networking backend implementations may need to allocate dynamic
resources that require an explicit free/release.
Since these cleanup are perfomed not very often, and only at specific
times, it makes sense to have the upper layer signal when it's the right
time to do so, by means of a new API call.

For this purpose two news APIs have been implemented:
- net_ctx_free() to release all backend specific resources. Expected to
  be called at application cleanup time;
- net_ctx_reset() to let backends release temporary resources (i.e.
  reset garbage collectors). To be invoked after routines that
  are expected to allocate memory (i.e. tun setup or shutdown).

In this patch related implementations for iproute2 and sitnl are also
provided.

Signed-off-by: Antonio Quartulli <antonio@openvpn.net>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <20190816202654.19388-1-a@unstable.cc>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg18780.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
5 years agombedtls: fix segfault by calling mbedtls_cipher_free() in cipher_ctx_free()
Antonio Quartulli [Fri, 16 Aug 2019 20:49:45 +0000 (22:49 +0200)] 
mbedtls: fix segfault by calling mbedtls_cipher_free() in cipher_ctx_free()

Commit ("openssl: Fix compilation without deprecated OpenSSL 1.1 APIs")
has removed the cipher_ctx_cleanup() API, as it is not anymore required
to be a distinct call. However, while doing so it also touched the
mbedtls backend in a wrong way causing a systematic segfault upon
connection.

Basically mbedtls_cipher_free(ctx) was moved from the defunct
cipher_ctx_cleanup()
to md_ctx_free(), while it was supposed to go into cipher_ctx_free().
This was clearly wrong as also the type of the ctx variable was not
correct anymore.

Fix this mistake by actually moving mbedtls_cipher_free(ctx) to
cipher_ctx_free().

Signed-off-by: Antonio Quartulli <a@unstable.cc>
Acked-by: Gert Doering <gert@greenie.muc.de>
Acked-by: Arne Schwabe <arne@rfc2549.org>
Message-Id: <20190816204945.7937-1-a@unstable.cc>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg18781.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
5 years agoopenssl: Fix compilation without deprecated OpenSSL 1.1 APIs
Rosen Penev [Wed, 24 Jul 2019 15:29:34 +0000 (17:29 +0200)] 
openssl: Fix compilation without deprecated OpenSSL 1.1 APIs

EVP_CIPHER_CTX_init and _cleanup were deprecated in 1.1 and both were
replaced with _reset.

EVP_CIPHER_CTX_free in OpenSSL 1.1 replaces the cleanup/free combo of
earlier OpenSSL version. And OpenSSL 1.0.2 already calls cleanup as part
of _free.

Therefore we can remove the _cleanup calls and use the OpenSSL 1.1. API
everywhere.

Also removed initialisation with OpenSSL 1.1 as it is no longer
needed and causes compilation errors when disabling deprecated APIs.

Same with SSL_CTX_set_ecdh_auto as it got removed.

Patch V3: Use EVP_CIPHER_CTX_reset instead of init/cleanup

Signed-off-by: Rosen Penev <rosenp@gmail.com>
Signed-off-by: Arne Schwabe <arne@rfc2549.org>
Acked-by: Rosen Penev <rosenp@gmail.com>
Acked-by: Steffan Karger <steffan.karger@fox-it.com>
Message-Id: <20190724152934.9884-1-arne@rfc2549.org>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg18700.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
5 years agoIncrease listen() backlog queue to 32
Gert Doering [Thu, 15 Aug 2019 15:53:19 +0000 (17:53 +0200)] 
Increase listen() backlog queue to 32

For reasons historically unknown, OpenVPN sets the listen() backlog
queue to "1", which signals the kernel "while there is one TCP connect
waiting for OpenVPN to handle it, refuse all others" - which, on
restarting a busy TCP server, will create connection issues.

The exact "best" value of the backlog queue is subject of discussion,
but for a server that is not extremely busy with many connections
coming in in parallel, there is no real difference between "10" or "500",
as long as it's "more than 1".

Found and debugged by "mjo" in Trac.

Trac: #1208

Signed-off-by: Gert Doering <gert@greenie.muc.de>
Acked-by: Antonio Quartulli <antonio@openvpn.net>
Acked-by: David Sommerseth <davids@openvpn.net>
Message-Id: <20190815155319.28249-1-gert@greenie.muc.de>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg18758.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
5 years agositnl: harden strncpy() by forcing arguments to have the same length
Antonio Quartulli [Mon, 5 Aug 2019 09:25:24 +0000 (11:25 +0200)] 
sitnl: harden strncpy() by forcing arguments to have the same length

At the moment a strcpy() (without length check!) is performed between a
string long IFNAMSIZ bytes and one of 16 bytes. This is ok right now
because IFNAMSIZ is defined as 16, however this bit is not under our
control and may change in he future without us being warned.

For this reason, force both strings to use IFNAMSIZ as size and, since
this constant may not exist on every platform, ensure it is always
defined.

Signed-off-by: Antonio Quartulli <antonio@openvpn.net>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <20190805092529.9467-2-a@unstable.cc>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg18722.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
5 years agoAdjust Android code after sitnl patch merge
Arne Schwabe [Thu, 15 Aug 2019 12:10:53 +0000 (14:10 +0200)] 
Adjust Android code after sitnl patch merge

It turns out that the only part of Android that still shares routing
code with Linux is the get_default_ipv6 method.

Instead of fixing a method that makes little sense on Android anyway,
have a method that returns a fake ipv6 gateway like for ipv4.

Patch V2: Instead adding ANDROID to a long list of ifdefs, change this
to a non LINUX ifdef

Signed-off-by: Arne Schwabe <arne@rfc2549.org>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <20190815121053.18433-2-arne@rfc2549.org>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg18752.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
5 years agoFix check if iface name is set
Arne Schwabe [Thu, 15 Aug 2019 12:10:52 +0000 (14:10 +0200)] 
Fix check if iface name is set

Clang/Android complained

 warning: address of array 'rgi6->iface' will always evaluate to 'true'
[-Wpointer-bool-conversion]
          if (rgi6->iface)

iface is a char[16]; So its pointer is always true.

we do a CLEAR(rgi6) always before setting this struct and strcpy the
name into iface. So using strlen instead of checking for the pointer
should be the right fix.

Patch V2: use if(strlen > 0) instead of if(strlen)

Signed-off-by: Arne Schwabe <arne@rfc2549.org>
Acked-by: Antonio Quartulli <antonio@openvpn.net>
Message-Id: <20190815121053.18433-1-arne@rfc2549.org>
URL: https://www.mail-archive.com/search?l=mid&q=20190815121053.18433-1-arne@rfc2549.org
Signed-off-by: Gert Doering <gert@greenie.muc.de>
5 years agonetworking/best_gw: remove useless prefixlen parameter
Antonio Quartulli [Mon, 5 Aug 2019 09:25:25 +0000 (11:25 +0200)] 
networking/best_gw: remove useless prefixlen parameter

The prefixlen parameter is not used at all while retrieving a route
therefore it can safely be removed.

Signed-off-by: Antonio Quartulli <antonio2openvpn.net>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <20190805092529.9467-3-a@unstable.cc>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg18725.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
5 years agoWrong FILETYPE in .rc files
Gisle Vanem [Wed, 3 Jul 2019 13:45:34 +0000 (15:45 +0200)] 
Wrong FILETYPE in .rc files

I noticed the .rc-files for programs uses
'FILETYPE 0x2L'. The 0x2L' is for a .DLL (VFT_DLL).

Ref: Win-Kit's 'um/verrsrc.h':
  #define VFT_DLL 0x00000002L

Hence these '0x2L' should be replaced with 'VFT_APP':

Acked-by: Lev Stipakov <lstipakov@gmail.com>
Message-Id: <aa4f4026-a684-f96d-c8cb-d4f8a3468c4c@gmail.com>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg18644.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
5 years agocrypto.c: fix Visual Studio build
Lev Stipakov [Thu, 18 Jul 2019 09:35:03 +0000 (12:35 +0300)] 
crypto.c: fix Visual Studio build

Commit fb4e8ab added variable-length array which
is C99 feature and is not supported by Visual Studio.

This removes VLA and writes data directly into passed buffer.

Signed-off-by: Lev Stipakov <lev@openvpn.net>
Acked-by: Arne Schwabe <arne@rfc2549.org>
Message-Id: <1563442503-11119-1-git-send-email-lstipakov@gmail.com>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg18676.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
5 years agoCorrect the return value of cryptoapi RSA signature callbacks
Selva Nair [Fri, 26 Jul 2019 20:39:17 +0000 (16:39 -0400)] 
Correct the return value of cryptoapi RSA signature callbacks

Fixes the wrong check on siglen instead of *siglen for
signing failures.

Bug reported by: lilulo <lilulo@gmail.com>

Signed-off-by: Selva Nair <selva.nair@gmail.com>
Acked-by: Steffan Karger <steffan.karger@fox-it.com>
Message-Id: <1564173557-11776-1-git-send-email-selva.nair@gmail.com>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg18706.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
5 years agoDo not set pkcs11-helper 'safe fork mode'
Hilko Bengen [Mon, 18 Feb 2019 15:31:28 +0000 (16:31 +0100)] 
Do not set pkcs11-helper 'safe fork mode'

From the pkcs11-helper API documentation about pkcs11h_setForkMode():

> This funciton is releavant if PKCS11H_FEATURE_MASK_THREADING is
> set. If safe mode is on, the child process can use the loaded
> PKCS#11 providers but it cannot use fork(), while it is in one of
> the hooks functions, since locked mutexes cannot be released.

As far as I can tell, pkcs11-helper functionality is not used in a
child process that is created after initialization. Even if OpenVPN is
turned into a daemon, the pkcs11-helper library is only initialized
after calling possibly_become_daemon(), i.e. in the child process. All
other uses of fork() are immediately followed by an exec()

This simple change fixes the symptoms described in both
<https://community.openvpn.net/openvpn/ticket/538> (hang on password
prompt when systemd support is enabled) and
<https://community.openvpn.net/openvpn/ticket/1157> (hang on
initialization with newer versions of pkcs11-helper).

I have successfully tested that this makes the described symptoms go
away. For this, I used a YubiKey NEO on Debian/stable, a rebuild of
OpenVPN 2.4.6 and two versions of libpkcs11-helper:

- libpkcs11-helper 1.21-1 from Debian/stretch
- a backport of libpkcs11-helper 1.25-1 from Debian/buster
Acked-by: Steffan Karger <steffan.karger@fox-it.com>
Message-Id: <20190218153129.3818-1-bengen@hilluzination.de>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg18218.html

Signed-off-by: Gert Doering <gert@greenie.muc.de>
5 years agoFix broken fragment/mssfix with NCP
Lev Stipakov [Mon, 21 Jan 2019 20:04:54 +0000 (22:04 +0200)] 
Fix broken fragment/mssfix with NCP

NCP negotiation replaces worst cast crypto overhead
with actual one in data channel frame. That frame
params are used by mssfix.

Fragment frame still contains worst case overhead.
Because of that TCP packets are fragmented, since
MSS value exceeds max fragment size.

Fix by replacing worst case crypto overhead with
actual one for fragment frame, as it is done for data
channel frame.

Trac #1140

Signed-off-by: Lev Stipakov <lstipakov@gmail.com>
Acked-by: Arne Schwabe <arne@rfc2549.org>
Acked-by: Steffan Karger <steffan.karger@fox-it.com>
Message-Id: <1548101094-4449-1-git-send-email-lstipakov@gmail.com>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg18135.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
5 years agoroute.c: use sitnl to implement get_default_gateway_ipv6()
Antonio Quartulli [Mon, 15 Jul 2019 14:46:09 +0000 (16:46 +0200)] 
route.c: use sitnl to implement get_default_gateway_ipv6()

get_default_gateway_ipv6() has always been implemented using
netlink, however, now that we have sitnl, we can re-use the
latter and get rid of the netlink code from route.c.

Signed-off-by: Antonio Quartulli <antonio@openvpn.net>
Acked-by: Arne Schwabe <arne@rfc2549.org>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <20190715144609.19616-1-a@unstable.cc>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg18667.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
6 years agoRemove -no-cpp-precomp flag from Darwin builds
Arne Schwabe [Fri, 5 Jul 2019 11:42:43 +0000 (13:42 +0200)] 
Remove -no-cpp-precomp flag from Darwin builds

GCC 9 no longer accepts this flag and trying to find out what it does do
leads to an article

"-no-cpp-precomp: the compiler flag that time forgot"

that also no longer on the Internet. And most other things are
PRs/commits from over ten years ago that remove the flag since it
is no longer needed.
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <20190705114243.9481-1-arne@rfc2549.org>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg18650.html

Signed-off-by: Gert Doering <gert@greenie.muc.de>
6 years agoAdd generate_ephemeral_key that allows a random ephermal key
Arne Schwabe [Thu, 13 Jun 2019 13:48:30 +0000 (15:48 +0200)] 
Add generate_ephemeral_key that allows a random ephermal key

This is useful for features that can use enither a persistent
or an ephemeral key.

Patch V2: Move the functionality of generating a random key into a
          separate function that acts as wrapper for pem_read_key_file
Patch V4: Move wrapper functionality to caller and leave only generate
          epehermal key functionality in the new function
Acked-by: David Sommerseth <davids@openvpn.net>
Message-Id: <20190613134834.5709-2-arne@rfc2549.org>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg18527.html

Signed-off-by: Gert Doering <gert@greenie.muc.de>
6 years agoImplement --genkey type keyfile syntax and migrate tls-crypt-v2
Arne Schwabe [Thu, 13 Jun 2019 13:48:29 +0000 (15:48 +0200)] 
Implement --genkey type keyfile syntax and migrate tls-crypt-v2

This unifies our key generation and also migrates the generation
of the tls-crypt-v2 keys. Since tls-crypt-v2 is not included in any
released version, we remove the the old syntax without compatibility.

PATCH V4: Introduce warning/error when using --secret with --genkey
          Update non code usages to use new --genkey syntax
Acked-by: David Sommerseth <davids@openvpn.net>
Message-Id: <20190613134834.5709-1-arne@rfc2549.org>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg18524.html

Signed-off-by: Gert Doering <gert@greenie.muc.de>
6 years agotravis-ci: update components versions
Ilya Shipitsin [Fri, 28 Jun 2019 19:46:37 +0000 (00:46 +0500)] 
travis-ci: update components versions

tap windows, pkcs11 helper, mbedtls, openssl were updated to the most
recent versions

Signed-off-by: Ilya Shipitsin <chipitsine@gmail.com>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <20190628194637.5038-3-chipitsine@gmail.com>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg18619.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
6 years agotravis-ci: fix osx builds
Ilya Shipitsin [Fri, 28 Jun 2019 19:46:36 +0000 (00:46 +0500)] 
travis-ci: fix osx builds

cached homebrew required update, so lzo was not installed.
enforce updating homebrew

Signed-off-by: Ilya Shipitsin <chipitsine@gmail.com>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <20190628194637.5038-2-chipitsine@gmail.com>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg18620.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
6 years agoRemove cmocka submodule, rely on system-wide installation instead.
Gert Doering [Sun, 23 Jun 2019 18:32:10 +0000 (20:32 +0200)] 
Remove cmocka submodule, rely on system-wide installation instead.

We used to ship git submodule instructions to build a local copy of
cmocka in vendor/cmocka/ and use that (if cmake is installed) to build
unit tests.  With the network test driver this turns out to be a
LD_LIBRARY_PATH vs. SUDO complication which is really outweighing the
benefit of a local build today - so, use the system-wide installation
if available (querying pgk-config).  Do not build unit-tests otherwise.

v2: (inspired by patch from David Sommerseth)
  introduce "configure --disable-unit-test" switch
  simplify configure.ac logic
  use CMOCKA_LIBS and CMOCKA_INCLUDE (set by PKG_CHECK)

v3:
  repair conflict with commit 7473f326366fbceb
  CMOCKA_INCLUDE is not correct, must be CMOCKA_CFLAGS (see config.status)

Signed-off-by: Gert Doering <gert@greenie.muc.de>
Acked-by: David Sommerseth <davids@openvpn.net>
Message-Id: <20190623183210.6005-1-gert@greenie.muc.de>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg18570.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
6 years agoman: correct the description of --capath and --crl-verify regarding CRLs
Michal Soltys [Tue, 9 Apr 2019 14:34:38 +0000 (16:34 +0200)] 
man: correct the description of --capath and --crl-verify regarding CRLs

The man page states that when using --capath, the user is required to
provide CRLs for CAs. This is not true and providing CRLs is optional -
both in case of --capath as well as --crl-verify options. When relevant
CRL is not found OpenVPN simply logs the warning in the logs while
allowing the connection, e.g.:

VERIFY WARNING: depth=0, unable to get certificate CRL

This patch clarifies the behavior.

Signed-off-by: Michal Soltys <soltys@ziu.info>
Acked-by: Arne Schwabe <arne@rfc2549.org>
Message-Id: <20190409143438.25348-2-soltys@ziu.info>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg18343.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
6 years agoconfigure.ac: add lzo CFLAGS/LIBS to the test flags
Steffan Karger [Sun, 2 Jun 2019 10:18:31 +0000 (12:18 +0200)] 
configure.ac: add lzo CFLAGS/LIBS to the test flags

This fixes "make check" builds on systems with lzo on a non-standard
location.

Signed-off-by: Steffan Karger <steffan@karger.me>
Acked-by: David Sommerseth <davids@openvpn.net>
Message-Id: <20190602101831.21216-1-steffan@karger.me>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg18482.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
6 years agot_net.sh: fixes for the networking test script
Antonio Quartulli [Tue, 18 Jun 2019 16:34:35 +0000 (18:34 +0200)] 
t_net.sh: fixes for the networking test script

1) Building the networking unit-test when SITNL is not enabled does not
make much sense right now.
Make compilation dependent on having SITNL configured.

2) Remove some no-op mock_msg function calls.

3) Remove obsolete comment and declarations

Signed-off-by: Antonio Quartulli <antonio@openvpn.net>
Acked-by: David Sommerseth <davids@openvpn.net>
Message-Id: <20190618163435.26431-1-a@unstable.cc>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg18556.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
6 years agoroute.c: fix windows build by removing mismatching function parameter
Antonio Quartulli [Mon, 17 Jun 2019 12:41:10 +0000 (14:41 +0200)] 
route.c: fix windows build by removing mismatching function parameter

Signed-off-by: Antonio Quartulli <antonio@openvpn.net>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <20190617124110.30907-2-a@unstable.cc>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg18551.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
6 years agot_net.sh: properly perform sudo check and print test steps
Antonio Quartulli [Sat, 15 Jun 2019 23:02:13 +0000 (01:02 +0200)] 
t_net.sh: properly perform sudo check and print test steps

The current script is performing a test on the "kill" command, but this
is not useful to the t_net.sh script as it never really executes it.

Rather test that "sudo <unit-test-binary>" really works.

<unit-test-binary> has to be added to the sudoers file if this test
has to be performend unattanded. The path is:
./unit_tests/openvpn/networking_testdriver

On top of that, print a simple OK for every test that is succesful.

Signed-off-by: Antonio Quartulli <antonio@openvpn.net>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <20190615230213.14888-2-a@unstable.cc>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg18548.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
6 years agot_net.sh: make bash dep explicit and run only if SITNL is compiled
Antonio Quartulli [Sat, 15 Jun 2019 23:02:12 +0000 (01:02 +0200)] 
t_net.sh: make bash dep explicit and run only if SITNL is compiled

The t_net script currently has #!/bin/sh but it implicitly assume to
be using bash.
This is fine on most distros, but some do not have sh pointing to bash
by default, thus breaking the script.
Explicitly use bash to avoid failures.

On the other hand, run this unit-test only if SITNL was enabled at
compile time. This test was designed with SITNL in mind and it is
not yet ready for other backends.

Running only when SITNL is enabled implies running on Linux only
therefore we are guaranteed that bash will always work.

While at it, also add a comment as of why the t_client.rc file is
sourced.

Signed-off-by: Antonio Quartulli <antonio@openvpn.net>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <20190615230213.14888-1-a@unstable.cc>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg18547.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
6 years agoCopy one byte less in strncpynt()
Gert Doering [Sat, 8 Jun 2019 07:56:22 +0000 (09:56 +0200)] 
Copy one byte less in strncpynt()

While the existing code is not wrong and will never cause an overflow,
it will copy (on a too-long source string) "maxlen" bytes to dest, and
then overwrite the last byte just copied with "0" - which causes a
warning in gcc 9 about filling the target buffer "up to the end,
with no room for a trailing 0 anymore".

Reducing the maximum bytes-to-be-copied to "maxlen -1", because the
last byte will be stamped with 0 anyway.

v2: do not ASSERT() on "maxlen == 0", but move the strncpy() call inside
the if() clause - so "just do nothing" on maxlen == 0, as before.

Signed-off-by: Gert Doering <gert@greenie.muc.de>
Acked-by: Antonio Quartulli <antonio@openvpn.net>
Message-Id: <20190608075622.11589-1-gert@greenie.muc.de>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg18502.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
6 years agoWrite key to stdout if filename is not given
Arne Schwabe [Fri, 10 May 2019 12:11:08 +0000 (14:11 +0200)] 
Write key to stdout if filename is not given

This change is preperation for changing the way --genkey works.
Acked-by: David Sommerseth <davids@openvpn.net>
Message-Id: <20190510121114.30468-2-arne@rfc2549.org>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg18445.html

Signed-off-by: Gert Doering <gert@greenie.muc.de>
6 years agounit tests: implement test for sitnl
Antonio Quartulli [Wed, 19 Dec 2018 05:01:17 +0000 (15:01 +1000)] 
unit tests: implement test for sitnl

This patch introduces a new unit test that is not executed
by the cmocka framework, but rather used by a new t_net.sh
bash script.

The idea behind this test is to ensure that invoking sitnl
functions or running iproute commands leads to the same
networking (interface and routing table) state.

To achieve this, the t_net.sh script first runs a binary
implemented invoking sitnl functions and then takes a
"screenshot" of the state. Subsequently a series of
iproute commands, expected to mimic exactly the same behaviour
as the sitnl functions invoked before, are executed.
The final state is then compared with the screenshot
previously taken.

If no mismatching is found, the test is passed.

The current unit_test, however, does not cover all the
sitnl functionalities and it is expected to be extended
in the future.

Signed-off-by: Antonio Quartulli <a@unstable.cc>
Acked-by: Arne Schwabe <arne@rfc2549.org>
Message-Id: <20181219050118.6568-7-a@unstable.cc>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg18027.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
6 years agoroute.c: use new networking API to handle routing table on Linux
Antonio Quartulli [Wed, 19 Dec 2018 05:01:15 +0000 (15:01 +1000)] 
route.c: use new networking API to handle routing table on Linux

By switching to the networking API (for Linux) openvpn will
now use any of the available implementations to handle the
routing table.

At the moment only iproute2 is implemented.

Signed-off-by: Antonio Quartulli <a@unstable.cc>
Acked-by: Arne Schwabe <arne@rfc2549.org>
Message-Id: <20181219050118.6568-5-a@unstable.cc>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg18029.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
6 years agotravis.yml: add test for iproute2 net implementation
Antonio Quartulli [Wed, 19 Dec 2018 05:01:18 +0000 (15:01 +1000)] 
travis.yml: add test for iproute2 net implementation

Signed-off-by: Antonio Quartulli <a@unstable.cc>
Acked-by: Arne Schwabe <arne@rfc2549.org>
Message-Id: <20181219050118.6568-8-a@unstable.cc>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg18032.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
6 years agotun.c: use new networking API to handle tun interface on Linux
Antonio Quartulli [Wed, 19 Dec 2018 05:01:14 +0000 (15:01 +1000)] 
tun.c: use new networking API to handle tun interface on Linux

By switching to the networking API (for Linux) openvpn will
now use any of the available implementations to handle the tun
interface.

At the moment only iproute2 and sitnl (NetLink) is implemented.

Signed-off-by: Antonio Quartulli <a@unstable.cc>
Acked-by: Arne Schwabe <arne@rfc2549.org>
Message-Id: <20181219050118.6568-4-a@unstable.cc>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg18028.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
6 years agointroduce sitnl: Simplified Interface To NetLink
Antonio Quartulli [Wed, 19 Dec 2018 05:01:13 +0000 (15:01 +1000)] 
introduce sitnl: Simplified Interface To NetLink

This patch introduces a tiny netlink interface, optimized
for the openvpn use case.

It basically exposes all those operations that are currently
handled by directly calling the /sbin/ip command (or even
ifconfig/route, if configured).

By using netlink, openvpn won't need to spawn new processes
when configuring the tun interface or routes.
This new approach will also allow openvpn to be granted
CAP_NET_ADMIN and be able to properly work even though it
dropped the root privileges (currently handled via workarounds).

By moving this logic into the sitnl module, tun.c and route.c
also benefit from some code simplification

Signed-off-by: Antonio Quartulli <a@unstable.cc>
Acked-by: Arne Schwabe <arne@rfc2549.org>
Message-Id: <20181219050118.6568-3-a@unstable.cc>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg18030.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
6 years agoFix poll.h logic in syshead.h
Arne Schwabe [Fri, 24 May 2019 09:02:36 +0000 (11:02 +0200)] 
Fix poll.h logic in syshead.h

Commit 62063162 change the include from sys/poll.h to just poll.h but
forgot to also change all occurrences of HAVE_SYS_POLL_H to HAVE_POLL_H.
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <20190524090236.10760-1-arne@rfc2549.org>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg18475.html

Signed-off-by: Gert Doering <gert@greenie.muc.de>
6 years agoimplement networking API for iproute2
Antonio Quartulli [Wed, 19 Dec 2018 05:01:12 +0000 (15:01 +1000)] 
implement networking API for iproute2

iproute2 is the first user of the new networking API and
its one of the two currently supported functionalities on
Linux (the other being net-tools).

This patch simply copies the current code from tun.c/route.c
to networking_iproute2.c without introducing any funcional
change to the code.

Signed-off-by: Antonio Quartulli <a@unstable.cc>
Acked-by: Arne Schwabe <arne@rfc2549.org>
Message-Id: <20181219050118.6568-2-a@unstable.cc>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg18031.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
6 years agoimplement platform generic networking API
Antonio Quartulli [Tue, 14 May 2019 08:11:59 +0000 (10:11 +0200)] 
implement platform generic networking API

tun.c and route.c contain all the code used by openvpn
to manage the tun interface and the routing table on all
the supported platforms.

Across the years, this resulted in a longer functions
and series of ifdefs.

This patch introduces a new "networking API" which aims at
creating a simple abstraction between the tun/route logic
and the platform dependent code.

The is API expected to be implemented outside of tun.c/route.c
by using platform specific functionalities.

Signed-off-by: Antonio Quartulli <a@unstable.cc>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <20190514081159.12192-1-a@unstable.cc>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg18458.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
6 years agoFix various compiler warnings
Lev Stipakov [Tue, 30 Oct 2018 08:53:35 +0000 (10:53 +0200)] 
Fix various compiler warnings

This patch fixes "unused variable/unreferenced format parameter"
warnings in different places, kudos to Visual Studio compiler
for discoveing some of those.

This also also removes unneeded uninit_management_callback_multi()
wrapper.

Signed-off-by: Lev Stipakov <lev@openvpn.net>
Acked-by: Arne Schwabe <arne@rfc2549.org>
Message-Id: <1540889615-24868-1-git-send-email-lstipakov@gmail.com>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg17855.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
6 years agotests: remove dependency on base64
Steffan Karger [Wed, 8 May 2019 13:52:20 +0000 (15:52 +0200)] 
tests: remove dependency on base64

Triggered by the report from Ilya, that if base64 is missing, the tests
would still report success:

  Testing tls-crypt-v2 key generation (max length
metadata)..../t_lpback.sh: base64: not found
  OK
  PASS: t_lpback.sh

The easiest way to fix that, is to remove the dependency on base64 (which
is it's current form wouldn't work on OSX anyway, because their base64
doesn't understand "-w0").

Signed-off-by: Steffan Karger <steffan.karger@fox-it.com>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <E1hON0G-0007yB-3H@sfs-ml-4.v29.lw.sourceforge.com>
URL: https://www.mail-archive.com/search?l=mid&q=E1hON0G-0007yB-3H@sfs-ml-4.v29.lw.sourceforge.com
Signed-off-by: Gert Doering <gert@greenie.muc.de>
6 years agobuild: Package missing mock_msg.h
David Sommerseth [Wed, 17 Apr 2019 20:30:15 +0000 (22:30 +0200)] 
build: Package missing mock_msg.h

The mock_msg.h file was not enlisted in the _SOURCES lists in
Makefile.am for the unit tests.  This caused the mock_msg.h file to not
be present in the .tar.gz file created by 'make dist'.

This was not noticed earlier as we haven't really tried much to run git
clone of the cmocka project manually in vendor/ from an unpacked
tarball.

With this fix the cmocka unit tests can also run from tarballs, with
manually extracting/fetching the cmocka source code in vendor/cmocka.

Signed-off-by: David Sommerseth <davids@openvpn.net>
----8<----8<----8<----8<----8<----8<----8<----8<----8<----8<----8<----

How to test:

- Create a tarball: make distcheck (or just 'dist')
- Extract openvpn-2.5_git.tar.gz in a clean directory
- cd openvpn-2.5_git/vendor
- git clone https://git.cryptomilk.org/projects/cmocka.git
- ./configure
- make check
- Observe that the cmocka unit tests ran as expected

Depending on the CMake version, you might want to check out cmocka git
commit b2732b52202ae48f; which is the one we use in the git submodule.
Acked-by: Steffan Karger <steffan.karger@fox-it.com>
Message-Id: <20190417203015.1903-1-davids@openvpn.net>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg18380.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
6 years agocmocka: use relative paths
Steffan Karger [Sun, 28 Oct 2018 14:54:49 +0000 (15:54 +0100)] 
cmocka: use relative paths

Simplifies the build scripts, and fixes my CI, where paths on the test
slave can be different from paths on the build slave.

Signed-off-by: Steffan Karger <steffan@karger.me>
Acked-by: David Sommerseth <davids@openvpn.net>
Message-Id: <20181028145449.12676-1-steffan@karger.me>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg17849.html
Signed-off-by: David Sommerseth <davids@openvpn.net>
6 years agoRemove wrong poll.h include
Rosen Penev [Wed, 3 Apr 2019 22:57:40 +0000 (15:57 -0700)] 
Remove wrong poll.h include

musl reports:

warning redirecting incorrect #include <sys/poll.h> to <poll.h>

Signed-off-by: Rosen Penev <rosenp@gmail.com>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <20190403225740.8285-1-rosenp@gmail.com>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg18336.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
6 years agoconfigure.ac: fix compile-time error in argv_testdriver
Ilya Shipitsin [Thu, 11 Apr 2019 07:45:19 +0000 (12:45 +0500)] 
configure.ac: fix compile-time error in argv_testdriver

allow run tests when lzo is installed to non default directory
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <20190411074519.9982-2-chipitsine@gmail.com>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg18357.html

Signed-off-by: Gert Doering <gert@greenie.muc.de>
6 years agodocs: Update INSTALL
David Sommerseth [Wed, 27 Mar 2019 12:06:04 +0000 (13:06 +0100)] 
docs: Update INSTALL

The INSTALL file contained several minor errors, typos and was generally
not up-to-date in regards to what ./configure provides today.  In
addition, several URL references have moved around to new homes.

Signed-off-by: David Sommerseth <davids@openvpn.net>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <20190327120604.21101-1-davids@openvpn.net>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg18307.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
6 years agotravis-ci: update osx to xcode9.4 and modernize brew management
Ilya Shipitsin [Mon, 11 Mar 2019 13:36:20 +0000 (18:36 +0500)] 
travis-ci: update osx to xcode9.4 and modernize brew management

osx image used for builds, i.e. xcode7.3 is outdated, we
can switch to "default" xcode9.4 and use more fast brew
travis-ci plugin

Signed-off-by: Ilya Shipitsin <chipitsine@gmail.com>
Acked-by: Steffan Karger <steffan.karger@fox-it.com>
Message-Id: <20190311133620.18278-4-chipitsine@gmail.com>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg18269.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>