From d3ccf8a30640899055a83063f67edcf5a035dd49 Mon Sep 17 00:00:00 2001 From: bert hubert Date: Fri, 11 Mar 2016 14:06:29 +0100 Subject: [PATCH] get number of key bits for presigned zone show-zone properly --- pdns/pdnsutil.cc | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/pdns/pdnsutil.cc b/pdns/pdnsutil.cc index 8d15e2ab47..cee9411a43 100644 --- a/pdns/pdnsutil.cc +++ b/pdns/pdnsutil.cc @@ -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 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: "<