Changeset 650

Show
Ignore:
Timestamp:
04/03/06 22:29:20 (4 years ago)
Author:
ahu
Message:

ok, I lied - rfc 4255 has chosen In All Its Wisdom to implement SSHFP as base-16 instead of base-64, like all the other crypto records. This is probably to make cutting & pasting from .ssh/known_hosts easier. Added support for hexadecimal records.

Location:
trunk/pdns/pdns
Files:
7 modified

Legend:

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

    r637 r650  
    391391  d_pos = d_startrecordpos + d_recordlen; 
    392392} 
     393 
     394void PacketReader::xfrHexBlob(string& blob) 
     395{ 
     396  xfrBlob(blob); 
     397} 
  • trunk/pdns/pdns/dnsparser.hh

    r612 r650  
    123123 
    124124  void xfrBlob(string& blob); 
     125  void xfrHexBlob(string& blob); 
    125126 
    126127  static uint16_t get16BitInt(const vector<unsigned char>&content, uint16_t& pos); 
  • trunk/pdns/pdns/dnsrecords.cc

    r649 r650  
    253253                 conv.xfr8BitInt(d_algorithm);  
    254254                 conv.xfr8BitInt(d_fptype);  
    255                  conv.xfrBlob(d_fingerprint); 
     255                 conv.xfrHexBlob(d_fingerprint); 
    256256                 ) 
    257257 
     
    297297   RRSIGRecordContent::report(); 
    298298   DSRecordContent::report(); 
     299   SSHFPRecordContent::report(); 
    299300   NSECRecordContent::report(); 
    300301   OPTRecordContent::report(); 
  • trunk/pdns/pdns/dnswriter.cc

    r643 r650  
    163163} 
    164164 
     165void DNSPacketWriter::xfrHexBlob(const string& blob) 
     166{ 
     167  xfrBlob(blob); 
     168} 
     169 
     170 
    165171void DNSPacketWriter::getRecords(string& records) 
    166172{ 
  • trunk/pdns/pdns/dnswriter.hh

    r517 r650  
    8484  void xfrText(const string& text); 
    8585  void xfrBlob(const string& blob); 
     86  void xfrHexBlob(const string& blob); 
    8687 
    8788  uint16_t d_pos; 
  • trunk/pdns/pdns/rcpgenerator.cc

    r542 r650  
    141141  B64Decode(tmp, val); 
    142142} 
     143 
     144 
     145static inline uint8_t hextodec(uint8_t val) 
     146{ 
     147  if(val >= '0' && val<='9') 
     148    return val-'0'; 
     149  else if(val >= 'A' && val<='F') 
     150    return 10+(val-'A'); 
     151  else if(val >= 'a' && val<='f') 
     152    return 10+(val-'a'); 
     153  else 
     154    throw RecordTextException("Unknown hexadecimal character '"+lexical_cast<string>(val)+"'"); 
     155} 
     156 
     157 
     158void HEXDecode(const char* begin, const char* end, string& val) 
     159{ 
     160  if((end - begin)%2) 
     161    throw RecordTextException("Hexadecimal blob with odd number of characters"); 
     162 
     163  int limit=(end-begin)/2; 
     164  val.resize(limit); 
     165  for(int n=0; n < limit; ++n) { 
     166    val[n] = hextodec(begin[2*n])*16 + hextodec(begin[2*n+1]);  
     167  } 
     168} 
     169 
     170void RecordTextReader::xfrHexBlob(string& val) 
     171{ 
     172  skipSpaces(); 
     173  int pos=d_pos; 
     174  while(d_pos < d_end && !dns_isspace(d_string[d_pos])) 
     175    d_pos++; 
     176 
     177  HEXDecode(d_string.c_str()+pos, d_string.c_str() + d_pos, val); 
     178} 
     179 
    143180 
    144181void RecordTextReader::xfrText(string& val) 
     
    280317} 
    281318 
     319void RecordTextWriter::xfrHexBlob(const string& val) 
     320{ 
     321  if(!d_string.empty()) 
     322    d_string.append(1,' '); 
     323 
     324  string::size_type limit=val.size(); 
     325  char tmp[5]; 
     326  for(string::size_type n = 0; n < limit; ++n) { 
     327    snprintf(tmp, sizeof(tmp)-1, "%02x", (unsigned char)val[n]); 
     328    d_string+=tmp; 
     329  } 
     330} 
     331 
    282332void RecordTextWriter::xfrText(const string& val) 
    283333{ 
  • trunk/pdns/pdns/rcpgenerator.hh

    r510 r650  
    4848  void xfrLabel(string& val, bool compress=false); 
    4949  void xfrText(string& val); 
     50  void xfrHexBlob(string& val); 
    5051  void xfrBlob(string& val); 
    5152 
     
    7374  void xfrText(const string& val); 
    7475  void xfrBlob(const string& val); 
     76  void xfrHexBlob(const string& val); 
    7577 
    7678private: