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

338 Commits

Author SHA1 Message Date
Arne Schwabe
708be87c72
[OSSL 3.0] Implement using a library context for OpenSSL 3.0
This allows use to load non default providers while also not touching
the default library context. THis is necessary to have profile with and
without legacy library for example

Signed-off-by: Arne Schwabe <arne@openvpn.net>
2021-11-12 20:58:30 +01:00
Arne Schwabe
de0d52b7ce [OSSL 3.0] Use new EVP_MAC API for HMAC implementation
The old API is deprecated in OpenSSL 3.0 and the new API does not yet
exist in OpenSSL 1.1. Emulating the new API or using one class with
ifdefs would be more complex than just having two implementations. So
this adds a new implementation for OpenSSL 3.0.

Signed-off-by: Arne Schwabe <arne@openvpn.net>
2021-11-12 14:27:12 +01:00
Arne Schwabe
88b2906a2c
Rework block-ipv6 to also allow blocking ipv4 and remove IV_IPV6
Since IPv4/IPv6 should be treated equally, we should have also
the opportunity to block IPv4. With this change we follow the API
that also Android provides and expliticly tell tunbuilder what to
do with address families that are not used by the VPN. If a
address family is used by the VPN, nothing changes.

This also remove IV_IPV6 as it is not used.
2021-10-27 20:15:26 +02:00
Heiko Hund
0d90ccbb19 RemoteList unittest: extend BulkResolve test
Add cache lifetime related tests.

  * define cache-lifetime
  * override lifetime via push
  * override decayed cache
  * make sure unresolvable items are kept during re-run
  * make sure indexed items can be updated, with addr index reset
  * make sure valid cache entries stay untouched

Signed-off-by: Heiko Hund <heiko@openvpn.net>
2021-09-28 15:29:03 +02:00
Heiko Hund
fda6d1bf1b RemoteList unittest: silence sign-compare warning
Signed-off-by: Heiko Hund <heiko@openvpn.net>
2021-09-28 15:29:03 +02:00
Heiko Hund
54e2d77f89 make RemoteList::get_item() return a RCPtr
Returning a reference can be harmful, since Items can potentially disappear
during lookup of hostnames. Thus, return a refcounted Ptr instead, so
that external references to internal data doesn't restrict RemoteList in
its daily business.

Signed-off-by: Heiko Hund <heiko@openvpn.net>
2021-09-28 15:29:03 +02:00
Heiko Hund
c540642c87 rename RemoteList::PreResolve to BulkResolve
Since we're now using it to also re-lookup stale RemoteList items the
new name makes more sense. Also changed the NotifyCallback method to
bulk_resolve_done().

Signed-off-by: Heiko Hund <heiko@openvpn.net>
2021-09-28 15:29:03 +02:00
Heiko Hund
f60a9f1826 add unit test for RemoteList traversal
Test that all addresses added from the resolver results are tried,
when iterating through the RemoteList with next().

Signed-off-by: Heiko Hund <heiko@openvpn.net>
2021-09-28 15:29:03 +02:00
Arne Schwabe
73890429d2
Implement external PKI emulation with OpenSSL
This uses the rather lowlevel EVP_* interfaces directly instead of
using OpenVPN's own PKI classes since this a very specific code
and reusability outside the testing scope is very limited.

Signed-off-by: Arne Schwabe <arne@openvpn.net>
2021-09-22 14:06:34 +02:00
Mark Deric
989d2f590a
WIP Fix the rhel7 unit test target failure
This might not be the final fix.  Note the extensive code comment
inside the cmake file if().  The comment suggest a potentially better
fix, but it's unlikely.

Signed-off-by: Mark Deric <jmark@openvpn.net>
2021-09-22 14:04:48 +02:00
Lev Stipakov
fd0655969d
Merge release of OpenVPN Core library 3.6.4 to master 2021-09-22 13:56:37 +02:00
Heiko Hund
aca0b7bf03 don't limit peer-fingerprint option size
Since in a config file we support both, multiple --peer-fingerprint options
as well as multiple fingerprints within a <peer-fingerprint> section, a
maximum size doesn't make much sense. Other inline sections do not limit
the size either and the individual fingerprint size is checked when
parsing them individually.

Signed-off-by: Heiko Hund <heiko@openvpn.net>
2021-09-07 14:41:01 +02:00
James Yonan
ea08b935f0 unittests: added SaveCurrentLogObject
When a test steps on Log::global_log, save and restore previous
Log::global_log so as not to mess up other tests when running a
multiple-compilation-unit build.

Signed-off-by: James Yonan <james@openvpn.net>
2021-08-17 13:07:40 -06:00
James Yonan
905ee72fe3 ClientProto: added OPENVPN_DISABLE_AUTH_TOKEN for debugging to disable transmission of auth token to server
Signed-off-by: James Yonan <james@openvpn.net>
2021-08-17 13:07:40 -06:00
James Yonan
303a39ad6c SafeString: use timing-attack-resistant crypto::str_neq for comparisons
Also added unit test.

Signed-off-by: James Yonan <james@openvpn.net>
2021-08-17 13:07:40 -06:00
Heiko Hund
634e58e23b ovpncli: add open_url support for unixoid OSes
Open the user's default browser for OPEN_URL and WEB_AUTH dynamic
auth requests.

Signed-off-by: Heiko Hund <heiko@openvpn.net>
2021-08-11 22:37:24 +02:00
Heiko Hund
0c57e23aca ovpncli: support CR_TEXT type challenge/response
Support CR_TEXT type challenge/response exchanges. The challenge flags are
ignored currently, but displayed with the challenge text for debug purposes.
Thus, input is always echoed and it is assumed that a response is
required.

Signed-off-by: Heiko Hund <heiko@openvpn.net>
2021-08-10 14:17:30 +02:00
Lev Stipakov
613aa6bf7a
Win: support for local DNS resolvers
Local DNS resolvers, such as Umbrella Roaming Client,
change DNS settings on adapters to 127.0.0.1.

This may not work with openvpn3 because:

 - NRPT rule might be created for "." zone,
which redirects all DNS requests to the server
specified in rule. This takes precendence over adapters'
DNS settings.

 - DNS requests might be blocked on all adapters
except TAP (tap-windows6/wintun/ovpn-dco-win) to prevent
DNS leaks.

To enable compatibility with local DNS resolvers, add
"allowLocalDnsResolvers" core config option, which,
when enabled, makes core to

 - avoid creating NRPT rule for "." zone

 - permit DNS requests to 127.0.0.1 / ::1

Signed-off-by: Lev Stipakov <lev@openvpn.net>
2021-08-10 15:00:58 +03:00
Heiko Hund
bff784ab25 remove class RemoteList c'tor RNG default value
Instead of throwing an exception with --remote-random-hostname, when
no RNG is present during construction, we treat an explicit null RNG
as a choice not to randomize the hosts. To make that choice explicit,
the default value for the RNG is removed, so that callers need to
decide which behavior they want.

Closes #53 in the openvpn3-linux issue tracker.

Signed-off-by: Heiko Hund <heiko@openvpn.net>
2021-08-03 15:35:51 +02:00
James Yonan
5231fa35ad
PacketStream: change message size validation logic to support growable buffers for DNS-over-TCP
In PacketStream, don't validate upper bound on message size
if BufferAllocated::GROW is set, allowing it to range up to
64kb.

Signed-off-by: James Yonan <james@openvpn.net>
2021-08-03 10:42:35 +02:00
James Yonan
abd1c5b208
PacketStream: minor cleanup and added a unit test
Removed declared_size_defined in favor of just setting
declared_size to a special value (SIZE_UNDEF) when it's
undefined.

Signed-off-by: James Yonan <james@openvpn.net>
2021-08-03 10:42:35 +02:00
James Yonan
95852fd24a
unittests: added THROW_FMT(...) convenience macro to throw an exception with printf-style argument substitution
Example:

  if (expect_throw != actual_throw)
    THROW_FMT("validate_size: bad throw, expect=%s, actual=%s, FC=%s size=%s",
	      expect_throw,
	      actual_throw,
	      fc.info(),
	      size);

Signed-off-by: James Yonan <james@openvpn.net>
2021-08-03 10:42:31 +02:00
Mark Deric
3cd0652d1e Add the getJoinedString() function
Useful in unit tests for which the input vector should be properly
sorted by the code under test.  This function is very similar to
getSortedJoinedString(), but it avoids sorting.  Because of the
similarity, the getSortedJoinedString() function is refactored to use
the new getJoinedString() function.

Signed-off-by: Mark Deric <jmark@openvpn.net>
2021-08-02 08:42:00 -07:00
Arne Schwabe
98f5b59a07 Document WEBAUTH and implement it as auth pending method in demo client
Signed-off-by: Arne Schwabe <arne@openvpn.net>
2021-07-28 14:50:06 +02:00
James Yonan
88ca59e0f6 unittests: helper now defines REGEX_WORKS to 1 if <regex> implementation is usable, and 0 otherwise
Signed-off-by: James Yonan <james@openvpn.net>
2021-07-03 13:10:01 -06:00
James Yonan
39719d64eb ProtoContext: added keepalive_timeout_early parameter
keepalive_timeout_early defines the keepalive_timeout
parameter early in the connection before the KeyContext
reaches ACTIVE.

It is set via the optional third parameter to the
"keepalive" directive, for example:

  keepalive 1 8 4

sets keepalive_timeout_early to 4 seconds.  If unspecified,
keepalive_timeout_early defaults to keepalive_timeout.

keepalive_timeout_early is useful on the server side to
reduce the resource footprint of abandoned connections,
and can be tuned to mitigate DDoS and UDP amplification
attacks.

Signed-off-by: James Yonan <james@openvpn.net>
2021-07-03 13:10:01 -06:00
Heiko Hund
dd104e8392 make it possible to specify dc algorithms
DCO only supports a limited set of ciphers, currently it is
discovered quite late if a unsupported algorithm is configured
(or pushed).

This introduces CryptoAlgs::allow_dc_algs() with which the
supported set of data channel algorithms can be specified.

The DCO code makes use of this, at the time a new_controller()
is created.

Signed-off-by: Heiko Hund <heiko@openvpn.net>
2021-06-18 15:09:35 +02:00
Lev Stipakov
d31620d0c6
agent mac: move from common
Windows agent has been moved from common to core,
so for consistency move mac agent too.

Since agent and agent-enabled client depend on jsoncpp,
also move jsoncpp build scripts.

Signed-off-by: Lev Stipakov <lev@openvpn.net>
2021-06-10 23:06:24 +02:00
James Yonan
0670c1606b proto test: retry up to 5 times to prevent errors from blowing up the test
By default, the proto test uses a relatively small
handshake_window to intentionally trigger
KEV_NEGOTIATE_ERROR, so that we can test mid-session error
recovery.  However if KEV_NEGOTIATE_ERROR is hit on the
first primary key (i.e. first KeyContext with key_id == 0),
it is fatal to the session and will trigger a disconnect.

This change introduces a retry to prevent this
low-probability, false-positive corner case from
blowing up the test.

Signed-off-by: James Yonan <james@openvpn.net>
2021-05-31 23:21:30 -06:00
James Yonan
e9fef02f52 unit tests: modified JY_ASSERT macros to use "do { ... } while (0)" syntax for better statement semantics
Signed-off-by: James Yonan <james@openvpn.net>
2021-05-31 13:34:44 -06:00
Heiko Hund
51bd6d4201 use DCO opportunistically
If DCO support is compiled in, detect if it is available (i.e. Windows driver
or Linux kernel module is loaded) and then use it, if it is.

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

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

Signed-off-by: Heiko Hund <heiko@openvpn.net>
2021-05-27 17:20:24 +02:00
Heiko Hund
5f3f4e82ae fix potential division by zero in compression test
Signed-off-by: Heiko Hund <heiko@openvpn.net>
2021-05-18 06:13:31 +02:00
Heiko Hund
deccb722ec always free allocated memory in base64 test
In case of an assertion throwing an exception decdata would never be
freed from the heap. Use a unique_ptr, so that stack unwinding does the
job in any case.

Signed-off-by: Heiko Hund <heiko@openvpn.net>
2021-05-18 06:13:12 +02:00
Heiko Hund
e2d252ef4a
add API to override IP protocol version
The new element ClientAPI::Config::protoVersionOverride can be set
to 4 or 6 respectively, to override the transport protocol IP version
used by RemoteList::Item entries. Clients can force all --remotes
to use IPv4 or IPv6 using this entry, if they know that only one of
the two is available in the current network.

Signed-off-by: Heiko Hund <heiko@openvpn.net>
2021-05-05 19:46:58 +02:00
Heiko Hund
f1bdbe5088
fix handling of --proto option
Make it possible to enforce the protocol family by appending 4/6 to
to the protocol, e.g. tcp6 or udp4. While it is already possible to
have protocol options like these in the configuration, they are not
enforced so far. Thus you could still be connected to a v6 address
even though the config requested v4 only.

Since v2.3 the openvpn 2.x series behaves like this. So, this is also
to catch up with the behavior there.

Signed-off-by: Heiko Hund <heiko@openvpn.net>
2021-05-05 19:46:57 +02:00
Heiko Hund
e9a903fd9f add support for the --peer-fingerprint option
This option lets you specify the SHA256 fingerprint of a peer's self-signed
certificate. The peer's certificate, presented during connection bring-up,
is compared to the fingerprint. The connection fails if it doesn't
match.

So, this serves as an easy, yet secure, alternative to setting up a PKI,
but can also be used in conjunction with one to add one more check during
leaf certificate validation.

The option can also be given as inline block, for easier management for
multiple fingerprints:

  <peer-fingerprint>
  00:11:22:33:...:BB:CC:DD:FF
  BB:CC:DD:FF:...:00:11:22:33
  </peer-fingerprint>

Signed-off-by: Heiko Hund <heiko@openvpn.net>
2021-04-28 23:56:22 +02:00
David Sommerseth
2a5f0ee76f
docs: Update README
The README file had several deprecated ways of building various test
binaries.  Clean up this and direct users towards using CMake
everywhere.

The change to test/ssl/CMakeLists.txt covers various build-time
parameters the deprecated build script supported.

Signed-off-by: David Sommerseth <davids@openvpn.net>
2021-04-22 12:54:34 +02:00
David Sommerseth
38f2a08d2b
cmake: Clean up duplications
The CMakeLists.txt settings from the project root directory are
inherited by the defined subdirectories automatically.

Also switch to a simpler way of setting the CMAKE_MODULE_PATH.
According to the CMake documentation, this variable is empty by
default [1] and should not need to pull in existing settings.

Finally remove the comment regarding CMake's use case, as we are
moving towards full CMake support for OpenVPN 3.

Signed-off-by: David Sommerseth <davids@openvpn.net>
2021-04-22 12:54:26 +02:00
Lev Stipakov
e9c62c1b08
Add vcpkg port for dco-win
Port script only copies uapi header, same way it is done for tap-windows6.

Signed-off-by: Lev Stipakov <lev@openvpn.net>
Signed-off-by: Heiko Hund <heiko@openvpn.net>
2021-04-14 22:44:52 +02:00
Heiko Hund
9b03cddea9
add support for ovpn-dco-win TAP driver
Signed-off-by: Heiko Hund <heiko@openvpn.net>
2021-04-14 22:44:49 +02:00
Heiko Hund
1e55fdadf1
make it possible to provide HTTP proxy creds
Extend struct ProvideCreds so that it can also hold HTTP proxy
credentials. This makes it possible to use proxy settings from
options, but provide credentials separately.

This is in contrast to the already existing struct Config::proxy*
which need to be given as a complete set to override eventual
HTTP proxy options.

Signed-off-by: Heiko Hund <heiko@openvpn.net>
2021-04-14 22:40:09 +02:00
Heiko Hund
f2508d9363
add unit test for HTTP proxy options
Signed-off-by: Heiko Hund <heiko@openvpn.net>
2021-04-14 22:40:07 +02:00
Heiko Hund
63d38ba278 add results_type to class AsyncResolvable
Makes code more readable and implicitly declares the
correct internet protocol.

Signed-off-by: Heiko Hund <heiko@openvpn.net>
2021-03-18 18:10:30 +01:00
Heiko Hund
bdc135c0d6 add unit tests for class RemoteList
Signed-off-by: Heiko Hund <heiko@openvpn.net>
2021-03-02 11:07:09 +01:00
Heiko Hund
08a02669c5 add support for remote-random-hostname option
Add the option from openvpn2. If given, prepend hostnames
from remote options with six random hex bytes before
DNS resolution is taking place, e.g.

	host.domain -> e3b17bf7cd57.host.domain

Signed-off-by: Heiko Hund <heiko@openvpn.net>
2021-03-02 11:07:09 +01:00
Heiko Hund
4e15a06468 Expand unit test for class PushedOptionsFilter
* add tests for pull-filter option
  * adapt route-nopull test to refactored class

Signed-off-by: Heiko Hund <heiko@openvpn.net>
2021-02-11 02:21:30 +01:00
Heiko Hund
ef2b3179b1 Fix some typos in unittest README files
Signed-off-by: Heiko Hund <heiko@openvpn.net>
2021-02-11 02:14:19 +01:00
Heiko Hund
cb7b37b1d7 Add unit test for class PushedOptionsFilter
Signed-off-by: Heiko Hund <heiko@openvpn.net>
2021-02-09 15:43:16 +01:00
James Yonan
68a5451c84 unittests/test_helper.hpp: added JY_ASSERT_LE and JY_ASSERT_GE
Googletest has issues with ASSERT macros in class
constructors or functions/methods that return values,
so we need to create our own suite of ASSERT macros.

Signed-off-by: James Yonan <james@openvpn.net>
2021-01-11 11:39:58 -07:00
James Yonan
f50bcab9e4 unit testing: LogOutputCollector: added log_wrapper() method for multi-threaded tests
To enable logging in new threads, add this line to the
beginning of your thread function:

  Log::Context log_context(testLog->log_wrapper());

Signed-off-by: James Yonan <james@openvpn.net>
2020-10-15 22:49:41 -06:00