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

100 Commits

Author SHA1 Message Date
Heiko Hund
f5db521aa7 WinSvc: define virtual d'tor
The Windows Service class did not specify its destructor as virtual, but
has other virtual function. Not specifying the d'tor virtual is an
anti-pattern in this case.

Signed-off-by: Heiko Hund <heiko@openvpn.net>
2024-08-13 02:01:33 +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
Heiko Hund
9bc6986873 add Windows network utilities and abstraction layer
Create a struct NetApi, which contains various network related functions
that will be used. This is done so that these operations can be injected
as a dependency and thus replaced with mock operation for the purpose of
testing.

There are also functions which operate solely on the Registry, those are
left out of the NetApi since they can already be abstracted by struct Reg.

Signed-off-by: Heiko Hund <heiko@openvpn.net>
2024-05-13 14:07:53 +02:00
Heiko Hund
bc24b7c80d add Windows Registry operations abstraction layer
Create a struct Reg, which contains various setter and getter functions
for different registry types and other operations that will be used.
This is done so that these operations can be injected as a dependency
and thus replaced with mock operation for the purpose of testing.
Besides that it makes code more brief and less error prone, since
there's now one implementation for converting C <-> C++ for each operation.

Move existing class RegKey and class RegKeyEnumerator into struct Reg as
well, so they are now known as Reg::Key and Reg::KeyEnumerator.

Signed-off-by: Heiko Hund <heiko@openvpn.net>
2024-05-13 14:07:53 +02:00
Heiko Hund
5e61f9ccbf initialize the RegKey handle correctly
Instead of using nullptr for uninitialized RegKey, use the value defined
in WIN32 API for that. We need to check for it anyways, so unifying this
makes the checks more straight forward.

Signed-off-by: Heiko Hund <heiko@openvpn.net>
2024-05-13 14:07:53 +02:00
Lev Stipakov
e34094e30d Refactor reauthentication logic
The reauthentication logic differs from openvpn2
and the code is a bit hard to follow. Simplify
the code and make it behave like in openvpn2.

 - password is cached by default

 - password is purged when auth-nocache is presented in a local config or pushed

 - when AUTH_FAILED is received and we have no session-id, throw a fatal error

 - when AUTH_FAILED is received and user interaction is required for
   authentication (MFA), throw a fatal error

 - when AUTH_FAILED is received, user interaction is not required
   for authentication and either we have a cached password OR password is not
   needed, we reconnect.

Password is "needed" when non-empty password is provided.

User interaction is required for static/dynamic challenge and SAML.

Signed-off-by: Lev Stipakov <lev@openvpn.net>
2024-05-08 16:39:24 +00:00
Frank Lichtenheld
2e10d21fa2
WriteFile takes DWORD, not size_t
Signed-off-by: Frank Lichtenheld <frank@lichtenheld.com>
2023-09-28 11:33:46 +02:00
David Sommerseth
0bcdeff84a
Merging changes from releaseprep/3.8 2023-05-10 19:57:23 +02:00
Frank Lichtenheld
b8ae379dd5 Make all C++ source code files have LF (Unix) line endings
For consistency. Some of the Windows-specific files, but not
all of them, had CRLF file endings.

Signed-off-by: Frank Lichtenheld <frank@lichtenheld.com>
2023-04-24 17:16:58 +02:00
Frank Lichtenheld
cb589b70f0 Remove support for pre-Vista Windows versions
We do not care about them anymore. So remove all
the support which is untested anyway.

Signed-off-by: Frank Lichtenheld <frank@lichtenheld.com>
2023-04-20 17:44:14 +02:00
Lev Stipakov
09be60d38d cli.cpp: implement get_password() on Windows
Password is not echoed and submitted when Enter is pressed.
This requires not removing ENABLE_PROCESSED_INPUT and ENABLE_LINE_INPUT
flags.

Signed-off-by: Lev Stipakov <lev@openvpn.net>
2023-04-19 18:47:48 +03:00
Lev Stipakov
7eba902d1c reg.hpp: support for INVALID_HANDLE_VALUE
We store an output of SetupDiOpenDevRegKey() in Win::RegKey. However,
this API returns INVALID_HANDLE_VALUE on error. In this case we should
not attempt to call RegCloseKey() on this handle, which we do in destructor
of Win::RegKey if handle is defined.

Signed-off-by: Lev Stipakov <lev@openvpn.net>
2023-04-19 18:47:39 +03: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
Lev Stipakov
9c6f67d271
win/call.hpp: fix include and linkage error
Add missing include.

Remove "console_cp" global variable which prevented from including
call.hpp twice.

Signed-off-by: Lev Stipakov <lev@openvpn.net>
2020-09-09 12:35:36 +03:00
David Sommerseth
3fbe0a2701
Update copyrights
Signed-off-by: David Sommerseth <davids@openvpn.net>
2020-03-18 19:37:32 +01:00
Lev Stipakov
7cf2e210d1
mingw: fix various warnings
- remove unused variable
 - replace deprecated JsonReader with CharReader
 - fix initialization order
 - fix signed-unsigned comparison
 - fix string constant to char* conversion
 - fix unknown (to mingw) format character
 - fix passing NULL to non-pointer agrument
 - remove unneeded #pragma once

Signed-off-by: Lev Stipakov <lev@openvpn.net>
2020-03-11 19:44:40 +01:00
Lev Stipakov
b17889fcd6
mingw: add missing include
FOLDERID_System used in this file is defined in "knownfloders.h"

Signed-off-by: Lev Stipakov <lev@openvpn.net>
2020-02-12 21:48:43 +02:00
Lev Stipakov
0a2663cc2b
scoped_handle.hpp: remove SEH code
This code is MSVC specific (other compilers
don't support SEH) and is only useful during
debugging.

It is better to remove it and mute exception
in debugger, than add ifdefs for other compilers.

Signed-off-by: Lev Stipakov <lev@openvpn.net>
2020-02-12 21:48:43 +02:00
Lev Stipakov
e07a2c4e62
mingw: use lowercase in includes
Linux filesystem is case-sensitive and all
mingw includes are in lower case.  Also use
Linux directory separator, since it works on both
Linux and Windows.

Signed-off-by: Lev Stipakov <lev@openvpn.net>
2020-02-12 16:12:19 +02:00
Lev Stipakov
67fb123b88
ovpnagent: start openvpn process
This is needed to make openvpn-gui client work with openpvn3.

openvpn-gui passes all information, required to start vpn session,
to agent via named pipe. Agent impersonates another end of pipe,
which is gui process, running under user privileges, and starts
openvpn process.

openvpn-gui generates a random password, which is written by agent
into openvpn process's stdin. That password is used by openvpn-gui to
connect to openvpn's management interface.

openvpn-gui creates an event with unique name, which it is passed
to openvpn via command line. When user disconnects VPN session, gui
sets event into signalled state. openvpn waits on event and, when it is signalled, quits.

Signed-off-by: Lev Stipakov <lev@openvpn.net>
2020-02-05 19:41:54 +01: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
5ce471e651
copyright: updated to 2017
Signed-off-by: James Yonan <james@openvpn.net>
2020-01-31 10:24:38 +02:00
James Yonan
5ec273f76c
license : this branch (common) is proprietary, so remove all GPL headers.
Signed-off-by: James Yonan <james@openvpn.net>
2020-01-31 10:24:37 +02:00
James Yonan
972d10204d
copyright : updated to 2016 2020-01-31 10:24:37 +02:00
James Yonan
6b6c0f2038
Refactored openvpn/win/logfile.hpp, moving core methods create_file() and log() into a new file logutil.hpp for use by OMI logger. 2020-01-31 10:24:37 +02:00
James Yonan
7be71b2064
Added Windows utility classes and methods:
Win::Service -- A Windows Service wrapper.

Win::LogFile -- a LogBase derivative that allows logging
                to a natively created and handled file.

Win::module_name() -- Get the module name as a
                      std::wstring.

Win::module_name_utf8() -- Get the module name as a UTF-8
                           string.
2020-01-31 10:24:37 +02:00
Lev Stipakov
72d80fc960
agent win: add missing quoting for service path
This fixes https://nvd.nist.gov/vuln/detail/CVE-2014-5455

Signed-off-by: Lev Stipakov <lev@openvpn.net>
2020-01-31 10:24:36 +02:00
James Yonan
4346762a0d
Log lines from C++ exceptions should contain the text "exception"
This makes it easier to scan log files for exceptions.

Signed-off-by: James Yonan <james@openvpn.net>
2020-01-31 10:24:36 +02:00
James Yonan
5734e99bdb
copyright: updated to 2017
Signed-off-by: James Yonan <james@openvpn.net>
2020-01-31 10:24:36 +02:00
James Yonan
06cbc850dc
license : this branch (common) is proprietary, so remove all GPL headers.
Signed-off-by: James Yonan <james@openvpn.net>
2020-01-31 10:24:36 +02:00
James Yonan
3ff97e4031
copyright : updated to 2016 2020-01-31 10:24:35 +02:00
James Yonan
549634e6c5
Moved pack_string_vector() from winsvc.hpp to core, where it's now called wstring::pack_string_vector(). 2020-01-31 10:24:35 +02:00
James Yonan
7d1eb28016
ovpnagent -- enable service autostart and also added automatic restart-on-fail. 2020-01-31 10:24:35 +02:00
James Yonan
2efdf8a745
Change to calls of Windows API methods:
* Where unicode/ansi versions of a method exist, always
  explicitly call one of unicode or ansi methods by
  appending a 'W' or 'A' to the end of the method name.
  Never omit the 'W' or 'A' because that will cause the
  default method to be used which may vary according to
  build flags.

* Prepend all Windows API method references with "::" to
  indicate that the method names should be resolved from
  the top-level namespace.
2020-01-31 10:24:34 +02:00
James Yonan
c0ecc864cd
Added Windows utility classes and methods:
Win::Service -- A Windows Service wrapper.

Win::LogFile -- a LogBase derivative that allows logging
                to a natively created and handled file.

Win::module_name() -- Get the module name as a
                      std::wstring.

Win::module_name_utf8() -- Get the module name as a UTF-8
                           string.
2020-01-31 10:24:34 +02:00
Lev Stipakov
a4d9989d81
Update license on files moved from common
Signed-off-by: Lev Stipakov <lev@openvpn.net>
2020-01-09 12:24:20 +02:00
James Yonan
efe7f6d620
copyright: updated to 2017
Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:23:32 +02:00
James Yonan
bfadf92762
license : this branch (common) is proprietary, so remove all GPL headers.
Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:23:32 +02:00
James Yonan
fd949d96a3
copyright : updated to 2016 2020-01-09 12:23:31 +02:00
James Yonan
706574a59f
Change to calls of Windows API methods:
* Where unicode/ansi versions of a method exist, always
  explicitly call one of unicode or ansi methods by
  appending a 'W' or 'A' to the end of the method name.
  Never omit the 'W' or 'A' because that will cause the
  default method to be used which may vary according to
  build flags.

* Prepend all Windows API method references with "::" to
  indicate that the method names should be resolved from
  the top-level namespace.
2020-01-09 12:23:31 +02:00
James Yonan
edcc119b85
In HTTP server (httpserv.hpp), allow users to specify the Windows SDDL string used to set the permissions on created named pipes.
Also, refactor some Windows-specific code into secattr.hpp
(SECURITY_ATTRIBUTES stuff) and npinfo.hpp (getting info
about named pipe peer).
2020-01-09 12:23:31 +02:00
James Yonan
5bb9515515
copyright: updated to 2017
Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:23:31 +02:00
James Yonan
0d4b64139c
license : this branch (common) is proprietary, so remove all GPL headers.
Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:23:30 +02:00
James Yonan
61c99b5f6d
copyright : updated to 2016 2020-01-09 12:23:30 +02:00
James Yonan
25085c9073
Windows: refactored NamedPipePeerInfoClient/Server to use a common base class that includes most of the implementation. 2020-01-09 12:23:30 +02:00
James Yonan
397d44fccc
Windows: In NamedPipePeerInfo::get_process() and allow_client_query(), allow/request SYNCHRONIZE access so that we can wait for process termination by waiting on the process HANDLE. 2020-01-09 12:23:30 +02:00
James Yonan
7bba5cec30
Added openvpn/win/handlecomm.hpp, containing classes for communicating Windows HANDLEs across process boundaries. 2020-01-09 12:23:29 +02:00
James Yonan
b8f3d013aa
In Windows npinfo.hpp, added:
1. NamedPipeImpersonate : RAII class for scoping
                          ImpersonateNamedPipeClient/RevertToSelf.

2. send_handle() : duplicate a handle prior to sending
                   to a remote process.

Added #ifdefs to support both XP/Win2003 and Vista+.
2020-01-09 12:23:29 +02:00
James Yonan
c1a793b27f
Change to calls of Windows API methods:
* Where unicode/ansi versions of a method exist, always
  explicitly call one of unicode or ansi methods by
  appending a 'W' or 'A' to the end of the method name.
  Never omit the 'W' or 'A' because that will cause the
  default method to be used which may vary according to
  build flags.

* Prepend all Windows API method references with "::" to
  indicate that the method names should be resolved from
  the top-level namespace.
2020-01-09 12:23:29 +02:00