refactor: move tls-cert to coreArgs

This commit is contained in:
sithlord48 2025-08-23 15:40:43 -04:00 committed by Chris Rizzitello
parent ff4c9dc421
commit a8348b1ccb
10 changed files with 24 additions and 27 deletions

View file

@ -130,8 +130,7 @@ private:
#endif #endif
constexpr static auto s_helpGeneralArgs = // constexpr static auto s_helpGeneralArgs = //
" -1, --no-restart do not try to restart on failure.\n" " -1, --no-restart do not try to restart on failure.\n"
"* --restart restart the server automatically if it fails.\n" "* --restart restart the server automatically if it fails.\n";
" --tls-cert specify the path to the TLS certificate file.\n";
constexpr static auto s_helpVersionArgs = // constexpr static auto s_helpVersionArgs = //
" -h, --help display this help and exit.\n"; " -h, --help display this help and exit.\n";

View file

@ -139,8 +139,6 @@ bool ArgParser::parseGenericArgs(int argc, const char *const *argv, int &i) cons
// HACK: stop error happening when using portable (deskflowp) // HACK: stop error happening when using portable (deskflowp)
} else if (isArg(i, argc, argv, nullptr, "--client")) { } else if (isArg(i, argc, argv, nullptr, "--client")) {
// HACK: stop error happening when using portable (deskflowp) // 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")) { } else if (isArg(i, argc, argv, nullptr, "--prevent-sleep")) {
argsBase().m_preventSleep = true; argsBase().m_preventSleep = true;
} else { } else {

View file

@ -50,9 +50,6 @@ public:
/// @brief Will cause the application to exit with fail code when set to true /// @brief Will cause the application to exit with fail code when set to true
bool m_shouldExitFail = false; bool m_shouldExitFail = false;
/// @brief Contains the location of the TLS certificate file
std::string m_tlsCertFile;
/// @brief Stop this computer from sleeping /// @brief Stop this computer from sleeping
bool m_preventSleep = false; bool m_preventSleep = false;

View file

@ -79,6 +79,10 @@ void CoreArgParser::parse()
); );
Settings::setValue(Settings::Security::TlsEnabled, value); 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 [[noreturn]] void CoreArgParser::showHelpText() const

View file

@ -41,6 +41,9 @@ struct CoreArgs
inline static const auto secureOption = inline static const auto secureOption =
QCommandLineOption("secure", "Enable TLS encryption (default: true)", "value"); 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, inline static const auto options = {helpOption, versionOption, configOption, interfaceOption, portOption,
nameOption, logLevelOption, logFileOption, secureOption}; nameOption, logLevelOption, logFileOption, secureOption, tlsCertOption};
}; };

View file

@ -485,14 +485,6 @@ bool CoreProcess::addServerArgs(QStringList &args)
// bizarrely, the tls cert path arg was being given to the core client. // 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 // since it's not clear why (it is only needed for the server), this has now
// been moved to server args. // 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; return true;
} }

View file

@ -44,14 +44,8 @@ std::unique_ptr<IDataSocket> SecureListenSocket::accept()
setListeningJob(); setListeningJob();
// default location of the TLS cert file in users dir // default location of the TLS cert file in users dir
std::string certificateFilename = Settings::value(Settings::Security::Certificate).toString().toStdString(); if (const auto certificateFilename = Settings::value(Settings::Security::Certificate).toString().toStdString();
!secureSocket->loadCertificates(certificateFilename)) {
// 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)) {
return nullptr; return nullptr;
} }

View file

@ -238,13 +238,12 @@ void ArgParserTests::client_commonArgs()
{ {
deskflow::ClientArgs clientArgs; deskflow::ClientArgs clientArgs;
clientArgs.m_enableLangSync = false; clientArgs.m_enableLangSync = false;
const int argc = 4; const int argc = 2;
std::array<const char *, argc> kLangCmd = {"stub", "--tls-cert", "tlsCertPath", "--prevent-sleep"}; std::array<const char *, argc> kLangCmd = {"stub", "--prevent-sleep"};
m_parser.parseClientArgs(clientArgs, argc, kLangCmd.data()); m_parser.parseClientArgs(clientArgs, argc, kLangCmd.data());
QVERIFY(clientArgs.m_preventSleep); QVERIFY(clientArgs.m_preventSleep);
QCOMPARE(clientArgs.m_tlsCertFile, "tlsCertPath");
} }
void ArgParserTests::client_setAddress() void ArgParserTests::client_setAddress()

View file

@ -150,4 +150,14 @@ void CoreArgParserTests::secure_1()
QVERIFY(Settings::value(Settings::Security::TlsEnabled).toBool()); 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) QTEST_MAIN(CoreArgParserTests)

View file

@ -27,6 +27,7 @@ private Q_SLOTS:
void secure_true(); void secure_true();
void secure_0(); void secure_0();
void secure_1(); void secure_1();
void tlsCert();
private: private:
inline static const QString m_settingsPath = QStringLiteral("tmp/test"); inline static const QString m_settingsPath = QStringLiteral("tmp/test");