Git Product home page Git Product logo

Comments (7)

mtanksl avatar mtanksl commented on June 8, 2024

Hello Mr. Mujica,

I suspect that before reading the four symmetric keys, you need to skip a single byte. Something like:

...

var clientOS = message.GetUShort();
var version = message.GetUShort();

message.SkipBytes(12);
    
Rsa.DecryptAndReplace(message.Buffer, message.Position);

message.SkipBytes(1); // Skip one more byte

connection.SymmetricKey[0] = message.GetUInt();
connection.SymmetricKey[1] = message.GetUInt();
connection.SymmetricKey[2] = message.GetUInt();
connection.SymmetricKey[3] = message.GetUInt();

...

Best regards,

from opentibia.

Ezzz-dev avatar Ezzz-dev commented on June 8, 2024

Even while doing it like this, the returned decrypted data is always random bytes, it is never the correct decrypted data.
Even the first byte to skip is never 0, it is always a random value.

from opentibia.

mtanksl avatar mtanksl commented on June 8, 2024

Can you share the message.Buffer bytes? In Tibia 8.6 it is around 149 bytes length.

Use this to convert the byte array to a string:

public static string Print(this byte[] bytes)
{
    StringBuilder builder = new StringBuilder();
    foreach (var b in bytes)
    {
        builder.Append(b.ToString("X2") + " ");
    }
    return builder.ToString();
}

from opentibia.

Ezzz-dev avatar Ezzz-dev commented on June 8, 2024
145 91 00 01 02 00 04 03 33 5A 9D 43 BE 52 98 43 E7 DD C5 56 42 1A FC EF C4 EF 62 9A 68 CF DB 02 B1 59 9B C1 25 41 47 87 16 12 ED 7D 32 52 92 0A A9 F0 46 27 AB 8C EB 5C F2 9B 58 A1 D9 B0 CE D7 B6 4F 1D 26 31 D4 8D A8 71 15 94 70 6D 3E A2 BC 1E 90 45 2A 20 88 3B ED FF C5 B5 AC B5 F8 7A 9A A5 F1 C2 8B AB 37 95 EB 11 55 85 23 28 19 FF 6A E6 FC 15 03 68 45 40 28 EA 14 2C 58 93 08 F2 2D B7 5E 0D 48 71 0B 29 42 42 62 C5 60 18 D1 56 93 57 21 C2 B4 00 

my buffer is 16k of length but I am only using what is received from the end-stream (what is printed here). Can you maybe give me guidance in Discord so it is easier?

from opentibia.

mtanksl avatar mtanksl commented on June 8, 2024

That is odd... 145 is not a valid byte hex number. Anyway, I ignored it during some parse tests. I tried to find out what had gone wrong. I could not. In the mean time, I've added two RSA examples in the source code (mtanksl.OpenTibia.Tests.RsaTests), one for the official Tibia 8.6 client (LoginPacketTibia860) and other for the official Tibia 7.72 client (LoginPacketTibia772).

You are using a custom Tibia client, are the sources available? I'm not sure what could've gone wrong, maybe the public key is different, maybe the algorithm is slightly different, maybe some weird endianness.

Oh, maybe try taking only the first 128 bytes for RSA:

Rsa.DecryptAndReplace(message.Buffer, message.Position, 128);

from opentibia.

Ezzz-dev avatar Ezzz-dev commented on June 8, 2024

Your reply helped me indeed.
I am very dumb at times.
The issue was this line:

Rsa.DecryptAndReplace(message.Buffer, message.Position);

It had to be like this:

Rsa.DecryptAndReplace(message.Buffer, message.Position, message.Length - message.Position);

from opentibia.

mtanksl avatar mtanksl commented on June 8, 2024

Excellent, If it worked, success. If there are any other questions I can help you with, feel free to ask.

Best regards,

from opentibia.

Related Issues (2)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.