Implemented the letsencrypt challange

This commit is contained in:
WolverinDEV 2019-11-22 00:09:27 +01:00
parent 8639a7d05e
commit ee608ad0c8
3 changed files with 31 additions and 0 deletions

View File

@ -69,6 +69,18 @@ void WebDNSHandler::handle_message(const std::shared_ptr<DNSServerBinding>& bind
a.set_type(query->qtype());
a.set_ttl(120);
a.builder<rrbuilder::A>().set_address(resp);
} else if(query->qclass() == rrclass::IN && query->qtype() == rrtype::TXT) {
auto dn = query->qname();
if(dn == "_acme-challenge.con-gate.work") {
std::cout << " Letsencrypt request\n";
std::cout << " Sending predefined key\n";
auto& a = response.push_answer(query->qname());
a.set_class(query->qclass());
a.set_type(query->qtype());
a.set_ttl(120);
a.builder<rrbuilder::TXT>().set_text("-YEqeIGJqoOz5uLbUiUfK06--n3jtVoI__6WJY-Ehgk");
}
}
}

View File

@ -143,6 +143,12 @@ namespace ts::dns {
uint32_t address{0};
);
define_builder(TXT, base,
inline void set_text(const std::string& text) { this->_text = text; }
private:
std::string _text;
);
#undef define_builder
}
}

View File

@ -119,4 +119,17 @@ bool rrbuilder::A::build(char *&buffer, size_t &max_size, std::string &error) {
buffer += 4;
max_size -= 4;
return true;
}
bool rrbuilder::TXT::build(char *&buffer, size_t &max_size, std::string &error) {
if(max_size + 1 < this->_text.size()) {
error = "buffer too small";
return false;
}
*buffer = this->_text.size();
memcpy(buffer + 1, this->_text.data(), this->_text.size());
buffer += this->_text.size() + 1;
max_size -= this->_text.size() + 1;
return true;
}