gui: Don't store openssl output as state of the object
This commit is contained in:
parent
bd3a8be956
commit
93ef15774b
|
@ -43,7 +43,7 @@ SslCertificate::SslCertificate(QObject *parent) :
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SslCertificate::runTool(const QStringList& args)
|
std::pair<bool, std::string> SslCertificate::runTool(const QStringList& args)
|
||||||
{
|
{
|
||||||
QString program;
|
QString program;
|
||||||
#if defined(Q_OS_WIN)
|
#if defined(Q_OS_WIN)
|
||||||
|
@ -66,11 +66,12 @@ bool SslCertificate::runTool(const QStringList& args)
|
||||||
process.start(program, args);
|
process.start(program, args);
|
||||||
|
|
||||||
bool success = process.waitForStarted();
|
bool success = process.waitForStarted();
|
||||||
|
std::string output;
|
||||||
|
|
||||||
QString standardError;
|
QString standardError;
|
||||||
if (success && process.waitForFinished())
|
if (success && process.waitForFinished())
|
||||||
{
|
{
|
||||||
m_ToolOutput = process.readAllStandardOutput().trimmed();
|
output = process.readAllStandardOutput().trimmed().toStdString();
|
||||||
standardError = process.readAllStandardError().trimmed();
|
standardError = process.readAllStandardError().trimmed();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -82,10 +83,10 @@ bool SslCertificate::runTool(const QStringList& args)
|
||||||
.arg(program)
|
.arg(program)
|
||||||
.arg(process.exitCode())
|
.arg(process.exitCode())
|
||||||
.arg(standardError.isEmpty() ? "Unknown" : standardError));
|
.arg(standardError.isEmpty() ? "Unknown" : standardError));
|
||||||
return false;
|
return {false, output};
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return {true, output};
|
||||||
}
|
}
|
||||||
|
|
||||||
void SslCertificate::generateCertificate()
|
void SslCertificate::generateCertificate()
|
||||||
|
@ -136,7 +137,7 @@ void SslCertificate::generateCertificate()
|
||||||
arguments.append("-out");
|
arguments.append("-out");
|
||||||
arguments.append(filename);
|
arguments.append(filename);
|
||||||
|
|
||||||
if (!runTool(arguments)) {
|
if (!runTool(arguments).first) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -158,21 +159,26 @@ void SslCertificate::generateFingerprint(const QString& certificateFilename)
|
||||||
arguments.append("-in");
|
arguments.append("-in");
|
||||||
arguments.append(certificateFilename);
|
arguments.append(certificateFilename);
|
||||||
|
|
||||||
if (!runTool(arguments)) {
|
auto ret = runTool(arguments);
|
||||||
|
bool success = ret.first;
|
||||||
|
std::string output = ret.second;
|
||||||
|
|
||||||
|
if (!success) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// find the fingerprint from the tool output
|
// find the fingerprint from the tool output
|
||||||
int i = m_ToolOutput.indexOf("=");
|
auto i = output.find_first_of('=');
|
||||||
if (i != -1) {
|
if (i != std::string::npos) {
|
||||||
i++;
|
i++;
|
||||||
QString fingerprint = m_ToolOutput.mid(
|
auto fingerprint = output.substr(
|
||||||
i, m_ToolOutput.size() - i);
|
i, output.size() - i);
|
||||||
|
|
||||||
Fingerprint::local().trust(fingerprint, false);
|
Fingerprint::local().trust(QString::fromStdString(fingerprint), false);
|
||||||
emit info(tr("SSL fingerprint generated."));
|
emit info(tr("SSL fingerprint generated."));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
emit error(tr("Failed to find SSL fingerprint."));
|
emit error(tr("Failed to find SSL fingerprint."));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
class SslCertificate : public QObject
|
class SslCertificate : public QObject
|
||||||
{
|
{
|
||||||
|
@ -35,10 +36,9 @@ signals:
|
||||||
void generateFinished();
|
void generateFinished();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool runTool(const QStringList& args);
|
std::pair<bool, std::string> runTool(const QStringList& args);
|
||||||
void generateFingerprint(const QString& certificateFilename);
|
void generateFingerprint(const QString& certificateFilename);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString m_ProfileDir;
|
QString m_ProfileDir;
|
||||||
QString m_ToolOutput;
|
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue