Skip to content

Commit

Permalink
gui: Don't store openssl output as state of the object
Browse files Browse the repository at this point in the history
  • Loading branch information
p12tic committed Jul 19, 2020
1 parent bd3a8be commit 93ef157
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
28 changes: 17 additions & 11 deletions src/gui/src/SslCertificate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
#if defined(Q_OS_WIN)
Expand All @@ -66,11 +66,12 @@ bool SslCertificate::runTool(const QStringList& args)
process.start(program, args);

bool success = process.waitForStarted();
std::string output;

QString standardError;
if (success && process.waitForFinished())
{
m_ToolOutput = process.readAllStandardOutput().trimmed();
output = process.readAllStandardOutput().trimmed().toStdString();
standardError = process.readAllStandardError().trimmed();
}

Expand All @@ -82,10 +83,10 @@ bool SslCertificate::runTool(const QStringList& args)
.arg(program)
.arg(process.exitCode())
.arg(standardError.isEmpty() ? "Unknown" : standardError));
return false;
return {false, output};
}

return true;
return {true, output};
}

void SslCertificate::generateCertificate()
Expand Down Expand Up @@ -136,7 +137,7 @@ void SslCertificate::generateCertificate()
arguments.append("-out");
arguments.append(filename);

if (!runTool(arguments)) {
if (!runTool(arguments).first) {
return;
}

Expand All @@ -158,21 +159,26 @@ void SslCertificate::generateFingerprint(const QString& certificateFilename)
arguments.append("-in");
arguments.append(certificateFilename);

if (!runTool(arguments)) {
auto ret = runTool(arguments);
bool success = ret.first;
std::string output = ret.second;

if (!success) {
return;
}

// find the fingerprint from the tool output
int i = m_ToolOutput.indexOf("=");
if (i != -1) {
auto i = output.find_first_of('=');
if (i != std::string::npos) {
i++;
QString fingerprint = m_ToolOutput.mid(
i, m_ToolOutput.size() - i);
auto fingerprint = output.substr(
i, output.size() - i);

Fingerprint::local().trust(fingerprint, false);
Fingerprint::local().trust(QString::fromStdString(fingerprint), false);
emit info(tr("SSL fingerprint generated."));
}
else {
emit error(tr("Failed to find SSL fingerprint."));
}
}

4 changes: 2 additions & 2 deletions src/gui/src/SslCertificate.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#pragma once

#include <QObject>
#include <string>

class SslCertificate : public QObject
{
Expand All @@ -35,10 +36,9 @@ public slots:
void generateFinished();

private:
bool runTool(const QStringList& args);
std::pair<bool, std::string> runTool(const QStringList& args);
void generateFingerprint(const QString& certificateFilename);

private:
QString m_ProfileDir;
QString m_ToolOutput;
};

0 comments on commit 93ef157

Please sign in to comment.