Changeset 1160

Show
Ignore:
Timestamp:
03/16/08 15:58:19 (5 years ago)
Author:
ahu
Message:

move to a real CSRNG, plus hooks for 'dns-0x20'.

Location:
trunk/pdns/pdns
Files:
6 modified

Legend:

Unmodified
Added
Removed
  • trunk/pdns/pdns/Makefile-recursor

    r1028 r1160  
    1414arguments.o lwres.o pdns_recursor.o recursor_cache.o dnsparser.o \ 
    1515dnswriter.o dnsrecords.o rcpgenerator.o base64.o zoneparser-tng.o \ 
    16 rec_channel.o rec_channel_rec.o malloc.o selectmplexer.o sillyrecords.o 
     16rec_channel.o rec_channel_rec.o malloc.o selectmplexer.o sillyrecords.o \ 
     17dns_random.o aescrypt.o aeskey.o aes_modes.o aestab.o 
     18 
    1719 
    1820REC_CONTROL_OBJECTS=rec_channel.o rec_control.o arguments.o  
     
    6971         
    7072dep: 
    71         $(CXX) $(CXXFLAGS) -MM -MG *.cc *.hh > $@ 
     73        $(CXX) $(CXXFLAGS) -MM -MG *.cc *.c *.hh > $@ 
    7274 
    7375-include dep 
  • trunk/pdns/pdns/Makefile.am

    r1094 r1160  
    3939base64.cc sillyrecords.cc \ 
    4040base64.hh zoneparser-tng.cc dnsrecords.cc dnswriter.cc \ 
    41 rcpgenerator.cc  dnsparser.cc 
     41rcpgenerator.cc dnsparser.cc \ 
     42aes/dns_random.cc aes/aescrypt.c aes/aeskey.c aes/aestab.c aes/aes_modes.c 
    4243 
    4344# 
     
    111112        utility.hh dnsparser.hh sillyrecords.cc 
    112113 
    113  
    114  
    115  
    116 # INCLUDES=-I/usr/include/mysql 
    117  
    118114rec_control_SOURCES=rec_channel.cc rec_channel.hh rec_control.cc arguments.cc arguments.hh 
    119115 
     
    123119dnswriter.cc dnswriter.hh dnsrecords.cc dnsrecords.hh rcpgenerator.cc rcpgenerator.hh \ 
    124120base64.cc base64.hh zoneparser-tng.cc zoneparser-tng.hh rec_channel.cc rec_channel.hh \ 
    125 rec_channel_rec.cc selectmplexer.cc epollmplexer.cc sillyrecords.cc htimer.cc htimer.hh 
     121rec_channel_rec.cc selectmplexer.cc epollmplexer.cc sillyrecords.cc htimer.cc htimer.hh \ 
     122aes/dns_random.cc aes/aescrypt.c aes/aeskey.c aes/aestab.c aes/aes_modes.c 
    126123 
    127124if NEDMALLOC 
  • trunk/pdns/pdns/dist-recursor

    r1158 r1160  
    66sstuff.hh mtasker.hh mtasker.cc lwres.hh logger.hh ahuexception.hh \ 
    77mplexer.hh win32_mtasker.hh win32_utility.cc ntservice.hh singleton.hh \ 
    8 recursorservice.hh" 
     8recursorservice.hh dns_random.hh" 
    99 
    1010CFILES="syncres.cc  misc.cc unix_utility.cc qtype.cc \ 
     
    3232cp tools/rrd/{create,update,makegraphs,index.html} $DIRNAME/rrd 
    3333cp ext/dlmalloc/malloc.{c,h} $DIRNAME 
     34cp aes/*.{c,cc,h} $DIRNAME 
    3435cp pdns-recursor.init.d $DIRNAME 
    3536cp docs/pdns_recursor.1 docs/rec_control.1 $DIRNAME 
  • trunk/pdns/pdns/lwres.cc

    r1130 r1160  
    11/* 
    22    PowerDNS Versatile Database Driven Nameserver 
    3     Copyright (C) 2002 - 2007 PowerDNS.COM BV 
     3    Copyright (C) 2002 - 2008 PowerDNS.COM BV 
    44 
    55    This program is free software; you can redistribute it and/or modify 
     
    3737#include "dnsparser.hh" 
    3838#include "logger.hh" 
     39#include "dns_random.hh" 
    3940#include <boost/scoped_array.hpp> 
     41#include <boost/algorithm/string.hpp> 
     42 
     43string dns0x20(const std::string& in) 
     44{ 
     45  string ret(in); 
     46  string::size_type len=ret.size(); 
     47  for(string::size_type pos = 0 ; pos < len; ++pos) { 
     48    if(isalpha(in[pos]) && dns_random(2)) 
     49      ret[pos]^=0x20; 
     50  } 
     51  //  cerr<<"'"<<in<<"' -> '"<<ret<<"'\n"; 
     52  return ret; 
     53} 
    4054 
    4155//! returns -2 for OS limits error, -1 for permanent error that has to do with remote, 0 for timeout, 1 for success 
     
    4761  scoped_array<unsigned char> buf(new unsigned char[bufsize]); 
    4862  vector<uint8_t> vpacket; 
     63  //  string mapped0x20=dns0x20(domain); 
    4964  DNSPacketWriter pw(vpacket, domain, type); 
    5065 
    5166  pw.getHeader()->rd=0; 
    52   pw.getHeader()->id=Utility::random(); 
     67  pw.getHeader()->id=dns_random(0xffff); 
    5368 
    5469  if(doEDNS0 && !doTCP) { 
     
    141156      goto out; 
    142157    } 
    143      
     158 
    144159    for(MOADNSParser::answers_t::const_iterator i=mdp.d_answers.begin(); i!=mdp.d_answers.end(); ++i) {           
    145160      DNSResourceRecord rr; 
    146161      rr.qtype=i->first.d_type; 
    147162      rr.qname=i->first.d_label; 
     163      /*  
     164      if(i->first.d_label == mapped0x20) 
     165        rr.qname=domain; 
     166      else 
     167        rr.qname=i->first.d_label; 
     168      */ 
    148169      rr.ttl=i->first.d_ttl; 
    149170      rr.content=i->first.d_content->getZoneRepresentation();  // this should be the serialised form 
  • trunk/pdns/pdns/pdns_recursor.cc

    r1150 r1160  
    2626 
    2727#include "utility.hh"  
     28#include "dns_random.hh" 
    2829#include <iostream> 
    2930#include <errno.h> 
     
    15911592} 
    15921593 
     1594void seedRandom(const string& source); 
     1595 
    15931596int serviceMain(int argc, char*argv[]) 
    15941597{ 
     
    16051608  } 
    16061609 
    1607   L<<Logger::Warning<<"PowerDNS recursor "<<VERSION<<" (C) 2001-2007 PowerDNS.COM BV ("<<__DATE__", "__TIME__; 
     1610  L<<Logger::Warning<<"PowerDNS recursor "<<VERSION<<" (C) 2001-2008 PowerDNS.COM BV ("<<__DATE__", "__TIME__; 
    16081611#ifdef __GNUC__ 
    16091612  L<<", gcc "__VERSION__; 
     
    16191622   
    16201623  L<<Logger::Warning<<"Operating in "<<(sizeof(unsigned long)*8) <<" bits mode"<<endl; 
     1624   
     1625  seedRandom(::arg()["entropy-source"]); 
    16211626 
    16221627  if(!::arg()["allow-from-file"].empty()) { 
     
    18241829#endif 
    18251830 
     1831void seedRandom(const string& source) 
     1832{ 
     1833  L<<Logger::Warning<<"Reading random entropy from '"<<source<<"'"<<endl; 
     1834 
     1835  int fd=open(source.c_str(), O_RDONLY); 
     1836  if(fd < 0) { 
     1837    L<<Logger::Error<<"Unable to open source of random '"<<source<<"': "<<stringerror()<<endl; 
     1838    exit(EXIT_FAILURE); 
     1839  } 
     1840  char seed[128]; 
     1841  int ret; 
     1842  int pos=0; 
     1843  while(pos!=sizeof(seed)) { 
     1844    ret = read(fd, seed+pos, sizeof(seed)-pos); 
     1845    if(ret < 0) {  
     1846      L<<Logger::Error<<"Unable to read random seed from "<<source<<": "<<stringerror()<<endl; 
     1847      close(fd); 
     1848      exit(EXIT_FAILURE); 
     1849    } 
     1850    if(!ret) { 
     1851      L<<Logger::Error<<"Unable to read random seed from "<<source<<": end of file"<<endl; 
     1852      close(fd); 
     1853      exit(EXIT_FAILURE); 
     1854    } 
     1855    pos+=ret; 
     1856  } 
     1857  close(fd); 
     1858  dns_random_init(seed); 
     1859} 
     1860 
    18261861int main(int argc, char **argv)  
    18271862{ 
     
    18431878 
    18441879  try { 
    1845     Utility::srandom(time(0)); 
    18461880    ::arg().set("stack-size","stack size per mthread")="200000"; 
    18471881    ::arg().set("soa-minimum-ttl","Don't change")="0"; 
     
    18841918    ::arg().set("allow-from", "If set, only allow these comma separated netmasks to recurse")="127.0.0.0/8, 10.0.0.0/8, 192.168.0.0/16, 172.16.0.0/12, ::1/128, fe80::/10"; 
    18851919    ::arg().set("allow-from-file", "If set, load allowed netmasks from this file")=""; 
     1920    ::arg().set("entropy-source", "If set, read entropy from this file")="/dev/urandom"; 
    18861921    ::arg().set("dont-query", "If set, do not query these netmasks for DNS data")="127.0.0.0/8, 10.0.0.0/8, 192.168.0.0/16, 172.16.0.0/12, ::1/128, fe80::/10"; 
    18871922    ::arg().set("max-tcp-per-client", "If set, maximum number of TCP sessions per client (IP address)")="0"; 
     
    19281963    } 
    19291964 
     1965 
    19301966#ifndef WIN32 
    19311967    serviceMain(argc, argv); 
  • trunk/pdns/pdns/syncres.cc

    r1157 r1160  
    3535#include "recursor_cache.hh" 
    3636#include "dnsparser.hh" 
     37#include "dns_random.hh" 
    3738 
    3839extern MemRecursorCache RC; 
     
    277278   
    278279  if(ret.size() > 1) { 
    279     random_shuffle(ret.begin(), ret.end()); 
     280    random_shuffle(ret.begin(), ret.end(), dns_random); 
    280281 
    281282    // move 'best' address for this nameserver name up front 
     
    543544    speeds[*i]=s_nsSpeeds[*i].get(&d_now); 
    544545  } 
    545   random_shuffle(rnameservers.begin(),rnameservers.end()); 
     546  random_shuffle(rnameservers.begin(),rnameservers.end(), dns_random); 
    546547  speedOrder so(speeds); 
    547548  stable_sort(rnameservers.begin(),rnameservers.end(), so);