diff --git a/Apps/ClientConsoleApp/Program.cs b/Apps/ClientConsoleApp/Program.cs index 56a521d..7483040 100644 --- a/Apps/ClientConsoleApp/Program.cs +++ b/Apps/ClientConsoleApp/Program.cs @@ -48,7 +48,7 @@ namespace ClientConsoleApp int ApiId = int.Parse(ConfigurationManager.AppSettings["ApiId"]); //string AuthCode = ConfigurationManager.AppSettings["AuthCode"]; string MainPhoneNumber = ConfigurationManager.AppSettings["NumberToAuthenticate"]; - var client = new TelegramClient(ApiId, ApiHash, null, "session", null, "127.0.0.1", 5000); + var client = new TelegramClient(ApiId, ApiHash);//, null, "session", null, "127.0.0.1", 5000 var phoneCodeHash = string.Empty; authenticated: Console.WriteLine("Start app"); diff --git a/Apps/TlgListenerApplication/Program.cs b/Apps/TlgListenerApplication/Program.cs index 4c964ce..4673951 100644 --- a/Apps/TlgListenerApplication/Program.cs +++ b/Apps/TlgListenerApplication/Program.cs @@ -91,22 +91,38 @@ namespace TlgListenerApplication netStream.Read(bytes, 0, (int)tcpClient.ReceiveBufferSize); var tcpMessage = TcpMessage.Decode(bytes); var binaryReader = new BinaryReader(new MemoryStream(tcpMessage.Body, false)); - var a = binaryReader.ReadInt64(); - var msgId = binaryReader.ReadInt64(); - var datalength = binaryReader.ReadInt32(); - var data = binaryReader.ReadBytes(datalength); - var binaryReader2 = new BinaryReader(new MemoryStream(data, false)); - - responseCode = binaryReader2.ReadUInt32(); - Console.WriteLine("Request code: " + responseCode); - if (responseCode == step1Constructor)//---Step1_PQRequest + var authKeyId = binaryReader.ReadInt64(); + if (authKeyId == 0) { - nonceFromClient = binaryReader2.ReadBytes(16); + var msgId = binaryReader.ReadInt64(); + var datalength = binaryReader.ReadInt32(); + var data = binaryReader.ReadBytes(datalength); + + var binaryReader2 = new BinaryReader(new MemoryStream(data, false)); + + responseCode = binaryReader2.ReadUInt32(); + Console.WriteLine("Request code: " + responseCode); + if (responseCode == step1Constructor) //---Step1_PQRequest + { + nonceFromClient = binaryReader2.ReadBytes(16); + } + else if (responseCode == step2Constructor) //---Step1_PQRequest + { + nonceFromClient = binaryReader2.ReadBytes(16); + } } - else if (responseCode == step2Constructor)//---Step1_PQRequest + else { - nonceFromClient = binaryReader2.ReadBytes(16); + var decodeMessage = DecodeMessage(tcpMessage.Body); + var buffer = new byte[binaryReader.BaseStream.Length - 24]; + int count; + using (var ms = new MemoryStream()) + while ((count = binaryReader.Read(buffer, 0, buffer.Length)) != 0) + ms.Write(buffer, 0, count); + + //var keyData = Helpers.CalcKey(buffer, messageKey, false); + //var data = AES.DecryptAES(keyData, buffer); } //var obj = new Step1_PQRequest().FromBytes(data); @@ -333,7 +349,7 @@ namespace TlgListenerApplication return newMessageId; } - private Tuple DecodeMessage(byte[] body) + private static Tuple DecodeMessage(byte[] body) { byte[] message; ulong remoteMessageId; diff --git a/TLSharp.Core/Auth/Step3_CompleteDHExchange.cs b/TLSharp.Core/Auth/Step3_CompleteDHExchange.cs index ca0d667..b1c69c1 100644 --- a/TLSharp.Core/Auth/Step3_CompleteDHExchange.cs +++ b/TLSharp.Core/Auth/Step3_CompleteDHExchange.cs @@ -37,7 +37,6 @@ 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) {