Register for your free account! | Forgot your password?

Go Back   elitepvpers > MMORPGs > Conquer Online 2 > CO2 Private Server
You last visited: Today at 08:34

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

Advertisement



Blowfish & Diffie-Hellman

Discussion on Blowfish & Diffie-Hellman within the CO2 Private Server forum part of the Conquer Online 2 category.

Reply
 
Old   #1
 
elite*gold: 0
Join Date: Jan 2008
Posts: 1,400
Received Thanks: 1,072
Blowfish & Diffie-Hellman

I don't know why, I make the same thing that I make on my PacketLogger, but with a new system (Blowfish/DH) and it's not working. When I check, the IVs are good, the P/G/A/B keys are the good, but I can't decrypt the first client packet... I know how work the blowfish system and the DH exchange. Any idea?

PHP Code:
        private void ServerReceiveHandler(Client ClientByte[] Data)
        {
            
Client.CBlowfish.Decrypt(Data);
            try
            {
                if (!
Client.ExchangeCompleted)
                {
                    
DiffieHellman.ServerPacket(Dataref Client.Exchange);
                    
Client.CBlowfish.DiffieHellman = new DH(BigNumber.FromHexString(Client.Exchange.P), BigNumber.FromHexString(Client.Exchange.G));
                    
Client.SBlowfish.DiffieHellman = new DH(BigNumber.FromHexString(Client.Exchange.P), BigNumber.FromHexString(Client.Exchange.G));

                    
Client.CBlowfish.DiffieHellman.GenerateKeys();
                    
Client.SBlowfish.DiffieHellman.GenerateKeys();

                    
DiffieHellman.EditKeyA(ref DataClient.SBlowfish.DiffieHellman.PublicKey.ToHexString());
                    
DiffieHellman.ServerPacket(Dataref Client.Exchange);
                    
Client.SendToClient(Data);
                }
            }
            catch (
Exception Exc) { Program.WriteLine(Exc); }
        }

        private 
void ClientReceiveHandler(Client ClientByte[] Data)
        {
            
Client.SBlowfish.Decrypt(Data);
            try
            {
                if (!
Client.ExchangeCompleted)
                {
                    
DiffieHellman.EditKeyB(ref DataClient.CBlowfish.DiffieHellman.PublicKey.ToHexString());
                    
DiffieHellman.ClientPacket(Dataref Client.Exchange);
                    
Client.SendToServer(Data);

                    
Client.CBlowfish.SetKey(Client.CBlowfish.DiffieHellman.ComputeKey(BigNumber.FromHexString(Client.Exchange.A)));
                    
Client.SBlowfish.SetKey(Client.SBlowfish.DiffieHellman.ComputeKey(BigNumber.FromHexString(Client.Exchange.B)));

                    
Client.CBlowfish.EncryptIVs Client.Exchange.ClientIVs;
                    
Client.CBlowfish.DecryptIVs Client.Exchange.ServerIVs;

                    
Client.SBlowfish.EncryptIVs Client.Exchange.ServerIVs;
                    
Client.SBlowfish.DecryptIVs Client.Exchange.ClientIVs;

                    
Client.ExchangeCompleted true;
                }
            }
            catch (
Exception Exc) { Program.WriteLine(Exc); }
        } 



CptSky is offline  
Old 08/07/2010, 10:31   #2
 
elite*gold: 20
Join Date: Mar 2006
Posts: 6,124
Received Thanks: 2,507
You set the initial key?


Korvacs is offline  
Old 08/07/2010, 12:37   #3
 
elite*gold: 0
Join Date: Nov 2009
Posts: 745
Received Thanks: 539
Code:
        public void Deserialize(ConquerPacket _Packet)
        {
            this.Packet = _Packet;
            if (this.KeyExchange == null)
                this.KeyExchange = new KeyExchange();
            if (this.Cryptography == null)
                this.Cryptography = new ProxyCrypto();
            if (this.Cryptography.ServerCryptographer == null)
                this.Cryptography.ServerCryptographer = new GameCryptographer(Encoding.ASCII.GetBytes(Constants.CryptKey));
            if (this.Cryptography.ClientCryptographer == null)
                this.Cryptography.ClientCryptographer = new GameCryptographer(Encoding.ASCII.GetBytes(Constants.CryptKey));
        }

        public void ProcessServer(ConquerClient Client)
        {
            if (!ServerKey_Exchanged)
            {
                this.Cryptography.DecryptServerData(Packet);
                this.KeyExchange.Deserialize(KeyExchange.Server, Packet);
                SendToClient(Packet, Client);
                this.ServerKey_Exchanged = true;
            }
            else
            {
                iProxy.ProcessServer(Packet, Client);
            }
        }

        public void ProcessClient(ConquerClient Client)
        {
            if (!ClientKey_Exchanged)
            {
                this.Cryptography.DecryptClientData(Packet);
                this.KeyExchange.Deserialize(KeyExchange.Client, Packet);
                SendToServer(Packet, Client);
                this.KeyExchange.Override(this.Cryptography);
                ClientKey_Exchanged = true;
            }
            else
            {
                iProxy.ProcessClient(Packet, Client);
            }
        }

        public void SendToServer(IPacket Packet, ConquerClient Client)
        {
            lock (this.Cryptography.ClientCryptographer)
            {
                byte[] buffer = new byte[Packet.ToArray().Length];
                Native.MemCopy(buffer, Packet.ToArray(), Packet.ToArray().Length);
                ConquerWriter.WriteString(Constants.ServerKey, Packet.ToArray().Length - 8, buffer);
                this.Cryptography.ClientCryptographer.Encode(buffer);
                if (Client.ServerConnection.Connected)
                    Client.ServerConnection.Send(buffer);
            }
        }

        public void SendToClient(IPacket Packet, ConquerClient Client)
        {
            lock (this.Cryptography.ServerCryptographer)
            {
                byte[] buffer = new byte[Packet.ToArray().Length];
                Native.MemCopy(buffer, Packet.ToArray(), Packet.ToArray().Length);
                ConquerWriter.WriteString(Constants.ClientKey, Packet.ToArray().Length - 8, buffer);
                this.Cryptography.ServerCryptographer.Encode(buffer);
                if (Client.ClientConnection.Connected)
                    Client.ClientConnection.Send(buffer);
            }
        }
And when I call override:
Code:
                BigNumber RealClientPublicKey = BigNumber.FromHexString(ClientPacket.GetPublicKey());
                BigNumber RealServerPublicKey = BigNumber.FromHexString(ServerPacket.PublicKey);

                Crypto.ClientCryptographer = new GameCryptographer(ClientSide.ComputeKey(RealServerPublicKey));
                Crypto.ServerCryptographer = new GameCryptographer(ServerSide.ComputeKey(RealClientPublicKey));

                ((GameCryptographer)Crypto.ClientCryptographer).Blowfish.EncryptIV = ServerPacket.ClientIV;
                ((GameCryptographer)Crypto.ClientCryptographer).Blowfish.DecryptIV = ServerPacket.ServerIV;
                ((GameCryptographer)Crypto.ServerCryptographer).Blowfish.EncryptIV = ServerPacket.ServerIV;
                ((GameCryptographer)Crypto.ServerCryptographer).Blowfish.DecryptIV = ServerPacket.ClientIV;
This might help you.
ImmuneOne is offline  
Reply


Similar Threads
[GUIDE] Diffie Hellman Key Exchange
06/26/2012 - CO2 Programming - 10 Replies
First, the Diffie Hellman (DH) Key Exchange is a cryptographic method of sharing a secret key over a public or insecure network, this key can be used to encrypt and decrypt data using symmetric key ciphers such as Blowfish as used by CO In this guide I'll cover the basic concept on how DH works and how to generate keys. I'll be be using two hosts/computers for my explanation, I'll refer to them as PC1 and PC2. Now, both PC1 and PC2 need to agree on a Prime number (P) greater than 2 and an...
[help]blowfish
10/15/2009 - Lineage 2 - 0 Replies
hello i haven't idea how to find blowfish in server any idea?



All times are GMT +1. The time now is 08:34.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.

BTC: 33E6kMtxYa7dApCFzrS3Jb7U3NrVvo8nsK
ETH: 0xc6ec801B7563A4376751F33b0573308aDa611E05

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