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

51 Commits

Author SHA1 Message Date
Frank Lichtenheld
079fb4dd4d
UserPass: Add unittest
Fixed one issue while at it, with parse() not clearing
the username and password arguments.

The general issue that overflow doesn't throw is reflected in
a disabled test. This will need to be fixed in SplitLines,
probably.

Signed-off-by: Frank Lichtenheld <frank@lichtenheld.com>
2023-11-08 21:05:01 +01:00
Mark Deric
989dd7ead5 Port the psid cookie defense from ovpn2
The psid cookie defense is designed to thwart resource exhaustion and
amplification attacks wherein a malicious client sends the server a
flood of CONTROL_HARD_RESET_CLIENT_V2 packets with spooofed source
addresses.  This patch allows the server to defer client tracking
state creation until the client responds to the server's
CONTROL_HARD_RESET_SERVER_V2 message.

Signed-off-by: Mark Deric <jmark@openvpn.net>
2023-10-03 12:42:29 -07:00
Mark Deric
8b93eb0b0a Fix randapi UBSAN bug, signed T:min map to >= 0
The undefined behavior is unary negation of T:min of a signed type
attempting to get a positive value of the same signed type.

This commit adds a unit test that exposes the original bug and well as
a fix for it.

Signed-off-by: Mark Deric <jmark@openvpn.net>
2023-08-15 07:28:35 -07:00
Frank Lichtenheld
775ff02527
dlgoogletest: update GoogleTest to latest upstream
This fixes deprecation warnings with latest CMake.
("Compatibility with CMake < 3.5 will be removed
from a future version of CMake.")

Signed-off-by: Frank Lichtenheld <frank@lichtenheld.com>
2023-08-02 17:25:16 +02:00
Mark Deric
1555d9581a unittest: Add proto test cmake parameters w/README
When the test/ssl/proto was migrated to a unit test, all the
build time tuneables for changing the test scope got lost.

This change re-introduces these parameters in the appropriate
CMakeLists.txt.  Further, it adds an improved README in .rst format
that describes the parameters; this is based on the original README
file in test/ssl.

In addition, it adds improved handling of the directory where the test
certificates and key files are located; now they can be adjusted more
easily.

Signed-off-by: Mark Deric <jmark@openvpn.net>
2023-06-16 18:37:02 +02:00
Mark Deric
f9be22ba53 Add proto test to unittests w/2nd executable
The new test file, test_proto.cpp, is moved from test/ssl/proto.cpp
and only minimally changed.  The 2nd executable is based upon
core_tests.cpp, same as the 1st executable.  But note that the CMake
file has differences between the executables.

Signed-off-by: Mark Deric <jmark@openvpn.net>
2023-06-07 11:18:33 -07:00
Frank Lichtenheld
d7b3419f8e CMake: clean up dependency handling
Always use find_package for all libraries.
Add missing Find*.cmake modules.
Always define an IMPORTED library in Find*

Signed-off-by: Frank Lichtenheld <frank@lichtenheld.com>
2023-02-28 13:45:16 +01:00
Frank Lichtenheld
4c81069564 CMake: move architecture detection closer to the actual executable
This makes it easier to see what is going on when looking at
individual CMakeLists.

Signed-off-by: Frank Lichtenheld <frank@lichtenheld.com>
2023-02-28 13:45:16 +01:00
Frank Lichtenheld
f18ef6d918 unittests: remove support for GCC < 5.1.0
Signed-off-by: Frank Lichtenheld <frank@lichtenheld.com>
2023-02-28 12:30:30 +01:00
Frank Lichtenheld
50271ee02a CMake: small improvements
- Increase required version to 3.10. That is the version in
  Ubuntu Bionic and currently the oldest one we still want
  to support.
- Enable CTest for test target

Signed-off-by: Frank Lichtenheld <frank@lichtenheld.com>
2023-02-28 12:30:30 +01:00
Charlie Vigue
d111fc301c
Add numeric limiting headers and tests
This commit adds two useful numeric limiting functions in
two headers plus a third supporting header and unit tests.
The unit tests cover all code paths and many conditions
but may not be 100% complete from a viewpoint of
covering all edge cases.

Signed-off-by: Charlie Vigue <charlie.vigue@openvpn.net>
2023-02-23 23:06:45 +01:00
James Yonan
48d114e691 BufferType: refactor const operations into new base ConstBufferType
Previously, ConstBuffer was simply a BufferType with a const
data type.  However this model, and the fact that BufferType
has a vtable, makes it difficult to efficiently cast Buffer
to ConstBuffer via static_cast without introducing an unsafe
downcast.

This commit tries a different approach by factoring out const
BufferType operations into a new base class ConstBufferType.
In the new model, BufferType inherits from ConstBufferType.
Member functions that treat the underlying data buffer as
const have been moved to ConstBufferType while member
functions that treat it as mutable remain in BufferType.
This makes casting BufferType to ConstBufferType a trivial
upcast while also greatly simplifying const_buffer_ref().

Signed-off-by: James Yonan <james@openvpn.net>
2023-01-30 17:16:08 -07:00
Mark Deric
e4b1afe148
Design a coercion-safe ostream<< for containers
Adds a library method C2os:cast() that converts an iterable container,
i.e., one that can be a range-expression in a range-based for loop,
into a type that can be inserted into an ostream.  This only addresses
the container semantics in the ostream insertion.  The underlying
contained type T (if the container were stl, the value_type) must work
with ostream<<.

The result of the operator<< insertion is a square bracket enclosed,
comma delimited string of the items in the container.  Note that the
commit includes ideas on expanding choices of container rendering
details.

Attribution to James Yonan.  Made significant contribution to
expanding the scope of collections.  And reduced code complexity.
Also to Charlie Vigue; eliminated the "first" test inside the loop.

Signed-off-by: Mark Deric <jmark@openvpn.net>
2022-12-29 22:47:09 +01:00
Arne Schwabe
e9630e86d7 Rework ack logic
This commit removes the ability to pass down the windows sizes for ack
windows down from the configuration. This capability was never used and
instead the receive and send window were both hardcoded at 4. Also
change the receive window to 12 and the send window to 6 like
OpenVPN 2.6 does.

Also to improve control channel reliability, resend previous ACKs in MRU
fashion if there is still room for them in a control channel packet.

This patch is based on a patch was written
by Charlie Vigue <charlie.vigue@openvpn.net>.

Signed-off-by: Arne Schwabe <arne@openvpn.net>
2022-11-23 17:08:00 +01:00
Mark Deric
8c7d6e1751 Move reliability layer tests from common
The tests in common were based on running main(); the tests have been
converted to the gtest framework and are now part of the automated
unit test suite.

Signed-off-by: Mark Deric <jmark@openvpn.net>
2022-11-09 08:29:26 -08:00
James Yonan
19201beb9f AuthCert: support up to 160 bit serial numbers
Previously, we only supported int64 serial numbers.

This change renames get_sn() method to serial_number_as_int64()
for code that cares about 64-bit serial numbers.

Signed-off-by: James Yonan <james@openvpn.net>
2022-09-21 23:00:13 -06:00
Arne Schwabe
5b5d80fad3
Improve dealing with unknown options
This commit add several improvements to dealing with unknown options
in client configuration files:
 - implement ignore-unknown-option
 - categorise the OpenVPN2 options in multiple categories and
   warn/error out depending on the category
 - error out when unsupported/unknown options are found. This avoids
   problems like with --tls-crypt/--tls-crypt-v2 before where client
   would ignore these options and not connect at all

Signed-off-by: Arne Schwabe <arne@openvpn.net>
2022-09-14 17:32:53 +02:00
Mark Deric
1a5e4a7558 Add a unit test for checking header dependencies
Signed-off-by: Mark Deric <jmark@openvpn.net>
2022-07-21 11:08:42 -07:00
Frank Lichtenheld
273297d630 test/unittests: Add newly imported unittests
Note that the test suite now depends on jsoncpp
and xxHash.

Signed-off-by: Frank Lichtenheld <frank@lichtenheld.com>
2022-07-06 11:21:28 +02:00
Heiko Hund
b660e5642b
add support for --dns option
As a first step towards DNS configuration in openvpn and a unified way
to push DNS related settings to clients in v2 and v3, this commit adds
support for parsing the new --dns option. Later commits will add support
for setting up DNS on different platforms.

For now, --dns and DNS related --dhcp-option can be used together for
smoother transition. Settings from --dns will override ones --dhcp-option
where applicable.

Signed-off-by: Heiko Hund <heiko@openvpn.net>
2022-02-10 18:35:02 +01:00
James Yonan
5be7dee87f Added fast IP address formatting via BufferFormat::ipv4/ipv6
Signed-off-by: James Yonan <james@openvpn.net>
2022-01-13 09:40:13 -06: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
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
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
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
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
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
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
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
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
cb7b37b1d7 Add unit test for class PushedOptionsFilter
Signed-off-by: Heiko Hund <heiko@openvpn.net>
2021-02-09 15:43:16 +01:00
David Sommerseth
5b15dbe940
Merge changes from Core library v3.5 2020-09-23 20:13:07 +02: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
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
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
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
1c9834c50d win: replace msvc project files with cmake
Signed-off-by: Lev Stipakov <lev@openvpn.net>
2020-01-29 23:24:54 +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
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
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
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
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