]> git.ipfire.org Git - thirdparty/openvpn.git/log
thirdparty/openvpn.git
16 months agopreparing release 2.6.0 v2.6.0
Gert Doering [Wed, 25 Jan 2023 09:30:09 +0000 (10:30 +0100)] 
preparing release 2.6.0

version.m4, ChangeLog, Changes.rst

Signed-off-by: Gert Doering <gert@greenie.muc.de>
16 months agodco_linux: update license for ovpn_dco_linux.h
Antonio Quartulli [Wed, 25 Jan 2023 09:53:21 +0000 (10:53 +0100)] 
dco_linux: update license for ovpn_dco_linux.h

The linux userspace API header has acquired the MIT license (check the
ovpn-dco repository for the related change), therefore we simply bring
this change in our local copy to ensure compliancy.

Signed-off-by: Antonio Quartulli <a@unstable.cc>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <20230125095321.23063-1-a@unstable.cc>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg26077.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
(cherry picked from commit 537cde6b8fa7d35414df715678e2cd22ab79a881)

16 months agoopenvpnmsica: fix adapters discovery logic for DCO
Lev Stipakov [Tue, 24 Jan 2023 14:23:16 +0000 (16:23 +0200)] 
openvpnmsica: fix adapters discovery logic for DCO

Custom action "FindSystemInfo" finds adapters with certain hwid and
assigns found adapters' guids to a certain property. Later another custom
action "EvaluateTUNTAPAdapters" schedules adapter creation if the
abovementioned property is not set - which means no adapters exist
with given hwid.

I think this logic is needed to prevent duplicate adapter creation
if adapter was renamed and then new version is installed.

As one can see, there is a typo in property name ("OVPNDCOAPTERS"). As
a result of this typo, installer will always try to create DCO adapter
no matter if there are existing adapters. It however won't do anything
if adapter with the name "OpenVPN Data Channel Offload" already exists,
this is handled in schedule_adapter_create() function.

Because of that typo, following scenario works fine:

 1) Upcoming release of OpenVPN Connect is installed, which creates
adapter named "OpenVPN Connect DCO Adapter"

 2) OpenVPN-GUI is installed. Because of typo, it ignores adapter created
by Connect and creates own "OpenVPN Data Channel Offload" adapter

 3) OpenVPN Connect is uninstalled and it removes
"OpenVPN Connect DCO Adapter".

 4) OpenVPN-GUI still has its "OpenVPN Data Channel Offload" adapter

If we just fix a typo, OpenVPN-GUI won't create a adapter on step 2 and
after Connect removal on step 3 there won't be DCO adapters anymore
for OpenVPN-GUI to use.

The ultimate solution to this would be moving adapter creation to MSM,
a shared component which adds/removes the DCO driver. However this change
is not trivial and requires a lot of work. For the time being we apply
this band-aid by excluding Connect-created adapters from enumerations in
"FindSystemInfo" custom action. This makes sure that OpenVPN-GUI won't
rely on adapter created by Connnect (which is deleted on Connect uninstall)
and ensures that additional DCO adapters won't be created on upgrade
if user decides to rename adapter.

Signed-off-by: Lev Stipakov <lev@openvpn.net>
Acked-by: Selva Nair <selva.nair@gmail.com>
Message-Id: <20230124142316.441-1-lstipakov@gmail.com>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg26072.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
(cherry picked from commit 7a23a7dda27349f7c7fd7af2ed1380ede1becf06)

16 months agoopenvpnmsica: remove unused declarations
Lev Stipakov [Tue, 24 Jan 2023 09:14:41 +0000 (11:14 +0200)] 
openvpnmsica: remove unused declarations

That code has been moved to MSM by commit 640c4d82
("openvpnmsica: remove dco installer custom actions")

Signed-off-by: Lev Stipakov <lev@openvpn.net>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <20230124091441.397-1-lstipakov@gmail.com>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg26070.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
(cherry picked from commit 6effd9197cdbadedc19bb5e3254a1178697513ce)

16 months agoFix one more 'existing route may get deleted' case
Selva Nair [Sat, 21 Jan 2023 19:42:26 +0000 (14:42 -0500)] 
Fix one more 'existing route may get deleted' case

- Ensure net_route_v4/v6_add/del() functions using iproute2 return
  error when route addition fails. Return value follows the same logic
  as corresponding functions using netlink though all failure reasons
  get the same error code of -1.

TODO: Preserve any preexisting direct route to VPN and optionally the
IPv6 connected net route.

v2: Following review, removed the poorly coded RL_DID_LOCAL-related chunks.
That part needs a better fix.

Signed-off-by: Selva Nair <selva.nair@gmail.com>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <20230121194226.2081637-1-selva.nair@gmail.com>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg26067.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
(cherry picked from commit 00fac39c58a7d5c8fa6d8f40232e9ab79f3fa9e0)

16 months agoCleanup route error and debug logging on Windows
Selva Nair [Fri, 20 Jan 2023 09:41:00 +0000 (04:41 -0500)] 
Cleanup route error and debug logging on Windows

Use a unified logging format for various route-methods

- Route add/delete errors are always logged with M_WARN, so
  log only additional information (succeed/exists) with D_ROUTE.

- Non-windows platforms log route errors with a prefix "ERROR:" and
  debug info with "ROUTE:". Do the same on Windows. Do not log
  errors or success multiple times.

- In add_route_ipv6, log the interface id instead of device name
  as the latter always point to the tun/tap adapter name on Windows.

Log lines prefixed with a PACKAGE_NAME "ROUTE" are unchanged.
They appear to use the same format on all platforms.

v2: rebase to master

Signed-off-by: Selva Nair <selva.nair@gmail.com>
Acked-by: Lev Stipakov <lstipakov@gmail.com>
Message-Id: <20230120094100.2063883-1-selva.nair@gmail.com>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg26058.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
(cherry picked from commit a45c201e2edcf5ccb6baea0a03145023db7f222b)

16 months agoWarn when pkcs11-id or pkcs11-id-management options are ignored
Selva Nair [Fri, 20 Jan 2023 02:18:41 +0000 (21:18 -0500)] 
Warn when pkcs11-id or pkcs11-id-management options are ignored

- If there are no pkcs11-providers either directly specified or
  through p11-kit-proxy made available through a build-time detection,
  these options are ignored. Log a warning in such cases.

  Especially important on Windows where automatic loading of p11-kit
  is not enabled in our release builds.

- Document this behaviour.

Signed-off-by: Selva Nair <selva.nair@gmail.com>
Acked-by: Frank Lichtenheld <frank@lichtenheld.com>
Message-Id: <20230120021841.2048791-1-selva.nair@gmail.com>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg26056.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
(cherry picked from commit abad04fc8ef6c1da7dc4e976bacee9f34931adea)

16 months agoopenvpnmsica: remove dco installer custom actions
Lev Stipakov [Thu, 19 Jan 2023 08:59:59 +0000 (10:59 +0200)] 
openvpnmsica: remove dco installer custom actions

Those have been moved into MSM to be reused by openvpn-gui and Connect.

Signed-off-by: Lev Stipakov <lev@openvpn.net>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <20230119085959.157-1-lstipakov@gmail.com>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg26053.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
(cherry picked from commit 7217c7137ef835eb70a3e0c0fcf1cbdf3d5f65b2)

16 months agoWorkaround: make ovpn-dco more reliable
Arne Schwabe [Thu, 12 Jan 2023 16:37:37 +0000 (17:37 +0100)] 
Workaround: make ovpn-dco more reliable

This workaround avoids the kernel trigger ENOBUFS when the kernel
internal queue is overrun with events of disconnectingh clients or
similar. This is a workaround until we come up with a more permanent
solution.

Signed-off-by: Arne Schwabe <arne@rfc2549.org>
Acked-by: Antonio Quartulli <antonio@openvpn.net>
Message-Id: <20230112163737.1240059-1-arne@rfc2549.org>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg25988.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
(cherry picked from commit f84a9fc5d4ac0f24912d239a3fccf3701926a50c)

16 months agoDon't clear capability bounding set on capng_change_id
Timo Rothenpieler [Wed, 18 Jan 2023 14:24:28 +0000 (15:24 +0100)] 
Don't clear capability bounding set on capng_change_id

The bounding set being empty will overpower the likes of su/sudo
and will make it impossible for any child processes to ever gain
additional privileges again.

Github: fixes OpenVPN/openvpn#220

Signed-off-by: Timo Rothenpieler <timo@rothenpieler.org>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <20230118142428.162-1-timo@rothenpieler.org>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg26048.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
(cherry picked from commit d8523119b95db55d2c101b8364ce7e9d0d0f6f3a)

16 months agoRepair special-casing of EEXIST for Linux/SITNL route install
Gert Doering [Wed, 18 Jan 2023 07:46:33 +0000 (08:46 +0100)] 
Repair special-casing of EEXIST for Linux/SITNL route install

The code in sitnl_route_set() used to treat "route can not be installed
because it already exists" (EEXIST) as "not an error".

This is arguably a reasonable approach, but needs to handled higher
up - if the low level add_route() function say "no error", we will try
to remove that route later on in delete_route(), possibly removing
someone else's "already existing" route then.

So:
 - remove special case in sitnl_route_set()
 - do not pass NLM_F_REPLACE flag to sitnl_route_set() call - this would
   cause netlink to just replace existing routes, never return EEXIST
   (see "man netlink(7)")
 - add detailed return code handling to add_route(), assign "2" on
"-EEXIST"
   (and log appropriate message).

(Note: sitnl_route_set() is a common function for sitnl route add and
delete, but EEXIST can not happen on delete - so this change has no
impact for the "delete" case)

v2: use RTA_ macros, also adjust add_route_ipv6()

Signed-off-by: Gert Doering <gert@greenie.muc.de>
Acked-by: Selva Nair <selva.nair@gmail.com>
Message-Id: <20230118074633.27586-1-gert@greenie.muc.de>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg26046.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
(cherry picked from commit adc54f483b210484ff1488e01c8aee1b2b0ea477)

16 months agoDefine and use macros for route addition status code
Selva Nair [Sun, 15 Jan 2023 16:48:18 +0000 (11:48 -0500)] 
Define and use macros for route addition status code

- Instead of 0, 1, 2 use RTA_ERROR, RTA_SUCCESS, RTA_EEXIST
  as the return code of route addition functions.

- Also fix a logging error: status -> (status == RTA_SUCCESS)

v2: fold long lines
    use "bool ret = .." pattern for android too
    fix two more lines where status was directly assigned to bool

Signed-off-by: Selva Nair <selva.nair@gmail.com>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <20230115164818.1973210-1-selva.nair@gmail.com>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg26041.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
(cherry picked from commit 328cc40c8368a9e1f9abc92eb4d34687470e3a92)

16 months agoFix OVPN_DEL_PEER_REASON_TRANSPORT_DISCONNECT breakage on FreeBSD+DCO
Gert Doering [Fri, 13 Jan 2023 08:07:45 +0000 (09:07 +0100)] 
Fix OVPN_DEL_PEER_REASON_TRANSPORT_DISCONNECT breakage on FreeBSD+DCO

commit 67c4eebdae introduces a new peer disconnect reason (transport
disconnected, aka "TCP session closed") which breaks compilation on
FreeBSD - OVPN_DEL_PEER_REASON_TRANSPORT_DISCONNECT not part of the
enum in freebsd_dco.h, and no kernel support for TCP anyway.

This patch is an intermediate bandaid, making the offending code in
multi.c "linux only" while a better solution is discussed.

Signed-off-by: Gert Doering <gert@greenie.muc.de>
Acked-by: Antonio Quartulli <antonio@openvpn.net>
Message-Id: <20230113080745.82783-1-gert@greenie.muc.de>
URL: https://www.mail-archive.com/search?l=mid&q=20230113080745.82783-1-gert@greenie.muc.de
Signed-off-by: Gert Doering <gert@greenie.muc.de>
(cherry picked from commit cf545d603ecd9fbacc6bd519efaa92d60f944287)

16 months agopreparing release 2.6_rc2 v2.6_rc2
Gert Doering [Wed, 11 Jan 2023 15:18:01 +0000 (16:18 +0100)] 
preparing release 2.6_rc2

version.m4, ChangeLog, Changes.rst

Signed-off-by: Gert Doering <gert@greenie.muc.de>
16 months agodco: print proper message in case of transport disconnection
Antonio Quartulli [Wed, 11 Jan 2023 23:50:52 +0000 (00:50 +0100)] 
dco: print proper message in case of transport disconnection

Signed-off-by: Antonio Quartulli <a@unstable.cc>
Acked-by: Lev Stipakov <lstipakov@gmail.com>
Message-Id: <20230111235052.24855-1-a@unstable.cc>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg25977.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
(cherry picked from commit 67c4eebdaee5b51aa041ee7ed9f697397c04a01f)

16 months agoDeprecate OCC checking
Arne Schwabe [Wed, 11 Jan 2023 13:44:39 +0000 (14:44 +0100)] 
Deprecate OCC checking

- Move OCC warnings to debug level. This moves the only useful OCC message
  of compress-migrate to D_PUSH
- remove configure option --enable-strict-options
- ignore disable-occ in TLS mode as it is logged under debug now only
  disable-occ is now strictly a non-TLS option
- mark opt-verify and disable-occ as deprecated.

Patch v2: change one missed M_WARN to D_OCC

Signed-off-by: Arne Schwabe <arne@rfc2549.org>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <20230111134439.1107915-1-arne@rfc2549.org>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg25970.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
(cherry picked from commit 2104ea62430e4d203f2cd998e053f4192798b9f1)

16 months agodocumentation: update 'unsupported options' section
Frank Lichtenheld [Wed, 11 Jan 2023 12:52:42 +0000 (13:52 +0100)] 
documentation: update 'unsupported options' section

We listed those in Changes, but did not update the documentation.

Signed-off-by: Frank Lichtenheld <frank@lichtenheld.com>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <20230111125242.21025-1-frank@lichtenheld.com>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg25968.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
(cherry picked from commit ee0a6026af9c47fe21217f57ab04b9cc2cc193f1)

16 months agocheck_engine_keys: make pass with OpenSSL 3
Frank Lichtenheld [Tue, 10 Jan 2023 17:02:57 +0000 (18:02 +0100)] 
check_engine_keys: make pass with OpenSSL 3

Not enabled by default with OpenSSL 3, so we don't
see this in our builds.
While here add missing entries to .gitignore (which
is what made me look at engine-key test in the first
place).

Signed-off-by: Frank Lichtenheld <frank@lichtenheld.com>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <20230110170257.113527-1-frank@lichtenheld.com>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg25949.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
(cherry picked from commit af25448ee19da5d225a6a1f30f26dc3949ed8921)

16 months agooptions: Always define options->management_flags
Frank Lichtenheld [Sun, 27 Nov 2022 14:25:06 +0000 (15:25 +0100)] 
options: Always define options->management_flags

That makes it possible to remove several preprocessor
directives which is a good thing. The cost should be
negligible.

Signed-off-by: Frank Lichtenheld <frank@lichtenheld.com>
Acked-by: Arne Schwabe <arne@rfc2549.org>
Message-Id: <20221127142506.41986-1-frank@lichtenheld.com>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg25554.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
(cherry picked from commit ff7d7989e007a8c66fba438a257c1b85e8bcca69)

16 months agoInclude CE_DISABLED status of remote in "remote-entry-get" response
Selva Nair [Wed, 11 Jan 2023 06:29:10 +0000 (01:29 -0500)] 
Include CE_DISABLED status of remote in "remote-entry-get" response

- The response to the management command "remote-entry-get" is
  amended to include the status of the remote entry. The status
  reads "disabled" if (ce->flag & DISABLED) is true, "enabled"
  otherwise.

- Update and correct the description of this option in
  management-notes.txt

  Example responses:
  In response to "remote-entry-get 0"

  0,vpn.example.com,udp,enabled
  END

  Or, in response to "remote-entry-get all"

  0,vpn.example.org,udp,enabled
  1,vpn.example.com,udp,enabled
  2,vpn.example.net,tcp-client,disabled
  END

This helps the management client to show only enabled remotes
to the user.
An alternative would require the  UI/GUI to have knowledge of
what makes the daemon set CE_DISABLED (--proto-force,
--htttp-proxy-override etc.).

Signed-off-by: Selva Nair <selva.nair@gmail.com>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <20230111062910.1846688-1-selva.nair@gmail.com>
URL: https://www.mail-archive.com/search?l=mid&q=20230111062910.1846688-1-selva.nair@gmail.com
Signed-off-by: Gert Doering <gert@greenie.muc.de>
(cherry picked from commit eafbedc583c48fd46405fa0d635c688ce59c3733)

16 months agoxkey_pkcs11h_sign: fix dangling pointer
Frank Lichtenheld [Tue, 10 Jan 2023 13:19:47 +0000 (14:19 +0100)] 
xkey_pkcs11h_sign: fix dangling pointer

Warning by GCC 12:
pkcs11_openssl.c:237:22: warning:
dangling pointer ‘tbs’ to ‘enc’ may be used [-Wdangling-pointer=]

Signed-off-by: Frank Lichtenheld <frank@lichtenheld.com>
Acked-by: Selva Nair <selva.nair@gmail.com>
Message-Id: <20230110131947.59552-1-frank@lichtenheld.com>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg25942.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
(cherry picked from commit 202b34da386c8574692111bad23814602d0e09f5)

16 months agoUpdate copyright year to 2023
Frank Lichtenheld [Tue, 10 Jan 2023 16:05:31 +0000 (17:05 +0100)] 
Update copyright year to 2023

Manually excluded ovpn_dco_win.h because it is an
imported file. ovpn_dco_linux.h is already excluded
because it still says 2021.

Signed-off-by: Frank Lichtenheld <frank@lichtenheld.com>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <20230110160531.81010-1-frank@lichtenheld.com>
URL: https://patchwork.openvpn.net/project/openvpn2/patch/20230110160531.81010-1-frank@lichtenheld.com/
Signed-off-by: Gert Doering <gert@greenie.muc.de>
(cherry picked from commit ccf9d57249acb9bc9a450aec3e613bda631415f5)

16 months agoLog peer-id if loglevel is D_DCO_DEBUG and dco is enabled
Arne Schwabe [Tue, 10 Jan 2023 15:19:01 +0000 (16:19 +0100)] 
Log peer-id if loglevel is D_DCO_DEBUG and dco is enabled

This enables logging the peer id in p2mp mode if dco is enabled
and the log level is high enough

Patch v2: use check_debug_level to check current log level

Signed-off-by: Arne Schwabe <arne@rfc2549.org>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <20230110151901.998479-1-arne@rfc2549.org>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg25946.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
(cherry picked from commit 533c170fb60882547152e3b3222c8f7788d6b80f)

16 months agoReduce logspam about 'dco_update_keys: peer_id=-1' in p2p server mode
Gert Doering [Mon, 9 Jan 2023 20:00:11 +0000 (21:00 +0100)] 
Reduce logspam about 'dco_update_keys: peer_id=-1' in p2p server mode

p2p --tls-server with no active client/peer logs once per second

  "dco_update_keys: peer_id=-1"

which does exactly nothing, except fill the disk.  So skip the call to
dco_update_keys() if peer_id == -1.

Signed-off-by: Gert Doering <gert@greenie.muc.de>
Acked-by: Antonio Quartulli <a@unstable.cc>
Message-Id: <20230109200011.2525342-1-gert@greenie.muc.de>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg25935.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
(cherry picked from commit 85e0df6b493396d9d1d9030c4018f67037d2f12b)

16 months agoPropagate route error to initialization_completed()
Selva Nair [Thu, 5 Jan 2023 02:27:18 +0000 (21:27 -0500)] 
Propagate route error to initialization_completed()

Makes it possible to report management state as CONNECTED,ROUTE_ERROR
instead of CONNECTED,SUCCESS in case of routing errors.

This depends on treating "route already exists" as not
an error which right now works when using netlink on Linux
and IPAPI or iservice on Windows.

For route set via command line there is no easy way to get this
information and current behaviour is unchanged: i.e., the management
state continues to be reported as CONNECTED,SUCCESS.

Status notification to systemd is not affected.

To test on Linux, build with netlink and use a --route option with
an unreachable gateway like:
"--route 192.168.122.0 255.255.255.0 1.1.1.1"

Notes:
On windows, if the route method is "exe", setting a route
that exists *may* get logged as error and this patch will lead to
a slightly misleading CONNECTED,ROUTE_ERROR state message. This is
considered tolerable as no one should be using "exe" (i.e. route.exe)
as the route method.

Signed-off-by: Selva Nair <selva.nair@gmail.com>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <20230105022718.1641751-3-selva.nair@gmail.com>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg25884.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
(cherry picked from commit e04c253618ce2a1bb0996a67b81af891e8607fa9)

16 months agoAdd connect-freq-initial option to limit initial connection responses
Arne Schwabe [Tue, 10 Jan 2023 01:59:01 +0000 (02:59 +0100)] 
Add connect-freq-initial option to limit initial connection responses

This limits the number of packets OpenVPN will respond to. This avoids
OpenVPN servers being abused for refelection attacks in a large scale
as we gotten a lot more efficient with the cookie approach in our
initial connection handling.

The defaults of 100 attempts per 10s should work for most people,
esepcially since completed three way handshakes are not counted. So
the default will throttle connection attempts on server with high packet
loss or that are actually under a DOS.

The 100 per 10s are similar in size to the old 2.5 and earlier behaviour
where every initial connection attempt would take up a slot of the
max-clients sessions and those would only expire after the TLS timeout.
This roughly translates to 1024 connection attempts in 60s on an
empty server.

OpenVPN will announce once per period when starting to drop packets and
ultimatively how many packets it dropped:

    Connection Attempt Note: --connect-freq-initial 100 10 rate limit
    exceeded, dropping initial handshake packets for the next 10 seconds

    Connection Attempt Dropped 217 initial handshake packets due to
    --connect-freq-initial 100 10

to inform an admin about the consequences of this feature.

Patch v2: use strtol instead of atoi to be able to differentiate between
          an error parsing and parsing 0. Use int64_t instead int to
          avoid overflow errors.

Patch v3: Add message when we start dropping. Add a few fixes to the logic.
          improve docs

Patch v4: missing missing return statement.
Patch v5: add build files for msvc build

Signed-off-by: Arne Schwabe <arne@rfc2549.org>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <20230110015901.933522-1-arne@rfc2549.org>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg25938.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
(cherry picked from commit b520c68c67b6e52cd71b16675f1c436abf18d4dc)

16 months agoUndo FreeBSD 12.x workaround on IPv6 ifconfig for 12.4 and up
Gert Doering [Sat, 7 Jan 2023 16:25:58 +0000 (17:25 +0100)] 
Undo FreeBSD 12.x workaround on IPv6 ifconfig for 12.4 and up

commit 5e19cc2c1bf22d introduced a workaround for a race condition
that showed itself on IPv6 ifconfig on FreeBSD 12.x - sometimes breaking
IPv6 connectivity on tun/tap interfaces.

This was fixed on the FreeBSD side in 12.4, 13.1 and up, and 13.0 is
no longer supported.  So conditionalize the workaround on "12.0..12.3",
to be fully removed later when 12.3 is also running out of support.

v2: fix version number comparison

Trac: 1226

Signed-off-by: Gert Doering <gert@greenie.muc.de>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <20230107162558.59659-1-gert@greenie.muc.de>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg25911.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
(cherry picked from commit 16d7f2cd4d904274580b2f031e92dde2f7f260c9)

16 months agoDistinguish route addition errors from route already exists
Selva Nair [Fri, 6 Jan 2023 15:04:12 +0000 (10:04 -0500)] 
Distinguish route addition errors from route already exists

When possible, functions that add a route now return 1 on success,
or 2 if route already exists or 0 on other errors instead of true/false.

Note:
net_route_v4/v6_add using netlink filters out EEXIST before returning
this looks like a bug as add_route() and add_route_ipv6() should set
RT_ADDED only if route was really added.

v2: "succeeded/skipped" --> "succeeded" in log.

Signed-off-by: Selva Nair <selva.nair@gmail.com>
Acked-by: Lev Stipakov <lstipakov@gmail.com>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <20230106150412.1667492-1-selva.nair@gmail.com>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg25903.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
(cherry picked from commit 9c6d72c783f4212f965e1e855b4fdb0ea34b595b)

16 months agotun: move print_windows_driver() out of tun.h
Lev Stipakov [Mon, 9 Jan 2023 11:30:46 +0000 (13:30 +0200)] 
tun: move print_windows_driver() out of tun.h

We got warnings from MinGW about function being defined
but not used when compiling modules which include tun.h.

This function is not defined as inline, so its definition
should not be in header. Since this is not a performance
critical, no need to make it inline.

Leave declaration in tun.h and move definition to tun.c.

Github: fixes OpenVPN/openvpn#215

Signed-off-by: Lev Stipakov <lev@openvpn.net>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <20230109113046.1678-1-lstipakov@gmail.com>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg25923.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
(cherry picked from commit a0eb1f764df39d9447b666e5a2cbd3aa01b41983)

17 months agoAssign and honour signal priority order
Selva Nair [Sun, 1 Jan 2023 21:51:07 +0000 (16:51 -0500)] 
Assign and honour signal priority order

Signals are ordered as SIGUSR2, SIGUSR1, SIGHUP, SIGTERM, SIGINT
in increasing priority. Lower priority signals are not allowed to
overwrite higher ones.

This should fix Trac #311, #639 -- SIGTER/SIGINT lost during dns
resolution (except for the Windows-specific bug handled in previous commit).

On sending SIGTERM during dns resolution, it still takes several seconds
to terminate as the signal will get processed only after getaddrinfo times
out twice (in phase1 and phase2 inits).

Github: fixes OpenVPN/openvpn#205
Trac: #311, #639

Note: one has to still wait for address resolution to time out as
getaddrinfo() is no interruptible. But a single ctrl-C (and some
patience) is enough.

Signed-off-by: Selva Nair <selva.nair@gmail.com>
Acked-by: Arne Schwabe <arne@rfc2549.org>
Message-Id: <20230101215109.1521549-4-selva.nair@gmail.com>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg25871.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
(cherry picked from commit 3a7257925791a086c1ac88362a8eb422be518b14)

17 months agoFix signal handling on Windows
Selva Nair [Fri, 6 Jan 2023 00:54:38 +0000 (19:54 -0500)] 
Fix signal handling on Windows

- In win32_signal_get() re-order the check so that Windows
  signals are picked up even if signal_received is non-zero

- When management is not active, management_sleep() becomes sleep()
  but it is not interruptible by signals on Windows. Fix this by
  periodically checking for signal.

Trac: #311 #639 (windows specific part)
Github: Fixes OpenVPN/openvpn#205 (windows specific part)

Note: if stuck in address resolution, press ctrl-C and wait for
getaddrinfo() to timeout.

v2: WIN32 --> _WIN32
    add a chunk in management_sleep that was missed by sloppy
    conflict-resolution

v3: following review by Lev Stipakov <lstipakov@gmail.com>
  win32_sleep()
    - Early fallback to Sleep() if no wait handles -- less indentation
    - Check signal only if wait-object triggered
    - Exit the while loop if not safe to continue
  Behaviour of win32_sleep(0) checking signal is retained though may be
  redundant

v4: Avoid Sleep(0) and never loop back to wait again if wait-failed

Signed-off-by: Selva Nair <selva.nair@gmail.com>
Acked-by: Lev Stipakov <lstipakov@gmail.com>
Message-Id: <20230106005438.1664046-1-selva.nair@gmail.com>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg25895.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
(cherry picked from commit 22977577ed128ac953e7ebfe30f839bcf651b334)

17 months agoUse IPAPI for setting ipv6 routes when iservice not available
Selva Nair [Thu, 5 Jan 2023 02:27:16 +0000 (21:27 -0500)] 
Use IPAPI for setting ipv6 routes when iservice not available

Currently we use netsh for this. The new code closely follows
what interactive service does.

Signed-off-by: Selva Nair <selva.nair@gmail.com>
Acked-by: Lev Stipakov <lstipakov@gmail.com>
Message-Id: <20230105022718.1641751-1-selva.nair@gmail.com>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg25886.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
(cherry picked from commit dd66958198f7c4dcf7fca0db82ca72996100b3bd)

17 months agodco: improve comment about hidden debug message
Antonio Quartulli [Tue, 3 Jan 2023 20:23:30 +0000 (21:23 +0100)] 
dco: improve comment about hidden debug message

While at it also improve the debug message itself
to be more self-explanatory.

Signed-off-by: Antonio Quartulli <a@unstable.cc>
Acked-by: Arne Schwabe <arne@rfc2549.org>
Message-Id: <20230103202330.1835-3-a@unstable.cc>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg25883.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
(cherry picked from commit b20daf274304ee30daa839910e633c96307a4744)

17 months agodco: bail out when no peer-specific message is delivered
Antonio Quartulli [Tue, 3 Jan 2023 20:23:29 +0000 (21:23 +0100)] 
dco: bail out when no peer-specific message is delivered

multi_process_incoming_dco() is currently partly processing
messages that were actually discarded. This results in a bogus
message being printed:

"Received packet for peer-id unknown to OpenVPN: -1, type 0, reason 2"

Change the flow so that we bail out immediately when we know that no
message was truly delivered by DCO.
Currently this can be verified by chacking that the peed_is is greater
than -1.

Signed-off-by: Antonio Quartulli <a@unstable.cc>
Acked-by: Arne Schwabe <arne@rfc2549.org>
Message-Id: <20230103202330.1835-2-a@unstable.cc>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg25882.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
(cherry picked from commit 388e032019ec3674b8294c856039b96fe35e5f32)

17 months agodco: properly re-initialize dco_del_peer_reason
Antonio Quartulli [Tue, 3 Jan 2023 20:23:28 +0000 (21:23 +0100)] 
dco: properly re-initialize dco_del_peer_reason

After processing a message, all fields of the dco object should be
re-initialized so that future processings are not affected by stale
values.

This includes dco_del_peer_reason.

Since its values can start at 0, re-initialize it with -1.

Signed-off-by: Antonio Quartulli <a@unstable.cc>
Acked-by: Arne Schwabe <arne@rfc2549.org>
Message-Id: <20230103202330.1835-1-a@unstable.cc>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg25881.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
(cherry picked from commit e9889016fb7269d025a2dbba5f7079ee87e39520)

17 months agoRefactor signal handling in openvpn_getaddrinfo
Selva Nair [Sun, 1 Jan 2023 21:51:06 +0000 (16:51 -0500)] 
Refactor signal handling in openvpn_getaddrinfo

Pass in sig_info struct to use register signal instead of
modifying signal_received.

No functional changes though some may be warranted.
Questions:
  - Why are we overwriting SIGUSR1 in this function?
  - Why the special interrupted syscall treatment for getaddrinfo?
    Its not a syscall, is it?

Signed-off-by: Selva Nair <selva.nair@gmail.com>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <20230101215109.1521549-3-selva.nair@gmail.com>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg25872.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
(cherry picked from commit eff95d500481c7927c5a9edd6b5c0dfa056a0cbb)

17 months agoPreparing for better signal handling: some code refactoring
Selva Nair [Sun, 1 Jan 2023 21:51:05 +0000 (16:51 -0500)] 
Preparing for better signal handling: some code refactoring

- Do not directly update signal_received: always use register_signal()
  throw_signal() or signal_reset().
  To facilitate this, register_signal() now takes c->sig as an argument
  instead of the context c itself, and sig_info struct is passed-in to
  functions that need to set a signal.

- openvpn_getaddrinfo() is updated in a following commit as it
  could benefit from some logic changes that we may or may not want
  to do.

No functional changes.

TODO:
(i)   update signal handling in openvpn_getaddrinfo
(ii)  enforce signal priority
(iii) fix signal handling on Windows
for 2.7?
(iv)  replace system-V signal with POSIX sigaction

Signed-off-by: Selva Nair <selva.nair@gmail.com>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <20230101215109.1521549-2-selva.nair@gmail.com>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg25874.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
(cherry picked from commit 05715485b45816e18b52ffb9b47ca22a55abb334)

17 months agoCleanup: Close duplicated handles in interactive service
Selva Nair [Thu, 29 Dec 2022 18:27:39 +0000 (13:27 -0500)] 
Cleanup: Close duplicated handles in interactive service

Several handles from openvpn.exe are duplicated in the
service for registering ring buffer memory maps with the
driver. These handles are not required after registration,
as all access is through handles in openvpn.exe. Only the
map base address (send_ring, rceive_ring) need be retained
for later unmapping.

Use local variables for duplicated handles and close them
soon after use.

The struct ring_buffer_handles_t is renamed to ring_buffer_maps_t
as there are no handles in there any longer.

Signed-off-by: Selva Nair <selva.nair@gmail.com>
Acked-by: Lev Stipakov <lstipakov@gmail.com>
Message-Id: <20221229182739.1477336-2-selva.nair@gmail.com>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg25863.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
(cherry picked from commit a10564c71608dca6172a89dc458e6e23254d600b)

17 months agoUse undo_lists for saving ring-buffer handles in interactive service
Selva Nair [Thu, 29 Dec 2022 18:27:38 +0000 (13:27 -0500)] 
Use undo_lists for saving ring-buffer handles in interactive service

HandleRegisterRingBuffers() in interactive.c did not follow the
the original API of HandleMessage(): a new argument was added
to HandleMessage to pass-in prer-process ring-buffer handles. The
existing undo lists argument is meant for such use.

Rewrite following the original design.

Signed-off-by: Selva Nair <selva.nair@gmail.com>
Acked-by: Lev Stipakov <lstipakov@gmail.com>
Message-Id: <20221229182739.1477336-1-selva.nair@gmail.com>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg25864.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
(cherry picked from commit 6ea9cf8146b1d72aa6a4790bc3ac2b99562b2cac)

17 months agoProperly unmap ring buffer file-map in interactive service
Selva Nair [Thu, 29 Dec 2022 13:47:29 +0000 (08:47 -0500)] 
Properly unmap ring buffer file-map in interactive service

The return value of MapViewOfFile must be passed to UnmapViewofFile,
instead of the file handle.

Github: Fixes OpenVPN/openvpn#206

v2: move *ring = NULL inside if {}

Signed-off-by: Selva Nair <selva.nair@gmail.com>
Acked-by: Lev Stipakov <lstipakov@gmail.com>
Message-Id: <20221229134729.1474034-1-selva.nair@gmail.com>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg25859.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
(cherry picked from commit 64f8833e119e31cf01dfe198538fbb5566fabf8f)

17 months agooptions.c: update usage description of --cipher
Frank Lichtenheld [Wed, 28 Dec 2022 17:13:14 +0000 (18:13 +0100)] 
options.c: update usage description of --cipher

GCC with -O3 complains:
warning: ‘%s’ directive argument is null [-Wformat-overflow=]

And indeed:
--cipher alg    : Encrypt packets with cipher algorithm alg
                  (default=(null)).

Since there is no real default anymore, remove it.
While here also indicate the somewhat-deprecated status
of the option.

Signed-off-by: Frank Lichtenheld <frank@lichtenheld.com>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <20221228171314.133115-1-frank@lichtenheld.com>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg25851.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
(cherry picked from commit 4410daac5af8be778cb2dd2d45a44b5e67938496)

17 months agooptions.c: fix format security error when compiling without optimization
Frank Lichtenheld [Wed, 28 Dec 2022 11:07:52 +0000 (12:07 +0100)] 
options.c: fix format security error when compiling without optimization

error: format not a string literal and no format arguments
[-Werror=format-security]
 2309 |     msg(M_USAGE, str);

Found by accident, since it only happens without optimization.
Seems the compiler can figure out that this is harmless when
thinking a bit harder about it. Fix anyway.

Signed-off-by: Frank Lichtenheld <frank@lichtenheld.com>
Acked-by: Arne Schwabe <arne@rfc2549.org>
Message-Id: <20221228110752.34060-1-frank@lichtenheld.com>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg25848.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
(cherry picked from commit 24fc4ce25432a42170477f21133bb0f25a8a860d)

17 months agoPreparing release 2.6_rc1 v2.6_rc1
Gert Doering [Wed, 28 Dec 2022 10:44:57 +0000 (11:44 +0100)] 
Preparing release 2.6_rc1

version.m4, ChangeLog, Changes.rst

Signed-off-by: Gert Doering <gert@greenie.muc.de>
17 months agobandaid fix for TCP multipoint server crash with Linux-DCO
Gert Doering [Tue, 27 Dec 2022 20:26:14 +0000 (21:26 +0100)] 
bandaid fix for TCP multipoint server crash with Linux-DCO

TCP multipoint servers with Linux-DCO can crash under yet-unknown
circumstances where a TCP socket gets handed to the kernel (= userland
shall not acceess it again) but the socket still lands in the event
polling mechanism, and is passed to link_socket_read() with
sock->fd being "-1" (SOCKET_UNDEFINED).

This is a bug, but it happens very unfrequently so not fixed yet.

When this happens, the server gets stuck in an endless loop of
"trying recvfrom(-1, ..), getting an error, looging that error,
continue" until the server's disk is full.

The situation is being made a bit more complex by the dco-win
approach of treating "all kernel sockets as UDP", so the Linux
implementation tries to access the -1 socket as UDP, confusing
the picture more.

As a bandaid to avoid the crash, this patch changes

 - socket.h: only do the "if dco_installed, treat as UDP" for WIN32
   (link_socket_read())

 - socket.c: add ASSERT(sock->fd >= 0); checks to all UDP socket paths
   (we should never even hit those as this is a TCP specific problem,
   but in the "sock->fd = -1" case, doing a clean server abort is
   preferred to "the disk is full with non-helpful logfiles, and then
   the server crashes anyway")

 - socket.c: in the TCP read function, link_socket_read_tcp(),
   check for sock->fd < 0 and trigger "sock->stream_reset = true"
   (+ write to the log what happened).

This change will kill this particular TCP client instance (SIGTERM),
but leave the rest of the server running fine - and given that
in our tests this issue seems to be triggered by inbound TCP RST
in just the wrong moment, it seems to be "a properly-sized bandaid".

v2: rebase on top of "move dco_installed back to link_socket"
v3: move sock->fd check inside !residual_fully_formed clause (so
    we can still handle already-read packets)

Github: OpenVPN/openvpn#190

Signed-off-by: Gert Doering <gert@greenie.muc.de>
Acked-by: Arne Schwabe <arne@rfc2549.org>
Message-Id: <20221227202614.2114971-1-gert@greenie.muc.de>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg25844.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
(cherry picked from commit c7416160fb2e5a66d5801e4b789751a7480e6384)

17 months agoReplace realloc with new gc_realloc function
Arne Schwabe [Tue, 27 Dec 2022 14:02:45 +0000 (15:02 +0100)] 
Replace realloc with new gc_realloc function

The realloc logic has the problem that it relies on the memory being
deallocated by uninit_options rather than by freeing the gc. This
does not always happen in all code path. Especially the crypto selftest
run by make check will not call uninit_options.

This introduces a gc_realloc function that ensures that the pointer is
instead freed when gc_free is called.

Signed-off-by: Arne Schwabe <arne@rfc2549.org>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <20221227140249.3524943-2-arne@rfc2549.org>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg25829.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
(cherry picked from commit e7f2169772f90f9bf158a17f5656a6a985e74e31)

17 months agoReplace custom min macro and use more C99 style in man_remote_entry_get
Arne Schwabe [Tue, 27 Dec 2022 14:02:44 +0000 (15:02 +0100)] 
Replace custom min macro and use more C99 style in man_remote_entry_get

Signed-off-by: Arne Schwabe <arne@rfc2549.org>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <20221227140249.3524943-1-arne@rfc2549.org>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg25830.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
(cherry picked from commit 841524153fbdcd377065e221e91ef163d83b9cc9)

17 months agoIgnore OVPN_DEL_PEER_REASON_USERSPACE to avoid race conditions
Arne Schwabe [Tue, 27 Dec 2022 02:24:03 +0000 (03:24 +0100)] 
Ignore OVPN_DEL_PEER_REASON_USERSPACE to avoid race conditions

Signed-off-by: Arne Schwabe <arne@rfc2549.org>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <20221227022404.3468137-3-arne@rfc2549.org>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg25820.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
(cherry picked from commit 6ad66b0c2950c0d7674a5867085fef8115f61d11)

17 months agoAllow skipping multple remotes via management interface
Selva Nair [Tue, 7 Sep 2021 22:36:14 +0000 (18:36 -0400)] 
Allow skipping multple remotes via management interface

The mamangement command "remote SKIP" is extended with an
optional parameter 'count' > 0. If count is greater than
number of connection entries (len), count % len is used.
On going past the index of the last connection entry,
counting is restarted from the first connection entry.

Without this, use of management-query-remote from a UI is
virtually impractical except when there are only a handful
of remote entries. Skipping the entries one by one takes
a long time when there are many entries to be skipped
(~ 1 second per entry).  Use of "remote MOD" is not an
option as change of protocol is not supported.

Management clients can determine the availability of this
feature by checking that the management interface version
is > 3. Older versions will ignore the count parameter and
behave identically to using count = 1.

Signed-off-by: Selva Nair <selva.nair@gmail.com>
Acked-by: Arne Schwabe <arne@rfc2549.org>
Message-Id: <20210907223614.8574-1-selva.nair@gmail.com>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg22817.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
(cherry picked from commit ec5ffe35a394c44b1ea25b7c10dab7da7d792ef2)

17 months agoUse a template for 'unsupported management commands' error
Selva Nair [Tue, 7 Sep 2021 22:31:26 +0000 (18:31 -0400)] 
Use a template for 'unsupported management commands' error

The message
"ERROR: The 'foo' commmand is not supported by current daemon mode"
is repeatedly used in manage.c. Move it to a function for uniformity
in messaging.

v3, v3: no change
Signed-off-by: Selva Nair <selva.nair@gmail.com>
Acked-by: Arne Schwabe <arne@rfc2549.org>
Message-Id: <20210907223126.8440-3-selva.nair@gmail.com>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg22814.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
(cherry picked from commit caf1b9030f28a984a0e12dd87b128b428d3683f0)

17 months agoPermit unlimited connection entries and remotes
Selva Nair [Tue, 7 Sep 2021 22:31:25 +0000 (18:31 -0400)] 
Permit unlimited connection entries and remotes

Currently we allow a max of 64 connection entries and remotes.
A larger number would allow users with 100's of independent
config files for different end points of same provider to
consolidate them to connection entries.

v2,v3: no change

Signed-off-by: Selva Nair <selva.nair@gmail.com>
Acked-by: Arne Schwabe <arne@rfc2549.org>
Message-Id: <20210907223126.8440-2-selva.nair@gmail.com>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg22816.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
(cherry picked from commit 4954beb618e8bf2dc756019d5a36040d791a8f38)

17 months agoAdd remote-count and remote-entry query via management
Selva Nair [Tue, 7 Sep 2021 22:31:24 +0000 (18:31 -0400)] 
Add remote-count and remote-entry query via management

Selecting the remote host via the management interface
(management-query-remote) provides a restrictive user
experience as there is no easy way to tabulate all available
remote entries and show a list to the user to choose from.
Fix that.

Two new commands for querying the management interface are added:
(i) remote-entry-count : returns the number of remotes specified
    in the config file. Example result:
       10
       END

(ii) remote-entry-get i [j]: returns the remote entry at index i
     in the form index,host,port,protocol. Or, if j is present
     all entries from index i to j-1 are returned, one per line.

     Example result for i = 2:
        2,ovpn.example.com,1194,udp
        END
     Example result for i = 2, j = 4
        2,ovpn.example.com,1194,udp
        3,ovpn.example.com,443,tcp-client
        END

     remote-entry-get all: returns all remote entries.

v2: use independent callback functions for the two commands
v3: return results as 0 or more lines terminated by END, as done
    for all other similar commands. v1 was fashioned after
    pkcs11-id-count and pkcs11-id-get which uses a format not
    consistent with the rest of the management commands.

See also management-notes.txt

Signed-off-by: Selva Nair <selva.nair@gmail.com>
Acked-by: Arne Schwabe <arne@rfc2549.org>
Message-Id: <20210907223126.8440-1-selva.nair@gmail.com>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg22815.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
(cherry picked from commit 125263804701f9e62a5a27587e4ea6afdb21f54d)

17 months agoImprove logging when seeing a message for an unkown peer
Arne Schwabe [Sat, 24 Dec 2022 19:42:52 +0000 (20:42 +0100)] 
Improve logging when seeing a message for an unkown peer

Signed-off-by: Arne Schwabe <arne@rfc2549.org>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <20221224194253.3202231-9-arne@rfc2549.org>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg25793.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
(cherry picked from commit 8516b4b3665aa94d3114194f33fbb9c34119ab71)

17 months agoAlso drop incoming dco packet content when dropping the packet
Arne Schwabe [Sat, 24 Dec 2022 19:42:49 +0000 (20:42 +0100)] 
Also drop incoming dco packet content when dropping the packet

If we get a message from a mismatched packet we need to clear
the incoming message buffer to ensure we can receive another
packet.

Signed-off-by: Arne Schwabe <arne@rfc2549.org>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <20221224194253.3202231-6-arne@rfc2549.org>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg25797.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
(cherry picked from commit 7433618cb4bea017ae7c360da42093f49cf014b4)

17 months agoDo not set nl socket buffer size
Arne Schwabe [Sat, 24 Dec 2022 19:42:50 +0000 (20:42 +0100)] 
Do not set nl socket buffer size

libnl increases the sizes we pass to 8192 anyway. Currently when we have
a lot of events queued we might run into a NLE_NOMEM message and that
terminates the server. So rather let the kernel decide the buffer sizes.

Signed-off-by: Arne Schwabe <arne@rfc2549.org>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <20221224194253.3202231-7-arne@rfc2549.org>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg25789.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
(cherry picked from commit b2ca179ce2678115c3a61fd3f843c64c1d059fbc)

17 months agoMove dco_installed back to link_socket from link_socket.info.actual
Arne Schwabe [Sat, 24 Dec 2022 19:42:47 +0000 (20:42 +0100)] 
Move dco_installed back to link_socket from link_socket.info.actual

this change was done in order to be able to differentiate when needing to
use dco and when to use normal socket sendto. Since we want to eventually
completely use the userspace sockets for sending/receiving, we just switch
to always use UDP sendto even if the socket is already installed in the
kernel.

Signed-off-by: Arne Schwabe <arne@rfc2549.org>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <20221224194253.3202231-4-arne@rfc2549.org>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg25792.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
(cherry picked from commit 1413b38d0eacafb6c03c701236fe546f44f39a8d)

17 months agoRename TM_UNTRUSTED to TM_INITIAL, always start session in TM_INITIAL rather than...
Arne Schwabe [Sat, 24 Dec 2022 19:42:45 +0000 (20:42 +0100)] 
Rename TM_UNTRUSTED to TM_INITIAL, always start session in TM_INITIAL rather than TM_ACTIVE or TM_INITIAL

Currently we start new session in TM_ACTIVE or TM_INITIAL depending if
we already have an active session in TM_ACTIVE or not.

With this change, all session will be started in TM_INITIAL both initiated
by a peer but also session by ourselves. This simplifies state transitions
and eliminates the wacky state transition that when we have a failed
reneogitiation (and move TM_ACTIVE to TM_LAME_DUCK) that a new session of
a peer starts in TM_ACTIVE rather than TM_INITIAL

This is a squash of two mailing list patches:

Signed-off-by: Arne Schwabe <arne@rfc2549.org>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <20221224194253.3202231-2-arne@rfc2549.org>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg25798.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
Signed-off-by: Arne Schwabe <arne@rfc2549.org>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <20221224194253.3202231-3-arne@rfc2549.org>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg25795.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
(cherry picked from commit 7dcde87b7a4323ffb173576d4559e14fcfe4e627)

17 months agomsvc: upgrade to Visual Studio 2022
Lev Stipakov [Wed, 14 Dec 2022 16:09:40 +0000 (18:09 +0200)] 
msvc: upgrade to Visual Studio 2022

Signed-off-by: Lev Stipakov <lev@openvpn.net>
Acked-by: Frank Lichtenheld <frank@lichtenheld.com>
Message-Id: <20221214160940.153-1-lstipakov@gmail.com>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg25697.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
(cherry picked from commit 80c5884886926094750366af57826cdb6f053fda)

17 months agoMake management password check constant time
Arne Schwabe [Tue, 20 Dec 2022 14:04:58 +0000 (15:04 +0100)] 
Make management password check constant time

This changes the password check on the management interface to be constant
time. Normally the management port should not be exposed in a way that
allows an attacker to even interact with it but making the check constant
time as an additional layer of security is always good.

Patch v2: include NUL byte in comparison

Reported-by: Connor Edwards <cedw@pm.me>
Signed-off-by: Arne Schwabe <arne@rfc2549.org>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <20221220140458.2666637-1-arne@rfc2549.org>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg25784.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
(cherry picked from commit e567f34262b0670fd51cbbcb6c6866b046454cee)

17 months agoEnsure that dco keepalive and mssfix options are also set in pure p2p mode
Arne Schwabe [Mon, 19 Dec 2022 17:40:27 +0000 (18:40 +0100)] 
Ensure that dco keepalive and mssfix options are also set in pure p2p mode

Trac: #1476
Signed-off-by: Arne Schwabe <arne@rfc2549.org>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <20221219174027.2567505-1-arne@rfc2549.org>
URL: https://www.mail-archive.com/search?l=mid&q=20221219174027.2567505-1-arne@rfc2549.org
Signed-off-by: Gert Doering <gert@greenie.muc.de>
(cherry picked from commit 7c66a6dab54d8efcde57c8fb562f95d95f9b18d4)

17 months agoPersist DCO client data channel traffic stats on restart
Selva Nair [Thu, 15 Dec 2022 23:21:04 +0000 (18:21 -0500)] 
Persist DCO client data channel traffic stats on restart

Signed-off-by: Selva Nair <selva.nair@gmail.com>
Acked-by: Lev Stipakov <lstipakov@gmail.com>
Message-Id: <20221215232104.1181936-1-selva.nair@gmail.com>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg25742.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
(cherry picked from commit 0fdbb288db06792d5dd29acd14205d751041513d)

17 months agoDo not include auth-token in pulled option digest
Selva Nair [Mon, 19 Dec 2022 14:04:05 +0000 (09:04 -0500)] 
Do not include auth-token in pulled option digest

As change in auth-token is common on restart and does not
require tun-reopen, exclude it from the "pulled options digest"
calculation. Without this tun is always re-opened on SIGUSR1
if auth-token is in use which breaks persist-tun.

Github: Fixes OpenVPN/openvpn#200

v2: explcitly filter auth-token and auth-token-user

Signed-off-by: Selva Nair <selva.nair@gmail.com>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <20221219140405.1221341-1-selva.nair@gmail.com>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg25768.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
(cherry picked from commit f778f4f88e56851c0a68205e95110c021f3032b3)

17 months agoUse include "buffer.h" instead of include <buffer.h>
Arne Schwabe [Mon, 19 Dec 2022 17:21:41 +0000 (18:21 +0100)] 
Use include "buffer.h" instead of include <buffer.h>

My own non-standard cmake based build system found this one. But
even if this is not a problem with the normal autoconf based system
we should still be consistent.

Signed-off-by: Arne Schwabe <arne@rfc2549.org>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <20221219172141.2565798-1-arne@rfc2549.org>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg25777.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
(cherry picked from commit 5bd787bb8fc647f508635b948be75179fbb0b8a5)

17 months agogit-version.py: proper support for tags
Lev Stipakov [Mon, 19 Dec 2022 15:56:38 +0000 (17:56 +0200)] 
git-version.py: proper support for tags

Git magic to get branch name

  git rev-parse --symbolic-full-name HEAD

doesn't work when we're on tag, which is the case when
we build releases.

First, try to get tag name with

   git describe --exact-match

and if this fails, get branch name as before.

Use subprocess.Popen() to suppress stdout/stderr output.

Github: Fixes OpenVPN/openvpn#199

Signed-off-by: Lev Stipakov <lev@openvpn.net>
Acked-by: Frank Lichtenheld <frank@lichtenheld.com>
Message-Id: <20221219155638.497-1-lstipakov@gmail.com>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg25773.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
(cherry picked from commit 91ab3d022e2652a46e6d6f25ab62f7c903e583c1)

17 months agoReduce default restart pause to 1 second
Selva Nair [Mon, 19 Dec 2022 15:04:35 +0000 (10:04 -0500)] 
Reduce default restart pause to 1 second

Current value of restart pause is 5 seconds which feels
unduly long. Reduce it to 1 second.

User can still customize the delay using the first parameter for
"--connect-retry".

Also improve the description of "--connect-retry" in the
man page.

v2 changes:
- fix incomplete man page edit as pointed out by Arne Schwabe
- fix man page (rst) changes as suggested by Frank Lichtenheld

Signed-off-by: Selva Nair <selva.nair@gmail.com>
Acked-by: Frank Lichtenheld <frank@lichtenheld.com>
Message-Id: <20221219150435.1222451-1-selva.nair@gmail.com>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg25770.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
(cherry picked from commit cb385c64279fcb11bf6622d9723e1223b4e2a7f5)

17 months agoDeprecate NTLMv1 proxy auth method.
Arne Schwabe [Thu, 15 Dec 2022 19:01:43 +0000 (20:01 +0100)] 
Deprecate NTLMv1 proxy auth method.

NTLMv1 is ancient and not considered secure anymore and we are not
aware of any users or software still requiring this feature.

Additionally it currently depends on our "doing single DES using
3DES" workaround for OpenSSL (cipher_des_encrypt_ecb). So removing
NTLMv1 will also allow us to remove that workaround.

Reported-By: Trial of Bits (TOB-OVPN-7)
Signed-off-by: Arne Schwabe <arne@rfc2549.org>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <20221215190143.2107896-9-arne@rfc2549.org>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg25731.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
(cherry picked from commit e005b8d1fda1ad1e26fe0dbe7e09184a1f19b553)

17 months agoFix corner case that might lead to leaked file descriptor
Arne Schwabe [Thu, 15 Dec 2022 19:01:42 +0000 (20:01 +0100)] 
Fix corner case that might lead to leaked file descriptor

Reported-By: Trail of Bits
Signed-off-by: Arne Schwabe <arne@rfc2549.org>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <20221215190143.2107896-8-arne@rfc2549.org>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg25730.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
(cherry picked from commit a034dc8153522713c3cfda90b2cda114cea70e2d)

17 months agoRemove unused gc_arena
Arne Schwabe [Thu, 15 Dec 2022 19:01:41 +0000 (20:01 +0100)] 
Remove unused gc_arena

Reported-By: Trail of Bits
Signed-off-by: Arne Schwabe <arne@rfc2549.org>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <20221215190143.2107896-7-arne@rfc2549.org>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg25736.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
(cherry picked from commit 97929d16a4eb05cb521a469ff4eaca32761699f3)

17 months agoEliminate or comment empty blocks and switch fallthrough
Arne Schwabe [Thu, 15 Dec 2022 19:01:40 +0000 (20:01 +0100)] 
Eliminate or comment empty blocks and switch fallthrough

These empty blocks are intentional but trigger code checkers and
were pointed out by Trail of Bits in the security audits. Add comments
to them or eliminate them whatever makes more sense.

For fallthrough C23 [1] has a standard way to signal that but we not
adding a C23 feature to our codebase, so use a comment for now.

[1] https://en.cppreference.com/w/c/language/attributes/fallthrough

Signed-off-by: Arne Schwabe <arne@rfc2549.org>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <20221215190143.2107896-6-arne@rfc2549.org>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg25735.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
(cherry picked from commit f2454ec6363d5578875d020179b38074b3c10964)

17 months agoImprove documentation on user/password requirement and unicodize function
Arne Schwabe [Thu, 15 Dec 2022 19:01:39 +0000 (20:01 +0100)] 
Improve documentation on user/password requirement and unicodize function

Signed-off-by: Arne Schwabe <arne@rfc2549.org>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <20221215190143.2107896-5-arne@rfc2549.org>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg25733.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
(cherry picked from commit 4b6854881c36e16054878e0467ef87d925e20cae)

17 months agoEnsure that argument to parse_line has always space for final sentinel
Arne Schwabe [Thu, 15 Dec 2022 19:01:38 +0000 (20:01 +0100)] 
Ensure that argument to parse_line has always space for final sentinel

This fixes two places were we do not have enough space in the array
of parameters given to parse_line for the final NULL parameter that
signal the end of the parsed argument errors.

Both these cases can lead to a buffer overflow. But both of these
cases require root/admin access to OpenVPN:

- parse_argv, only able to trigger if starting openvpn from the command
  line, at this point you cannot  gain more privileges than you already
  have.

  Way to reproduce, compile with ASAN and run:

       openvpn --tls-verify a a a a a a a a a a a a a a a

- remove_iroutes_from_push_route_list

This operates on the list of pushed entries that is generated
by the server itself. So trigger this, you need to have control
over config, management interface, a plugin or cdd files.

The parse_argv problem was found by Trial of Bits. I found the
remove_iroutes_from_push_route_list problem by looking for similar
problems.

Reported-By: Trial of Bits (TOB-OVPN-4)
Signed-off-by: Arne Schwabe <arne@rfc2549.org>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <20221215190143.2107896-4-arne@rfc2549.org>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg25734.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
(cherry picked from commit 749beb6d0cb9f8628997bb656ba2f64e31cac377)

17 months agossl_verify: Fix memleak if creating deferred auth control files fails
David Sommerseth [Thu, 15 Dec 2022 19:01:37 +0000 (20:01 +0100)] 
ssl_verify: Fix memleak if creating deferred auth control files fails

If the key_state_gen_auth_control_files() call fails, the code would
just return without freeing the argv container.  Instead the code should
jump to an appropriate exit point where memory is being released.

Also adjust the related comment, to indicate that these deferred auth
control files are really pre-created.

Signed-off-by: David Sommerseth <davids@openvpn.net>
Reported-by: Trail of Bits (TOB-OVPN-2)
Signed-off-by: Arne Schwabe <arne@rfc2549.org>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <20221215190143.2107896-3-arne@rfc2549.org>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg25737.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
(cherry picked from commit 0567da5377704cf64bd2599f2d49aa478d386941)

17 months agoPreparing release 2.6_beta2 v2.6_beta2
Gert Doering [Thu, 15 Dec 2022 13:22:32 +0000 (14:22 +0100)] 
Preparing release 2.6_beta2

version.m4, ChangeLog, Changes.rst

Signed-off-by: Gert Doering <gert@greenie.muc.de>
17 months agoIntroduce dco_get_peer_stats API and Windows implementation
Lev Stipakov [Wed, 14 Dec 2022 21:14:26 +0000 (23:14 +0200)] 
Introduce dco_get_peer_stats API and Windows implementation

dco_get_peer_stats fetches stats for a single peer. This is mostly
useful in client mode. So far only Windows implements that.

Signed-off-by: Lev Stipakov <lev@openvpn.net>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <20221214211426.227-1-lstipakov@gmail.com>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg25703.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
(cherry picked from commit 74d5ece4a035fbbd962ba5ea73c19118b82f8f45)

17 months agomanagement: add timer to output BYTECOUNT
Lev Stipakov [Wed, 14 Dec 2022 22:42:20 +0000 (00:42 +0200)] 
management: add timer to output BYTECOUNT

BYTECOUNT on management interface is used to display client stats,
for example by openvpn-gui. At the moment BYTECOUNT is sent if
there is a traffic. With DCO, userspace process doesn't see data
channel traffic, BYTECOUNT is not sent and therefore stats
are not updated.

Fix displaying DCO client stats by adding a timer, which is triggerd
every n seconds, where n is set by existing management command
bytecount <n>. Output stats, taking into account stats from DCO,
when timer is triggered.

While on it, simplify bytecount routines call chains - inlining
functions which are used only once.

DCO stats fetching is not yet implemented.

Stats for the server mode (BYTECOUNT_CLI) are unaffected
by this change - to output those in timer callback we would need to
enumerate all peers, and I am not sure we want to output stats
for all peers every <n> seconds.

Signed-off-by: Lev Stipakov <lev@openvpn.net>
Acked-by: Arne Schwabe <arne@rfc2549.org>
Message-Id: <20221214224220.307-1-lstipakov@gmail.com>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg25707.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
(cherry picked from commit a9991b3eb6644785421398bff8cb3a728d131713)

17 months agovcpkg-ports/pkcs11-helper: support loader flags
Marc Becker [Wed, 14 Dec 2022 14:33:25 +0000 (15:33 +0100)] 
vcpkg-ports/pkcs11-helper: support loader flags

Add dynamic loader flag feature to bundled pkcs11-helper.
Required to allow special handling for PKCS11 providers on win32.

Signed-off-by: Marc Becker <marc.becker@astos.de>
Acked-by: Lev Stipakov <lstipakov@gmail.com>
Message-Id: <20221214143325.2604-1-marc.becker@astos.de>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg25691.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
(cherry picked from commit 2f9c56e2cb0ce0f8d7a2a30f89831d1ddc0f2bbb)

17 months agospecial handling for PKCS11 providers on win32
Marc Becker [Sun, 11 Dec 2022 20:01:08 +0000 (21:01 +0100)] 
special handling for PKCS11 providers on win32

Change win32 dynamic loader behavior when supplying an absolute path.
The DLL location is considered/preferred to resolve dependencies.
Support in pkcs11-helper for loader flag is detected at compile time.

3rd party DLLs and additional dependencies do no longer need to be moved
to the OpenVPN directory or require changes to %PATH% configuration.

Signed-off-by: Marc Becker <marc.becker@astos.de>
Acked-by: Selva Nair <selva.nair@gmail.com>
Message-Id: <20221211200108.1402-1-marc.becker@astos.de>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg25646.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
(cherry picked from commit e299b8d0d62a4763b20bf9a3bd6aadf414aa89fe)

17 months agouse new pkcs11-helper interface to add providers
Marc Becker [Sun, 11 Dec 2022 19:14:03 +0000 (20:14 +0100)] 
use new pkcs11-helper interface to add providers

The new interface in  pkcs11-helper 1.28 allows decoupling of provider
registration and initialization.
This allows modifying more (and future) properties apart from the
6 fixed ones supported as arguments to pkcs11h_addProvider().

With the new interface it is easier to see (from a code perspective)
which option is set to which value.
It's also not necessary to supply values for built-in defaults:
- slot_event_method=PKCS11H_SLOTEVENT_METHOD_AUTO
- slot_poll_interval=0

Signed-off-by: Marc Becker <marc.becker@astos.de>
Acked-by: Selva Nair <selva.nair@gmail.com>
Message-Id: <20221211191403.805-1-marc.becker@astos.de>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg25643.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
(cherry picked from commit 45d9b0210a22353e587c29c5d3c3990346a4a189)

17 months agounify code path for adding PKCS#11 providers
Marc Becker [Sun, 11 Dec 2022 19:09:13 +0000 (20:09 +0100)] 
unify code path for adding PKCS#11 providers

Use existing wrapper for pkcs11h_addProvider to have arguments with
"magic values" for pkcs11-helper call in a central place.

Slot event argument to pkcs11h_addProvider has NOT been a boolean for
at least 15 years.
Luckily the default is PKCS11H_SLOTEVENT_METHOD_AUTO=0=FALSE.

Signed-off-by: Marc Becker <marc.becker@astos.de>
Acked-by: Frank Lichtenheld <frank@lichtenheld.com>
Message-Id: <20221211190913.190-1-marc.becker@astos.de>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg25642.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
(cherry picked from commit 8958a365479348c1500dee44e1a8b27e7e35a96f)

17 months agoFix message for too long tls-crypt-v2 metadata
Max Fillinger [Wed, 14 Dec 2022 15:34:14 +0000 (16:34 +0100)] 
Fix message for too long tls-crypt-v2 metadata

The current code only checks if the base64-encoded metadata is at most
980 characters. However, that can encode up to 735 bytes of data, while
only up to 733 bytes are allowed. When passing 734 or 735 bytes, openvpn
prints a misleading error message saying that the base64 cannot be
decoded.

This patch checks the decoded length to show an accurate error message.

v2: Remove now-unused macro and fix an off-by-one error.

Signed-off-by: Max Fillinger <maximilian.fillinger@foxcrypto.com>
Acked-by: Arne Schwabe <arne@rfc2549.org>
Message-Id: <20221214153414.12671-1-maximilian.fillinger@foxcrypto.com>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg25694.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
(cherry picked from commit 860bf4bf9248077259690a518925ecc14da4b320)

17 months agodco: cleanup FreeBSD dco_do_read()
Kristof Provost [Mon, 5 Dec 2022 16:41:03 +0000 (17:41 +0100)] 
dco: cleanup FreeBSD dco_do_read()

Remove support for reading packets through the control interface.
FreeBSD no longer does this, so there's no point in keeping the code for it.

While here also check that we know what type of notification we're
getting. There's currently only one, but we should check anyway.

Signed-off-by: Kristof Provost <kprovost@netgate.com>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <20221205164103.9190-5-kprovost@netgate.com>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg25616.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
(cherry picked from commit 235161cd2bcd5403c807e66432c421114c896b74)

17 months agoRename dco_get_peer_stats to dco_get_peer_stats_multi
Lev Stipakov [Wed, 14 Dec 2022 13:28:35 +0000 (15:28 +0200)] 
Rename dco_get_peer_stats to dco_get_peer_stats_multi

Existing API and implementation (FreeBSD only) are designed for
server usage. Rename it to *_multi to indicate that and not to mix
with upcoming client API/implementation.

Signed-off-by: Lev Stipakov <lev@openvpn.net>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <20221214132835.1010-1-lstipakov@gmail.com>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg25690.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
(cherry picked from commit 6dbf8352ef2151dfdee7f02ccbdd9560b3e2be75)

17 months agoRead the peer deletion reason from the kernel
Kristof Provost [Mon, 5 Dec 2022 16:41:02 +0000 (17:41 +0100)] 
Read the peer deletion reason from the kernel

Recent FreeBSD kernels supply a reason for the OVPN_NOTIF_DEL_PEER
notification. Parse this from the nvlist so we can distinguish
user-requested removals from timeouts.

Signed-off-by: Kristof Provost <kprovost@netgate.com>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <20221205164103.9190-4-kprovost@netgate.com>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg25617.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
(cherry picked from commit 10ea19092ded38ff25a445f987ad948aa9eac49f)

17 months agodco: Update counters when a client disconnects
Kristof Provost [Mon, 5 Dec 2022 16:41:01 +0000 (17:41 +0100)] 
dco: Update counters when a client disconnects

When the kernel module (Linux or FreeBSD) notifies us that a peer has
disconnected we'd like to get a final count of the in/out bytes for that
peer.
We can't request that information any more, because the kernel has
already removed the peer at that point.

Have the kernel send that information as part of the "delete peer"
notification, and update the counters a final time.

This implements the FreeBSD-specific DCO code, but not the
Linux-specific code. It will simply add 0 to the count on Linux.

Signed-off-by: Kristof Provost <kprovost@netgate.com>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <20221205164103.9190-3-kprovost@netgate.com>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg25614.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
(cherry picked from commit 6674963debfb88c0dd3dd4eae4533010ffc319b1)

17 months agoSet DCO_NOT_INSTALLED also for keys not in the get_key_scan range
Arne Schwabe [Tue, 13 Dec 2022 22:54:30 +0000 (23:54 +0100)] 
Set DCO_NOT_INSTALLED also for keys not in the get_key_scan range

We have 6 key slots but normally only consider 3 of them to be
active/valid keys. Especially the secondary key of TM_LAME_DUCK can
in rare corner cases have a key that is still installed in the kernel.

While this should not cause any issues since I do not see way for this
key to become active ever again, it is better to keep the state correctly.

Signed-off-by: Arne Schwabe <arne@rfc2549.org>
Acked-by: Antonio Quartulli <antonio@openvpn.net>
Message-Id: <20221213225430.1892940-3-arne@rfc2549.org>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg25681.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
(cherry picked from commit 4cf7409e82580f2890c391372d60ed713ba4650c)

17 months agoTrigger a USR1 if dco_update_keys fails
Arne Schwabe [Tue, 13 Dec 2022 22:54:29 +0000 (23:54 +0100)] 
Trigger a USR1 if dco_update_keys fails

When dco_update_keys fails, we are in some weird state that we are
unlikely to recover since what userspace and kernel space think of
the keys is very likely to not in sync anymore. So abandon the
connection if this happens.

Signed-off-by: Arne Schwabe <arne@rfc2549.org>
Acked-by: Antonio Quartulli <antonio@openvpn.net>
Message-Id: <20221213225430.1892940-2-arne@rfc2549.org>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg25679.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
(cherry picked from commit 419051c96e9fb1f3202fd67733aa3b6a4bbc3181)

17 months agoImprove debug logging of DCO swap key message and Linux dco_new_peer
Arne Schwabe [Tue, 13 Dec 2022 22:54:28 +0000 (23:54 +0100)] 
Improve debug logging of DCO swap key message and Linux dco_new_peer

Signed-off-by: Arne Schwabe <arne@rfc2549.org>
Acked-by: Antonio Quartulli <antonio@openvpn.net>
Message-Id: <20221213225430.1892940-1-arne@rfc2549.org>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg25680.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
(cherry picked from commit 63f838e384df3fb644bdeae6ede777b54dc968db)

17 months agoRead DCO traffic stats from the kernel
Kristof Provost [Mon, 5 Dec 2022 16:41:00 +0000 (17:41 +0100)] 
Read DCO traffic stats from the kernel

When DCO is active userspace doesn't see all of the traffic, so when we
access these stats we must update them.

Retrieve kernel statistics every time we access the
link_(read|write)_bytes values.

Introduce a dco_(read|write)_bytes so that we don't clobber the existing
statistics, which still count control packets, sent or received directly
through the socket.

Signed-off-by: Kristof Provost <kprovost@netgate.com>
Acked-by: Antonio Quartulli <antonio@openvpn.net>
Message-Id: <20221205164103.9190-2-kprovost@netgate.com>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg25618.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
(cherry picked from commit ce2b459dabc29d071be28b8ddaa0512f8c8143ec)

17 months agoIgnore connection attempts while server is shutting down
Arne Schwabe [Thu, 8 Dec 2022 15:31:29 +0000 (16:31 +0100)] 
Ignore connection attempts while server is shutting down

Currently we still allow clients to connect while the server is waiting
to shut down. This window is very small (2s) and is only used when
explicit-exit-notify is enabled on the server side.

The chance of a client connecting during this time period is very low
unless someone puts something stupid like --connect-retry 1 3 into his/her
client config and forces the client to reconnect during this time period.

Github: OpenVPN/openvpn#189

Signed-off-by: Arne Schwabe <arne@rfc2549.org>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <20221208153129.1207228-1-arne@rfc2549.org>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg25638.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
(cherry picked from commit 7d0a90335fe79a352456f262ce42ea501796ae87)

17 months agoCorrect tls-crypt-v2 metadata length in man page
Max Fillinger [Sat, 26 Nov 2022 16:26:47 +0000 (17:26 +0100)] 
Correct tls-crypt-v2 metadata length in man page

The manual page claims that the client metadata can be up to 735 bytes
(encoded as upt to 980 characters base64), but the actual maximum length
is 733 bytes which is also encoded as 980 characters in base64.

Signed-off-by: Max Fillinger <maximilian.fillinger@foxcrypto.com>
Acked-by: Arne Schwabe <arne@rfc2549.org>
Message-Id: <20221126162648.150678-1-maximilian.fillinger@foxcrypto.com>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg25546.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
(cherry picked from commit 0bd2fa38fb70ad9022c05ffa67b2bd8751ca5a5b)

17 months agoDisable DCO when TLS mode is not used
Arne Schwabe [Sat, 10 Dec 2022 13:44:27 +0000 (14:44 +0100)] 
Disable DCO when TLS mode is not used

This disables DCO in both --secret mode and when no encryption/TLS is
used. Also aligns the message with the deprecation warning we have in
place.

Signed-off-by: Arne Schwabe <arne@rfc2549.org>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <20221210134427.1433419-1-arne@rfc2549.org>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg25641.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
(cherry picked from commit a666668f064c7ff57cdebb3afceb72e1263a3ba9)

18 months agoFix unit test of test_pkt on little endian Linux
Arne Schwabe [Wed, 7 Dec 2022 14:02:59 +0000 (15:02 +0100)] 
Fix unit test of test_pkt on little endian Linux

This surprising breakage results from the fact that Linux basically uses
a different structure from the *BSD:

For exmaple, macOS has:

struct sockaddr_in {
    __uint8_t       sin_len;
    sa_family_t     sin_family;
    in_port_t       sin_port;
    struct  in_addr sin_addr;
    char            sin_zero[8];
};

with sa_family_t also uint8_t

and Linux has stupidly complex definition that boils down to:

struct sockaddr_in
  {
    uint16_t sin_family;
    in_port_t sin_port;
    struct in_addr sin_addr
    char sin_zero[8];
  };

So Linux basically has a 16 bit uint16 instead of two uint8_t. Because
s390x is big endian, this happens to be same in memory layout as on all
BSDs with first byte being 0 and second byte being the family.

Introduce a second array to check against, if we are on little endian
Linux.
This is a bit fragile but this is also just a unit test.

This also fixes compiling test_pkt with windows.

Signed-off-by: Arne Schwabe <arne@rfc2549.org>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <20221207140259.1083577-1-arne@rfc2549.org>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg25633.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
(cherry picked from commit 0f904615bd2eac9d246055ff1ca4e4da95586f86)

18 months agoChangeLog: Fix encoding
Frank Lichtenheld [Wed, 7 Dec 2022 10:35:30 +0000 (11:35 +0100)] 
ChangeLog: Fix encoding

Convert to UTF-8.
Also collapse entries "Richard Bonhomme" and "Richard T Bonhomme".

Signed-off-by: Frank Lichtenheld <frank@lichtenheld.com>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <20221207103530.18198-1-frank@lichtenheld.com>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg25630.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
18 months agodisable DCO if --secret is specified
Antonio Quartulli [Wed, 7 Dec 2022 10:02:01 +0000 (11:02 +0100)] 
disable DCO if --secret is specified

P2P mode with pre-shared key is deprecated, unsecure and should NOT be
used. This said we still carry it around for a bit and we have to make
sure it does not fight with DCO.

Disable DCO at all when --secret is specified.

Github: OpenVPN/openvpn#188

Signed-off-by: Antonio Quartulli <a@unstable.cc>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <20221207100201.6467-1-a@unstable.cc>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg25629.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
(cherry picked from commit f5febf7f8998e425afb051cd6f965f4dd40b1659)

18 months agoFix connection cookie not including address and fix endianness in test
Arne Schwabe [Tue, 6 Dec 2022 13:36:47 +0000 (14:36 +0100)] 
Fix connection cookie not including address and fix endianness in test

We accidentially checked the adress family size instead of the address
family.

For  unit test checks we need to consider endianess to ensure the hmac
for the adress is always the same. The real code does not care about
endian since it only needs it to be same on the same architecture.

Converting the session to endianess is strictly speaking unecessary
for the actual function of the function but is almost no overhead
and makes the unit testing more robust.

Reported by David trying to the package on Red Hat/s390x and painfully
debugged by setting up a s390x qemu machine that takes 40s just to
run ./configure.

Signed-off-by: Arne Schwabe <arne@rfc2549.org>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <20221206133647.954724-1-arne@rfc2549.org>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg25619.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
(cherry picked from commit 67bef0357280040b83f2185c91c4f830ba542d6b)

18 months agoPreparing release 2.6_beta1 v2.6_beta1
Gert Doering [Thu, 1 Dec 2022 15:32:02 +0000 (16:32 +0100)] 
Preparing release 2.6_beta1

version.m4, ChangeLog, branching off release/2.6 from master.

Signed-off-by: Gert Doering <gert@greenie.muc.de>
18 months agodocumentation: avoid recommending --user nobody
Frank Lichtenheld [Tue, 29 Nov 2022 14:47:31 +0000 (15:47 +0100)] 
documentation: avoid recommending --user nobody

Recommend to create an user dedicated to openvpn
so that there is no priviledge escalation between
different services using that user.

cf. https://wiki.ubuntu.com/nobody

Trac: #1335
CC: tincantech <tincantech@protonmail.com>
Signed-off-by: Frank Lichtenheld <frank@lichtenheld.com>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <20221129144731.35105-1-frank@lichtenheld.com>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg25573.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
18 months agodco: disable dco on Windows if --remote is not defined
Lev Stipakov [Thu, 1 Dec 2022 12:59:02 +0000 (14:59 +0200)] 
dco: disable dco on Windows if --remote is not defined

At the moment Windows driver requires remote to work.

Signed-off-by: Lev Stipakov <lev@openvpn.net>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <20221201125902.400-1-lstipakov@gmail.com>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg25604.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
18 months agoAllow reconnecting in p2p mode work under FreeBSD
Arne Schwabe [Thu, 1 Dec 2022 11:01:28 +0000 (12:01 +0100)] 
Allow reconnecting in p2p mode work under FreeBSD

This commit consists of two parts.
 - explicitly removing an existing peer in p2p mode
 - ignoring the ping timeout notification that is generated by the first
part

Signed-off-by: Arne Schwabe <arne@rfc2549.org>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <20221201110128.271064-1-arne@rfc2549.org>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg25602.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
18 months agoSignal USR1 when connection initialising fails
Arne Schwabe [Wed, 30 Nov 2022 16:57:12 +0000 (17:57 +0100)] 
Signal USR1 when connection initialising fails

When we fail initialisation the connection (e.g. P2P cipher NCP), we have
a non-working connection. Even though previous version would then stay in
this state, it does not really make sense to be in this state until the
keepalive timeout expires and triggers a USR1 anyway.

Signed-off-by: Arne Schwabe <arne@rfc2549.org>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <20221130165712.159683-1-arne@rfc2549.org>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg25596.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
18 months agoIntroduce connection state for reconnecting peer in p2p
Arne Schwabe [Wed, 30 Nov 2022 16:57:05 +0000 (17:57 +0100)] 
Introduce connection state for reconnecting peer in p2p

We introduce this state to make the reconnecting of a client more
obvious and what is called again instead of making it implicit. The
new state CAS_RECONNECT_PENDING is between CAS_WAITING_OPTIONS_IMPORT and
CAS_CONNECT_DONE as we need to redo some of the steps of the connection
setup, so this new state is going a "half step" back in the state machine.

We also do no longer generate data channel keys for untrusted session. This
is done for clarity but also to allow them being generated after the
session has become actually active.

These changes allow a reconnect in p2p mode with DCO to work as the initial
reconnect working.

Signed-off-by: Arne Schwabe <arne@rfc2549.org>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <20221130165705.159610-1-arne@rfc2549.org>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg25595.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>