Changeset 1761

Show
Ignore:
Timestamp:
12/27/10 21:55:18 (2 years ago)
Author:
ahu
Message:

with this commit, ldns-signzone+nsd and 'drill -t axfr' on powerdns and nsd delivers identical results for an NSEC zone!

Location:
trunk/pdns/pdns
Files:
5 modified

Legend:

Unmodified
Added
Removed
  • trunk/pdns/pdns/dnssecinfra.cc

    r1757 r1761  
    150150} 
    151151 
    152 DNSKEYRecordContent makeDNSKEYFromRSAKey(rsa_context* rc, uint8_t algorithm) 
     152DNSKEYRecordContent makeDNSKEYFromRSAKey(const rsa_context* rc, uint8_t algorithm, uint16_t flags) 
    153153{ 
    154154  DNSKEYRecordContent drc; 
     
    176176  drc.d_algorithm = algorithm; 
    177177 
    178   drc.d_flags=256 + (modulus.length()>128);  // oops, I just made this up.. 
     178  drc.d_flags=flags; 
    179179 
    180180  return drc; 
  • trunk/pdns/pdns/dnssecinfra.hh

    r1616 r1761  
    2929bool sharedDNSSECCompare(const boost::shared_ptr<DNSRecordContent>& a, const shared_ptr<DNSRecordContent>& b); 
    3030string getSHA1HashForRRSET(const std::string& qname, const RRSIGRecordContent& rrc, std::vector<boost::shared_ptr<DNSRecordContent> >& signRecords); 
    31 DNSKEYRecordContent makeDNSKEYFromRSAKey(rsa_context* rc, uint8_t algorithm); 
     31DNSKEYRecordContent makeDNSKEYFromRSAKey(const rsa_context* rc, uint8_t algorithm, uint16_t flags); 
    3232DSRecordContent makeDSFromDNSKey(const std::string& qname, const DNSKEYRecordContent& drc, int digest=1); 
    3333 
  • trunk/pdns/pdns/dnsseckeeper.hh

    r1757 r1761  
    5656  } 
    5757 
    58   rsa_context& getContext() 
     58  const rsa_context& getConstContext() const 
    5959  { 
    6060    return d_context; 
    6161  } 
     62 
     63  rsa_context& getContext()  
     64  { 
     65    return d_context; 
     66  } 
     67 
    6268 
    6369  void create(unsigned int bits); 
     
    7884   
    7985  RSAContext d_key; 
    80   DNSKEYRecordContent getDNSKEY(); 
     86  DNSKEYRecordContent getDNSKEY() const; 
    8187  uint8_t d_algorithm; 
     88  uint16_t d_flags; 
    8289}; 
    8390 
  • trunk/pdns/pdns/fsdnsseckeeper.cc

    r1760 r1761  
    6969  } 
    7070  return !keys.empty(); 
    71    
    72   #if 0 
    73   fs::path full_path = fs::system_complete( fs::path(d_dirname + "/" + zone + "/keys/" ) ); 
    74  
    75   if ( !fs::exists( full_path ) ) 
    76     return false; 
    77  
    78   fs::directory_iterator end_iter; 
    79   for ( fs::directory_iterator dir_itr( full_path ); 
    80         dir_itr != end_iter; 
    81         ++dir_itr ) 
    82   { 
    83     //    cerr<<"Entry: '"<< dir_itr->leaf() <<"'"<<endl; 
    84     if(ends_with(dir_itr->leaf(),".private")) { 
    85       //      cerr<<"Hit!"<<endl; 
    86  
    87       if(dpk) { 
    88         getRSAKeyFromISC(&dpk->d_key.getContext(), dir_itr->path().file_string().c_str()); 
    89          
    90         if(getNSEC3PARAM(zone)) { 
    91           dpk->d_algorithm = 7; 
    92         } 
    93         else { 
    94           dpk->d_algorithm = 5; 
    95         } 
    96        
    97       } 
    98       return true; 
    99     } 
    100   } 
    101  
    102   return false; 
    103   #endif 
    10471} 
    10572 
     
    12996 
    13097  if ( !fs::exists( full_path ) ) 
    131     unixDie("Unable to get free key id from '"+dirname+"'"); 
     98    unixDie("Unable to get filname key id from '"+dirname+"'"); 
    13299 
    133100  fs::directory_iterator end_iter; 
     
    137104    ++dir_itr ) 
    138105  { 
     106    if(!ends_with(dir_itr->leaf(), ".private")) 
     107      continue; 
    139108    parts = splitField(dir_itr->leaf(), '-'); 
    140109          if(atoi(parts.first.c_str()) == (signed int)id)  
     
    152121  string isc = dpk.d_key.convertToISC(); 
    153122  DNSKEYRecordContent drc = dpk.getDNSKEY(); 
    154   drc.d_flags = 256; // KSK 
     123  drc.d_flags = 256 + keyOrZone; // KSK 
    155124  drc.d_algorithm = algorithm;  
    156125  string iscName=d_dirname+"/"+name+"/keys/"; 
     
    189158void DNSSECKeeper::removeKey(const std::string& zname, unsigned int id) 
    190159{ 
    191   string fname = getKeyFilenameById(d_dirname+"/keys/", id); 
     160  string fname = getKeyFilenameById(d_dirname+"/"+zname+"/keys", id); 
    192161  if(unlink(fname.c_str()) < 0) 
    193162    unixDie("removing key file '"+fname+"'"); 
     
    196165void DNSSECKeeper::deactivateKey(const std::string& zname, unsigned int id) 
    197166{ 
    198   string fname = getKeyFilenameById(d_dirname+"/keys/", id); 
     167  string fname = getKeyFilenameById(d_dirname+"/"+zname+"/keys/", id); 
    199168  string newname = boost::replace_last_copy(fname, ".active", ".passive"); 
    200169  if(rename(fname.c_str(), newname.c_str()) < 0) 
     
    204173void DNSSECKeeper::activateKey(const std::string& zname, unsigned int id) 
    205174{ 
    206   string fname = getKeyFilenameById(d_dirname+"/keys/", id); 
     175  string fname = getKeyFilenameById(d_dirname+"/"+zname+"/keys/", id); 
    207176  string newname = boost::replace_last_copy(fname, ".passive", ".active"); 
    208177  if(rename(fname.c_str(), newname.c_str()) < 0) 
     
    275244        dpk.d_algorithm = 5; 
    276245      } 
    277        
    278246      struct tm ts1, ts2; 
    279247       
     
    296264      kmd.active = kmd.fname.find(".active") != string::npos; 
    297265      kmd.keyOrZone = kmd.fname.find(".ksk") != string::npos; 
     266       
     267      dpk.d_flags = 256 + kmd.keyOrZone;  // this is a clear sign we've got our abstractions wrong! FIXME XXX 
     268       
    298269      if(boost::indeterminate(allOrKeyOrZone) || allOrKeyOrZone == kmd.keyOrZone) 
    299270        keyset.push_back(make_pair(dpk, kmd)); 
     
    305276} 
    306277 
    307 DNSKEYRecordContent DNSSECPrivateKey::getDNSKEY() 
    308 { 
    309   return makeDNSKEYFromRSAKey(&d_key.getContext(), d_algorithm); 
     278DNSKEYRecordContent DNSSECPrivateKey::getDNSKEY() const 
     279{ 
     280  return makeDNSKEYFromRSAKey(&d_key.getConstContext(), d_algorithm, d_flags); 
    310281} 
    311282 
  • trunk/pdns/pdns/tcpreceiver.cc

    r1563 r1761  
    1919#include "utility.hh" 
    2020#include "dnssecinfra.hh" 
     21#include "dnsseckeeper.hh" 
    2122#include <cstdio> 
    2223#include <cstring> 
     
    457458  outpacket->addRecord(soa); // AXFR format begins and ends with a SOA record, so we add one 
    458459  //  sendPacket(outpacket, outsock); 
     460  typedef map<string, set<uint16_t>, CanonicalCompare> nsecrepo_t; 
     461  nsecrepo_t nsecrepo; 
     462  // this is where the DNSKEYs go 
     463   
     464  DNSSECKeeper dk(::arg()["key-repository"]); 
     465  DNSSECKeeper::keyset_t keys = dk.getKeys(target); 
     466  BOOST_FOREACH(const DNSSECKeeper::keyset_t::value_type& value, keys) { 
     467    rr.qname = target; 
     468    rr.qtype = QType(QType::DNSKEY); 
     469    rr.ttl = 3600; 
     470    rr.content = value.first.getDNSKEY().getZoneRepresentation(); 
     471    nsecrepo[rr.qname].insert(rr.qtype.getCode()); 
     472    outpacket->addRecord(rr); 
     473  } 
    459474 
    460475  /* now write all other records */ 
     
    469484  outpacket->d_dnssecOk=true; // WRONG 
    470485 
    471   typedef map<string, set<uint16_t>, CanonicalCompare> nsecrepo_t; 
    472   nsecrepo_t nsecrepo; 
     486 
    473487 
    474488  while(B->get(rr)) {