updated DNSResolver/things that use it for DNSSEC

Note: DNSResolver does not yet *use* DNSSEC, but rather this commit is
preparation for including DNSSEC validation.  The function in
src/wallet/wallet2.cpp that uses DNSResolver still needs its parameters
updated accordingly.
This commit is contained in:
Thomas Winget 2014-09-25 00:14:22 -04:00
parent 6f2c2e1c27
commit 0e1449135d
4 changed files with 40 additions and 19 deletions

View file

@ -118,9 +118,11 @@ DNSResolver::~DNSResolver()
} }
} }
std::vector<std::string> DNSResolver::get_ipv4(const std::string& url) std::vector<std::string> DNSResolver::get_ipv4(const std::string& url, bool& dnssec_available, bool& dnssec_valid)
{ {
std::vector<std::string> addresses; std::vector<std::string> addresses;
dnssec_available = false;
dnssec_valid = false;
char urlC[1000]; // waaaay too big, but just in case... char urlC[1000]; // waaaay too big, but just in case...
strncpy(urlC, url.c_str(), 999); strncpy(urlC, url.c_str(), 999);
@ -148,9 +150,11 @@ std::vector<std::string> DNSResolver::get_ipv4(const std::string& url)
return addresses; return addresses;
} }
std::vector<std::string> DNSResolver::get_ipv6(const std::string& url) std::vector<std::string> DNSResolver::get_ipv6(const std::string& url, bool& dnssec_available, bool& dnssec_valid)
{ {
std::vector<std::string> addresses; std::vector<std::string> addresses;
dnssec_available = false;
dnssec_valid = false;
char urlC[1000]; // waaaay too big, but just in case... char urlC[1000]; // waaaay too big, but just in case...
strncpy(urlC, url.c_str(), 999); strncpy(urlC, url.c_str(), 999);
@ -178,9 +182,11 @@ std::vector<std::string> DNSResolver::get_ipv6(const std::string& url)
return addresses; return addresses;
} }
std::vector<std::string> DNSResolver::get_txt_record(const std::string& url) std::vector<std::string> DNSResolver::get_txt_record(const std::string& url, bool& dnssec_available, bool& dnssec_valid)
{ {
std::vector<std::string> records; std::vector<std::string> records;
dnssec_available = false;
dnssec_valid = false;
char urlC[1000]; // waaaay too big, but just in case... char urlC[1000]; // waaaay too big, but just in case...
strncpy(urlC, url.c_str(), 999); strncpy(urlC, url.c_str(), 999);

View file

@ -71,9 +71,11 @@ public:
* *
* @param url A string containing a URL to query for * @param url A string containing a URL to query for
* *
* @param dnssec_available
*
* @return vector of strings containing ipv4 addresses * @return vector of strings containing ipv4 addresses
*/ */
std::vector<std::string> get_ipv4(const std::string& url); std::vector<std::string> get_ipv4(const std::string& url, bool& dnssec_available, bool& dnssec_valid);
/** /**
* @brief gets ipv6 addresses from DNS query * @brief gets ipv6 addresses from DNS query
@ -85,7 +87,7 @@ public:
* *
* @return vector of strings containing ipv6 addresses * @return vector of strings containing ipv6 addresses
*/ */
std::vector<std::string> get_ipv6(const std::string& url); std::vector<std::string> get_ipv6(const std::string& url, bool& dnssec_available, bool& dnssec_valid);
/** /**
* @brief gets all TXT records from a DNS query for the supplied URL; * @brief gets all TXT records from a DNS query for the supplied URL;
@ -96,7 +98,7 @@ public:
* @return A vector of strings containing a TXT record; or an empty vector * @return A vector of strings containing a TXT record; or an empty vector
*/ */
// TODO: modify this to accomodate DNSSEC // TODO: modify this to accomodate DNSSEC
std::vector<std::string> get_txt_record(const std::string& url); std::vector<std::string> get_txt_record(const std::string& url, bool& dnssec_available, bool& dnssec_valid);
/** /**
* @brief Gets the singleton instance of DNSResolver * @brief Gets the singleton instance of DNSResolver

View file

@ -833,12 +833,17 @@ std::vector<std::vector<cryptonote::tx_destination_entry>> split_amounts(
*/ */
std::vector<std::string> wallet2::addresses_from_url(const std::string& url, bool& dnssec_valid) std::vector<std::string> wallet2::addresses_from_url(const std::string& url, bool& dnssec_valid)
{ {
// TODO: update this correctly once DNSResolver::get_txt_record() supports it.
dnssec_valid = false;
std::vector<std::string> addresses; std::vector<std::string> addresses;
// get txt records // get txt records
auto records = tools::DNSResolver::instance().get_txt_record(url); bool dnssec_available, dnssec_isvalid;
auto records = tools::DNSResolver::instance().get_txt_record(url, dnssec_available, dnssec_isvalid);
// TODO: update this to allow for conveying that dnssec was not available
if (dnssec_available && dnssec_isvalid)
{
dnssec_valid = true;
}
else dnssec_valid = false;
// for each txt record, try to find a monero address in it. // for each txt record, try to find a monero address in it.
for (auto& rec : records) for (auto& rec : records)

View file

@ -37,13 +37,15 @@ TEST(DNSResolver, IPv4Success)
{ {
tools::DNSResolver resolver; tools::DNSResolver resolver;
auto ips = resolver.get_ipv4("example.com"); bool avail, valid;
auto ips = resolver.get_ipv4("example.com", avail, valid);
ASSERT_EQ(1, ips.size()); ASSERT_EQ(1, ips.size());
ASSERT_STREQ("93.184.216.119", ips[0].c_str()); ASSERT_STREQ("93.184.216.119", ips[0].c_str());
ips = tools::DNSResolver::instance().get_ipv4("example.com"); ips = tools::DNSResolver::instance().get_ipv4("example.com", avail, valid);
ASSERT_EQ(1, ips.size()); ASSERT_EQ(1, ips.size());
@ -55,11 +57,13 @@ TEST(DNSResolver, IPv4Failure)
// guaranteed by IANA/ICANN/RFC to be invalid // guaranteed by IANA/ICANN/RFC to be invalid
tools::DNSResolver resolver; tools::DNSResolver resolver;
auto ips = resolver.get_ipv4("example.invalid"); bool avail, valid;
auto ips = resolver.get_ipv4("example.invalid", avail, valid);
ASSERT_EQ(0, ips.size()); ASSERT_EQ(0, ips.size());
ips = tools::DNSResolver::instance().get_ipv4("example.invalid"); ips = tools::DNSResolver::instance().get_ipv4("example.invalid", avail, valid);
ASSERT_EQ(0, ips.size()); ASSERT_EQ(0, ips.size());
} }
@ -68,13 +72,15 @@ TEST(DNSResolver, IPv6Success)
{ {
tools::DNSResolver resolver; tools::DNSResolver resolver;
auto ips = resolver.get_ipv6("example.com"); bool avail, valid;
auto ips = resolver.get_ipv6("example.com", avail, valid);
ASSERT_EQ(1, ips.size()); ASSERT_EQ(1, ips.size());
ASSERT_STREQ("2606:2800:220:6d:26bf:1447:1097:aa7", ips[0].c_str()); ASSERT_STREQ("2606:2800:220:6d:26bf:1447:1097:aa7", ips[0].c_str());
ips = tools::DNSResolver::instance().get_ipv6("example.com"); ips = tools::DNSResolver::instance().get_ipv6("example.com", avail, valid);
ASSERT_EQ(1, ips.size()); ASSERT_EQ(1, ips.size());
@ -86,11 +92,13 @@ TEST(DNSResolver, IPv6Failure)
// guaranteed by IANA/ICANN/RFC to be invalid // guaranteed by IANA/ICANN/RFC to be invalid
tools::DNSResolver resolver; tools::DNSResolver resolver;
auto ips = resolver.get_ipv6("example.invalid"); bool avail, valid;
auto ips = resolver.get_ipv6("example.invalid", avail, valid);
ASSERT_EQ(0, ips.size()); ASSERT_EQ(0, ips.size());
ips = tools::DNSResolver::instance().get_ipv6("example.invalid"); ips = tools::DNSResolver::instance().get_ipv6("example.invalid", avail, valid);
ASSERT_EQ(0, ips.size()); ASSERT_EQ(0, ips.size());
} }
@ -98,7 +106,7 @@ TEST(DNSResolver, IPv6Failure)
TEST(DNSResolver, GetTXTRecord) TEST(DNSResolver, GetTXTRecord)
{ {
std::vector<std::string> records = tools::DNSResolver::instance().get_txt_record("donate.monero.cc"); std::vector<std::string> records = tools::DNSResolver::instance().get_txt_record("donate.monero.cc", avail, valid);
EXPECT_NE(0, records.size()); EXPECT_NE(0, records.size());