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

4118 Commits

Author SHA1 Message Date
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
Charlie Vigue
f4f8caa400
Refactor RC - readability and doxygen
- Split big classes into declaration and definition
- Added doxygen

The goal here is to add make the classes easier to reason about by
splitting them into declaration and definition and then adding
doxygen.

The notify parts are left intentionally undocumented for now.

Signed-off-by: Charlie Vigue <charlie.vigue@openvpn.com>
2024-01-24 19:17:12 +01:00
Charlie Vigue
9f3d32b2f4
Add virtual default DTOR to ClientEvent::Base
ClientEvent::Base is the base class for many other classes including
a few that add data members. If at some point one of these enhanced
derived classes is referenced and then deleted via a base class
pointer, some memory could leak.

I don't think we do that yet, but it seems worth preventing.

Signed-off-by: Charlie Vigue <charlie.vigue@openvpn.com>
2024-01-24 16:24:14 +01:00
Charlie Vigue
b06252bb5d Cleanup API for JSON, map() --> asObject() etc
- .map() --> .asObject()
- .array() --> .asArray()

Required by changes in JSON API

Signed-off-by: Charlie Vigue <charlie.vigue@openvpn.com>
2024-01-23 13:21:53 +00:00
Arne Schwabe
1824aaed1d
Use OpenSSL 3.0 API for generating TLS 1.0 PRF
When compiling against OpenSSL 3.0, use the newer API for generating the
TLS 1.0 PRF.  Older OpenSSL versions will use the OpenSSL 1.x API.

Signed-off-by: Arne Schwabe <arne@openvpn.net>
2024-01-10 21:01:46 +01:00
Charlie Vigue
6bc9c0bd59
Check length of response before accessing it
The NTLM protocol implementation does not validate the length of
the proxy server’s response. If the response is shorter than
expected, the code will access the response buffer out of bounds,
which will raise an exception. This change checks and explicitly
raises an exception with an informative message if the response
is too short.

This was never a security issue as such but might result in a client
terminating early and without a nice diagnostic.

Signed-off-by: Charlie Vigue <charlie.vigue@openvpn.com>
2024-01-08 21:32:17 +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
8bfdc2809b Implement various fixes to avoid copying argument related to appcontrol 2024-01-04 17:51:23 +01:00
Frank Lichtenheld
44aa9acab2
ClientProto::Session: fix coverity issue "declaration hides parameter"
CID 11873: (#12 of 12): Parse warning (PW.PARAMETER_HIDDEN)
parameter_hidden: declaration hides parameter "e"

Signed-off-by: Frank Lichtenheld <frank@lichtenheld.com>
2023-12-20 23:18:33 +01:00
Frank Lichtenheld
185426c5e8
ServerProto::Session: fix coverity issue "declaration hides parameter"
CID 11809: (#2 of 3): Parse warning (PW.PARAMETER_HIDDEN)
parameter_hidden: declaration hides parameter "e"

Signed-off-by: Frank Lichtenheld <frank@lichtenheld.com>
2023-12-20 23:18:33 +01:00
Frank Lichtenheld
b4082c93cb
WS::Client::HTTPCore: fix coverity issue "declaration hides parameter"
CID 11948: (#2 of 2): Parse warning (PW.PARAMETER_HIDDEN)
parameter_hidden: declaration hides parameter "error"

Signed-off-by: Frank Lichtenheld <frank@lichtenheld.com>
2023-12-20 23:18:33 +01:00
Frank Lichtenheld
9524e33727
ClientOptions: fix coverity error "Structurally dead code"
CID 11851: (#1 of 1): Structurally dead code (UNREACHABLE)
unreachable: This code cannot be reached

Signed-off-by: Frank Lichtenheld <frank@lichtenheld.com>
2023-12-20 23:18:32 +01:00
Mark Deric
5b3294202c Prefer special purpose accessor to public
Instead of exposing protected data to the global environment, provide
a special purpose accessor to satisfy AppControl needs.

Signed-off-by: Mark Deric <jmark@openvpn.net>
2023-12-20 08:29:55 -08:00
Arne Schwabe
c151efc908 Allow specifying different client and server reasons for disconnect
Currently PG only allows to either send or withhold the reason to the
client but there are certain circumstances where you want to have more
detailed internal reason but still want to send some reason to the
client.

Signed-off-by: Arne Schwabe <arne@openvpn.net>
2023-12-13 16:51:22 +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
f97c00fc72 Make IV_PROTO defines public
This allows other code to use the values without having to repeat
the values.

Signed-off-by: Arne Schwabe <arne@openvpn.net>
2023-12-13 16:51:22 +01:00
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
f1ac7e500f Allow a client to announce custom control channel support
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
Arne Schwabe
e4f22c5567 Remove feature to allow a client to send INFO message
This is an obscure and never used feature to trigger sending
the SSO web auth URL from the client instead of server.

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
Arne Schwabe
247e74a929 Teach build to compile multiple compilation unit
Even though this script is deprecated, it is still used.

Signed-off-by: Arne Schwabe <arne@openvpn.net>
2023-12-13 16:51:22 +01:00
Frank Lichtenheld
130caea570 GHA: copy caching enhancements for coverity scan from OpenVPN 2
Do not run the daily scan if there was no push since the
last run.

Reduces resource usage and notification noise.

Signed-off-by: Frank Lichtenheld <frank@lichtenheld.com>
2023-11-30 11:53:27 +01:00
Heiko Hund
c5d37c4184
add Doxygen comments to randapi.hpp
Document classes RandomAPI, StrongRandomAPI and WeakRandomAPI

Signed-off-by: Heiko Hund <heiko@openvpn.net>
2023-11-29 22:17:49 +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
Arne Schwabe
6af5b505f1
Fix --compress initialising the wrong stub method
The option compress is extremely seldom used since there virtually no sense
in using it as all clients that support the compress option also support
pushing compression, so adding a stub only compression method by default
in the configuration does not give any benefit, only downsides.

When compress is in the config *and* the server never pushes any compression
option (even "push compress" is fine), we initialise "comp-lzo no" instead.
And comp-lzo and compress are different compression stub methods (byte swap
vs no byte swap) that are incompatible.

compress without argument in config is extremely seldom used.

Signed-off-by: Arne Schwabe <arne@openvpn.net>
2023-11-29 21:06:37 +01:00
David Sommerseth
48aa1920c7
Sync-up with the released branch (Core v3.8.3)
Some commits targeted for the Core v3.8.3 release did not end up
in the released branch and got lost.  These were already approved
for the Core v3.8.3 release.  This marks the starting point for
the Core v3.8.4 release.

Signed-off-by: David Sommerseth <davids@openvpn.net>
2023-11-29 21:04:37 +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
Mark Deric
ecdf041d63
Fix psid cookie older client failure bug [PG-93]
Older clients, 2.5.x and below, send an ACK_V1 packet in response to
the server's HARD_RESET packet whereas 2.6.x clients send a CONTROL_V1
packet.  The code that checked the packet length of the client's
response failed to comprehend the fact the ACK_V1 packet does not
include a packet id field following the peer session id field.  So the
code rejected the ACK_V1 packet as being too short.

The fix was to require packet length only up to and including the peer
session id field.  This works to allow safe parsing for both the
ACK_V1 response and the CONTROL_V1 response.

Signed-off-by: Mark Deric <jmark@openvpn.net>
2023-11-24 21:09:26 +01:00
James Yonan
b928585086
Time: added hash() template method
hash() will return a hash of the raw time.  It's useful
for unordered map/set collections where the key is a tuple
that includes a Time object.

Because hash() is a template method, it doesn't introduce
any new dependencies for class Time.

Signed-off-by: James Yonan <james@openvpn.net>
2023-11-24 21:06:18 +01:00
James Yonan
13bae10df5
VPNServerNetblock::Netblock: added override_server_gw() method
By default, the Netblock constructor already sets the server
gateway to the .1 address of the subnet, but the new method
override_server_gw() can now be used to override that
setting.

Signed-off-by: James Yonan <james@openvpn.net>
2023-11-24 21:06:17 +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
dfe26892b9 remove now unused RandomAPI::is_crypto function
Signed-off-by: Heiko Hund <heiko@openvpn.net>
2023-11-22 16:29:46 +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
87d0933b7c require TLS session ticket names use a strong PRNG
RFC 5077 talks about the ticket key_names to be randomly generated to
avoid collision between servers. To enforce unpredictable randomness,
require a strong PRNG to construct such names.

This is a formality, since all users of the class already provide such a
strong randmon number source.

Signed-off-by: Heiko Hund <heiko@openvpn.net>
2023-11-22 04:49:31 +01: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
cc58225888
Replace call of virtual in CTOR w/ non-virtual
Refactors the call of a virtual member function in the CTOR
by adding a private _impl function, which is non-virtual and
which both the CTOR and the original virtual function
delegate to.

Signed-off-by: Charlie Vigue <charlie.vigue@openvpn.com>
2023-11-10 16:05:46 +01:00
Charlie Vigue
3927b61b33
Changed virtual override to final
It's possible that someone might try to derive from and override
here, and if so the result will be perhaps not as expected. This
change will make it slightly harder to produce an unexpected
call to the wrong vtable dispatch from the ctor.

Signed-off-by: Charlie Vigue <charlie.vigue@openvpn.com>
2023-11-10 16:05:27 +01:00
Frank Lichtenheld
22ba196429
SITNL: revert change of sitnl_send return type, return int
This was changed in commit
ae663c573a ("Using new numeric
conversion tools") to avoid some conversion warnings. But
after understanding the workings of the function better, the
change turns out to have been wrong. Instead the function was
changed to use different intermediate variables for different
purposes.

This change ripples through the whole Netlink/SITNL interface.

Signed-off-by: Frank Lichtenheld <frank@lichtenheld.com>
2023-11-10 15:45:41 +01:00
Frank Lichtenheld
3b945e62e6
SITNL: document interface and code of sitnl_send function
Past changes make it clear that the interface was not well
understood.

While here, clean up the code to make it easier to understand.

Signed-off-by: Frank Lichtenheld <frank@lichtenheld.com>
2023-11-10 15:45:40 +01:00
Frank Lichtenheld
1e135e4f05
GeNL: add explicit casts in nl interface
To allow compiling the code with -Wconversion.

Also remove one line of unused code.

Signed-off-by: Frank Lichtenheld <frank@lichtenheld.com>
2023-11-10 15:45:29 +01:00