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

559 Commits

Author SHA1 Message Date
Charlie Vigue
dd115d2e83 Fix RouteBase string formatting bug
When correcting conversion issues in RouteBase a to_string bug was
introduced which caused some characters to be escaped when inserted
to the string, for example a prefix_len of 0 would render as "\0"
rather than inserting '0'. The std::ios::binary flag does not seem
to prevent this for std::ostringstream so I have cast the data member
up to uint16_t which should be safe, and solves the issue.

Added a unit test to demonstrate the issue. Old code output was
"0.0.0.0/\0", now outputs "0.0.0.0/0" as expected.

Signed-off-by: Charlie Vigue <charlie.vigue@openvpn.com>
2024-03-29 03:13:00 +00:00
Mark Deric
5955f05eab Improve C2os unit tests with better templates
Signed-off-by: Mark Deric <jmark@openvpn.net>
2024-03-28 11:27:23 +00:00
Mark Deric
18e92a823f Extend C2os to handle containers of pointers
Create a new cast to tell the ostreamer to dereference before
inserting.

Signed-off-by: Mark Deric <jmark@openvpn.net>
2024-03-22 15:15:10 +00:00
Illia Polishchuk
00bdf8ba8b Make profile errors clearer for users by reporting specific error codes.
ERR_INVALID_OPTION_DNS -- invalid value for some of DNS\Domain options
ERR_INVALID_OPTION_CRYPTO -- invalid value for some of SSL\Crypto option
ERR_INVALID_CONFIG -- missing option or not supported option
ERR_INVALID_OPTION_PUSHED -- pushed to server option error
ERR_INVALID_OPTION_VAL -- invalid value for some general option

Signed-off-by: Illia Polishchuk <illia.polishchuk@openvpn.com>
2024-03-22 15:15:09 +00:00
Arne Schwabe
282075fee9 Allow test_sslctx to work with mbed TLS
Signed-off-by: Arne Schwabe <arne@openvpn.net>
2024-02-23 15:32:58 +01:00
Arne Schwabe
c1bcf78d2e Add support for mbed TLS 3.0
This currently still depends on the mbed TLS compat API functionality.

Signed-off-by: Arne Schwabe <arne@openvpn.net>
2024-02-23 15:32:58 +01:00
David Sommerseth
bae10062b3
Merging in changes from OpenVPN 3 Core version 3.8.4
Signed-off-by: David Sommerseth <davids@openvpn.net>
2024-02-19 22:46:53 +01: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
Charlie Vigue
cb9ce3d71c
Add notes to sslctx and add unit tests
- Add notes regarding some unexpected behaviors in sslctx
- Add unit tests specifically for sslctx, including simple in-memory
handshaking with both success and failure examples.

Signed-off-by: Charlie Vigue <charlie.vigue@openvpn.com>
2024-02-01 13:29:21 +01:00
Frank Lichtenheld
fe40d7288f
Change some arguments to const refs
Triggered by move suggestions from Coverity.

Signed-off-by: Frank Lichtenheld <frank@lichtenheld.com>
2024-01-31 17:02:47 +01:00
Frank Lichtenheld
fdf55e8776
ovpncli: simplify Client::open_url()
Remove unused argument "flags".

Signed-off-by: Frank Lichtenheld <frank@lichtenheld.com>
2024-01-31 17:02:46 +01:00
Frank Lichtenheld
eaf9147fcd
Add various moves as suggested by Coverity
Out of all the suggestions by Coverity I picked
the ones that move non-Ptr objects into variables
or attributes.

Signed-off-by: Frank Lichtenheld <frank@lichtenheld.com>
2024-01-31 17:02:45 +01:00
Frank Lichtenheld
853169a566
Fix various "auto causes copy" Coverity warnings
No reason not to fix those.

Signed-off-by: Frank Lichtenheld <frank@lichtenheld.com>
2024-01-31 17:02:28 +01: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
8ad83b5ae8 Add missing length check in parsing ACC messages, add more related tests
Signed-off-by: Arne Schwabe <arne@openvpn.net>
2024-01-04 17:51:23 +01:00
Arne Schwabe
2910164ebf Add helper method for reliable uniform int for unit tests
Signed-off-by: Arne Schwabe <arne@openvpn.net>
2023-12-13 16:51:22 +01:00
Arne Schwabe
95b821a2fd Allow to string methods of IP::Addr to display mapped IPv4 as plain IPv4
Some systems like to see the mapped IPv4 addresses as real IP addresses.
This commit adds the ability to show IP addresses as such.

Signed-off-by: Arne Schwabe <arne@openvpn.net>
2023-12-13 16:51:22 +01:00
Arne Schwabe
e9ade86de7 Implement logic to send and receive custom control channel messages
This adds the capability to implement a custom app level protocol
that support message passing over the OpenVPN control channel.
The protocol is agnostic to the data that is transported over it
and the message splitting/reassmbly is handled transparently by the
OpenVPN library itself.

Signed-off-by: Arne Schwabe <arne@openvpn.net>
2023-12-13 16:51:22 +01:00
James Yonan
c93b235260
unitests: added test_time to .gitignore
Signed-off-by: James Yonan <james@openvpn.net>
2023-11-24 21:06:16 +01:00
Heiko Hund
47795ea2d5 remove 'prng' argument from SSLLib::RandomAPI ctor
It was only supported by mbedTLS and is very easily used wrong since it
is just a boolean value. Other TLS stacks were using the regular strength
PRNG no matter what. Also we should not weaken a crypto strength PRNG,
now that we have the StrongRandomAPI type in place. It might give the
wrong sense of strength, when in reality we might reseed a hundred times
less often.

In places where prng was passed as true before, use MTRand now instead.

Signed-off-by: Heiko Hund <heiko@openvpn.net>
2023-11-22 04:49:31 +01:00
Heiko Hund
e484aceec9 require a strong PRNG for session id generation
Since session ids should always be truly random require a
cryptographically strong random number generator.

Since all places in the codes (besides tests) already pass a strong
random source, this is just a formality.

Signed-off-by: Heiko Hund <heiko@openvpn.net>
2023-11-22 04:49:31 +01:00
Heiko Hund
be3f20dc58 introduce base types for strong and weak RNGs
The need of having to call the assert_crypto() member function to ensure
that a cryptographically strong RNG is used where needed, was reported
as potentially insecure, since calling it manually can easily be missed.

In the commit the two new classes StrongRandomAPI and WeakRandomAPI are
introduced. They are to be used instead of just RandomAPI, unless it
doesn't matter what strength the RNG is.

All the places the assert_crypto() was called were converted to using
StrongRandomAPI instead. Also the RNGs for which assert_crypto() was not
throwing are now inheriting from StrongRandomAPI.

Variable names, which have the StrongRandomAPI type, but were called
prng, are changed to rng instead to follow the source code convention.

Signed-off-by: Heiko Hund <heiko@openvpn.net>
2023-11-22 04:49:31 +01:00
Frank Lichtenheld
cb06f9e330
SplitLines/UserPass: Review fixes
Signed-off-by: Frank Lichtenheld <frank@lichtenheld.com>
2023-11-08 21:05:06 +01:00
Frank Lichtenheld
59a1d2398e
test_splitlines: New UT for SplitLines
Also enable UserPass UT that now passes with new
SplitLines.

Signed-off-by: Frank Lichtenheld <frank@lichtenheld.com>
2023-11-08 21:05:05 +01:00
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
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
Mark Deric
ef74a5b059 Improve psid cookie unit tests [OVPN3-1069]
-- Instantiate the PsidCookieImpl and spot check it's correctness
-- Check for client replies within and outside of the allowable time
   window

Signed-off-by: Mark Deric <jmark@openvpn.net>
2023-10-25 09:10:40 -07:00
Arne Schwabe
34a1faf162 Fix logic of INFO_PRE and INFO substring replacment swapped
The refactoring introduced a logic error were the two options are
swapped.
2023-10-12 18:18:48 +02:00
Frank Lichtenheld
542457f986 test_clamp_typerange: avoid -Wconversion warning
Make sure the lambda return types are correct.

Signed-off-by: Frank Lichtenheld <frank@lichtenheld.com>
2023-10-11 12:28:55 +02:00
Frank Lichtenheld
227a8e7a65 test_proto: avoid -Wconversion warning
Instead of magic constant say what we want to say.
So that randrange also produces the correct output
type.

Signed-off-by: Frank Lichtenheld <frank@lichtenheld.com>
2023-10-11 12:28:55 +02: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
Frank Lichtenheld
7cd7b6619e
Fix misc wrong types
Signed-off-by: Frank Lichtenheld <frank@lichtenheld.com>
2023-09-28 11:33:44 +02:00
Frank Lichtenheld
8f7fdd10ff
Use openvpn_io::detail::socket_type instead of "int"
On Linux those might be identical, but not on Windows.

Signed-off-by: Frank Lichtenheld <frank@lichtenheld.com>
2023-09-28 11:33:41 +02:00
Frank Lichtenheld
0ba4910509
Address warning C4101 (unreferenced local variable)
Usually caused by the only use being in macros that do not
necessarily expand to code depending on the preprocessor
flags.

While here, convert existing work-arounds to [[maybe_unused]]
as well.

Signed-off-by: Frank Lichtenheld <frank@lichtenheld.com>
2023-09-28 11:33:35 +02:00
James Yonan
36f8122389 PacketStream: templatize stream segment length word
PacketStream was originally used in the OpenVPN protocol
to segment a TCP stream into packets.  Then we realized
it could perform the same function for the DNS protocol.
Now there are other protocols of interest (such as the
Vici protocol in Strongswan) that also use stream
segmentation, but use a different word size for the
stream length as represented on the wire protocol.
OpenVPN and DNS use a 16 bit word size, while Vici uses
a 32 bit word size.  Both use network-endian encoding
of the word size.

So this patch makes the stream length word size a
template parameter.

Signed-off-by: James Yonan <james@openvpn.net>
2023-09-17 10:08:36 -06:00
David Sommerseth
75dbcdfa93
Merge OpenVPN 3 Core v3.8.2 into master
Signed-off-by: David Sommerseth <davids@openvpn.net>
2023-09-13 16:46:05 +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
f159710100
Rename ProtoContext::Config to ProtoContext::ProtoConfig
The name Config is very generic and often leads to confusion which
class in particular is used in a given context. Rename Config to
ProtoConfig to give some more clue about the context.

Signed-off-by: Arne Schwabe <arne@openvpn.net>
2023-08-23 21:13:02 +02:00
Arne Schwabe
ff80eca4e5
Rename ProtoContextOptions to ProtoContextCompressOptions
This might have been used or intended to be used for more than compression
but currently it is only used for compression, so rename it accordingly.

Signed-off-by: Arne Schwabe <arne@openvpn.net>
2023-08-23 21:13:01 +02:00
Charlie Vigue
a9e152522a
Enhancing clamp_ tooling
Signed-off-by: Charlie Vigue <charlie.vigue@openvpn.com>
2023-08-23 18:44:22 +02:00
Charlie Vigue
de2f6d422e
Switched C casts to static_cast
Signed-off-by: Charlie Vigue <charlie.vigue@openvpn.com>
2023-08-23 18:44:16 +02:00
Charlie Vigue
b6b8282d33 Addressed 2nd set of -Wconversion warnings
- Used static_cast instead of direct type conversions in places where
it's safe
- Used numeric_cast where failure is possible
- Changed types of arguments and locals when practical

Signed-off-by: Charlie Vigue <charlie.vigue@openvpn.com>
2023-08-21 13:51:50 +00: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
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
Arne Schwabe
75dbf4b5d2 Rename generate_tun_builder_capture_event to camelcase
This makes this option have the same style as the other options in
the client config to ensure consistencyv

Signed-off-by: Arne Schwabe <arne@openvpn.net>
2023-07-25 12:00:48 +02:00
Arne Schwabe
0c5e356075 Simplify client options classes
The current passing of client options is very confusing since it is
three classes that largely have the same attributes and the code is
copying them around between the classes.

Instead create a new base class that hold the settings that can be shared
between the classes and only parse/copy the settings that need special
handling. This might keep an extra copy of some settings around but in
constract greatly reduces the code complexity of the options handling.

Also move the check_dco_compatibility function to client options to
be able to avoid carrying around the dco_compatiblity flag.

Signed-off-by: Arne Schwabe <arne@openvpn.net>
2023-07-25 12:00:48 +02:00
David Sommerseth
8f5afdd3f8 OpenVPN 3 Core library version 3.8
-----BEGIN PGP SIGNATURE-----
 
 iQJHBAABCAAxFiEEgDq5E1p1aZrNLFFkhs+UTJZx/fIFAmSb2ywTHGRhdmlkc0Bv
 cGVudnBuLm5ldAAKCRCGz5RMlnH98lKHD/4z+eI5Jlek9f1q+CcPopGwTBZHkN1u
 lTtnU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hd7Z350s7bjsl2ejxj7FmrEXaCh3geK8ovfYfurpX5me8i389LcaM/TD
 MvBStvZIJa2inYxU5IUQnGtqGYdtU4IW8VM3aq8pNy2+U9WNnC/3Q1msplOjPPur
 a2WzNnRcFqxxeVgNmYZgdiS3m6FvAaG3bGUN9haFz3Rjz0yaumbhA4VrLmcimghj
 9AarITBznK8h+JqHdEIarZWwOfLj7A7sdsKQwe7ycBs29WbRW6+iSkhNxnI0BcLu
 mgwf00il4czEWIUthlTF7KcREj/WE/rMSDGAcW+TKJZpdffS2FVQeQITG9SLuBJa
 fVD9C1UYfrrkk408YuButJK2aEYICVFkDfmWcRxF2s8zxyPaVhCLyx2jTaIILV5M
 7HzgnHjlc8e5mhwI3/bE09pzrogtXd3n0s2Yf+f1h8y31GgUHKZRIqY2ESIZghML
 9BZmMAnOprRuWw==
 =HH92
 -----END PGP SIGNATURE-----

Release Merge: OpenVPN 3 Core library version 3.8

Signed-off-by: David Sommerseth <davids@openvpn.net>
2023-06-28 09:13:00 +02:00