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

304 Commits

Author SHA1 Message Date
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
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
Mark Deric
22af472e8a
Improve names
-- disambiguate new_obj(): new_man_obj(), new_tun_obj
-- remove obfuscatory typedef <class> Base; use <class>
-- in servproto.hpp typedef ProtoContext::ProtoConfig to ProtoConfig
   since Arne's already disambiguated Config
-- disambiguate Link<>: TCPLink<>, UDPLink<>

Added TODO comment on unneeded version of control_net_recv()

Signed-off-by: Mark Deric <jmark@openvpn.net>
2023-10-11 18:49:23 +02:00
Frank Lichtenheld
cc5e61e81b
httpcommon.hpp: Add missing cast from CONTENT_LENGTH_TYPE to size_t
With the std::max we do make sure it is > 0, so this
should be safe.

Signed-off-by: Frank Lichtenheld <frank@lichtenheld.com>
2023-09-28 11:33:40 +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
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
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
Frank Lichtenheld
dabc3a0009 Fix various problems with implicit size_t casts
All of these cases are safe casts since the
value is checked before-hand. So convert them
to explicit casts.

Signed-off-by: Frank Lichtenheld <frank@lichtenheld.com>
2023-06-28 14:22:31 +02:00
James Yonan
cdc62e9a9c WS::Client::AltRoutingShimFactory: make local_ip() plural and remove error_expire()
* local_ip() has been renamed to local_addrs() and now
  returns a vector of addresses.  This is because the
  user may want to specify local addresses for both
  IPv4 and IPv6.

* error_expire() has been removed because it currently
  has no users.

Signed-off-by: James Yonan <james@openvpn.net>
2023-05-05 15:06:01 -06:00
James Yonan
993875b6f8 WS::Client: added websocket_timeout parameter
Previously, when WS::Client entered websocket streaming
mode, it would cancel the general_timeout.

Now when websocket_timeout is nonzero, general_timeout will
be reset to the websocket_timeout value when the websocket
begins streaming.  This allows websocket use cases
to retain a general_timeout even during streaming.

By default, websocket_timeout is set to zero, which will
retain the pre-existing behavior of canceling the
general_timeout when streaming begins.

Signed-off-by: James Yonan <james@openvpn.net>
2023-04-28 09:34:01 -06:00
James Yonan
8654108234 WS::Server: added a comment about ksm.is_internal() usage
Signed-off-by: James Yonan <james@openvpn.net>
2023-04-28 00:00:02 -06:00
James Yonan
55dd04c6a6 WS::Client: in AltRoutingShimFactory, added virtual method local_ip()
When WS::Client is operating with a AltRoutingShimFactory
object, bind to the local address provided by the local_ip()
method if defined.

Signed-off-by: James Yonan <james@openvpn.net>
2023-04-28 00:00:02 -06:00
James Yonan
d7e5bd5397 WS::Client: in AltRoutingShimFactory, added virtual method alt_routing_debug_level()
Previously the debug message "ALT_ROUTING HTTP CONNECT to ..."
was conditional on debug_level in WS::Client::Config being
>= 2.

Instead, we now consult alt_routing_debug_level()
defined by AltRoutingShimFactory for the debug level.

This makes it more straightforward to debug
AltRoutingShimFactory because the relevant debug levels
have been consolidated within the class being debugged.

Signed-off-by: James Yonan <james@openvpn.net>
2023-04-28 00:00:02 -06: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
David Sommerseth
4996c38ed4
Merge lastest changes from Core v3.7.2 2022-12-14 17:34:29 +01: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
5b524b1f86 WS::ClientSet: added new TransactionSet flag retry_on_http_4xx
When enabled, retry_on_http_4xx indicates that HTTP status
codes between 400 and 499 should be considered a
retryable error.  AWS appears to need this.

Note that error codes between 500 and 599 are always
considered to be retryable.

Signed-off-by: James Yonan <james@openvpn.net>
2022-06-29 08:39:22 -06:00
James Yonan
7dc64f62d3 WS::Client: added new status code E_HOST_UPDATE
E_HOST_UPDATE is used to signal that the underlying
host has been updated.

Signed-off-by: James Yonan <james@openvpn.net>
2022-06-29 08:39:22 -06:00
James Yonan
4ef1ac65b1 WS::ClientSet: added HTTPStateContainer debug logging at debug_level >= 3
Signed-off-by: James Yonan <james@openvpn.net>
2022-06-29 08:39:22 -06:00
James Yonan
b2df3ca663 Renamed VPN_CONNECTION_PROFILES -> VPN_BINDING_PROFILES for clarity
VPN Binding Profiles (previously committed as VPN Connection
Profiles) contain information on an active VPN client session
such as local VPN IPs, gateway, and DNS resolver addresses
that can be directly used by higher-layer HTTP/REST-API
clients to (a) ensure that sessions are routed over the VPN,
and (b) privately use the VPN-server-pushed DNS resolvers
without publishing them in /etc/resolv.conf.

Signed-off-by: James Yonan <james@openvpn.net>
2022-06-29 08:39:22 -06:00
James Yonan
4021a081cc WS::Server: fixed an issue where in some cases client override http_stop() was not called on stop()
Signed-off-by: James Yonan <james@openvpn.net>
2022-06-29 08:39:22 -06:00
James Yonan
77d7667eb2 WS::ClientSet::new_request_synchronous(): fixes related to io_context recycling
Signed-off-by: James Yonan <james@openvpn.net>
2022-06-29 08:39:22 -06:00
James Yonan
9f16394c55 WS::ViaVPN: added client_ip() method
Signed-off-by: James Yonan <james@openvpn.net>
2022-06-29 08:39:22 -06:00
James Yonan
28c9eb2baa WS::ViaVPN: add const attribute to client_update_host()
Signed-off-by: James Yonan <james@openvpn.net>
2022-06-29 08:39:22 -06:00
James Yonan
5931f48007 WS::ClientSet: interpret max_retries == 0 as infinite retries
Signed-off-by: James Yonan <james@openvpn.net>
2022-05-16 21:28:39 -06:00
James Yonan
9b5d87fd43 HTTP client/server: support binding to VPN connection profiles
A VPN connection profile is basically a JSON representation
of the server-pushed parameters of a VPN session such as
VPN IPs, Gateway IPs, and DNS servers.  It can be obtained
on the client via TunBuilderCapture::to_json()

This patch allows an HTTP client or server to bind to the
VPN connection profile, so that the VPN IP is used as the
local address, the Gateway IP is optionally used as the
destination address, and DNS lookups are performed using
the pushed DNS servers (without needing to overwrite
/etc/resolv.conf).

For example, suppose the VPN connection profile
is in /pg/uplink-connection-info

Then we can bind to the VPN IP addresses on the server side:

  http-listen @/pg/uplink-connection-info 8443 tcp4 ssl
  http-listen @/pg/uplink-connection-info 8443 tcp6 ssl

Or connect to a remote REST API using the VPN session
and VPN server-provided resolvers.

  <aws-client>
  host mybucket.s3.amazonaws.com
  port 443
  vpn-connection-info /pg/uplink-connection-info
  ...
  </aws-client>

Signed-off-by: James Yonan <james@openvpn.net>
2022-05-14 01:39:37 -06:00
James Yonan
b0e1c2ec6e WS::Creds: added password_eq() method
Signed-off-by: James Yonan <james@openvpn.net>
2022-05-13 19:09:09 -06:00
James Yonan
42e586417f WS::ClientSet: added commented-out OPENVPN_LOG line for showing HTTPStateContainer state
Signed-off-by: James Yonan <james@openvpn.net>
2022-05-13 19:09:09 -06:00
James Yonan
79b6bd15e0 WS::ClientSet: check io_context stopped() method before running or persisting
Signed-off-by: James Yonan <james@openvpn.net>
2022-05-13 19:09:09 -06:00
James Yonan
a092a2dbb1 WS::ClientSet: it seems more logical for SyncPersistState to be inside of HTTPStateContainer
HTTPStateContainer contains the current HTTP client session
state, and can be retained for multiple HTTP transactions
over a persistent HTTP session.

Since SyncPersistState can optionally contain the Asio
io_context for synchronous operations, it seems logical
to colocate this object with HTTPStateContainer.

Signed-off-by: James Yonan <james@openvpn.net>
2022-03-24 17:31:45 -06:00
James Yonan
3ac1f0d613 HTTP: attempt to fix a lockup bug in HTTPS cleartext read path
Previously, ssl_up_stack() in httpcommon.hpp would
loop indefinitely until ssl_sess->read_cleartext_ready()
returned false, or halt is set. read_cleartext_ready()
will return true as long as the SSL_pending() function in
OpenSSL returns non-zero.  But recent experience as well
as updates to the SSL_pending() man page suggest that
SSL_pending() may return non-zero even though no data is
actually readable from the object.  In this case,
the previous code would enter an infinite loop.

The fix is to break out of the ssl_up_stack() loop when
ssl_sess->read_cleartext() returns zero size, rather
than solely relying on the return value of SSL_pending().

Signed-off-by: James Yonan <james@openvpn.net>
2022-01-13 09:40:13 -06:00
James Yonan
67a7ec8631 WS::Client: added a comment about general timeout and websocket streaming
Signed-off-by: James Yonan <james@openvpn.net>
2022-01-13 09:40:13 -06:00
James Yonan
cbb2018b3c WS::Client: fixed weird indentation
Signed-off-by: James Yonan <james@openvpn.net>
2021-11-24 13:18:35 -07:00
Heiko Hund
4a0daf7827 fix signedness of variable
AltRoutingShimFactory::connect_timeout() returns an int, not an unsigned.
With that the if condition below makes sense again.

Signed-off-by: Heiko Hund <heiko@openvpn.net>
2021-05-19 03:30:25 +02:00
Heiko Hund
f3133090a6 remove unnecessary const from return type qualifier
Adding const here serves no purpose, since the return type is
a rvalue and cannot be modified anyways.

Signed-off-by: Heiko Hund <heiko@openvpn.net>
2021-05-18 06:13:31 +02:00
Heiko Hund
63d38ba278 add results_type to class AsyncResolvable
Makes code more readable and implicitly declares the
correct internet protocol.

Signed-off-by: Heiko Hund <heiko@openvpn.net>
2021-03-18 18:10:30 +01:00
Lev Stipakov
cf6d113337
httpcli.hpp: fix build error
openvpn/common/periodic_fail.hpp is not a part
of public repo, surround it with #ifdef guard.

Signed-off-by: Lev Stipakov <lev@openvpn.net>
2021-01-20 11:15:33 +02:00
James Yonan
016664582e WS::Client: #include change for pgmesh-test
Include openvpn/common/periodic_fail.hpp unconditionally,
since more than one test component now requires it.

Signed-off-by: James Yonan <james@openvpn.net>
2021-01-03 11:32:24 -07:00
James Yonan
fd11e37ca8
Asio patches: in basic_resolver_results, added data() and cdata() members for access to underlying storage vector
This seems like a more general solution for developing resolver results mutators
such as randomize and filter by IP version.

Signed-off-by: James Yonan <james@openvpn.net>
2020-08-19 18:52:55 +02:00
David Sommerseth
3fbe0a2701
Update copyrights
Signed-off-by: David Sommerseth <davids@openvpn.net>
2020-03-18 19:37:32 +01:00
James Yonan
c7972b0532 WS::Client: reworked SIMULATE_HTTPCLI_FAILURES to more closely hew to asio error throw points
Signed-off-by: James Yonan <james@openvpn.net>
2020-02-28 11:56:04 -07:00
James Yonan
84ef4533c6 WS::Client: implemented simulated network fault injection
Enable with SIMULATE_HTTPCLI_FAILURES

Signed-off-by: James Yonan <james@openvpn.net>
2020-02-28 11:56:04 -07:00
Lev Stipakov
10127e2bdd
Add GPL headers
Signed-off-by: Lev Stipakov <lev@openvpn.net>
2020-01-31 10:24:38 +02:00
James Yonan
9524b1496b
WS::Server, Acceptor::TCP: added bind/close logging when OPENVPN_DEBUG_ACCEPT is defined
Signed-off-by: James Yonan <james@openvpn.net>
2020-01-31 10:24:34 +02:00
James Yonan
78cd98a1c8
WS::Server: log accepts when OPENVPN_DEBUG_ACCEPT is defined
Signed-off-by: James Yonan <james@openvpn.net>
2020-01-31 10:24:33 +02:00
James Yonan
8bffbe6acf
Implement TCP shutdown at the HTTP layer
This patch tries to gracefully shutdown a socket before
closing it, in non-error, non-stop situations.

Signed-off-by: James Yonan <james@openvpn.net>
2020-01-31 10:24:33 +02:00
James Yonan
b91d7e39ba
Acceptor::TCP: don't set reuseport flag by default on listener socket
Previously, all listener sockets were configured with both
reuseaddr and reuseport.  reuseaddr is reasonable to use as
a default, but reuseport should only be used when different
threads are listening on the same local port/address for
load-balancing purposes.

This patch adds two new socket option flags DISABLE_REUSE_ADDR
and REUSE_PORT, to provide finer-grained control over
these options.

Signed-off-by: James Yonan <james@openvpn.net>
2020-01-31 10:24:33 +02:00
James Yonan
94581ff22e
Replace AsioTimer with AsioTimerSafe in cases where handler doesn't clearly check for late cancellation
As noted in the Asio documentation, an AsioTimer handler can be
called with a non-error status after timer cancellation.

Unfortunately, this can lead to race conditions, so I'm moving over
all AsioTimer users to AsioTimerSafe when I don't see the handler
clearly checking for late cancellation.

Signed-off-by: James Yonan <james@openvpn.net>
2020-01-31 10:24:32 +02:00
James Yonan
be171b5367
WS::Server::Listener: added walk() method
The walk() method calls a caller-defined function on all
of the active client instance objects bound to the listener.

Signed-off-by: James Yonan <james@openvpn.net>
2020-01-31 10:24:32 +02:00
Antonio Quartulli
1aedadbc6d
httpserv::client: add and invoke tcp_intercept() before consuming buffer
Child classes may want to operate on a received buffer, before it is
passed down the stack. This can be useful when the Proxy Protocol
parser wants to parse and wipe its header.

Make it a virtual method so that it can be overridden by child classes
where higher level logic are implemented.

Signed-off-by: Antonio Quartulli <antonio@openvpn.net>
2020-01-31 10:24:32 +02:00