Register for your free account! | Forgot your password?

You last visited: Today at 04:23

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



Game encryption

Discussion on Game encryption within the CO2 Programming forum part of the Conquer Online 2 category.

Reply
 
Old   #1
 
TomasLT's Avatar
 
elite*gold: 0
Join Date: Nov 2006
Posts: 286
Received Thanks: 38
Game encryption

Past few days i read lots of articles about DHkeyexchange/blowfish. And now i i am more confused. So i need a deep explaining about game encryption. For example about first packets from server. which packet contains the keys, and so on .So if some1 want to help a litle bit write it here or add me on MSN. () .
TomasLT is offline  
Thanks
1 User
Old 03/27/2011, 06:45   #2
 
elite*gold: 0
Join Date: Jun 2006
Posts: 457
Received Thanks: 67
I was expecting this coming. You are not really asking for explanation, you are asking for solution. If you follow korvac's guide carefully AND if you had enough understanding of DH exchange, you will not be asking this question. Also, use search function wisely. I am pretty sure you also bumped one of the threads i have started when i had problems with DH exchange & blowfish.

Funny enough, if you google java dh exchange and blowfish, the first couple links are all threads started by me struggling to get help from different java forums.

Anyway. google as much material as you can about DH exchange theory (wiki is not always the best place, try google image search) and java implementations. Similarly you also need to figure out how to really use a blowfish cipher in java. When you get to the right stage and start asking the correct questions, i'd be glad to help you, which will save you from all the detours that i have taken.

I hope you really took time to read through this thread and do as I suggested. Else you will have to pray some extremely patient kind heart will step out to help you.
shitboi is offline  
Thanks
1 User
Old 03/27/2011, 14:48   #3
 
TomasLT's Avatar
 
elite*gold: 0
Join Date: Nov 2006
Posts: 286
Received Thanks: 38
Ok. I will read more about DH key exchange. Ang about what korvac's guide do u speak ?
TomasLT is offline  
Thanks
1 User
Old 03/27/2011, 15:48   #4
 
elite*gold: 0
Join Date: Jun 2006
Posts: 457
Received Thanks: 67

is what i am talking about. Pay extra attention to the preface he has written and keyexchange.cs.

Work on simple java programs that actually performs key exchange.
Eg, try to write a noob client and server that performs a DH exchange, and chats with one another with msg encoded in blowfish.

You can try to find out the threads started by me, one of them will answer a lot of your questions and give you a good lead.
shitboi is offline  
Thanks
1 User
Old 03/27/2011, 18:22   #5
 
TomasLT's Avatar
 
elite*gold: 0
Join Date: Nov 2006
Posts: 286
Received Thanks: 38
Ok. I will say what did i understand and if i'm wrong please correct me.

So Server generate private key. And Client generate his own private key.

Then server and client generate his own public key .

Then they exchange theres public keys (how do they exchange it ?).

So then some DH calculation and they have shared key which is same for server and client.

So with this key packets is encrypted using blowfish algoritm and sended to to other side ( Server -> client / Client ->server) .

So what do i need to know more ?
TomasLT is offline  
Thanks
1 User
Old 03/27/2011, 18:46   #6
 
elite*gold: 0
Join Date: Jun 2006
Posts: 457
Received Thanks: 67
you're got most of it.

This is the flow of events.

1. Server first generates a pair of DH parameters, P (a large prime number), G, (a generator base, usually is 3 or 5 or 7).

2. using this pair of DH parameters, server generates a DH key pair; this includes a public key of 128bytes long and a private key not longer than public key. Just in case you do not know, the so called Keys we are talking about are simply HUGE numbers. To represent them more efficiently, hexadecimal representation is usually chosen.

3. Up till this point, the server side DH information is complete. But TQ wants to be more efficient in sending packets. They decided to include some blowfish info as well. Blowfish cfb64 encryption requires a Initialization Vector (IV) of 8 bytes long. TQ decides to use a predefined IV for server->client encryption, and another for client->server encryption. These 2 IVs are included in the first packet as well. Note: these 2 IVs will be reserved for later use.

The structure of the first game packet is roughly
[random junk] [packetsize] [length of junk] [junk] [IV length] [IV] [IV length] [IV] [Lenth of P] [P] [Length of G] [G] [Length of Server Public Key] [Server Public Key]

P, G, Server Public Key are all ascii encoded, meaning to say, you can System.out.println(new String(packet)); should let you see P, G, and SPK.

For more information on the DH packet thingy, browse this forum, i think there are quite a couple threads on them. (Really, it is there, browsing is faster than waiting for answers)

4. The first packet from server, and the first packet sent by client are considered DH packets. They are encrypted using Blowfish cfb64 with an initialization vector of 8 bytes of zeros.

Eg. byte[] defaultIV = {0,0,0,0,0,0,0,0};

you need to create a blowfish cipher object in cfb64 mode, and initialize the encryption cipher and decryption cipher with defaultIV before you can de/crypt the DH packet. This one is rather lengthy and takes some time to digest.

It works out the best if you can take a couple minutes to write a short server/client test program to get used to implementing dh/blow in java. In that way you wont be messing around with your proxy codes too much.



Add: I have seen that DH exchange picture too.. i find it not as intuitive as some others. I am sure you will find way better DH exchange mechanism pictures on gooogle images.
shitboi is offline  
Thanks
2 Users
Old 03/27/2011, 19:58   #7
 
TomasLT's Avatar
 
elite*gold: 0
Join Date: Nov 2006
Posts: 286
Received Thanks: 38
At last perfect answer. This is exactly what i wanted to hear. It explains everything.
Tomorow i will have dificult test in university and need to prepare for it. So maybe tomowor i will try to write a short server/client test program to get used to implementing dh/blow in java like u said. And ur only 1 who want to helm me.

So here is what i`ve done alredy.
I try to extract theses keys from first packet from server:
random junk = 11 bytes long ?
Code:
...
Connected TO game SERVER
public key (2) : €
P (128) : A320A85EDD79171C341459E94807D71D39BB3B3F3B5161CA84894F3AC3FC7FEC317A2DDEC83B66D30C29261C6492643061AECFCF4A051816D7C359A6A7B7D8FB
G (2) : 05
...
And public key is printed as string so seconf caracter is liek a square.

And P is always the same!(dont checket all bytes)
TomasLT is offline  
Thanks
1 User
Old 03/28/2011, 15:55   #8
 
elite*gold: 0
Join Date: Jun 2006
Posts: 457
Received Thanks: 67
yes, your P and G are correct. You should search this forum for a thread I have started before. I have had the exact same issue as you do now, and with the help of other members, the problem was solve. The details to get past this problem is simply, but lengthy. It's easier for you to look at the old threads. GL
shitboi is offline  
Thanks
1 User
Old 03/30/2011, 01:54   #9
 
TomasLT's Avatar
 
elite*gold: 0
Join Date: Nov 2006
Posts: 286
Received Thanks: 38
Ok. Still few question.

DH packet from client is :
[random junk] [packetsize] [length of junk] [junk] [Length of Client Public Key] [Client Public Key] ? (random junk is 7 bytes ?)
and if i`m right:
Client public key (128) : 9F14236870FDB29C26D4633A2DBD855CC63824C66743A160BE ABFB0FC8B0DE9E893B79B75369EE286BB735800EF0DFC005A1 EBB9374B7B60C47CD1745116F37E


So as u said alredy i read lots of threads started not only by u about DH exchange/blowfish.
Do i need to change public keys before sending to another side ?

Maybe u can write a another explanation about other packet encryption ?
TomasLT is offline  
Thanks
1 User
Old 03/30/2011, 02:29   #10
 
elite*gold: 0
Join Date: Jun 2006
Posts: 457
Received Thanks: 67
yeah. you have to change public keys.

Here is the complete flow of the DH exchange procedure.

1. Server send to proxy ServerBlowfishIV, ClientBlowfishIV, P, G, ServerPubKey.
2. Decrypt packet in (1) using blowfish cfb64, IV = {0,0,0,0,0,0,0,0}, and you will obtain the information stated in (1).
3. Using P and G, you can generate a pair of DH private and public key for your proxy. Let's call these keys the ProxyPrivateKey and ProxyPublicKey.
4. Using ProxyPrivateKey and ServerPubKey, you can generate a ProxyServerSharedKey. This key shall be used to crypt packets between proxy and server.
5. Edit the packet in (1) by replacing ServerPublicKey with ProxyPublicKey, and you can forward to client.
6. Client recieves proxy's DH packet, and will return a client DH packet.
7. Decrypt this packet using same method as in (2), obtain ClientPubKey.
8. Using CLientPubKey and ProxyPrivateKey, you can generate a ProxyClientSharedKey. This key will be used to crypt all packets between proxy and client.
9. Edit the packet in (8) such that ClientPubKey is replaced by ProxyPublicKey, relay packet to server.
10. At this point in time, DH exchange is technically complete. But you have a few more things to do.

i. create a blowfish cipher A, initalize A with proxyserverSharedKey and ServerBlowfishIV. This cipher decrypts all packets from server.
ii. create a blowfish cipher B, initialize B with proxyServerSharedKey and ClientBlowfishIV. This cipher encrypts all packets going to server.
iii.create a blowfish cipher C, initialize C with ProxyClientSharedKey and ServerBlowfishIV. This cipher encrypts all packets going to client.
iv. create a blowfish cipher D, intialize D with ProxyClientSharedKey and ClientBlowfishIV, this cipher decrypts all packets from client.


Then all the packets will get decrypted smoothly. This one is really lengthy, and you will have the most problems implementing them. Also, try to cross reference to Tanel's source or Project Alchemy for packet handling methods.

If any one spot a mistake in my statements, please point it out, i dont want to mis-lead others.
shitboi is offline  
Thanks
2 Users
Old 03/30/2011, 13:00   #11


 
Korvacs's Avatar
 
elite*gold: 20
Join Date: Mar 2006
Posts: 6,125
Received Thanks: 2,518
Theres plenty of conquer related examples of the dh key exchange and blowfish decryption, simply by suing breakpoints and stepping through the code you can see exactly how things work and in what order things occur, proper working examples will teach you more than people just telling you how it works, any white paper can describe the methods that take place.
Korvacs is offline  
Old 03/30/2011, 16:32   #12
 
elite*gold: 0
Join Date: Jun 2006
Posts: 457
Received Thanks: 67
Quote:
Originally Posted by Korvacs View Post
Theres plenty of conquer related examples of the dh key exchange and blowfish decryption, simply by suing breakpoints and stepping through the code you can see exactly how things work and in what order things occur, proper working examples will teach you more than people just telling you how it works, any white paper can describe the methods that take place.
Will start on learning x86 asm soon, being able to see how things works is too important, and I totally agree with you.






@Tomas: proxy key pair generation may go bogus at times. Eg, instead of giving you a 128byte public key, it generates a 127byte key. That will **** you up. you can perform a simple action like this to get over the problem.
Code:
        do {
	        	kpair = keyGen.generateKeyPair();
	        } while(((DHPublicKey)kpair.getPublic()).getY().toString(16).length() != this.serverPublicKey.length());
shitboi is offline  
Thanks
1 User
Old 03/30/2011, 21:52   #13
 
TomasLT's Avatar
 
elite*gold: 0
Join Date: Nov 2006
Posts: 286
Received Thanks: 38
hmmm. but when i try to generate new Proxy public and privates keys, i got this output:
Code:
Proxy priv key 64 : 20c70d0a520e615b865b43493d22e9a463b6d105f5aa514c93d8c5894a68cf7b
Proxy pub key 128 : 2ded810c4e6b8bc9517499af8f578b13e7d0d151173c456939531de1b8621dc589696b00f951513a9280f92ff3a34c9443b46c70dcc295e5bb5495a81ee42409
And why priv key is only 64b only ?
And here is how do i generate it:
Code:
		BigInteger p = new BigInteger(p1, 0x10);
        BigInteger g = new BigInteger(g1, 0x10);
        
        KeyPairGenerator keyGen = KeyPairGenerator.getInstance("DiffieHellman");
        DHParameterSpec params = new DHParameterSpec(p, g, 128);
        keyGen.initialize(params);
        KeyPair kp = keyGen.generateKeyPair();
        
        ProxyPrivKey = ((DHPrivateKey) kp.getPrivate()).getX().toString(16);
        ProxyPubKey  = ((DHPublicKey) kp.getPublic()).getY().toString(16);
Sorry for double post!

In ur example u store ur public/privatekeys as string ? then how u generate sharedkey ? it need that proxyprivatekey and serverpublickey will be as key ! And cast it as Key dont helps
TomasLT is offline  
Old 03/31/2011, 01:58   #14
 
elite*gold: 0
Join Date: Jun 2006
Posts: 457
Received Thanks: 67
Quote:
Originally Posted by TomasLT View Post
hmmm. but when i try to generate new Proxy public and privates keys, i got this output:
Code:
Proxy priv key 64 : 20c70d0a520e615b865b43493d22e9a463b6d105f5aa514c93d8c5894a68cf7b
Proxy pub key 128 : 2ded810c4e6b8bc9517499af8f578b13e7d0d151173c456939531de1b8621dc589696b00f951513a9280f92ff3a34c9443b46c70dcc295e5bb5495a81ee42409
And why priv key is only 64b only ?
And here is how do i generate it:
Code:
		BigInteger p = new BigInteger(p1, 0x10);
        BigInteger g = new BigInteger(g1, 0x10);
        
        KeyPairGenerator keyGen = KeyPairGenerator.getInstance("DiffieHellman");
        DHParameterSpec params = new DHParameterSpec(p, g, 128);
        keyGen.initialize(params);
        KeyPair kp = keyGen.generateKeyPair();
        
        ProxyPrivKey = ((DHPrivateKey) kp.getPrivate()).getX().toString(16);
        ProxyPubKey  = ((DHPublicKey) kp.getPublic()).getY().toString(16);
getInstance("DH") is good.. doing DiffieHellman should be fine too.
you should be using another overload of DHParameterSpec constructor.
DHParameterSpec(P, G);

the private key should be 97 bytes usually.

Here are a couple of my snippets

obtaining DHParameterSpec, nvm about the br.readInt32() thingy.. it is only a binary reader i wrote myself. I didn't know about bytebuffer back then. should have used bytebuffer
Code:
        this.P_string = new String(br.readBytes((int) br.readInt32()), "UTF8");
        this.G_string = new String(br.readBytes((int) br.readInt32()), "UTF8");
        this.P = new BigInteger(this.P_string, 16);
        this.G = new BigInteger(this.G_string, 16);
        //------------------------------------------------------
        this.dhparam = new DHParameterSpec(this.P, this.G);	//ok
        this.serverPublicKey = new String(br.readBytes((int) br.readInt32()), "UTF8");
        this.spublicKey = new DHPublicKeySpec(new BigInteger(this.serverPublicKey,16), this.P, this.G); //ok

generate proxy key pair
Code:
    private void generateProxyKeyPair() throws NoSuchAlgorithmException, InvalidAlgorithmParameterException{
        keyGen = KeyPairGenerator.getInstance("DH");	//ok
        keyGen.initialize(dhparam, new SecureRandom());	//ok
        do {
	        	kpair = keyGen.generateKeyPair();
	        } while(((DHPublicKey)kpair.getPublic()).getY().toString(16).length() != this.serverPublicKey.length());
        this.privateKey = (DHPrivateKey) kpair.getPrivate();	//ok
        this.proxyPriKey = ((DHPrivateKey) kpair.getPrivate()).getX().toString(16).toUpperCase();
        this.proxyPubKey = ((DHPublicKey) kpair.getPublic()).getY().toString(16).toUpperCase();
    }
Add On:

didn't see your 2nd post.
Yes, after many tries i figured out the easiest way is to store keys both as strings and key objects. I needed them in both forms ... so ... that is just my implementation. You can come up with yours.
Strings can be converted to BigInteger. BigInteger can be converted to to DHPublicKeySpec and etc... DHPublicKeySpec and its private counterpart are used to generate shared key in keyfactory.
i stored my sharedkey in byte[]
shitboi is offline  
Thanks
1 User
Old 03/31/2011, 23:31   #15
 
TomasLT's Avatar
 
elite*gold: 0
Join Date: Nov 2006
Posts: 286
Received Thanks: 38
At last now i can generate secret key.
Here is how i generate it:
Code:
public class DHexchange{
	public String ProxyPubKey;
	public String ProxyPrivKey;
	public DHPrivateKey privateKey;
	public BigInteger p;
	public BigInteger g;
	public BigInteger SpubKey;
	public KeyPair kp;
	public SecretKey sharedKey;
	public byte[] sharedarray;
	public BigInteger shared;
	
	public void GeneratePair(String p1,String g1,String SpKey) throws NoSuchAlgorithmException, InvalidKeyException, InvalidAlgorithmParameterException, InvalidKeySpecException {
		this.p = new BigInteger(p1, 0x10);
        this.g = new BigInteger(g1, 0x10);
        
        KeyPairGenerator keyGen = KeyPairGenerator.getInstance("DiffieHellman");
        DHParameterSpec params = new DHParameterSpec(this.p, this.g);
        DHPublicKeySpec spublicKey = new DHPublicKeySpec(new BigInteger(SpKey,16), this.p, this.g);
        //DHPrivateKeySpec sprivKey = new DHPrivateKeySpec(new BigInteger(SpKey,16), this.p, this.g);
    
        keyGen = KeyPairGenerator.getInstance("DiffieHellman");	//ok
        keyGen.initialize(params, new SecureRandom());	//ok
        do {
	        	kp = keyGen.generateKeyPair();
	        } while(((DHPublicKey)kp.getPublic()).getY().toString(16).length() != SpKey.length());
        this.privateKey = (DHPrivateKey) kp.getPrivate();	//ok
        this.ProxyPrivKey = ((DHPrivateKey) kp.getPrivate()).getX().toString(16).toUpperCase();
        this.ProxyPubKey = ((DHPublicKey) kp.getPublic()).getY().toString(16).toUpperCase();
 
        KeyAgreement ka=KeyAgreement.getInstance("DiffieHellman");
        KeyFactory kf = KeyFactory.getInstance("DH");
        PublicKey PubKey=kf.generatePublic(spublicKey);
        ka.init(privateKey);
        ka.doPhase(PubKey, true);
        byte[] SharedSecret=ka.generateSecret();
        shared = new BigInteger(SharedSecret);
        sharedarray = shared.toByteArray();  
	}
}
And the secret key is :
Code:
Shared key 64 ŒŠK©Â‰€Ò•Úƒ?µ¡ŠMUÊÖÄŠêdÕ7'ü±Ã‡µ,t ~*Ýg™½ª\ùWÏv§›$*FàîÁSÐÝFe
Shared key 64 8C8A4BA9C2108980D295DA839DB5A18A4D55CAD6C48AEA64D5073727FCB1C387B52C74207EADDD670499BDAA5CF957CF0B76A79B242A46E0EEC11353D0DD4665
Shared key is 64b ? or i generate it wrong ?
TomasLT is offline  
Reply

Tags
blowfish, dh, game encryption


Similar Threads Similar Threads
BOI Packet Encryption
09/28/2011 - Battle of the Immortals - 13 Replies
I've made some research about the packet encryption used in this game and I thought I'd share them. BOI uses a simple XOR-Algorithm. Each byte of a packet is being XORed with the value of the previous byte. The first byte of every packet indicates its length. Furthermore the first byte of the very first packet sent after the connection was established is being XORed with the value 0xCD. Example: Let's say the client sends this packet right after connecting to the server. 0x06 0xA7 0x57...
[Help]PHP Encryption Software
10/18/2010 - CO2 Private Server - 0 Replies
I have made an Auto Rewards system for conquer online private servers but i dont want to release the source, just the software. Does anyone know of a PHP Encryption software that doesnt require the server to download additional software to use the encrypted files?
encryption
08/17/2010 - CO2 Private Server - 0 Replies
anybody can explain this? I got it from another site about encryptions and cryptographers. but didn't understand much of it, so if anybody can explain better. //******************** //KEYS //******************** //Binary //******************** 01000101 01111000 01111000 00100000 01111011 00100000 00101111 00101111 01000101 01111000 01111000 00100000 01001000 01100101 01111000 00100000 01100011 01110010 01111001 01110000 01110100 01101111 00001101 00001010 01111000 00101000 01001000...
Encryption
12/04/2008 - CO2 Private Server - 23 Replies
What is so good about having a client that is 5017+? And this encryption......what is it?
RF CM encryption??
05/20/2008 - RF Online - 5 Replies
I was playing a little with WPE and now it seems all packets are ciphered, cause for example, when you throw away an item you could recognise a pattern, but now all i can see are random bytes in the throw away packets. Could it be cause of the last patch that CM has applied? Has anyone experienced this? Sorry pls move this thread to the other forum



All times are GMT +2. The time now is 04:23.


Powered by vBulletin®
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2024 elitepvpers All Rights Reserved.