]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
Added AES
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>
Mon, 19 Dec 2005 14:33:11 +0000 (14:33 +0000)
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>
Mon, 19 Dec 2005 14:33:11 +0000 (14:33 +0000)
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@2569 e03df62e-2008-0410-955e-edbf42e46eb7

src/aes.cpp
src/modules/m_spanningtree.cpp

index c9189d68f25717351b12be62a05c8ef1fa4db0fb..25f29d4bac58807b23014a3a3e01abbc4fea0da6 100644 (file)
@@ -1389,7 +1389,7 @@ static const char base64val[] = {
     BAD, 26, 27, 28,  29, 30, 31, 32,  33, 34, 35, 36,  37, 38, 39, 40,
      41, 42, 43, 44,  45, 46, 47, 48,  49, 50, 51,BAD, BAD,BAD,BAD,BAD
 };
-#define DECODE64(c)  (isascii(c) ? base64val[c] : BAD)
+#define DECODE64(c)  (c < 128 ? base64val[c] : BAD)
 
 void to64frombits(unsigned char *out, const unsigned char *in, int inlen)
 /* raw bytes in quasi-big-endian order to base 64 string (NUL-terminated) */
index 55313eb053934eba03f7b31af9ab0f502ac785e0..568dbf3108261d7bf9c96297275959c0795bc28e 100644 (file)
@@ -539,6 +539,7 @@ class TreeSocket : public InspSocket
        bool LastPingWasGood;
        bool bursting;
        AES* ctx;
+       unsigned int keylength;
        
  public:
 
@@ -554,23 +555,21 @@ class TreeSocket : public InspSocket
                this->LinkState = LISTENER;
        }
 
-       TreeSocket(std::string host, int port, bool listening, unsigned long maxtime, std::string ServerName, std::string encryptionkey)
+       TreeSocket(std::string host, int port, bool listening, unsigned long maxtime, std::string ServerName)
                : InspSocket(host, port, listening, maxtime)
        {
                myhost = ServerName;
                this->LinkState = CONNECTING;
-               InitAES(encryptionkey);
        }
 
        /* When a listening socket gives us a new file descriptor,
         * we must associate it with a socket without creating a new
         * connection. This constructor is used for this purpose.
         */
-       TreeSocket(int newfd, char* ip, std::string encryptionkey)
+       TreeSocket(int newfd, char* ip)
                : InspSocket(newfd, ip)
        {
                this->LinkState = WAIT_AUTH_1;
-               InitAES(encryptionkey);
        }
 
        void InitAES(std::string key)
@@ -580,13 +579,14 @@ class TreeSocket : public InspSocket
 
                ctx = new AES();
                // key must be 16, 24, 32 etc bytes (multiple of 8)
-               unsigned int keylength = key.length();
+               keylength = key.length();
                if (!(keylength == 16 || keylength == 24 || keylength == 32))
                {
+                       log(DEBUG,"Key length not 16, 24 or 32 characters!");
                }
                else
                {
-                       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
+                       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);
                }
        }
@@ -1166,7 +1166,7 @@ class TreeSocket : public InspSocket
                                        char result[1024];
                                        int nbytes = from64tobits(out, ret.c_str(), 1024);
                                        log(DEBUG,"m_spanningtree: decrypt %d bytes",nbytes);
-                                       ctx->Decrypt(out, result, nbytes, AES::ECB);
+                                       ctx->Decrypt(out, result, nbytes, 0);
                                        ret = result;
                                }
                                if (!this->ProcessLine(ret))
@@ -1183,15 +1183,17 @@ class TreeSocket : public InspSocket
                log(DEBUG,"OUT: %s",line.c_str());
                if (ctx)
                {
-                       char* result[1024];
-                       char* result64[1024];
+                       char result[1024];
+                       char result64[1024];
                        while (line.length() % this->keylength != 0)
                        {
                                // pad it to be a multiple of the key length
                                line = line + "\0";
                        }
-                       ctx->Encrypt(line.c_str(), result, line.length(), AES::ECB);
-                       to64frombits(result64, result, line.length());
+                       ctx->Encrypt(line.c_str(), result, line.length(),0);
+                       to64frombits((unsigned char*)result64,
+                                       (unsigned char*)result,
+                                       line.length());
                        line = result64;
                        log(DEBUG,"Encrypted: %s",line.c_str());
                        //int from64tobits(char *out, const char *in, int maxlen);
@@ -1894,6 +1896,16 @@ 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