From: Aki Tuomi Date: Fri, 22 May 2015 13:02:26 +0000 (+0300) Subject: Move getTSIGHashEnum to misc X-Git-Tag: dnsdist-1.0.0-alpha1~248^2~79^2~9^2~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=da15912b18cf8ee28815c001b2ac37e939e81fbd;p=thirdparty%2Fpdns.git Move getTSIGHashEnum to misc --- diff --git a/pdns/dnssecinfra.cc b/pdns/dnssecinfra.cc index d5ae99e664..17a101ef05 100644 --- a/pdns/dnssecinfra.cc +++ b/pdns/dnssecinfra.cc @@ -23,6 +23,7 @@ #include "pkcs11signers.hh" #endif #include "gss_context.hh" +#include "misc.hh" using namespace boost::assign; @@ -585,30 +586,6 @@ string makeTSIGMessageFromTSIGPacket(const string& opacket, unsigned int tsigOff return message; } - -bool getTSIGHashEnum(const string &algoName, TSIGHashEnum& algoEnum) -{ - string normalizedName = toLowerCanonic(algoName); - - if (normalizedName == "hmac-md5.sig-alg.reg.int") - algoEnum = TSIG_MD5; - else if (normalizedName == "hmac-sha1") - algoEnum = TSIG_SHA1; - else if (normalizedName == "hmac-sha224") - algoEnum = TSIG_SHA224; - else if (normalizedName == "hmac-sha256") - algoEnum = TSIG_SHA256; - else if (normalizedName == "hmac-sha384") - algoEnum = TSIG_SHA384; - else if (normalizedName == "hmac-sha512") - algoEnum = TSIG_SHA512; - else { - return false; - } - return true; -} - - void addTSIG(DNSPacketWriter& pw, TSIGRecordContent* trc, const string& tsigkeyname, const string& tsigsecret, const string& tsigprevious, bool timersonly) { TSIGHashEnum algo; diff --git a/pdns/dnssecinfra.hh b/pdns/dnssecinfra.hh index 9267cf2c3a..82cd57c645 100644 --- a/pdns/dnssecinfra.hh +++ b/pdns/dnssecinfra.hh @@ -130,14 +130,12 @@ void decodeDERIntegerSequence(const std::string& input, vector& output); class DNSPacket; void addRRSigs(DNSSECKeeper& dk, UeberBackend& db, const std::set& authMap, vector& rrs); -typedef enum { TSIG_MD5, TSIG_SHA1, TSIG_SHA224, TSIG_SHA256, TSIG_SHA384, TSIG_SHA512 } TSIGHashEnum; string calculateMD5HMAC(const std::string& key, const std::string& text); string calculateSHAHMAC(const std::string& key, const std::string& text, TSIGHashEnum hash); string calculateHMAC(const std::string& key, const std::string& text, TSIGHashEnum hash); string makeTSIGMessageFromTSIGPacket(const string& opacket, unsigned int tsigoffset, const string& keyname, const TSIGRecordContent& trc, const string& previous, bool timersonly, unsigned int dnsHeaderOffset=0); -bool getTSIGHashEnum(const string &algoName, TSIGHashEnum& algoEnum); void addTSIG(DNSPacketWriter& pw, TSIGRecordContent* trc, const string& tsigkeyname, const string& tsigsecret, const string& tsigprevious, bool timersonly); uint64_t signatureCacheSize(const std::string& str); #endif diff --git a/pdns/misc.cc b/pdns/misc.cc index 77461b9874..7557e1229c 100644 --- a/pdns/misc.cc +++ b/pdns/misc.cc @@ -972,7 +972,6 @@ bool setCloseOnExec(int sock) return true; } -// please feel free to add other operating systems here. What we need are stats on dropped UDP packets uint64_t udpErrorStats(const std::string& str) { #ifdef __linux__ @@ -1001,3 +1000,25 @@ uint64_t udpErrorStats(const std::string& str) #endif return 0; } + +bool getTSIGHashEnum(const string &algoName, TSIGHashEnum& algoEnum) +{ + string normalizedName = toLowerCanonic(algoName); + + if (normalizedName == "hmac-md5.sig-alg.reg.int") + algoEnum = TSIG_MD5; + else if (normalizedName == "hmac-sha1") + algoEnum = TSIG_SHA1; + else if (normalizedName == "hmac-sha224") + algoEnum = TSIG_SHA224; + else if (normalizedName == "hmac-sha256") + algoEnum = TSIG_SHA256; + else if (normalizedName == "hmac-sha384") + algoEnum = TSIG_SHA384; + else if (normalizedName == "hmac-sha512") + algoEnum = TSIG_SHA512; + else { + return false; + } + return true; +} diff --git a/pdns/misc.hh b/pdns/misc.hh index 6cd29f34dc..59207d979d 100644 --- a/pdns/misc.hh +++ b/pdns/misc.hh @@ -48,6 +48,8 @@ using namespace ::boost::multi_index; #include #include "namespaces.hh" +typedef enum { TSIG_MD5, TSIG_SHA1, TSIG_SHA224, TSIG_SHA256, TSIG_SHA384, TSIG_SHA512 } TSIGHashEnum; + bool chopOff(string &domain); bool chopOffDotted(string &domain); @@ -68,6 +70,7 @@ uint16_t getShort(const char *p); uint32_t getLong(const unsigned char *p); uint32_t getLong(const char *p); uint32_t pdns_strtoui(const char *nptr, char **endptr, int base); +bool getTSIGHashEnum(const string &algoName, TSIGHashEnum& algoEnum); int logFacilityToLOG(unsigned int facility);