Page 1 of 2

PacketDocu: 0x0065 - Send Crypt (login server)

PostPosted: Sat Jul 19, 2003 4:23 pm
by duff
packet send by login server to client to send crypte key on connection of client
Code: Select all
Packet Structure:
//packet hdr
0x02 bytes = UNKNOWN
0x02 bytes = Packet Size (always 22)
0x02 bytes = code of packet (0x0065)
0x01 bytes = checksum (65)
0x01 bytes = sequence (0x6e)
//packet data
0x01 bytes = 0x01
0x01 bytes = 0x00
0x0D bytes = crypte key
0x03 bytes = 0x000000

PostPosted: Tue Jan 27, 2004 12:00 pm
by wad
In version 1.66+ this packet have a new format.
Code: Select all
Packet header...
...
End of packet header.
Packet body (all words is in network bytes order):
offset 0: word - crypt version (1 - new);
offset 2: word - unknown (not important);
offset 4: word - size of crypt block;
Begin of crypt block:
offset 6: word - size of crypt key;
offset 8: X bytes - RSA public key in special exported format from
[url]http://math.libtomcrypt.org[/url]
Functions for key creation:
rsa_make_key( &prng, find_prng( "sprng"), 2048 / 8, 65537, &key);
rsa_export( outbuf, &outlen, PK_PUBLIC, &key);

NOTE: Please use only TomCrypt version 9.1, exported key have version of this lib inside.

PostPosted: Tue Jan 27, 2004 12:35 pm
by duff
hmmm
hi wad but for moment we can just make a quick hack and put it later because do not think it s really important

PostPosted: Tue Jan 27, 2004 12:40 pm
by wad
i don't care, i just dig and share information :cool:

PostPosted: Sun Feb 01, 2004 9:55 pm
by duff
lib is for c and we are in c#but thanks for that

PostPosted: Mon Feb 02, 2004 11:27 am
by wad
No way to make tomcryptlib.dll and use it in the DOL?

PostPosted: Mon Feb 02, 2004 11:52 am
by duff
yes we can but .net ever done a great part of RSA so no need of that

PostPosted: Mon Feb 02, 2004 12:23 pm
by wad
and this 'great part of rsa' in the .net have compatibly with tomcrypt? :)

PostPosted: Mon Feb 02, 2004 1:31 pm
by duff
for the special exported format
i try to use the
return keyexchangeformatter.CreateKeyExchange(rgbldata);
function of .net framework
but you put special so i think rgbldata are fixed so what is it?

PostPosted: Mon Feb 02, 2004 1:54 pm
by wad
i think - microsoft stuff is not compatible with anything :)
You must use only the tomcrypt library, and only the version 9.1.
Not MS Crypt, not OpenSSL or SSLEay - only TomCrypt. sorry.

PostPosted: Mon Feb 02, 2004 3:14 pm
by Technoboy
Format of the public key

4 bytes - signature from TomCrypt
Then
BIGNUM - Public key modulus
BIGNUM - Public key Exp

With
BIGNUM:
4 bytes - Length
* bytes - Number

As an add-on, everything uses the PKCS#1 padding.

PostPosted: Mon Feb 02, 2004 3:26 pm
by wad
and how you will convert this from CreateKeyExchange(), Technoboy?

PostPosted: Mon Feb 02, 2004 3:54 pm
by Technoboy
Ok, additions, and answers:

The header is basically first byte as version. TomCrypt only look at it being <= 0x91 so put whatever you want with it.

To get the public key from the MS api, just use the ExportParameter method on your crypto provider, and generate the key by using the mod and exp

This public key goes to the client side, the client uses it to encrypt a random number that is generated by using the pseudo random generator from the plain C++ CryptoAPI (AcquireContext and friends). This is absolutely equivalent to do the CreateKeyExchange, as from what i understand what is sent by the server is its public key and only that.

Once the key exchange hash is generated on the client it sends it back in 0x14B

If you look at the code for a CreateKeyExchange that you created from a provider created itself from the given public key, the call will resolve to provider.Encrypt() and return you with the encryption of the data with the public key.

PostPosted: Wed Apr 14, 2004 3:06 pm
by duff
can i have some log about crypt key and logger on login server to see order of packet send and see the exacte packet headler because not sure for version example if it s 0x0091 (it s a ushort) do i put write(00) and after write(91) or just add with low endian write(91) and afer(00)
same for modulus lenght and exponent lenght (it s int but do not know if put the begin or the end before)
to sum up :like a stack or not?

PostPosted: Wed Apr 14, 2004 6:36 pm
by Smallhorse
Ah duff, for login server you need to make it different :) You get this packet from the gameclient -> Server and inside the server you need to extract the "public key" from the message (its in tomcrypt format, just like in my example) ... but you need to import the public key to the RSAManaged class, not export it... so it ís easier :) and then you need to do Crypt on outgoing packet