25#define OPENVPN_CLIENT_EXPORT
26#ifndef OPENVPN_CORE_API_VISIBILITY_HIDDEN
27#pragma GCC visibility push(default)
30#ifndef OPENVPN_CORE_API_VISIBILITY_HIDDEN
31#pragma GCC visibility pop
35#define OPENVPN_CLIENT_EXPORT
43#define OPENVPN_DEBUG_PROTO 1
46#define OPENVPN_DEBUG_TUN 2
47#define OPENVPN_DEBUG_UDPLINK 2
48#define OPENVPN_DEBUG_TCPLINK 2
49#define OPENVPN_DEBUG_COMPRESS 1
50#define OPENVPN_DEBUG_REMOTELIST 0
51#define OPENVPN_DEBUG_TUN_BUILDER 0
66#define OPENVPN_LOG_CLASS openvpn::ClientAPI::LogReceiver
67#define OPENVPN_LOG_INFO openvpn::ClientAPI::LogInfo
74#if (defined(OPENVPN_PLATFORM_ANDROID) || defined(OPENVPN_PLATFORM_IPHONE)) && !defined(OPENVPN_FORCE_TUN_NULL) && !defined(OPENVPN_EXTERNAL_TUN_FACTORY)
75#define USE_TUN_BUILDER
109#ifdef OPENVPN_DEBUG_VERBOSE_ERRORS
160 void error(
const size_t err,
const std::string *text =
nullptr)
override
164#ifdef OPENVPN_DEBUG_VERBOSE_ERRORS
204 ev.
name =
event->name();
205 ev.
info =
event->render();
206 ev.
error =
event->is_error();
207 ev.
fatal =
event->is_fatal();
279#if defined(OPENVPN_COMMAND_AGENT) && defined(OPENVPN_PLATFORM_WIN)
281#elif defined(OPENVPN_COMMAND_AGENT) && defined(OPENVPN_PLATFORM_MAC)
348 const std::string title =
"remote-override";
354 catch (
const std::exception &e)
359 if (ro.
error.empty())
367 ri->server_host = std::move(ro.
host);
368 ri->server_port = std::move(ro.
port);
388 const unsigned int ms)
408 timer.async_wait([
this](
const openvpn_io::error_code &error)
450#ifdef OPENVPN_GREMLIN
456 template <
typename SESSION_STATS,
typename CLIENT_EVENTS>
463 throw Exception(
"ClientState::attach() can only be called once per ClientState instantiation");
510 stats->detach_from_parent();
512 events->detach_from_parent();
595#ifndef OPENVPN_NORESET_TIME
611 if (!
config.protoOverride.empty())
615 if (!
config.allowUnusedAddrFamilies.empty())
620 kvl.reserve(
config.contentList.size());
621 for (
size_t i = 0; i <
config.contentList.size(); ++i)
630#ifdef OPENVPN_DUMP_CONFIG
631 std::cout <<
"---------- ARGS ----------" << std::endl;
633 std::cout <<
"---------- MAP ----------" << std::endl;
634 std::cout << options.
render_map() << std::endl;
652 for (ParseClientConfig::ServerList::const_iterator i = cc.
serverList().begin(); i != cc.
serverList().end(); ++i)
660 catch (
const std::exception &e)
663 eval.
message = Unicode::utf8_printable<std::string>(std::string(
"ERR_PROFILE_GENERIC: ") + e.what(), 256);
673 if (!
config.compressionMode.empty())
679 if (!
config.gremlinConfig.empty())
681#ifdef OPENVPN_GREMLIN
684 throw Exception(
"client not built with OPENVPN_GREMLIN");
688 if (!
config.proxyHost.empty())
691 ho->set_proxy_server(
config.proxyHost,
config.proxyPort);
692 ho->username =
config.proxyUsername;
693 ho->password =
config.proxyPassword;
694 ho->allow_cleartext_auth =
config.proxyAllowCleartextAuth;
698 catch (
const std::exception &e)
701 eval.
message = Unicode::utf8_printable<std::string>(e.what(), 256);
706 : init(new InitProcess::Init())
721 bool follow_references)
797 catch (
const std::exception &e)
800 ret.message = Unicode::utf8_printable<std::string>(e.what(), 256);
821 catch (
const std::exception &)
830 if (!req.
cert.empty())
863#if !defined(OPENVPN_OVPNCLI_SINGLE_THREAD)
864 openvpn_io::detail::signal_blocker signal_blocker;
866#if defined(OPENVPN_LOG_LOGTHREAD_H) && !defined(OPENVPN_LOG_LOGBASE_H)
867#ifdef OPENVPN_LOG_GLOBAL
868#error ovpn3 core logging object only supports thread-local scope
881 bool session_started =
false;
885#if defined(OPENVPN_OVPNCLI_ASYNC_SETUP)
887 { do_connect_async(); });
894 catch (
const std::exception &e)
910 StopType stop_type = NONE;
912 bool session_started =
false;
917 catch (
const std::exception &e)
919 stop_type = session_started ? SESSION : EXPLICIT;
927 if (stop_type == SESSION)
929#ifdef OPENVPN_IO_REQUIRES_STOP
930 if (stop_type == EXPLICIT)
938#if defined(USE_MBEDTLS) || defined(USE_MBEDTLS_APPLE_HYBRID)
956#if defined(USE_TUN_BUILDER)
959#if defined(OPENVPN_EXTERNAL_TUN_FACTORY)
960 cc.extern_tun_factory =
this;
962#if defined(OPENVPN_EXTERNAL_TRANSPORT_FACTORY)
963 cc.extern_transport_factory =
this;
967#if !defined(USE_APPLE_SSL)
989 status.
message =
"Missing External PKI alias";
999 "Always verified correctly with OpenSSL",
1023 session_started =
true;
1123 const std::string &data,
1125 const std::string &algorithm,
1126 const std::string &hashalg,
1127 const std::string &saltlen)
1184 std::vector<long long> sv;
1192 for (
size_t i = 0; i < n; ++i)
1197 for (
size_t i = 0; i < n; ++i)
1257 const Time::Duration dur =
Time::now() - lpr;
1258 const unsigned int delta = (
unsigned int)dur.to_binary_ms();
1259 if (delta <= 60 * 60 * 24 * 1024)
1260 ret.lastPacketReceived = delta;
1331 const std::string &extra_certs,
1332 const std::optional<const std::string> &ca)
1334 SSLLib::SSLAPI::Config::Ptr
config =
new SSLLib::SSLAPI::Config;
1337 config->load_cert(client_cert, extra_certs);
1341 config->load_ca(*ca,
false);
1351 const std::string &clientkey,
1352 const std::optional<const std::string> &ca)
1360 config->load_private_key(clientkey);
1386 config->set_external_pki_callback(
this, alias);
1410 return openvpn_copyright;
1416#ifdef PRIVATE_TUNNEL_PROXY
1421#elif defined(ENABLE_OVPNDCO) || defined(ENABLE_OVPNDCOWIN)
1424#ifdef OPENVPN_GREMLIN
1428 ret +=
" built on " __DATE__
" " __TIME__;
#define OPENVPN_ASYNC_HANDLER
void error(const size_t err_type, const std::string *text=nullptr) override
std::size_t expires_after(const Time::Duration &d)
const std::string & get_state_id() const
bool get_response_required() const
const std::string & get_challenge_text() const
void get_connection_info(ConnectionInfo &ci)
RCPtr< MyClientEvents > Ptr
void add_event(ClientEvent::Base::Ptr event) override
void detach_from_parent()
ClientEvent::Base::Ptr last_connected
MyClientEvents(OpenVPNClient *parent_arg)
void detach_from_parent()
MyClockTick(openvpn_io::io_context &io_context, OpenVPNClient *parent_arg, const unsigned int ms)
const Time::Duration period
void detach_from_parent()
bool pause_on_connection_timeout() override
void set_parent(OpenVPNClient *parent_arg)
void set_parent(OpenVPNClient *parent_arg)
void detach_from_parent()
RemoteList::Item::Ptr get() override
count_t errors[Error::N_ERRORS]
void error(const size_t err, const std::string *text=nullptr) override
MySessionStats(OpenVPNClient *parent_arg)
count_t error_count(const size_t index) const
void detach_from_parent()
count_t combined_value(const size_t index) const
RCPtr< MySessionStats > Ptr
static std::string combined_name(const size_t index)
count_t stat_count(const size_t index) const
static size_t combined_n()
bool socket_protect(openvpn_io::detail::socket_type socket, IP::Addr endpoint) override
void detach_from_parent()
void set_rg_local(bool rg_local_arg)
void set_parent(OpenVPNClient *parent_arg)
static std::string copyright()
std::string crypto_self_test()
EvalConfig eval_config(const Config &config)
MergeConfig merge_config(const std::string &path, bool follow_references)
static std::string platform()
static void parse_config(const Config &, EvalConfig &, OptionList &)
static long max_profile_size()
static bool parse_dynamic_challenge(const std::string &cookie, DynamicChallenge &dc)
MergeConfig merge_config_string(const std::string &config_content)
static MergeConfig build_merge_config(const ProfileMerge &)
virtual void clock_tick()
void send_app_control_channel_msg(const std::string &protocol, const std::string &msg)
void external_pki_error(const ExternalPKIRequestBase &, const size_t)
virtual void external_pki_sign_request(ExternalPKISignRequest &)=0
TransportStats transport_stats() const
void post_cc_msg(const std::string &msg)
virtual void event(const Event &)=0
void start_cert_check_epki(const std::string &alias, const std::optional< const std::string > &ca)
Start up the cert check handshake using the given epki_alias string.
bool session_token(SessionToken &tok)
static Status status_from_exception(const std::exception &)
virtual void remote_override(RemoteOverride &)
InterfaceStats tun_stats() const
std::vector< long long > stats_bundle() const
virtual Stop * get_async_stop()
void start_cert_check(const std::string &client_cert, const std::string &clientkey, const std::optional< const std::string > &ca=std::nullopt)
Start up the cert check handshake using the given certs and key.
void process_epki_cert_chain(const ExternalPKICertRequest &)
virtual void connect_attach()
ConnectionInfo connection_info()
virtual bool remote_override_enabled()
virtual void connect_pre_run()
Status provide_creds(const ProvideCreds &)
static std::string stats_name(int index)
virtual bool pause_on_connection_timeout()=0
void connect_setup(Status &, bool &)
virtual void connect_run()
long long stats_value(int index) const
virtual void connect_session_stop()
virtual void external_pki_cert_request(ExternalPKICertRequest &)=0
virtual bool socket_protect(openvpn_io::detail::socket_type socket, std::string remote, bool ipv6)
Private::ClientState * state
void pause(const std::string &reason)
EvalConfig eval_config(const Config &)
bool sign(const std::string &alias, const std::string &data, std::string &sig, const std::string &algorithm, const std::string &hashalg, const std::string &saltlen) override
void reconnect(int seconds)
virtual void acc_event(const AppCustomControlMessageEvent &)=0
void parse_extras(const Config &, EvalConfig &)
std::unique_ptr< AsioStopScope > stop_scope_global
bool is_foreign_thread_access()
ProtoContextCompressionOptions::Ptr proto_context_options
HTTPProxyTransport::Options::Ptr http_proxy_options
void attach(OpenVPNClient *parent, openvpn_io::io_context *io_context, Stop *async_stop_global)
Stop * async_stop_local()
ClientState & operator=(const ClientState &)=delete
MySessionStats::Ptr stats
std::unique_ptr< AsioStopScope > stop_scope_local
void enable_foreign_thread_access()
PeerInfo::Set::Ptr extra_peer_info
openvpn_io::io_context * io_context_
openvpn_io::io_context * io_context()
Stop * async_stop_global_
ClientState(const ClientState &)=delete
MySocketProtect socket_protect
std::unique_ptr< MyClockTick > clock_tick
MyReconnectNotify reconnect_notify
void setup_async_stop_scopes()
void trigger_async_stop_local()
ClientConfigParsed clientconf
MyClientEvents::Ptr events
ClientConnect::Ptr session
std::atomic< bool > foreign_thread_ready
MyRemoteOverride remote_override
Stop * async_stop_global()
void thread_safe_resume()
void thread_safe_post_cc_msg(std::string msg)
void thread_safe_reconnect(int seconds)
void start_acc_certcheck(ArgsT &&...args)
Passes the given arguments through to start_acc_certcheck.
void thread_safe_pause(const std::string &reason)
void thread_safe_send_app_control_channel_msg(std::string protocol, std::string msg)
void set_http_proxy_username(const std::string &username)
void set_dynamic_challenge_cookie(const std::string &cookie, const std::string &username)
std::string get_password() const
void set_username(const std::string &username_arg)
void set_http_proxy_password(const std::string &password)
std::string get_username() const
void set_response(const std::string &response_arg)
bool session_id_defined() const
void set_password(const std::string &password_arg)
void save_username_for_session_id()
static std::tuple< bool, std::string > check_dco_compatibility(const ClientAPI::ConfigCommon &config, const OptionList &opt)
void submit_creds(const ClientCreds::Ptr &creds_arg)
bool code_defined() const
std::string to_string() const
std::string render_map() const
void add_item(const Option &opt)
std::string render(const unsigned int flags) const
bool exists(const std::string &name) const
void push_back(const std::string &item)
static ParseClientConfig parse(const std::string &content)
bool allowPasswordSave() const
const std::string & windowsDriver() const
const std::string & profileName() const
const std::string & friendlyName() const
bool staticChallengeEcho() const
const RemoteItem & firstRemoteListItem() const
std::string vpnCa() const
const std::string & staticChallenge() const
const std::string & message() const
const std::string & userlockedUsername() const
const ServerList & serverList() const
bool privateKeyPasswordRequired() const
const std::string & basename() const
const std::string & error() const
const char * status_string() const
const std::string & profile_content() const
const std::vector< std::string > & ref_path_list() const
static Protocol parse(const std::string &str, const AllowSuffix allow_suffix, const char *title=nullptr)
void reset() noexcept
Points this RCPtr<T> to nullptr safely.
T * get() const noexcept
Returns the raw pointer to the object T, or nullptr.
@ LF_ALLOW_CLIENT_CERT_NOT_REQUIRED
count_t get_stat_fast(const size_t type) const
const Time & last_packet_received() const
void session_stats_set_verbose(const bool v)
static const char * stat_name(const size_t type)
count_t get_stat(const size_t type) const
static void reset_base_conditional()
static TriStateSetting parse(const std::string &str)
static bool add_bypass_route(IP::Addr endpoint)
static bool add_bypass_route(IP::Addr endpoint)
#define OPENVPN_SIMPLE_EXCEPTION(C)
#define OPENVPN_LOG(args)
static SSLLib::SSLAPI::Config::Ptr setup_certcheck_ssl_config(const std::string &client_cert, const std::string &extra_certs, const std::optional< const std::string > &ca)
const char * name(const size_t type)
void validate_host(const std::string &host, const std::string &title)
void validate_port(const std::string &port, const std::string &title, unsigned int *value=nullptr)
std::string crypto_self_test()
Support deferred server-side state creation when client connects.
std::string platform_string()
#define OPENVPN_CLIENT_EXPORT
Struct containing configuration details parsed from an OpenVPN configuration file.
std::vector< ServerEntry > serverList
std::string dcoIncompatibilityReason
std::string userlockedUsername
bool privateKeyPasswordRequired
std::string staticChallenge
std::string windowsDriver
std::string supportingChain
std::string http_proxy_pass
std::string http_proxy_user
std::string dynamicChallengeCookie
std::string external_pki_alias
void import_client_settings(const ClientAPI::Config &config)
std::string custommessage
ReconnectNotify * reconnect_notify
ClientEvent::Queue::Ptr cli_events
ClientConfigParsed clientconf
PeerInfo::Set::Ptr extra_peer_info
RemoteList::RemoteOverride * remote_override
ExternalPKIBase * external_pki
SessionStats::Ptr cli_stats
ProtoContextCompressionOptions::Ptr proto_context_options
HTTPProxyTransport::Options::Ptr http_proxy_options
SocketProtect * socket_protect
Scoped RAII for the global_log pointer.
static Ptr new_from_foreign_set(const SET &other)
void parse_compression_mode(const std::string &mode)
static const char config[]