]> granicus.if.org Git - pdns/commitdiff
move to keys with ids in addition to tags, so we can refer to keys in an unambiguous...
authorBert Hubert <bert.hubert@netherlabs.nl>
Tue, 21 Dec 2010 20:49:33 +0000 (20:49 +0000)
committerBert Hubert <bert.hubert@netherlabs.nl>
Tue, 21 Dec 2010 20:49:33 +0000 (20:49 +0000)
Prefix 000001 .. 000002 to the filenames containing your keys pls.

git-svn-id: svn://svn.powerdns.com/pdns/trunk/pdns@1755 d19b8d6e-7fed-0310-83ef-9ca221ded41b

pdns/dnsseckeeper.cc
pdns/dnsseckeeper.hh
pdns/pdnssec.cc

index 7a6aa935bd8c19506d5214050be47da06fb09f95..7f2d43a51e1033ad2edc5c521d84fa44ee94de02 100644 (file)
@@ -96,6 +96,26 @@ bool DNSSECKeeper::haveKSKFor(const std::string& zone, DNSSECPrivateKey* dpk)
   return false;
 }
 
+unsigned int DNSSECKeeper::getNextKeyIDFromDir(const std::string& dirname)
+{
+  fs::path full_path = fs::system_complete( fs::path(dirname));
+
+  if ( !fs::exists( full_path ) )
+    unixDie("Unable to get next free key id from '"+dirname+"'");
+
+  fs::directory_iterator end_iter;
+  unsigned int maxID=0;
+  for ( fs::directory_iterator dir_itr( full_path );
+       dir_itr != end_iter;
+       ++dir_itr )
+  {
+         if(ends_with(dir_itr->leaf(),".isc")) {
+                 maxID = max(maxID, (unsigned int)atoi(dir_itr->leaf().c_str()));
+         }
+  }
+  return maxID+1;
+}
+
 void DNSSECKeeper::addZSKFor(const std::string& name, int algorithm, bool active)
 {
   DNSSECPrivateKey dpk;
@@ -106,14 +126,13 @@ void DNSSECKeeper::addZSKFor(const std::string& name, int algorithm, bool active
   drc.d_flags = 256; // KSK
   drc.d_algorithm = algorithm; 
   string iscName=d_dirname+"/"+name+"/zsks/";
+  unsigned int id = getNextKeyIDFromDir(iscName);
   time_t inception=time(0);
 
-
   struct tm ts;
   gmtime_r(&inception, &ts);
 
-  iscName += (boost::format("%04d%02d%02d%02d%02d") 
+  iscName += (boost::format("%06d-%04d%02d%02d%02d%02d") % id
              % (1900+ts.tm_year) % (ts.tm_mon + 1)
              % ts.tm_mday % ts.tm_hour % ts.tm_min).str();
 
@@ -131,14 +150,12 @@ void DNSSECKeeper::addZSKFor(const std::string& name, int algorithm, bool active
 
 }
 
-/*
-bool zskSortByDates(const DNSSECKeeper::zskset_t::value_type& a, const DNSSECKeeper::zskset_t::value_type& b)
+
+static bool zskCompareByID(const DNSSECKeeper::zskset_t::value_type& a, const DNSSECKeeper::zskset_t::value_type& b)
 {
-  return 
-    tie(a.second.beginValidity, a.second.endValidity) < 
-    tie(b.second.beginValidity, b.second.endValidity);
+  return a.second.id < b.second.id;
 }
-* */
+
 void DNSSECKeeper::deleteZSKFor(const std::string& zname, const std::string& fname)
 {
   unlink((d_dirname +"/"+ zname +"/zsks/"+fname).c_str());
@@ -216,7 +233,9 @@ DNSSECKeeper::zskset_t DNSSECKeeper::getZSKsFor(const std::string& zone, bool al
       memset(&ts1, 0, sizeof(ts1));
       memset(&ts2, 0, sizeof(ts2));
       
-      sscanf(dir_itr->leaf().c_str(), "%04d%02d%02d%02d%02d",
+      unsigned int id;
+      sscanf(dir_itr->leaf().c_str(), "%06u-%04d%02d%02d%02d%02d",
+                &id,
             &ts1.tm_year, 
             &ts1.tm_mon, &ts1.tm_mday, &ts1.tm_hour, &ts1.tm_min);
             
@@ -227,12 +246,12 @@ DNSSECKeeper::zskset_t DNSSECKeeper::getZSKsFor(const std::string& zone, bool al
       
       KeyMetaData kmd;
       
-      
+         kmd.id = id;
       kmd.fname = dir_itr->leaf();
       kmd.active = kmd.fname.find(".active") != string::npos;
       zskset.push_back(make_pair(dpk, kmd));
     }
-    // sort(zskset.begin(), zskset.end(), zskSortByDates);
+    sort(zskset.begin(), zskset.end(), zskCompareByID);
   }
 
   return zskset;
@@ -251,19 +270,22 @@ void DNSSECKeeper::secureZone(const std::string& name, int algorithm)
   if(mkdir((d_dirname+"/"+name+"/zsks").c_str(), 0700) < 0)
     unixDie("Making directory for keys in '"+d_dirname+"'");
 
+  // now add the KSK
+
   DNSSECPrivateKey dpk;
   dpk.d_key.create(2048); // for testing, 1024
 
   string isc = dpk.d_key.convertToISC();
   DNSKEYRecordContent drc = dpk.getDNSKEY();
-  drc.d_flags = 257; // ZSK
+  drc.d_flags = 257; // ZSK (?? for a KSK?)
   drc.d_algorithm = algorithm;  
   string iscName=d_dirname+"/"+name+"/ksks/";
 
   time_t now=time(0);
   struct tm ts;
   gmtime_r(&now, &ts);
-  iscName += (boost::format("%04d%02d%02d%02d%02d.%u") 
+  unsigned int id=1;
+  iscName += (boost::format("%06d-%04d%02d%02d%02d%02d.%u") % id
              % (1900+ts.tm_year) % (ts.tm_mon + 1)
              % ts.tm_mday % ts.tm_hour % ts.tm_min % drc.getTag()).str();
 
index f777c7197f295fdb9714807b03340962fdfebf1a..2c0b12a92fdb94dcca632c5001604cb16c997a25 100644 (file)
@@ -84,6 +84,7 @@ class DNSSECKeeper
 public:
   struct KeyMetaData
   {
+       unsigned int id;
     bool active;
     string fname;
   }; 
@@ -103,7 +104,7 @@ public:
 
   bool getNSEC3PARAM(const std::string& zname, NSEC3PARAMRecordContent* n3p=0);
   void setNSEC3PARAM(const std::string& zname, const NSEC3PARAMRecordContent* n3p);
-
+  static unsigned int getNextKeyIDFromDir(const std::string& dirname);
 private:
   std::string d_dirname;
 };
index b9b5a64fb8ad1ba483dd7f06a66e7b8c1a945f3e..e7b1de00cf37beabf2865e6b2095755165dfccfa 100644 (file)
@@ -210,6 +210,7 @@ try
     }
     checkZone(dk, cmds[1]);
   }
+#if 0
   else if(cmds[0] == "update-zone-keys") {
     if(cmds.size() != 2) {
       cerr << "Error: "<<cmds[0]<<" takes exactly 1 parameter"<<endl;
@@ -263,6 +264,7 @@ try
     }
 
   }
+#endif
   else if(cmds[0] == "show-zone") {
     if(cmds.size() != 2) {
       cerr << "Error: "<<cmds[0]<<" takes exactly 1 parameter"<<endl;
@@ -290,7 +292,7 @@ try
     else {  
       cout << "ZSKs for zone '"<<zone<<"':"<<endl;
       BOOST_FOREACH(DNSSECKeeper::zskset_t::value_type value, zskset) {
-        cout<<"Tag = "<<value.first.getDNSKEY().getTag()<<"\tActive: "<<value.second.active<< endl; // humanTime(value.second.beginValidity)<<" - "<<humanTime(value.second.endValidity)<<endl;
+        cout<<"ID = "<<value.second.id<<", tag = "<<value.first.getDNSKEY().getTag()<<"\tActive: "<<value.second.active<< endl; // humanTime(value.second.beginValidity)<<" - "<<humanTime(value.second.endValidity)<<endl;
       }
     }
   }
@@ -331,7 +333,7 @@ try
 
     cout<<"There are now "<<zskset.size()<<" ZSKs"<<endl;
     BOOST_FOREACH(DNSSECKeeper::zskset_t::value_type value, zskset) {
-      cout<<"Tag = "<<value.first.getDNSKEY().getTag()<<"\tActive: "<<value.second.active<<endl;
+      cout<<"id = "<<value.second.id<<", tag = "<<value.first.getDNSKEY().getTag()<<"\tActive: "<<value.second.active<<endl;
     }
   }
   else {