mirror of
https://github.com/chenx-dust/EZ4Connect.git
synced 2026-09-20 10:23:33 +08:00
chore: 让 easyconnect 专属的参数不给进去
This commit is contained in:
@@ -73,6 +73,7 @@ QString CoreCommand::loggableCommandLine() const
|
|||||||
CoreCommand CoreCommandBuilder::build(const ConnectionProfile &profile, const CoreRuntimePaths &runtimePaths)
|
CoreCommand CoreCommandBuilder::build(const ConnectionProfile &profile, const CoreRuntimePaths &runtimePaths)
|
||||||
{
|
{
|
||||||
QStringList arguments;
|
QStringList arguments;
|
||||||
|
QStringList credentials;
|
||||||
|
|
||||||
appendOption(arguments, "-protocol", profile.endpoint.protocol);
|
appendOption(arguments, "-protocol", profile.endpoint.protocol);
|
||||||
|
|
||||||
@@ -91,6 +92,24 @@ CoreCommand CoreCommandBuilder::build(const ConnectionProfile &profile, const Co
|
|||||||
arguments << "-update-best-nodes-interval" << QString::number(profile.behavior.updateBestNodesInterval);
|
arguments << "-update-best-nodes-interval" << QString::number(profile.behavior.updateBestNodesInterval);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (profile.endpoint.protocol == "easyconnect")
|
||||||
|
{
|
||||||
|
if (profile.behavior.disableMultiLine)
|
||||||
|
{
|
||||||
|
arguments << "-disable-multi-line";
|
||||||
|
}
|
||||||
|
if (profile.behavior.disableZjuConfig)
|
||||||
|
{
|
||||||
|
arguments << "-disable-zju-config";
|
||||||
|
}
|
||||||
|
if (profile.behavior.skipDomainResource)
|
||||||
|
{
|
||||||
|
arguments << "-skip-domain-resource";
|
||||||
|
}
|
||||||
|
appendOption(arguments, "-custom-proxy-domain", profile.proxy.customDomains);
|
||||||
|
appendOption(credentials, "-cert-file", profile.credentials.certFile);
|
||||||
|
appendOption(credentials, "-cert-password", profile.credentials.certPassword);
|
||||||
|
}
|
||||||
|
|
||||||
appendOption(arguments, "-server", profile.endpoint.server);
|
appendOption(arguments, "-server", profile.endpoint.server);
|
||||||
if (profile.endpoint.port != 0)
|
if (profile.endpoint.port != 0)
|
||||||
@@ -108,10 +127,6 @@ CoreCommand CoreCommandBuilder::build(const ConnectionProfile &profile, const Co
|
|||||||
}
|
}
|
||||||
appendOption(arguments, "-secondary-dns-server", profile.dns.secondary);
|
appendOption(arguments, "-secondary-dns-server", profile.dns.secondary);
|
||||||
|
|
||||||
if (profile.behavior.disableMultiLine)
|
|
||||||
{
|
|
||||||
arguments << "-disable-multi-line";
|
|
||||||
}
|
|
||||||
if (profile.behavior.disableKeepAlive)
|
if (profile.behavior.disableKeepAlive)
|
||||||
{
|
{
|
||||||
arguments << "-disable-keep-alive";
|
arguments << "-disable-keep-alive";
|
||||||
@@ -122,10 +137,6 @@ CoreCommand CoreCommandBuilder::build(const ConnectionProfile &profile, const Co
|
|||||||
{
|
{
|
||||||
arguments << "-auto-detect-interface";
|
arguments << "-auto-detect-interface";
|
||||||
}
|
}
|
||||||
if (profile.behavior.disableZjuConfig)
|
|
||||||
{
|
|
||||||
arguments << "-disable-zju-config";
|
|
||||||
}
|
|
||||||
if (profile.dns.disableZjuDns)
|
if (profile.dns.disableZjuDns)
|
||||||
{
|
{
|
||||||
arguments << "-disable-zju-dns";
|
arguments << "-disable-zju-dns";
|
||||||
@@ -138,11 +149,6 @@ CoreCommand CoreCommandBuilder::build(const ConnectionProfile &profile, const Co
|
|||||||
{
|
{
|
||||||
arguments << "-proxy-all";
|
arguments << "-proxy-all";
|
||||||
}
|
}
|
||||||
if (profile.behavior.skipDomainResource)
|
|
||||||
{
|
|
||||||
arguments << "-skip-domain-resource";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (profile.tunnel.tunMode)
|
if (profile.tunnel.tunMode)
|
||||||
{
|
{
|
||||||
arguments << "-tun-mode";
|
arguments << "-tun-mode";
|
||||||
@@ -171,7 +177,6 @@ CoreCommand CoreCommandBuilder::build(const ConnectionProfile &profile, const Co
|
|||||||
appendOption(arguments, "-tcp-port-forwarding", profile.tunnel.tcpPortForwarding);
|
appendOption(arguments, "-tcp-port-forwarding", profile.tunnel.tcpPortForwarding);
|
||||||
appendOption(arguments, "-udp-port-forwarding", profile.tunnel.udpPortForwarding);
|
appendOption(arguments, "-udp-port-forwarding", profile.tunnel.udpPortForwarding);
|
||||||
appendOption(arguments, "-custom-dns", profile.dns.custom);
|
appendOption(arguments, "-custom-dns", profile.dns.custom);
|
||||||
appendOption(arguments, "-custom-proxy-domain", profile.proxy.customDomains);
|
|
||||||
if (!profile.extraArguments.isEmpty())
|
if (!profile.extraArguments.isEmpty())
|
||||||
{
|
{
|
||||||
arguments.append(profile.extraArguments.split(" "));
|
arguments.append(profile.extraArguments.split(" "));
|
||||||
@@ -180,13 +185,10 @@ CoreCommand CoreCommandBuilder::build(const ConnectionProfile &profile, const Co
|
|||||||
CoreCommand command;
|
CoreCommand command;
|
||||||
command.loggableArguments = arguments;
|
command.loggableArguments = arguments;
|
||||||
|
|
||||||
QStringList credentials;
|
|
||||||
appendOption(credentials, "-username", profile.credentials.username);
|
appendOption(credentials, "-username", profile.credentials.username);
|
||||||
appendOption(credentials, "-password", profile.credentials.password);
|
appendOption(credentials, "-password", profile.credentials.password);
|
||||||
appendOption(credentials, "-totp-secret", profile.credentials.totpSecret);
|
appendOption(credentials, "-totp-secret", profile.credentials.totpSecret);
|
||||||
|
|
||||||
appendOption(arguments, "-cert-file", profile.credentials.certFile);
|
|
||||||
appendOption(arguments, "-cert-password", profile.credentials.certPassword);
|
|
||||||
command.arguments = credentials + arguments;
|
command.arguments = credentials + arguments;
|
||||||
return command;
|
return command;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,11 @@ void DeviceTrust::set(
|
|||||||
bool trusted
|
bool trusted
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
|
if (protocol != "atrust")
|
||||||
|
{
|
||||||
|
throw std::runtime_error("授信设备功能仅支持 aTrust");
|
||||||
|
}
|
||||||
|
|
||||||
QStringList arguments;
|
QStringList arguments;
|
||||||
if (!protocol.isEmpty())
|
if (!protocol.isEmpty())
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -215,7 +215,8 @@ void ZjuConnectProcess::start(const ConnectionProfile &profile)
|
|||||||
{
|
{
|
||||||
qInfo().noquote() << "使用了 TOTP";
|
qInfo().noquote() << "使用了 TOTP";
|
||||||
}
|
}
|
||||||
if (!profile.credentials.certFile.isEmpty())
|
if (profile.endpoint.protocol == "easyconnect"
|
||||||
|
&& !profile.credentials.certFile.isEmpty())
|
||||||
{
|
{
|
||||||
qInfo().noquote() << "使用了证书文件";
|
qInfo().noquote() << "使用了证书文件";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,8 +16,8 @@ ConnectionProfile SettingsProfileLoader::load(
|
|||||||
: "certificate"
|
: "certificate"
|
||||||
).toString();
|
).toString();
|
||||||
const bool useCertificate =
|
const bool useCertificate =
|
||||||
settings.value("ZJUConnect/Protocol").toString() != "easyconnect"
|
settings.value("ZJUConnect/Protocol").toString() == "easyconnect"
|
||||||
|| easyconnectAuthType == "certificate";
|
&& easyconnectAuthType == "certificate";
|
||||||
profile.credentials = {
|
profile.credentials = {
|
||||||
username,
|
username,
|
||||||
password,
|
password,
|
||||||
|
|||||||
@@ -89,16 +89,13 @@ bool buildsCompleteCommandInCompatibleOrder()
|
|||||||
"-zju-dns-server", "10.0.0.1",
|
"-zju-dns-server", "10.0.0.1",
|
||||||
"-dns-ttl", "60",
|
"-dns-ttl", "60",
|
||||||
"-secondary-dns-server", "10.0.0.2",
|
"-secondary-dns-server", "10.0.0.2",
|
||||||
"-disable-multi-line",
|
|
||||||
"-disable-keep-alive",
|
"-disable-keep-alive",
|
||||||
"-keep-alive-url", "https://keepalive",
|
"-keep-alive-url", "https://keepalive",
|
||||||
"-bind-interface", "en0",
|
"-bind-interface", "en0",
|
||||||
"-auto-detect-interface",
|
"-auto-detect-interface",
|
||||||
"-disable-zju-config",
|
|
||||||
"-disable-zju-dns",
|
"-disable-zju-dns",
|
||||||
"-disable-server-config",
|
"-disable-server-config",
|
||||||
"-proxy-all",
|
"-proxy-all",
|
||||||
"-skip-domain-resource",
|
|
||||||
"-tun-mode",
|
"-tun-mode",
|
||||||
"-dns-hijack",
|
"-dns-hijack",
|
||||||
"-fake-ip",
|
"-fake-ip",
|
||||||
@@ -111,14 +108,74 @@ bool buildsCompleteCommandInCompatibleOrder()
|
|||||||
"-tcp-port-forwarding", "127.0.0.1:80/10.0.0.1:80",
|
"-tcp-port-forwarding", "127.0.0.1:80/10.0.0.1:80",
|
||||||
"-udp-port-forwarding", "127.0.0.1:53/10.0.0.1:53",
|
"-udp-port-forwarding", "127.0.0.1:53/10.0.0.1:53",
|
||||||
"-custom-dns", "example.org=1.1.1.1",
|
"-custom-dns", "example.org=1.1.1.1",
|
||||||
"-custom-proxy-domain", "example.org",
|
"-foo", "bar"
|
||||||
"-foo", "bar",
|
|
||||||
"-cert-file", "/tmp/client.p12",
|
|
||||||
"-cert-password", "cert-secret"
|
|
||||||
};
|
};
|
||||||
return expectEqual(command.arguments, expected, "buildsCompleteCommandInCompatibleOrder");
|
return expectEqual(command.arguments, expected, "buildsCompleteCommandInCompatibleOrder");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool keepsEasyConnectOnlyOptionsOutOfATrustCommand()
|
||||||
|
{
|
||||||
|
ConnectionProfile profile;
|
||||||
|
profile.endpoint.protocol = "atrust";
|
||||||
|
profile.credentials.certFile = "/tmp/client.p12";
|
||||||
|
profile.credentials.certPassword = "cert-secret";
|
||||||
|
profile.proxy.customDomains = "example.org";
|
||||||
|
profile.behavior.disableMultiLine = true;
|
||||||
|
profile.behavior.disableZjuConfig = true;
|
||||||
|
profile.behavior.skipDomainResource = true;
|
||||||
|
|
||||||
|
const CoreCommand command = CoreCommandBuilder::build(profile);
|
||||||
|
return expectEqual(
|
||||||
|
command.arguments,
|
||||||
|
{"-protocol", "atrust"},
|
||||||
|
"keepsEasyConnectOnlyOptionsOutOfATrustCommand"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool addsEasyConnectOnlyOptionsForEasyConnect()
|
||||||
|
{
|
||||||
|
ConnectionProfile profile;
|
||||||
|
profile.endpoint.protocol = "easyconnect";
|
||||||
|
profile.credentials.username = "alice";
|
||||||
|
profile.credentials.certFile = "/tmp/client.p12";
|
||||||
|
profile.credentials.certPassword = "cert-secret";
|
||||||
|
profile.proxy.customDomains = "example.org";
|
||||||
|
profile.behavior.disableMultiLine = true;
|
||||||
|
profile.behavior.disableZjuConfig = true;
|
||||||
|
profile.behavior.skipDomainResource = true;
|
||||||
|
|
||||||
|
const CoreCommand command = CoreCommandBuilder::build(profile);
|
||||||
|
return expectEqual(
|
||||||
|
command.arguments,
|
||||||
|
{
|
||||||
|
"-cert-file", "/tmp/client.p12",
|
||||||
|
"-cert-password", "cert-secret",
|
||||||
|
"-username", "alice",
|
||||||
|
"-protocol", "easyconnect",
|
||||||
|
"-disable-multi-line",
|
||||||
|
"-disable-zju-config",
|
||||||
|
"-skip-domain-resource",
|
||||||
|
"-custom-proxy-domain", "example.org"
|
||||||
|
},
|
||||||
|
"addsEasyConnectOnlyOptionsForEasyConnect"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool keepsATrustOnlyOptionsOutOfEasyConnectCommand()
|
||||||
|
{
|
||||||
|
ConnectionProfile profile;
|
||||||
|
profile.endpoint = {"easyconnect", "cas", "domain", "86-123", QString(), 0};
|
||||||
|
profile.behavior.updateBestNodesInterval = 30;
|
||||||
|
|
||||||
|
const CoreRuntimePaths runtimePaths{QString(), "/tmp/structured-client-data.json"};
|
||||||
|
const CoreCommand command = CoreCommandBuilder::build(profile, runtimePaths);
|
||||||
|
return expectEqual(
|
||||||
|
command.arguments,
|
||||||
|
{"-protocol", "easyconnect"},
|
||||||
|
"keepsATrustOnlyOptionsOutOfEasyConnectCommand"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
bool excludesCredentialsFromLoggableArguments()
|
bool excludesCredentialsFromLoggableArguments()
|
||||||
{
|
{
|
||||||
ConnectionProfile profile;
|
ConnectionProfile profile;
|
||||||
@@ -171,6 +228,9 @@ int main(int argc, char *argv[])
|
|||||||
const bool passed = buildsMinimalCommand()
|
const bool passed = buildsMinimalCommand()
|
||||||
&& addsGraphCaptchaFileForEasyConnect()
|
&& addsGraphCaptchaFileForEasyConnect()
|
||||||
&& buildsCompleteCommandInCompatibleOrder()
|
&& buildsCompleteCommandInCompatibleOrder()
|
||||||
|
&& keepsEasyConnectOnlyOptionsOutOfATrustCommand()
|
||||||
|
&& addsEasyConnectOnlyOptionsForEasyConnect()
|
||||||
|
&& keepsATrustOnlyOptionsOutOfEasyConnectCommand()
|
||||||
&& excludesCredentialsFromLoggableArguments()
|
&& excludesCredentialsFromLoggableArguments()
|
||||||
&& quotesLoggableArgumentsWithoutChangingArguments();
|
&& quotesLoggableArgumentsWithoutChangingArguments();
|
||||||
return passed ? 0 : 1;
|
return passed ? 0 : 1;
|
||||||
|
|||||||
@@ -69,8 +69,8 @@ bool loadsSettingsIntoTypedProfile()
|
|||||||
&& profile.credentials.username == "alice"
|
&& profile.credentials.username == "alice"
|
||||||
&& profile.credentials.password == "secret"
|
&& profile.credentials.password == "secret"
|
||||||
&& profile.credentials.totpSecret == "totp"
|
&& profile.credentials.totpSecret == "totp"
|
||||||
&& profile.credentials.certFile == "/tmp/client.p12"
|
&& profile.credentials.certFile.isEmpty()
|
||||||
&& profile.credentials.certPassword == "cert-password"
|
&& profile.credentials.certPassword.isEmpty()
|
||||||
&& profile.endpoint.protocol == "atrust"
|
&& profile.endpoint.protocol == "atrust"
|
||||||
&& profile.endpoint.authType == "cas"
|
&& profile.endpoint.authType == "cas"
|
||||||
&& profile.endpoint.loginDomain == "domain"
|
&& profile.endpoint.loginDomain == "domain"
|
||||||
|
|||||||
Reference in New Issue
Block a user