From b9101b46da610d887e2baa434de2a015c45827d4 Mon Sep 17 00:00:00 2001 From: "m.navaei" Date: Wed, 7 Feb 2018 18:50:36 +0330 Subject: [PATCH] . --- Apps/TlgListenerApplication/Program.cs | 24 ++++++++++++++++--- TLSharp.Core/Auth/Step2_DHExchange.cs | 6 ++--- TLSharp.Core/Auth/Step3_CompleteDHExchange.cs | 3 ++- 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/Apps/TlgListenerApplication/Program.cs b/Apps/TlgListenerApplication/Program.cs index 851fb7a..b936eeb 100644 --- a/Apps/TlgListenerApplication/Program.cs +++ b/Apps/TlgListenerApplication/Program.cs @@ -83,6 +83,7 @@ namespace TlgListenerApplication uint responseCode = 0; const uint step1Constructor = 0x60469778; const uint step2Constructor = 0xd712e4be; + const uint step3Constructor = 0xf5045f1f; if (netStream.CanRead) { @@ -122,7 +123,7 @@ namespace TlgListenerApplication if (netStream.CanWrite) { - + var fingerprint = StringToByteArray("216be86c022bb4c3"); byte[] outputdata = null; @@ -140,13 +141,13 @@ namespace TlgListenerApplication } else if (responseCode == step2Constructor) { - var newnonce = new byte[32]; + var newnonce = new byte[16]; new Random().NextBytes(newnonce); byte[] answer; var hashsum = Encoding.UTF8.GetBytes("asdfghjklmnbvcxzasdf"); const uint innerCode = 0xb5890dba; - AESKeyData key = AES.GenerateKeyDataFromNonces(nonceFromClient, newnonce); + AESKeyData key = AES.GenerateKeyDataFromNonces(newnonce, newnonce); using (var memoryStream = new MemoryStream()) { using (var binaryWriter = new BinaryWriter(memoryStream)) @@ -170,6 +171,23 @@ namespace TlgListenerApplication EncryptedAnswer = AES.EncryptAES(key, answer) }.ToBytes(); } + else if (responseCode == step3Constructor) + { + var newnonce = new byte[16]; + new Random().NextBytes(newnonce); + const uint innerCode = 0x3bcbf734; + using (var memoryStream = new MemoryStream()) + { + using (var binaryWriter = new BinaryWriter(memoryStream)) + { + binaryWriter.Write(innerCode); + binaryWriter.Write(newnonce); + binaryWriter.Write(nonceFromClient); + binaryWriter.Write(newnonce); + outputdata = memoryStream.ToArray(); + } + } + } var bytes = PrepareToSend(outputdata); var datatosend = Encode(bytes, 11); diff --git a/TLSharp.Core/Auth/Step2_DHExchange.cs b/TLSharp.Core/Auth/Step2_DHExchange.cs index 55bff0d..aa81749 100644 --- a/TLSharp.Core/Auth/Step2_DHExchange.cs +++ b/TLSharp.Core/Auth/Step2_DHExchange.cs @@ -15,7 +15,6 @@ namespace TLSharp.Core.Auth public byte[] ToBytes() { - new Random().NextBytes(Nonce); const uint constructorNumber = 0xd0e8075c; using (var memoryStream = new MemoryStream()) @@ -25,7 +24,8 @@ namespace TLSharp.Core.Auth binaryWriter.Write(constructorNumber); binaryWriter.Write(ServerNonce); binaryWriter.Write(Nonce); - binaryWriter.Write(EncryptedAnswer); + //binaryWriter.Write(EncryptedAnswer); + Serializers.Bytes.write(binaryWriter, EncryptedAnswer); return memoryStream.ToArray(); } @@ -152,7 +152,7 @@ namespace TLSharp.Core.Auth EncryptedAnswer = encryptedAnswer, ServerNonce = serverNonceFromServer, Nonce = nonceFromServer, - NewNonce = newNonce + NewNonce = serverNonceFromServer }; } } diff --git a/TLSharp.Core/Auth/Step3_CompleteDHExchange.cs b/TLSharp.Core/Auth/Step3_CompleteDHExchange.cs index 8ba8f5a..ca0d667 100644 --- a/TLSharp.Core/Auth/Step3_CompleteDHExchange.cs +++ b/TLSharp.Core/Auth/Step3_CompleteDHExchange.cs @@ -2,6 +2,7 @@ using System.IO; using System.Linq; using System.Security.Cryptography; +using System.Text; using TLSharp.Core.MTProto; using TLSharp.Core.MTProto.Crypto; @@ -11,7 +12,6 @@ namespace TLSharp.Core.Auth { public AuthKey AuthKey { get; set; } public int TimeOffset { get; set; } - } public class Step3_CompleteDHExchange @@ -37,6 +37,7 @@ namespace TLSharp.Core.Auth using (BinaryReader dhInnerDataReader = new BinaryReader(dhInnerData)) { byte[] hashsum = dhInnerDataReader.ReadBytes(20); + var hashsumstr = Encoding.UTF8.GetString(hashsum); uint code = dhInnerDataReader.ReadUInt32(); if (code != 0xb5890dba) {