]> granicus.if.org Git - pdns/commitdiff
move some more stuff to the 'infra' and away from the 'keeper'
authorBert Hubert <bert.hubert@netherlabs.nl>
Sat, 1 Jan 2011 21:23:18 +0000 (21:23 +0000)
committerBert Hubert <bert.hubert@netherlabs.nl>
Sat, 1 Jan 2011 21:23:18 +0000 (21:23 +0000)
git-svn-id: svn://svn.powerdns.com/pdns/trunk/pdns@1785 d19b8d6e-7fed-0310-83ef-9ca221ded41b

pdns/dnssecinfra.cc
pdns/dnssecinfra.hh
pdns/dnsseckeeper.hh

index 4987851af513dd1d7018a422a4032d9f4c9e3f2b..fcb6a5a32eb1adeadfd7c1a780553f8dbbcb8d2a 100644 (file)
@@ -132,6 +132,70 @@ DNSKEYRecordContent getRSAKeyFromISC(rsa_context* rsa, const char* fname)
   return drc;
 }
 
+DNSKEYRecordContent getRSAKeyFromISCString(rsa_context* rsa, const std::string& content)
+{
+  string sline;
+  string key,value;
+  map<string, mpi*> places;
+
+  
+  rsa_init(rsa, RSA_PKCS_V15, 0, NULL, NULL );
+
+  places["Modulus"]=&rsa->N;
+  places["PublicExponent"]=&rsa->E;
+  places["PrivateExponent"]=&rsa->D;
+  places["Prime1"]=&rsa->P;
+  places["Prime2"]=&rsa->Q;
+  places["Exponent1"]=&rsa->DP;
+  places["Exponent2"]=&rsa->DQ;
+  places["Coefficient"]=&rsa->QP;
+
+  DNSKEYRecordContent drc;
+  string modulus, exponent;
+  istringstream str(content);
+  unsigned char decoded[1024];
+  while(getline(str, sline)) {
+    tie(key,value)=splitField(sline, ':');
+    trim(value);
+
+    if(places.count(key)) {
+      if(places[key]) {
+        int len=sizeof(decoded);
+        if(base64_decode(decoded, &len, (unsigned char*)value.c_str(), value.length()) < 0) {
+          cerr<<"Error base64 decoding '"<<value<<"'\n";
+          exit(1);
+        }
+        //     B64Decode(value, decoded);
+        //     cerr<<key<<" decoded.length(): "<<8*len<<endl;
+        mpi_read_binary(places[key], decoded, len);
+        if(key=="Modulus")
+          modulus.assign((const char*)decoded,len);
+        if(key=="PublicExponent")
+          exponent.assign((const char*)decoded,len);
+      }
+    }
+    else {
+      if(key != "Private-key-format" && key != "Algorithm") 
+      cerr<<"Unknown field '"<<key<<"'\n";
+    }
+  }
+  rsa->len = ( mpi_msb( &rsa->N ) + 7 ) >> 3; // no clue what this does
+
+  if(exponent.length() < 255) 
+    drc.d_key.assign(1, (char) (unsigned int) exponent.length());
+  else {
+    drc.d_key.assign(1, 0);
+    uint16_t len=htons(exponent.length());
+    drc.d_key.append((char*)&len, 2);
+  }
+  drc.d_key.append(exponent);
+  drc.d_key.append(modulus);
+  drc.d_protocol=3;
+  drc.d_algorithm = 0; // should not be filled out here..
+  return drc;
+}
+
+
 
 void makeRSAPublicKeyFromDNS(rsa_context* rc, const DNSKEYRecordContent& dkrc)
 {
index 400c94e6d975656797cf7118b9c77b8a5488bf32..e835fca94c1a78b53ff9eb371dd0d1ffe317afcf 100644 (file)
@@ -24,7 +24,7 @@ struct CanonicalCompare: public binary_function<string, string, bool>
 
 
 DNSKEYRecordContent getRSAKeyFromISC(rsa_context* rsa, const char* fname);
-
+DNSKEYRecordContent getRSAKeyFromISCString(rsa_context* rsa, const std::string& content);
 void makeRSAPublicKeyFromDNS(rsa_context* rc, const DNSKEYRecordContent& dkrc);
 bool sharedDNSSECCompare(const boost::shared_ptr<DNSRecordContent>& a, const shared_ptr<DNSRecordContent>& b);
 string getSHA1HashForRRSET(const std::string& qname, const RRSIGRecordContent& rrc, std::vector<boost::shared_ptr<DNSRecordContent> >& signRecords);
index 5fe0675f9c913cc5c146f59d023a5828bb0a2a8a..5c491feb0cc192016f801f29d02a39c0faccdd6d 100644 (file)
@@ -117,8 +117,7 @@ public:
   bool getNSEC3PARAM(const std::string& zname, NSEC3PARAMRecordContent* n3p=0);
   void setNSEC3PARAM(const std::string& zname, const NSEC3PARAMRecordContent& n3p);
   void unsetNSEC3PARAM(const std::string& zname);
-  static unsigned int getNextKeyIDFromDir(const std::string& dirname);
-  std::string getKeyFilenameById(const std::string& dirname, unsigned int id);
+  
 private:
   std::string d_dirname;
 };