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

450 Commits

Author SHA1 Message Date
Arne Schwabe
8fe1b0870d
Document -non-preffered-algorithms option in ovpncli
Signed-off-by: Arne Schwabe <arne@openvpn.net>
2022-01-12 18:30:05 +01:00
Arne Schwabe
d0a9b61b4b
Do not allow SWEET32 vulnerable algorithms and MD4 without enableLegacyAlgorithm
With OpenSSL3, these algorithms are no longer allowed. With this change
we do the same regardless of the crypto library. Note that in contrast
to OpenSSL3, we include here 3DES into the legacy algorithms.

Signed-off-by: Arne Schwabe <arne@openvpn.net>
2022-01-12 18:30:04 +01:00
Arne Schwabe
291e675748
Move SSL context from OpenSSL Context to OpenSSL Config
We already load the certificates from the config and need the SSL
library context initialised there to allow loading of keys encrypted
with legacy algorithm. Also ensure that enable legacy provider is
set before actually attempting to load the private keys.

Signed-off-by: Arne Schwabe <arne@openvpn.net>
2022-01-12 18:29:50 +01:00
Frank Lichtenheld
88b0d28295 unittests: fix test_sitnl
- Test for CAP_NET_ADMIN instead of root.
  This correctly skips the test if you're root but have
  dropped capabilities, e.g. inside docker.
- Fix TestSetMTU to correctly ignore any additional lines
  in the output.

Signed-off-by: Frank Lichtenheld <frank@lichtenheld.com>
2022-01-11 15:00:44 +01:00
Arne Schwabe
d7b316bd11 Move helper function from OpenVPNClient int OpenVPNClientHelper
This also makes most of them non-static to avoid the problem that these
functions depend on Initprocess::Init being instantiated before being
called.

Rename the local variables eval to eval_cfg to avoid shadowing the
class field of the same name.
2021-12-15 13:03:41 +01:00
James Yonan
7a829ede11 cli: fixed expected behavior of --write-url, -Z
cli -Z <file> is used by automated test scripts to write the
SSO URL to a file rather than launch a browser with the URL.

Recently this behavior changed on Linux where -Z now both
writes the URL to a file and also launches a browser with
the URL.  This patch reverts behavior back to only writing
the file.

Signed-off-by: James Yonan <james@openvpn.net>
2021-11-24 13:18:35 -07:00
Arne Schwabe
3f90304154
Allow controlling usage of non preferred DC ciphers via option
Signed-off-by: Arne Schwabe <arne@openvpn.net>
2021-11-12 20:58:46 +01:00
Arne Schwabe
847f8da3ee
Remove some leftover forceAesCbcCiphersuites code
This feature was removed a while ago and these settings do not do
anything any more.

Signed-off-by: Arne Schwabe <arne@openvpn.net>
2021-11-12 20:58:45 +01:00
Arne Schwabe
7897c3bd7e
Rename OPENVPN_USE_TLS_MD5 to OPENVPN_ALLOW_INSECURE_CERTPROFILE
With OpenSSL 3.0 the name with MD5 no longer makes sense as it affects
not only MD5 but also SHA1 and number of other settings. So replace the
define with a more fitting name.

Signed-off-by: Arne Schwabe <arne@openvpn.net>
2021-11-12 20:58:44 +01:00
Arne Schwabe
aee55f307b
[OSSL 3.0] Add unit test to test that legacy provider loading works
Signed-off-by: Arne Schwabe <arne@openvpn.net>
2021-11-12 20:58:40 +01:00
Arne Schwabe
1b5d913503
Implement setting legacy provider from ovpncli.cpp/test client
Signed-off-by: Arne Schwabe <arne@openvpn.net>
2021-11-12 20:58:38 +01:00
Arne Schwabe
9fe7a29148
Implement allowing only data channel ciphers that are actually available by the library
Signed-off-by: Arne Schwabe <arne@openvpn.net>
2021-11-12 20:58:37 +01:00
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
Arne Schwabe
f964fb07b1 Allow auth pending methods be specified via commandline
Signed-off-by: Arne Schwabe <arne@openvpn.net>
2020-09-30 17:58:12 +02:00
Arne Schwabe
b67702e19f Also log the signature algorithm when printing the verified certificates
This allows the user to figure out which certificate uses MD5/SHA1.

Signed-off-by: Arne Schwabe <arne@openvpn.net>
2020-09-30 17:58:12 +02:00
Arne Schwabe
949386f5fe Change continuation_test1 to always only use 100 iteration
This test also takes more than one minute to run on my mac with
a debug build and consume 99% of the time of the test run.

Signed-off-by: Arne Schwabe <arne@openvpn.net>
2020-09-30 17:58:12 +02:00
David Sommerseth
5b15dbe940
Merge changes from Core library v3.5 2020-09-23 20:13:07 +02:00
Lev Stipakov
081b17fcbd
test_sitnl.cpp: add missing "override" specifier
Signed-off-by: Lev Stipakov <lev@openvpn.net>
2020-09-23 10:20:01 +03:00
Lev Stipakov
242cdad9c9
win: add ipv4 routes via IP Helper API
Use ::CreateIpForwardEntry2() to add route instead of
expensive netsh call. Make it as a default choce.

Add unit test.

Signed-off-by: Lev Stipakov <lev@openvpn.net>
2020-09-09 18:25:38 +03:00
Lev Stipakov
d0e2e036eb
win: add ipv4 routes via IP Helper API
Use ::CreateIpForwardEntry2() to add route instead of
expensive netsh call. Make it as a default choce.

Add unit test.

Signed-off-by: Lev Stipakov <lev@openvpn.net>
2020-09-09 13:07:06 +03:00
Lev Stipakov
d79536240e
unittests/CMakeLists.txt: fix tests execution
Commit 941104cf4 refactored the way how test files are added, but
broke (disabled) execution of sitnl and cputime tests. Fix that.

Signed-off-by: Lev Stipakov <lev@openvpn.net>
2020-09-09 12:35:25 +03:00
Arne Schwabe
012e7e8226
Refactor InitProcess to use refcounting
Although the init calls were protected by a mutex more than consumer of
the API will the second one if the uninit was called too early.

While at it, move from explicit init/uninit calls to RAII.

Signed-off-by: Arne Schwabe <arne@openvpn.net>
2020-09-02 20:37:01 +02:00
Lev Stipakov
8593c41540 ovpn-dco: basic communication with kernel module
Add dependency to libnl-genl, which is C library
for generic netlink communication.

Implement C++ wrapper for libnl-genl, inspired by
ovpn-cli - a test client for ovpn-dco kernel module.

Implement ovpn-dco netlink commands:

  - OVPN_CMD_START_VPN - pass transport socket,
protocol (UDP) and mode (client).

  - OVPN_CMD_NEW_PEER - pass local and remote
endpoint info.

  - OVPN_CMD_PACKET - move (control channel) packets
between userspace and kernel.

  - OVPN_CMD_DEL_PEER - sent by kernel when peer is deleted
due to keepalive timeout (causes reconnect) or any other
reason (considered as fatal).

This change allows to perform openvpn handshake and
establish connection which doesn't work, since data channel
keys are not passed to kernel yet.

Signed-off-by: Lev Stipakov <lev@openvpn.net>
2020-08-26 14:59:24 +00:00
Lev Stipakov
3761f2ff89 ovpn-dco: initial support
Add tun/transport client skeleton for ovpn-dco,
which doesn't do any work except creating/removing
ovpn-dco device.

Signed-off-by: Lev Stipakov <lev@openvpn.net>
2020-08-26 10:53:27 +00:00
Lev Stipakov
5bc16a71ef dcocli.hpp: refactor dco transport client
In preparation of ovpn-dco support, split dco transport
client into two parts:

 - generic dco support in dcocli.hpp
 - kovpn-specific code in kovpncli.hpp

Add build directory (used by VS Code) to .gitignore

Use #pragma once instead of #ifndef/#define/#endif

Signed-off-by: Lev Stipakov <lev@openvpn.net>
2020-08-26 10:53:27 +00:00
Lev Stipakov
0ba5e06882 cli.cpp: use SITNL on Linux by default
Macro OPENVPN_USE_SITNL should be defined before
inclusion of client/ovpncli.cpp.

Include tuncli.hpp for consistency with mac-specific code below.

Signed-off-by: Lev Stipakov <lev@openvpn.net>
2020-08-26 10:53:27 +00:00
James Yonan
c6441ee9f3
unittests: added test_all to .gitignore
Signed-off-by: James Yonan <james@openvpn.net>
2020-08-19 18:53:07 +02:00
James Yonan
3555b12a16
push-continuation: added new server-side fragmentor
Includes new unit test for both client and
server-side push-continuation code.

Signed-off-by: James Yonan <james@openvpn.net>
2020-08-19 18:53:00 +02:00
James Yonan
d0298f5520
unittests: test_common.h should include <openvpn/io/io.hpp> rather than <asio.hpp> directly
Signed-off-by: James Yonan <james@openvpn.net>
2020-08-19 18:52:56 +02:00
James Yonan
159a64e338
unittests: work around some limitations in googletest
Signed-off-by: James Yonan <james@openvpn.net>
2020-08-19 18:52:54 +02:00
James Yonan
fc0e12fdf7
Unit tests: added new "fake-secure" random source that's guaranteed to be deterministic
Signed-off-by: James Yonan <james@openvpn.net>
2020-08-19 18:52:51 +02:00
David Sommerseth
f6ab0178a5
test: Fix OPENVPN_USE_SITNL redefine warning in ovpncli
If the OPENVPN_USE_SITNL is defined as compiler arguments or set
earlier if cli.cpp was used in an #include statement, the compiler
would warn about OPENVPN_USE_SITNL being redefined.

We want OPENVPN_USE_SITNL by default, but the code does not need
to explicitly define it if it is already defined.

Signed-off-by: David Sommerseth <davids@openvpn.net>
2020-08-18 10:49:54 +02:00
Arne Schwabe
2141e23ecd Implement tls-groups option to specify eliptic curves/groups
OpenSSL 1.1+ by default only allows signatures and key exchange from the
default list of X25519:secp256r1:X448:secp521r1:secp384r1. Since in
TLS1.3 key exchange is independent from the signature/key of the
certificates, allowing all groups per default is not a sensible choice
anymore and the shorter lister is reasonable.

However, when using certificates with exotic curves the signatures of
this certificates will no longer be accepted. This option allows to
modify the list for these corner cases.

Signed-off-by: Arne Schwabe <arne@openvpn.net>
2020-05-13 16:23:36 +02:00
James Yonan
3b3ee130b9 cli: allow --peer-info option to accept a JSON file as input
Signed-off-by: James Yonan <james@openvpn.net>
2020-05-02 20:33:14 -06:00
James Yonan
bf69c9f046
unittests/test_comp.cpp: added missing '/' in filename lookup
Signed-off-by: James Yonan <james@openvpn.net>
2020-04-24 13:22:53 +02:00
James Yonan
e2a9630718
unit tests: added a .gitignore for executables
Signed-off-by: James Yonan <james@openvpn.net>
2020-04-24 13:22:48 +02:00
David Sommerseth
3fbe0a2701
Update copyrights
Signed-off-by: David Sommerseth <davids@openvpn.net>
2020-03-18 19:37:32 +01:00
Arne Schwabe
941104cf49
Implement supporting IANA cipher names in tls-cipher and unit tests
Signed-off-by: Arne Schwabe <arne@openvpn.net>
2020-03-11 19:51:37 +01:00
Arne Schwabe
fa5f0f0b02
Ensure that InitProcess is always called before starting unit test
This is needed for the tls-cipehr/tls-ciphersuites to have an
initialised OpenSSL when using OpenSSL < 1.1.0

Signed-off-by: Arne Schwabe <arne@openvpn.net>
2020-03-11 19:51:37 +01:00
Arne Schwabe
9c547ba3ff
Remove force_aes_cbc_ciphersuites option
This option has been very likely been to fix some incompatibilities
between some TLS libraries. But nobody really remember what it fixes
and its usage today is questionable. So remove the option instead
of supporting an option we cannot even test anymore.

Signed-off-by: Arne Schwabe <arne@openvpn.net>
2020-03-11 19:51:18 +01:00
Lev Stipakov
532ebf1798
cli agent: disable agent path check for test client
Signed-off-by: Lev Stipakov <lev@openvpn.net>
2020-03-11 19:44:51 +01:00
James Yonan
9f430b46ba cli: added --write-url option to write URLs received via INFO/OPEN_URL notifications to a file
Signed-off-by: James Yonan <james@openvpn.net>
2020-03-11 11:11:56 -06:00
James Yonan
f669831556 Base64: fixed issue where decode() method would ignore bad chars rather than throwing base64_decode_error()
Added a unit test to confirm the fix.

Other changes:

* In Base64 decode(), avoid the use of std::strlen() in favor
  of std::string length() method since a std::string could
  conceivably contain embedded null chars.

* In Base64 unit test, renamed b64_test_bad() to
  b64_test_bad_decode() for clarity.

Signed-off-by: James Yonan <james@openvpn.net>
2020-03-11 11:11:56 -06:00
James Yonan
93f6ed83c5 system_cmd_async: added optional sigset_t* parameter to configure signals in child
This is useful for running a command from a worker thread
where signals have been blocked, but we want the child
process to run with the original pre-blocked signal configuration.

Signed-off-by: James Yonan <james@openvpn.net>
2020-02-28 11:56:04 -07:00
Arne Schwabe
a2e2bf626e Increase frame size in proto test to 378
The added IV_CIPHER string that we send, brought the Frame used in
the proto test client over the 256 byte limit. Change the proto test
to use a larger test frame of 378 byte.

Signed-off-by: Arne Schwabe <arne@openvpn.net>
2020-02-18 18:50:27 +01:00
Lev Stipakov
e07a2c4e62
mingw: use lowercase in includes
Linux filesystem is case-sensitive and all
mingw includes are in lower case.  Also use
Linux directory separator, since it works on both
Linux and Windows.

Signed-off-by: Lev Stipakov <lev@openvpn.net>
2020-02-12 16:12:19 +02:00
Arne Schwabe
8f4da2ec62 Move CMAKE module path to root directory
This fixes the cmake build when using openvpn3 standonline

Signed-off-by: Arne Schwabe <arne@openvpn.net>
2020-01-30 14:52:57 +01:00
Lev Stipakov
1a7cb2b694
cmake: Don't use "Wno-unused-private-field" for msvc
Signed-off-by: Lev Stipakov <lev@openvpn.net>
2020-01-30 10:31:14 +02:00
Lev Stipakov
1c9834c50d win: replace msvc project files with cmake
Signed-off-by: Lev Stipakov <lev@openvpn.net>
2020-01-29 23:24:54 +01:00
Arne Schwabe
4c089df991 Add cmake build file for proto
Signed-off-by: Arne Schwabe <arne@openvpn.net>
2020-01-29 18:13:28 +01:00
Arne Schwabe
86008fd2ee Remove dependency on std::regex from getSortedString
Signed-off-by: Arne Schwabe <arne@openvpn.net>
2020-01-29 18:13:28 +01:00
Arne Schwabe
70923f41df
Silence used return value warning of BIO_flush 2020-01-15 23:08:32 +01:00
Arne Schwabe
984c601090
Fix multiple instances of comparison of signed with unsigned 2020-01-15 23:08:30 +01:00
Arne Schwabe
cb229c7bba
Add -Wall option by default to openvpn compile
Fix DCO compile from a fresh checkout

Allow do use -DUSE_WERROR=true to error out on warnings during the build
2020-01-15 23:08:29 +01:00
Arne Schwabe
6dc5d5ddf0
Fix various warnings reported by -Wall/clang
- missing override annotations
- wrong order of init in constructor
- delete on a pointer to a virtual class without virtual destructor
2020-01-15 23:08:28 +01:00
Arne Schwabe
4c361ec4c3 Expand Unittest documentation 2019-12-03 11:04:15 +01:00
James Yonan
4d138252df
unittests: added missing #include <mutex>
Signed-off-by: James Yonan <james@openvpn.net>
2019-11-27 18:55:08 +01:00
Arne Schwabe
a8275e13f4
Add ovpnclinull and ovpnclidco variants to cmake build script 2019-11-20 11:07:49 +01:00
David Sommerseth
ae6bf893bb
mbedtls: Add unit tests for x509_get_subject() and x509_get_common_name()
These functions are found in openvpn/mbedtls/pki/x509certinfo.hpp.

This change also adds support to build coreUnitTests against mbed TLS
instead of OpenSSL (default) by providing -DUSE_MBEDTLS=true to cmake.

Signed-off-by: David Sommerseth <davids@openvpn.net>
2019-11-08 10:00:44 +01:00
David Sommerseth
61ba6e9c41
openssl: Add unit tests for OpenSSLPKI::x509_get_*() functions
This adds some basic unit tests for the various functions retrieving
information from a X.509 certificate.

Signed-off-by: David Sommerseth <davids@openvpn.net>
2019-11-08 10:00:41 +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
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
12309c31b6 Document unit tests
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
e790c45eda Add helper functions for temporary file and joining test outputs
Signed-off-by: Arne Schwabe <arne@openvpn.net>
2019-11-07 09:58:54 +01:00
Arne Schwabe
16342679fe Add helper function to get the content of a expected output file
Signed-off-by: Arne Schwabe <arne@openvpn.net>
2019-11-07 09:58:54 +01:00
Arne Schwabe
7324ca879e Add OPENVPN_LOG implementation that can collect logs in a variable
To support the pre unittest tests that compare the output against an
expected output without fully rewriting them, this logger provides a
facility to integrate them in the unit test framework

Signed-off-by: Arne Schwabe <arne@openvpn.net>
2019-11-07 09:58:54 +01:00
James Yonan
e8b31c5454 cli: advertise "openurl" as supported SSO method
Signed-off-by: James Yonan <james@openvpn.net>
2019-09-06 22:24:57 -06:00
Arne Schwabe
63ab5b5e46 Only initialise static member in OpenSSLContext once
This avoid a linkage problem encountered when building core with two
compilation units and OPENVPN_EXTERN being used.

Also adjust core unit tests with regard to now different extern usage
2019-08-29 16:21:57 +02:00
Antonio Quartulli
47046cf6d2
Merge branch 'qa' 2019-07-19 14:39:43 +02:00
James Yonan
4eaa46a879 MbedTLS: added MBEDTLS_DISABLE_NAME_CONSTRAINTS preprocessor flag
This allows building a client against a generic mbedTLS library.

Signed-off-by: James Yonan <james@openvpn.net>
2019-07-17 10:53:46 -06:00
Lev Stipakov
03a906771e win: add OpenSSL as solution configuration
This also removes unittest.vcxproj from solution, since
it is deprecated in favor of CMake-based unit tests.

Signed-off-by: Lev Stipakov <lev@openvpn.net>
2019-06-05 13:54:13 +03:00
David Sommerseth
a55fe2b554
tests: Added unit test for linux/cputime.hpp
This test attempts to assure that the measurements we get from
openvpn::cpu_time() is within a reasonable range of what we should
normally expect.

This is achieved by using a simple worker thread which ensures the
process is not "idling" (like it would with sleep()) but in a real busy
loop which takes some time.  Then we measure the time spent in the busy
loop, both using a simplistic time() and comparing that with what
cpu_time() returns.

This unit test also supports measuring multiple running threads
individually too.

Signed-off-by: David Sommerseth <davids@openvpn.net>
2019-06-03 19:05:34 +02:00
Lev Stipakov
a2496a3616 Wintun: experimental support
This introduces experimental support for Wintun
as an alternative for tap-windows6.

In order to use wintun, set "ClientAPI::Config::wintun"
flag to "true" or use "-w" option in test client.

Signed-off-by: Lev Stipakov <lev@openvpn.net>
2019-05-29 20:21:28 +03:00
Lev Stipakov
b55f78dd1d test_sitnl.cpp: account for old iptools output
On CentOS 7 "ip route get" produces different
output comparison to Ubuntu 18 etc.

Signed-off-by: Lev Stipakov <lev@openvpn.net>
2019-05-14 16:32:03 +03:00
Arne Schwabe
d56e049ea4 Refactor dependencies to be in a cmake script
This allows the dependencies to be used by multiple parts of the project,
e.g. non public unit tests, ovpncli etc.

Building ovpncli demostrates this
2019-05-13 14:49:36 +02:00
Lev Stipakov
e9dc75ec90 sitnl: add unit tests
This adds unit tests for sitnl code.

Signed-off-by: Lev Stipakov <lev@openvpn.net>
2019-05-10 10:48:53 +03:00
Lev Stipakov
dfcc4bc437 [OVPN3-354] cli.cpp: support for round-robin DNS and redirect gw
This takes into use new TunSetup API which enables to create bypass
routes before establishing connection.

Signed-off-by: Lev Stipakov <lev@openvpn.net>
2019-05-10 10:48:53 +03:00
Lev Stipakov
7d112eb3e5 cli: enable utf8 console output
This allows cli to display non-ASCII strings,
assuming they're utf8 encoded.

Signed-off-by: Lev Stipakov <lev@openvpn.net>
2019-05-06 17:10:12 +03:00
Lev Stipakov
7150f72e09 tun: remove code duplications in Linux tun implementations
There are two ways how Linux tun can be manipulated -
by using iproute2 or netlink. Both implementations have
defined identical Setup class implementation.

This commit factors out Setup class from tun implementations
and templatizes it, which removes need in duplicated code.

Signed-off-by: Lev Stipakov <lev@openvpn.net>
2019-05-02 21:34:20 +03:00
Lev Stipakov
8112f0cd7c [OVPN3-378] cli: support for TunBuilder API
This enables to use TunBuidler API by test client
on Linux and Mac platforms.

Signed-off-by: Lev Stipakov <lev@openvpn.net>
2019-05-02 21:34:20 +03:00
Lev Stipakov
4d7c12ac4d [OVPN3-405] Support for non-ASCII profile path on Windows
This uses Windows-specific wchar_t override of std::ifstream
to make it work with UNICODE paths. It is assumed that caller
passes UTF8-encoded string.

To support passing non-ASCII chars via command line, we
read it as wstring and then convert to UTF-8 encoded string.

Signed-off-by: Lev Stipakov <lev@openvpn.net>
2019-04-30 17:45:01 +03:00
Arne Schwabe
aba98471fc Fix base64 unit test with mbedtls and windows
- the output buffer was sometimes too small in mbed tls
- msvc compiler does not like stack arrays with dynamic sizes
2019-04-18 14:47:16 +02:00
Arne Schwabe
9f84174f0b Add unit tests for Base64 2019-04-15 17:23:37 +02:00
Arne Schwabe
dfdd528dc1 Convert unit test to Googletest
Signed-off-by: Arne Schwabe <arne@openvpn.net>
2019-04-15 17:23:37 +02:00
Arne Schwabe
bd9ee482e6 Add copyright header to test_comp 2019-04-15 17:23:37 +02:00
Arne Schwabe
059f20f2b2 Move compression unit test from common to core repository
Signed-off-by: Arne Schwabe <arne@openvpn.net>
2019-04-15 17:05:09 +02:00
James Yonan
5a024cde5c Added Snappy corpus for testing compression/decompression.
Signed-off-by: Arne Schwabe <arne@openvpn.net>
2019-04-15 17:05:09 +02:00
Arne Schwabe
6ef089164e Allow unit tests to be also compiled with mbed TLS and on Windows 2019-03-12 11:36:29 +01:00
Arne Schwabe
7c67bf7f50 Add unit tests for route emulation and establish common test suite
This puts the log demo unit test and real route emulation into the same
unit test compilation unit to save compilation time.
2019-03-12 11:36:29 +01:00
Arne Schwabe
64a7b2f124 Add build file for core unit tests
Currently we only have unit test build file for Visual Studio. Add one
that is compatible with Unix like systems.
2019-03-12 11:36:29 +01:00
Lev Stipakov
1bf3fc0e4a win: update project files
Remove Win32 target, set platform version to Windows 10 and set platform toolset to v141.

Signed-off-by: Lev Stipakov <lev@openvpn.net>
2018-12-21 10:30:31 +02:00
Arne Schwabe
84dbc5b9b2 Allow test/cli.cpp to be used with NetCfg Tunbuilder client
This requires cli.cpp to be included in openvpn3-linux build environment
and the right defines set before the test.cpp is included.

This workaround is necessary since the dbus dependencies are not part
of the core and to adding an extra copy of cli.cpp to openvpn3-linux

Signed-off-by: Arne Schwabe <arne@openvpn.net>
2018-12-06 11:49:30 +01:00
Antonio Quartulli
9814079944
tls-crypt-v2: implement abstract metadata parser
The metadata that may be possibly be contained in the WKc has to be
verified by means of a user implemented behaviour.

Implement an abstract class that exports a verify() method to be
used for this purpose.

Users can extend this class and override the verify() method with
their own.

A basic implementation is also provided: it will just ignore the
metadata (if any) and report success to the core.

Signed-off-by: Antonio Quartulli <antonio@openvpn.net>
2018-12-06 09:19:22 +10:00
Antonio Quartulli
be38bbeb84
tls-crypt-v2: test/ssl/proto.cpp - extend protocol test
Signed-off-by: Antonio Quartulli <antonio@openvpn.net>
2018-12-06 09:19:22 +10:00
Arne Schwabe
2ea88a93ba Add Remote endpoint information to protect_socket call
On the linux client we need the information to which remote the client
is connecting to query the route information to ultimately discover the
device. On other platform that do not need these extra information we
ignore the extra arguments

The API uses std::string and bool instead of passing of passing IPAddr as
the API needs to be understand by Swig/Java and similar methods also opt in
favour of call by value and simply types.

Signed-off-by: Arne Schwabe <arne@openvpn.net>
2018-12-04 13:33:18 +01:00
Antonio Quartulli
0a081ee17f
[OVPN3-315] cli/go: add option to compile SITNL component
Signed-off-by: Antonio Quartulli <antonio@openvpn.net>
2018-11-30 08:51:14 +10:00
David Sommerseth
4a25059f5c
test/ovpncli: Don't override PROF env variable
If the PROF env variable is already set, respect that original value
instead of enforcing a value which might be wrong on the build host.

Signed-off-by: David Sommerseth <davids@openvpn.net>
2018-11-07 17:57:08 +01:00
Antonio Quartulli
8d9834b793
cli: build with OPENVPN_VERSION generated from commit id
Signed-off-by: Antonio Quartulli <antonio@openvpn.net>
2018-06-25 16:37:51 +08:00
James Yonan
0e673f1e0b Cleaned up cli build script
Also added an option to build with OpenSSL
instead of mbedTLS.

Signed-off-by: James Yonan <james@openvpn.net>
2018-05-21 11:34:01 +03:00
Antonio Quartulli
d9b5055cda
[OVPN3-169] cli.cpp: compile with -DOPENVPN_TLS_LINK when requested
Compile with -DOPENVPN_TLS_LINK if TLS=1 was specified on
the command line

Signed-off-by: Antonio Quartulli <antonio@openvpn.net>
2018-04-19 17:38:19 +08:00