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

493 Commits

Author SHA1 Message Date
Frank Lichtenheld
458e5df1ab
test_cliopt: Refactor by using parameterized tests
This makes it easier to add other configuration
variants to test.

Signed-off-by: Frank Lichtenheld <frank@lichtenheld.com>
2024-03-13 16:51:32 +01:00
Frank Lichtenheld
37fb7c2efc 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>
(cherry picked from commit d7b3419f8e)
2024-03-04 12:58:23 +02:00
Frank Lichtenheld
3614c1a004 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>
(cherry picked from commit 4c81069564)
2024-03-04 12:58:23 +02:00
Frank Lichtenheld
cdcf942c24 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>
(cherry picked from commit 50271ee02a)
2024-03-04 12:58:23 +02:00
Lev Stipakov
b4a400f6fe Improve handling of unknown options
Currently we error out on the first unsupported
option which belongs to the "fatal" category, such as
"removed deprecated option" or "Option allowed only to
be pushed by the server".

To improve user experice and allow application code
to display all problematic options and their categories,
collect options into a category->options map and then
serialize it into multiline string:

  cat1: opt1,opt2
  cat2: opt3

Introduce a new error code UNUSED_OPTIONS, which is
placed into ClientAPI::Status::status. The serialized
options map is placed into ClientAPI::Status::message.

Signed-off-by: Lev Stipakov <lev@openvpn.net>
2024-02-07 17:03:45 +02:00
Arne Schwabe
afdfe1bb3f
Fix accessing a null pointer when PKCS7 is invalid
If we get a valid but almost empty PKCS7 structure we otherwise try
to access invalid fields.

CVE: CVE-2023-6247
Reported-by: Bahaa Naamneh <bahaa.cpl@gmail.com>
Signed-off-by: Arne Schwabe <arne@openvpn.net>
2024-01-25 12:02:12 +01:00
Arne Schwabe
89d382853e
Allow key-method 2 in OpenVPN3 client configs
Also this is a very rare option to be used today as it was for compatibility
with OpenVPN 1.x we should still not error out when it is present.

Signed-off-by: Arne Schwabe <arne@openvpn.net>
2023-10-25 22:35:46 +02:00
Arne Schwabe
181dafdb0d
Add unsupported option name in error message
Signed-off-by: Arne Schwabe <arne@openvpn.net>
2023-10-25 22:35:43 +02:00
Frank Lichtenheld
a5914b80fa test_sitnl: Allow to pass on systems with iproute 6.1.0
On some systems, probably depending on the glibc version,
the ipv6 address will be truncated in the output.
Currently affects only Fedora 38.

Signed-off-by: Frank Lichtenheld <frank@lichtenheld.com>
2023-09-05 10:42:51 +02:00
Lev Stipakov
7fc0b701a1
Parse meta options from content_list
At the moment meta options are parsed only from
content. This doesn't work well with iOS where
config is imported via content_list. The config might
contain meta options, which currently won't be
recognized as meta and connection won't be established
due to "unknown option" error.

This adds meta options parsing to content_list.

Signed-off-by: Lev Stipakov <lev@openvpn.net>
2023-08-30 18:00:35 +02:00
Arne Schwabe
53614a0cce Properly implement OpenVPN3 checking of --client mode
Earlier implementations just assumed that --client mode is always
present in the config, which lead to config behaving different in
OpenVPN 2.x and 3.x. This creates hard to debug corner cases.

Additionally OpenVPN 3.x was not parsing the tls-client and pull
options. This lead to OpenVPN 3.x erroring on a perfectly legal
config with --pull in it.

Note the original patch was by Merten Fermont <merten.fermont@gmail.com>
but his patch got mangled in the email and when I started to apply
it manually I instead wrote my own version of it since we need
unit tests anyway.
2023-08-02 10:33:05 +02:00
Antonio Quartulli
17980287f9
fix cmake
Signed-off-by: Antonio Quartulli <antonio@openvpn.net>
2023-06-06 13:54:41 +02:00
Arne Schwabe
ff2d7c0b67 Log OpenSSL errors if error stack is not empty on exit in test cli program
Signed-off-by: Arne Schwabe <arne@openvpn.net>
2023-05-10 17:23:33 +02:00
Lev Stipakov
84cf8f45cd dco: check for options/config DCO compatibility
When parsing config, check DCO compatibility. Following
options break DCO compatibility:

 - http-proxy
 - compress
 - comp-lzo

Same for config settings:

 - non-preferred-algorithms
 - legacy-algorithms
 - proxyHost

DCO compatibility could be checked with

 - bool EvalConfig::dcoCompatible
 - std::string dcoIncompatibilityReason

If client nevertheless tries to connect, an exception
will be thrown:

  connect error: option_error: dco_compatibility: config/options are not
compatible with dco

Fixes OVPN3-960.

Signed-off-by: Lev Stipakov <lev@openvpn.net>
2023-05-08 13:51:34 +03:00
Lev Stipakov
09be60d38d cli.cpp: implement get_password() on Windows
Password is not echoed and submitted when Enter is pressed.
This requires not removing ENABLE_PROCESSED_INPUT and ENABLE_LINE_INPUT
flags.

Signed-off-by: Lev Stipakov <lev@openvpn.net>
2023-04-19 18:47:48 +03:00
Arne Schwabe
d5c09e2b08
Do not allow SHA1 cipher suites when using preferred tls-cert-profile
We do not allow SHA1 in other instances using this profile and while
SHA1 is still fine as HMAC in these situation, people freak out when
seeing SHA1 and also the description and documentation will state
that SHA1 is not allowed in other context (certificate signature),
causing confusion. So better not allow it in this context as well.

Signed-off-by: Arne Schwabe <arne@openvpn.net>
2023-03-29 23:14:30 +02:00
Mark Deric
65c9e9e4be
Fix use after move issue
Addresses coverity issue 11442 and corrects a comment that
misunderstands the compiler's generation of move operations.

Signed-off-by: Mark Deric <jmark@openvpn.net>
(cherry picked from commit 83289ae99b)
2023-03-17 12:11:57 +01:00
Arne Schwabe
171fd2f0af
Fix mbed TLS AEAD encrypt/decrypt with newer mbed TLS 2.x versions
Newer mbed TLS version changed the API. This fixes our usage of the API and
also removed the micro optimisation of reusing the buffer for plain and cipher
text.

It also adds a unit test to ensure the data is correctly encrypted/decrypted.

Signed-off-by: Arne Schwabe <arne@openvpn.net>
2023-03-08 17:06:24 +01:00
Arne Schwabe
8b13cdd7a1 Allow duplicate options without error in configuration files
we often have configuration files where a directive is duplicated and
the later one wins. This is quite common and should not rais an error. We
still warn about these as this might an error/oversight.

Signed-off-by: Arne Schwabe <arne@openvpn.net>
2023-03-08 16:52:51 +01:00
Heiko Hund
2ea80037e3 implement support for dynamic tls-crypt
Signed-off-by: Heiko Hund <heiko@openvpn.net>
2023-02-01 23:05:05 +01:00
Heiko Hund
e791304181 define CryptoAlgs within set_tls_crypt_algs()
Signed-off-by: Heiko Hund <heiko@openvpn.net>
2023-02-01 23:05:05 +01:00
Arne Schwabe
dbe166c78d Avoid null pointer references in unit tests
Reported-By: Trail of Bits (TOB-OVPN3-7)
2023-02-01 16:43:53 +01:00
Arne Schwabe
78fb15a052 Add unit test for shifts of IPv6 addresses 2023-02-01 16:43:53 +01:00
Arne Schwabe
dba51b32db Do not mix signed and unsigned in shift operations in ipv4/ipv6.hpp
The current mixing of signed and unsigned is undefined behaviour. Avoid
it by explicitly only using unsiged integers.

Also fix the same issue in the test_prefixlen unit test

Reported-By: Trail of Bits (TOB-OVPN3-5)
2023-02-01 16:43:53 +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
David Sommerseth
dde1574596
Reformatting source code to new coding style
This is the result after running 'clang-format -i' on all C++ files and
headers, with the defined formatting rules in .clang-format.

Only the openvpn/common/unicode-impl.hpp has been excluded, as that is
mostly a copy of an external project.

Signed-off-by: David Sommerseth <davids@openvpn.net>
2023-01-18 19:24:15 +01: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
David Sommerseth
4996c38ed4
Merge lastest changes from Core v3.7.2 2022-12-14 17:34:29 +01:00
Heiko Hund
83d5a53c66
Allow empty lines and comments in peer-fingerprint blocks
Signed-off-by: Heiko Hund <heiko@openvpn.net>
2022-12-14 17:01:56 +01:00
James Yonan
ea93acd432 AuthCert::Serial: consider negative serial numbers from OpenSSL layer to be undefined
Signed-off-by: James Yonan <james@openvpn.net>
2022-11-29 18:23:46 -07:00
James Yonan
b0e6e842bd AuthCert: refactor certificate serial number into its own class AuthCert::Serial
Also, added support for parsing long serial numbers.

Signed-off-by: James Yonan <james@openvpn.net>
2022-11-29 18:23:46 -07: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
David Sommerseth
8c94a8f774
copyright: Update to 2022
Signed-off-by: David Sommerseth <davids@openvpn.net>
2022-09-29 12:00:26 +02: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
Frank Lichtenheld
515c2f7d05 ovpncli: add missing override keyword for remote_override
Found by clang:
ovpn3/core/test/ovpncli/cli.cpp:664:16: warning:
 'remote_override' overrides a member function but is not marked 'override'
[-Winconsistent-missing-override]
  virtual void remote_override(ClientAPI::RemoteOverride& ro)
               ^
ovpn3/core/cmake/../client/ovpncli.hpp:658:20: note:
 overridden virtual function is here
      virtual void remote_override(RemoteOverride&);

Signed-off-by: Frank Lichtenheld <frank@lichtenheld.com>
2022-09-16 11:21:44 +02:00
Frank Lichtenheld
8345e99b46 ovpncli: compile kovpn variant with more flags by default
Both OPENVPN_REMOTE_OVERRIDE and PRIVATE_TUNNEL_PROXY
only enable features and do not change the behavior unless
configuration is also changed. Since the kovpn variant
is internal anyway, this should be safe to enable.

Signed-off-by: Frank Lichtenheld <frank@lichtenheld.com>
2022-09-16 11:21:44 +02: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
Arne Schwabe
ef6dbd250d
Add generic name to JY_EXPECT_THROW and improve error message
This renames the macro to OVPN_EXPECT_THROW and keeps the old name
as alias.
2022-09-14 17:32:52 +02:00
Lev Stipakov
970bed9f9b tun win: use IPAPI to add excluded routes
We already use IPAPI to add routes, so there is no reason
not to use it to add excluded routes. Example from server config:

  push "redirect-gateway def1"
  push "route 192.168.0.0 255.255.0.0 net_gateway"

This should redirect all traffic to VPN except one route. What
we should see in logs is:

  IPHelper: add route 192.168.0.0/16 21 100.64.0.1 metric=-1

(where 100.64 is a default gw on my machine)

Reported-by: Arul Thileeban <arulthileeban@vt.edu>
Signed-off-by: Lev Stipakov <lev@openvpn.net>
2022-08-31 14:14:20 +03:00
rstular
d0647e69f5
build: Fix typo in CMakeLists.txt
Signed-off-by: David Sommerseth <davids@openvpn.net>
2022-08-24 17:55:31 +02:00
Frank Lichtenheld
f48d020b67
test_cpu_time: fix unused variable
clang 13 complains:
test/unittests/test_cpu_time.cpp:110:16:
error: variable 'd' set but not used [-Werror,-Wunused-but-set-variable]
        double d=0;

Signed-off-by: Frank Lichtenheld <frank@lichtenheld.com>
(cherry picked from commit 9367513b4a)
2022-08-24 17:06:24 +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
18af519fae test_ssl: fix ssl.enablelegacyProvider
Since we didn't have any regular builds against
OpenSSL 3.0 so far we didn't notice that it was
broken by commit 291e675748
(Move SSL context from OpenSSL Context to OpenSSL Config)

Since context is now part of config, we need to use
separate configs.

Signed-off-by: Frank Lichtenheld <frank@lichtenheld.com>
(cherry picked from commit 6715afd4c7)
2022-07-11 12:20:17 +02: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
Frank Lichtenheld
757a06de99 test_pktid: add explicit cast for PIDRecv::REPLAY_WINDOW_SIZE
mingw complained about this.

Signed-off-by: Frank Lichtenheld <frank@lichtenheld.com>
2022-07-06 11:21:28 +02:00
Frank Lichtenheld
d1097e6169 test_path: add missing output file for windows build
Signed-off-by: Frank Lichtenheld <frank@lichtenheld.com>
2022-07-06 11:17:18 +02:00
Frank Lichtenheld
1cdc74d5ed Merge various unittests into Core library
When the OpenVPN3 Core library was carved out,
the existing test cases in test/misc were not
analyzed whether they only test functionality
in the library.

Import all tests for which that is true now,
including their history. Note that many of
the commit messages from this history already
exist in the OpenVPN3 repository from the first
creation of the Core library repository. So we
prefix all commit messages in this import with
[test/misc] to make it easy to see where they
are coming from.

Required changes to CMakeLists.txt will be done
after this merge.

Signed-off-by: Frank Lichtenheld <frank@lichtenheld.com>
2022-07-06 11:17:18 +02:00
Frank Lichtenheld
ab04ffd636 [test/misc] test_time: fix range error to show correct interval
Signed-off-by: Frank Lichtenheld <frank@lichtenheld.com>
2022-07-01 15:57:30 +02:00
James Yonan
90f7bfe8cb [test/misc] unittests: added new test for HostPort::split_host_port()
Signed-off-by: James Yonan <james@openvpn.net>
2022-07-01 15:57:30 +02:00