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
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";

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)
} 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 {

View File

@ -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;

View File

@ -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

View File

@ -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};
};

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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()

View File

@ -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)

View File

@ -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");