]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_spanningtree.cpp
Changed AES negotiation to occur before SERVER
[user/henk/code/inspircd.git] / src / modules / m_spanningtree.cpp
index 9a5b13734d94bb637429fc6c1746fb62f112ec58..09a3b2c56b2a0b302e62d858c3dbc290621f2b4c 100644 (file)
@@ -583,10 +583,17 @@ class TreeSocket : public InspSocket
                keylength = key.length();
                if (!(keylength == 16 || keylength == 24 || keylength == 32))
                {
+                       WriteOpers("\2ERROR\2: Key length for encryptionkey is not 16, 24 or 32 bytes in length!");
                        log(DEBUG,"Key length not 16, 24 or 32 characters!");
                }
                else
                {
+                       std::string SName = myhost;
+                       if (InboundServerName != "")
+                       {
+                               SName = InboundServerName;
+                       }
+                       WriteOpers("\2AES\2: Initialized %d bit encryption to server %s",keylength*8,SName.c_str());
                        ctx->MakeKey(key.c_str(), "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\
                                \0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", keylength, keylength);
                }
@@ -608,6 +615,11 @@ class TreeSocket : public InspSocket
                        {
                                if (x->Name == this->myhost)
                                {
+                                       if (x->EncryptionKey != "")
+                                       {
+                                               this->WriteLine("AES "+Srv->GetServerName());
+                                               this->InitAES(x->EncryptionKey);
+                                       }
                                        /* found who we're supposed to be connecting to, send the neccessary gubbins. */
                                        this->WriteLine("SERVER "+Srv->GetServerName()+" "+x->SendPass+" 0 :"+Srv->GetServerDescription());
                                        return true;
@@ -1141,7 +1153,6 @@ class TreeSocket : public InspSocket
                char* data = this->Read();
                if (data)
                {
-                       Srv->Log(DEBUG,"m_spanningtree: READ");
                        this->in_buffer += data;
                        /* While there is at least one new line in the buffer,
                         * do something useful (we hope!) with it.
@@ -1169,6 +1180,8 @@ class TreeSocket : public InspSocket
                                        int nbytes = from64tobits(out, ret.c_str(), 1024);
                                        log(DEBUG,"m_spanningtree: decrypt %d bytes",nbytes);
                                        ctx->Decrypt(out, result, nbytes, 0);
+                                       for (int t = 0; t < nbytes; t++)
+                                               if (result[t] == '\7') result[t] = 0;
                                        ret = result;
                                }
                                if (!this->ProcessLine(ret))
@@ -1193,7 +1206,7 @@ class TreeSocket : public InspSocket
                                while (line.length() % this->keylength != 0)
                                {
                                        // pad it to be a multiple of the key length
-                                       line = line + "\n";
+                                       line = line + "\7";
                                }
                        }
                        ctx->Encrypt(line.c_str(), result, line.length(),0);
@@ -1698,6 +1711,19 @@ class TreeSocket : public InspSocket
                        command = params[0];
                        params.pop_front();
                }
+
+               if ((!this->ctx) && (command == "AES"))
+               {
+                        std::string sserv = params[0];
+                        for (std::vector<Link>::iterator x = LinkBlocks.begin(); x < LinkBlocks.end(); x++)
+                        {
+                                if ((x->EncryptionKey != "") && (x->Name == sserv))
+                                {
+                                        this->InitAES(x->EncryptionKey);
+                                }
+                        }
+                        return true;
+               }
                
                switch (this->LinkState)
                {
@@ -1902,16 +1928,6 @@ class TreeSocket : public InspSocket
                                else if (command == "ENDBURST")
                                {
                                        this->bursting = false;
-                                       std::string sserv = this->myhost;
-                                       if (this->InboundServerName != "")
-                                               sserv = this->InboundServerName;
-                                       for (std::vector<Link>::iterator x = LinkBlocks.begin(); x < LinkBlocks.end(); x++)
-                                       {
-                                               if ((x->EncryptionKey != "") && (x->Name == sserv))
-                                               {
-                                                       this->InitAES(x->EncryptionKey);
-                                               }
-                                       }
                                        return true;
                                }
                                else