]> granicus.if.org Git - pdns/commitdiff
Use DNSName in GSS-TSIG code
authorAki Tuomi <cmouse@cmouse.fi>
Tue, 20 Oct 2015 05:41:25 +0000 (08:41 +0300)
committerAki Tuomi <cmouse@desteem.org>
Fri, 23 Oct 2015 10:55:15 +0000 (13:55 +0300)
pdns/gss_context.cc
pdns/gss_context.hh
pdns/packethandler.cc
pdns/resolver.cc
pdns/saxfr.cc
pdns/tcpreceiver.cc
pdns/tkey.cc

index 1f88996c01e541432fc6fa815d562fcee46fcce3..10d103ed12f3bd35cbc42e9d2679bc511c8f80bd 100644 (file)
 
 bool GssContext::supported() { return false; }
 GssContext::GssContext() { d_error = GSS_CONTEXT_UNSUPPORTED; d_type = GSS_CONTEXT_NONE; }
-GssContext::GssContext(const std::string& label) { d_error = GSS_CONTEXT_UNSUPPORTED; d_type = GSS_CONTEXT_NONE; }
+GssContext::GssContext(const DNSName& label) { d_error = GSS_CONTEXT_UNSUPPORTED; d_type = GSS_CONTEXT_NONE; }
 void GssContext::setLocalPrincipal(const std::string& name) {}
 bool GssContext::getLocalPrincipal(std::string& name) { return false; }
 void GssContext::setPeerPrincipal(const std::string& name) {}
 bool GssContext::getPeerPrincipal(std::string& name) { return false; }
 void GssContext::generateLabel(const std::string& suffix) {}
-void GssContext::setLabel(const std::string& label) {}
+void GssContext::setLabel(const DNSName& label) {}
 bool GssContext::init(const std::string &input, std::string& output) { return false; }
 bool GssContext::accept(const std::string &input, std::string& output) { return false; }
 bool GssContext::destroy() { return false; }
@@ -116,7 +116,7 @@ std::map<std::string, boost::shared_ptr<GssCredential> > s_gss_init_creds;
 
 class GssSecContext : boost::noncopyable {
 public:
-  GssSecContext(const std::string& label, boost::shared_ptr<GssCredential> cred) {    
+  GssSecContext(boost::shared_ptr<GssCredential> cred) {
     if (cred->valid() == false) throw PDNSException("Invalid credential " + cred->d_nameS);
     d_cred = cred;
     d_state = GssStateInitial;
@@ -153,12 +153,11 @@ public:
 
 };
 
-std::map<std::string, boost::shared_ptr<GssSecContext> > s_gss_sec_context;
+std::map<DNSName, boost::shared_ptr<GssSecContext> > s_gss_sec_context;
 
 bool GssContext::supported() { return true; }
 
 void GssContext::initialize() {
-  d_label = "";
   d_peerPrincipal = "";
   d_localPrincipal = "";
   d_error = GSS_CONTEXT_NO_ERROR;
@@ -170,9 +169,9 @@ GssContext::GssContext() {
   generateLabel("pdns.tsig");
 }
 
-GssContext::GssContext(const std::string& label) {
+GssContext::GssContext(const DNSName& label) {
   initialize();
-  setLabel(toLowerCanonic(label));
+  setLabel(label);
 }
 
 void GssContext::generateLabel(const std::string& suffix) {
@@ -181,7 +180,7 @@ void GssContext::generateLabel(const std::string& suffix) {
   setLabel(oss.str());
 }
 
-void GssContext::setLabel(const std::string& label) {
+void GssContext::setLabel(const DNSName& label) {
   d_label = label;
   if (s_gss_sec_context.find(d_label) != s_gss_sec_context.end()) {
     d_ctx = s_gss_sec_context[d_label];
@@ -227,7 +226,7 @@ bool GssContext::init(const std::string &input, std::string& output) {
     }
   } else {
     // make context
-    s_gss_sec_context[d_label] = boost::make_shared<GssSecContext>(d_label, cred);
+    s_gss_sec_context[d_label] = boost::make_shared<GssSecContext>(cred);
     s_gss_sec_context[d_label]->d_type = d_type;
     d_ctx = s_gss_sec_context[d_label];
     d_ctx->d_state = GssSecContext::GssStateNegotiate;
@@ -298,7 +297,7 @@ bool GssContext::accept(const std::string &input, std::string& output) {
     } 
   } else {
     // make context
-    s_gss_sec_context[d_label] = boost::make_shared<GssSecContext>(d_label, cred);
+    s_gss_sec_context[d_label] = boost::make_shared<GssSecContext>(cred);
     s_gss_sec_context[d_label]->d_type = d_type;
     d_ctx = s_gss_sec_context[d_label];
     d_ctx->d_state = GssSecContext::GssStateNegotiate;
@@ -434,7 +433,7 @@ void GssContext::processError(const std::string& method, OM_uint32 maj, OM_uint3
 
 bool gss_add_signature(const DNSName& context, const std::string& message, std::string& mac) {
   string tmp_mac;
-  GssContext gssctx(context.toStringNoDot());
+  GssContext gssctx(context);
   if (!gssctx.valid()) {
     L<<Logger::Error<<"GSS context '"<<context<<"' is not valid"<<endl;
     BOOST_FOREACH(const string& error, gssctx.getErrorStrings()) {
@@ -455,7 +454,7 @@ bool gss_add_signature(const DNSName& context, const std::string& message, std::
 }
 
 bool gss_verify_signature(const DNSName& context, const std::string& message, const std::string& mac) {
-  GssContext gssctx(context.toStringNoDot());
+  GssContext gssctx(context);
   if (!gssctx.valid()) {
     L<<Logger::Error<<"GSS context '"<<context<<"' is not valid"<<endl;
     BOOST_FOREACH(const string& error, gssctx.getErrorStrings()) {
index d9f519b6a694ff97c6d2ab85da820f2c910c8f4d..da47631251ad77923a4d6795c7e67e92e5e824a6 100644 (file)
@@ -120,7 +120,7 @@ class GssContext {
 public:
   static bool supported(); //<! Returns true if GSS is supported in the first place
   GssContext(); //<! Construct new GSS context with random name
-  GssContext(const std::string& label); //<! Create or open existing named context
+  GssContext(const DNSName& label); //<! Create or open existing named context
 
   void setLocalPrincipal(const std::string& name); //<! Set our gss name
   bool getLocalPrincipal(std::string& name); //<! Get our name
@@ -128,8 +128,8 @@ public:
   bool getPeerPrincipal(std::string &name); //<! Return remote name, returns actual name after negotatioan
 
   void generateLabel(const std::string& suffix); //<! Generate random context name using suffix (such as mydomain.com)
-  void setLabel(const std::string& label); //<! Set context name to this label
-  const std::string& getLabel() { return d_label; } //<! Return context name
+  void setLabel(const DNSName& label); //<! Set context name to this label
+  const DNSName& getLabel() { return d_label; } //<! Return context name
 
   bool init(const std::string &input, std::string& output); //<! Perform GSS Initiate Security Context handshake
   bool accept(const std::string &input, std::string& output); //<! Perform GSS Acccept Security Context handshake
@@ -148,7 +148,7 @@ public:
 #ifdef ENABLE_GSS_TSIG
   void processError(const string& method, OM_uint32 maj, OM_uint32 min); //<! Process and fill error text vector
 #endif
-  std::string d_label; //<! Context name
+  DNSName d_label; //<! Context name
   std::string d_peerPrincipal; //<! Remote name
   std::string d_localPrincipal; //<! Our name
   GssContextError d_error; //<! Context error
index 50fbcb1998481b5d88d5db206be065703188ff92..2ed23adc206c35cc250cc7f7abdea716f1980f39 100644 (file)
@@ -1154,7 +1154,7 @@ DNSPacket *PacketHandler::questionOrRecurse(DNSPacket *p, bool *shouldRecurse)
     } else {
       getTSIGHashEnum(trc.d_algoName, p->d_tsig_algo);
       if (p->d_tsig_algo == TSIG_GSS) {
-        GssContext gssctx(keyname.toStringNoDot());
+        GssContext gssctx(keyname);
         if (!gssctx.getPeerPrincipal(p->d_peer_principal)) {
           L<<Logger::Warning<<"Failed to extract peer principal from GSS context with keyname '"<<keyname<<"'"<<endl;
         }
index df8ea6ba6c52e7d723dd8c22566aaca167e4682e..d0ce7f42eb6ff7816a25d2d98f585d76be49bb70 100644 (file)
@@ -504,7 +504,7 @@ int AXFRRetriever::getChunk(Resolver::res_t &res) // Implementation is making su
       }
 
       if (algo == TSIG_GSS) {
-        GssContext gssctx(d_tsigkeyname.toStringNoDot());
+        GssContext gssctx(d_tsigkeyname);
         if (!gss_verify_signature(d_tsigkeyname, message, theirMac)) {
           throw ResolverException("Signature failed to validate on AXFR response from "+d_remote.toStringWithPort()+" signed with TSIG key '"+d_tsigkeyname.toString()+"'");
         }
index 5f048f2a07664be1ec95ce5dbe418bfb94cb7b5b..26b4919482b5d087b002282353ace2bf044161fc 100644 (file)
@@ -16,7 +16,7 @@
 
 StatBag S;
 
-bool validateTSIG(const string& message, const TSIGHashEnum& algo, const string& key, const string& secret, const TSIGRecordContent *trc) {
+bool validateTSIG(const string& message, const TSIGHashEnum& algo, const DNSName& key, const string& secret, const TSIGRecordContent *trc) {
   int64_t now = time(0);
   if(abs((int64_t)trc->d_time - now) > trc->d_fudge) {
     cerr<<"TSIG (key '"<<key<<"') time delta "<< abs(trc->d_time - now)<<" > 'fudge' "<<trc->d_fudge<<endl;
index 9496ba0d2db2914dd08a4d4e95b120be77573420..4ffabf6f0239e682b707e0e7266cea22ad89688b 100644 (file)
@@ -411,7 +411,7 @@ bool TCPNameserver::canDoAXFR(shared_ptr<DNSPacket> q)
     } else {
       getTSIGHashEnum(trc.d_algoName, q->d_tsig_algo);
       if (q->d_tsig_algo == TSIG_GSS) {
-        GssContext gssctx(keyname.toStringNoDot());
+        GssContext gssctx(keyname);
         if (!gssctx.getPeerPrincipal(q->d_peer_principal)) {
           L<<Logger::Warning<<"Failed to extract peer principal from GSS context with keyname '"<<keyname<<"'"<<endl;
         }
index fa9283de295af544f0f19d005f196bcda13de8b5..18103f63fc27e852a886eb70d6cf4531f6648ff2 100644 (file)
@@ -22,7 +22,7 @@ void PacketHandler::tkeyHandler(DNSPacket *p, DNSPacket *r) {
   tkey_out->d_inception = time((time_t*)NULL);
   tkey_out->d_expiration = tkey_out->d_inception+15;
 
-  GssContext ctx(name.toStringNoDot());
+  GssContext ctx(name);
 
   if (tkey_in.d_mode == 3) { // establish context
     if (tkey_in.d_algo == DNSName("gss-tsig.")) {