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

301 Commits

Author SHA1 Message Date
James Yonan
2af25cca08
Minor readability/comments update to httpcommon.hpp. 2020-01-09 12:24:09 +02:00
James Yonan
8f535eb76e
Refactored web services classes (openvpn/ws) to support HTTP/S servers. 2020-01-09 12:24:08 +02:00
James Yonan
a22d7c3d7d
In HTTPCore (httpcli.hpp), factor out code into httpcommon.hpp that is common to both HTTP clients and servers, so upcoming HTTP server implementation can leverage on the same code currently used by the client. 2020-01-09 12:24:08 +02:00
James Yonan
c61a41f509
Factored out web services get_content_length() method into openvpn/ws/httpcommon.hpp which is intended for code that is common between HTTP clients and servers. 2020-01-09 12:24:08 +02:00
James Yonan
98e5e0a6a3
HTTP: before logging, pass HTTP headers through HTTP::headers_redact()
Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:24:08 +02:00
James Yonan
1443d9c000
Implement TCP shutdown at the HTTP layer
This patch tries to gracefully shutdown a socket before
closing it, in non-error, non-stop situations.

Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:24:07 +02:00
James Yonan
a52b22afe9
Replace AsioTimer with AsioTimerSafe in cases where handler doesn't clearly check for late cancellation
As noted in the Asio documentation, an AsioTimer handler can be
called with a non-error status after timer cancellation.

Unfortunately, this can lead to race conditions, so I'm moving over
all AsioTimer users to AsioTimerSafe when I don't see the handler
clearly checking for late cancellation.

Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:24:07 +02:00
Lev Stipakov
a43a95a527
win agent: properly handle timeout
Sometimes when machine wakes from sleep,
it takes too long for agent service to start. This causes
an error which core treats as fatal and stops connection.

Fix by detecting timeout and throw non-fatal error, which
makes core reconnect.

Signed-off-by: Lev Stipakov <lev@openvpn.net>
2020-01-09 12:24:07 +02:00
James Yonan
8bfc822183
WS::ClientSet: HTTP persistence refactor
HTTP persistence across transaction sets can now be
simplified using assign_http_state()

Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:24:07 +02:00
James Yonan
72e5cb6b52
WS::ClientSet: added commented-out debug logging in keepalive_close()
Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:24:07 +02:00
James Yonan
dfed44d539
WS::ClientSet: retry on 5xx HTTP status codes
Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:24:06 +02:00
James Yonan
dd00ef3be3
WS::ClientSet::TransactionSet: added reset_host() method
Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:24:06 +02:00
James Yonan
9cf0003de4
WS::ClientSet::Transaction: added new methods is_redirect() and get_redirect_location()
Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:24:06 +02:00
James Yonan
cc2638a21d
WS::ClientSet: special case on retry -- no delay after TCP EOF on first retry
Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:24:06 +02:00
James Yonan
99494dedf6
WS::ClientSet::TransactionSet: added stop() method
Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:24:05 +02:00
James Yonan
767f717023
WS::ClientSet: added reset_callbacks() methods to break refcount cycles in callback closures
Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:24:05 +02:00
James Yonan
7183c6b1da
WS::ClientSet::Transaction: refactored format_status()
Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:24:05 +02:00
James Yonan
bb67edbe31
WS::ClientSet::Transaction:: added content_in_buffer() method
Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:24:05 +02:00
James Yonan
f54992798f
WS::ClientSet: pass refcounted pointers by value
Also use std::move() on passed pointers where appropriate

Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:24:04 +02:00
James Yonan
bd59f8937b
JsonClient/AppServer: full HTTP compression support
* gzip or lz4 supported for standard HTTP.

* lz4 support for websocket.

Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:24:04 +02:00
James Yonan
9b12054680
WS::ClientSet: misc changes
* HostRetry, which is essentially a string vector, now
  inherits directly from std::vector<std::string>

* WS::ClientSet doesn't need a crypto-grade RNG, so rename
  rng to prng.

* WS::ClientSet almost always contains a single client
  object, so use std::map instead of std::unordered_map
  to contain it so as to reduce overhead.

Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:24:04 +02:00
James Yonan
7a0df7104f
AsioTimer: use expires_after() method when possible.
A common AsioTimer usage pattern is:

  expires_at(Time::now() + duration)

This is more succinctly and efficiently stated as:

  expires_after(duration).

Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:24:04 +02:00
James Yonan
f97c0812d3
httpcliset.hpp: use Function instead of std::function.
Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:24:03 +02:00
James Yonan
dcaf7e5358
Added i/o abstraction layer.
Created a lightweight abstraction layer so that another i/o
reactor can be dropped in place of asio.

This commit includes:

* Added ASIO=1 to many "go" scripts that require asio
* Renamed "asio::" to "openvpn_io::".

Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:24:03 +02:00
James Yonan
2805a7819d
Moved asio files from openvpn/common to openvpn/asio
Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:24:03 +02:00
James Yonan
f524e75c34
copyright: updated to 2017
Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:24:03 +02:00
James Yonan
c8accf5923
license : this branch (common) is proprietary, so remove all GPL headers.
Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:24:02 +02:00
James Yonan
10526fa7d8
httpcliset : minor refactor of new_request_synchronous() which removes SyncPersistState as a parameter (replacing with sps boolean) and moves it to private area of TransactionSet. 2020-01-09 12:24:02 +02:00
James Yonan
11821b44b4
httpcliset : prevent done() method from being called reentrantly if it throws an exception. 2020-01-09 12:24:02 +02:00
James Yonan
01199c3728
copyright : updated to 2016 2020-01-09 12:24:02 +02:00
James Yonan
ee68d87a87
httpcliset : Added user-defined error recovery method, and HostRetry as an error recovery implementation that allows cycling through a list of hostnames on failover. Also refactored reconnect_schedule() so that reconnect_callback() can be eliminated. 2020-01-09 12:24:01 +02:00
James Yonan
f838a91421
httpcliset : Added WS::ClientSet::run_synchronous() method. 2020-01-09 12:24:01 +02:00
James Yonan
8913eefca0
httpcliset : in new_request_synchronous(), added optional RandomAPI parameter. 2020-01-09 12:24:01 +02:00
James Yonan
d36a9145fe
httpcliset : Added WS::ClientSet::get_random() method. 2020-01-09 12:24:01 +02:00
James Yonan
585990d801
httpcliset : when preserve_http_state is false, close out the HTTPStateContainer before calling completion callback, so as to improve reentrancy-safety if completion callback tries to queue a new request. 2020-01-09 12:24:00 +02:00
James Yonan
7cc0104d8c
random : consolidate random functionality in RandomAPI. 2020-01-09 12:24:00 +02:00
James Yonan
2cffff05d4
Fixed a recent regression in WS::ClientSet::new_request_synchronous() that was introduced with the new SyncPersistState parameter.
The Cleanup code could potentially execute after io_context
is released, causing undefined behavior.  The fix is to move
the io_context declaration to the outermost scope (i.e. top
of the method) so that it is still in scope when Cleanup code
is called.
2020-01-09 12:24:00 +02:00
James Yonan
c77bd04c8b
In WS::ClientSet::new_request_synchronous(), only use io_context->run_one() when SyncPersistState obj is provided. Otherwise, use io_context->run(). 2020-01-09 12:24:00 +02:00
James Yonan
cb37d11424
In HTTP client set, allow successive calls of new_request_synchronous() to operate off of the same persisted HTTP session. 2020-01-09 12:23:59 +02:00
James Yonan
fb7d46e008
In httpcliset.hpp, replace class HSCCleanup with the general-purpose Cleanup template. 2020-01-09 12:23:59 +02:00
James Yonan
d6de23f761
Apparently Android NDK doesn't support std::to_string (WTF?), so work around it.
http://stackoverflow.com/questions/22774009/android-ndk-stdto-string-support
2020-01-09 12:23:59 +02:00
James Yonan
861aec6da5
In httpcliset.hpp, fixed recent regression where new_request_synchronous() was not ensuring that ts->hsc.reset() is called before method exit. Not doing so can cause later destruction of the HTTPDelegate in HTTPStateContainer to reference an out-of-scope io_context. 2020-01-09 12:23:59 +02:00
James Yonan
e2e0701842
In httpcliset.hpp, changes to WS::ClientSet::new_request_synchronous():
* Added optional Stop object to new_request_synchronous()
  method to allow for asynchronous request abort that is
  triggered from another thread.

* In new_request_synchronous(), allow exceptions to
  break out of method and reach caller.

* In new_request_synchronous(), don't automatically call
  ts->hsc.reset() before method exit, since that is better
  controlled by preserve_http_state.
2020-01-09 12:23:58 +02:00
James Yonan
9de22d87d8
In HTTPStateContainer::stop() (httpcliset.hpp), make sure to check that http is non-null before calling http->stop(). 2020-01-09 12:23:58 +02:00
James Yonan
47d3195685
In WS::ClientSet, call completion method before ts->hsc.stop() to allow completion method to use socket before it is closed. 2020-01-09 12:23:58 +02:00
James Yonan
008ad4a7a4
In HTTP client:
Added get_socket() method to WS::Client to return the
underlying HTTP AsioPolySock::Base object.

Added unix_fd() method to WS::ClientSet which depends on
get_socket() above and will return the fd of HTTP socket
if it's a unix domain socket.
2020-01-09 12:23:58 +02:00
James Yonan
24418ad8fe
In HTTP client, added abort() method to both WS::Client and WS::ClientSet. 2020-01-09 12:23:57 +02:00
James Yonan
24552a1514
In httpcliset.hpp, break up http_status_success() into:
1. comm_status_success()
2. request_status_success()

to differentiate between communication and request errors.
2020-01-09 12:23:57 +02:00
James Yonan
484481bacf
In WS::ClientSet, use BufferList::put_consume() to store incoming content. This approach is more efficient when incoming content is composed of many small messages. 2020-01-09 12:23:57 +02:00
James Yonan
ece0aa681e
The WS::ClientSet::new_request_synchronous() method doesn't really need to fork off a thread to do its work. This change uses a local asio::io_context within the caller's own thread. 2020-01-09 12:23:57 +02:00
James Yonan
16a967db39
In httpcliset.hpp, be consistent about member vars coming first in Transaction and TransactionSet, before member functions. 2020-01-09 12:23:56 +02:00
James Yonan
8ca342cbdd
In WS::ClientSet::new_request_synchronous(), ensure that socket is fully destroyed before exiting thread, as we don't want any asio-level destructors to be called from the parent thread.
As part of this change, HTTPStateContainer::stop() now stops
the HTTPDelegate instance and HTTPStateContainer::reset()
resets the shared pointer.
2020-01-09 12:23:56 +02:00
James Yonan
bb107abf39
WS::ClientSet bugfix : a segfault can occur when general_timeout is set to 0 because HTTPStateContainer::reset() can potentially be called under tcp_read_handler() at the http_done/next_request boundary when no timeout exists to keep a stable reference on the HTTPDelegate instance.
The fix is twofold:

1. HTTPStateContainer should reset the HTTPDelegate by calling
   stop() in the delegate instead of reset() on the shared
   pointer to avoid triggering HTTPDelegate destructor.

2. http_done() method should not call next_request() directly but
   should instead call it through an asio::post() to ensure a
   fresh stack.
2020-01-09 12:23:56 +02:00
James Yonan
e6816832f1
Added WS::ClientSet::Transaction::http_status_success() method to complement the same method in WS::ClientSet::TransactionSet. 2020-01-09 12:23:56 +02:00
James Yonan
65c2aee203
httpcliset changes:
* Added new_request_synchronous() static method
  to synchronously execute a TransactionSet
  in a worker thread.

* Added TransactionSet::preserve_http_state bool
  (default=false) to determine whether or not to
  preserve HTTP session across multiple completions.

* TransactionSet::completion() callback is now optional.

* Simplify Transaction and TransactionSet class
  declarations by eliminating constructors in favor
  of C++11 member initialization.
2020-01-09 12:23:55 +02:00
James Yonan
76fe2a9061
In HTTP client, added http_post_connect() virtual callback method to allow user to verify server socket immediately after connect. This is useful when the server is local via a unix domain socket or windows named pipe.
In WS::ClientSet, exposed the callback as a std::function
in TransactionSet::post_connect.
2020-01-09 12:23:55 +02:00
James Yonan
0a697e21d7
In httpcliset.hpp, use URL::Parse for building and rendering URLs. 2020-01-09 12:23:55 +02:00
James Yonan
5f4e0396b9
In test/httpcli/httpcli.cpp and httpcliset.hpp, support building without zlib. 2020-01-09 12:23:55 +02:00
James Yonan
6c0e9b26e3
In httpcliset.hpp, added new method WS::ClientSet::TransactionSet::http_status_success() that returns true if and only if all HTTP transactions succeeded AND each HTTP status code was in the successful range of 2xx. 2020-01-09 12:23:54 +02:00
James Yonan
74b6ee5c1b
In httpcliset.hpp, minor changes to dump() formatting:
* Added content_only flag to dump().

* In title header, show full format_status() line.

* format_status() no longer adds a newline to end of
  returned string.
2020-01-09 12:23:54 +02:00
James Yonan
1661ddfcc7
In httpcliset.hpp, fixed issue where setting accept_gzip_in flag wasn't sending "Accept-Encoding: gzip" header. 2020-01-09 12:23:54 +02:00
James Yonan
c1a0a5972f
In httpcliset.hpp, programmatically turn on/off ZLib compress/decompress debug logging based on our own debug level. 2020-01-09 12:23:54 +02:00
James Yonan
95f1afef37
Added WS::ClientSet::Transaction::format_status() method. 2020-01-09 12:23:53 +02:00
James Yonan
7994bb9d7d
In httpcliset.hpp, make dump() methods const. 2020-01-09 12:23:53 +02:00
James Yonan
6b9e2c4537
Added WS::ClientSet, a higher-level client session manager abstraction on top of WS::Client with features such as:
* multiple sessions (concurrent or linearized on a persistent
  HTTP session),
* transactions,
* persistence,
* retry/failover,
* gzip integration, and
* resolver results randomization.
2020-01-09 12:23:53 +02:00
James Yonan
a6cd836dde
WS::Client: don't use AsyncResolvableTCP unless USE_ASYNC_RESOLVE is defined
In testing, I found an s3fetch regression apparently caused by
AsyncResolvableTCP.

When WS::Client is built with AsyncResolvableTCP, s3fetch will
segfault when large numbers of query threads (> 256) are used.

Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:23:53 +02:00
James Yonan
9244137de0
Implement TCP shutdown at the HTTP layer
This patch tries to gracefully shutdown a socket before
closing it, in non-error, non-stop situations.

Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:23:52 +02:00
James Yonan
f5ac6450da
Replace AsioTimer with AsioTimerSafe in cases where handler doesn't clearly check for late cancellation
As noted in the Asio documentation, an AsioTimer handler can be
called with a non-error status after timer cancellation.

Unfortunately, this can lead to race conditions, so I'm moving over
all AsioTimer users to AsioTimerSafe when I don't see the handler
clearly checking for late cancellation.

Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:23:52 +02:00
James Yonan
a76cc3f1a5
httpcli: avoid E_KEEPALIVE_TIMEOUT race with start_request by checking ready
Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:23:52 +02:00
James Yonan
734032f04a
WS::Client::Host: added key parameter for client-side TLS session caching
In InfraJson::SetupTemplate allow key parameter to be
controlled via "cache-key" directive.

Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:23:52 +02:00
James Yonan
aee28239ab
Implemented TLS session ticket support in the HTTP layers.
Added support for PGDB server and clients, and the chat test.

Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:23:51 +02:00
Lev Stipakov
7f9e493ef3
transport: remove unused ip_hole_punch() API
Signed-off-by: Lev Stipakov <lev@openvpn.net>
2020-01-09 12:23:51 +02:00
Antonio Quartulli
3b9af47f32
httpcli.hpp: use new AsyncResolvable class for async DNS resolution
Signed-off-by: Antonio Quartulli <antonio@openvpn.net>
2020-01-09 12:23:51 +02:00
James Yonan
cdf149a015
WS::ClientSet: HTTP persistence refactor
HTTP persistence across transaction sets can now be
simplified using assign_http_state()

Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:23:51 +02:00
Lev Stipakov
83b02d87df
httpcli.hpp : fix PG build
Signed-off-by: Lev Stipakov <lev@openvpn.net>
2020-01-09 12:23:51 +02:00
James Yonan
caaf1529b9
JsonClient: fixed a bug in handling exceptions thrown by done()
Fixed a bug where exceptions thrown by done() method would
endlessly retry, ignoring the max_retries value.

Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:23:50 +02:00
James Yonan
fe4f62d925
httpcli: log pre-connect address info if debug_level >= 2
Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:23:50 +02:00
James Yonan
80f7206327
HTTP: added Alt Routing support to HTTP client/server
Alt Routing allows services on meshed PG nodes to communicate
with services on other nodes via the secure mesh, and without
requiring SSL.

Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:23:50 +02:00
James Yonan
8fd5e6b7da
httpcli: support Alt-Routing
Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:23:50 +02:00
James Yonan
94f471d7f8
httpcli: Initialize content_out_hold to true initially and then reset to false later on in the session.
Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:23:49 +02:00
James Yonan
01ef08b0e2
httpcli: added cancel_general_timeout.
Also: CoarseTimer must always be reset when its associated
AsioTimer is cancelled.

Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:23:49 +02:00
James Yonan
4aa8f0b54a
httpcli: added new methods:
a. is_link_active()
b. streaming_restart()
c. is_streaming_restartable()
d. is_streaming_hold()

Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:23:49 +02:00
James Yonan
19939c1927
HTTP layer: added Websocket support
Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:23:49 +02:00
James Yonan
5de6fb14fb
httpcli: support bind to local address.
Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:23:48 +02:00
James Yonan
e0734f990c
AsioTimer: use expires_after() method when possible.
A common AsioTimer usage pattern is:

  expires_at(Time::now() + duration)

This is more succinctly and efficiently stated as:

  expires_after(duration).

Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:23:48 +02:00
James Yonan
64022e8247
httpcli.hpp: when calling async_connect(), pass the results set using std::move().
Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:23:48 +02:00
James Yonan
25608597fc
Added i/o abstraction layer.
Created a lightweight abstraction layer so that another i/o
reactor can be dropped in place of asio.

This commit includes:

* Added ASIO=1 to many "go" scripts that require asio
* Renamed "asio::" to "openvpn_io::".

Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:23:48 +02:00
James Yonan
569b3d3afd
Moved asio files from openvpn/common to openvpn/asio
Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:23:47 +02:00
James Yonan
4460abd830
Moved openvpn::to_string() to separate source file.
Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:23:47 +02:00
James Yonan
388be07fdb
copyright: updated to 2017
Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:23:47 +02:00
James Yonan
8484f906cb
license : this branch (common) is proprietary, so remove all GPL headers.
Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:23:47 +02:00
James Yonan
71e825761c
mbedTLS: Port from polarssl-1.3 to mbedtls-2.3
This patch is mostly about polarssl -> mbedtls symbol renaming.
2020-01-09 12:23:46 +02:00
James Yonan
f0eb518b77
relay : added relay functionality and tests. 2020-01-09 12:23:46 +02:00
James Yonan
12866f4d0a
HTTP client : status argument to WS::Client::Status::error_str() should be an int because -1 is one of the possible values. 2020-01-09 12:23:46 +02:00
James Yonan
3b8a5595fb
copyright : updated to 2016 2020-01-09 12:23:46 +02:00
James Yonan
7059606bae
keepalive : added HTTPCore::is_keepalive_enabled() stub method to comply with TransportClientParent requirements. 2020-01-09 12:23:45 +02:00
James Yonan
2f56fb9fbd
httpcli.hpp : added Request::creds_defined() method. 2020-01-09 12:23:45 +02:00
James Yonan
d4cf3b75d7
First working OMI wrapper for OpenVPN 3 client. Tested with OpenVPN Connect on Mac.
Could benefit from some minor modifications to
python client backend and tray app:

* Client backend and ovpn3 both implement connection timeout.
  Client backend should defer to the ovpn3 implementation.

* Client backend and ovpn3 both implement DNS server config
  and SystemConfiguration event sent to
  'Setup:/Network/Global/IPv4' for 'VPN up'.
  Client backend should defer to the ovpn3 implementation.

* Ensure that system state changes (sleep, wakeup, network
  roam, fast user switching, etc.) don't cause conflicts
  between client backend and ovpn3 core both trying to
  implement similar functionality.

* Tray app should render error detail in >FATAL: messages.
  Right now tray raises a Disconnected notification but
  loses any error detail.
2020-01-09 12:23:45 +02:00
James Yonan
fee78ccfe4
In HTTP client and server, enable TCP_NODELAY on socket. 2020-01-09 12:23:45 +02:00
James Yonan
438ad6f4db
In WS::Client::Status::error_str(), handle cases where status == -1. Also, show the numerical status value for unknown errors. 2020-01-09 12:23:44 +02:00
James Yonan
3df9f988e3
Apparently Android NDK doesn't support std::to_string (WTF?), so work around it.
http://stackoverflow.com/questions/22774009/android-ndk-stdto-string-support
2020-01-09 12:23:44 +02:00
James Yonan
21ad74202e
In httpcli.hpp, need to rename E_ABORT to E_ABORTED to avoid a Windows symbol conflict. 2020-01-09 12:23:44 +02:00
James Yonan
a29b91760d
In HTTP client:
Added get_socket() method to WS::Client to return the
underlying HTTP AsioPolySock::Base object.

Added unix_fd() method to WS::ClientSet which depends on
get_socket() above and will return the fd of HTTP socket
if it's a unix domain socket.
2020-01-09 12:23:44 +02:00
James Yonan
3637c2976e
In httpcli.hpp, use C++11 member initialization in class ContentInfo. 2020-01-09 12:23:43 +02:00
James Yonan
eb6971b972
In HTTP client, added abort() method to both WS::Client and WS::ClientSet. 2020-01-09 12:23:43 +02:00
James Yonan
d3b5f1b186
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:43 +02:00
James Yonan
3175805174
In WS::Client::Config, use C++11 member initializers. 2020-01-09 12:23:43 +02:00
James Yonan
fa513773c0
In HTTP client, added http_post_connect() virtual callback method to allow user to verify server socket immediately after connect. This is useful when the server is local via a unix domain socket or windows named pipe.
In WS::ClientSet, exposed the callback as a std::function
in TransactionSet::post_connect.
2020-01-09 12:23:42 +02:00
James Yonan
56736bb90d
Minor simplification in HTTP client Windows-specific code for opening a named pipe. Use Win::LastError instead of asio::error_code... 2020-01-09 12:23:42 +02:00
James Yonan
fab921f714
Added Windows named pipe support to HTTP client/server library. 2020-01-09 12:23:42 +02:00
James Yonan
f811dfd42c
In HTTP client (httpcli.hpp):
* Added Request::set_creds() method.

* In HTTPCore, added a virtual destructor that calls stop().

* Added is_alive() method.

* In HTTPDelegate class template, detach() method now accepts
  a keepalive parameter.

* Added HTTPDelegate::attach() method.
2020-01-09 12:23:42 +02:00
James Yonan
dd5b4980ff
Asio async_wait lambdas should always check error status. 2020-01-09 12:23:41 +02:00
James Yonan
6b599f158c
In HTTP client/server, added msg_overhead_bytes member to Config class to allow for accounting of message overhead.
This is to prevent attacks where a large number of very
small messages (such as 1 byte each) are sent to the
server to force it to consume more memory than the
max_content_bytes limit would normally allow.
2020-01-09 12:23:41 +02:00
James Yonan
e49d4adae3
Added AGPL license header to HTTP, Java, and common code. 2020-01-09 12:23:41 +02:00
James Yonan
5087ea6a36
HTTP changes.
Both Client/Server side:

1. Support asynchronous sending of content via
   set_async_out() and http_content_out_finish()
   methods and http_content_out_needed() callback.

2. Added ContentInfo::extra_headers for caller-defined
   extra HTTP headers.

3. Made ContentInfo::CHUNKED into a constexpr
   type to match ContentInfo::length member var.

4. Set FD_CLOEXEC on socket.

5. Added remote_ip_port() method to allow remote IP
   address and port of socket to be obtained.

Client side:

1. In Host, added hint string to override transport host
   when a specific IP address should be used for host
   instead of resolving host via DNS.

2. Added Host::host_port_str() method.

3. Make general_timeout work like a true timeout, where
   traffic resets the timer (this is how server-side
   already works).

4. Added new method remote_endpoint_str() to match
   the same method on server-side.

5. Added new method host_hint() to return the current Host
   object, but set the hint/port fields to the live
   remote IP address/port of the connection.

6. Added new callback http_mutate_resolver_results() to
   allow user to modify the order of endpoint list returned
   by resolver.

Server side:

1. Make content_len_t into a 64-bit signed int since one
   of its possible values is -1 for CHUNKED.

2. Added ContentInfo::no_cache member var to trigger headers
   telling clients to not cache the content.

3. Added Factory::stop() virtual method for users to
   optionally override.

4. Made get_client_id() method public.

5. Fixed issue where code that allocates a client_id
   wasn't actually calling new_client_id().
2020-01-09 12:23:41 +02:00
James Yonan
30c4c2f37f
HTTP client/server -- now that socket is a smart pointer, make sure to check it is defined before calling close() method. 2020-01-09 12:23:40 +02:00
James Yonan
bbf84f1db1
In HTTP client/server stop() methods, do socket->close() instead of socket.reset(), as the latter may free the underlying socket while asio still holds dangling pointers to it. 2020-01-09 12:23:40 +02:00
James Yonan
10a0bfb6a7
Minor changes to httpcli.hpp:
* Check for empty DNS resolve results.
* Fix some debugging names passed to asio_error_handler,
  after functions were renamed for tcp vs. unix domain
  sockets.
2020-01-09 12:23:40 +02:00
James Yonan
135e2436bf
HTTP client/server changes:
* HTTP client and server now support unix domain sockets
  via AsioPolySock abstraction.

* HTTP server now supports Basic auth credentials.

* HTTP server now supports peercred authentication
  over unix domain sockets.

* HTTP server now supports file creation permission
  bits on unix domain socket.

* Added udstest tool to test HTTP client over unix domain
  sockets.
2020-01-09 12:23:40 +02:00
James Yonan
acfb70ab8a
Don't use deprecated asio features. 2020-01-09 12:23:40 +02:00
James Yonan
c0dcbae82f
Obsoleted asiodispatch in favor of C++11 lambdas. 2020-01-09 12:23:39 +02:00
James Yonan
ab72082bd4
Made protocol type a template parameter to TCPTransport::Link, so we can work with protocols other than TCP such as unix domain sockets. 2020-01-09 12:23:39 +02:00
James Yonan
12e4cfb4a4
Method signature changes for DCO (Data Channel Offload). 2020-01-09 12:23:39 +02:00
James Yonan
038b02fb2a
Boost dependency elimination -- final removal of Boost dependency. Asio is now included as a standalone, header-only dependency. 2020-01-09 12:23:39 +02:00
James Yonan
3ab7739fed
HTTP server:
* Fixed issue where HTTP server did not detect
  mid-session client disconnect.

* Implement parent_handoff (for proxies).

* Improved handling of residual content, allowing
  HTTP 1.1 pipelining to be supported.
2020-01-09 12:23:38 +02:00
James Yonan
8cabba1665
OPENVPN_HTTP_SERV_RC may be defined to override WS::Server::Listener::Client RC root class. 2020-01-09 12:23:38 +02:00
James Yonan
e608ee6db4
Renamed boost::intrusive_ptr<T> usage to RCPtr<T>. 2020-01-09 12:23:38 +02:00
James Yonan
686968992d
Moved array_size() function to its own header file. 2020-01-09 12:23:38 +02:00
James Yonan
47ffbe7401
C++11 : rename NULL to nullptr 2020-01-09 12:23:37 +02:00
James Yonan
8dbf685a25
Extended WS::Client to allow the use of any OpenVPN client transport driver for the HTTP/S transport layer. This enables use of HTTP CONNECT and OBFS proxy drivers. To enable, set the WS::Client::Config::transcli member to any TransportClientFactory instance. 2020-01-09 12:23:37 +02:00
James Yonan
c5d3fdad87
Added pgproxy, an HTTP proxy supporting both CONNECT and OBFS. 2020-01-09 12:23:37 +02:00
James Yonan
84b234b68b
Refactored web services classes (openvpn/ws) to support HTTP/S servers. 2020-01-09 12:23:37 +02:00
James Yonan
16a69d0325
In HTTPCore (httpcli.hpp), factor out code into httpcommon.hpp that is common to both HTTP clients and servers, so upcoming HTTP server implementation can leverage on the same code currently used by the client. 2020-01-09 12:23:36 +02:00
James Yonan
80c63cd93e
Refactored WS::Client status codes from WS::Client::E_x to WS::Client::Status::E_x. 2020-01-09 12:23:36 +02:00
James Yonan
1aebd88dc7
Factored out web services get_content_length() method into openvpn/ws/httpcommon.hpp which is intended for code that is common between HTTP clients and servers. 2020-01-09 12:23:36 +02:00
James Yonan
45b5d3bf69
Refactored WS::HTTPCore::ChunkedHelper into its own source file in preparation for HTTP server implementation. 2020-01-09 12:23:36 +02:00
James Yonan
937082b80d
Added minimal Content-Encoding support to HTTP client. 2020-01-09 12:23:35 +02:00
James Yonan
5d2a05cf8e
In HTTP client, added the ability to separately specify:
* hostname for TCP transport
* hostname for CN verification
* hostname sent as HTTP Host header
2020-01-09 12:23:35 +02:00
James Yonan
3175a9c9dd
Extended WS::Client:
* Added WS::Client:error_str() for formatting
  error codes.

* Added reset() method.

* When calling start_request(), set ready=false immediately
  to avoid race.

* Added http_headers_sent() and http_keepalive_close()
  callbacks.

* Added HTTPDelegate class.
2020-01-09 12:23:35 +02:00
James Yonan
93f10d74e2
Updated web services client classes to use SSLConfigAPI, and to support PolarSSL or OpenSSL. 2020-01-09 12:23:35 +02:00
James Yonan
51fbf93a93
Updated copyright to 2015. 2020-01-09 12:23:34 +02:00
James Yonan
9b0dbba02c
Remove AGPL licensing for openvpn/ws, as these sources will be left proprietary for now. 2020-01-09 12:23:34 +02:00
James Yonan
82012b7e66
Added some comments (overview) to openvpn/ws/httpcli.hpp. 2020-01-09 12:23:34 +02:00
James Yonan
9df14bb61f
Added web services client. 2020-01-09 12:23:34 +02:00
James Yonan
075143f23f
copyright: updated to 2017
Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:23:33 +02:00
James Yonan
5ab2e44e25
license : this branch (common) is proprietary, so remove all GPL headers.
Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:23:33 +02:00
James Yonan
0c46a7a7ec
copyright : updated to 2016 2020-01-09 12:23:33 +02:00
James Yonan
f6f40e24cd
Added AGPL license header to HTTP, Java, and common code. 2020-01-09 12:23:33 +02:00
James Yonan
1c8052be45
Renamed types.hpp to size.hpp since it now only defines size_t and ssize_t. 2020-01-09 12:23:33 +02:00
James Yonan
7194db16c2
In HTTPCore (httpcli.hpp), factor out code into httpcommon.hpp that is common to both HTTP clients and servers, so upcoming HTTP server implementation can leverage on the same code currently used by the client. 2020-01-09 12:23:32 +02:00
James Yonan
06fa9d2f21
Refactored WS::HTTPCore::ChunkedHelper into its own source file in preparation for HTTP server implementation. 2020-01-09 12:23:32 +02:00