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

66 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
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
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
Charlie Vigue
1bf5b91392 Make LoggerMixin specializations unique by tag
Adds an optional TAG type to the LoggerMixin so that each class or
subsystem may have a distinct specialization if desired.
2024-06-21 08:13:42 +00:00
Razvan Cojocaru
272d0ef07d Fix LOG_{DEBUG, INFO} conflicts with syslog.h
The syslog.h UNIX header already #defines LOG_{DEBUG, INFO} as
log-level constants, which means that we can't have code that
includes both openvpn/log/logger.hpp and syslog.h.

This patch renames all the LOG_<LEVEL>() macros to
OVPN_LOG_<LEVEL>(), to hopefully eliminate "macro already defined"
conflicts in the future.

Signed-off-by: Razvan Cojocaru <razvan.cojocaru@openvpn.com>
2024-05-30 08:45:08 +03:00
Arne Schwabe
e2c2f6e936 Refactor compression to allow setting log level at runtime
Signed-off-by: Arne Schwabe <arne@openvpn.net>
2024-04-17 14:48:50 +00:00
David Sommerseth
bae10062b3
Merging in changes from OpenVPN 3 Core version 3.8.4
Signed-off-by: David Sommerseth <davids@openvpn.net>
2024-02-19 22:46:53 +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
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
964b7cbd30
Use [[fallthrough]] where appropriate
Since we use C++17 now, the attribute is guaranteed
to be available.

Should silence some Coverity warnings.

Signed-off-by: Frank Lichtenheld <frank@lichtenheld.com>
2023-08-02 18:05:33 +02: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
Frank Lichtenheld
db7ea3d96a lzo_asym_impl: fix unaligned access
Helpfully the comment above the code actually provided
a solution...

Signed-off-by: Frank Lichtenheld <frank@lichtenheld.com>
2023-02-28 13:45:16 +01: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
8c94a8f774
copyright: Update to 2022
Signed-off-by: David Sommerseth <davids@openvpn.net>
2022-09-29 12:00:26 +02:00
Heiko Hund
5787dc8835 remove unnecessary addition
match_ptr is not used after this statement. It is then overridden by a new
value in both surrounding loops in case there's more iterations. Thus the
incremented value is not inspected in any case.

Signed-off-by: Heiko Hund <heiko@openvpn.net>
2021-05-18 06:13:31 +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
984c601090
Fix multiple instances of comparison of signed with unsigned 2020-01-15 23:08:30 +01:00
David Sommerseth
67b4641a99
CompressContext: Add is_any_stub() method
This method is used to identify if any of the stub compression types is
in use.

Signed-off-by: David Sommerseth <davids@openvpn.net>
2019-10-02 17:36:48 +02:00
Arne Schwabe
30ea53cb92 Replace custom memcpy implementation
The custom memcpy implementation is not faster than the
standard memcpy in my tests (standard one is assembler optimised on
almost all platforms).

Also the custom memcpy version crashes with a segfault on a current
Android clang/arm32 compiler. I suspect this due to the fact that it
ignores memory alignment.

Signed-off-by: Arne Schwabe <arne@openvpn.net>
2019-03-19 14:42:45 +01:00
David Sommerseth
16b10559f2 [OVPN3-140] Update company names in copyrights
OpenVPN Technologies, Inc. change their name to OpenVPN Inc. during the
autumn of 2017.

Signed-off-by: David Sommerseth <davids@openvpn.net>
2017-12-22 17:59:39 +08:00
David Sommerseth
6caca2c313 [OVPN3-140] Relicense back to AGPLv3
This is essentially a revert of commit 04b2a3c9b7 and commit
ef42e59e05.

Signed-off-by: David Sommerseth <davids@openvpn.net>
2017-12-22 17:59:39 +08:00
Antonio Quartulli
4f99310341 remove function accidentally duplicated by last merge
Signed-off-by: Antonio Quartulli <antonio@openvpn.net>
2017-12-22 17:59:39 +08:00
Antonio Quartulli
2fe56c3be0 Compress: convert from ctx type to config string
Add function to convert the current compress context
type to the string that was used to configure it.

Signed-off-by: Antonio Quartulli <antonio@openvpn.net>
2017-12-22 17:59:38 +08:00
James Yonan
27387181a8 compress: added method_to_string() method, i.e. the
inverse of parse_method().

Signed-off-by: James Yonan <james@openvpn.net>
2017-12-22 17:59:38 +08:00
James Yonan
7b47f998ad compress: since parse_method() performs a linear search
on method, reorder so that more frequently used methods
appear at the top of the list.

Signed-off-by: James Yonan <james@openvpn.net>
2017-12-22 17:59:38 +08:00
James Yonan
c373bf87f2 CompressContext: use C++11 member initialization and remove explicit attribute on constructor
Signed-off-by: James Yonan <james@openvpn.net>
2017-09-27 16:16:17 +08:00
James Yonan
b2cd82a5bf copyright: updated to 2017.
Signed-off-by: James Yonan <james@openvpn.net>
2017-03-18 13:11:09 -06:00
David Sommerseth
ede022e04e compress: Update lz4 implementation to new API
As of LZ4 v1.7, the LZ4_compress() function is deprecated and
is to be replaced with LZ4_compress_default().

This new function adds an extra argument which declares the size
of the destination buffer.  In addition, if the result is 0, the
result buffer is not to be trusted as the compression failed.

Signed-off-by: David Sommerseth <davids@openvpn.net>
2017-03-18 12:24:54 -06:00
Samuli Seppänen
04b2a3c9b7 Switch from AGPLv3 to GPLv3
Signed-off-by: Samuli Seppänen <samuli@openvpn.net>
2017-03-16 14:43:55 +02:00
James Yonan
971abda88f copyright : updated to 2016 2016-09-03 23:29:23 -06:00
James Yonan
134ba710f2 ovpn3 core globals cleanup:
1. move all const globals into anonymous namespace
2. make sure that all non-class functions are inline
3. refactor class static data members
2015-11-25 11:34:41 -07:00
James Yonan
b75c780cab Renamed boost::intrusive_ptr<T> usage to RCPtr<T>. 2015-05-17 21:26:53 -06:00
James Yonan
35ac9f6229 Renamed types.hpp to size.hpp since it now only defines
size_t and ssize_t.
2015-05-17 13:27:34 -06:00
James Yonan
fe6fcefa61 C++11 : rename NULL to nullptr 2015-05-17 02:53:37 -06:00
James Yonan
0fde33173a C++11 update: mass replace of boost::uint/int to std::uint/int. 2015-04-23 17:55:07 -06:00
James Yonan
c2c7292a70 Updated copyright to 2015. 2015-01-06 12:56:21 -07:00
James Yonan
8482f7f76d Misc changes to dynamically support OpenVPN protocols V1 and V2:
1. force_aes_cbc_ciphersuites flag will disable V2.

2. Added class CryptoDCSettings to Manage cipher/digest settings,
   DC factory, and DC context.  A CryptoDCSettings instance is
   now declared as a member of ProtoContext::Config and is used
   to define the cipher/digest pair of the config.

3. ProtoContext::Config::load now parses the "tun-mtu" directive.

Server-side changes:

1. Parse "keepalive" directive, using the same logic
   as OpenVPN 2.x.

2. Added ProtoContext::init_data_channel() method for initializing
   the data channel after IV_x peer info received from client.
2014-12-29 22:20:50 -07:00
James Yonan
7e1d159cee Major protocol upgrades:
* peer_id/DATA_V2/op32
  client -> server:
    IV_PROTO=2
  server -> client :
    push "peer-id 1234"
    push "peer-id -1"

* AEAD/GCM support
  client -> server:
    IV_NCP=2
  server -> client:
    push "cipher AES-256-GCM"

* Compression V2
  client -> server:
    IV_LZ4v2=1
    IV_COMP_STUBv2=1
  server -> client:
    push "compress stub-v2"
    push "compress lz4-v2"

* TCP non-linear packet ID
  client -> server:
    IV_TCPNL=1
  server -> client:
    [always enabled]
2014-12-21 10:32:37 -07:00
James Yonan
2c6d972ad6 Added AGPL copyright/licensing language. 2014-07-20 21:22:06 -06:00
James Yonan
08e6937cc5 Core: workaround for LZO integer overflow bug. Don't accept
decompressed payloads larger than 64KB.
2014-07-09 17:44:47 -06:00
James Yonan
2cbe310f35 OpenVPN 1.0.4 build 114 (iOS)
Dusted off LZ4 implementation and enabled in iOS
and cli.cpp builds.

Tested LZ4 as well with OpenVPN 3 acting as the client,
with a hacked AS and OpenVPN 2.3 (JY) acting as the server
(see lz4hack patches).
2013-12-27 22:21:22 -07:00
James Yonan
1481327d72 OpenVPN 1.0.2 build 98 (iOS)
Ported iOS client and OpenVPN 3 core to ARM-64.
Now building a "fat binary" with Xcode 5.0.1 that
targets arm7, arm7s, and arm64.

Outstanding issues:

* IPv6 doesn't route through tunnel on iOS7
* Client doesn't install on iOS 5.1.1.
2013-11-11 12:33:35 -07:00
James Yonan
4d9a751af2 Added head comments to all source files.
Minor reorganization of unicode code.
2012-11-23 06:18:43 +00:00
James Yonan
d647a07b24 Minor changes. 2012-09-26 23:41:16 +00:00
James Yonan
6366c848d2 LZO-Asym: Fixed possible signed/unsigned issue on CHECK_x macros. 2012-09-26 23:39:18 +00:00
James Yonan
2bd85245d6 LZO-Asym optimizations for ARM. 2012-09-26 07:20:42 +00:00
James Yonan
e19137013c Reimplemented lzoasym_impl.hpp using improved primitives for incremental
and regular memory copy operations.
2012-09-26 01:37:11 +00:00
James Yonan
e64f429095 When reporting client compression capabilities to server, include
IV_COMP_STUB whenever IV_LZO_STUB is reported.
2012-09-17 21:41:41 +00:00
James Yonan
1ba895a6a0 Added NO_LZO preprocessor flag to disable inclusion of all LZO
functionality (including LZO-Asym) except for LZO stub:

NO_LZO   -- disable all LZO functionality except for stub
HAVE_LZO -- use LZO library for compression/decompression
default  -- use LZO-Asym decompressor (no compression)

Added init_process call to start of test/ovpncli/cli.cpp
2012-09-11 08:45:27 +00:00