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

150 Commits

Author SHA1 Message Date
Charlie Vigue
ef8da98bd4 Buffer: Prepare to decouple allocated buffer / RC
Rename BufferAllocated --> BufferAllocatedRc

Buffer: split RC from BufferAllocated
Also make changes as needed where BufferAllocated is used

Buffer: Split allocation flags into own struct
Leaving flags in template causes each alias to have identical flags
by different names, which requires each type to pointlessly use
the nested name.

Make RC: Clean up headers buffer.hpp, make_rc.hpp

Signed-off-by: Charlie Vigue <charlie.vigue@openvpn.com>
2024-09-11 13:23:28 +00:00
Arne Schwabe
ca91f3e91c Implement data v3 features for AEAD tag at the end and 64 bit packet counter
Split the implementation of the packet counter for normal packet ID
that includes the "weird" long format for long 64 bit packet ids used
in tls-auth and tls-crypt and a simplified implementation for AEAD that
only does 32 bit and 64 bit flat counters.

Signed-off-by: Arne Schwabe <arne@openvpn.net>
2024-08-19 12:18:49 +00:00
Razvan Cojocaru
880ebb081a server: Add new to_string_debug() pure virtual member to SendBase
This is part of a series of patches instrumenting crash checks.
Classes that implement SendBase can optionally collect debug
information for various scenarios, and create a string here that
presents them in human-readable form when requested.

Signed-off-by: Razvan Cojocaru <razvan.cojocaru@openvpn.com>
2024-08-19 10:57:32 +00:00
James Yonan
2b0960452d ServerProto: don't generate new management or tun instances after stop() has been called
This change is intended to safeguard against potential
post-stop() management activity that could result in
management agent getting into a bad state.

Signed-off-by: James Yonan <james@openvpn.net>
2024-08-17 12:53:23 -06:00
Heiko Hund
8c8e96e138 streamline overriding virtual function syntax
In the code base three different syntaxes for overriding virtual member
functions could be found:

  1) virtual ... override
  2) virtual ...
  3) ... override

This converts all of them to the third syntax, as recommended by the ISO
C++ core guidelines in C.128

Signed-off-by: Heiko Hund <heiko@openvpn.net>
2024-08-13 02:01:24 +02:00
James Yonan
6132010ea1 ManClientInstance::SendBase: added is_stopped() virtual method
is_stopped() should return true when the instance
is stopped or halted.

Signed-off-by: James Yonan <james@openvpn.net>
2024-08-09 10:10:05 +00:00
Leonard Ossa
3646265d15 Refactor nested namespace to C++17 style
Signed-off-by: Leonard Ossa <leonard.ossa@openvpn.com>
2024-07-03 10:20:11 +00:00
Arne Schwabe
0f32847f2c Reject invalid control channel messages
Instead of silently ignoring errors in control channel message and removing
invalid characters, we should be more strict and reject these message.

A similar change has been also submitted to OpenVPN 2.x
2024-05-30 15:27:29 +00:00
Arne Schwabe
e14c3f0441 Refactor ClientProto::Session to use ProtoContext as field insatead of Base
Currently the protocontext is used as kind of composition but not really
and makes following the code harder, since this inheritance not only serves
for composition but also as callbacks through virtual method inheritance.

Making ProtoContext a normal field and definining a callback interface makes
the class relationship easier to understand.

Signed-off-by: Arne Schwabe <arne@openvpn.net>
2024-04-11 09:59:05 +00: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
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
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
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
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
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
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
James Yonan
64a535c65d ManClientInstance: refactor Send into two classes, Send and SendBase
This refactoring moves all generic methods into SendBase
that are independent of VPN protocol, while OpenVPN
protocol-specific methods will remain in Send.

Signed-off-by: James Yonan <james@openvpn.net>
2023-09-17 10:08:36 -06: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
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
Mark Deric
f2df99ccab Fix unit test with AuthStatus::Type enum fwd decl
Signed-off-by: Mark Deric <jmark@openvpn.net>
2022-07-21 11:08:42 -07: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
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
ea5c978be4 VPNServerNetblock::Netblock: added route() method
Signed-off-by: James Yonan <james@openvpn.net>
2022-05-13 19:09:09 -06:00
James Yonan
0e2ecc5641 Listen::List: added new load mode AllowVPNClientConnectionProfile
AllowVPNClientConnectionProfile tells us to support
special address case for WS::ViaVPN, where address
begins with '@' followed by a client connection
profile filename.

Signed-off-by: James Yonan <james@openvpn.net>
2022-05-13 19:09:09 -06:00
James Yonan
5392a9e197 Listen::List: use opt.get_index_ptr() optimization to avoid linear search through option list
This removes the feature of allowing directive to be a
prefix, but I didn't find any users of this method that
require it.

Signed-off-by: James Yonan <james@openvpn.net>
2022-05-13 19:09:09 -06:00
James Yonan
7baf7b5978 ManClientInstance, ServerProto::Session, TransportClientInstance::Recv: added ipma_notify() virtual method
Signed-off-by: James Yonan <james@openvpn.net>
2022-02-07 13:56:13 -07:00
James Yonan
994ae2eed8 VPNServerNetblock: allow null configuration
Signed-off-by: James Yonan <james@openvpn.net>
2021-11-24 13:18:35 -07:00
James Yonan
a133c248fa ServerProto constructor: for performance, use move constructor for man_factory and tun_factory
Signed-off-by: James Yonan <james@openvpn.net>
2021-11-24 13:18:35 -07:00
James Yonan
677b6edf1f
ServerProto: prefix all logging with client name
Signed-off-by: James Yonan <james@openvpn.net>
2021-08-03 10:42:35 +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
69ed0a6f10
make Protocol::mod_addr_version() take a Version
Change method signature from

    void Protocol::mod_addr_version(const IP::Addr&)
to
    void Protocol::mod_addr_version(const IP::Addr::Version)

This is done in preparation for allowing to override the protocol
version of a RemoteList::Item, where mod_addr_version() will be used.

Signed-off-by: Heiko Hund <heiko@openvpn.net>
2021-05-05 19:46:56 +02:00
James Yonan
1fe87f0842
Allow management layer to override keepalive parameters
Signed-off-by: James Yonan <james@openvpn.net>
2020-09-23 20:00:41 +02:00
James Yonan
b06e30a3a5
PeerAddr: make copyable by inheriting from RCCopyable<thread_unsafe_refcount>
Unit tests need PeerAddr to be copyable

Signed-off-by: James Yonan <james@openvpn.net>
2020-08-19 18:53:04 +02:00
James Yonan
2ba720fdfb
ManClientInstance::Send: added doma_acl() method
Signed-off-by: James Yonan <james@openvpn.net>
2020-08-19 18:52:52 +02:00
James Yonan
97a4b8f9f2
HaltRestart: added to_string() method
Signed-off-by: James Yonan <james@openvpn.net>
2020-08-19 18:52:49 +02:00
James Yonan
9978ea2e65
PeerStats: use C++11 member initializers
Signed-off-by: James Yonan <james@openvpn.net>
2020-08-19 18:52:48 +02:00
Arne Schwabe
35d01b8a71 Fix indentation and unused variables related warnings from Clang 10
Signed-off-by: Arne Schwabe <arne@openvpn.net>
2020-04-29 11:55:38 +02:00
Arne Schwabe
f8fe13e07c Add missing overrides
Signed-off-by: Arne Schwabe <arne@openvpn.net>
2020-04-29 11:55:38 +02:00
James Yonan
edc62cd3b4 PeerStats: added to_string() method
Signed-off-by: James Yonan <james@openvpn.net>
2020-04-13 16:29:45 -06:00
David Sommerseth
3fbe0a2701
Update copyrights
Signed-off-by: David Sommerseth <davids@openvpn.net>
2020-03-18 19:37:32 +01:00
Arne Schwabe
984c601090
Fix multiple instances of comparison of signed with unsigned 2020-01-15 23:08:30 +01:00
James Yonan
23c14a3e32 AddrPort, PeerAddr: added to_json() methods
Signed-off-by: James Yonan <james@openvpn.net>
2019-12-26 03:44:14 -07:00
James Yonan
725ee04593 VPNServerNetblock::Netblock::to_string(): show prefix_len
Signed-off-by: James Yonan <james@openvpn.net>
2019-09-09 21:07:13 -06:00
James Yonan
409d1c52b8 ManClientInstance::Send::describe_user(): added bool show_userprop parameter
Signed-off-by: James Yonan <james@openvpn.net>
2019-09-09 21:05:11 -06:00
James Yonan
c00b6f6302
Listen::List: refactored and extended expand_ports()
Renamed expand_ports() to expand_ports_by_n_threads() and
added expand_ports_by_unit().  Both methods extend a set
of Listen::Item entries to span a port range.

Signed-off-by: James Yonan <james@openvpn.net>
2019-05-16 14:50:06 +02:00
James Yonan
ae22f155fd
server: determine when server-side session ID should be preserved on soon-to-be-closed connections
Provides a callback should_preserve_session_id() for the management
layer to query.

Signed-off-by: James Yonan <james@openvpn.net>
2019-05-15 18:56:45 +02:00
James Yonan
68170941fb manage: pass ProtoContext::Config::Ptr by value
Signed-off-by: James Yonan <james@openvpn.net>
2018-05-21 11:34:02 +03:00