]> granicus.if.org Git - pdns/commitdiff
make dnsseckeeper & dnssecinfra code, plus pdnssec, aware of non-RSASHA1 algorithms...
authorBert Hubert <bert.hubert@netherlabs.nl>
Fri, 7 Jan 2011 23:57:48 +0000 (23:57 +0000)
committerBert Hubert <bert.hubert@netherlabs.nl>
Fri, 7 Jan 2011 23:57:48 +0000 (23:57 +0000)
git-svn-id: svn://svn.powerdns.com/pdns/trunk/pdns@1835 d19b8d6e-7fed-0310-83ef-9ca221ded41b

pdns/dbdnsseckeeper.cc
pdns/dnssecinfra.cc
pdns/pdnssec.cc

index 8361eda9a370d93d40160151c0052f3e3bc44f05..21496de4ae9d328e445d75a99f302e1dfc2299a2 100644 (file)
@@ -37,6 +37,7 @@ void DNSSECKeeper::addKey(const std::string& name, bool keyOrZone, int algorithm
     bits = keyOrZone ? 2048 : 1024;
   DNSSECPrivateKey dpk;
   dpk.d_key.create(bits); 
+  dpk.d_algorithm = algorithm;
   addKey(name, keyOrZone, dpk, active);
 }
 
@@ -45,8 +46,7 @@ void DNSSECKeeper::addKey(const std::string& name, bool keyOrZone, const DNSSECP
   DNSBackend::KeyData kd;
   kd.flags = 256 + keyOrZone;
   kd.active = active;
-  kd.content = dpk.d_key.convertToISC(5);
+  kd.content = dpk.d_key.convertToISC(dpk.d_algorithm);
  // now store it
   d_db.addDomainKey(name, kd);
 }
@@ -67,16 +67,13 @@ DNSSECPrivateKey DNSSECKeeper::getKeyById(const std::string& zname, unsigned int
       continue;
     
     DNSSECPrivateKey dpk;
-
-    getRSAKeyFromISCString(&dpk.d_key.getContext(), kd.content);
+    DNSKEYRecordContent dkrc = getRSAKeyFromISCString(&dpk.d_key.getContext(), kd.content);
     dpk.d_flags = kd.flags;
-    dpk.d_algorithm = 5 + 2*getNSEC3PARAM(zname);
+    dpk.d_algorithm = dkrc.d_algorithm;
     
-    KeyMetaData kmd;
-
-    kmd.active = kd.active;
-    kmd.keyOrZone = (kd.flags == 257);
-    kmd.id = kd.id;
+    if(dpk.d_algorithm == 5 && getNSEC3PARAM(zname)) {
+      dpk.d_algorithm += 2;
+    }
     
     return dpk;    
   }
@@ -159,9 +156,11 @@ DNSSECKeeper::keyset_t DNSSECKeeper::getKeys(const std::string& zone, boost::tri
   {
     DNSSECPrivateKey dpk;
 
-    getRSAKeyFromISCString(&dpk.d_key.getContext(), kd.content);
+    DNSKEYRecordContent dkrc=getRSAKeyFromISCString(&dpk.d_key.getContext(), kd.content);
     dpk.d_flags = kd.flags;
-    dpk.d_algorithm = 5 + 2*getNSEC3PARAM(zone);
+    dpk.d_algorithm = dkrc.d_algorithm;
+    if(dpk.d_algorithm == 5 && getNSEC3PARAM(zone))
+      dpk.d_algorithm+=2;
     
     KeyMetaData kmd;
 
index eec44bfa0f1ca81fd1ab85573fcc584205ceb176..6aba1e020d96ffe367fd0f845c135aa1c974cbad 100644 (file)
@@ -46,7 +46,17 @@ std::string RSAContext::convertToISC(unsigned int algorithm) const
     ("Exponent2",&d_context.DQ)
     ("Coefficient",&d_context.QP);
 
-  ret = "Private-key-format: v1.2\nAlgorithm: "+lexical_cast<string>(algorithm)+" (RSASHA1)\n";
+  ret = "Private-key-format: v1.2\nAlgorithm: "+lexical_cast<string>(algorithm);
+  switch(algorithm) {
+    case 5:
+    case 7 :
+      ret+= " (RSASHA1)";
+      break;
+    case 8:
+      ret += " (RSASHA256)";
+      break;
+  }
+  ret += "\n";
 
   BOOST_FOREACH(outputs_t::value_type value, outputs) {
     ret += value.first;
@@ -95,23 +105,25 @@ DNSKEYRecordContent getRSAKeyFromISC(rsa_context* rsa, const char* fname)
       continue;
     if(places.count(key)) {
       if(places[key]) {
-
-       int len=sizeof(decoded);
-       if(base64_decode(decoded, &len, (unsigned char*)value.c_str(), value.length()) < 0) {
-         cerr<<"Error base64 decoding '"<<value<<"'\n";
-         exit(1);
-       }
-       //      B64Decode(value, decoded);
-       //      cerr<<key<<" decoded.length(): "<<8*len<<endl;
-       mpi_read_binary(places[key], decoded, len);
-       if(key=="Modulus")
-         modulus.assign((const char*)decoded,len);
-       if(key=="PublicExponent")
-         exponent.assign((const char*)decoded,len);
+        int len=sizeof(decoded);
+        if(base64_decode(decoded, &len, (unsigned char*)value.c_str(), value.length()) < 0) {
+          cerr<<"Error base64 decoding '"<<value<<"'\n";
+          exit(1);
+        }
+        //     B64Decode(value, decoded);
+        //     cerr<<key<<" decoded.length(): "<<8*len<<endl;
+        mpi_read_binary(places[key], decoded, len);
+        if(key=="Modulus")
+          modulus.assign((const char*)decoded,len);
+        if(key=="PublicExponent")
+          exponent.assign((const char*)decoded,len);
       }
     }
     else {
-      if(key != "Private-key-format" && key != "Algorithm") 
+      if(key=="Algorithm") {
+        drc.d_algorithm = atoi(value.c_str());
+      }
+      else if(key != "Private-key-format")
         cerr<<"Unknown field '"<<key<<"'\n";
     }
   }
@@ -127,7 +139,6 @@ DNSKEYRecordContent getRSAKeyFromISC(rsa_context* rsa, const char* fname)
   drc.d_key.append(exponent);
   drc.d_key.append(modulus);
   drc.d_protocol=3;
-  drc.d_algorithm = 0; // should not be filled out here..
   fclose(fp);
   return drc;
 }
@@ -175,8 +186,10 @@ DNSKEYRecordContent getRSAKeyFromISCString(rsa_context* rsa, const std::string&
       }
     }
     else {
-      if(key != "Private-key-format" && key != "Algorithm") 
-      cerr<<"Unknown field '"<<key<<"'\n";
+      if(key == "Algorithm") 
+        drc.d_algorithm = atoi(value.c_str());
+      else if(key != "Private-key-format")
+        cerr<<"Unknown field '"<<key<<"'\n";
     }
   }
   rsa->len = ( mpi_msb( &rsa->N ) + 7 ) >> 3; // no clue what this does
@@ -191,7 +204,7 @@ DNSKEYRecordContent getRSAKeyFromISCString(rsa_context* rsa, const std::string&
   drc.d_key.append(exponent);
   drc.d_key.append(modulus);
   drc.d_protocol=3;
-  drc.d_algorithm = 0; // should not be filled out here..
+  
   return drc;
 }
 
index 9349587ac8e8bf408e3d77981e09de57b46c1925..354dd35be89469af31de1933b845bcfd212056cf 100644 (file)
@@ -201,7 +201,8 @@ try
     cerr<<"Usage: \npdnssec [options] [show-zone] [secure-zone] [rectify-zone] [add-zone-key] [deactivate-zone-key] [remove-zone-key] [activate-zone-key]\n";
     cerr<<"         [import-zone-key] [export-zone-key] [set-nsec3] [unset-nsec3] [export-zone-dnskey]\n\n";
     cerr<<"activate-zone-key ZONE KEY-ID   Activate the key with key id KEY-ID in ZONE\n";
-    cerr<<"add-zone-key ZONE [zsk|ksk]     Add a ZSK or KSK to a zone (ZSK only now)\n";
+    cerr<<"add-zone-key ZONE [zsk|ksk] \n";
+    cerr<<"  [bits] [rsasha1|rsasha256]    Add a ZSK or KSK to a zone\n";
     cerr<<"deactivate-zone-key             Dectivate the key with key id KEY-ID in ZONE\n";
     cerr<<"export-zone-dnskey ZONE KEY-ID  Export to stdout the public DNSKEY described\n";
     cerr<<"export-zone-key ZONE KEY-ID     Export to stdout the private key described\n";
@@ -286,21 +287,26 @@ try
     // need to get algorithm, bits & ksk or zsk from commandline
     bool keyOrZone=false;
     int bits=0;
+    int algorithm=5;
     for(unsigned int n=2; n < cmds.size(); ++n) {
       if(pdns_iequals(cmds[n], "zsk"))
         keyOrZone = false;
       else if(pdns_iequals(cmds[n], "ksk"))
         keyOrZone = true;
+      else if(pdns_iequals(cmds[n], "rsasha1"))
+        algorithm=5;
+      else if(pdns_iequals(cmds[n], "rsasha256"))
+        algorithm=8;
       else if(atoi(cmds[n].c_str()))
         bits = atoi(cmds[n].c_str());
       else { 
-        cerr<<"Unknown key flag or size '"<<cmds[n]<<"'"<<endl;
+        cerr<<"Unknown algorithm, key flag or size '"<<cmds[n]<<"'"<<endl;
       }
     }
-    cerr<<"Adding a " << (keyOrZone ? "KSK" : "ZSK")<<endl;
+    cerr<<"Adding a " << (keyOrZone ? "KSK" : "ZSK")<<" with algorithm = "<<algorithm<<endl;
     if(bits)
       cerr<<"Requesting specific key size of "<<bits<<" bits"<<endl;
-    dk.addKey(zone, keyOrZone, 5, bits); 
+    dk.addKey(zone, keyOrZone, algorithm, bits); 
   }
   else if(cmds[0] == "remove-zone-key") {
     const string& zone=cmds[1];