From b261d9207ba5cdc0334fab403204971f79b6ca03 Mon Sep 17 00:00:00 2001 From: Thomas Winget Date: Fri, 26 Sep 2014 01:01:58 -0400 Subject: DNS checkpoint updating added, and daemon flag to enforce them The daemon should now check for updated checkpoints from checkpoints.moneropulse.org as well as from the configured json file every ~1hr (and on launch). The daemon now has a flag to enable enforcing these checkpoints (rather than just printing a warning when they fail). TODO: an easily configurable list of DNS servers to check for checkpoints as opposed to the hard-coded "checkpoints.moneropulse.org" --- src/cryptonote_core/checkpoints_create.cpp | 50 ++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) (limited to 'src/cryptonote_core/checkpoints_create.cpp') diff --git a/src/cryptonote_core/checkpoints_create.cpp b/src/cryptonote_core/checkpoints_create.cpp index ff927396e..b81353539 100644 --- a/src/cryptonote_core/checkpoints_create.cpp +++ b/src/cryptonote_core/checkpoints_create.cpp @@ -29,6 +29,9 @@ // Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers #include "checkpoints_create.h" +#include "common/dns_utils.h" +#include "include_base_utils.h" +#include #include "storages/portable_storage_template_helper.h" // epee json include namespace cryptonote @@ -107,4 +110,51 @@ bool load_checkpoints_from_json(cryptonote::checkpoints& checkpoints, std::strin return true; } +bool load_checkpoints_from_dns(cryptonote::checkpoints& checkpoints, const std::string& url) +{ + bool avail, valid; + auto records = tools::DNSResolver::instance().get_txt_record(url, avail, valid); + + if (avail && !valid) + { + LOG_ERROR("DNSSEC present and failed validation for query to" << url); + return false; + } + + for (auto& record : records) + { + auto pos = record.find(":"); + if (pos != std::string::npos) + { + uint64_t height; + crypto::hash hash; + + // parse the first part as uint64_t, + // if this fails move on to the next record + std::stringstream ss(record.substr(0, pos)); + if (!(ss >> height)) + { + continue; + } + + // parse the second part as crypto::hash, + // if this fails move on to the next record + std::string hashStr = record.substr(pos + 1); + if (!epee::string_tools::parse_tpod_from_hex_string(hashStr, hash)) + { + continue; + } + + ADD_CHECKPOINT(height, hashStr); + } + } + return true; +} + +bool load_new_checkpoints(cryptonote::checkpoints& checkpoints, std::string json_hashfile_fullpath) +{ + // TODO: replace hard-coded url with const string or #define + return (load_checkpoints_from_json(checkpoints, json_hashfile_fullpath) && load_checkpoints_from_dns(checkpoints, "checkpoints.moneropulse.org")); +} + } // namespace cryptonote -- cgit v1.2.3