Skip to content

Commit

Permalink
Autodpdater and SSL bugfixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
DolceTriade committed Sep 25, 2017
1 parent df43d6f commit 499f04d
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 16 deletions.
7 changes: 7 additions & 0 deletions ariadownloader.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "ariadownloader.h"
#include "system.h"

int downloadEventCallback(aria2::Session* session, aria2::DownloadEvent event,
aria2::A2Gid gid, void* userData)
Expand All @@ -23,6 +24,12 @@ AriaDownloader::AriaDownloader() : callback_(nullptr)
options.push_back({ "seed-time", "0" });
options.push_back({ "file-allocation", "none" });
options.push_back({ "follow-torrent", "mem" });
options.push_back({ "quiet", "false" });

std::string certsPath = Sys::getCertStore();
if (!certsPath.empty()) {
options.push_back({ "ca-certificates", certsPath });
}
session = aria2::sessionNew(options, config);
}

Expand Down
14 changes: 11 additions & 3 deletions osx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,11 @@ bool updateUpdater(const QString& updaterArchive)
}
if (extractedAppPath.isEmpty()) return false;
QDir extractedApp(extractedAppPath);
if (!extractDir.rename(extractedApp.dirName(), currentApp.dirName())) {
qDebug() << "Could not rename update. pls manually update.";
return false;
if (extractedApp.dirName() != currentApp.dirName()) {
if (!extractDir.rename(extractedApp.dirName(), currentApp.dirName())) {
qDebug() << "Could not rename update. pls manually update.";
return false;
}
}
// TODO: Maybe don't use system? startDetached didn't work for me...
int i = system((QString("/usr/bin/open -F -n \"%1\"").arg(currentAppPath)).toStdString().c_str());
Expand All @@ -114,4 +116,10 @@ QString updaterArchiveName(void)
return "UnvUpdaterOSX.zip";
}

std::string getCertStore()
{
return ""; // Not used on OSX.
}


} // namespace Sys
13 changes: 6 additions & 7 deletions qmldownloader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,15 +179,14 @@ void QmlDownloader::stopAria(void)

void QmlDownloader::checkForUpdate()
{
if (!settings_.installFinished()) {
if (networkManager_.isOnline()) {
connect(&fetcher_, SIGNAL(onCurrentVersions(QString, QString)), this, SLOT(onCurrentVersions(QString, QString)));
fetcher_.fetchCurrentVersion("http://dl.unvanquished.net/versions.json");
return;
}
else if (!settings_.installFinished()) {
emit updateNeeded(true);
return;
} else {
if (networkManager_.isOnline()) {
connect(&fetcher_, SIGNAL(onCurrentVersions(QString, QString)), this, SLOT(onCurrentVersions(QString, QString)));
fetcher_.fetchCurrentVersion("http://dl.unvanquished.net/versions.json");
return;
}
}
emit updateNeeded(false);
}
Expand Down
3 changes: 3 additions & 0 deletions system.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#include <string>

#include <QString>

namespace Sys {
Expand All @@ -7,4 +9,5 @@ QString executableName(void);
bool install(void);
bool updateUpdater(const QString& updaterArchive);
QString updaterArchiveName(void);
std::string getCertStore(void);
}
27 changes: 24 additions & 3 deletions unix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,12 @@ bool updateUpdater(const QString& updaterArchive)
qDebug() << "Invalid update archive.";
return false;
}
if (!QFile::rename(out[0], current)) {
qDebug() << "Error renaming new updater to previous file name.";
return false;

if (out[0] != current) {
if (!QFile::rename(out[0], current)) {
qDebug() << "Error renaming new updater to previous file name.";
return false;
}
}

if (!QProcess::startDetached(current)) {
Expand All @@ -101,4 +104,22 @@ QString updaterArchiveName(void)
return "UnvUpdaterLinux.zip";
}

std::string getCertStore()
{
// From Go: https://golang.org/src/crypto/x509/root_linux.go
static constexpr QStringList CERT_LOCATIONS = {
"/etc/ssl/certs/ca-certificates.crt", // Debian/Ubuntu/Gentoo etc.
"/etc/pki/tls/certs/ca-bundle.crt", // Fedora/RHEL 6
"/etc/ssl/ca-bundle.pem", // OpenSUSE
"/etc/pki/tls/cacert.pem", // OpenELEC
"/etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem", // CentOS/RHEL 7
};

for (const QString& path : CERT_LOCATIONS) {
QFile file(path);
if (file.exists()) return path.toStdString();
}
return "";
}

} // namespace Sys
14 changes: 11 additions & 3 deletions win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,11 @@ bool updateUpdater(const QString& updaterArchive)
return false;
}

if (!QFile::rename(out[0], current)) {
qDebug() << "Error renaming new updater to previous file name.";
return false;
if (out[0] != current) {
if (!QFile::rename(out[0], current)) {
qDebug() << "Error renaming new updater to previous file name.";
return false;
}
}

if (!QProcess::startDetached(current)) {
Expand All @@ -194,4 +196,10 @@ QString updaterArchiveName(void)
return "UnvUpdaterWin.zip";
}

std::string getCertStore()
{
return ""; // Not used on windows.
}


} // namespace Sys

0 comments on commit 499f04d

Please sign in to comment.