]> granicus.if.org Git - pdns/commitdiff
evaluate KSK ZSK pairs per algorithm
authorKees Monshouwer <mind04@monshouwer.org>
Wed, 11 Feb 2015 21:54:08 +0000 (22:54 +0100)
committermind04 <mind04@monshouwer.org>
Thu, 26 Feb 2015 19:48:59 +0000 (20:48 +0100)
(cherry picked from commit 7dc95f99c6aaafb9d1856a9ef85896022de04f93)

pdns/dnssecsigner.cc

index f21fb37bb99ff6a1822e89bb4d6495adf84c031c..c6980571956fcbae33d1580ad46d911266d89c30 100644 (file)
@@ -51,34 +51,36 @@ int getRRSIGsForRRSET(DNSSECKeeper& dk, const std::string& signer, const std::st
   // we sign the RRSET in toSign + the rrc w/o hash
   
   DNSSECKeeper::keyset_t keys = dk.getKeys(signer); // we don't want the . for the root!
-  vector<DNSSECPrivateKey> KSKs, ZSKs;
-  vector<DNSSECPrivateKey>* signingKeys;
-  
-  // if ksk==1, only get KSKs
-  // if ksk==0, get ZSKs, unless there is no ZSK, then get KSK
+  set<int> algoHasKSK, algoHasZSK;
+  vector<DNSSECPrivateKey> signingKeys;
+
+  BOOST_FOREACH(DNSSECKeeper::keyset_t::value_type& keymeta, keys) {
+    if(keymeta.second.active) {
+      if(keymeta.second.keyOrZone)
+        algoHasKSK.insert(keymeta.first.d_algorithm);
+      else
+        algoHasZSK.insert(keymeta.first.d_algorithm);
+    }
+  }
+
   BOOST_FOREACH(DNSSECKeeper::keyset_t::value_type& keymeta, keys) {
-    rrc.d_algorithm = keymeta.first.d_algorithm;
-    if(!keymeta.second.active) 
+    if(!keymeta.second.active)
       continue;
 
-    if(keymeta.second.keyOrZone)
-      KSKs.push_back(keymeta.first);
-    else
-      ZSKs.push_back(keymeta.first);
-  }
-  if(signQType == QType::DNSKEY) {
-    if(KSKs.empty())
-      signingKeys = &ZSKs;
-    else
-      signingKeys = &KSKs;
-  } else {
-    if(ZSKs.empty())
-      signingKeys = &KSKs;
-    else
-      signingKeys = &ZSKs;
+    if(signQType == QType::DNSKEY) {
+      // skip ZSK, if this algorithm has a KSK
+      if(!keymeta.second.keyOrZone && algoHasKSK.count(keymeta.first.d_algorithm))
+        continue;
+    } else {
+      // skip KSK, if this algorithm has a ZSK
+      if(keymeta.second.keyOrZone && algoHasZSK.count(keymeta.first.d_algorithm))
+        continue;
+    }
+
+    signingKeys.push_back(keymeta.first);
   }
 
-  BOOST_FOREACH(DNSSECPrivateKey& dpk, *signingKeys) {
+  BOOST_FOREACH(DNSSECPrivateKey& dpk, signingKeys) {
     fillOutRRSIG(dpk, signQName, rrc, toSign);
     rrcs.push_back(rrc);
   }