From: Bert Hubert Date: Thu, 30 Dec 2010 19:52:51 +0000 (+0000) Subject: spruce up 'show-zone' output, add 'set-nsec3', 'unset-nsec3', 'export-zone-key',... X-Git-Tag: auth-3.0~474 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=da11ed0e0d9dba021f2882fcd9b9eeac13f6de5b;p=pdns spruce up 'show-zone' output, add 'set-nsec3', 'unset-nsec3', 'export-zone-key', 'export-zone-dnskey' (for interop), remove storage of DNSKEY in key-repo, derive it from private key if needed git-svn-id: svn://svn.powerdns.com/pdns/trunk/pdns@1773 d19b8d6e-7fed-0310-83ef-9ca221ded41b --- diff --git a/pdns/dnsseckeeper.hh b/pdns/dnsseckeeper.hh index 4cb2a7c01..45e5984f3 100644 --- a/pdns/dnsseckeeper.hh +++ b/pdns/dnsseckeeper.hh @@ -106,7 +106,8 @@ public: bool haveActiveKSKFor(const std::string& zone, DNSSECPrivateKey* ksk=0); keyset_t getKeys(const std::string& zone, boost::tribool allOrKeyOrZone = boost::indeterminate); - void addKey(const std::string& zname, bool keyOrZone, int algorithm, bool active=true); + DNSSECPrivateKey getKeyById(const std::string& zone, unsigned int id); + void addKey(const std::string& zname, bool keyOrZone, int algorithm=5, int bits=0, bool active=true); void removeKey(const std::string& zname, unsigned int id); void activateKey(const std::string& zname, unsigned int id); void deactivateKey(const std::string& zname, unsigned int id); @@ -114,7 +115,8 @@ public: void secureZone(const std::string& fname, int algorithm); bool getNSEC3PARAM(const std::string& zname, NSEC3PARAMRecordContent* n3p=0); - void setNSEC3PARAM(const std::string& zname, const NSEC3PARAMRecordContent* n3p); + void setNSEC3PARAM(const std::string& zname, const NSEC3PARAMRecordContent& n3p); + void unsetNSEC3PARAM(const std::string& zname); static unsigned int getNextKeyIDFromDir(const std::string& dirname); std::string getKeyFilenameById(const std::string& dirname, unsigned int id); private: diff --git a/pdns/fsdnsseckeeper.cc b/pdns/fsdnsseckeeper.cc index 1030b764d..f1330c26f 100644 --- a/pdns/fsdnsseckeeper.cc +++ b/pdns/fsdnsseckeeper.cc @@ -113,15 +113,17 @@ std::string DNSSECKeeper::getKeyFilenameById(const std::string& dirname, unsigne } -void DNSSECKeeper::addKey(const std::string& name, bool keyOrZone, int algorithm, bool active) +void DNSSECKeeper::addKey(const std::string& name, bool keyOrZone, int algorithm, int bits, bool active) { + if(!bits) + bits = keyOrZone ? 2048 : 1024; DNSSECPrivateKey dpk; - dpk.d_key.create(1024); // for testing, 1024 + dpk.d_key.create(bits); // for testing, 1024 string isc = dpk.d_key.convertToISC(); DNSKEYRecordContent drc = dpk.getDNSKEY(); drc.d_flags = 256 + keyOrZone; // KSK - drc.d_algorithm = algorithm; + drc.d_algorithm = algorithm; // 5 = RSA, we'll add '2' later on for NSEC3 if needed string iscName=d_dirname+"/"+name+"/keys/"; unsigned int id = getNextKeyIDFromDir(iscName); time_t inception=time(0); @@ -129,9 +131,9 @@ void DNSSECKeeper::addKey(const std::string& name, bool keyOrZone, int algorithm struct tm ts; gmtime_r(&inception, &ts); - iscName += (boost::format("%06d-%04d%02d%02d%02d%02d.%u") % id + 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 % drc.getTag()).str(); + % ts.tm_mday % ts.tm_hour % ts.tm_min).str(); iscName += keyOrZone ? ".ksk" : ".zsk"; iscName += active ? ".active" : ".passive"; @@ -140,12 +142,12 @@ void DNSSECKeeper::addKey(const std::string& name, bool keyOrZone, int algorithm ofstream iscFile((iscName+".private").c_str()); iscFile << isc; } - +#if 0 { ofstream dnskeyFile((iscName+".key").c_str()); dnskeyFile << toCanonic("", name) << " IN DNSKEY " << drc.getZoneRepresentation()<(DNSRecordContent::mastermake(QType::NSEC3PARAM, 1, descr)); if(!tmp) { cerr<<"Could not parse "<< full_path.external_directory_string() <d_salt)<getZoneRepresentation(); - - - ofstream of(full_path.external_directory_string().c_str()); - of << descr; - } - else { - unlink(full_path.external_directory_string().c_str()); - } + string descr = ns3p.getZoneRepresentation(); + ofstream of(full_path.external_directory_string().c_str()); + of << descr; +} + +void DNSSECKeeper::unsetNSEC3PARAM(const std::string& zname) +{ + fs::path full_path = fs::system_complete( fs::path(d_dirname + "/" + zname + "/nsec3param" ) ); + unlink(full_path.external_directory_string().c_str()); } @@ -287,40 +300,8 @@ void DNSSECKeeper::secureZone(const std::string& name, int algorithm) if(mkdir((d_dirname+"/"+name+"/keys").c_str(), 0700) < 0) unixDie("Making directory for keys in '"+d_dirname+"'"); - // now add the KSK - addKey(name, true, algorithm); -#if 0 - - 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 (?? for a KSK?) - drc.d_algorithm = algorithm; - string iscName=d_dirname+"/"+name+"/keys/"; - - time_t now=time(0); - struct tm ts; - gmtime_r(&now, &ts); - unsigned int id=1; - iscName += (boost::format("%06d-%04d%02d%02d%02d%02d.%u.%s.%s") % id - % (1900+ts.tm_year) % (ts.tm_mon + 1) - % ts.tm_mday % ts.tm_hour % ts.tm_min % drc.getTag() % "ksk" % "active").str(); - - - { - ofstream iscFile((iscName+".private").c_str()); - iscFile << isc; - } - - { - ofstream dnskeyFile((iscName+".key").c_str()); - dnskeyFile << toCanonic("", name) << " IN DNSKEY " << drc.getZoneRepresentation()<= 2) { - cerr << "Two or more ZSKs were active already, not generating a third" << endl; - return 0; - } - dk.addKey(zone, true, 5); - dk.addKey(zone, true, 5, false); // not yet active - - keyset = dk.getKeys(zone); - if(zskset.empty()) { - cerr<<"This should not happen, still no ZSK!"< 2 ? cmds[2] : "1 0 1 ab"; + + NSEC3PARAMRecordContent ns3pr(nsec3params); + dk.setNSEC3PARAM(cmds[1], ns3pr); + } + else if(cmds[0]=="unset-nsec3") { + dk.unsetNSEC3PARAM(cmds[1]); + } + else if(cmds[0]=="export-zone-key") { + string zone=cmds[1]; + unsigned int id=atoi(cmds[2].c_str()); + DNSSECPrivateKey dpk=dk.getKeyById(zone, id); + cout << dpk.d_key.convertToISC() <