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

2186 Commits

Author SHA1 Message Date
James Yonan
f6f40e24cd
Added AGPL license header to HTTP, Java, and common code. 2020-01-09 12:23:33 +02:00
James Yonan
1c8052be45
Renamed types.hpp to size.hpp since it now only defines size_t and ssize_t. 2020-01-09 12:23:33 +02:00
James Yonan
7194db16c2
In HTTPCore (httpcli.hpp), factor out code into httpcommon.hpp that is common to both HTTP clients and servers, so upcoming HTTP server implementation can leverage on the same code currently used by the client. 2020-01-09 12:23:32 +02:00
James Yonan
06fa9d2f21
Refactored WS::HTTPCore::ChunkedHelper into its own source file in preparation for HTTP server implementation. 2020-01-09 12:23:32 +02:00
James Yonan
efe7f6d620
copyright: updated to 2017
Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:23:32 +02:00
James Yonan
bfadf92762
license : this branch (common) is proprietary, so remove all GPL headers.
Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:23:32 +02:00
James Yonan
fd949d96a3
copyright : updated to 2016 2020-01-09 12:23:31 +02:00
James Yonan
706574a59f
Change to calls of Windows API methods:
* Where unicode/ansi versions of a method exist, always
  explicitly call one of unicode or ansi methods by
  appending a 'W' or 'A' to the end of the method name.
  Never omit the 'W' or 'A' because that will cause the
  default method to be used which may vary according to
  build flags.

* Prepend all Windows API method references with "::" to
  indicate that the method names should be resolved from
  the top-level namespace.
2020-01-09 12:23:31 +02:00
James Yonan
edcc119b85
In HTTP server (httpserv.hpp), allow users to specify the Windows SDDL string used to set the permissions on created named pipes.
Also, refactor some Windows-specific code into secattr.hpp
(SECURITY_ATTRIBUTES stuff) and npinfo.hpp (getting info
about named pipe peer).
2020-01-09 12:23:31 +02:00
James Yonan
5bb9515515
copyright: updated to 2017
Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:23:31 +02:00
James Yonan
0d4b64139c
license : this branch (common) is proprietary, so remove all GPL headers.
Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:23:30 +02:00
James Yonan
61c99b5f6d
copyright : updated to 2016 2020-01-09 12:23:30 +02:00
James Yonan
25085c9073
Windows: refactored NamedPipePeerInfoClient/Server to use a common base class that includes most of the implementation. 2020-01-09 12:23:30 +02:00
James Yonan
397d44fccc
Windows: In NamedPipePeerInfo::get_process() and allow_client_query(), allow/request SYNCHRONIZE access so that we can wait for process termination by waiting on the process HANDLE. 2020-01-09 12:23:30 +02:00
James Yonan
7bba5cec30
Added openvpn/win/handlecomm.hpp, containing classes for communicating Windows HANDLEs across process boundaries. 2020-01-09 12:23:29 +02:00
James Yonan
b8f3d013aa
In Windows npinfo.hpp, added:
1. NamedPipeImpersonate : RAII class for scoping
                          ImpersonateNamedPipeClient/RevertToSelf.

2. send_handle() : duplicate a handle prior to sending
                   to a remote process.

Added #ifdefs to support both XP/Win2003 and Vista+.
2020-01-09 12:23:29 +02:00
James Yonan
c1a793b27f
Change to calls of Windows API methods:
* Where unicode/ansi versions of a method exist, always
  explicitly call one of unicode or ansi methods by
  appending a 'W' or 'A' to the end of the method name.
  Never omit the 'W' or 'A' because that will cause the
  default method to be used which may vary according to
  build flags.

* Prepend all Windows API method references with "::" to
  indicate that the method names should be resolved from
  the top-level namespace.
2020-01-09 12:23:29 +02:00
James Yonan
22061c8135
In HTTP server (httpserv.hpp), allow users to specify the Windows SDDL string used to set the permissions on created named pipes.
Also, refactor some Windows-specific code into secattr.hpp
(SECURITY_ATTRIBUTES stuff) and npinfo.hpp (getting info
about named pipe peer).
2020-01-09 12:23:29 +02:00
James Yonan
c81b4ac4ff
copyright: updated to 2017
Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:23:28 +02:00
James Yonan
a518f007c2
license : this branch (common) is proprietary, so remove all GPL headers.
Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:23:28 +02:00
James Yonan
ad1bf8ee8d
copyright : updated to 2016 2020-01-09 12:23:28 +02:00
James Yonan
70866a59dd
Refactored openvpn/win/logfile.hpp, moving core methods create_file() and log() into a new file logutil.hpp for use by OMI logger. 2020-01-09 12:23:28 +02:00
James Yonan
2a21d63486
copyright: updated to 2017
Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:23:27 +02:00
James Yonan
4793912e3f
license : this branch (common) is proprietary, so remove all GPL headers.
Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:23:27 +02:00
James Yonan
bc9b4390c3
copyright : updated to 2016 2020-01-09 12:23:27 +02:00
James Yonan
2e8946b093
Added openvpn/win/handlecomm.hpp, containing classes for communicating Windows HANDLEs across process boundaries. 2020-01-09 12:23:27 +02:00
James Yonan
0c5c0cbe57
Acceptor::TCP: don't set reuseport flag by default on listener socket
Previously, all listener sockets were configured with both
reuseaddr and reuseport.  reuseaddr is reasonable to use as
a default, but reuseport should only be used when different
threads are listening on the same local port/address for
load-balancing purposes.

This patch adds two new socket option flags DISABLE_REUSE_ADDR
and REUSE_PORT, to provide finer-grained control over
these options.

Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:23:21 +02:00
James Yonan
80e754d00a
Replace AsioTimer with AsioTimerSafe in cases where handler doesn't clearly check for late cancellation
As noted in the Asio documentation, an AsioTimer handler can be
called with a non-error status after timer cancellation.

Unfortunately, this can lead to race conditions, so I'm moving over
all AsioTimer users to AsioTimerSafe when I don't see the handler
clearly checking for late cancellation.

Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:23:21 +02:00
James Yonan
ac158fd0bf
OMICore: support asynchronous command response
To support asynchronous command response, the virtual
method omi_command_in() should now return a boolean.

When omi_command_in() returns false, synchronous mode
is chosen (the previous default).  This means that
omi_command_in() must emit "SUCCESS: ..." or
"ERROR: ..." before it returns.

When omi_command_in() returns true, the new asynchronous
mode is chosen, and omi_command_in() may return before
emitting SUCCESS or ERROR.  In this mode, OMICore will
pause the incoming command pipeline and not make any
further calls to omi_command_in() until
OMICore::async_done() is called.

Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:23:21 +02:00
James Yonan
fd1ed92b68
Make lambda functions mutable that benefit from using std::move() on closure vars
Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:23:20 +02:00
James Yonan
35c0480180
AsioTimer: use expires_after() method when possible.
A common AsioTimer usage pattern is:

  expires_at(Time::now() + duration)

This is more succinctly and efficiently stated as:

  expires_after(duration).

Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:23:20 +02:00
James Yonan
d3da69e35c
Added i/o abstraction layer.
Created a lightweight abstraction layer so that another i/o
reactor can be dropped in place of asio.

This commit includes:

* Added ASIO=1 to many "go" scripts that require asio
* Renamed "asio::" to "openvpn_io::".

Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:23:20 +02:00
James Yonan
cff607cae1
copyright: updated to 2017
Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:23:20 +02:00
James Yonan
658efb6232
license : this branch (common) is proprietary, so remove all GPL headers.
Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:23:19 +02:00
James Yonan
c747b20e2b
asio: deal with symbol renaming in latest github master
mutable_buffers_1 -> mutable_buffer
const_buffers_1 -> const_buffer
2020-01-09 12:23:19 +02:00
James Yonan
c0d93bbd5f
copyright : updated to 2016 2020-01-09 12:23:19 +02:00
James Yonan
4a45609b29
Updated OMI to support server-side usage. 2020-01-09 12:23:19 +02:00
James Yonan
061daa8e3c
OMI : Windows seems to lose >FATAL: notifications that are transmitted immediately before OMI socket close. Work around the issue by adding a 250ms delay between the last write to the socket and the close. 2020-01-09 12:23:19 +02:00
James Yonan
26e99b1a37
Ported OpenVPN 3 OMI to Windows
* Added build script buildomi.py

* Implemented logging using Win::LogUtil

* Still an issue with External PKI that is documented in
  omi/doc/omi.log
2020-01-09 12:23:18 +02:00
James Yonan
d0c63d3150
First working OMI wrapper for OpenVPN 3 client. Tested with OpenVPN Connect on Mac.
Could benefit from some minor modifications to
python client backend and tray app:

* Client backend and ovpn3 both implement connection timeout.
  Client backend should defer to the ovpn3 implementation.

* Client backend and ovpn3 both implement DNS server config
  and SystemConfiguration event sent to
  'Setup:/Network/Global/IPv4' for 'VPN up'.
  Client backend should defer to the ovpn3 implementation.

* Ensure that system state changes (sleep, wakeup, network
  roam, fast user switching, etc.) don't cause conflicts
  between client backend and ovpn3 core both trying to
  implement similar functionality.

* Tray app should render error detail in >FATAL: messages.
  Right now tray raises a Disconnected notification but
  loses any error detail.
2020-01-09 12:23:18 +02:00
James Yonan
e8a21acb25
Initial OMI (OpenVPN Management Interface) commit, still unfinished. 2020-01-09 12:23:18 +02:00
James Yonan
1d090e7e88
Use openvpn::strerror_str() instead of std::strerror().
std::strerror() doesn't claim to be thread-safe, so
add openvpn::strerror_str() which is thread-safe by
virtue of the fact that it backs to strerror_r().

Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:23:18 +02:00
James Yonan
0368d32cb6
copyright: updated to 2017
Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:23:17 +02:00
James Yonan
6e51d02eff
license : this branch (common) is proprietary, so remove all GPL headers.
Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:23:17 +02:00
James Yonan
e6f67cedc7
copyright : updated to 2016 2020-01-09 12:23:17 +02:00
James Yonan
7dc71fa837
Added write_private() methods from core (no Windows implementation yet).
In httpcreds.hpp, use write_private() for creating creds
files rather than UMask.
2020-01-09 12:23:17 +02:00
James Yonan
0057bb7ec4
jsonhelper: allow NAME or TITLE parameters to be an array index
Also, break out json::fmt_name* methods into their own
source file.

NOTE: this code includes some SFINAE, so may need #ifdefs for
Visual Studio.

Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:23:16 +02:00
James Yonan
02b531e619
jsonhelper: extend polymorphism to allow string or numerical indices
Updated StringTempl to work with numeric types.

Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:23:16 +02:00
James Yonan
f02ea1f762
library: added BijectiveSetMapping and enhanced StringTempl::to_string()
BijectiveSetMapping is a one-to-many bijective mapping.

If K is the key and V is the value, you can:

1. add to the forward map in the form [ K : set(V) ]
2. delete K from the forward map

The BijectiveSetMapping automatically maintains the
reverse mapping where each element is the form:

  [ V: set(K) ]

Also enhanced StringTempl::to_string() with an SFINAE
variant that supports objects having a to_string() method.

Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:23:16 +02:00
James Yonan
730a57c39e
jsonhelper: allow NAME or TITLE parameters to be an array index
Also, break out json::fmt_name* methods into their own
source file.

NOTE: this code includes some SFINAE, so may need #ifdefs for
Visual Studio.

Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:23:16 +02:00
Arne Schwabe
ec7d4746b3
Update jsonhelper to current JSONcpp library
Signed-off-by: Arne Schwabe <arne@openvpn.net>
2020-01-09 12:23:15 +02:00
James Yonan
e79add27a8
jsonhelper: C++ standard appears to indicate no need to do explicit std::move on return value
This edit also silences a warning in clang.

Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:23:15 +02:00
James Yonan
b0669ab4e3
jsonhelper: added dict_result() method
Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:23:15 +02:00
James Yonan
6e242ee555
jsonhelper: added error() method
Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:23:15 +02:00
James Yonan
0c61d0dfa8
jsonhelper: minor fix: typo in exception string
Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:23:14 +02:00
James Yonan
201e0e68a2
jsonhelper: added cast() method
Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:23:14 +02:00
James Yonan
9f3afbae91
Json: support parsing from ConstBuffer
Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:23:14 +02:00
James Yonan
e13f1f3859
JSON: added #ifdef OPENVPN_JSON_INTERNAL around code requiring internal JSON lib
Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:23:14 +02:00
James Yonan
d30c6f4e8f
jsonhelper: added get_string_ref() method
Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:23:13 +02:00
James Yonan
121d647fe2
jsonhelper: added get_bool_tristate() method
Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:23:13 +02:00
James Yonan
df1695dc74
jsonhelper: get_bool_optional: removed string interpretation
Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:23:13 +02:00
James Yonan
580bbb9bf0
jsonhelper: allow NAME or TITLE parameters to be an array index
Also, break out json::fmt_name* methods into their own
source file.

NOTE: this code includes some SFINAE, so may need #ifdefs for
Visual Studio.

Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:23:13 +02:00
James Yonan
819cc56962
jsonhelper: minor changes
* Added simple parse() method that only requires
  JSON string to be parsed.

* Added get_string_from_array() method that doesn't
  require title parameter.

* Added cast_array() method that doesn't require
  title parameter.

Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:23:13 +02:00
James Yonan
550d308480
jsonhelper: extend polymorphism to allow string or numerical indices
Updated StringTempl to work with numeric types.

Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:23:12 +02:00
James Yonan
672e07f210
jsonhelper: trivial indentation change
Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:23:12 +02:00
James Yonan
372eb97457
jsonhelper: Use new JSON library implementation.
Also:

* break up some long lines in source code

* added get_uint_optional_via_string() and
  get_uint64_optional_via_string()

Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:23:12 +02:00
James Yonan
04c3aa9b0a
jsonhelper: added format() method outputting to Buffer.
Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:23:11 +02:00
James Yonan
407b83e529
jsonhelper: added get_array() method without title argument.
Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:23:11 +02:00
James Yonan
a01d34deaa
jsonhelper: exists() method should return false if argument is not a JSON object.
Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:23:11 +02:00
James Yonan
3d0d9de34e
jsonhelper.hpp misc changes
* use namespace json instead of class json so that other
  source files can also add stuff to namespace json

* make fmt_name() method public

* added get_string_from_array() method

* added get_(int|uint|uint64)_optional() methods

* added get_(uint|uint64)_via_string() methods

* added some title-free method variants such as get_dict()
  and cast_dict()

Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:23:11 +02:00
James Yonan
cb6914e6a4
copyright: updated to 2017
Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:23:10 +02:00
James Yonan
b8f64a02b7
license : this branch (common) is proprietary, so remove all GPL headers.
Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:23:10 +02:00
James Yonan
6e33ef89c0
jsonhelper: major refactor
* Templatize name and title parameters.
* String construct the json_parse exceptions instead of
  using OPENVPN_THROW.
* Refactor to_x() methods to derive from get_x() methods
  instead of the other way around.
* Added get_uint64() method.
* Added cast_array() method.
* Added format() method.
2020-01-09 12:23:10 +02:00
James Yonan
bfb9833354
jsonhelper : added default_value parameter to get_bool_optional() 2020-01-09 12:23:10 +02:00
James Yonan
6e5b04fd01
jsonhelper : added parse_from_buffer() 2020-01-09 12:23:09 +02:00
James Yonan
760ae4a5f1
jsonhelper : added json::format_compact() methods for formatting JSON into a compact representation without extraneous whitespace. 2020-01-09 12:23:09 +02:00
James Yonan
ff804f93f0
copyright : updated to 2016 2020-01-09 12:23:09 +02:00
James Yonan
b850f4875c
jsonhelper : added json::get_string_optional() method. 2020-01-09 12:23:09 +02:00
James Yonan
8831925837
jsonhelper : added json::exists() method. 2020-01-09 12:23:08 +02:00
James Yonan
90ece7de04
jsonhelper : for consistency, swap the order of title and default_value in to_uint_optional(). 2020-01-09 12:23:08 +02:00
James Yonan
3154ec0f92
jsonhelper : in get_bool_optional(), convert string "true" (case insensitive) to boolean true. 2020-01-09 12:23:08 +02:00
James Yonan
5c25bb7089
jsonhelper.hpp : added new methods parse_from_file(), cast_dict(), and get_array(). 2020-01-09 12:23:08 +02:00
James Yonan
76b5f880b5
jsonhelper : added get_bool_optional(). 2020-01-09 12:23:07 +02:00
James Yonan
042c0194ac
For jsoncpp usage, rename deprecated misspelled method name:
getFormatedErrorMessages -> getFormattedErrorMessages
2020-01-09 12:23:07 +02:00
James Yonan
ba18268dfc
In class json (jsonhelper.hpp):
Added new static method parse().

Modified to_uint_optional() to make 'title' the last
parameter.

Moved to_vector() method.
2020-01-09 12:23:07 +02:00
James Yonan
1e7e8210ab
Added new file openvpn/common/jsonhelper.hpp with convenience methods for dealing with Json::Value objects. 2020-01-09 12:23:07 +02:00
Lev Stipakov
e86b3bef38
endian64.hpp: Add MSVS version of int64 byte swap
Signed-off-by: Lev Stipakov <lev@openvpn.net>
2020-01-09 12:23:06 +02:00
James Yonan
b9b4bb8c55
Endian: use more portable method to determine machine byte order
Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:23:06 +02:00
Arne Schwabe
c8a2405722
Add Clang specific swap 64 bit builtin macro
This fixes build on Android NDK with clang/clang++

Neither the Android libc nor the libc++ used by Android by default
have the __bswap_constant_64 macro.

The more standard include of byteswap.h and bswap_64 exists only on
Linux and Android. Mac OS X defines no function in its includes that
does a byteswap. Therefore keep the compiler internal but choose
Clang's when compiling with Clang.
2020-01-09 12:23:06 +02:00
James Yonan
02d95918e4
Endian: added missing inline
Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:23:06 +02:00
James Yonan
db7c5613f3
HTTP layer: added Websocket support
Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:23:05 +02:00
James Yonan
341d983734
JsonClient/AppServer: full HTTP compression support
* gzip or lz4 supported for standard HTTP.

* lz4 support for websocket.

Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:23:05 +02:00
Lev Stipakov
48444e5513
agent win: implement add_bypass_route
Add /add-bypass-route method, which is called
by socket_protect() call in client before opening
connection to remote.

This is needed to do reconnect to another remote
in case when force-tunneling is used and existing
VPN tunnel is broken.

OVPN3-427

Signed-off-by: Lev Stipakov <lev@openvpn.net>
2020-01-09 12:23:05 +02:00
Lev Stipakov
215c6a0976
win/agent: change event.hpp include path
event.hpp was moved in core from common/ to win/

Signed-off-by: Lev Stipakov <lev@openvpn.net>
2020-01-09 12:23:05 +02:00
Lev Stipakov
2d5f056b65
openvpn/win/event.hpp: move to openvpn3 repo
Signed-off-by: Lev Stipakov <lev@openvpn.net>
2020-01-09 12:23:04 +02:00
Lev Stipakov
bce60fe08b
ovpnagent/win: support for Wintun ring buffers registration
Signed-off-by: Lev Stipakov <lev@openvpn.net>
2020-01-09 12:23:04 +02:00
Lev Stipakov
15a4499a9d
agent: Wintun support for agent
This enables agent to use Wintun instead of tap-windows6
as a tun driver. We pass an optional boolean flag, based on
config setting, from client to agent. That flag is then passed
by agent to TunSetup, which selects tun driver.

Signed-off-by: Lev Stipakov <lev@openvpn.net>
2020-01-09 12:23:04 +02:00
Lev Stipakov
74a51815b0
win agent: properly handle timeout
Sometimes when machine wakes from sleep,
it takes too long for agent service to start. This causes
an error which core treats as fatal and stops connection.

Fix by detecting timeout and throw non-fatal error, which
makes core reconnect.

Signed-off-by: Lev Stipakov <lev@openvpn.net>
2020-01-09 12:23:04 +02:00
Lev Stipakov
ba99bd928c
cmdagent.hpp: Add missing io_context
Adapt to latest core changes.

Signed-off-by: Lev Stipakov <lev@openvpn.net>
2020-01-09 12:23:03 +02:00
James Yonan
2d78ccb803
Added i/o abstraction layer.
Created a lightweight abstraction layer so that another i/o
reactor can be dropped in place of asio.

This commit includes:

* Added ASIO=1 to many "go" scripts that require asio
* Renamed "asio::" to "openvpn_io::".

Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:23:03 +02:00
James Yonan
8604a87e43
copyright: updated to 2017
Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:23:03 +02:00
James Yonan
068cf36233
license : this branch (common) is proprietary, so remove all GPL headers.
Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:23:03 +02:00
James Yonan
cdf5d6c0b4
copyright : updated to 2016 2020-01-09 12:23:02 +02:00
James Yonan
d8610e5e8f
windows cmdagent : updated with new layer 2 virtual methods (none of the methods are current implemented). 2020-01-09 12:23:02 +02:00
James Yonan
78557c54f3
In Windows cmdagent/ovpnagent, make the client exe path available to establish_tun() method. 2020-01-09 12:23:02 +02:00
James Yonan
ebc1292da8
Additional robustness fixes for Windows agent/service:
* When transmitting Windows event objects from client app to
  agent/service, duplicate the event HANDLEs before
  transmission in case the original HANDLEs are closed before
  the agent receives them.  This has a minor disadvantage in
  that the duplicated HANDLEs will leak if the agent/service
  never establishes ownership over them.

* When agent/service receives event HANDLEs, since they have
  already been duplicated in the context of the remote
  process, move (instead of copy) the HANDLEs into the local
  process context by using the DUPLICATE_CLOSE_SOURCE flag
  to DuplicateHandle.

* When agent/service receives event HANDLEs, do some basic
  sanity checks on them before calling async_wait.

* Split agent/service impersonation block into two sections,
  one that can be executed before parent()->establish_tun()
  and one after.  This is done so that any exceptions
  thrown by the pre-establish_tun() block can prevent the
  expensive establish_tun() method from starting.

* In agent/service, call parent()->destroy_tun(os) if any
  exceptions are thrown from http_request_received().
2020-01-09 12:23:02 +02:00
James Yonan
c3e8b60b89
Windows agent/service changes for better robustness:
* Avoid TAP HANDLE leakage on named pipe comm link errors
  when the agent has duplicated the HANDLE but before the
  app has received it by using a Windows Event object
  ("confirm_event") that the agent client can use to assert
  ownership over the HANDLE.  If confirm_event never
  signals, the agent will take responsibility for closing
  the duplicated HANDLE.

* Trigger tun destroy through a Windows Event
  ("destroy_event") instead of a separate API method
  ("/tun-destroy") for better robustness since the Event
  can easily be signaled by the app-side tuncli instance
  destructor without any potential for exceptions.

* Agent client will now detect unexpected agent/service
  process termination and immediately disconnect any
  active session via this error:

    self->parent.tun_error(Error::TUN_IFACE_DISABLED,
                           "service failure");

* /tun-setup API method will now explicitly close any
  pre-existing tun instance before establishing a new
  instance.

* Increased agent client API timeout from 10 to 30 seconds.

* Increased verbosity of agent/service logging in
  agent.log.
2020-01-09 12:23:01 +02:00
James Yonan
c731d2395d
For jsoncpp usage, rename deprecated misspelled method name:
getFormatedErrorMessages -> getFormattedErrorMessages
2020-01-09 12:23:01 +02:00
James Yonan
447868cf44
Implemented Stop support for Windows cmdagent.hpp (via TunWin::SetupBase interface).
Also updated Windows ovpnagent.cpp with Stop hooks
but without implementation.
2020-01-09 12:23:01 +02:00
James Yonan
920ca44c29
In Windows cmdagent.hpp, when parsing returned TAP handle, catch the error case where service is 64 bits and client is 32 bits. 2020-01-09 12:23:01 +02:00
James Yonan
7943a1007b
Windows OpenVPN agent : refactored internal named-pipe API (between non-privileged client and privileged service) to be based on TunBuilderCapture instead of ActionList:
* TAP interface is now opened from the service and
  the TAP HANDLE is communicated back to the client.
  This allows us to configure the TAP driver to
  reject open requests from non-privileged users.

* Old ActionList approach required us to validate and
  execute command lines sent from client to service.
  The new API approach is higher-level and communicates
  at the TunBuilderCapture level instead of using
  lists of command lines (ActionList objects) that must
  be sanity-checked.

* ovpnagent service can now detect client crashes and
  close out an active tun session, preventing network
  lockout.
2020-01-09 12:23:00 +02:00
James Yonan
7f7873d81d
Windows client: added privilege separation layer, including:
1. OpenVPN Agent service -- ovpnagent/win/ovpnagent.cpp
2. OpenVPN agent client -- openvpn/client/win/cmdagent.hpp

Common configuration in openvpn/client/win/agentconfig.hpp

The client and service communicate over a named pipe, and
Windows Vista+ platforms will verify that both client and
server .exe files are running from the same directory.

Build OpenVPN 3 Windows client with OPENVPN_COMMAND_AGENT
to enable the privilege separation layer.
2020-01-09 12:23:00 +02:00
Lev Stipakov
de5662221c
ovpnagent/win: add Visual Studio project files
Signed-off-by: Lev Stipakov <lev@openvpn.net>
2020-01-09 12:23:00 +02:00
Yuriy Barnovych
586e8cc8a8
ovpnagent: Enable pipe name build-time customization
We need to support customization of pipe name in case when few
clients based on ovpnagent running at the same time. Name of
pipe is defined by build-time variable “OVPNAGENT_NAME” (we
already use it as name of Windows service).

Signed-off-by: Yuriy Barnovych <yuriy@openvpn.net>
Jira: UCONNECT-1151
2020-01-09 12:23:00 +02:00
James Yonan
a2962be74e
copyright: updated to 2017
Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:22:59 +02:00
James Yonan
1d974645b4
license : this branch (common) is proprietary, so remove all GPL headers.
Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:22:59 +02:00
James Yonan
3fd389586b
copyright : updated to 2016 2020-01-09 12:22:59 +02:00
James Yonan
08f8563be5
Windows client: added privilege separation layer, including:
1. OpenVPN Agent service -- ovpnagent/win/ovpnagent.cpp
2. OpenVPN agent client -- openvpn/client/win/cmdagent.hpp

Common configuration in openvpn/client/win/agentconfig.hpp

The client and service communicate over a named pipe, and
Windows Vista+ platforms will verify that both client and
server .exe files are running from the same directory.

Build OpenVPN 3 Windows client with OPENVPN_COMMAND_AGENT
to enable the privilege separation layer.
2020-01-09 12:22:59 +02:00
James Yonan
ced729b67f
Make lambda functions mutable that benefit from using std::move() on closure vars
Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:22:58 +02:00
James Yonan
be378a8579
Added i/o abstraction layer.
Created a lightweight abstraction layer so that another i/o
reactor can be dropped in place of asio.

This commit includes:

* Added ASIO=1 to many "go" scripts that require asio
* Renamed "asio::" to "openvpn_io::".

Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:22:58 +02:00
James Yonan
a33bfb08ff
copyright: updated to 2017
Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:22:58 +02:00
James Yonan
b15978552c
license : this branch (common) is proprietary, so remove all GPL headers.
Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:22:57 +02:00
James Yonan
4d4af4255e
copyright : updated to 2016 2020-01-09 12:22:57 +02:00
James Yonan
0b386531ba
Factored out HTTP Server acceptor classes into openvpn/acceptor. 2020-01-09 12:22:57 +02:00
James Yonan
267dcad489
WS::Server, Acceptor::TCP: added bind/close logging when OPENVPN_DEBUG_ACCEPT is defined
Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:22:57 +02:00
James Yonan
0e03f4b21b
Acceptor::TCP: don't set reuseport flag by default on listener socket
Previously, all listener sockets were configured with both
reuseaddr and reuseport.  reuseaddr is reasonable to use as
a default, but reuseport should only be used when different
threads are listening on the same local port/address for
load-balancing purposes.

This patch adds two new socket option flags DISABLE_REUSE_ADDR
and REUSE_PORT, to provide finer-grained control over
these options.

Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:22:56 +02:00
James Yonan
146b143ba1
Make lambda functions mutable that benefit from using std::move() on closure vars
Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:22:56 +02:00
James Yonan
ff207adf05
Added i/o abstraction layer.
Created a lightweight abstraction layer so that another i/o
reactor can be dropped in place of asio.

This commit includes:

* Added ASIO=1 to many "go" scripts that require asio
* Renamed "asio::" to "openvpn_io::".

Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:22:56 +02:00
James Yonan
f89b6984c1
copyright: updated to 2017
Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:22:56 +02:00
James Yonan
160c4f667a
license : this branch (common) is proprietary, so remove all GPL headers.
Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:22:55 +02:00
James Yonan
20a160b723
copyright : updated to 2016 2020-01-09 12:22:55 +02:00
James Yonan
a23ebb0654
Factored out HTTP Server acceptor classes into openvpn/acceptor. 2020-01-09 12:22:55 +02:00
James Yonan
bde3a3ec01
Added i/o abstraction layer.
Created a lightweight abstraction layer so that another i/o
reactor can be dropped in place of asio.

This commit includes:

* Added ASIO=1 to many "go" scripts that require asio
* Renamed "asio::" to "openvpn_io::".

Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:22:55 +02:00
James Yonan
05f6f01772
copyright: updated to 2017
Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:22:55 +02:00
James Yonan
e316c8d82d
license : this branch (common) is proprietary, so remove all GPL headers.
Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:22:54 +02:00
James Yonan
aed8b6c194
copyright : updated to 2016 2020-01-09 12:22:54 +02:00
James Yonan
e8aeff0607
Fixed issue in openvpn/acceptor/namedpipe.hpp when building on pre-Vista Windows: the PIPE_REJECT_REMOTE_CLIENTS flag to CreateNamedPipeA isn't recognized by pre-Vista Windows, so #ifdef out on those platforms. 2020-01-09 12:22:54 +02:00
James Yonan
780fc414c8
Minor fix to namedpipe.hpp: added missing include. 2020-01-09 12:22:54 +02:00
James Yonan
2b0ff516a2
Factored out HTTP Server acceptor classes into openvpn/acceptor. 2020-01-09 12:22:53 +02:00
James Yonan
713d1c9ffc
HTTP: added Alt Routing support to HTTP client/server
Alt Routing allows services on meshed PG nodes to communicate
with services on other nodes via the secure mesh, and without
requiring SSL.

Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:22:53 +02:00
James Yonan
fd5eb53e18
Added i/o abstraction layer.
Created a lightweight abstraction layer so that another i/o
reactor can be dropped in place of asio.

This commit includes:

* Added ASIO=1 to many "go" scripts that require asio
* Renamed "asio::" to "openvpn_io::".

Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:22:53 +02:00
James Yonan
f914b19b5a
Moved asio files from openvpn/common to openvpn/asio
Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:22:53 +02:00
James Yonan
6a005cd487
copyright: updated to 2017
Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:22:52 +02:00
James Yonan
ac4550b413
license : this branch (common) is proprietary, so remove all GPL headers.
Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:22:52 +02:00
James Yonan
4983ec3e03
copyright : updated to 2016 2020-01-09 12:22:52 +02:00
James Yonan
6e3857adc5
ListenerBase : now inherits from preprocessor var OPENVPN_ACCEPTOR_LISTENER_BASE_RC (which may be virtual) and which defaults to non-virtual RC<thread_unsafe_refcount>
This is done for OMI server-side, to allow the OMI object to
be both a socket listener and runcontext client.
2020-01-09 12:22:52 +02:00
James Yonan
3f8b88e40a
Factored out HTTP Server acceptor classes into openvpn/acceptor. 2020-01-09 12:22:46 +02:00
James Yonan
23c14a3e32 AddrPort, PeerAddr: added to_json() methods
Signed-off-by: James Yonan <james@openvpn.net>
2019-12-26 03:44:14 -07:00
James Yonan
6a5430e763 ServerPushList: added JSON parse() method
Signed-off-by: James Yonan <james@openvpn.net>
2019-12-26 03:44:14 -07:00
James Yonan
a9f2055d07 string: added starts_with_delim() function
Signed-off-by: James Yonan <james@openvpn.net>
2019-12-26 03:44:14 -07:00
Arne Schwabe
8ea9b68138 Fix free in RSA external PKI, remove unused return value of EC do_sign
Errors fixed from gcc:

openvpn/openssl/pki/extpki.hpp: In static member function ‘static ECDSA_SIG* openvpn::ExternalPKIECImpl::ecdsa_sign_sig(const unsigned char*, int, const BIGNUM*, const BIGNUM*, EC_KEY*)’:
openvpn/openssl/pki/extpki.hpp:366:11: warning: variable ‘out’ set but not used [-Wunused-but-set-variable]

From Converity scan:

>>>     CID 351295:  Null pointer dereferences  (REVERSE_INULL)
>>>     Null-checking "rsa_meth" suggests that it may be null, but it has already been dereferenced on all paths leading to the check.
117     	  if (rsa_meth)
118     	    RSA_meth_free(rsa_meth);
119     	}

Remove also check from sigout.size() > siglen. The buffer will throw an
exception if the decoded bytes do not fit.
2019-12-18 17:48:50 +01:00
David Sommerseth
d0ab53a5d5
Merge changes applied to coming Core release 2019-12-10 15:20:49 +01:00
Lev Stipakov
d97d4882d9 net30 topology (win): fix incorrect remote calculation
When configuring net30 topology (TAP_WIN_IOCTL_CONFIG_POINT_TO_POINT),
remote value is calculated based on assumption that local address is
network + 2 and remote is network + 1. This holds for openvpn 2.4:

ifconfig 10.8.0.6 10.8.0.5

local 10.8.0.6
network = local & 255.255.255.252 = 10.8.0.4
remote = network + 1 = 10.8.0.5

But this doesn't hold when using VPN server by vpngate:

ifconfig 10.211.1.73 10.211.1.74

local 10.211.1.73
network = local & 255.255.255.252 = 10.211.1.72
remote = network + 1 = 10.211.1.73

Remote is same as local.

To fix, use openvpn2's approach - don't do any assumptions
and use ipconfig's second option as remote value.

Fixes https://github.com/OpenVPN/openvpn3/issues/95 (broken connection to vpngate)

Reported-by: Serathin <https://github.com/Serathin>
Signed-off-by: Lev Stipakov <lev@openvpn.net>
2019-12-05 11:21:15 +01:00
James Yonan
050f994347 Buffer: added some useful debugging info to buffer_full exception
Signed-off-by: James Yonan <james@openvpn.net>
2019-12-05 11:20:10 +01:00
Arne Schwabe
99adaa0e88 Rename openvpnerrstr.c to openvpnerrstr.h
The file is used like a header in all its uses. Having it being a .c
file is a lot more difficult to handle with modern build systems
2019-12-02 14:16:56 +01:00
James Yonan
1ecb82ee2f
kovpn: support disabling compression framing
Signed-off-by: James Yonan <james@openvpn.net>
2019-11-27 18:55:06 +01:00
Arne Schwabe
15e5547849 [OVPN3-492] Add support for external EC certificates/keys
Signed-off-by: Arne Schwabe <arne@openvpn.net>
2019-11-27 17:58:57 +01:00
Arne Schwabe
d159dc7c1c Move RSA external key implementation to its own file
Signed-off-by: Arne Schwabe <arne@openvpn.net>
2019-11-27 17:58:57 +01:00
David Sommerseth
22d0f2bf28 dcocli: Do not use KoTun with ENABLE_PG and USE_TUN_BUILDER
Signed-off-by: David Sommerseth <davids@openvpn.net>
Signed-off-by: Arne Schwabe <arne@openvpn.net>
2019-11-27 17:11:50 +01:00
Arne Schwabe
d1fd4ef1f1 Minor code style clean up
- use explicit for non copy single argument constructor
- add override where applicable

Signed-off-by: Arne Schwabe <arne@openvpn.net>
Signed-off-by: David Sommerseth <davids@openvpn.net>
2019-11-27 17:11:50 +01:00
Arne Schwabe
e7799e32ee Fix missing parameter introduce by add_bypass_routes commit
Signed-off-by: Arne Schwabe <arne@openvpn.net>
2019-11-27 17:11:50 +01:00
Arne Schwabe
3817b8072e Refactor selecting tun methods into a common header file
This fixes DCO client only including iproute and using methods of
TUN_LINUX

Signed-off-by: Arne Schwabe <arne@openvpn.net>
2019-11-27 17:11:50 +01:00
Arne Schwabe
8c9092b56a Rename add_exclude_route to add_route_tunbuilder
The name add_exclude_route is extremely confusing in this context as
it implies that the function only adds exclude routes and not include
routes.

Signed-off-by: Arne Schwabe <arne@openvpn.net>
2019-11-27 17:11:50 +01:00
Arne Schwabe
6228165f37 Implement configuring DCO dev via tun builder
Signed-off-by: Arne Schwabe <arne@openvpn.net>
2019-11-27 17:11:50 +01:00
Arne Schwabe
1e2d7b1c81 Implement opening /dev/net/ovpn via tun builder interface
Signed-off-by: Arne Schwabe <arne@openvpn.net>
2019-11-27 17:11:50 +01:00
Arne Schwabe
913adc6807 Move KoTun::DevConf into its own header file
This allows to include/use this file when the other dependencies of
kodev.hpp are not yet declared. (E.g. logging)

Signed-off-by: Arne Schwabe <arne@openvpn.net>
2019-11-27 17:11:50 +01:00
Arne Schwabe
97881b5c4f Require internal json for sslctx json functions
These functions require methods that are not available if
jsoncp is used as json library

Signed-off-by: Arne Schwabe <arne@openvpn.net>
2019-11-27 16:03:44 +01:00
David Sommerseth
568fdce197
Finalizing OpenVPN 3 release v3.5.2
Signed-off-by: David Sommerseth <davids@openvpn.net>
2019-11-22 15:13:05 +01:00
Lev Stipakov
13cc577053
wintun: fix ring buffer registration
As documentation says:

 > If lpOverlapped is NULL, lpBytesReturned cannot be NULL

While on Windows 10 passing NULL works by accident,
on Windows 7 it crashes.

Signed-off-by: Lev Stipakov <lev@openvpn.net>
(cherry picked from commit 11d705d2c7)
2019-11-22 15:12:23 +01:00
David Sommerseth
1668f1cd9b
cliopthelper: Extend support for encrypted EC private keys
The ClientAPI::EvalConfig::privateKeyPasswordRequired bool flag was not
set correctly when the private key was an encrypted EC key.

This flag is set in EvalConfig by OpenVPNClient::parse_config()
when it calls ParseClientConfig::privateKeyPasswordRequired().

Signed-off-by: David Sommerseth <davids@openvpn.net>
2019-11-21 13:17:42 +01:00
Lev Stipakov
acec6e80ee
mac: add bypass route from socket_protect call
This is used to enable connectivity to a different remote
when force-tunneling is used and current VPN connection is broken.

Signed-off-by: Lev Stipakov <lev@openvpn.net>
2019-11-20 11:22:40 +01:00
Lev Stipakov
a9659a7d1f
tun mac: implement add_bypass_route() method
This method generates /sbin/route commands which
create and delete bypass route for given host.

It is needed to enable connectivity to a different remote
when force-tunneling is used and current VPN connection is broken.

Signed-off-by: Lev Stipakov <lev@openvpn.net>
2019-11-20 11:22:39 +01:00
Lev Stipakov
11d705d2c7
wintun: fix ring buffer registration
As documentation says:

 > If lpOverlapped is NULL, lpBytesReturned cannot be NULL

While on Windows 10 passing NULL works by accident,
on Windows 7 it crashes.

Signed-off-by: Lev Stipakov <lev@openvpn.net>
2019-11-20 11:17:11 +01:00
James Yonan
1719681472
Added HTTP::headers_redact() for redacting basic auth creds from Authorization header
Before debug logging, HTTP headers should be passed through
HTTP::headers_redact() to prevent the creds from being logged.

Signed-off-by: James Yonan <james@openvpn.net>
2019-11-20 11:14:23 +01:00
James Yonan
fd82cec419
logsimple.hpp: OPENVPN_LOG_STRING, OPENVPN_LOG_NTNL: flush output stream
Signed-off-by: James Yonan <james@openvpn.net>
2019-11-20 11:14:23 +01:00
David Sommerseth
02e524dcef
Merge branch 'released' into master 2019-11-20 11:07:22 +01:00
David Sommerseth
f4778a9f65
Finalizing OpenVPN 3 release v3.5.1
Signed-off-by: David Sommerseth <davids@openvpn.net>
2019-11-14 18:46:02 +01:00
David Sommerseth
81d6e5c3c1
Update version to indicate development base version
Signed-off-by: David Sommerseth <davids@openvpn.net>
2019-11-14 18:41:25 +01:00
David Sommerseth
6201b316f5
Merge branch 'hotfix/3.4' into released 2019-11-14 18:39:55 +01:00
David Sommerseth
300e0218dc
Merge hotfix/3.3 into hotfix/3.4 2019-11-13 21:12:41 +01:00
Antonio Quartulli
7f3756336d
httpcli.cpp: perform lock before running async DNS resolution
d8d14e1991 implemented a new logic which
allows the DNS resolution to happen in a detachable thread. Since then,
we must execute async_resolve_lock() before performing the resolution so
that the main event queue is kept alive, while the core is busy
resolving the hostname.

Failing to do so will result in the main event queue terminating due to
"no events in the queue" and thus closing the core process.

Add lock (and related cancel) around resolution operation to guarantee
the core process stays alive during resolution.

Signed-off-by: Antonio Quartulli <antonio@openvpn.net>
2019-11-08 17:19:48 +01:00
Antonio Quartulli
7f0abcb3c3
httpcli.cpp: remove unused resolver member
Signed-off-by: Antonio Quartulli <antonio@openvpn.net>
2019-11-08 17:19:47 +01:00
David Sommerseth
7bd55e0a7b
mbedtls: Add support for --verify-x509-name
This is the mbed TLS counterpart of the OpenSSL change in
commit c069b7cf5fb9ba47.

Signed-off-by: David Sommerseth <davids@openvpn.net>
2019-11-08 10:00:45 +01:00
David Sommerseth
fc060bd317
mbedtls: Move x509_get_subject() and x509_get_common_name() to an independent file
This is the mbed TLS counter part to the OpenSSL change in
commit e0fd92f30756.  These two methods are generic and not
tied to the MbedTLSContext in any particular way.

This is needed to be able to add a unit test for the x509_get_*()
functions.

Signed-off-by: David Sommerseth <davids@openvpn.net>
2019-11-08 10:00:43 +01:00
David Sommerseth
7900c71f5c
mbedtls: Add missing include file in x509cert.hpp
This file uses BufferAllocated, which is defined in
openvpn/buffer/buffer.hpp

Signed-off-by: David Sommerseth <davids@openvpn.net>
2019-11-08 10:00:42 +01:00
David Sommerseth
5f881fe7bf
openssl: Move generic X.509 cert extraction code to a separate file
This moves generic OpenSSL related functions used to extract X.509
certificate information to an independent file which can be used more
freely.  This code does not contain anything specific to the
OpenSSLContext class group and works nicely as a separate unit.

This is needed to be able to add unit test code for the x509_get_*()
functions.

Signed-off-by: David Sommerseth <davids@openvpn.net>
2019-11-08 10:00:40 +01:00
David Sommerseth
5839869202
openssl: Add --verify-x509-name support
This implements the --verify-x509-name support for builds with OpenSSL.
This change requires the x509_get_subject() to be extended to provide
the subject field in a newer format, which requires using a different
OpenSSL API.  Since we have code which might require the old format as
well, x509_get_subject() will default to use the old format.

The --verify-x509-name supports matching both against the full subject
line and the X.509 Certificate Common Name, which means we need to check
which mode is configured and extract the proper value before calling the
VerifyX509Name::verify() method.

Signed-off-by: David Sommerseth <davids@openvpn.net>
2019-11-08 10:00:39 +01:00
David Sommerseth
71a14a3553
verify-x509-name: Implement base class for processing this option
This new VerifyX509Name class handles both extracting and parsing the
appropriate --verify-x509-name option and is able to verify if a given
subject or hostname is matching the expectation.

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

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

Signed-off-by: David Sommerseth <davids@openvpn.net>
2019-11-07 16:30:03 +01:00
Arne Schwabe
6ae997472c Add macOS implementation in cpu time helper and adjust unit test
Signed-off-by: Arne Schwabe <arne@openvpn.net>
2019-11-07 09:58:55 +01:00
Arne Schwabe
f6aada9577 Tempfile.hpp is unix only, add error when including it on win32
Signed-off-by: Arne Schwabe <arne@openvpn.net>
2019-11-07 09:58:54 +01:00
Arne Schwabe
204d7e4a20 Replace OPENVPN_INSECURE_RANDOM with FakeRandom class
This avoids the mistake of using the insecure MTRand in anything but
a unit test and has the advantage that not all MTRand in a unit test
suite report being secure

Signed-off-by: Arne Schwabe <arne@openvpn.net>
2019-11-07 09:58:54 +01:00
Arne Schwabe
54fbe7604c Fix file modifcation time retrieval stat.hpp on macOS
Signed-off-by: Arne Schwabe <arne@openvpn.net>
2019-11-07 09:58:54 +01:00
Arne Schwabe
da41ea24d8 Require internal json for sslctx json functions
These functions require methods that are not available if
jsoncp is used as json library

Signed-off-by: Arne Schwabe <arne@openvpn.net>
2019-11-07 09:58:54 +01:00
Arne Schwabe
f5f9b4d57c Add missing override keywords in openssl/sslctx.hpp
Signed-off-by: Arne Schwabe <arne@openvpn.net>
2019-11-07 09:58:54 +01:00
David Sommerseth
8ffe1de50e
Release of OpenVPN 3 Core Library 3.5
Merge branch 'releaseprep/3.5' into released
2019-11-06 17:06:49 +01:00
David Sommerseth
c441a01d63
Finalizing OpenVPN 3 release v3.4.1
Signed-off-by: David Sommerseth <davids@openvpn.net>
2019-10-31 11:15:41 +01:00
David Sommerseth
15c71c44e9
Finalizing OpenVPN 3 release v3.3.2
Signed-off-by: David Sommerseth <davids@openvpn.net>
2019-10-31 11:10:06 +01:00
David Sommerseth
595ce9ac7d
Release of OpenVPN 3 Core Library version 3.4
Signed-off-by: David Sommerseth <davids@openvpn.net>
2019-10-24 15:29:22 +02:00
David Sommerseth
6c68c33513
Update version.hpp for releaseprep/3.5
Signed-off-by: David Sommerseth <davids@openvpn.net>
2019-10-24 15:07:39 +02:00
David Sommerseth
29e060ffb3
CryptoAlgs: Don't report any digests for ciphers not using them
The CryptoDCSettings::digest() method returns SHA1 digest when the
cipher is an AEAD cipher.  This is incorrect, as AEAD ciphers does not
use digests for authentication at all; the authentication is an
integral part of the AEAD cipher itself.

To solve this, the CryptoAlgs::AlgFlags has been extended with a new
F_NO_CIPHER_DIGEST flag which is expected to be set on ciphers not
depending on any digests for authentication, like AES-GCM/AEAD
ciphers.  A new method, use_cipher_digest(), will return True if
the cipher depends on a digest for authentication.

Signed-off-by: David Sommerseth <davids@openvpn.net>
2019-10-24 14:48:22 +02:00
Lev Stipakov
12763bbbb8 win/client/tunsetup.hpp: implement add_bypass_route() method
This method, which is called by agent, generates netsh commands
to add/remove bypass route.

While we also do it in adapter_config() call, with force tunneling
and tun_persist this functionality is required before opening tun,
therefore need in a separate method.

Signed-off-by: Lev Stipakov <lev@openvpn.net>
2019-10-10 15:23:17 +03:00
Lev Stipakov
0d7143c4bf transport: enable socket_protect call for all platforms
This enables socket_protect call for all transports / platforms
with default implemenation being no-op.

This is needed for better round-robin DNS
fix for Connect clients (OVPN3-427).

Signed-off-by: Lev Stipakov <lev@openvpn.net>
2019-10-10 15:23:17 +03:00
Lev Stipakov
a6cae41285 cliopt.hpp: disable remote list bypass for agent-enabled build
When tun_persist is set, we do pre-resolve and install bypass routes
for all remotes to be able to reconnect in force-tunneling case and tunnel is broken.
This is sub-optimal, since DNS may change during VPN session and there is no need
to have bypass route for remote A when we are connected to remote B.

Following commits will add bypass route before opening tunnel.

Signed-off-by: Lev Stipakov <lev@openvpn.net>
2019-10-10 15:23:17 +03:00
Antonio Quartulli
3166957e2e
add error codes for better error management at profile parsing time
Prefix error messages with a predefined string of the form:

ERR_PROFILE_xxxxx:

This way a user can parse the prefix and get a better understanding of
the error, without relying on the sole message.

Signed-off-by: Antonio Quartulli <antonio@openvpn.net>
2019-10-09 17:58:05 +02:00
David Sommerseth
7db7a009b0
proto: Client complains about stub compressors
When connecting to a server which pushes a stub compressor and the
client has compression disabled, it will complain about it in the log.

  > Server has pushed compressor COMP_STUBv2, but client has disabled
    compression, switching to asymmetric

This is confusing, since stub compressors does not compress.  No need to
confuse the users, so we just remove the warning in this case.

Signed-off-by: David Sommerseth <davids@openvpn.net>
2019-10-04 11:56:09 +02:00
David Sommerseth
8cab79540d
compression: Extend compression alert to include server pushes
Extend the CompressionEnabled event to also consider compression mode
pushed by the server.

Signed-off-by: David Sommerseth <davids@openvpn.net>
2019-10-02 17:36:48 +02:00
David Sommerseth
67b4641a99
CompressContext: Add is_any_stub() method
This method is used to identify if any of the stub compression types is
in use.

Signed-off-by: David Sommerseth <davids@openvpn.net>
2019-10-02 17:36:48 +02:00
David Sommerseth
cdf9e7bece
compression: Issue an Event if compression is activated
If the connection enables compression, ensure the UI can get a
notification about this and evaluate if the should be warned or not.

Signed-off-by: David Sommerseth <davids@openvpn.net>
2019-10-02 17:36:48 +02:00
David Sommerseth
2ae73415d2
deps: Update to mbedtls-2.7.12
This Mbed TLS update contains a security hotfix for a new ECDSA related
side-channel attack.

URL: https://tls.mbed.org/tech-updates/security-advisories/mbedtls-security-advisory-2019-10
CVE: 2019-16910

Signed-off-by: David Sommerseth <davids@openvpn.net>
2019-10-01 18:01:09 +02:00
James Yonan
7ce7b52b7c MTRand: added OPENVPN_INSECURE_RANDOM compile flag that allows MTRand to masquerade as a secure RNG
This is useful for unit tests that must produce deterministic results.

You would never want to define this in production, because it turns off
the check that prevents non-crypto RNGs from being used for crypto
purposes.

Signed-off-by: James Yonan <james@openvpn.net>
2019-09-25 19:51:27 +02:00
James Yonan
85e7e49f72 MTRand: added constructor accepting an initialization seed
Initializing MTRand with a constant seed is useful for unit tests
that need to produce deterministic output.

Signed-off-by: James Yonan <james@openvpn.net>
2019-09-25 19:51:27 +02:00
James Yonan
1fa3229a10 IPv4, IPv6: added #include <openvpn/common/hash.hpp>
Signed-off-by: James Yonan <james@openvpn.net>
2019-09-25 19:51:27 +02:00
Lev Stipakov
d2a2601b2f Wintun: unmap ring buffers
This unmaps ring buffers on tun destory
and prevents memory (working set) leak on reconnect.

I didn't fix it earlier because of Working Set is not visible in
Task Manager, had to use ProcessExplorer.

Signed-off-by: Lev Stipakov <lev@openvpn.net>
2019-09-12 10:47:40 +03:00
David Sommerseth
e320bc63ff
openssl: Improve OpenSSLContext fencing against multiple declarations
OpenSSLContext::SSL::ssl23_method_client_ and
OpenSSLContext::SSL::ssl23_method_server_ are only defined if the
OPENSSL_VERSION_NUMBER is below 0x10100000L.  But this will still make
multiple compilation units fail, due to how the various #include lines
are ordered and used.  This can eventually lead to multiple declarations
of ssl23_method_client_ and ssl23_method_server_ - which happens to
coreUnitTests on RHEL-7.

We add an additional defined(OPENVPN_NO_EXTERN) test to be sure this is
really not declared unless externs are expected to be declared.

Signed-off-by: David Sommerseth <davids@openvpn.net>
2019-09-11 20:21:33 +02:00
David Sommerseth
2f8fe2d318
openssl: Missing inline keyword in a couple of compat functions
Two of the OpenSSL API compat function declarations in compat.hpp was
missing the 'inline' keyword.  Without this keyword, builds using
multiple compilation units (such as the coreUnitTests) would fail due to
multiple declarations of these functions.

Signed-off-by: David Sommerseth <davids@openvpn.net>
2019-09-11 20:21:33 +02:00
James Yonan
32b984c0ff enum_dir: use a function template
Signed-off-by: James Yonan <james@openvpn.net>
2019-09-10 14:08:09 -06:00
James Yonan
725ee04593 VPNServerNetblock::Netblock::to_string(): show prefix_len
Signed-off-by: James Yonan <james@openvpn.net>
2019-09-09 21:07:13 -06:00
James Yonan
409d1c52b8 ManClientInstance::Send::describe_user(): added bool show_userprop parameter
Signed-off-by: James Yonan <james@openvpn.net>
2019-09-09 21:05:11 -06:00
James Yonan
e05fc16b20 string::indent(): try to fix all the corner cases
1. Don't emit spaces if the input string is empty.
2. Don't emit spaces after the last newline in the input string.

Signed-off-by: James Yonan <james@openvpn.net>
2019-09-09 21:01:30 -06:00
James Yonan
4e1645ea80 RunContext: mark virtual Stop* async_stop() with override attribute
Signed-off-by: James Yonan <james@openvpn.net>
2019-09-07 00:18:00 -06:00
James Yonan
80b45731eb ICMPv6: added DEST_UNREACH code
Signed-off-by: James Yonan <james@openvpn.net>
2019-09-06 22:24:57 -06:00
James Yonan
679003094d AsioTimerSafe: refactor to allow as drop-in replacement for AsioTimer
Signed-off-by: James Yonan <james@openvpn.net>
2019-09-06 22:24:57 -06:00
James Yonan
f7845578f1 RunContext: check for halt in timer closure
Signed-off-by: James Yonan <james@openvpn.net>
2019-09-06 22:24:57 -06:00
James Yonan
84483eda25 AsioPolySock: add support for socket shutdown
Signed-off-by: James Yonan <james@openvpn.net>
2019-09-06 22:24:57 -06:00
James Yonan
1b3402aec3 tcplinkcommon.hpp: added missing include
Signed-off-by: James Yonan <james@openvpn.net>
2019-09-06 22:24:57 -06:00
James Yonan
2e26c7565c time: added nanotime_t typedef
Signed-off-by: James Yonan <james@openvpn.net>
2019-09-06 22:24:57 -06:00
James Yonan
c3c8ab7f6b string: added additional detail to split() comment
Signed-off-by: James Yonan <james@openvpn.net>
2019-09-06 22:24:56 -06:00
James Yonan
95ce4f22c8 string: added to_delim() method then redefined first_line() method to use it
Signed-off-by: James Yonan <james@openvpn.net>
2019-09-06 22:24:56 -06:00
James Yonan
448218b1e1 string: added add_leading() method
Signed-off-by: James Yonan <james@openvpn.net>
2019-09-06 22:24:56 -06:00
James Yonan
e3b0bf4f5c MSF iterator: allow conversion from ordinary iterator and added exists() method
Also added better comments for MSF::find().

Signed-off-by: James Yonan <james@openvpn.net>
2019-09-06 22:24:56 -06:00
James Yonan
11412ac50a AsioPolySock: in remote_endpoint_str() method, test for alt_routing_enabled()
Signed-off-by: James Yonan <james@openvpn.net>
2019-09-06 22:24:56 -06:00
James Yonan
9fb4e705f9 Added TimeSkew to skew a time duration by a random flux
Signed-off-by: James Yonan <james@openvpn.net>
2019-09-06 22:24:56 -06:00
James Yonan
7496383002 write_binary_atomic: reduce the length of the temporary filename
Linux has a filename maximum of 255 chars, but we need to
be careful about the composition of the temporary filename
so that we don't exceed this limitation on the temporary,
even when the original is within the limit.

Signed-off-by: James Yonan <james@openvpn.net>
2019-09-06 22:24:56 -06:00
James Yonan
b31d9c0191 auth-token-user: increase size limit to 340 chars
Since the auth-token-user directive (that is pushed from
server to client) is base64-encoded, increase the size
to support a pre-base64-encoded username length
of 256 characters.

Signed-off-by: James Yonan <james@openvpn.net>
2019-09-06 22:24:56 -06:00
James Yonan
c82644c03a Added BufferLineIterator
Iterate over the lines in a buffer by returning
a sub-buffer for each line.  Zero-copy.

Signed-off-by: James Yonan <james@openvpn.net>
2019-09-06 22:24:56 -06:00
James Yonan
115cb656b6 RandomAPI: added randbyte() and randbool() methods
Signed-off-by: James Yonan <james@openvpn.net>
2019-09-06 22:24:56 -06:00
James Yonan
4fa8348689 RunContext: ASIO SIGNAL message now shows signal name rather than number
Signed-off-by: James Yonan <james@openvpn.net>
2019-09-06 22:24:56 -06:00
James Yonan
ebfce58513 Added StaticBuffer, a constant-length Buffer for writing that cannot be extended
Signed-off-by: James Yonan <james@openvpn.net>
2019-09-06 22:24:56 -06:00
James Yonan
c8f9cb88a4 string::split(): call reserve() on return vector
Signed-off-by: James Yonan <james@openvpn.net>
2019-09-06 22:24:56 -06:00
James Yonan
f15e566065 read_binary_unix_fast: should return an int (i.e. errno), not a bool
Signed-off-by: James Yonan <james@openvpn.net>
2019-09-06 22:24:56 -06:00
James Yonan
60501b4513 random: factor out rand32_distribute() from RandomAPI::randrange32()
This is done so that rand32_distribute() can be used for
hash seeds as well.

Signed-off-by: James Yonan <james@openvpn.net>
2019-09-06 22:24:56 -06:00
Lev Stipakov
90123495a5 wintun: get device interfaces list only once
Instead of getting device interfaces list for every adapter,
do it just one.

Signed-off-by: Lev Stipakov <lev@openvpn.net>
2019-09-05 13:45:41 +03:00
Lev Stipakov
ec790df73b wintun: read packets in bulk
Instead of reading single packet and calling
asio::post (which incurs overhead) to read next one,
continue reading packets until ringbuffer is empty (head == tail).

According to tests, this increases read performance
by 40% (from 1.25 to 1.70 Gbit/s).

Signed-off-by: Lev Stipakov <lev@openvpn.net>
2019-09-05 13:45:41 +03:00
Lev Stipakov
0f85d3f729 wintun: use correct io_context when performing initial read
Without specifying io_context, ASIO will use system
executor, which creates separate thread pool and runs
read() in a wrong, non openvpn core, thread.

Signed-off-by: Lev Stipakov <lev@openvpn.net>
2019-09-05 13:45:41 +03:00
Lev Stipakov
a6151cdeab wintun: use auto-reset events
Wintun documentation clearly states that we must use auto-reset events in ring buffers.
Auto-reset sets event back to non-signalled state after calling WaitForSingleObject.
Without auto-reset and explicit ResetEvent call we got a busy loop.

To avoid confusion move event.hpp from common/ to win/, since it is
Windows-specific code.

Signed-off-by: Lev Stipakov <lev@openvpn.net>
2019-09-05 13:45:41 +03:00
David Sommerseth
a376cdad03
version: Preparing for 3.4 release work
Signed-off-by: David Sommerseth <davids@openvpn.net>
2019-08-29 18:53:41 +02:00
David Sommerseth
44725ad094
ssl: Fix building with OpenSSL 1.0.2
OpenSSL 1.1.0 introduces OpenSSL_version() function and the
OPENVPN_VERSION macro.  Since they are not defined in older OpenSSL
versoins, building breaks.

The usage of OpenSSL_version() and OPENSSL_VERSION where introduced with
commit 23959fa705

Signed-off-by: David Sommerseth <davids@openvpn.net>
2019-08-29 17:45:45 +02:00
David Sommerseth
efe3f1f635
version: Reset version reference for git master
Signed-off-by: David Sommerseth <davids@openvpn.net>
2019-08-29 17:27:57 +02:00
Arne Schwabe
8c79c06d94 Make tls-crypt/tls-cryptv2 compile with multiple compilation units
This changes the the non constexpr expression to constexpr so that
they can be used in multiple compilation units
2019-08-29 16:59:33 +02:00