aboutsummaryrefslogtreecommitdiff
path: root/src/qt/downloader.cpp
diff options
context:
space:
mode:
authorxiphon <xiphon@protonmail.com>2020-04-14 21:03:15 +0000
committerxiphon <xiphon@protonmail.com>2020-04-14 21:37:04 +0000
commitea25b71ca66a7d81203bbfed7fa1a1d6fa79553f (patch)
tree40bfaac76cba0e0f68a7b1e2b79cec0eab4841d6 /src/qt/downloader.cpp
parent8e4124f06aa6c580ee62dd1b78735bc488e21366 (diff)
downloadmonzero-gui-ea25b71ca66a7d81203bbfed7fa1a1d6fa79553f.tar.gz
monzero-gui-ea25b71ca66a7d81203bbfed7fa1a1d6fa79553f.tar.xz
monzero-gui-ea25b71ca66a7d81203bbfed7fa1a1d6fa79553f.zip
updater: fetch signed hashes from getmonero.org, verify downloads
Diffstat (limited to 'src/qt/downloader.cpp')
-rw-r--r--src/qt/downloader.cpp19
1 files changed, 17 insertions, 2 deletions
diff --git a/src/qt/downloader.cpp b/src/qt/downloader.cpp
index afd2049e..d925c77c 100644
--- a/src/qt/downloader.cpp
+++ b/src/qt/downloader.cpp
@@ -31,6 +31,8 @@
#include <QReadLocker>
#include <QWriteLocker>
+#include "updater.h"
+
namespace
{
@@ -112,10 +114,10 @@ void Downloader::cancel()
m_contents.clear();
}
-bool Downloader::get(const QString &url, const QJSValue &callback)
+bool Downloader::get(const QString &url, const QString &hash, const QJSValue &callback)
{
auto future = m_scheduler.run(
- [this, url]() {
+ [this, url, hash]() {
DownloaderStateGuard stateGuard(m_active, m_mutex, [this]() {
emit activeChanged();
});
@@ -153,6 +155,19 @@ bool Downloader::get(const QString &url, const QJSValue &callback)
return QJSValueList({"empty response"});
}
+ try
+ {
+ const QByteArray calculatedHash = Updater().getHash(&response[0], response.size());
+ if (QByteArray::fromHex(hash.toUtf8()) != calculatedHash)
+ {
+ return QJSValueList({"hash sum mismatch"});
+ }
+ }
+ catch (const std::exception &e)
+ {
+ return QJSValueList({e.what()});
+ }
+
{
QWriteLocker locker(&m_mutex);