forked from sochix/TLSharp
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Core,TL,Gen: Transport layer rewrite and bugfixes
This commit consists of the following changes: - Fixes the typo in generator that caused all ComputeFlags() functions to be empty. - Adds the missing call to ComputeFlags() inside the serialize function - Uses obfuscated websocket transport instead of TCP - Adds asynchronous response handling
- Loading branch information
Showing
1,152 changed files
with
4,040 additions
and
1,899 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,61 @@ | ||
using System; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using TgSharp.Core.Network; | ||
|
||
namespace TgSharp.Core.Auth | ||
{ | ||
public static class Authenticator | ||
public class Authenticator | ||
{ | ||
public static async Task<Step3_Response> DoAuthentication(TcpTransport transport, CancellationToken token = default(CancellationToken)) | ||
private readonly MtProtoPlainSender sender; | ||
private TaskCompletionSource<Step3_Response> completionSource; | ||
public Authenticator(WSTransport transport) | ||
{ | ||
token.ThrowIfCancellationRequested(); | ||
sender = new MtProtoPlainSender(transport); | ||
completionSource = new TaskCompletionSource<Step3_Response>(); | ||
} | ||
|
||
var sender = new MtProtoPlainSender(transport); | ||
public Task<Step3_Response> DoAuthentication() | ||
{ | ||
var step1 = new Step1_PQRequest(); | ||
|
||
await sender.Send(step1.ToBytes(), token).ConfigureAwait(false); | ||
var step1Response = step1.FromBytes(await sender.Receive(token) | ||
.ConfigureAwait(false)); | ||
//race condition ? move randomization in consturctor | ||
sender.OnResponseReceived = (step1Message) => Sender_OnStep1ResponseReceived(step1, step1Message); | ||
sender.Send(step1.ToBytes()); | ||
|
||
return completionSource.Task; | ||
} | ||
|
||
private void Sender_OnStep1ResponseReceived(Step1_PQRequest step1, byte[] step1Message) | ||
{ | ||
var step1Response = step1.FromBytes(step1Message); | ||
|
||
var step2 = new Step2_DHExchange(); | ||
await sender.Send(step2.ToBytes( | ||
sender.OnResponseReceived = (step2message) => Sender_OnStep2ResponseReceived(step2, step2message); | ||
sender.Send(step2.ToBytes( | ||
step1Response.Nonce, | ||
step1Response.ServerNonce, | ||
step1Response.Fingerprints, | ||
step1Response.Pq), token) | ||
.ConfigureAwait(false); | ||
step1Response.Pq)); | ||
} | ||
|
||
private void Sender_OnStep2ResponseReceived(Step2_DHExchange step2, byte[] step2message) | ||
{ | ||
var step2Response = step2.FromBytes(step2message); | ||
|
||
var step2Response = step2.FromBytes(await sender.Receive(token) | ||
.ConfigureAwait(false)); | ||
|
||
var step3 = new Step3_CompleteDHExchange(); | ||
await sender.Send(step3.ToBytes( | ||
sender.OnResponseReceived = (step3Message) => Sender_OnStep3ResponseReceived(step3, step3Message); | ||
sender.Send(step3.ToBytes( | ||
step2Response.Nonce, | ||
step2Response.ServerNonce, | ||
step2Response.NewNonce, | ||
step2Response.EncryptedAnswer), token) | ||
.ConfigureAwait(false); | ||
|
||
var step3Response = step3.FromBytes(await sender.Receive(token) | ||
.ConfigureAwait(false)); | ||
step2Response.EncryptedAnswer)); | ||
} | ||
|
||
return step3Response; | ||
private void Sender_OnStep3ResponseReceived(Step3_CompleteDHExchange step3, byte[] response) | ||
{ | ||
completionSource.SetResult(step3.FromBytes(response)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.