From: Bert Hubert Date: Thu, 27 Jan 2011 10:31:27 +0000 (+0000) Subject: add signature verification infrastructure for RSA & GOST, test with 'pdnssec verify... X-Git-Tag: auth-3.0~332 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=aa65a8321afdc388e0838c393bb26d10105f3da1;p=pdns add signature verification infrastructure for RSA & GOST, test with 'pdnssec verify-crypto fname' where fname contains a zone with a key, something to be signed, and an RRSIG git-svn-id: svn://svn.powerdns.com/pdns/trunk/pdns@1915 d19b8d6e-7fed-0310-83ef-9ca221ded41b --- diff --git a/pdns/botan19signers.cc b/pdns/botan19signers.cc index 7b22d05af..26bf7225a 100644 --- a/pdns/botan19signers.cc +++ b/pdns/botan19signers.cc @@ -33,6 +33,7 @@ public: std::string getPublicKeyString() const; int getBits() const; void fromISCString(DNSKEYRecordContent& drc, const std::string& content); + void fromPublicKeyString(unsigned int algorithm, const std::string& content); void fromPEMString(DNSKEYRecordContent& drc, const std::string& raw) {} @@ -43,6 +44,7 @@ public: private: shared_ptr d_key; + shared_ptr d_pubkey; }; /* @@ -142,6 +144,31 @@ void GOSTDNSPrivateKey::fromISCString(DNSKEYRecordContent& drc, const std::strin SecureVector buffer=BigInt::encode(x); // cerr<<"And out again! "< msg_le(msg, msg_len); + + for(size_t i = 0; i != msg_le.size() / 2; ++i) + std::swap(msg_le[i], msg_le[msg_le.size()-1-i]); + + return BigInt(&msg_le[0], msg_le.size()); + } + +} +void GOSTDNSPrivateKey::fromPublicKeyString(unsigned int algorithm, const std::string& input) +{ + BigInt x, y; + + x=decode_le((const byte*)input.c_str(), input.length()/2); + y=decode_le((const byte*)input.c_str() + input.length()/2, input.length()/2); + + EC_Domain_Params params("1.2.643.2.2.35.1"); + PointGFp point(params.get_curve(), x,y); + d_pubkey = shared_ptr(new GOST_3410_PublicKey(params, point)); + +} std::string GOSTDNSPrivateKey::getPubKeyHash() const { @@ -194,13 +221,26 @@ std::string GOSTDNSPrivateKey::hash(const std::string& orig) const GOST_34_11 hasher; result= hasher.process(orig); - return string((const char*)result.begin(), (const char*) result.end()); } + bool GOSTDNSPrivateKey::verify(const std::string& hash, const std::string& signature) const { - GOST_3410_Verification_Operation ops(*d_key); + GOST_3410_PublicKey* pk; + if(d_pubkey) { + cerr<<"Worked from the public key"<fromPublicKeyString(algorithm, content); + return dpk; +} + DNSPrivateKey* DNSPrivateKey::makeFromPEMString(DNSKEYRecordContent& drc, const std::string& raw) { diff --git a/pdns/dnssecinfra.hh b/pdns/dnssecinfra.hh index 4ff91296e..6135dc417 100644 --- a/pdns/dnssecinfra.hh +++ b/pdns/dnssecinfra.hh @@ -15,15 +15,21 @@ class DNSPrivateKey virtual std::string getPubKeyHash()const =0; virtual std::string sign(const std::string& hash) const =0; virtual std::string hash(const std::string& hash) const =0; + virtual bool verify(const std::string& hash, const std::string& signature) const =0; virtual std::string getPublicKeyString()const =0; virtual int getBits() const =0; virtual void fromISCString(DNSKEYRecordContent& drc, const std::string& content)=0; virtual void fromPEMString(DNSKEYRecordContent& drc, const std::string& raw)=0; + virtual void fromPublicKeyString(unsigned algorithm, const std::string& content) + { + throw std::runtime_error("Can't import from public key string"); + } static DNSPrivateKey* makeFromISCFile(DNSKEYRecordContent& drc, const char* fname); static DNSPrivateKey* makeFromISCString(DNSKEYRecordContent& drc, const std::string& content); static DNSPrivateKey* makeFromPEMString(DNSKEYRecordContent& drc, const std::string& raw); + static DNSPrivateKey* makeFromPublicKeyString(unsigned int algorithm, const std::string& raw); static DNSPrivateKey* make(unsigned int algorithm); typedef DNSPrivateKey* maker_t(unsigned int algorithm); diff --git a/pdns/pdnssec.cc b/pdns/pdnssec.cc index cf2b8e527..cc67d0044 100644 --- a/pdns/pdnssec.cc +++ b/pdns/pdnssec.cc @@ -9,7 +9,7 @@ #include "ueberbackend.hh" #include "arguments.hh" #include "packetcache.hh" - +#include "zoneparser-tng.hh" StatBag S; PacketCache PC; @@ -176,6 +176,36 @@ void checkZone(DNSSECKeeper& dk, const std::string& zone) cerr<<"Checked "< > toSign; + unsigned int ttl; + string qname; + + while(zpt.get(rr)) { + if(rr.qtype.getCode() == QType::DNSKEY) { + cerr<<"got DNSKEY!"<(DNSRecordContent::mastermake(QType::DNSKEY, 1, rr.content)); + } + else if(rr.qtype.getCode() == QType::RRSIG) { + cerr<<"got RRSIG"<(DNSRecordContent::mastermake(QType::RRSIG, 1, rr.content)); + } + else { + qname = rr.qname; + ttl = rr.ttl; + toSign.push_back(shared_ptr(DNSRecordContent::mastermake(rr.qtype.getCode(), 1, rr.content))); + } + } + DNSPrivateKey* dpk = DNSPrivateKey::makeFromPublicKeyString(drc.d_algorithm, drc.d_key); + string hash = getHashForRRSET(qname, rrc, toSign); + cerr<<"Verify: "<verify(hash, rrc.d_signature)<(&d_context), RSA_PUBLIC, + hashKind, + hash.size(), + (const unsigned char*) hash.c_str(), (unsigned char*) signature.c_str()); + cerr<<"verification returned: "<E, (unsigned char*)dkrc.getExponent().c_str(), dkrc.getExponent().length()); // exponent - mpi_read_binary(&rc->N, (unsigned char*)dkrc.getModulus().c_str(), dkrc.getModulus().length()); // modulus - rc->len = ( mpi_msb( &rc->N ) + 7 ) >> 3; // no clue what this does +void RSADNSPrivateKey::fromPublicKeyString(unsigned int algorithm, const std::string& rawString) +{ + rsa_init(&d_context, RSA_PKCS_V15, 0, NULL, NULL ); + string exponent, modulus; + const unsigned char* raw = (const unsigned char*)rawString.c_str(); + + if(raw[0] != 0) { + exponent=rawString.substr(1, raw[0]); + modulus=rawString.substr(raw[0]+1); + } else { + exponent=rawString.substr(3, raw[1]*0xff + raw[2]); + modulus = rawString.substr(3+ raw[1]*0xff + raw[2]); + } + mpi_read_binary(&d_context.E, (unsigned char*)exponent.c_str(), exponent.length()); + mpi_read_binary(&d_context.N, (unsigned char*)modulus.c_str(), modulus.length()); + d_context.len = ( mpi_msb( &d_context.N ) + 7 ) >> 3; // no clue what this does } -#endif + string RSADNSPrivateKey::getPublicKeyString() const { string keystring;