]> granicus.if.org Git - pdns/commitdiff
also include DNSKEY on a case-insensitive match.
authorBert Hubert <bert.hubert@netherlabs.nl>
Mon, 3 Jan 2011 20:59:25 +0000 (20:59 +0000)
committerBert Hubert <bert.hubert@netherlabs.nl>
Mon, 3 Jan 2011 20:59:25 +0000 (20:59 +0000)
Lowercase RRDATA properly for signing -> hopefully gets us 0x20 compliant

git-svn-id: svn://svn.powerdns.com/pdns/trunk/pdns@1799 d19b8d6e-7fed-0310-83ef-9ca221ded41b

pdns/backends/gsql/gsqlbackend.cc
pdns/dnsparser.hh
pdns/dnssecinfra.cc
pdns/dnswriter.cc
pdns/dnswriter.hh
pdns/packethandler.cc

index 5e5a7ef55bd8e30eb1ae3f87008b63b96988827b..8bbd4071087dccc40769b1bf5d8fc413c9c84bbc 100644 (file)
@@ -320,7 +320,7 @@ int GSQLBackend::addDomainKey(const string& name, const KeyData& key)
 {
   char output[16384];  
   snprintf(output,sizeof(output)-1,d_AddDomainKeyQuery.c_str(),
-          key.flags, (int)key.active, sqlEscape(key.content).c_str(), sqlEscape(name).c_str());
+          key.flags, (int)key.active, sqlEscape(key.content).c_str(), sqlEscape(toLower(name)).c_str());
 
   try {
     d_db->doCommand(output);
@@ -334,7 +334,7 @@ int GSQLBackend::addDomainKey(const string& name, const KeyData& key)
 bool GSQLBackend::activateDomainKey(const string& name, unsigned int id)
 {
   char output[1024];
-  snprintf(output,sizeof(output)-1,d_ActivateDomainKeyQuery.c_str(), sqlEscape(name).c_str(), id);
+  snprintf(output,sizeof(output)-1,d_ActivateDomainKeyQuery.c_str(), sqlEscape(toLower(name)).c_str(), id);
 
   try {
     d_db->doCommand(output);
@@ -348,7 +348,7 @@ bool GSQLBackend::activateDomainKey(const string& name, unsigned int id)
 bool GSQLBackend::deactivateDomainKey(const string& name, unsigned int id)
 {
   char output[1024];
-  snprintf(output,sizeof(output)-1,d_DeactivateDomainKeyQuery.c_str(), sqlEscape(name).c_str(), id);
+  snprintf(output,sizeof(output)-1,d_DeactivateDomainKeyQuery.c_str(), sqlEscape(toLower(name)).c_str(), id);
 
   try {
     d_db->doCommand(output);
@@ -362,7 +362,7 @@ bool GSQLBackend::deactivateDomainKey(const string& name, unsigned int id)
 bool GSQLBackend::removeDomainKey(const string& name, unsigned int id)
 {
   char output[1024];
-  snprintf(output,sizeof(output)-1,d_RemoveDomainKeyQuery.c_str(), sqlEscape(name).c_str(), id);
+  snprintf(output,sizeof(output)-1,d_RemoveDomainKeyQuery.c_str(), sqlEscape(toLower(name)).c_str(), id);
 
   try {
     d_db->doCommand(output);
@@ -378,7 +378,7 @@ bool GSQLBackend::removeDomainKey(const string& name, unsigned int id)
 bool GSQLBackend::getDomainKeys(const string& name, unsigned int kind, std::vector<KeyData>& keys)
 {
   char output[1024];  
-  snprintf(output,sizeof(output)-1,d_ListDomainKeysQuery.c_str(), sqlEscape(name).c_str());
+  snprintf(output,sizeof(output)-1,d_ListDomainKeysQuery.c_str(), sqlEscape(toLower(name)).c_str());
 
   try {
     d_db->doQuery(output);
index c541a4aab4ee9ed409921fae680ed3f416c34cc2..35f16977dba5ac1d58f009cebc12ca6661ee4457 100644 (file)
@@ -1,6 +1,6 @@
 /*
     PowerDNS Versatile Database Driven Nameserver
-    Copyright (C) 2005 - 2010 PowerDNS.COM BV
+    Copyright (C) 2005 - 2011 PowerDNS.COM BV
 
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License version 2 as 
@@ -150,7 +150,7 @@ public:
   virtual std::string getZoneRepresentation() const = 0;
   virtual ~DNSRecordContent() {}
   virtual void toPacket(DNSPacketWriter& pw)=0;
-  virtual string serialize(const string& qname, bool canonic=false) // it would rock if this were const, but it is too hard
+  virtual string serialize(const string& qname, bool canonic=false, bool lowerCase=false) // it would rock if this were const, but it is too hard
   {
     vector<uint8_t> packet;
     string empty;
@@ -158,6 +158,9 @@ public:
     if(canonic)
       pw.setCanonic(true);
 
+    if(lowerCase)
+      pw.setLowercase(true);
+
     pw.startRecord(qname, d_qtype);
     this->toPacket(pw);
     pw.commit();
index 6b20626c5211ffcadb5bf56fede3bcc934d8c0f1..33e0acf5563ad02175bd13883d81bca4898dce5e 100644 (file)
@@ -206,7 +206,7 @@ void makeRSAPublicKeyFromDNS(rsa_context* rc, const DNSKEYRecordContent& dkrc)
 
 bool sharedDNSSECCompare(const shared_ptr<DNSRecordContent>& a, const shared_ptr<DNSRecordContent>& b)
 {
-  return a->serialize("", true) < b->serialize("", true);
+  return a->serialize("", true, true) < b->serialize("", true, true);
 }
 
 string getSHA1HashForRRSET(const std::string& qname, const RRSIGRecordContent& rrc, vector<shared_ptr<DNSRecordContent> >& signRecords) 
@@ -214,7 +214,7 @@ string getSHA1HashForRRSET(const std::string& qname, const RRSIGRecordContent& r
   sort(signRecords.begin(), signRecords.end(), sharedDNSSECCompare);
 
   string toHash;
-  toHash.append(const_cast<RRSIGRecordContent&>(rrc).serialize("", true));
+  toHash.append(const_cast<RRSIGRecordContent&>(rrc).serialize("", true, true));
   toHash.resize(toHash.size() - rrc.d_signature.length()); // chop off the end;
   //  cerr<<"toHash start size: "<<toHash.size()<<", signature length: "<<rrc.d_signature.length()<<endl;
 
@@ -228,7 +228,7 @@ string getSHA1HashForRRSET(const std::string& qname, const RRSIGRecordContent& r
     toHash.append((char*)&tmp, 2);
     uint32_t ttl=htonl(rrc.d_originalttl);
     toHash.append((char*)&ttl, 4);
-    string rdata=add->serialize("", true);  // case issues hiding here..
+    string rdata=add->serialize("", true, true); 
     tmp=htons(rdata.length());
     toHash.append((char*)&tmp, 2);
     toHash.append(rdata);
@@ -243,7 +243,7 @@ DSRecordContent makeDSFromDNSKey(const std::string& qname, const DNSKEYRecordCon
 {
   string toHash;
   toHash.assign(toLower(simpleCompress(qname)));
-  toHash.append(const_cast<DNSKEYRecordContent&>(drc).serialize("", true));
+  toHash.append(const_cast<DNSKEYRecordContent&>(drc).serialize("", true, true));
 
   unsigned char hash[32];
   if(digest==1)
index f4e664ff79d780c1ffe4708302b7a60ab8b01c0d..644406b9cd34130441b35d11eeef96dffcf1ce10 100644 (file)
@@ -6,7 +6,7 @@
 #include <limits.h>
 
 DNSPacketWriter::DNSPacketWriter(vector<uint8_t>& content, const string& qname, uint16_t  qtype, uint16_t qclass, uint8_t opcode)
-  : d_pos(0), d_content(content), d_qname(qname), d_qtype(qtype), d_qclass(qclass), d_canonic(false)
+  : d_pos(0), d_content(content), d_qname(qname), d_qtype(qtype), d_qclass(qclass), d_canonic(false), d_lowerCase(false)
 {
   d_content.clear();
   dnsheader dnsheader;
@@ -197,8 +197,9 @@ bool labeltokUnescape(labelparts_t& parts, const string& label)
 }
 
 // this is the absolute hottest function in the pdns recursor 
-void DNSPacketWriter::xfrLabel(const string& label, bool compress)
+void DNSPacketWriter::xfrLabel(const string& Label, bool compress)
 {
+  string label = d_lowerCase ? toLower(Label) : Label;
   labelparts_t parts;
 
   if(d_canonic)
index f62cbcb84c83bd284c4c31d2d4edc1fec1bf2afd..8c8cbe0f20f387115c332c8dcbecc33ff1ccc0ac 100644 (file)
@@ -100,6 +100,12 @@ public:
     d_canonic=val;
   }
 
+  void setLowercase(bool val) 
+  {
+    d_lowerCase=val;
+  }
+
+
 private:
   vector <uint8_t>& d_content;
   vector <uint8_t> d_record;
@@ -113,7 +119,7 @@ private:
   uint16_t d_sor;
   uint16_t d_rollbackmarker; // start of last complete packet, for rollback
   Place d_recordplace;
-  bool d_canonic;
+  bool d_canonic, d_lowerCase;
 };
 
 typedef vector<pair<string::size_type, string::size_type> > labelparts_t;
index c250ca69cb8f76309f7cb210656fa475d8226003..92a4c01099b7ef2c06817a2b45d4de339fa8ee78 100644 (file)
@@ -1027,7 +1027,7 @@ void PacketHandler::completeANYRecords(DNSPacket *p, DNSPacket*r, SOAData& sd, c
     cerr<<"Need to add all the RRSIGs too for '"<<target<<"', should do this manually since DNSSEC was not requested"<<endl;
   //  cerr<<"Need to add all the NSEC too.."<<endl; /// XXX FIXME THE ABOVE IF IS WEIRD
   addNSECX(p, r, target, sd.qname, 2); 
-  if(sd.qname == p->qdomain) {
+  if(pdns_iequals(sd.qname, p->qdomain)) {
     DNSSECKeeper::keyset_t zskset = d_dk.getKeys(p->qdomain);
     DNSResourceRecord rr;
     BOOST_FOREACH(DNSSECKeeper::keyset_t::value_type value, zskset) {