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

794 Commits

Author SHA1 Message Date
Arne Schwabe
9afc0b2310 Allow ovpn::string::join to work also with other contains than std::vector
Signed-off-by: Arne Schwabe <arne@openvpn.net>
2023-12-13 16:51:22 +01:00
Arne Schwabe
335daeb454 Ensure Link raw pointer constructor is only used with intrusive pointers
Using the raw pointer constructor only really works if the pointer is
intrusive. Ensure this with a static assert

Signed-off-by: Arne Schwabe <arne@openvpn.net>
2023-12-13 16:51:22 +01:00
Charlie Vigue
deaced48bd
Fixed call of virtual from DTOR issue
Removed virtual and changed the only overrider of the virtual to
do the special case

Signed-off-by: Charlie Vigue <charlie.vigue@openvpn.com>
2023-11-29 22:15:46 +01:00
James Yonan
a93d711927 Coverity 11892: in class Stop, address lock-free access to stop_called member
In class Stop, the stop_called member is safe to read
without locking, but make it volatile to document this.

Signed-off-by: James Yonan <james@openvpn.net>
2023-11-24 16:59:07 -07:00
Heiko Hund
bf6d373c93 require a strong PRNG for temp filename generation
Since predictable names for temporary files can potentially cause a
security issue, require such filenames to be generated with
unpredictable randomness.

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
dffd6036e0 RC: suppress compiler warnings with GCC 12 and 13
We're pretty sure that these warnings are false positives.
Both are related to destructing MultiCompleteType objects.

GCC 12 (thread_unsafe_refcount):
rc.hpp:322:18: pointer used after ‘void operator delete(void*, std::size_t)’
[-Wuse-after-free]

GCC 13 (thread_safe_refcount, only arm64):
inlined from ‘...thread_safe_refcount::operator--()’ at .../rc.hpp:404:39
atomic_base.h:645:34: ‘long unsigned int __atomic_sub_fetch_8(...)’ writing
8 bytes into a region of size 0 overflows the destination
[-Werror=stringop-overflow=]

Signed-off-by: Frank Lichtenheld <frank@lichtenheld.com>
2023-11-15 16:58:06 +01:00
Charlie Vigue
e2f3f7509a
numeric_util: Add missing cstdint include
Signed-off-by: Charlie Vigue <charlie.vigue@openvpn.com>
2023-11-08 21:23: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
1cf9556fe0
SplitLines: Add doxygen documentation
Signed-off-by: Frank Lichtenheld <frank@lichtenheld.com>
2023-11-08 21:05:06 +01:00
Frank Lichtenheld
4620b1f8cd
SplitLines: throw on error
Except in the next() interface which allows for more
fine-grained error control.

Signed-off-by: Frank Lichtenheld <frank@lichtenheld.com>
2023-11-08 21:05:04 +01:00
Frank Lichtenheld
34c06c2f7a
UserPass: add doxygen documentation
Based on the understanding from the unittest.

Signed-off-by: Frank Lichtenheld <frank@lichtenheld.com>
2023-11-08 21:05:03 +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
Frank Lichtenheld
185182e1be
UserPass: rename one overload of parse to parse_file
This really has very different implications than the
others overloads. So make it distinct.

I would also rename the others to parse_opt, but feel
that causes too much churn in the code. parse_file has
only one use in our own code base.

Signed-off-by: Frank Lichtenheld <frank@lichtenheld.com>
2023-11-08 21:04:41 +01:00
Frank Lichtenheld
40d987f335 Avoid some -Wconversion warnings by changing parameter types
These functions can safely handle bigger types, so
avoid needless downcasts.

Signed-off-by: Frank Lichtenheld <frank@lichtenheld.com>
2023-10-11 12:28:55 +02: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
97924d6c92
Use uint64_t for hash values
They are uint64_t. Usually size_t is a uint64_t as
well, but not always (e.g. Win32).

Signed-off-by: Frank Lichtenheld <frank@lichtenheld.com>
2023-09-28 11:33:39 +02:00
Frank Lichtenheld
e02821915a
file.hpp: explicitely convert between std::streamsize and size_t
They might not be identical (e.g. Win32).

Since everything in this function is limited by
block_size, the casts are all safe.

Signed-off-by: Frank Lichtenheld <frank@lichtenheld.com>
2023-09-28 11:33:38 +02:00
James Yonan
133bcec850 jsonfile: added read_fast_dict() function
read_fast_dict() is a convenience function that reads JSON
from a file, but also validates that the top-level construct
of the file is a JSON dictionary.

Signed-off-by: James Yonan <james@openvpn.net>
2023-09-17 10:08:36 -06:00
James Yonan
5711be6b97 string: added remove_char()
Signed-off-by: James Yonan <james@openvpn.net>
2023-09-17 10:08:36 -06:00
James Yonan
cfe4a9a9e7 Option: make constructor explicit
The Option constructor is quite general and therefore
prone to implicit matching.  Make it explicit to prevent
that.

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
David Sommerseth
ea747cba84
Release: OpenVPN 3 Core Library, version 3.8.2
Signed-off-by: David Sommerseth <davids@openvpn.net>
2023-09-13 15:02:35 +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
Charlie Vigue
ae663c573a
Using new numeric conversion tools
Using is_safe_conversion in places where it is a better fit than
numeric_cast.

Signed-off-by: Charlie Vigue <charlie.vigue@openvpn.com>
2023-08-23 18:44:29 +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
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
James Yonan
5c27ed24b1
enum_dir: restore move semantics
This commit mostly reverts a previous commit:

commit b7bc687396

    Avoid compiler warning with gcc by not using move semantics

The previous commit changed the semantics of the client
callback to use copy instead of move semantics on the
filename string to placate a compiler warning which was
later determined to be a false positive.

We revert to calling the client-provided func()
with move semantics on the filename parameter.

We also retain the use of std::invoke to call the
client-provided callback.

Signed-off-by: James Yonan <james@openvpn.net>
2023-08-09 20:04:34 +02:00
David Sommerseth
43669510ed
Merging in OpenVPN 3 Core Library v3.8.1
Signed-off-by: David Sommerseth <davids@openvpn.net>
2023-08-01 14:42:25 +02:00
David Sommerseth
cd0c404275
Release: OpenVPN 3 Core Library, version 3.8.1
Signed-off-by: David Sommerseth <davids@openvpn.net>
2023-07-31 18:58:00 +02:00
Arne Schwabe
bfdfa13082 Make RC pointer class a bit nicer
- use = default for constructur/deconstructors
- deleted constructors should be public

Signed-off-by: Arne Schwabe <arne@openvpn.net>
2023-07-05 14:16:09 +02:00
Arne Schwabe
71e94d9e8f Disable dangling warnings for json helper
This is though to be a bug in the GCC compiler.
Ignore these warnings on GCC 12/13 to avoid breaking
Werror.

Signed-off-by: Arne Schwabe <arne@openvpn.net>
2023-07-04 14:44:22 +02:00
Arne Schwabe
b7bc687396
Avoid compiler warning with gcc by not using move semantics
gcc 12+ warn about temporary that used after its lifetime when we use
the move semantics here. Since the code here is not super performance
critical just remove the move semantics to be able to compile with
Werror.

Signed-off-by: Arne Schwabe <arne@openvpn.net>
2023-07-03 13:29:48 +02:00
David Sommerseth
8f5afdd3f8 OpenVPN 3 Core library version 3.8
-----BEGIN PGP SIGNATURE-----
 
 iQJHBAABCAAxFiEEgDq5E1p1aZrNLFFkhs+UTJZx/fIFAmSb2ywTHGRhdmlkc0Bv
 cGVudnBuLm5ldAAKCRCGz5RMlnH98lKHD/4z+eI5Jlek9f1q+CcPopGwTBZHkN1u
 lTtnUgKtGZ7x42PZr5t5W+vcQspHSMurlYOjCES6d4DjYJ6vW3/a5qm4s7OokW6u
 Ts2iGWGSf09kDXVff7ogfsJs3LTi/GDNq9VTTWH3fGyEaM89w2ss9OpUBjDImpbs
 nCU7B3BgXIBKKsl4sKNfm8kulakEp4YZlMlvuvGujfTWc8ATqP2tsGdV8HN82gXl
 7uw9N7/aaU6VFgpGjqgdkChAHJlcr9koUWPtVr+4Hf934jQYX4d80SI3umzs2JfW
 xEIcWwStTKztFB5l/Vr6hNmR5sMdW5AEvHfc2W/31gng5cK/0VxEElPQMvVxFteC
 7SlkpNH70mUC5FgO9lIuoUGxYV0MV3+lHrYHBcj2/7z4B4C57K7reqToNHMpT1Ns
 7Cdfu50wijtOnwy0VY/PCkPNLC5lfO2tka+ZLuIDq6p7V1uapA49Axqli9QZ+IZ8
 mYIFQrFKkD3E6NTlDKiMBGnWqKR9U/O49hQAN6I7Kx79GqrPTj/3Q8Z7pZ5iulPQ
 aXjWKvfBdWpR3XmkU30EGKN5J98Wh1qPv56gJ3d71ab4FM57eTfp9BdXbuGHxq9P
 YdExIbZM2Wmv5AQMLAMkw4O7FtABSIPONCz7lD8d9PoCRb1trsnDKQ8ZgFfrOIcs
 BeDyC2eZeBeMnw==
 =1Hd0
 -----END PGP SIGNATURE-----
gpgsig -----BEGIN PGP SIGNATURE-----
 
 iQJHBAABCAAxFiEEgDq5E1p1aZrNLFFkhs+UTJZx/fIFAmSb3boTHGRhdmlkc0Bv
 cGVudnBuLm5ldAAKCRCGz5RMlnH98hjnD/0XyldUsdoEgrM0PKDe7u/u7RYxQx1n
 gCrhLZQbnE++U1qITRraHfQu0qLLLXwFIDBiagIVuotcxwOWPz1+tTyUICc4KsLS
 zzkuube2aSBRtbwa8C4FfDuKSWosCOTv56ZE/3Ioq6v0Hf7sDqMDCvUxBjNlQLWu
 m604/yxWxAEnu6lHPY5rj3+9U5TSpErXJk/DqW6ewJjh/TFWG5nA1Z2Q/IF0XIR9
 pbqnhL1Dhd7Z350s7bjsl2ejxj7FmrEXaCh3geK8ovfYfurpX5me8i389LcaM/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
David Sommerseth
44f9cc447c
Release: OpenVPN 3 Core library version 3.8
Signed-off-by: David Sommerseth <davids@openvpn.net>
2023-06-28 08:58:16 +02:00
Arne Schwabe
e1037508e3
Add minimal FreeBSD support
Signed-off-by: Arne Schwabe <arne@openvpn.net>
2023-06-22 19:07:20 +02:00
Arne Schwabe
966515737d
Add missing includes in cli.cpp
The code for browser opening on Unix platforms assumes some includes to
be always present but nulltun + FreeBSD actually do not have include them.
So include them explicitly. And since this break windows, ensure that
process.hpp does nothing on that platform.

Signed-off-by: Arne Schwabe <arne@openvpn.net>
2023-06-22 19:07:19 +02:00
Antonio Quartulli
699bcb455a
numeric_cast.hpp: add missing include
Including cstdint is required by uintmax_t.

Fixes the following:

openvpn/common/numeric_cast.hpp:66:25: error: ‘uintmax_t’ does not name a type

Signed-off-by: Antonio Quartulli <antonio@openvpn.net>
2023-06-08 17:30:40 +02:00
David Sommerseth
0bcdeff84a
Merging changes from releaseprep/3.8 2023-05-10 19:57:23 +02:00
Arne Schwabe
9e5de78347 Document behaviour of Signal class a bit more
Signed-off-by: Arne Schwabe <arne@openvpn.net>
2023-05-10 17:23:33 +02:00
James Yonan
493a5d8d15 RCCopyable: added move methods for construction/assignment
Copy/move construction/assignment are no-ops because
we always want to default-construct the refcount from
scratch.  We never want to actually copy or move
the refcount because that would break any
referencing smart pointers.

Signed-off-by: James Yonan <james@openvpn.net>
2023-05-01 11:48:16 -06:00
James Yonan
f3a861d54c jsonhelper: provide rvalue reference overloads for all methods that return a reference to a passed object
Signed-off-by: James Yonan <james@openvpn.net>
2023-05-01 11:48:09 -06:00
Arne Schwabe
0d0e3809c1
Remove OPENVPN_EXTERN
with the new C++17 capability of inline for variables, we can avoid
having to ifdef tricks to only include the variables into one compilation
unit. Also remove the extern.hpp that serves no purpose now anymore.

Signed-off-by: Arne Schwabe <arne@openvpn.net>
2023-04-27 23:35:41 +02:00
Frank Lichtenheld
5a84a32f9f Add some preprocessor checks for Windows ARM64
Signed-off-by: Frank Lichtenheld <frank@lichtenheld.com>
2023-04-24 14:37:44 +02: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
David Sommerseth
bc3b549ed6
Merge changes from releaseprep/3.8
Signed-off-by: David Sommerseth <davids@openvpn.net>
2023-03-08 17:24: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
Charlie Vigue
f38e97e1c3 Eliminate some conversion warnings
- [ipv4.hpp, ipv6.hpp] In both v4 and v6 headers it is safe to cast the hex
so as to eliminate the spurious warnings.

- [lz4.hpp] Apply value clamp to the hint that is sent to the compressor
to prevent a potential conversion overflow.

- [zlib.hpp] In compress_gzip, zs.s.avail_in and zs.s.avail_out are
theoretically susceptable to overflow. To prevent this we use
numeric_cast. In decompress_gzip we do a similar thing for zs.s.avail_in
but only value clamp avail_out, since the read loop looks like it will
compensate

- [buffmt.hpp] It's safe to cast the result of the arithmentically caused
promotion back down to char.

- [base64.hpp] In Base64 CTOR, changed type of a couple variables to
match the type of the table they generate. In decode, perform a static
cast to the type of the template elements the function is
instantiated for.

- [core.hpp] Perform static cast long --> int on value representing
number of cores. If we run on systems where there are more cores than
int can represent this will behave oddly, but this circumstance
seems unlikely at the present time.

- [environ.hpp] The casts seem to be safe but I have added a todo ticket
to evaluate this change further.

- [hexstr.hpp] In render_hex_char there were two conversion warnings
and a bug involving out of range input. Those are addressed.
In dump_hex the result of some math and logic is now clamped
to the range of acceptable input values for string::spaces
In parse_hex the result of converting from a hex string to an
integral value is cast to the template value_type

- [hostport.hpp] The static_cast should be safe because the value
produced by validate_port is range checked.

- [split.hpp] Applied numeric cast to ensure output of lex.get stays
within acceptable type limit.

- [stop.hpp] In Stop::Scope It's extremely unlikely but was possible for
the vector size to exceed the limit of int. The size now has a much lower
limit applied and will throw if it is exceeded.

- [string.hpp] Changed the call to toupper/tolower so they call the
locale function template instead of the cctype C function. This
eliminates the warning and the need for the cast.

- [cliproto.hpp] The computation of mss_fix is stored in a size_t and
then assigned to an unsigned short. We clamp this assignment
to the range of unsigned short.

- [tempfile.hpp] In TempFile CTOR suffixLen is computed as one type
and consumed as another. Since the CTOR is already throwing
for a couple other error conditions, I have added a
numeric_cast to the conversion that also throws in case of a
value overflow.

- [unicode.hpp] In an 8 --> 16 bit string conversion we mask and assign
in a way the compiler can't be certain is safe even though it is safe.
Added static cast to let the compiler know it's safe. In the second case
the class uses unsigned int to store a size, and then uses it in with size_t
which generates conversion warnings. I have changed the type of size
to size_t

- [logperiod.hpp] in log_period changed return type specification to
match the actual return type.

- [usergroup_retain_cap.hpp] In the unlikely event the caps size (size_t)
exceeds the range cap_set_flag can accept, an exception will be thrown.

- [crypto_aead.hpp] StaticKey::size provides a size_t where unsigned int
is required. We use numeric_cast to check the size() value in the
extremely unlikely event it is manipulated to exceed the allowed value.

- [packet_id.hpp] Code packs a time_t into a uint32_t for replay packet
ID protection purposes. The warning is supressed by a mask and cast
since the 32 bit limit is baked into the protocol and the overflow itself
does not cause a severe breakage.

- [headredact.hpp] Altered code such that the type that stores the find
result is compatible with the result from find. Additionally used the
npos constant instead of -1. There is a commented out code block that
claims to be dropped due to requiring C++ '14 - consider just using
that.

- [csum.hpp] in csum fold and cfold one has a mask and cast, the
second is just a cast to undo a promotion. Both appear safe.

- [ipv4.hpp] Values are masked and shifted so the cast should be safe.
Added cast.

- [ping4.hpp] ICMP ID and sequence number function arguments are
changed to the same type as needed by the structure. For
IPv4 header version_len 2nd arg is int but sizeof is not, so we
cast it. IPv4 tot_len is a uint16_t so we clamp to that value
range and compute it once.

- [ping6.hpp] Enforces a value constraint on the len argument to
csum_icmp, then checks the result of some math to ensure
the result will fit in the type it has to fit. In generate_echo_request
the ICMP ID and sequence args are changed to match the
type they are assigned to in the struct, and added
numeric_cast to range check payload_len.

 - [remotelist.hpp] In get_endpoint, endpoint.port is called with an
unsigned int where the function is expecting an unsigned short int.
Since parse_number_throw is a function template, we just ask it to
return the correct type now.

- [compress.hpp] In v2_push we accept an int value that is assigned to
an unsigned char we push to the buffer. I changed the function to
accept an unsigned char directly.

Added unit tests - thanks Mark Deric.

Signed-off-by: Charlie Vigue <charlie.vigue@openvpn.net>
2023-03-08 15:21:50 +00: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