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

199 Commits

Author SHA1 Message Date
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
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
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
Lev Stipakov
48863ace12
digestapi.hpp: pass libctx to digest api
Digest API calculates MD4/MD5 digests etc which
are deprecated. In order to use those one needs to
load OpenSSL legacy provider and EVP_MD_fetch() to
fetch digest implementation from all loaded providers.

EVP_MD_fetch() takes library context as an argument,
so we need to pass it there through the digest api stack.

Signed-off-by: Lev Stipakov <lev@openvpn.net>
2023-06-07 17:09:49 +02:00
Lev Stipakov
de01e278cc
Display configured family address for UDP and DCO
Instead if displaying resolved family address (v4/v6),
display the one which is configured - either in ovpn profile
or config override options.

This is already the case for TCP.

Signed-off-by: Lev Stipakov <lev@openvpn.net>
2023-05-10 18:22:59 +02:00
Lev Stipakov
f544e04df7
Bring back "allow local DNS resolvers" functionality
This was introduced in commit

  613aa6bf ("Win: support for local DNS resolvers")

but got removed by mistake in commit

  fd065596 ("Merge release of OpenVPN Core library 3.6.4 to master")

Besides, this never worked for DCO, so fix that too.

Fixes OVPN3-964.

Signed-off-by: Lev Stipakov <lev@openvpn.net>
2023-04-24 13:07:46 +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
Lev Stipakov
ae99307219
tun: add persis-tun support for dco-win
Add DcoTunPersist object to DCO::TunConfig.

DcoTunPersist stores:

 - device handle
 - tun settings
 - adapter index/name
 - pointer to TunSetup object, which itself
 stores commands to undo tun settings

When intializing client options, instantiate DcoTunPersist
object within the scope of ClientConfig, which serves as
transport and tun factory for dco. Indicate that "sock" object
(device handle) should be preserved - not replaced when persisting
tun settings.

When establishing dco-win connection in OvpnDcoWinClient,
either use tun_persist created above (if persistance is enabled)
or instantiate it in-place (no persistance).

If nothing is stored in tun_persist (means this is first
connection or reconnect without persistance), acquire device
handle from tun_setup, wrap it into ASIO's basic_stream_handle
and store it in OvpnDcoWinClient - no need to persist it yet.

When starting tun, check if persisted tun session matches
to-be-created session. If no - clear previous tun settings,
set up tun and persist tun state. If device handle is already
stored in tun_persist, it won't be replaced.

On tun stop, send DEL_PEER command, which deletes peer
from the driver but keeps adapter in connected state. Then
close locally stored ASIO handle and reset tun_persist.
In case of "short term persistance" this will undo tun settings
and close device handle. For long term persistence, tun_persist
is also stored in ClientConfig and handle won't be closed yet.

In case of disconnect, ClientConfig::finalize(disconnect=true)
is called, which resets tun_persist, which in turn
undoes tun settings and closes device handle.

Signed-off-by: Lev Stipakov <lev@openvpn.net>
2022-10-13 15:16:25 +02:00
David Sommerseth
8c94a8f774
copyright: Update to 2022
Signed-off-by: David Sommerseth <davids@openvpn.net>
2022-09-29 12:00:26 +02:00
Lev Stipakov
ac15879588 support for default mssfix
Add support for default mssfix, which is calculated
based on upper bound value 1492 minus payload and
encapculation overhead.

Payload overhead includes:

 - compression byte (except for V2, which doesn't add overhead)
 - pktid (in CBC)
 - IPv4 and TCP headers

Encapculation overhead:

 - crypto overhead (for AEAD 16 bytes auth tag, 4 bytes pktid, 4 bytes opcode/peer-id = 24)
 - 2 bytes packet size for TCP transport

Also for CBC we must take padding [1..blocksize] into account.

Signed-off-by: Lev Stipakov <lev@openvpn.net>
2022-05-04 18:15:07 +03: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
Heiko Hund
98af6cc703 mark a couple of methods override instead of virtual
This is done to silence the inconsistent-missing-override warning, which
is new, since we introduced override into the files. I guess it is best
practise anyway, since C++11. So, no hard feelings.

Signed-off-by: Heiko Hund <heiko@openvpn.net>
2021-09-28 15:29:03 +02:00
Heiko Hund
0d32d45ab7 process pushed remote-cache-timeout option
Take option value if pushed for the next round of remote address
caching.

Since the push replies are processed in Session, we need to extend the
transport slightly to process pushed options. There was no need so far,
since transport options are used before the session starts. The remote
cache timeout is currently the only exception to this rule.

Signed-off-by: Heiko Hund <heiko@openvpn.net>
2021-09-28 15:29:03 +02:00
Lev Stipakov
fd0655969d
Merge release of OpenVPN Core library 3.6.4 to master 2021-09-22 13:56:37 +02:00
James Yonan
5231fa35ad
PacketStream: change message size validation logic to support growable buffers for DNS-over-TCP
In PacketStream, don't validate upper bound on message size
if BufferAllocated::GROW is set, allowing it to range up to
64kb.

Signed-off-by: James Yonan <james@openvpn.net>
2021-08-03 10:42:35 +02:00
James Yonan
abd1c5b208
PacketStream: minor cleanup and added a unit test
Removed declared_size_defined in favor of just setting
declared_size to a special value (SIZE_UNDEF) when it's
undefined.

Signed-off-by: James Yonan <james@openvpn.net>
2021-08-03 10:42:35 +02:00
Heiko Hund
dee1b625c3
fix occ proto strings
There are two things addressed here.

 1) regression introduced by commit f1bdbe5088:
    Since TCP is not an alias for TCPv4 anymore the occ string
    contained TCP_CLIENT as proto, which is not understood by peers.
    Since only the "v4" version of the proto strings are understood
    the code was simplified.
 2) wrong occ proto string for TCP servers:
    Servers were also sending out the proto with client suffix. Fixed
    by passing in a boolean and returning the server version if true.

Also renamed the method to reflect better what it is used for.

Signed-off-by: Heiko Hund <heiko@openvpn.net>
2021-06-10 22:40:18 +02:00
James Yonan
95b277ca58 TCPTransport::LinkCommon: updated initialization of halt to use C++11 member initializer
Signed-off-by: James Yonan <james@openvpn.net>
2021-05-31 13:34:44 -06:00
James Yonan
38ed30d4ad TCPTransport::LinkCommon: updated comment to reflect the fact that non-raw mode can be used for DNS as well as OpenVPN protocol over TCP
Signed-off-by: James Yonan <james@openvpn.net>
2021-05-31 13:34:44 -06:00
Heiko Hund
f1bdbe5088
fix handling of --proto option
Make it possible to enforce the protocol family by appending 4/6 to
to the protocol, e.g. tcp6 or udp4. While it is already possible to
have protocol options like these in the configuration, they are not
enforced so far. Thus you could still be connected to a v6 address
even though the config requested v4 only.

Since v2.3 the openvpn 2.x series behaves like this. So, this is also
to catch up with the behavior there.

Signed-off-by: Heiko Hund <heiko@openvpn.net>
2021-05-05 19:46:57 +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
Heiko Hund
32a32cf04c
add support for dco-win to agent service
Signed-off-by: Heiko Hund <heiko@openvpn.net>
2021-04-14 22:44:50 +02:00
Heiko Hund
7f103450f9
respect --http-proxy auth-method
Do not try other auth methods, if a specific method was given
as a third parameter to the --http-proxy config option.

Signed-off-by: Heiko Hund <heiko@openvpn.net>
2021-04-14 22:40:08 +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
Antonio Quartulli
2c2fdaa7c5
transport-client: allow retrieving server port and socket fd
To properly implement support for ovpn-dco, we need the TCP/UDP
transport clients to allow the parent to retrieve the server port and
the native handle (socket fd).

Both are used when informing ovpn-dco about the new peer.

Signed-off-by: Antonio Quartulli <antonio@openvpn.net>
2021-02-23 01:37:20 +01:00
Lev Stipakov
e419e07c7f dcocli.cpp: add missing socket_protect call
As other transport clients, call socket_protect()
before establishing connection.

This gives ability to create bypass route.

Signed-off-by: Lev Stipakov <lev@openvpn.net>
2020-08-26 10:53:27 +00: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
David Sommerseth
3fbe0a2701
Update copyrights
Signed-off-by: David Sommerseth <davids@openvpn.net>
2020-03-18 19:37:32 +01:00
Arne Schwabe
d1fd4ef1f1 Minor code style clean up
- use explicit for non copy single argument constructor
- add override where applicable

Signed-off-by: Arne Schwabe <arne@openvpn.net>
Signed-off-by: David Sommerseth <davids@openvpn.net>
2019-11-27 17:11:50 +01:00
Arne Schwabe
1e2d7b1c81 Implement opening /dev/net/ovpn via tun builder interface
Signed-off-by: Arne Schwabe <arne@openvpn.net>
2019-11-27 17:11:50 +01:00
David Sommerseth
6201b316f5
Merge branch 'hotfix/3.4' into released 2019-11-14 18:39:55 +01:00
David Sommerseth
300e0218dc
Merge hotfix/3.3 into hotfix/3.4 2019-11-13 21:12:41 +01:00
Antonio Quartulli
7f3756336d
httpcli.cpp: perform lock before running async DNS resolution
d8d14e1991 implemented a new logic which
allows the DNS resolution to happen in a detachable thread. Since then,
we must execute async_resolve_lock() before performing the resolution so
that the main event queue is kept alive, while the core is busy
resolving the hostname.

Failing to do so will result in the main event queue terminating due to
"no events in the queue" and thus closing the core process.

Add lock (and related cancel) around resolution operation to guarantee
the core process stays alive during resolution.

Signed-off-by: Antonio Quartulli <antonio@openvpn.net>
2019-11-08 17:19:48 +01:00
Antonio Quartulli
7f0abcb3c3
httpcli.cpp: remove unused resolver member
Signed-off-by: Antonio Quartulli <antonio@openvpn.net>
2019-11-08 17:19:47 +01:00
Lev Stipakov
0d7143c4bf transport: enable socket_protect call for all platforms
This enables socket_protect call for all transports / platforms
with default implemenation being no-op.

This is needed for better round-robin DNS
fix for Connect clients (OVPN3-427).

Signed-off-by: Lev Stipakov <lev@openvpn.net>
2019-10-10 15:23:17 +03:00
James Yonan
1b3402aec3 tcplinkcommon.hpp: added missing include
Signed-off-by: James Yonan <james@openvpn.net>
2019-09-06 22:24:57 -06:00
Antonio Quartulli
1d6bae4b5b
tcplinkcommon: bubble up real exception error
In case of error along the TCP RX path it is better to grab the error
coming with the exception and report it back up.

For this reason, catch ExceptionCode objects rather than std::exception
as the former carries the error code together with the text message.

Signed-off-by: Antonio Quartulli <antonio@openvpn.net>
2019-06-25 11:47:35 +02:00
Antonio Quartulli
c18c8bd156
tcpcli: ensure SSL Factory survives as long as TLS link
The SSL factory holds the config used by the link implementation during
various SSL operations.

For this reason we have to make the sure the Factory is not destroyed
(and thus the config) while the TLS link is alive.

Signed-off-by: Antonio Quartulli <antonio@openvpn.net>
2019-06-25 11:47:34 +02:00
Antonio Quartulli
4192193087
tls: parse and load TLS specific CA
Signed-off-by: Antonio Quartulli <antonio@openvpn.net>
2019-06-25 11:47:31 +02:00
James Yonan
bbae814864
OpenSSL: added SNI implementation
On the server side, we add the abstract base class
SNIHandlerBase to provide a hook (sni_hello) where
servers can inspect the SNI name given in the client
hello message and possibly return a different SSLFactoryAPI.

In other changes, we rename the ENABLE_SNI flag to
ENABLE_CLIENT_SNI to be clear that this flag only affects
the client-side SNI implementation.

We also add the NO_VERIFY_HOSTNAME flag on the client side
to allow the SNI name to be transmitted to the server
without requiring a match between the SNI name and the
common name or subject alternative name in the server
certificate.

Signed-off-by: James Yonan <james@openvpn.net>
2019-06-19 18:21:00 +02:00
Lev Stipakov
5771dfc0ee transport: remove ip_hole_punch API
That API was introduced in commit 5c00943
to implement persistence for macOS. That functionality
was refactored in 0609c76, but framework was left intact.

Since socket_protect() is called almost at the
same time as ip_hole_punch() and also receives
remote address, there is no need in this unused
API anymore.

Signed-off-by: Lev Stipakov <lev@openvpn.net>
2019-05-09 16:40:24 +03:00
Antonio Quartulli
a2713ce1f6
PureTLS: enable SNI by default when configuring client
Signed-off-by: Antonio Quartulli <antonio@openvpn.net>
2019-04-30 09:03:31 +02:00
Arne Schwabe
84fcecd5e7 Fix missing override annotation in udp/tcp/httpcli
Clang warns about these on default warning level.
2019-03-15 15:08:20 +01:00
Antonio Quartulli
c3026c65a6
Merge remote-tracking branch 'origin/qa' 2019-02-07 10:55:27 +10:00
Antonio Quartulli
f33fe76658
[UCONNECT-1027] perform async DNS resolution in a detached thread
When ASIO performs an async DNS resolution, it relies on the
getaddrinfo() syscall in order to obtain a result.

This syscall is non-interruptible by design, which means that, in case
of sudden stop command received by the user, the core will not be able
to terminate all its threads until the getaddrinfo() has returned
(either by timeout or with a result).

If the the external core user is synchronously waiting for it to
terminate (i.e. like a UI), this behaviour will lead to the entire
client hanging.

To avoid this issue, this commit converts each asynchronous DNS
resolution to a synchrnous one performed in a detached thread.

This way, if the core wants to stop, it can do so without waiting for
the DNS thread to join. Otherwise, this change should not lead to any
functional difference.

Signed-off-by: Yuriy Barnovych <yuriy@openvpn.net>
Signed-off-by: Antonio Quartulli <antonio@openvpn.net>
2019-02-07 09:07:00 +10:00