Changeset 1555

Show
Ignore:
Timestamp:
04/18/10 15:52:44 (3 years ago)
Author:
ahu
Message:

commit more DNSSEC infrastructure, plus NSEC3 builder

Location:
trunk/pdns/pdns
Files:
7 modified

Legend:

Unmodified
Added
Removed
  • trunk/pdns/pdns/Makefile.am

    r1485 r1555  
    2121 
    2222EXTRA_PROGRAMS=pdns_recursor sdig tsig-tests speedtest dnspbench pdns_control dnsscope dnsgram \ 
    23  dnsdemog dnswasher dnsreplay dnsscan dnslog nproxy notify 
     23 dnsdemog dnswasher dnsreplay dnsscan dnslog nproxy notify  
    2424 
    2525pdns_server_SOURCES=dnspacket.cc nameserver.cc tcpreceiver.hh \ 
     
    4343aes/aescrypt.c aes/aes.h aes/aeskey.c aes/aes_modes.c aes/aesopt.h \ 
    4444aes/aestab.c aes/aestab.h aes/brg_endian.h aes/brg_types.h aes/dns_random.cc \ 
    45 randomhelper.cc namespaces.hh 
     45randomhelper.cc namespaces.hh nsecrecords.cc base32.cc 
    4646 
    4747# 
  • trunk/pdns/pdns/common_startup.cc

    r1472 r1555  
    100100  ::arg().set("webserver-port","Port of webserver to listen on")="8081"; 
    101101  ::arg().set("webserver-password","Password required for accessing the webserver")=""; 
     102  ::arg().set("key-repository", "Where DNSSEC keying material lives")="./keys"; 
    102103 
    103104  ::arg().setSwitch("out-of-zone-additional-processing","Do out of zone additional processing")="yes"; 
  • trunk/pdns/pdns/dnsrecords.cc

    r1472 r1555  
    9191 
    9292 
    93 void NSECRecordContent::report(void) 
    94 { 
    95   regist(1, 47, &make, &make, "NSEC"); 
    96 } 
    97  
    98 DNSRecordContent* NSECRecordContent::make(const string& content) 
    99 { 
    100   return new NSECRecordContent(content); 
    101 } 
    102  
    103 NSECRecordContent::NSECRecordContent(const string& content, const string& zone) : DNSRecordContent(47) 
    104 { 
    105   RecordTextReader rtr(content, zone); 
    106   rtr.xfrLabel(d_next); 
    107  
    108   while(!rtr.eof()) { 
    109     uint16_t type; 
    110     rtr.xfrType(type); 
    111     d_set.insert(type); 
    112   } 
    113 } 
    114  
    115 void NSECRecordContent::toPacket(DNSPacketWriter& pw) 
    116 { 
    117   pw.xfrLabel(d_next); 
    118  
    119   uint8_t res[34]; 
    120   memset(res, 0, sizeof(res)); 
    121  
    122   set<uint16_t>::const_iterator i; 
    123   for(i=d_set.begin(); i != d_set.end() && *i<255; ++i){ 
    124     res[2+*i/8] |= 1 << (7-(*i%8)); 
    125   } 
    126   int len=0; 
    127   if(!d_set.empty())  
    128     len=1+*--i/8; 
    129  
    130   res[1]=len; 
    131  
    132   string tmp; 
    133   tmp.assign(res, res+len+2); 
    134   pw.xfrBlob(tmp); 
    135 } 
    136  
    137 NSECRecordContent::DNSRecordContent* NSECRecordContent::make(const DNSRecord &dr, PacketReader& pr)  
    138 { 
    139   NSECRecordContent* ret=new NSECRecordContent(); 
    140   pr.xfrLabel(ret->d_next); 
    141   string bitmap; 
    142   pr.xfrBlob(bitmap); 
    143    
    144   // 00 06 20 00 00 00 00 03  -> NS RRSIG NSEC  ( 2, 46, 47 ) counts from left 
    145    
    146   if(bitmap.size() < 2) 
    147     throw MOADNSException("NSEC record with impossibly small bitmap"); 
    148    
    149   if(bitmap[0]) 
    150     throw MOADNSException("Can't deal with NSEC mappings > 255 yet"); 
    151    
    152   unsigned int len=bitmap[1]; 
    153   if(bitmap.size()!=2+len) 
    154     throw MOADNSException("Can't deal with multi-part NSEC mappings yet"); 
    155    
    156   for(unsigned int n=0 ; n < len ; ++n) { 
    157     uint8_t val=bitmap[2+n]; 
    158     for(int bit = 0; bit < 8 ; ++bit , val>>=1) 
    159       if(val & 1) { 
    160         ret->d_set.insert((7-bit) + 8*(n)); 
    161       } 
    162   } 
    163    
    164   return ret; 
    165 } 
    166  
    167 string NSECRecordContent::getZoneRepresentation() const 
    168 { 
    169   string ret; 
    170   RecordTextWriter rtw(ret); 
    171   rtw.xfrLabel(d_next); 
    172    
    173   for(set<uint16_t>::const_iterator i=d_set.begin(); i!=d_set.end(); ++i) { 
    174     ret+=" "; 
    175     ret+=NumberToType(*i); 
    176   } 
    177    
    178   return ret; 
    179 } 
    18093 
    18194boilerplate_conv(NS, ns_t_ns, conv.xfrLabel(d_content, true)); 
     
    310223                 ) 
    311224#undef DS 
     225DSRecordContent::DSRecordContent() : DNSRecordContent(43) {} 
    312226boilerplate_conv(DS, 43,  
    313227                 conv.xfr16BitInt(d_tag);  
     
    336250                 ) 
    337251                  
     252RRSIGRecordContent::RRSIGRecordContent() : DNSRecordContent(46) {} 
     253 
    338254boilerplate_conv(DNSKEY, 48,  
    339255                 conv.xfr16BitInt(d_flags);  
     
    342258                 conv.xfrBlob(d_key); 
    343259                 ) 
     260DNSKEYRecordContent::DNSKEYRecordContent() : DNSRecordContent(48) {} 
     261 
     262uint16_t DNSKEYRecordContent::getTag() 
     263{ 
     264  string data=this->serialize(""); 
     265  const unsigned char* key=(const unsigned char*)data.c_str(); 
     266  unsigned int keysize=data.length(); 
     267 
     268  unsigned long ac;     /* assumed to be 32 bits or larger */ 
     269  unsigned int i;                /* loop index */ 
     270   
     271  for ( ac = 0, i = 0; i < keysize; ++i ) 
     272    ac += (i & 1) ? key[i] : key[i] << 8; 
     273  ac += (ac >> 16) & 0xFFFF; 
     274  return ac & 0xFFFF; 
     275} 
     276 
     277void DNSKEYRecordContent::getExpLen(uint16_t& startPos, uint16_t& expLen) const 
     278{ 
     279  unsigned char* decoded=(unsigned char*) d_key.c_str(); 
     280  if(decoded[0] != 0) { 
     281    startPos=1; 
     282    expLen=decoded[0]; 
     283  } 
     284  else { 
     285    startPos=3; 
     286    expLen=decoded[1]*0xff + decoded[2]; // XXX FIXME 
     287  } 
     288} 
     289 
     290string DNSKEYRecordContent::getExponent() const 
     291{ 
     292  uint16_t startPos, expLen; 
     293  getExpLen(startPos, expLen); 
     294  return d_key.substr(startPos, expLen); 
     295} 
     296 
     297string DNSKEYRecordContent::getModulus() const 
     298{ 
     299  uint16_t startPos, expLen; 
     300  getExpLen(startPos, expLen); 
     301 
     302  return d_key.substr(startPos+expLen); 
     303} 
     304 
    344305 
    345306// "fancy records"  
     
    408369   CERTRecordContent::report(); 
    409370   NSECRecordContent::report(); 
     371   NSEC3RecordContent::report(); 
     372   NSEC3PARAMRecordContent::report(); 
    410373   DNSRecordContent::regist(0xff, QType::TSIG, &TSIGRecordContent::make, &TSIGRecordContent::make, "TSIG"); 
    411374   OPTRecordContent::report(); 
  • trunk/pdns/pdns/dnsrecords.hh

    r1526 r1555  
    11/* 
    22    PowerDNS Versatile Database Driven Nameserver 
    3     Copyright (C) 2005 - 2007  PowerDNS.COM BV 
     3    Copyright (C) 2005 - 2009  PowerDNS.COM BV 
    44 
    55    This program is free software; you can redistribute it and/or modify 
     
    228228{ 
    229229public: 
     230  DNSKEYRecordContent(); 
    230231  includeboilerplate(DNSKEY) 
    231  
    232 private: 
     232  uint16_t getTag(); 
     233  string getExponent() const; 
     234  string getModulus() const; 
     235 
    233236  uint16_t d_flags; 
    234237  uint8_t d_protocol; 
    235238  uint8_t d_algorithm; 
    236239  string d_key; 
     240private: 
     241  void getExpLen(uint16_t& startPos, uint16_t& expLen) const; 
    237242}; 
    238243 
     
    240245{ 
    241246public: 
     247  DSRecordContent(); 
    242248  includeboilerplate(DS) 
    243249 
    244 private: 
    245250  uint16_t d_tag; 
    246251  uint8_t d_algorithm, d_digesttype; 
     
    294299{ 
    295300public: 
     301  RRSIGRecordContent();  
    296302  includeboilerplate(RRSIG) 
    297303 
    298 private: 
    299304  uint16_t d_type; 
    300305  uint8_t d_algorithm, d_labels; 
     
    329334}; 
    330335 
    331 class HIPRecordContent : public DNSRecordContent 
    332 { 
    333 public: 
    334   includeboilerplate(HIP) 
    335   HIPRecordContent(uint8_t algorithm, const string& hit, const string& key); 
    336 }; 
    337  
    338  
    339336class NSECRecordContent : public DNSRecordContent 
    340337{ 
     
    353350private: 
    354351}; 
     352 
     353class NSEC3RecordContent : public DNSRecordContent 
     354{ 
     355public: 
     356  static void report(void); 
     357  NSEC3RecordContent() : DNSRecordContent(50) 
     358  {} 
     359  NSEC3RecordContent(const string& content, const string& zone=""); 
     360 
     361  static DNSRecordContent* make(const DNSRecord &dr, PacketReader& pr); 
     362  static DNSRecordContent* make(const string& content); 
     363  string getZoneRepresentation() const; 
     364  void toPacket(DNSPacketWriter& pw); 
     365 
     366  uint8_t d_algorithm, d_flags; 
     367  uint16_t d_iterations; 
     368  uint8_t d_saltlength; 
     369  string d_salt; 
     370  uint8_t d_nexthashlength; 
     371  string d_nexthash; 
     372  std::set<uint16_t> d_set; 
     373 
     374private: 
     375}; 
     376 
     377 
     378class NSEC3PARAMRecordContent : public DNSRecordContent 
     379{ 
     380public: 
     381  includeboilerplate(NSEC3PARAM) 
     382 
     383  uint8_t d_algorithm, d_flags; 
     384  uint16_t d_iterations; 
     385  uint8_t d_saltlength; 
     386  string d_salt; 
     387}; 
     388 
    355389 
    356390class LOCRecordContent : public DNSRecordContent 
  • trunk/pdns/pdns/nsecrecords.cc

    r1472 r1555  
    6868    for(int bit = 0; bit < 8 ; ++bit , val>>=1) 
    6969      if(val & 1) { 
    70         ret->d_set.insert((7-bit) + 8*(n)); 
     70        ret->d_set.insert((7-bit) + 8*(n)); 
    7171      } 
    7272  } 
     
    182182    for(int bit = 0; bit < 8 ; ++bit , val>>=1) 
    183183      if(val & 1) { 
    184         ret->d_set.insert((7-bit) + 8*(n)); 
     184        ret->d_set.insert((7-bit) + 8*(n)); 
    185185      } 
    186186  } 
     
    198198 
    199199  rtw.xfrHexBlob(d_salt); 
    200   rtw.xfrHexBlob(d_nexthash); 
     200  rtw.xfrBase32HexBlob(d_nexthash); 
    201201   
    202202  for(set<uint16_t>::const_iterator i=d_set.begin(); i!=d_set.end(); ++i) { 
     
    210210 
    211211boilerplate_conv(NSEC3PARAM, 51,  
    212                  conv.xfr8BitInt(d_algorithm);  
    213                  conv.xfr8BitInt(d_flags);  
    214                  conv.xfr16BitInt(d_iterations);  
    215                  conv.xfr8BitInt(d_saltlength);  
    216                  conv.xfrHexBlob(d_salt); 
    217                  ) 
     212                 conv.xfr8BitInt(d_algorithm);  
     213                 conv.xfr8BitInt(d_flags);  
     214                 conv.xfr16BitInt(d_iterations);  
     215                 conv.xfr8BitInt(d_saltlength);  
     216                 conv.xfrHexBlob(d_salt); 
     217                 ) 
  • trunk/pdns/pdns/rcpgenerator.cc

    r1547 r1555  
    2323#include <boost/algorithm/string.hpp> 
    2424#include <iostream> 
     25#include "base32.hh" 
    2526#include "base64.hh" 
    2627#include "namespaces.hh" 
     
    244245  HEXDecode(d_string.c_str()+pos, d_string.c_str() + d_pos, val); 
    245246} 
     247 
     248void RecordTextWriter::xfrBase32HexBlob(const string& val) 
     249{ 
     250  if(!d_string.empty()) 
     251    d_string.append(1,' '); 
     252 
     253  d_string.append(toBase32Hex(val)); 
     254} 
     255 
    246256 
    247257void RecordTextReader::xfrText(string& val, bool multi) 
  • trunk/pdns/pdns/rcpgenerator.hh

    r1440 r1555  
    5555  void xfrText(string& val, bool multi=false); 
    5656  void xfrHexBlob(string& val); 
     57 
     58 
    5759  void xfrBlob(string& val, int len=-1); 
    5860 
     
    7678  void xfrIP(const uint32_t& val); 
    7779  void xfrTime(const uint32_t& val); 
     80  void xfrBase32HexBlob(const string& val); 
    7881 
    7982  void xfrType(const uint16_t& val);