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

2180 Commits

Author SHA1 Message Date
James Yonan
78cae5bb52
OpenSSLPKI::DH: copy constructor doesn't need erase()
Only the assignment constructor needs to erase the
current value.

Signed-off-by: James Yonan <james@openvpn.net>
2019-06-19 18:20:59 +02:00
James Yonan
c0d43a4153
RCPtr: added static_pointer_cast() method
Signed-off-by: James Yonan <james@openvpn.net>
2019-06-19 18:20:56 +02:00
Arne Schwabe
34a3f264f5 [OVPN-314] Add support for signalling SSO support via IV_SSO 2019-06-13 12:05:16 +02:00
Jay Freeman (saurik)
275cf80efb
mac/tuncli: Don't take address of temporary error.
The function code() on a system_error returns a temporary value of type error_code; using & on such a value is incorrect.

    In file included from openvpn3/test/ovpncli/cli.cpp:58:
    In file included from openvpn3/client/ovpncli.cpp:97:
    In file included from openvpn3/openvpn/client/cliconnect.hpp:60:
    In file included from openvpn3/openvpn/client/cliopt.hpp:85:
    In file included from openvpn3/openvpn/tun/mac/client/tuncli.hpp:38:
    openvpn3/openvpn/tun/tunio.hpp:119:42: error: taking the address of a temporary object of type 'boost::system::error_code' [-Waddress-of-temporary]
                  tun_error(Error::TUN_WRITE_ERROR, &e.code());
                                                    ^~~~~~~~~
    openvpn3/openvpn/tun/tunio.hpp:152:42: error: taking the address of a temporary object of type 'boost::system::error_code' [-Waddress-of-temporary]
                  tun_error(Error::TUN_WRITE_ERROR, &e.code());
                                                    ^~~~~~~~~
    openvpn3/openvpn/tun/tunio.hpp:119:42: error: taking the address of a temporary object of type 'boost::system::error_code' [-Waddress-of-temporary]
                  tun_error(Error::TUN_WRITE_ERROR, &e.code());
                                                    ^~~~~~~~~
    openvpn3/openvpn/tun/mac/client/tuncli.hpp:330:17: note: in instantiation of member function 'openvpn::TunIO<openvpn::TunMac::Client *, openvpn::TunMac::PacketFrom, openvpn::TunWrapAsioStream<openvpn::TunPersistTemplate<openvpn::ScopedAsioStream<boost::asio::posix::basic_stream_descriptor<boost::asio::executor> > > > >::write' requested here
              return impl->write(buf);
                           ^

Signed-off-by: Jay Freeman (saurik) <saurik@saurik.com>
GitHub-pull-req: #76
Approved-by: Lev Stipakov <lev@openvpn.net>
Approved-by: David Sommerseth <davids@openvpn.net>
2019-06-12 19:39:32 +02:00
Jay Freeman (saurik)
1406187bfc
tun/win/tunutil: Don't auto& a temporary iterator.
The current Tun code for Windows happens to compile on Microsoft Visual C++,
but will not compile on either clang or gcc as it isn't standards compliant.

    openvpn3/openvpn/tun/win/tunutil.hpp:213:17: error: non-const lvalue reference to type '__wrap_iter<...>' cannot bind to a temporary of type '__wrap_iter<...>'
                for (auto& i = guids.begin(); i != guids.end(); i++)
                           ^   ~~~~~~~~~~~~~

The type of guids.begin() is a value iterator, and so must be merely "auto".

Signed-off-by: Jay Freeman (saurik) <saurik@saurik.com>
GitHub-pull-req: #74
Approved-by: Lev Stipakov <lev@openvpn.net>
Approved-by: David Sommerseth <davids@openvpn.net>
2019-06-12 19:40:07 +02:00
Jay Freeman (saurik)
fe7f984c5d
ip/ping6: Use _WIN32, not _MSC_VER (to fix MinGW).
When compiling openvpn3 with MinGW, the build fails as follows:

    openvpn3/openvpn/ip/ping6.hpp:46:20: error: no member named 's6_addr16' in 'in6_addr'
          return addr->s6_addr16;
                 ~~~~  ^

This is because the code checks for _MSC_VER instead of _WIN32.

Signed-off-by: Jay Freeman (saurik) <saurik@saurik.com>
GitHub-pull-req: #73
Approved-by: Lev Stipakov <lev@openvpn.net>
Approved-by: David Sommerseth <davids@openvpn.net>
2019-06-12 19:39:32 +02:00
Lev Stipakov
03a906771e win: add OpenSSL as solution configuration
This also removes unittest.vcxproj from solution, since
it is deprecated in favor of CMake-based unit tests.

Signed-off-by: Lev Stipakov <lev@openvpn.net>
2019-06-05 13:54:13 +03:00
Lev Stipakov
89cc11b300 win: enable building Windows client with OpenSSL
Signed-off-by: Lev Stipakov <lev@openvpn.net>
2019-06-05 13:54:12 +03:00
Lev Stipakov
febb24e7d9 openssl/compat.hpp: remove functions already defined in OpenSSL
Contrary to what OpenSSL doc for 1.0.2 says:

https://www.openssl.org/docs/man1.0.2/man3/EVP_CIPHER_CTX_type.html

those functions have been defined since year 2005 (0.9.8b):

b40228a61d
Signed-off-by: Lev Stipakov <lev@openvpn.net>
2019-06-05 13:01:00 +03:00
David Sommerseth
0833eb1f76
linux/tunsetup: Fix missing asio/errinfo declaration
When building the clinetcfg test client in openvpn3-linux with DCO support,
the building fails with the following compiler error:

    In file included from ./openvpn3-core/openvpn/common/base64.hpp:31:0,
                     from ./openvpn3-core/openvpn/init/initprocess.hpp:31,
                     from ./openvpn3-core/client/ovpncli.cpp:90,
                     from ./openvpn3-core/test/ovpncli/cli.cpp:58,
                     from src/tests/netcfg/cli.cpp:29:
    ./openvpn3-core/openvpn/tun/linux/client/tunsetup.hpp: In member function ‘int openvpn::TunLinuxSetup::Setup<TUNMETHODS>::establish(const openvpn::TunBuilderCapture&, openvpn::TunBuilderSetup::Config*, openvpn::Stop*, std::ostream&)’:
    ./openvpn3-core/openvpn/tun/linux/client/tunsetup.hpp:145:94: error: there are no arguments to ‘errinfo’ that depend on a template parameter, so a declaration of ‘errinfo’ must be available [-fpermissive]
         OPENVPN_THROW(tun_open_error, "error opening tun device " << node <<": " << errinfo(errno));
                                                                                                  ^
    ./openvpn3-core/openvpn/common/exception.hpp:130:18: note: in definition of macro ‘OPENVPN_THROW’
         _ovpn_exc << stuff; \
                      ^

By including the asioerr.hpp header file in
openvpn/tun/linux/client/tunsetup.hpp, this failure is resolved.

Signed-off-by: David Sommerseth <davids@openvpn.net>
2019-06-03 21:08:21 +02:00
David Sommerseth
d54b742910
linux: Improve cpu_time() using glibc/kernel methods
Swap out the /proc parsing logic with getrusage() instead.

Signed-off-by: David Sommerseth <davids@openvpn.net>
2019-06-03 19:05:34 +02:00
David Sommerseth
a55fe2b554
tests: Added unit test for linux/cputime.hpp
This test attempts to assure that the measurements we get from
openvpn::cpu_time() is within a reasonable range of what we should
normally expect.

This is achieved by using a simple worker thread which ensures the
process is not "idling" (like it would with sleep()) but in a real busy
loop which takes some time.  Then we measure the time spent in the busy
loop, both using a simplistic time() and comparing that with what
cpu_time() returns.

This unit test also supports measuring multiple running threads
individually too.

Signed-off-by: David Sommerseth <davids@openvpn.net>
2019-06-03 19:05:34 +02:00
Lev Stipakov
e33a00e6de [OVPN3-431] agent: Wintun support for agent
Signed-off-by: Lev Stipakov <lev@openvpn.net>
2019-06-03 14:53:33 +03:00
Lev Stipakov
42592eb1b1 appveyor: initial commit
Add appveyor script which builds Windows test client.

Signed-off-by: Lev Stipakov <lev@openvpn.net>
2019-05-29 22:16:38 +03:00
Lev Stipakov
3e3f2078e6 win: rename env var in project file
Use $O3 instead of $OVPN3_ROOT to be consistent
with other platforms.

Signed-off-by: Lev Stipakov <lev@openvpn.net>
2019-05-29 22:15:45 +03:00
Lev Stipakov
a2496a3616 Wintun: experimental support
This introduces experimental support for Wintun
as an alternative for tap-windows6.

In order to use wintun, set "ClientAPI::Config::wintun"
flag to "true" or use "-w" option in test client.

Signed-off-by: Lev Stipakov <lev@openvpn.net>
2019-05-29 20:21:28 +03:00
James Yonan
58a7866b45
build script: added OPENSSL_DIST parameter to specify a custom OpenSSL build
Signed-off-by: James Yonan <james@openvpn.net>
2019-05-22 17:57:42 +02:00
James Yonan
288ea0277e
OpenSSLContext: SSL_CTX_set_ecdh_auto() becomes a no-op in OpenSSL 1.1, so #ifdef out to avoid compiler warnings
Signed-off-by: James Yonan <james@openvpn.net>
2019-05-22 17:57:42 +02:00
James Yonan
3ef5059fa6
TLSSessionTicketBase: removed the ERROR symbol from a local enum in case it conflicts with a global preprocessor symbol
Signed-off-by: James Yonan <james@openvpn.net>
2019-05-22 17:57:42 +02:00
James Yonan
3364ed76b8
TLSSessionTicketBase: removed trailing comma from Status enum
Windows c++ compiler apparently doesn't like trailing
comma in enum.

Signed-off-by: James Yonan <james@openvpn.net>
2019-05-22 17:57:42 +02:00
David Sommerseth
025c7bad88
mbedtls/sslctx: Fix missing override in virtual methods
The Clang++ compiler is not happy about this missing declaration on
virtual methods, which is a fair complaint.

Signed-off-by: David Sommerseth <davids@openvpn.net>
2019-05-16 15:12:47 +02:00
James Yonan
6cb3243681
mbedTLS: ssl() method accepting hostname should check if it is null
Signed-off-by: James Yonan <james@openvpn.net>
2019-05-16 14:50:06 +02:00
James Yonan
ca31da7d28
bio_memq_stream.hpp: fixed multi-thread race (introduced with OpenSSL 1.1 support) using init_static() approach
Signed-off-by: James Yonan <james@openvpn.net>
2019-05-16 14:50:06 +02:00
James Yonan
2deb402223
OpenSSLContext::tls_ticket_key_callback: get self with SSL_get_ex_data instead of ssl->ctx->app_verify_arg
Fixed this error:

  Appserv: E_EXCEPTION : HTTPCore Exception tcp_read_handler:
    OpenSSLContext::SSL::read_cleartext: BIO_read failed, cap=2048 status=-1

Signed-off-by: James Yonan <james@openvpn.net>
2019-05-16 14:50:06 +02:00
James Yonan
eec139a100
MSF::find: renamed template type names to avoid conflict with preprocessor symbol (ITER) in test/ssl/proto.cpp
Signed-off-by: James Yonan <james@openvpn.net>
2019-05-16 14:50:06 +02:00
James Yonan
1024d37f33
str_neq: fixed bug where neq was not initialized
Signed-off-by: James Yonan <james@openvpn.net>
2019-05-16 14:50:06 +02: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
448c549a0b
cpu_time(): added bool thread parameter to return CPU time of current thread (instead of process)
Signed-off-by: James Yonan <james@openvpn.net>
2019-05-16 14:50:06 +02:00
James Yonan
868801d7d9
Linux library: added cpu_time() method to return the CPU time of the current process
Signed-off-by: James Yonan <james@openvpn.net>
2019-05-16 14:50:06 +02:00
James Yonan
964d2cd428
SSL layer: added did_full_handshake() method and implemented for OpenSSL
Returns true if we did a full SSL handshake/negotiation.
or false for cached, reused, or persisted sessions.

Signed-off-by: James Yonan <james@openvpn.net>
2019-05-16 14:50:06 +02:00
James Yonan
dd18d6c806
crypto::str_neq: use atomic_thread_fence(std::memory_order_acq_rel) instead of OPENVPN_COMPILER_FENCE
Signed-off-by: James Yonan <james@openvpn.net>
2019-05-16 14:50:06 +02:00
James Yonan
6a30af9528
OpenSSLSessionCache: use map instead of unordered_map
Signed-off-by: James Yonan <james@openvpn.net>
2019-05-16 14:50:06 +02:00
James Yonan
3ecbcbc81b
OptionList: fixed compile errors that occur when get_num<T>() is used with a const type
Signed-off-by: James Yonan <james@openvpn.net>
2019-05-16 14:50:06 +02:00
James Yonan
72e9f858e4
SSL: added SSLConst::PEER_CERT_OPTIONAL flag and implemented for OpenSSL
Signed-off-by: James Yonan <james@openvpn.net>
2019-05-16 14:50:06 +02:00
James Yonan
33f15c8840
OpenSSL: use OPENSSL_VERSION_NUMBER instead of SSLEAY_VERSION_NUMBER
Signed-off-by: James Yonan <james@openvpn.net>
2019-05-16 14:50:06 +02:00
James Yonan
cadb712ea9
ProfileMerge: added "static-key" to is_fileref_directive()
Signed-off-by: James Yonan <james@openvpn.net>
2019-05-16 14:50:06 +02:00
James Yonan
85befa316a
TLS session tickets: work around an issue in OpenSSL session ticket keying callback
Earlier versions of OpenSSL (before 1.0.2r) appear to
segfault when the SSL_CTX_set_tlsext_ticket_key_cb
callback returns 0 (no key) when enc==1.

This commit also privatizes the default constructor for
TLSSessionTicketBase Name/Key (which creates the object in an
undefined state) and removes methods that allow direct access
to the underlying name/key data.  Since only the SSL
implementation classes (OpenSSLContext and MbedTLSContext)
require this level of access, we friend them, but deny access
to all other users.  This helps to prevent bugs in the
higher-level Name/Key handling code, such as failing to
initialize a Key by using the default constructor.

Signed-off-by: James Yonan <james@openvpn.net>
2019-05-16 14:50:06 +02:00
James Yonan
f43c4c1440
TLSSessionTicketBase: misc fixes/enhancements
* Fixed a bug in Name::operator<()

* ~Key() now wipes key data from memory

* Added key_transform() method

* Added session_id_context() virtual method for identifying app

Signed-off-by: James Yonan <james@openvpn.net>
2019-05-16 14:50:06 +02:00
James Yonan
c5f4d59d39
OpenSSLContext: added missing X509_free() to rebuild_authcert()
Signed-off-by: James Yonan <james@openvpn.net>
2019-05-16 14:50:06 +02:00
James Yonan
658fcc50eb
OptionList: added get_num methods with min/max but no default
Signed-off-by: James Yonan <james@openvpn.net>
2019-05-16 14:50:06 +02:00
James Yonan
162eeaa485
SSL layer: added RFC 5077 TLS session resumption ticket support
This is an initial client and server-side implementation
for OpenSSL 1.0.2.

Note that this functionality is intended for use with
HTTP sessions, and should not be used with the OpenVPN
protocol.

Signed-off-by: James Yonan <james@openvpn.net>
2019-05-16 14:50:06 +02:00
James Yonan
e0a821ddd6
OpenSSLContext: use C++11 member initializers
Signed-off-by: James Yonan <james@openvpn.net>
2019-05-15 19:15:04 +02:00
James Yonan
1ea5acce3c
OpenSSLContext: minor changes to handshake_details()
* Passed ::SSL* argument should not be const
* Check for null cipher

Signed-off-by: James Yonan <james@openvpn.net>
2019-05-15 19:14:45 +02:00
James Yonan
74c0a4f995
string: added copy_fill() method
Signed-off-by: James Yonan <james@openvpn.net>
2019-05-15 19:12:59 +02:00
James Yonan
3e5921c06d
AuthCert: added is_uninitialized() method
Signed-off-by: James Yonan <james@openvpn.net>
2019-05-15 19:12:59 +02:00
James Yonan
3d6b6b2319
library: added convenience method MSF::find() for maps/sets
MSF::find() is like ordinary map/set find(), but returns an
iterator that defines an operator bool() method for testing
if the iterator is defined, e.g.:

  std::map<std::string, std::string> m;
  m.emplace("hello", "world");

  auto e = MSF::find(m, "hello");
  if (e)
    std::cout << e->first << " -> " << e->second << std::endl;

Signed-off-by: James Yonan <james@openvpn.net>
2019-05-15 19:12:59 +02:00
James Yonan
18f5f4d1b5
SSLConfigAPI: remove set_enable_renegotiation()
Removed set_enable_renegotiation from SSLConfigAPI and underlying
SSL implementations (OpenSSL, MbedTLS) since we are not currently
using it and TLS 1.3 standardizes on a session ticket model rather
than server-side session caching.

Signed-off-by: James Yonan <james@openvpn.net>
2019-05-15 18:56:48 +02:00
James Yonan
18dcfd616c
Added crypto::str_neq() function for securely comparing variable-length strings
The goal is to prevent the leakage of timing data about
the length or content of the target string.

Signed-off-by: James Yonan <james@openvpn.net>
2019-05-15 18:56:47 +02:00
James Yonan
4fc5725b9e
RunContext: added get_servers() method
Signed-off-by: James Yonan <james@openvpn.net>
2019-05-15 18:56:46 +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