Server Help

ASSS Questions - Module works on windows, but not linux

Doc Flabby - Thu Jan 17, 2008 5:48 am
Post subject: Module works on windows, but not linux
I've created my own "encryption" module. The code compiles on both platforms, but doesnt work properly on linux, basically is doesnt decrypt the packets on linux, but it does on windows. I don't know much about C so i'm guessing something i've done with the pointers is dangerous so linux doesn't like it but windows doesn't care. I've attached the code.

I'm probably doing something really stupid icon_smile.gif
D1st0rt - Thu Jan 17, 2008 12:50 pm
Post subject:
Without looking at it, I would wonder if byte order perhaps had something to do with it?
Doc Flabby - Fri Jan 18, 2008 4:49 am
Post subject:
D1st0rt wrote:
Without looking at it, I would wonder if byte order perhaps had something to do with it?

The byte order should be the same, as both systems are 32-bit Intel x86.

Also it just seems like the its doing the decryption fine, but then not passing the value back to ASSS. Instead it uses the value originally passed to it. Bizarrly on windows its works fine, with the same code icon_sad.gif
Doc Flabby - Sun Jan 20, 2008 9:55 am
Post subject:
Code: Show/Hide

int do_dec(EncData *ed, byte *data, int len)
{
   //packet to small
   if(len < 13) return 0; 
         
   //my key holds key
   byte *mykey = (byte*)ed->key;
   //display IV if its there
    #ifdef CFG_LOG_CONNECTION
    lm->Log(L_DRIVEL, "<enc_ss2> CLIENTKEY");
    dump_pk(mykey,16);
    lm->Log(L_DRIVEL, "<enc_ss2> END KEY"); 
    #endif
   //get IV
   byte *IV = data;   
   byte *Content = data+8;
   
   byte* moreData = amalloc(len-8);
   memcpy(moreData, Content, len-8);

   //init and clear decryption key
   byte deckey[24];
   memset(&deckey[0], 0, 24);
   byte* deckeypos = &deckey[0];

   memcpy (deckeypos, mykey, 16);
   memcpy (deckeypos+16, IV, 8);

   #ifdef CFG_LOG_CONNECTION
   lm->Log(L_DRIVEL, "<enc_ss2> IV");
   dump_pk(deckeypos,24);
   lm->Log(L_DRIVEL, "<enc_ss2> END IV"); 
   #endif

   struct MD5Context ctx;

   byte out[16];

   MD5Init(&ctx);
   MD5Update(&ctx, deckeypos, 24);
   MD5Final(out, &ctx);

    #ifdef CFG_LOG_CONNECTION
   lm->Log(L_DRIVEL, "<enc_ss2> MD5");
   dump_pk(&out[0],16);
   lm->Log(L_DRIVEL, "<enc_ss2> END MD5"); 
   #endif
   //out contains the sessionkey
   
   
    #ifdef CFG_LOG_CONNECTION
   lm->Log(L_DRIVEL, "<enc_ss2> DATA TO DECRYPT");
   dump_pk(moreData,len-8);
   lm->Log(L_DRIVEL, "<enc_ss2> END DATA TO DECRYPT"); 
   #endif

   rc4_skip((byte*)&out, 16, 1024,moreData,len-8);
   
   memcpy(data,moreData+4,len-12);
   afree(moreData);
   
    #ifdef CFG_LOG_CONNECTION
   lm->Log(L_DRIVEL, "<enc_ss2> DECRYPTED DATA");
   dump_pk(data,len-12);
   lm->Log(L_DRIVEL, "<enc_ss2> END DECRYPTED DATA"); 
   #endif
   

   
   return len-12;
}

int Decrypt(Player *p, byte *data, int len)
{
   #ifdef CFG_LOG_CONNECTION
   lm->Log(L_DRIVEL, "<enc_ss2> Decrypt %i",len);
   #endif
   EncData *ed, **p_ed = PPDATA(p, enckey);
   pthread_mutex_lock(&mtx);
   ed = *p_ed;
   pthread_mutex_unlock(&mtx);
   return ed ? do_dec(ed, data, len) : len;
}


I've narrowed down the problem. do_dec(ed, data, len) is not being called. However it should be as I have unwravelled the line into separate if statements and can confirm ed does exist so it should be called.
k0zy - Sun Jan 20, 2008 10:22 am
Post subject:
Maybe some other thread manipulates "ed" so it equals a value interpreted as false?
Dr Brain - Sun Jan 20, 2008 10:25 am
Post subject:
Set a breakpoint in the calling function and step it through.
Doc Flabby - Sun Jan 20, 2008 10:37 am
Post subject:
I located the problem

Code: Show/Hide

int do_dec(EncData *ed, byte *data, int len)

needed to be
Code: Show/Hide

local int do_dec(EncData *ed, byte *data, int len)

works like a charm now. Still don't understand what the difference between the two is...but nevermind...
Mine GO BOOM - Sun Jan 20, 2008 3:40 pm
Post subject:
local is an alias for static in ASSS. When you make a function static in C, it is known only in that file, no other. It helps keep the namespace clean.

GCC compiler attempted to find the best do_dec when compiling that file, and it found correct one. Windows's compiler attempted to find the best one, and it sounds like it found the vie encryption's do_dec, which is not local. It failed the tests in there, and returned nothing.

So yes, this is a bug in ASSS where the vie encryption's file is filling the namespace with functions it shouldn't be. I'd recommend reporting it as a bug.
k0zy - Sun Jan 20, 2008 3:54 pm
Post subject:
Mine GO BOOM wrote:
GCC compiler attempted to find the best do_dec when compiling that file, and it found correct one. Windows's compiler attempted to find the best one, and it sounds like it found the vie encryption's do_dec, which is not local. It failed the tests in there, and returned nothing.


I didn't understand that...
The way you explained it, it would have failed on windows and not on linux.
Mine GO BOOM - Sun Jan 20, 2008 8:31 pm
Post subject:
Bob Dole.. Bob Dole... Bob Dole...... bob dole.... bob... dole.... wrote:
I didn't understand that...
The way you explained it, it would have failed on windows and not on linux.

Ok, so I got it reversed. Either way, one of the compilers found the right function, and the other one didn't. The real issue is that there are two functions of the same prototype trying to fill the same namespace. I'm pretty sure one or both of the compilers should show a warning about that.
Dr Brain - Mon Jan 21, 2008 12:07 pm
Post subject:
Actually, from my understanding, it was a linker issue, and not a compiler one.

The dynamic linker tries to resolve things a little differently between the two operating systems. So when it was loaded under linux, it used the function that already existed in memory, where as in windows it used the function that was in the .dll.
Animate Dreams - Mon Jan 21, 2008 10:22 pm
Post subject: Re: Module works on windows, but not linux
Doc Flabby wrote:
I don't know much about C so i'm guessing something i've done with the pointers is dangerous so linux doesn't like it but windows doesn't care.


I've always heard that Linux cared much less about things like that. That Linux didn't try to protect the OS from the user. So wouldn't that go the opposite way?
Cyan~Fire - Mon Jan 21, 2008 11:53 pm
Post subject:
Apples and oranges. Windows generally tries to separate the internals of the OS from the user with lots of nice, easy-to-use (ahem) dialogs, while Linux typically allows the user lots of options through text config files and stuff. How the operating system deals with applications is unrelated.
Goldeye - Thu Jan 31, 2008 11:21 pm
Post subject: Re: Module works on windows, but not linux
Animate Dreams wrote:
[..]



I've always heard that Linux cared much less about things like that. That Linux didn't try to protect the OS from the user. So wouldn't that go the opposite way?


This is the compiler and linker we're talking about, not the OS, anyway. (Though I guess ld is part of the os?)
Any system should report what it's doing for an undefined behavior.


Anyway, Flabby. Just add local to the do_enc in both files. Also. probably a good idea to just change the function names in your module.
All times are -5 GMT
View topic
Powered by phpBB 2.0 .0.11 © 2001 phpBB Group