mirror of
https://github.com/deneraraujo/OpenVPNAdapter.git
synced 2026-04-24 00:00:05 +08:00
Merge commit '84ad2a289f33a43dd71276cc494f337d0fbb3ed6' into feature/update-dependencies
This commit is contained in:
@@ -68,6 +68,10 @@
|
||||
#include <openvpn/ssl/peerinfo.hpp>
|
||||
#include <openvpn/ssl/sslchoose.hpp>
|
||||
|
||||
#ifdef OPENVPN_REMOTE_OVERRIDE
|
||||
#include <openvpn/common/process.hpp>
|
||||
#endif
|
||||
|
||||
#if defined(USE_MBEDTLS)
|
||||
#include <openvpn/mbedtls/util/pkcs1.hpp>
|
||||
#endif
|
||||
@@ -129,6 +133,13 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef OPENVPN_REMOTE_OVERRIDE
|
||||
void set_remote_override_cmd(const std::string& cmd)
|
||||
{
|
||||
remote_override_cmd = cmd;
|
||||
}
|
||||
#endif
|
||||
|
||||
private:
|
||||
virtual bool socket_protect(int socket) override
|
||||
{
|
||||
@@ -304,10 +315,51 @@ private:
|
||||
return false;
|
||||
}
|
||||
|
||||
#ifdef OPENVPN_REMOTE_OVERRIDE
|
||||
virtual bool remote_override_enabled() override
|
||||
{
|
||||
return !remote_override_cmd.empty();
|
||||
}
|
||||
|
||||
virtual void remote_override(ClientAPI::RemoteOverride& ro)
|
||||
{
|
||||
RedirectPipe::InOut pio;
|
||||
Argv argv;
|
||||
argv.emplace_back(remote_override_cmd);
|
||||
OPENVPN_LOG(argv.to_string());
|
||||
const int status = system_cmd(remote_override_cmd,
|
||||
argv,
|
||||
nullptr,
|
||||
pio,
|
||||
RedirectPipe::IGNORE_ERR);
|
||||
if (!status)
|
||||
{
|
||||
const std::string out = string::first_line(pio.out);
|
||||
OPENVPN_LOG("REMOTE OVERRIDE: " << out);
|
||||
auto svec = string::split(out, ',');
|
||||
if (svec.size() == 4)
|
||||
{
|
||||
ro.host = svec[0];
|
||||
ro.ip = svec[1];
|
||||
ro.port = svec[2];
|
||||
ro.proto = svec[3];
|
||||
}
|
||||
else
|
||||
ro.error = "cannot parse remote-override, expecting host,ip,port,proto (at least one or both of host and ip must be defined)";
|
||||
}
|
||||
else
|
||||
ro.error = "status=" + std::to_string(status);
|
||||
}
|
||||
#endif
|
||||
|
||||
std::mutex log_mutex;
|
||||
std::string dc_cookie;
|
||||
RandomAPI::Ptr rng; // random data source for epki
|
||||
volatile ClockTickAction clock_tick_action = CT_UNDEF;
|
||||
|
||||
#ifdef OPENVPN_REMOTE_OVERRIDE
|
||||
std::string remote_override_cmd;
|
||||
#endif
|
||||
};
|
||||
|
||||
static Client *the_client = nullptr; // GLOBAL
|
||||
@@ -543,11 +595,15 @@ int openvpn_client(int argc, char *argv[], const std::string* profile_content)
|
||||
{ "merge", no_argument, nullptr, 'm' },
|
||||
{ "version", no_argument, nullptr, 'v' },
|
||||
{ "auto-sess", no_argument, nullptr, 'a' },
|
||||
{ "auth-retry", no_argument, nullptr, 'Y' },
|
||||
{ "tcprof-override", required_argument, nullptr, 'X' },
|
||||
{ "ssl-debug", required_argument, nullptr, 1 },
|
||||
{ "epki-cert", required_argument, nullptr, 2 },
|
||||
{ "epki-ca", required_argument, nullptr, 3 },
|
||||
{ "epki-key", required_argument, nullptr, 4 },
|
||||
#ifdef OPENVPN_REMOTE_OVERRIDE
|
||||
{ "remote-override",required_argument, nullptr, 5 },
|
||||
#endif
|
||||
{ nullptr, 0, nullptr, 0 }
|
||||
};
|
||||
|
||||
@@ -588,6 +644,7 @@ int openvpn_client(int argc, char *argv[], const std::string* profile_content)
|
||||
int sslDebugLevel = 0;
|
||||
bool googleDnsFallback = false;
|
||||
bool autologinSessions = false;
|
||||
bool retryOnAuthFailed = false;
|
||||
bool tunPersist = false;
|
||||
bool merge = false;
|
||||
bool version = false;
|
||||
@@ -596,10 +653,13 @@ int openvpn_client(int argc, char *argv[], const std::string* profile_content)
|
||||
std::string epki_cert_fn;
|
||||
std::string epki_ca_fn;
|
||||
std::string epki_key_fn;
|
||||
#ifdef OPENVPN_REMOTE_OVERRIDE
|
||||
std::string remote_override_cmd;
|
||||
#endif
|
||||
|
||||
int ch;
|
||||
optind = 1;
|
||||
while ((ch = getopt_long(argc, argv, "BAdeTCxfgjmvau:p:r:D:P:6:s:t:c:z:M:h:q:U:W:I:G:k:X:R:", longopts, nullptr)) != -1)
|
||||
while ((ch = getopt_long(argc, argv, "BAdeTCxfgjmvaYu:p:r:D:P:6:s:t:c:z:M:h:q:U:W:I:G:k:X:R:", longopts, nullptr)) != -1)
|
||||
{
|
||||
switch (ch)
|
||||
{
|
||||
@@ -615,6 +675,11 @@ int openvpn_client(int argc, char *argv[], const std::string* profile_content)
|
||||
case 4: // --epki-key
|
||||
epki_key_fn = optarg;
|
||||
break;
|
||||
#ifdef OPENVPN_REMOTE_OVERRIDE
|
||||
case 5: // --remote-override
|
||||
remote_override_cmd = optarg;
|
||||
break;
|
||||
#endif
|
||||
case 'e':
|
||||
eval = true;
|
||||
break;
|
||||
@@ -693,6 +758,9 @@ int openvpn_client(int argc, char *argv[], const std::string* profile_content)
|
||||
case 'a':
|
||||
autologinSessions = true;
|
||||
break;
|
||||
case 'Y':
|
||||
retryOnAuthFailed = true;
|
||||
break;
|
||||
case 'j':
|
||||
tunPersist = true;
|
||||
break;
|
||||
@@ -786,6 +854,7 @@ int openvpn_client(int argc, char *argv[], const std::string* profile_content)
|
||||
config.sslDebugLevel = sslDebugLevel;
|
||||
config.googleDnsFallback = googleDnsFallback;
|
||||
config.autologinSessions = autologinSessions;
|
||||
config.retryOnAuthFailed = retryOnAuthFailed;
|
||||
config.tunPersist = tunPersist;
|
||||
config.gremlinConfig = gremlin;
|
||||
config.info = true;
|
||||
@@ -798,9 +867,25 @@ int openvpn_client(int argc, char *argv[], const std::string* profile_content)
|
||||
|
||||
PeerInfo::Set::parse_csv(peer_info, config.peerInfo);
|
||||
|
||||
// allow -s server override to reference a friendly name
|
||||
// in the config.
|
||||
// setenv SERVER <HOST>/<FRIENDLY_NAME>
|
||||
if (!config.serverOverride.empty())
|
||||
{
|
||||
const ClientAPI::EvalConfig eval = ClientAPI::OpenVPNClient::eval_config_static(config);
|
||||
for (auto &se : eval.serverList)
|
||||
{
|
||||
if (config.serverOverride == se.friendlyName)
|
||||
{
|
||||
config.serverOverride = se.server;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (eval)
|
||||
{
|
||||
ClientAPI::EvalConfig eval = ClientAPI::OpenVPNClient::eval_config_static(config);
|
||||
const ClientAPI::EvalConfig eval = ClientAPI::OpenVPNClient::eval_config_static(config);
|
||||
std::cout << "EVAL PROFILE" << std::endl;
|
||||
std::cout << "error=" << eval.error << std::endl;
|
||||
std::cout << "message=" << eval.message << std::endl;
|
||||
@@ -814,6 +899,9 @@ int openvpn_client(int argc, char *argv[], const std::string* profile_content)
|
||||
std::cout << "privateKeyPasswordRequired=" << eval.privateKeyPasswordRequired << std::endl;
|
||||
std::cout << "allowPasswordSave=" << eval.allowPasswordSave << std::endl;
|
||||
|
||||
if (!config.serverOverride.empty())
|
||||
std::cout << "server=" << config.serverOverride << std::endl;
|
||||
|
||||
for (size_t i = 0; i < eval.serverList.size(); ++i)
|
||||
{
|
||||
const ClientAPI::ServerEntry& se = eval.serverList[i];
|
||||
@@ -823,7 +911,7 @@ int openvpn_client(int argc, char *argv[], const std::string* profile_content)
|
||||
else
|
||||
{
|
||||
Client client;
|
||||
ClientAPI::EvalConfig eval = client.eval_config(config);
|
||||
const ClientAPI::EvalConfig eval = client.eval_config(config);
|
||||
if (eval.error)
|
||||
OPENVPN_THROW_EXCEPTION("eval config error: " << eval.message);
|
||||
if (eval.autologin)
|
||||
@@ -866,6 +954,10 @@ int openvpn_client(int argc, char *argv[], const std::string* profile_content)
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef OPENVPN_REMOTE_OVERRIDE
|
||||
client.set_remote_override_cmd(remote_override_cmd);
|
||||
#endif
|
||||
|
||||
std::cout << "CONNECTING..." << std::endl;
|
||||
|
||||
// start the client thread
|
||||
@@ -908,6 +1000,9 @@ int openvpn_client(int argc, char *argv[], const std::string* profile_content)
|
||||
std::cout << "--proto, -P : protocol override (udp|tcp)" << std::endl;
|
||||
std::cout << "--server, -s : server override" << std::endl;
|
||||
std::cout << "--port, -R : port override" << std::endl;
|
||||
#ifdef OPENVPN_REMOTE_OVERRIDE
|
||||
std::cout << "--remote-override : command to run to generate next remote (returning host,ip,port,proto)" << std::endl;
|
||||
#endif
|
||||
std::cout << "--ipv6, -6 : IPv6 (yes|no|default)" << std::endl;
|
||||
std::cout << "--timeout, -t : timeout" << std::endl;
|
||||
std::cout << "--compress, -c : compression mode (yes|no|asym)" << std::endl;
|
||||
@@ -932,6 +1027,7 @@ int openvpn_client(int argc, char *argv[], const std::string* profile_content)
|
||||
std::cout << "--ssl-debug : SSL debug level" << std::endl;
|
||||
std::cout << "--google-dns, -g : enable Google DNS fallback" << std::endl;
|
||||
std::cout << "--auto-sess, -a : request autologin session" << std::endl;
|
||||
std::cout << "--auth-retry, -Y : retry connection on auth failure" << std::endl;
|
||||
std::cout << "--persist-tun, -j : keep TUN interface open across reconnects" << std::endl;
|
||||
std::cout << "--peer-info, -I : peer info key/value list in the form K1=V1,K2=V2,..." << std::endl;
|
||||
std::cout << "--gremlin, -G : gremlin info (send_delay_ms, recv_delay_ms, send_drop_prob, recv_drop_prob)" << std::endl;
|
||||
|
||||
@@ -6,6 +6,7 @@ GCC_EXTRA="$GCC_EXTRA -DOPENVPN_SHOW_SESSION_TOKEN"
|
||||
[ "$GREMLIN" = "1" ] && GCC_EXTRA="$GCC_EXTRA -DOPENVPN_GREMLIN"
|
||||
[ "$DEX" = "1" ] && GCC_EXTRA="$GCC_EXTRA -DOPENVPN_DISABLE_EXPLICIT_EXIT"
|
||||
[ "$BS64" = "1" ] && GCC_EXTRA="$GCC_EXTRA -DOPENVPN_BS64_DATA_LIMIT=2500000"
|
||||
[ "$ROVER" = "1" ] && GCC_EXTRA="$GCC_EXTRA -DOPENVPN_REMOTE_OVERRIDE"
|
||||
if [ "$AGENT" = "1" ]; then
|
||||
GCC_EXTRA="$GCC_EXTRA -DOPENVPN_COMMAND_AGENT"
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user