core: updates can now be downloaded (and SHA256 hash checked)

This commit is contained in:
moneromooo-monero 2017-02-20 20:48:36 +00:00
parent 216f062eb8
commit a5a0a3c894
No known key found for this signature in database
GPG key ID: 686F07454D6CEFC3
4 changed files with 206 additions and 0 deletions

View file

@ -36,6 +36,7 @@ using namespace epee;
#include "common/command_line.h"
#include "common/util.h"
#include "common/updates.h"
#include "common/download.h"
#include "warnings.h"
#include "crypto/crypto.h"
#include "cryptonote_config.h"
@ -1090,6 +1091,35 @@ namespace cryptonote
if (check_updates_level == UPDATES_NOTIFY)
return true;
std::string filename;
const char *slash = strrchr(url.c_str(), '/');
if (slash)
filename = slash + 1;
else
filename = std::string(software) + "-update-" + version;
boost::filesystem::path path(epee::string_tools::get_current_module_folder());
path /= filename;
if (!tools::download(path.string(), url))
{
MERROR("Failed to download " << url);
return false;
}
crypto::hash file_hash;
if (!tools::sha256sum(path.string(), file_hash))
{
MERROR("Failed to hash " << path);
return false;
}
if (hash != epee::string_tools::pod_to_hex(file_hash))
{
MERROR("Download from " << url << " does not match the expected hash");
return false;
}
MGINFO("New version downloaded to " << path);
if (check_updates_level == UPDATES_DOWNLOAD)
return true;
MERROR("Download/update not implemented yet");
return true;
}