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

134 Commits

Author SHA1 Message Date
James Yonan
3f74ec1466 Listen::List: minor changes
* Use C++11 range-based iterators.
* Use std::string rather than std::ostringstream
  for string formatting.
* Added to_string() method.
* Added local_addr() method.

Signed-off-by: James Yonan <james@openvpn.net>
2017-09-27 16:16:18 +08:00
James Yonan
691a641a43 Added i/o abstraction layer.
Created a lightweight abstraction layer so that another i/o
reactor can be dropped in place of asio.

The basic approach is to rename all references to asio::xxx
types to openvpn_io::xxx and then make openvpn_io a
preprocessor variable that points to the top-level namespace
of the i/o reactor implementation.

All of the source files that currently include <asio.hpp> now
include <openvpn/io/io.hpp> instead:

This gives us a lightweight abstraction layer that allows us
to define openvpn_io to be something other than asio.

Other changes:

* Inclusion of asio by scripts/build is now optional, and is
  enabled by passing ASIO=1 or ASIO_DIR=<dir>.

* Refactored openvpn/common/socktypes.hpp to no longer
  require asio.

* Refactored openvpn/log/logthread.hpp to no longer require
  asio.

* Added openvpn::get_hostname() method as alternative to
  calling asio directly.

* openvpn/openssl/util/init.hpp will now #error
  if USE_ASIO is undefined.

Signed-off-by: James Yonan <james@openvpn.net>
2017-03-30 15:48:14 -06:00
James Yonan
6e8f2a73f8 Moved openvpn::to_string() to separate source file.
Signed-off-by: James Yonan <james@openvpn.net>
2017-03-18 15:46:45 -06:00
James Yonan
b2cd82a5bf copyright: updated to 2017.
Signed-off-by: James Yonan <james@openvpn.net>
2017-03-18 13:11:09 -06:00
James Yonan
3ac83e36b8 manage : added new ManClientInstanceSend virtual methods
Added instance_name() and instance_id()
2017-03-18 12:24:54 -06:00
James Yonan
81c9d74f29 server : provide a management layer callback
info_request() for INFO messages posted by client
to OpenVPN control channel.
2017-03-18 12:24:54 -06:00
James Yonan
9c0397ebd3 Added Relay capability, a kind of proxy function similar
to HTTP CONNECT but implemented over the OpenVPN protocol.

1. Client connects to relay server as if it were connecting
   to an ordinary OpenVPN server.

2. Client authenticates to relay server using its client
   certificate.

3. Client sends a PUSH_REQUEST method to relay server which
   then replies with a RELAY message instead of PUSH_REPLY.

4. On receiving the RELAY message, the client attempts to
   reconnect using the existing transport socket.  The
   server will proxy this new connection (at the transport
   layer) to a second server (chosen by the relay server)
   that is the target of proxy.

5. The client must establish and authenticate a new session
   from scratch with the target server, only reusing the
   transport layer socket from the original connection to
   the relay server.

6. The relay acts as a man-in-the-middle only at the
   transport layer (like most proxies), i.e. it forwards
   the encrypted session between client and target server
   without decrypting or having the capability to decrypt
   the session.

7. The client is designed to protect against potentially
   untrusted or malicious relays:

   (a) The client never transmits the target server
       username/password credentials to the relay server.

   (b) The relay forwards the encrypted OpenVPN session
       between client and target server without having
       access to the session keys.

   (c) The client configuration has a special directive
       for relay server CA (<relay-extra-ca>) and relay
       server tls-auth key (<relay-tls-auth>) to allow
       for separation of TLS/crypto configuration between
       relay and target servers.

   (d) The client will reject any PUSH_REPLY messages
       from the relay itself to prevent the relay from
       trying to establish a tunnel directly with the
       client.

Example configuring a client for relay:

  # remote addresses point to the relay server
  remote ... 1194 udp
  remote ... 443 tcp

  # include all other directives for connecting
  # to the target server

  # enable relay mode
  relay-mode

  # constrain the relay server's cert type
  relay-ns-cert-type server

  # include extra CAs that validate the relay
  # server cert (optional).
  <relay-extra-ca>
  -----BEGIN CERTIFICATE-----
  . . .
  -----END CERTIFICATE-----
  </relay-extra-ca>

  # specify the TLS auth key for the relay server
  relay-key-direction 1
  <relay-tls-auth>
  -----BEGIN OpenVPN Static key V1-----
  . . .
  -----END OpenVPN Static key V1-----
  </relay-tls-auth>
2017-03-18 12:24:54 -06:00
James Yonan
053bb3fc6f VPNServerNetblock : added contains() and netblock_contains()
methods.
2017-03-18 12:19:39 -06:00
James Yonan
1c302cde29 manage : in set_acl_id(), change type of acl_id from
unsigned int to int.
2017-03-18 12:19:39 -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
662bf7833e ovpn3 core : Added automatic data limits for Blowfish,
Triple DES, and other 64-bit block-size ciphers vulnerable
to "Sweet32" birthday attack (CVE-2016-6329).  Limit such
cipher keys to no more than 64 MB of data
encrypted/decrypted.  While our overall goal is to limit
data-limited keys to 64 MB, we trigger a renegotiation
at 48 MB to compensate for possible delays in renegotiation
and rollover to the new key.

This client-side implementation extends data limit
protection to the entire session, even when the server
doesn't implement data limits.

This capability is advertised to servers via the a
peer info setting:

  IV_BS64DL=1

meaning "Block-Size 64-bit Data Limit".  The "1" indicates
the implementation version.

The implementation currently has some limitations:

* Keys are renegotiated at a maximum rate of once per
  5 seconds to reduce the likelihood of loss of
  synchronization between peers.

* The maximum renegotiation rate may be further extended
  if the peer delays rollover from the old to new key
  after renegotiation.

Added N_KEY_LIMIT_RENEG stats counter to count the number
of data-limit-triggered renegotiations.

Added new stats counter KEY_STATE_ERROR which roughly
corresponds to the OpenVPN 2.x error "TLS Error:
local/remote TLS keys are out of sync".

Prevously, the TLS ack/retransmit timeout was hardcoded to
2 seconds.  Now we lower the default to 1 second and make
it variable using the (pushable) "tls-timeout" directive.
Additionally, the tls-timeout directive can be specified
in milliseconds instead of seconds by using the
"tls-timeout-ms" form of the directive.

Made the "become primary" time duration configurable via
the (pushable) "become-primary" directive which accepts
a number-of-seconds parameter.  become-primary indicates
the time delay between renegotiation and rollover to the
new key for encryption/transmission.  become-primary
defaults to the handshake-window which in turn defaults
to 60 seconds.

Incremented core version to 3.0.20.
2016-09-01 15:19:00 -06:00
James Yonan
5957ab8af1 server APIs : added set_acl_id(), set_fwmark(), and changed
the signature of push_reply().
2016-08-17 11:36:34 -07:00
James Yonan
a3ecdf3260 route : removed mark as a route-specific property. 2016-08-17 11:31:11 -07:00
James Yonan
689bfd7e8f keepalive : added is_keepalive_enabled() method. 2016-07-12 22:15:35 -07:00
James Yonan
2f1fd1ad83 Added INFO notification to OpenVPN control channel protocol:
INFO,<payload>

Payload can be any UTF-8 printable string under 64 KB
(multiple lines are okay).

INFO notifications can be sent from server to client
in real-time, on any active client connection.

The client will attach the payload to an INFO event and
forward it to the controlling app via the event callback:

  virtual void event(const Event&) = 0;
2016-05-10 17:53:09 -06:00
James Yonan
4083281bd1 buffer : added Buffer::null_terminate() method to
null-terminate a buffer that is not already null-terminated.
2016-05-10 17:50:03 -06:00
James Yonan
74d89fab7c OpenVPN protocol core : when passing objects to methods that
may assert ownership over them, use C++11 rvalue/move
semantics.
2016-05-10 13:02:11 -06:00
James Yonan
2255bab03a OpenVPN protocol core : added logic to control channel
receive path to reassemble messages fragmented by the
SSL layer up to a max message size of 64 KB.

Ramifications:

* Peer info data and pushed options can be significantly
  larger (i.e. approaching 64 KB).

* Less need for the options continuation feature.

Limitations:

* While this patch doesn't change the underlying OpenVPN
  protocol, it can result in messages being sent that are
  fragmented by the receiving SSL implementation into
  multiple buffers.  Implementations that lack reassembly
  capabilities (such as OpenVPN 2.x at this point in time)
  would see each buffer fragment as a separate message.

* This patch running on the server will break negotiation
  with pre-peer-info clients.  Basically this means it will
  interoperate with any OpenVPN 3 version or OpenVPN 2.x
  version that includes the June 2010 commit "Implemented a
  key/value auth channel from client to server.
  Version 2.1.1i".
2016-05-09 21:39:04 -06:00
James Yonan
cd1a20964b vpnservpool : major refactor for OMI.
* eliminated the GENERAL_POOL enumeration and vector.

* added support for standalone "ifconfig-push" directive
  as alternative to "server" for OMI agents that
  manage their own IP address pools.
2016-05-05 00:37:10 -06:00
James Yonan
a2fe68ae68 HaltRestart : added new RAW type for OMI. 2016-05-05 00:36:00 -06:00
James Yonan
6965eade7a class Protocol : add enum for client/server suffix. 2016-05-05 00:13:43 -06:00
James Yonan
71cb95c436 servproto : push_halt_restart_msg() needs to ensure
that time is up-to-date.
2016-04-14 13:38:47 -06:00
James Yonan
acf59d7600 Added request_ipv6 bool to VPNServerPool acquire() methods. 2016-02-04 15:53:46 -07:00
James Yonan
871f4c1299 Added VPNServerPool::IP46::to_string() method. 2016-01-27 14:14:57 -07:00
James Yonan
e8a63d1fdd Added HaltRestart::RESTART_PASSIVE type that sends a
RESTART_PSID to client but doesn't disconnect the internal
client instance object.
2016-01-27 14:12:33 -07:00
James Yonan
958d27d0c2 Added AUTH_FAILED to HaltRestart::Type.
In ServerProto::Session (servproto.hpp),
push_halt_restart_msg() can now push AUTH_FAILED messages
as well.

In fact ServerProto::Session::auth_failed() is now defined
in terms of push_halt_restart_msg().
2016-01-26 23:32:49 -07:00
James Yonan
030ede7a96 Added class IP46AutoRelease, derived from IP46, that automatically
releases allocated IP addresses in the destructor.
2016-01-26 23:30:48 -07:00
James Yonan
89ead953b3 Added Listen::Item::port_offset() method for generating
sequences of port numbers.
2016-01-18 00:37:37 -07:00
James Yonan
db118c46ff In Listen::Item, use C++11 member initialization. 2015-11-20 19:03:08 -07:00
James Yonan
32b6912931 Added Windows named-pipe support to RemoteList,
Listen::List, Protocol, and AsioPolySock.
2015-10-16 21:00:51 -06:00
James Yonan
9023c34929 Changes to vpnservnetblock.hpp and vpnservpool.hpp to
allow the use of multiple server-side VPN IP address
pools.
2015-09-20 20:58:35 -07:00
James Yonan
276a52d811 Added SSL switch (on/off/unspecified) to Listen::Item.
When parsing listen directives, "ssl" or "!ssl" may
be specified as the last parameter to set the ssl
switch.  By default, the switch is set to unspecified.
2015-09-08 05:58:32 -07:00
James Yonan
e0a51ad181 Added LoadMode enum on Listen::List constructor that supports
empty construction via AllowEmpty.
2015-09-02 03:20:12 -07:00
James Yonan
aa01b37d74 Added API method so management implementations can access
client bandwidth stats.
2015-07-18 14:19:08 -07:00
James Yonan
883620a95c Added new Listen::List constructor that accepts a single
Listen::Item.
2015-07-04 16:05:42 -06:00
James Yonan
16bde170c0 Don't use deprecated asio features. 2015-06-30 00:05:37 -06:00
James Yonan
0ec1bf62ba Perform additional size-based sanitization on creds
before passing to ManClientInstanceSend::auth_request()
2015-06-27 16:34:41 -06:00
James Yonan
9e50e8048a Added new methods to ManClientInstanceSend API: describe_user()
and disconnect_user().
2015-06-27 16:32:19 -06:00
James Yonan
1acc33feaf Obsoleted asiodispatch in favor of C++11 lambdas. 2015-06-25 13:59:12 -06:00
James Yonan
062391463c In options parser, add support for "remote" and "listen"
directives to refer to unix domain sockets.
2015-06-24 16:23:07 -06:00
James Yonan
496e797a21 Added client hooks for DCO (Data Channel offload).
Updated tun implementation on Linux.
2015-06-17 01:48:33 -06:00
James Yonan
c6a21c827b Boost dependency elimination -- final removal of Boost
dependency.  Asio is now included as a standalone,
header-only dependency.
2015-06-06 10:59:18 -06:00
James Yonan
88518335c4 Boost dependency elimination -- change boost::algorithm
usage (for string algorithms) to use methods of our own
implementation in openvpn/common/string.hpp.
2015-06-04 19:22:59 -06:00
James Yonan
be2922de39 Refactored methods for parsing/validating hosts/ports
into openvpn/common/hostport.hpp
2015-05-19 15:01:53 -06:00
James Yonan
e609e318ca Renamed openvpn/common/port.hpp -> openvpn/common/hostport.hpp 2015-05-19 13:33:29 -06:00
James Yonan
4366b3d3de In servproto.hpp, add to list of errors common enough that they
don't need an explicit "Session invalidated:" log message.

This list currently includes:

  Error::KEV_NEGOTIATE_ERROR
  Error::KEEPALIVE_TIMEOUT
2015-05-18 17:57:20 -06: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
3bcf8743c1 More conversions of threads/mutexes from boost to C++11 std.
As part of this work, removed openvpn/common/thread.hpp
2015-05-10 20:04:22 -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
9d9c51d6f4 C++11 update -- converted boost::unordered_map usage to
std::unordered_map.
2015-04-23 14:08:54 -06:00
James Yonan
b1550519b1 Added default constructor for Listen::List. 2015-04-19 11:21:24 -06:00
James Yonan
d313704255 On server side, count instead of log Error::KEV_NEGOTIATE_ERROR. 2015-04-12 11:14:33 -06:00
James Yonan
73b2b41f75 Extended Listen::List/Item to support different "listen"
directives.
2015-03-19 14:02:34 -06:00
James Yonan
65b24f39e9 Server: null-terminate transmitted control channel messages. 2015-01-22 17:55:57 -07:00
James Yonan
226785cbe2 Increased initial allocation of server-side AUTH_FAILED
buffer to 128 bytes.
2015-01-22 17:54:12 -07:00
James Yonan
3350db2c41 For Listen::List parser, allow number of threads parameter
to be multiplied by the number of processor cores on the machine
using this syntax:

  listen 0.0.0.0 1194 udp 4*N

The 4*N syntax indicates that OpenVPN should spawn 4 * N threads
to listen on 0.0.0.0:1194 where N is the number of processor
cores on the machine.
2015-01-19 14:26:41 -07:00
James Yonan
6f3aed5f90 Minor debug output change. 2015-01-16 00:22:14 -07:00
James Yonan
7daa811458 For consistency, ServerProto::Session should refer to base
class methods using a "Base::" prefix.
2015-01-15 17:06:12 -07:00
James Yonan
e2c90bf030 ServerProto::Session::stop() should reset the DC (data channel) factory. 2015-01-15 17:05:50 -07:00
James Yonan
d2bd31a80b Added some missing #includes. 2015-01-13 17:02:47 -07:00
James Yonan
b2190bbb7b Added server-side APIs for peer address, client float,
and bandwidth stats notifications.
2015-01-12 10:58:20 -07:00
James Yonan
3816443db5 Added total_threads() method to struct Listen::List. 2015-01-12 10:53:28 -07:00
James Yonan
ec0e7d5549 On server side, collect client cert info in the
new AuthCert object, and pass it through to
management decision object along with other creds
to consider for authentication.

In OpenSSL driver, split the verify_callback
function into client/server versions.

Modified InitProcess to do a special one-time call of
SSL_get_ex_new_index in OpenSSL library, so that we
can store a private object pointer in an OpenSSL
SSL struct.

TODO: Add AuthCert functionality to PolarSSL driver.
2015-01-08 15:33:48 -07:00
James Yonan
a6fc108384 Modified auth fail APIs (both initial and mid-session) to
include a flag (bool tell_client) indicating whether or not
the reason string should be transmitted to the client.
2015-01-08 15:25:23 -07:00
James Yonan
c2c7292a70 Updated copyright to 2015. 2015-01-06 12:56:21 -07:00
James Yonan
cc3a966ff5 TransportClientInstanceRecv::transport_recv now returns
true if incoming packet was successfully validated.
2015-01-04 20:35:53 -07:00
James Yonan
ba6b87cbbc Modified TLSAuthPreValidate to validate opcode and key_id
in addition to tls-auth.
2015-01-04 20:32:33 -07:00
James Yonan
74c576647f Server side: Added minimal local_peer_id support to proto.hpp. 2015-01-04 12:37:10 -07:00
James Yonan
a19b247567 Server side: added push_halt_restart_msg method for server to
disconnect clients with a specific user-visible reason string.
2015-01-04 12:34:30 -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
cdf5afb57f Added classes Listen::List and Listen::Item for parsing
new "listen" directive.
2014-12-13 21:28:55 -07:00
James Yonan
4751376a7c Added VPNServerNetblockPool, a shared, mutex-protected
IP address pool.
2014-12-13 21:26:24 -07:00
James Yonan
1b84fdbfe9 Minor fix of misplaced parenthesis in servproto.hpp. 2014-11-04 07:21:51 -07:00
James Yonan
d7c2b9d55f Added ManClientInstanceFactory::start().
Added ServerProto delayed disconnect for AUTH_FAILED.
2014-11-03 08:16:38 -07:00
James Yonan
641e58d5ee Changes to openvpn/addr:
* Use standard naming convention in openvpn/addr template classes,
  where "ADDR" is the address class, the class template name
  ends with "Type", and the IP::Addr specialization of the class
  template has the "Type" suffix removed.

* Added class RangePartitionType and RangeType::pull_front to help
  with subnet subdivision.

* Misc convenience methods added to RangeType and RouteType.

New file openvpn/server/vpnservnetblock.hpp :

* Added class VPNServerNetblock for deriving useful info about the
  top-level VPN IP address block and helping to subdivide it
  across server threads.
2014-11-02 20:31:48 -07:00
James Yonan
4b0f95483e TransportClientInstanceRecv::disable_keepalive now returns the
previous keepalive parameters.
2014-10-31 13:57:41 -06:00
James Yonan
eb25f37d11 Route:
* Make class Route standalone, moving it out of namespace
  CIDRMap.

CryptoAlgs:

* Added comments

* For type-safety, mode() now returns a Mode rather than an
  int.

CryptoDC:

* Added CRYPTO_DEFINED flag to indicate when encrypt() and
  decrypt() methods are implemented by a data channel
  provider.

Manage:

* Implemented skeleton management API for server-side client
  authentication and managing client-instance properties.

Proto:

* Added Config::update_dc_factory() method.

* Support new CryptoDCInstance::CRYPTO_DEFINED flag.

* Updated server_auth() method to support SafeString transit
  of client-provided auth-user-pass password to management
  layer.

* control_send now does a reset() on the provided
  Ptr reference before returning to reflect the
  transfer-of-ownership of the underlying buffer.

* Implemented disable_keepalive() and override_dc_factory
  methods.

Transbase (server) new methods:

  // disable keepalive for rest of session
  virtual void disable_keepalive() = 0;

  // override the data channel factory
  virtual void override_dc_factory(const CryptoDCFactory::Ptr& dc_factory) = 0;

  // override the tun provider
  virtual TunClientInstanceRecv* override_tun(TunClientInstanceSend* tun) = 0;

ServProto:

* Added abstract base classes for Tun factories and client instance
  sender/receivers.

* Added Tun and Management linkages.

* Added new receiver methods for overriding the data channel
  factory, Tun factory, and keepalive config.

* Added AuthCreds support.
2014-10-30 10:41:53 -06:00
James Yonan
92ac73e4ed Updated ServerProto for new template-free ProtoContext. 2014-10-22 11:29:45 -06:00
James Yonan
12e3f20e92 Converted SSL_API from static to dynamic polymorphism
(using SSLFactoryAPI and SSLAPI as base classes).
2014-10-15 18:12:38 -06:00
James Yonan
8b71fa9800 Converted RAND_API from static to dynamic polymorphism
(using RandomAPI as base class).
2014-10-15 12:53:18 -06:00
James Yonan
5826910bbe Refactored server-side client instance object (ServerProto::Session)
to use Link abstraction (openvpn/common/link.hpp) to link with
transport layer (and other layers such as routing and management
as development progresses).
2014-08-19 15:41:59 -06:00
James Yonan
d87a9e3c1e Server development initial checkpoint:
1. UDP server
2. Client instance objects

No routing, authentication, or management.

Server will negotiate a client then push AUTH_FAILED.
2014-08-19 01:13:42 -06:00