refactor: move tls-cert to coreArgs
This commit is contained in:
committed by
Chris Rizzitello
parent
ff4c9dc421
commit
a8348b1ccb
@ -130,8 +130,7 @@ private:
|
||||
#endif
|
||||
constexpr static auto s_helpGeneralArgs = //
|
||||
" -1, --no-restart do not try to restart on failure.\n"
|
||||
"* --restart restart the server automatically if it fails.\n"
|
||||
" --tls-cert specify the path to the TLS certificate file.\n";
|
||||
"* --restart restart the server automatically if it fails.\n";
|
||||
|
||||
constexpr static auto s_helpVersionArgs = //
|
||||
" -h, --help display this help and exit.\n";
|
||||
|
||||
@ -139,8 +139,6 @@ bool ArgParser::parseGenericArgs(int argc, const char *const *argv, int &i) cons
|
||||
// HACK: stop error happening when using portable (deskflowp)
|
||||
} else if (isArg(i, argc, argv, nullptr, "--client")) {
|
||||
// HACK: stop error happening when using portable (deskflowp)
|
||||
} else if (isArg(i, argc, argv, nullptr, "--tls-cert", 1)) {
|
||||
argsBase().m_tlsCertFile = argv[++i];
|
||||
} else if (isArg(i, argc, argv, nullptr, "--prevent-sleep")) {
|
||||
argsBase().m_preventSleep = true;
|
||||
} else {
|
||||
|
||||
@ -50,9 +50,6 @@ public:
|
||||
/// @brief Will cause the application to exit with fail code when set to true
|
||||
bool m_shouldExitFail = false;
|
||||
|
||||
/// @brief Contains the location of the TLS certificate file
|
||||
std::string m_tlsCertFile;
|
||||
|
||||
/// @brief Stop this computer from sleeping
|
||||
bool m_preventSleep = false;
|
||||
|
||||
|
||||
@ -79,6 +79,10 @@ void CoreArgParser::parse()
|
||||
);
|
||||
Settings::setValue(Settings::Security::TlsEnabled, value);
|
||||
}
|
||||
|
||||
if (m_parser.isSet(CoreArgs::tlsCertOption)) {
|
||||
Settings::setValue(Settings::Security::Certificate, m_parser.value(CoreArgs::tlsCertOption));
|
||||
}
|
||||
}
|
||||
|
||||
[[noreturn]] void CoreArgParser::showHelpText() const
|
||||
|
||||
@ -41,6 +41,9 @@ struct CoreArgs
|
||||
inline static const auto secureOption =
|
||||
QCommandLineOption("secure", "Enable TLS encryption (default: true)", "value");
|
||||
|
||||
inline static const auto tlsCertOption =
|
||||
QCommandLineOption("tls-cert", "Use file in place of default TLS certificate path", "file");
|
||||
|
||||
inline static const auto options = {helpOption, versionOption, configOption, interfaceOption, portOption,
|
||||
nameOption, logLevelOption, logFileOption, secureOption};
|
||||
nameOption, logLevelOption, logFileOption, secureOption, tlsCertOption};
|
||||
};
|
||||
|
||||
@ -485,14 +485,6 @@ bool CoreProcess::addServerArgs(QStringList &args)
|
||||
// bizarrely, the tls cert path arg was being given to the core client.
|
||||
// since it's not clear why (it is only needed for the server), this has now
|
||||
// been moved to server args.
|
||||
if (Settings::value(Settings::Security::TlsEnabled).toBool()) {
|
||||
if (TlsUtility tlsUtility(this); !tlsUtility.persistCertificate()) {
|
||||
qCritical("failed to persist tls certificate");
|
||||
return false;
|
||||
}
|
||||
args << "--tls-cert" << Settings::value(Settings::Security::Certificate).toString();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@ -44,14 +44,8 @@ std::unique_ptr<IDataSocket> SecureListenSocket::accept()
|
||||
setListeningJob();
|
||||
|
||||
// default location of the TLS cert file in users dir
|
||||
std::string certificateFilename = Settings::value(Settings::Security::Certificate).toString().toStdString();
|
||||
|
||||
// if the tls cert option is set use that for the certificate file
|
||||
if (!ArgParser::argsBase().m_tlsCertFile.empty()) {
|
||||
certificateFilename = ArgParser::argsBase().m_tlsCertFile;
|
||||
}
|
||||
|
||||
if (!secureSocket->loadCertificates(certificateFilename)) {
|
||||
if (const auto certificateFilename = Settings::value(Settings::Security::Certificate).toString().toStdString();
|
||||
!secureSocket->loadCertificates(certificateFilename)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
@ -238,13 +238,12 @@ void ArgParserTests::client_commonArgs()
|
||||
{
|
||||
deskflow::ClientArgs clientArgs;
|
||||
clientArgs.m_enableLangSync = false;
|
||||
const int argc = 4;
|
||||
std::array<const char *, argc> kLangCmd = {"stub", "--tls-cert", "tlsCertPath", "--prevent-sleep"};
|
||||
const int argc = 2;
|
||||
std::array<const char *, argc> kLangCmd = {"stub", "--prevent-sleep"};
|
||||
|
||||
m_parser.parseClientArgs(clientArgs, argc, kLangCmd.data());
|
||||
|
||||
QVERIFY(clientArgs.m_preventSleep);
|
||||
QCOMPARE(clientArgs.m_tlsCertFile, "tlsCertPath");
|
||||
}
|
||||
|
||||
void ArgParserTests::client_setAddress()
|
||||
|
||||
@ -150,4 +150,14 @@ void CoreArgParserTests::secure_1()
|
||||
QVERIFY(Settings::value(Settings::Security::TlsEnabled).toBool());
|
||||
}
|
||||
|
||||
void CoreArgParserTests::tlsCert()
|
||||
{
|
||||
QStringList args = {"stub", "client", "--tls-cert", "certFile"};
|
||||
|
||||
CoreArgParser parser(args);
|
||||
parser.parse();
|
||||
|
||||
QCOMPARE(Settings::value(Settings::Security::Certificate).toString(), "certFile");
|
||||
}
|
||||
|
||||
QTEST_MAIN(CoreArgParserTests)
|
||||
|
||||
@ -27,6 +27,7 @@ private Q_SLOTS:
|
||||
void secure_true();
|
||||
void secure_0();
|
||||
void secure_1();
|
||||
void tlsCert();
|
||||
|
||||
private:
|
||||
inline static const QString m_settingsPath = QStringLiteral("tmp/test");
|
||||
|
||||
Reference in New Issue
Block a user