| 1 | // Copyright (c) 2019-2022, The Monero Project |
| 2 | // |
| 3 | // All rights reserved. |
| 4 | // |
| 5 | // Redistribution and use in source and binary forms, with or without modification, are |
| 6 | // permitted provided that the following conditions are met: |
| 7 | // |
| 8 | // 1. Redistributions of source code must retain the above copyright notice, this list of |
| 9 | // conditions and the following disclaimer. |
| 10 | // |
| 11 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list |
| 12 | // of conditions and the following disclaimer in the documentation and/or other |
| 13 | // materials provided with the distribution. |
| 14 | // |
| 15 | // 3. Neither the name of the copyright holder nor the names of its contributors may be |
| 16 | // used to endorse or promote products derived from this software without specific |
| 17 | // prior written permission. |
| 18 | // |
| 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY |
| 20 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 21 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL |
| 22 | // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 24 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 25 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
| 26 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF |
| 27 | // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 28 | |
| 29 | #include <string> |
| 30 | #include <vector> |
| 31 | #include <map> |
| 32 | #include <algorithm> |
| 33 | #include <boost/program_options.hpp> |
| 34 | #include "misc_log_ex.h" |
| 35 | #include "common/util.h" |
| 36 | #include "common/command_line.h" |
| 37 | #include "common/dns_utils.h" |
| 38 | #include "version.h" |
| 39 | |
| 40 | #undef MONERO_DEFAULT_LOG_CATEGORY |
| 41 | #define MONERO_DEFAULT_LOG_CATEGORY "debugtools.dnschecks" |
| 42 | |
| 43 | namespace po = boost::program_options; |
| 44 | |
| 45 | enum lookup_t { LOOKUP_A, LOOKUP_TXT }; |
| 46 | |
| 47 | static std::vector<std::string> lookup(lookup_t type, const char *hostname) |
| 48 | { |
| 49 | bool dnssec_available = false, dnssec_valid = false; |
| 50 | std::vector<std::string> res; |
| 51 | switch (type) |
| 52 | { |
| 53 | case LOOKUP_A: res = tools::DNSResolver::instance().get_ipv4(hostname, dnssec_available, dnssec_valid); break; |
| 54 | case LOOKUP_TXT: res = tools::DNSResolver::instance().get_txt_record(hostname, dnssec_available, dnssec_valid); break; |
| 55 | default: MERROR("Invalid lookup type: " << (int)type); return {}; |
| 56 | } |
| 57 | if (!dnssec_available) |
| 58 | { |
| 59 | MWARNING("No DNSSEC for " << hostname); |
| 60 | return {}; |
| 61 | } |
| 62 | if (!dnssec_valid) |
| 63 | { |
| 64 | MWARNING("Invalid DNSSEC check for " << hostname); |
| 65 | return {}; |
| 66 | } |
| 67 | MINFO(res.size() << " valid signed result(s) for " << hostname); |
| 68 | return res; |
| 69 | } |
| 70 | |
| 71 | static void lookup(lookup_t type, const std::vector<std::string> hostnames) |
| 72 | { |
| 73 | std::vector<std::vector<std::string>> results; |
| 74 | for (const std::string &hostname: hostnames) |
| 75 | { |
| 76 | auto res = lookup(type, hostname.c_str()); |
| 77 | if (!res.empty()) |
| 78 | { |
| 79 | std::sort(res.begin(), res.end()); |
| 80 | results.push_back(res); |
| 81 | } |
| 82 | } |
| 83 | std::map<std::vector<std::string>, size_t> counter; |
| 84 | for (const auto &e: results) |
| 85 | counter[e]++; |
| 86 | size_t count = 0; |
| 87 | for (const auto &e: counter) |
| 88 | count = std::max(count, e.second); |
| 89 | if (results.size() > 1) |
| 90 | { |
| 91 | if (count < results.size()) |
| 92 | MERROR("Only " << count << "/" << results.size() << " records match"); |
| 93 | else |
| 94 | MINFO(count << "/" << results.size() << " records match"); |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | int main(int argc, char* argv[]) |
| 99 | { |
| 100 | TRY_ENTRY(); |
| 101 | |
| 102 | tools::on_startup(); |
| 103 | |
| 104 | po::options_description desc_cmd_only("Command line options"); |
| 105 | po::options_description desc_cmd_sett("Command line options and settings options"); |
| 106 | |
| 107 | command_line::add_arg(desc_cmd_only, command_line::arg_help); |
| 108 | |
| 109 | po::options_description desc_options("Allowed options"); |
| 110 | desc_options.add(desc_cmd_only).add(desc_cmd_sett); |
| 111 | |
| 112 | po::variables_map vm; |
| 113 | bool r = command_line::handle_error_helper(desc_options, [&]() |
| 114 | { |
| 115 | po::store(po::parse_command_line(argc, argv, desc_options), vm); |
| 116 | po::notify(vm); |
| 117 | return true; |
| 118 | }); |
| 119 | if (! r) |
| 120 | return 1; |
| 121 | |
| 122 | if (command_line::get_arg(vm, command_line::arg_help)) |
| 123 | { |
| 124 | std::cout << "Monero '" << MONERO_RELEASE_NAME << "' (v" << MONERO_VERSION_FULL << ")" << ENDL << ENDL; |
| 125 | std::cout << desc_options << std::endl; |
| 126 | return 1; |
| 127 | } |
| 128 | |
| 129 | mlog_configure("", true); |
| 130 | mlog_set_categories("+" MONERO_DEFAULT_LOG_CATEGORY ":INFO"); |
| 131 | |
| 132 | lookup(LOOKUP_A, {"seeds.moneroseeds.se", "seeds.moneroseeds.ae.org", "seeds.moneroseeds.ch", "seeds.moneroseeds.li"}); |
| 133 | |
| 134 | lookup(LOOKUP_TXT, {"updates.moneropulse.org", "updates.moneropulse.net", "updates.moneropulse.co", "updates.moneropulse.se", "updates.moneropulse.fr", "updates.moneropulse.de", "updates.moneropulse.ch"}); |
| 135 | |
| 136 | lookup(LOOKUP_TXT, {"checkpoints.moneropulse.org", "checkpoints.moneropulse.net", "checkpoints.moneropulse.co", "checkpoints.moneropulse.se"}); |
| 137 | |
| 138 | // those are in the code, but don't seem to actually exist |
| 139 | #if 0 |
| 140 | lookup(LOOKUP_TXT, {"testpoints.moneropulse.org", "testpoints.moneropulse.net", "testpoints.moneropulse.co", "testpoints.moneropulse.se"); |
| 141 | |
| 142 | lookup(LOOKUP_TXT, {"stagenetpoints.moneropulse.org", "stagenetpoints.moneropulse.net", "stagenetpoints.moneropulse.co", "stagenetpoints.moneropulse.se"}); |
| 143 | #endif |
| 144 | |
| 145 | lookup(LOOKUP_TXT, {"segheights.moneropulse.org", "segheights.moneropulse.net", "segheights.moneropulse.co", "segheights.moneropulse.se"}); |
| 146 | |
| 147 | return 0; |
| 148 | CATCH_ENTRY_L0("main", 1); |
| 149 | } |