]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
get number of key bits for presigned zone show-zone properly 3553/head
authorbert hubert <bert.hubert@netherlabs.nl>
Fri, 11 Mar 2016 13:06:29 +0000 (14:06 +0100)
committerbert hubert <bert.hubert@netherlabs.nl>
Fri, 11 Mar 2016 13:08:24 +0000 (14:08 +0100)
pdns/pdnsutil.cc

index 8d15e2ab470444926f7da18bb0b8d9fe9b5347f8..cee9411a43631a4acce179794991f58445edd910 100644 (file)
@@ -1519,12 +1519,15 @@ bool showZone(DNSSECKeeper& dk, const DNSName& zone)
     bool shown=false;
     for(const auto& key : keys) {
       string algname = DNSSECKeeper::algorithm2name(key.d_algorithm);
-      int bits;
-      if (key.d_key[0] == 0)
-        bits = *(uint16_t*)(key.d_key.c_str()+1);
-      else
-        bits = *(uint8_t*)key.d_key.c_str();
-      bits = (key.d_key.size() - (bits+1))*8;
+
+      int bits = -1;
+      try {
+        std::unique_ptr<DNSCryptoKeyEngine> engine(DNSCryptoKeyEngine::makeFromPublicKeyString(key.d_algorithm, key.d_key)); // throws on unknown algo or bad key
+        bits=engine->getBits();
+      }
+      catch(std::exception& e) {
+        cout<<"Could not process key to extract metadata: "<<e.what()<<endl;
+      }
       cout << (key.d_flags == 257 ? "KSK" : "ZSK") << ", tag = " << key.getTag() << ", algo = "<<(int)key.d_algorithm << ", bits = " << bits << endl;
       cout << "DNSKEY = " <<zone.toString()<<" IN DNSKEY "<< key.getZoneRepresentation() << "; ( " + algname + " ) " <<endl;
       if (shown) continue;