RSA & HelloConnectMessage

Inscrit
2 Janvier 2016
Messages
13
Reactions
1
#1
Bonjour,

Je travaille actuellement sur le développement d'un Bot D2 en Socket développé en NodeJS.
Je bloque actuellement sur le Message HelloConnectMessage plus spécifiquement sur la partie RSA et décodage de la clé reçu dans ce message.

Actuellement je suis capable de me connecté si je passe manuellement dans mon code, l'hexadécimal du IdentificationMessage. Donc, mes serialize et desezialize sont fonctionnel.
Je souhaitais donc implémenter la partie encryption des credentials.

J'ai donc récupéré la clé contenue dans les sources de Dofus :
Code:
-----BEGIN PUBLIC KEY-----
MIIBUzANBgkqhkiG9w0BAQEFAAOCAUAAMIIBOwKCATIAgucoka9J2PXcNdjcu6CuDmgteIMB+rih
2UZJIuSoNT/0J/lEKL/W4UYbDA4U/6TDS0dkMhOpDsSCIDpO1gPG6+6JfhADRfIJItyHZflyXNUj
WOBG4zuxc/L6wldgX24jKo+iCvlDTNUedE553lrfSU23Hwwzt3+doEfgkgAf0l4ZBez5Z/ldp9it
2NH6/2/7spHm0Hsvt/YPrJ+EK8ly5fdLk9cvB4QIQel9SQ3JE8UQrxOAx2wrivc6P0gXp5Q6bHQo
ad1aUp81Ox77l5e8KBJXHzYhdeXaM91wnHTZNhuWmFS3snUHRCBpjDBCkZZ+CxPnKMtm2qJIi57R
slALQVTykEZoAETKWpLBlSm92X/eXY2DdGf+a7vju9EigYbX0aXxQy2Ln2ZBWmUJyZE8B58CAwEA
AQ==
-----END PUBLIC KEY-----
Et également le clé reçu dans le HelloConnectMessage ( En base64) :
Code:
DHyg1lSz/PukXBNDZMjF3CgfBLSH6g3jSksiPHCH42JYsZHEd1AJbyhzisAJZT69cpR95m80tQS7
Xdaf6c27rexrcRtH7yuM2cwHwdt/dL4tuyxLtWOKK8Y8+i389c8dln9Y2sbLD99DEEi8UgYW1GIh
3ywsgfNByM6+pEvpz9HRgtop4NblibrhdE/tXWk29hai875KQQaBbhBHmJ/iOpsVc6aHLN/JFdp3
3UC5bDpfyDvk94MtOEMP0pQDcRbA/PA44ZxN5V6wr72BM5xVWKE0H9L7zmt13iTzbXj/cMyppniM
I8tJ1VnQmz2/Gjrr092NVpzPXWNic6tBOmvueuzntMwbvFwBla8QWFLA7vOkqWAaUYlwKRh8S41M
0lgArFtFZtueCS/NAAySiyazjYA=
Cependant je ne comprend pas ce que je dois en faire, d'après ce que j'ai lu sur le forum je devrais décodé la clé reçu par le serveur à l'aide de ma clé récupéré dans le client Dofus.

Merci d'avance pour votre aide ! :)
 
Inscrit
4 Octobre 2019
Messages
9
Reactions
0
#2
1. Understand how the protocol works https://cadernis.fr/index.php?threads/comprendre-le-protocole-de-dofus.115/, specifically how the data is serialized and deserialized server<->client in Dofus 2.

2. Parse the PKIX public key (RSA)
Code:
----- BEGIN PUBLIC KEY -----
DHyg1lSz/PukXBNDZMjF3CgfBLSH6g3jSksiPHCH42JYsZHEd1AJbyhzisAJZT69cpR95m80tQS7
Xdaf6c27rexrcRtH7yuM2cwHwdt/dL4tuyxLtWOKK8Y8+i389c8dln9Y2sbLD99DEEi8UgYW1GIh
3ywsgfNByM6+pEvpz9HRgtop4NblibrhdE/tXWk29hai875KQQaBbhBHmJ/iOpsVc6aHLN/JFdp3
3UC5bDpfyDvk94MtOEMP0pQDcRbA/PA44ZxN5V6wr72BM5xVWKE0H9L7zmt13iTzbXj/cMyppniM
I8tJ1VnQmz2/Gjrr092NVpzPXWNic6tBOmvueuzntMwbvFwBla8QWFLA7vOkqWAaUYlwKRh8S41M
0lgArFtFZtueCS/NAAySiyazjYA=
----- END PUBLIC KEY -----
3. Use that parsed public key to encrypt the content of IdentificationMessage.Credentials

This will result impossible if you don't know how the protocol works, so read that first, and also reverse engineer the client :p
 
Inscrit
2 Janvier 2016
Messages
13
Reactions
1
#3
Thanks a lot for your response I already know how D2 protocol Work and I successfuly implemented It in nodeJs
What I dont understand is how to parse this public key
For now i achieved parsing the key I reiceved from the HelloConnectMessage but I Don’t understand what I have to do with it

Thanks Again for your help :) !
 
Inscrit
4 Octobre 2019
Messages
9
Reactions
0
#4
Thanks a lot for your response I already know how D2 protocol Work and I successfuly implemented It in nodeJs
What I dont understand is how to parse this public key
For now i achieved parsing the key I reiceved from the HelloConnectMessage but I Don’t understand what I have to do with it

Thanks Again for your help :) !
Now you have to use that RSA public key to encrypt something like salt+username+passwordLength+password. Where salt = the 32 characters-long salt you received from HelloConnectMessage. I say “something like”, because the format probably varies by protocol version (basically by Dofus version) — I'm working with Dofus 2.14 right now (protocol 1547). For example, in some other versions it may be something like salt+username+hashLength+md5(password), instead

Check public function getIdentificationMessage() : IdentificationMessage inside com\ankamagames\dofus\logic\connection\managers\AuthentificationManager.as, in your DofusInvoker.swf ;)
 
Inscrit
2 Janvier 2016
Messages
13
Reactions
1
#5
Okay I'll try your method !
I didn't know it was sufficient to just convert in base64 the key we received from the HelloConnectMessage. I though it was necessary to "decrypt" this base64 key using the known key from Dofus Client !

I'll try your method :)

Thanks you !! Hope It will work
 
Inscrit
2 Janvier 2016
Messages
13
Reactions
1
#6
Hello Again !

I did what you told me but it's not working :/
For now I got my function to set my publicKey wich will be use to encode the credentials,
Code:
setPublicKey (publicKey) {
    publicKey = crypto.publicDecrypt(this._verifyKey, Buffer.from(publicKey));

    this.publicKey = `-----BEGIN PUBLIC KEY-----\n${publicKey.toString('base64')}\n-----END PUBLIC KEY-----`;
}
Then I use this.publicKey to encode my credentials,

Code:
    cipherRsa (username, password, certificate = null) {
        const input = new ByteArray();

        input.writeUTFBytes(this.salt);
        input.writeBytes(this.AESKey);
        // TODO
        /*if (certificate) {
            input.writeUnsignedInt(certificate.id);
            input.writeUTFBytes(certificate.hash);
        }*/
        input.writeByte(username.length);
        input.writeUTFBytes(username);
        input.writeUTFBytes(password);

        return crypto.publicEncrypt(this.publicKey, input.buffer);
    }
It's working well, the problem Is, the credentials array It gives me contains number that are upper than 127. So when I arrive at my function to serialize the IdentificationMessage It throw me an Error when It tried to writeByte on credentials ...

I don't understand what I did wrong so If you or anyone could help me that would be great :)

Thanks you have a nice day !

[UPDATE]
I final got a response from the Server saying me,

Code:
{
    "__type__": "IdentificationFailedMessage",
    "reason": 2
}
So now i'm sure my serialize is working well !
 
Dernière édition:

asyade

Membre Actif
Inscrit
26 Avril 2013
Messages
368
Reactions
1
#7
Il faut que ton `salt` fasse exactement 32 caractères, si ton salt est plus petit il faut le combler avec des espaces, ensuite vérifie ta clef AES et lit le doc de ta lib cryptographique (compare avec celle du c# par exemple) tu as peut-être des paramètres par défaut qui ne sont pas les meme qu'avec la lib `hurlant`

Ps: Tu peux comparer avec ce code qui fonctionnait jusqu'en fin 2018, j'ai pas tester depuis (c'est du c# mais bon)
 
Inscrit
2 Janvier 2016
Messages
13
Reactions
1
#8
Ah je te remercie je n ai pas vérifier pour le salt effectivement ça peut venir de la !
d accords je vérifierais dès que je peux merci !
J essaie tout ça et je ferais un retour merci encore :)
 
Haut Bas