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

3706 Commits

Author SHA1 Message Date
Frank Lichtenheld
866e0c9596 mingw: add new script build-vcpkg
This avoids all the manual deps building and instead
uses vcpkg directly.

Note: need to remove gtest from VCPKG manifest for now:
- it only builds with -posix variant of mingw compiler
- vcpkg uses the non-posix variant and can't be trivially
  reconfigured
- we build gtest from unittests anyway and that one uses
  the compiler we specify

Using the posix variant of mingw compiler will require
setting up a custom triplet and toolchain. That will be
done in a later commit.

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
a9570cb780 CMake: support BUILD_TESTING option
This is important since it allows us to avoid
the JsonCPP dependency on non-Win/non-Apple
systems.

Signed-off-by: Frank Lichtenheld <frank@lichtenheld.com>
2023-02-28 12:30:30 +01:00
Frank Lichtenheld
e720bf3aba CMake: Generalize add_json_library
Make sure we find vcpkg and system packages on all
platforms.

Signed-off-by: Frank Lichtenheld <frank@lichtenheld.com>
2023-02-28 12:30:30 +01:00
Frank Lichtenheld
2fb5d08ea0 CMake: Fix issues in FindmbedTLS
Use add_library to define a target so that we do not
need to apply all the setting manually.
Use find_package_message() to avoid printing the
message more than once.

Signed-off-by: Frank Lichtenheld <frank@lichtenheld.com>
2023-02-28 12:30:30 +01:00
Frank Lichtenheld
330a91ef64 unittests: Fix -Wsigned-compare errors
Seen with newer versions of GoogleTest.

Signed-off-by: Frank Lichtenheld <frank@lichtenheld.com>
2023-02-28 12:30:30 +01:00
Frank Lichtenheld
71cf5f48fe vcpkg-ports/asio: copy update asio-config.cmake from vcpkg
Fixes problems when calling find_package on asio multiple
times.

Originally fixed by commit cba75f1aa08374733dcc79abebeca262ae94118a
in vcpkg#28299.

Signed-off-by: Frank Lichtenheld <frank@lichtenheld.com>
2023-02-28 12:30:30 +01:00
Frank Lichtenheld
98c002ffea vcpkg_ports/asio: apply all patches
So that we can use this port for building all binaries.

Signed-off-by: Frank Lichtenheld <frank@lichtenheld.com>
2023-02-28 12:30:30 +01:00
Frank Lichtenheld
0f299e8bc8 GHA: update to lukka/run-vcpkg@v10
While here, also update vcpkg to latest.

To resolve warning:
The `save-state` command is deprecated and will be disabled soon.
Please upgrade to using Environment Files. For more information see:
https://github.blog/changelog/2022-10-11-github-actions-deprecating-save-state-and-set-output-commands/

Signed-off-by: Frank Lichtenheld <frank@lichtenheld.com>
2023-02-28 12:30:30 +01:00
Frank Lichtenheld
1a723da4fb README.rst: cleanup
Signed-off-by: Frank Lichtenheld <frank@lichtenheld.com>
2023-02-28 12:30:30 +01:00
Frank Lichtenheld
fb9bee5ad6 vcpkg.json: Allow to use on Linux
- Fix PATCHES to work on Linux
- While here, fix version number

Signed-off-by: Frank Lichtenheld <frank@lichtenheld.com>
2023-02-28 12:30:30 +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
Frank Lichtenheld
4666c7f9c1 .travis: remove unused files
Signed-off-by: Frank Lichtenheld <frank@lichtenheld.com>
2023-02-28 12:30:30 +01:00
Arne Schwabe
156ea554e2 Ensure NTLM phase 2 is always large enough
Reported-By: Trail of Bits (TOB-OVPN3-14)
Signed-off-by: Arne Schwabe <arne@openvpn.net>
2023-02-27 17:42:03 +01:00
Arne Schwabe
da41e7cfdf Ensure members of openvpn::TunLinuxSetup::Config are initialised
Reported-By: Trail of Bits (TOB-OVPN3-13)
Signed-off-by: Arne Schwabe <arne@openvpn.net>
2023-02-27 17:42:03 +01:00
Arne Schwabe
91859b1edc Use std::optional for rekey_type instead of rekey_type_defined
This also eliminates the undefined behaviour when rekey_type_defined
was false and rekey_type was not defined but copied

Reported-By: Trail of Bits (TOB-OVPN3-11)
Signed-off-by: Arne Schwabe <arne@openvpn.net>
2023-02-27 17:42:03 +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
charlie
c71d81f0a4
Fixes OVPN3-936 wstring deprecation warning Win32
Rewrote Win32 conversion routines to use Win32 native
conversion MultiByteToWideChar and WideCharToMultiByte.

When we go to a C++ version that supplies a non-
deprecated replacement we could revisit this.
2023-02-17 12:08:26 +01:00
charlie
a6dfe63ecc
Adds unit tests for new buffer implementation 2023-02-17 11:49:43 +01:00
James Yonan
15181cc1f1 Added OPENVPN_THROW_FMT macro for throwing a formatted exception
Signed-off-by: James Yonan <james@openvpn.net>
2023-02-10 19:59:37 -07:00
James Yonan
87c57514f5 unittests: added test_cliopt to .gitignore
Signed-off-by: James Yonan <james@openvpn.net>
2023-02-10 19:59:37 -07:00
Frank Lichtenheld
18f3ae7c25 Switch builds to c++17 standard
We want to use features only present with c++17.

Signed-off-by: Frank Lichtenheld <frank@lichtenheld.com>
2023-02-09 13:15:02 +01:00
Frank Lichtenheld
3a5d0f710c vars-linux: add work-around for Ubuntu 18
If we have g++-8 available use that so we can support C++ 17.

Signed-off-by: Frank Lichtenheld <frank@lichtenheld.com>
2023-02-02 10:51:38 +01:00
Heiko Hund
c6deee6270 fix some style and typos
Signed-off-by: Heiko Hund <heiko@openvpn.net>
2023-02-01 23:05:05 +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
be3834a740 Add public function to class KeyContext to EKM
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
Heiko Hund
b91e138106 add OpenVPNStaticKey::XOR() function
Allows to XOR (^) the key with the contents of another one.

Signed-off-by: Heiko Hund <heiko@openvpn.net>
2023-02-01 23:05:05 +01:00
David Sommerseth
3bcb671d33
scripts: Add pre-commit hook for clang-format style check
When enabling this pre-commit hook, clang-format will be run before the
commit can be completed.  If the changes about to be committed does not
adhere to the defined code style, the current commit will not be completed.

To install this pre-commit hook, run:

    $ ./scripts/git-pre-commit-clangformat.sh install

This script is a slightly modified version of what is used in the
OpenVPN 2.x project, slightly modified to use clang-format instead of
uncrustify and to extend the file change filter check to include C++ source
and header files.

Signed-off-by: David Sommerseth <davids@openvpn.net>
2023-02-01 19:16:51 +01:00
Arne Schwabe
07b77a13a1 Fix unsigned/signed mixing and unaligned accesses in gwv4.hpp 2023-02-01 16:43:53 +01:00
Arne Schwabe
3072d9431f Use memcpy to read from potientially unaligned memory in ipv6.hpp
The char* pointers we get can get be aligned to any adress. Use memcpy
to read from them to ensure we do not use unaligned reads/writes
2023-02-01 16:43:53 +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
d4c43ad50f Remove undefined behavior in IPv6::Addr::shiftl128 and shiftr128
This function were something doing 64 bit shifts on 64 bit integers
which is not defined. Ensure that all our shifts are between 0 and
63 and restructure the function to flatten the if conditions and
use recursion for the two shift instead of repeating the same logic
for the two shifts.

Reported-By: Trail of Bits (TOB-OVPN3-6)
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
Arne Schwabe
6de146361e Explictly initialise enable_nonpreferred_dcalgs as all other variables
This might be an noop as this might be default initialised but better
safe than sorry.

Reported-By: Trail of Bits (TOB-OVPN3-8)
2023-02-01 16:43:53 +01:00
Arne Schwabe
e64f710ea6 Add cmake build configuration to build with address sanatiser
This allows an easy way to build with llvm address sanitiser feature using

    CXX=clang++ CC=clang cmake -DCMAKE_BUILD_TYPE=asan

Reported-By: Trail of Bits (TOB-OVPN3-4)
2023-02-01 16:43:53 +01:00
Arne Schwabe
8b3542cd72 Remove LZ4_DISABLE_DEPRECATE_WARNINGS flag.
We do not use any deprecated LZ4 functions. So we can remove this flag
from our builds.

Reported-By: Trail of Bits (TOB-OVPN3-1)
2023-02-01 16:43:53 +01:00
Arne Schwabe
03e27e8c0a Do not print the length of passwords
Reported-By: Trail of Bits (TOB-OVPN3-3)
2023-02-01 16:43:53 +01:00
Lev Stipakov
20edab8dd5
dco-win: fix destroy_tun behavior
When agent-enabled client disconnects, it signals
destroy_tun event, which signals to agent that tun
has to be teared down. For dco-win, event handle is passed
to agent with /tun-open request.

Before sending /establish request, client closes previous
tun instance. Closing tun involves signaling destroy_tun event.
Event handle is closed after signaling, and here we have a problem:

 - client calls /tun-open and passes event handle to agent
 - client calls /establish, and before that it signals destroy_tun
   event, which handle is now closed
 - at some point client disconnects and signals tun_destroy event

Since event was already signaled and its handle is closed, nothing
happens and agent doesn't tear tun down. As a consequence, DNS
resolution might not work if DNS is overriden by VPN.

When client exits, agent tears tun down by failsafe logic. This doesn't
work for Connect client, which obviously doesn't exit on disconnect.

Fix this problem by avoiding signaling event between /tun-open
and /establish requests. This is done by not adding tun_setup
destructor (which signals event) to tun_persist right after /tun-open
call. There is nothing to tear down at that point yet since tun is
opened later by /establish call.

As a downside of this approach, we lose callback in client code
if agent process dies in between /tun-setup and /establish. This is
not a big problem IMO and can be fixed later.

In addition to that, send destroy_tun event also in /establish
request when using dco. This is needed to cover persist-tun case
when we reconnect and get new tun options. In this case we instantiate
new tun_setup instance, but don't call /tun-open since we keep tun
handle. Hence we have to pass destroy_tun event via /establish request.

Fixes https://github.com/OpenVPN/openvpn3/issues/257

Signed-off-by: Lev Stipakov <lev@openvpn.net>
2023-02-01 16:39:03 +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
df01679cf0
Add .git-blame-ignore-revs
This file will help reading through git blame and similar outputs, as
listed commit references will be ignored/skipped.  This file will
typically contain commits related to code style changes and similar
changes.  This way the code style commits will not add confusion to who
did a certain change.

Signed-off-by: David Sommerseth <davids@openvpn.net>
2023-01-25 13:13:39 +01: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
David Sommerseth
7590cb1093
OpenVPN 3 Core library version 3.7.2
Signed-off-by: David Sommerseth <davids@openvpn.net>
2022-12-14 17:28:56 +01:00
Arne Schwabe
aa3bcb8b3a
Fix route emulation not correctly working and being disabled
Signed-off-by: Arne Schwabe <arne@openvpn.net>
2022-12-14 17:23:13 +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
Arne Schwabe
d7c16e5878 Always use crypto library memcmp function in favour of our own
The crypto library function from OpenSSL uses custom assembler code
and should be safe. Also the code has been excersised already by the
Android/iOS builds.

Signed-off-by: Arne Schwabe <arne@openvpn.net>
2022-12-08 10:40:43 +01:00