Author |
Message |
Doc Flabby Server Help Squatter

Joined: Feb 26 2006 Posts: 636 Offline
|
Posted: 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  _________________ Rediscover online gaming. Get Subspace | STF The future...prehaps
enc
enc_ss2.c - 7.69 KB
File downloaded or viewed 32 time(s)
|
|
Back to top |
|
 |
D1st0rt Miss Directed Wannabe

Age:37 Gender: Joined: Aug 31 2003 Posts: 2247 Location: Blacksburg, VA Offline
|
Posted: 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? _________________
|
|
Back to top |
|
 |
Doc Flabby Server Help Squatter

Joined: Feb 26 2006 Posts: 636 Offline
|
Posted: 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
|
|
Back to top |
|
 |
Doc Flabby Server Help Squatter

Joined: Feb 26 2006 Posts: 636 Offline
|
Posted: Sun Jan 20, 2008 9:55 am Post subject: |
 |
|
|
|
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.
|
|
Back to top |
|
 |
k0zy Server Help Squatter

Gender: Joined: Jan 11 2003 Posts: 571 Location: Germany Offline
|
Posted: Sun Jan 20, 2008 10:22 am Post subject: |
 |
|
|
|
Maybe some other thread manipulates "ed" so it equals a value interpreted as false? _________________ It's a shark! Oh my god! Unbelievable!
|
|
Back to top |
|
 |
Dr Brain Flip-flopping like a wind surfer

Age:39 Gender: Joined: Dec 01 2002 Posts: 3502 Location: Hyperspace Offline
|
Posted: Sun Jan 20, 2008 10:25 am Post subject: |
 |
|
|
|
Set a breakpoint in the calling function and step it through. _________________ Hyperspace Owner
Smong> so long as 99% deaths feel lame it will always be hyperspace to me
|
|
Back to top |
|
 |
Doc Flabby Server Help Squatter

Joined: Feb 26 2006 Posts: 636 Offline
|
Posted: Sun Jan 20, 2008 10:37 am Post subject: |
 |
|
|
|
I located the problem
int do_dec(EncData *ed, byte *data, int len)
|
needed to be
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...
|
|
Back to top |
|
 |
Mine GO BOOM Hunch Hunch What What

Age:41 Gender: Joined: Aug 01 2002 Posts: 3615 Location: Las Vegas Offline
|
Posted: 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.
|
|
Back to top |
|
 |
k0zy Server Help Squatter

Gender: Joined: Jan 11 2003 Posts: 571 Location: Germany Offline
|
Posted: 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.
|
|
Back to top |
|
 |
Mine GO BOOM Hunch Hunch What What

Age:41 Gender: Joined: Aug 01 2002 Posts: 3615 Location: Las Vegas Offline
|
Posted: 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.
|
|
Back to top |
|
 |
Dr Brain Flip-flopping like a wind surfer

Age:39 Gender: Joined: Dec 01 2002 Posts: 3502 Location: Hyperspace Offline
|
Posted: 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.
|
|
Back to top |
|
 |
Animate Dreams Gotta buy them all! (Consumer whore)

Age:37 Gender: Joined: May 01 2004 Posts: 821 Location: Middle Tennessee Offline
|
Posted: 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?
|
|
Back to top |
|
 |
Cyan~Fire I'll count you!

Age:37 Gender: Joined: Jul 14 2003 Posts: 4608 Location: A Dream Offline
|
Posted: 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. _________________ This help is informational only. No representation is made or warranty given as to its content. User assumes all risk of use. Cyan~Fire assumes no responsibility for any loss or delay resulting from such use.
Wise men STILL seek Him.
|
|
Back to top |
|
 |
Goldeye Novice
Gender: Joined: Dec 15 2003 Posts: 57 Offline
|
Posted: 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.
|
|
Back to top |
|
 |
|