Bryan Drewery преди 16 години
родител
ревизия
9fe5a9ae39
променени са 3 файла, в които са добавени 13 реда и са изтрити 13 реда
  1. 1 1
      src/base64.c
  2. 1 1
      src/base64.h
  3. 11 11
      src/mod/irc.mod/irc.c

+ 1 - 1
src/base64.c

@@ -73,7 +73,7 @@ static char base64to[256] =
 };
 
 
-int base64_to_int(char *buf)
+int base64_to_int(const char *buf)
 {
   int i = 0;
 

+ 1 - 1
src/base64.h

@@ -7,7 +7,7 @@ namespace bd {
 };
 
 char *int_to_base64(unsigned int);
-int base64_to_int(char *);
+int base64_to_int(const char *);
 
 bd::String broken_base64Encode(const bd::String&);
 char *b64enc(const unsigned char *data, size_t len);

+ 11 - 11
src/mod/irc.mod/irc.c

@@ -56,6 +56,7 @@
 #include "src/mod/ctcp.mod/ctcp.h"
 #include <bdlib/src/String.h>
 #include <bdlib/src/HashTable.h>
+#include <bdlib/src/base64.h>
 
 #include <stdarg.h>
 
@@ -402,7 +403,8 @@ void makecookie(char *out, size_t len, const char *chname, const memberlist* opp
   const char* hash1 = cookie_hash(chname, opper, m1, &ts[4], randstring, key);
   const char* hash2 = m2 ? cookie_hash(chname, opper, m2, &ts[4], randstring, key) : NULL;
   const char* hash3 = m3 ? cookie_hash(chname, opper, m3, &ts[4], randstring, key) : NULL;
-  const char* cookie = encrypt_string(MD5(key), cookie_clear);
+  bd::String cookie = encrypt_string(MD5(key), bd::String(cookie_clear));
+  cookie = bd::base64Encode(cookie);
 #ifdef DEBUG
 sdprintf("key: %s", key);
 sdprintf("cookie_clear: %s", cookie_clear);
@@ -423,7 +425,7 @@ if (hash3) sdprintf("hash3: %s", hash3);
                          hash3[HASH_INDEX2(2)], 
                          hash3[HASH_INDEX3(2)], 
                          randstring, 
-                         cookie);
+                         cookie.c_str());
   else if (m2)
     simple_snprintf(out, len + 1, STR("%c%c%c%c%c%c!%s@%s"), 
                          hash1[HASH_INDEX1(0)], 
@@ -433,18 +435,17 @@ if (hash3) sdprintf("hash3: %s", hash3);
                          hash2[HASH_INDEX2(1)], 
                          hash2[HASH_INDEX3(1)], 
                          randstring, 
-                         cookie);
+                         cookie.c_str());
   else
     simple_snprintf(out, len + 1, STR("%c%c%c!%s@%s"), 
                          hash1[HASH_INDEX1(0)], 
                          hash1[HASH_INDEX2(0)], 
                          hash1[HASH_INDEX3(0)], 
                          randstring, 
-                         cookie);
+                         cookie.c_str());
 #ifdef DEBUG
 sdprintf("cookie: %s", out);
 #endif
-  free((char*)cookie);
 }
 
 // Clear counter for bot
@@ -463,10 +464,11 @@ static inline int checkcookie(const char *chname, const memberlist* opper, const
 
   cookie_key(key, sizeof(key), randstring, opper, chname);
 
-  char* cleartext = decrypt_string(MD5(key), (char*) &cookie[HOST(0)]);
+  bd::String ciphertext = bd::base64Decode((char*) &cookie[HOST(0)]);
+  bd::String cleartext = decrypt_string(MD5(key), ciphertext);
   char ts[8] = "";
-  strlcpy(ts, cleartext + 4, sizeof(ts));
-  unsigned long counter = base64_to_int(cleartext + 4 + 7);
+  strlcpy(ts, cleartext.c_str() + 4, sizeof(ts));
+  unsigned long counter = base64_to_int(cleartext.c_str() + 4 + 7);
 
   //Lookup counter for the opper
   unsigned long last_counter = 0;
@@ -482,7 +484,7 @@ static inline int checkcookie(const char *chname, const memberlist* opper, const
 
 #ifdef DEBUG
 sdprintf("key: %s", key);
-sdprintf("plaintext from cookie: %s", cleartext);
+sdprintf("plaintext from cookie: %s", cleartext.c_str());
 sdprintf("ts from cookie: %s", ts);
 if (indexHint == 0) {
   sdprintf("last counter from %s: %lu", opper->user->handle, last_counter);
@@ -490,8 +492,6 @@ if (indexHint == 0) {
 }
 #endif
 
-  free(cleartext);
-
   const time_t optime = atol(ts);
   if ((((now + timesync) % 10000000) - optime) > 3900)
     return BC_SLACK;