mirror of
https://github.com/sochix/TLSharp.git
synced 2025-12-06 08:02:00 +01:00
.
This commit is contained in:
parent
558d58a950
commit
0b6c67b5aa
|
|
@ -101,11 +101,26 @@ namespace TLSharp.Core.Network
|
|||
ulong remoteMessageId;
|
||||
int remoteSequence;
|
||||
|
||||
/*
|
||||
if (body.Length<8)
|
||||
{
|
||||
List<byte> lb = new List<byte>();
|
||||
foreach (var vb in body)
|
||||
lb.Add(vb);
|
||||
for (int i = lb.Count; i < (8+16); i++)
|
||||
lb.Add(0);
|
||||
|
||||
body = lb.ToArray();
|
||||
}
|
||||
*/
|
||||
|
||||
using (var inputStream = new MemoryStream(body))
|
||||
using (var inputReader = new BinaryReader(inputStream))
|
||||
{
|
||||
if (inputReader.BaseStream.Length < 8)
|
||||
{
|
||||
throw new InvalidOperationException($"Can't decode packet");
|
||||
}
|
||||
|
||||
ulong remoteAuthKeyId = inputReader.ReadUInt64(); // TODO: check auth key id
|
||||
byte[] msgKey = inputReader.ReadBytes(16); // TODO: check msg_key correctness
|
||||
|
|
@ -342,7 +357,7 @@ namespace TLSharp.Core.Network
|
|||
}
|
||||
catch (ZlibException ex)
|
||||
{
|
||||
|
||||
Console.WriteLine(ex.Message);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
|
@ -512,6 +527,7 @@ namespace TLSharp.Core.Network
|
|||
{
|
||||
// logger.error("failed to process message in contailer: {0}", e);
|
||||
messageReader.BaseStream.Position = beginPosition + innerLength;
|
||||
Console.WriteLine(e.Message);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -83,14 +83,23 @@ namespace TLSharp.Core
|
|||
if (dcOptions == null || !dcOptions.Any())
|
||||
throw new InvalidOperationException($"Can't reconnect. Establish initial connection first.");
|
||||
|
||||
TLDcOption dc = null;
|
||||
foreach (var d2 in dcOptions)
|
||||
{
|
||||
if (d2.Id == dcId && d2.Ipv6 == false)
|
||||
{
|
||||
dc = d2;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
TLExportedAuthorization exported = null;
|
||||
if (_session.TLUser != null)
|
||||
{
|
||||
TLRequestExportAuthorization exportAuthorization = new TLRequestExportAuthorization() { DcId = dcId };
|
||||
exported = await SendRequestAsync<TLExportedAuthorization>(exportAuthorization,times);
|
||||
exported = await SendRequestAsync<TLExportedAuthorization>(exportAuthorization, times);
|
||||
}
|
||||
|
||||
var dc = dcOptions.First(d => d.Id == dcId);
|
||||
|
||||
_transport = new TcpTransport(dc.IpAddress, dc.Port, _handler);
|
||||
_session.ServerAddress = dc.IpAddress;
|
||||
|
|
@ -124,7 +133,7 @@ namespace TLSharp.Core
|
|||
}
|
||||
catch(DataCenterMigrationException e)
|
||||
{
|
||||
if (times <= 1)
|
||||
if (times <= 150)
|
||||
{
|
||||
await ReconnectToDcAsync(e.DC, times + 1);
|
||||
// prepare the request for another try
|
||||
|
|
|
|||
|
|
@ -34,20 +34,20 @@ namespace TLSharp.Core.Utils
|
|||
|
||||
Array.Copy(msgKey, 0, buffer, 0, 16); // buffer[0:16] = msgKey
|
||||
Array.Copy(sharedKey, x, buffer, 16, 32); // buffer[16:48] = authKey[x:x+32]
|
||||
byte[] sha1a = sha1(buffer); // sha1a = sha1(buffer)
|
||||
byte[] sha1a = Sha1(buffer); // sha1a = sha1(buffer)
|
||||
|
||||
Array.Copy(sharedKey, 32 + x, buffer, 0, 16); // buffer[0:16] = authKey[x+32:x+48]
|
||||
Array.Copy(msgKey, 0, buffer, 16, 16); // buffer[16:32] = msgKey
|
||||
Array.Copy(sharedKey, 48 + x, buffer, 32, 16); // buffer[32:48] = authKey[x+48:x+64]
|
||||
byte[] sha1b = sha1(buffer); // sha1b = sha1(buffer)
|
||||
byte[] sha1b = Sha1(buffer); // sha1b = sha1(buffer)
|
||||
|
||||
Array.Copy(sharedKey, 64 + x, buffer, 0, 32); // buffer[0:32] = authKey[x+64:x+96]
|
||||
Array.Copy(msgKey, 0, buffer, 32, 16); // buffer[32:48] = msgKey
|
||||
byte[] sha1c = sha1(buffer); // sha1c = sha1(buffer)
|
||||
byte[] sha1c = Sha1(buffer); // sha1c = sha1(buffer)
|
||||
|
||||
Array.Copy(msgKey, 0, buffer, 0, 16); // buffer[0:16] = msgKey
|
||||
Array.Copy(sharedKey, 96 + x, buffer, 16, 32); // buffer[16:48] = authKey[x+96:x+128]
|
||||
byte[] sha1d = sha1(buffer); // sha1d = sha1(buffer)
|
||||
byte[] sha1d = Sha1(buffer); // sha1d = sha1(buffer)
|
||||
|
||||
byte[] key = new byte[32]; // key = sha1a[0:8] + sha1b[8:20] + sha1c[4:16]
|
||||
Array.Copy(sha1a, 0, key, 0, 8);
|
||||
|
|
@ -66,18 +66,18 @@ namespace TLSharp.Core.Utils
|
|||
public static byte[] CalcMsgKey(byte[] data)
|
||||
{
|
||||
byte[] msgKey = new byte[16];
|
||||
Array.Copy(sha1(data), 4, msgKey, 0, 16);
|
||||
Array.Copy(Sha1(data), 4, msgKey, 0, 16);
|
||||
return msgKey;
|
||||
}
|
||||
|
||||
public static byte[] CalcMsgKey(byte[] data, int offset, int limit)
|
||||
{
|
||||
byte[] msgKey = new byte[16];
|
||||
Array.Copy(sha1(data, offset, limit), 4, msgKey, 0, 16);
|
||||
Array.Copy(Sha1(data, offset, limit), 4, msgKey, 0, 16);
|
||||
return msgKey;
|
||||
}
|
||||
|
||||
public static byte[] sha1(byte[] data)
|
||||
public static byte[] Sha1(byte[] data)
|
||||
{
|
||||
using (SHA1 sha1 = new SHA1Managed())
|
||||
{
|
||||
|
|
@ -85,7 +85,7 @@ namespace TLSharp.Core.Utils
|
|||
}
|
||||
}
|
||||
|
||||
public static byte[] sha1(byte[] data, int offset, int limit)
|
||||
public static byte[] Sha1(byte[] data, int offset, int limit)
|
||||
{
|
||||
using (SHA1 sha1 = new SHA1Managed())
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue