Fix 2FA issue under .NET Fw 4.7.2

minor doc updates
This commit is contained in:
Wizou 2021-12-01 15:50:35 +01:00
parent 12ea8ac1bb
commit 5e04a51e54
6 changed files with 33 additions and 18 deletions

View file

@ -7,9 +7,12 @@ using System.Linq;
using TL;
```
Those examples use environment variables for configuration so make sure to go to your **Project Properties > Debug > Environment variables** and add at least these variables with adequate value: **api_id, api_hash, phone_number**
Those examples use environment variables for configuration so make sure to
go to your **Project Properties > Debug > Environment variables**
and add at least these variables with adequate value: **api_id, api_hash, phone_number**
Remember that these are just simple example codes that you should adjust to your needs. In real production code, you're supposed to properly test the success of each operation.
Remember that these are just simple example codes that you should adjust to your needs.
In real production code, you might want to properly test the success of each operation or handle exceptions.
### Send a message to someone by @username
```csharp
@ -158,11 +161,12 @@ for (int offset = 0; ;)
### Monitor all Telegram events happening for the user
This is done through the `client.Update` callback event.
See [Examples/Program_ListenUpdates.cs](Examples/Program_ListenUpdates.cs).
### Monitor new messages being posted in chats
You have to catch Update events containing an `UpdateNewMessage`.
You have to handle `client.Update` events containing an `UpdateNewMessage`.
See the `DisplayMessage` method in [Examples/Program_ListenUpdates.cs](Examples/Program_ListenUpdates.cs).
@ -170,13 +174,17 @@ You can filter specific chats the message are posted in, by looking at the `Mess
### Download media files you forward to yourself (Saved Messages)
This is done using the helper method `client.DownloadFileAsync(file, outputStream)`
that simplify the download of a photo/document/file once you get a reference to its location.
See [Examples/Program_DownloadSavedMedia.cs](Examples/Program_DownloadSavedMedia.cs).
### Collect Access Hash and save them for later use
You can automate the collection of `access_hash` for the various resources obtained in response to API calls or Update events, so that you don't have to remember them by yourself or ask the API about them each time.
You can automate the collection of `access_hash` for the various resources obtained in response to API calls or Update events,
so that you don't have to remember them by yourself or ask the API about them each time.
This is done by activating the experimental `client.CollectAccessHash` system.
This is done by activating the experimental `client.CollectAccessHash` system.
See [Examples/Program_CollectAccessHash.cs](Examples/Program_CollectAccessHash.cs) for how to enable it, and save/restore them for later use.
### Use a proxy to connect to Telegram

8
FAQ.md
View file

@ -59,9 +59,9 @@ The developmental versions of the library are available through Azure DevOps as
You can access these versions for testing in your program by going to our [private nuget feed](https://dev.azure.com/wiz0u/WTelegramClient/_packaging?_a=package&feed=WTelegramClient&view=overview&package=WTelegramClient&protocolType=NuGet), then click on "Connect to feed" and follow the steps.
After that, you should be able to see/install the pre-release versions in your Nuget package manager and install them in your application. *(make sure you enable the **pre-release** checkbox)*
#### 6. Telegram asks me to signup (firstname, lastname) even for an existing account and can't find any chats
#### 6. Telegram can't find any chats and asks me to signup (firstname, lastname) even for an existing account
This happens when you connect to Telegram Test servers instead of Production servers.
On these separate test servers, created accounts and chats are periodically deleted, so you shouldn't use them under normal circumstances.
On these separate test servers, all created accounts and chats are periodically deleted, so you shouldn't use them under normal circumstances.
This wrong-server problem typically happens when you use WTelegramClient Github source project in your application in DEBUG builds.
It is **not recommended** to use WTelegramClient in source code form.
@ -97,9 +97,11 @@ Here are some key points:
*(the above section is derived from [gotd SUPPORT.md](https://github.com/gotd/td/blob/main/.github/SUPPORT.md))*
If your client displays Telegram channels to the user, you have to support and display [official sponsored messages](https://core.telegram.org/api/sponsored-messages).
#### 8. I can't import phone numbers. I get error PHONE_NUMBER_BANNED or FLOOD_WAIT_8xxxx
You can get these kind of problems if you abuse Telegram [Terms of Service](https://telegram.org/tos) or make excessive requests.
You can get these kind of problems if you abuse Telegram [Terms of Service](https://telegram.org/tos) or https://core.telegram.org/api/terms or make excessive requests.
You can try to wait more between the requests, wait for a day or two to see if the requests become possible again.

View file

@ -5,7 +5,7 @@
[![Support Chat](https://img.shields.io/badge/Chat_with_us-on_Telegram-0088cc)](https://t.me/WTelegramClient)
[![Donate](https://img.shields.io/badge/Help_this_project:-Donate-ff4444)](http://wizou.fr/donate.html)
## _Telegram Client API library written 100% in C# and .NET Standard_
## _a Telegram Client API library written 100% in C# and .NET Standard_
# How to use
@ -82,7 +82,7 @@ using TL;
var chats = await client.Messages_GetAllChats(null);
Console.WriteLine("This user has joined the following:");
foreach (var (id, chat) in chats.chats)
switch (chat)
switch (chat) // example of downcasting to their real classes:
{
case Chat smallgroup when smallgroup.IsActive:
Console.WriteLine($"{id}: Small group: {smallgroup.title} with {smallgroup.participants_count} members");
@ -135,11 +135,12 @@ This library can be used for any Telegram scenarios including:
- Sequential or parallel automated steps based on API requests/responses
- Real-time monitoring of incoming Updates/Messages
- Download/upload of files/media
- or even a full-featured interactive client
It has been tested in a Console app, WinForms app, ASP.NET webservice.
Secret chats (end-to-end encryption, PFS) and connection to CDN DCs have not been tested yet.
Please don't use this library for Spam or Scam. Respect Telegram [Terms of Service](https://telegram.org/tos) or you might get banned from Telegram servers.
Please don't use this library for Spam or Scam. Respect Telegram [Terms of Service](https://telegram.org/tos) as well as the [API Terms of Service](https://core.telegram.org/api/terms) or you might get banned from Telegram servers.
Developers feedbacks are welcome in the Telegram support group [@WTelegramClient](https://t.me/WTelegramClient)
You can also check our [📖 Frequently Asked Questions](https://github.com/wiz0u/WTelegramClient/blob/master/FAQ.md) for more help and troubleshooting guide.

View file

@ -35,7 +35,7 @@ namespace WTelegram
public int FloodRetryThreshold { get; set; } = 60;
/// <summary>Is this Client instance the main or a secondary DC session</summary>
public bool IsMainDC => (_dcSession?.DataCenter?.id ?? 0) == _session.MainDC;
/// <summary>Is this Client currently disconnected?</summary>
/// <summary>Has this Client established connection been disconnected?</summary>
public bool Disconnected => _tcpClient != null && !(_tcpClient.Client?.Connected ?? false);
/// <summary>Used to indicate progression of file download/upload</summary>
/// <param name="totalSize">total size of file in bytes, or 0 if unknown</param>
@ -1003,8 +1003,7 @@ namespace WTelegram
catch (RpcException e) when (e.Code == 401 && e.Message == "SESSION_PASSWORD_NEEDED")
{
var accountPassword = await this.Account_GetPassword();
Helpers.Log(3, $"This account has enabled 2FA. A password is needed. {accountPassword.hint}");
var checkPasswordSRP = Check2FA(accountPassword, Config("password"));
var checkPasswordSRP = Check2FA(accountPassword, () => Config("password"));
authorization = await this.Auth_CheckPassword(checkPasswordSRP);
break;
}

View file

@ -362,18 +362,22 @@ j4WcDuXc2CTHgH8gFTNhp/Y8/SpDOhvn9QIDAQAB
return output;
}
internal static InputCheckPasswordSRP Check2FA(Account_Password accountPassword, string password)
internal static InputCheckPasswordSRP Check2FA(Account_Password accountPassword, Func<string> getPassword)
{
if (accountPassword.current_algo is not PasswordKdfAlgoSHA256SHA256PBKDF2HMACSHA512iter100000SHA256ModPow algo)
throw new ApplicationException("2FA authentication uses an unsupported algo: " + accountPassword.current_algo?.GetType().Name);
var passwordBytes = Encoding.UTF8.GetBytes(password);
var g = new BigInteger(algo.g);
var p = BigEndianInteger(algo.p);
var g_b = BigEndianInteger(accountPassword.srp_B);
var g_b_256 = g_b.To256Bytes();
var g_256 = g.To256Bytes();
ValidityChecks(p, algo.g);
var validTask = Task.Run(() => ValidityChecks(p, algo.g));
System.Threading.Thread.Sleep(100);
Helpers.Log(3, $"This account has enabled 2FA. A password is needed. {accountPassword.hint}");
var passwordBytes = Encoding.UTF8.GetBytes(getPassword());
validTask.Wait();
using var sha256 = SHA256.Create();
sha256.TransformBlock(algo.salt1, 0, algo.salt1.Length, null, 0);
@ -416,6 +420,7 @@ j4WcDuXc2CTHgH8gFTNhp/Y8/SpDOhvn9QIDAQAB
var t = (g_b - k_v) % p; //(positive modulo, if the result is negative increment by p)
if (t.Sign < 0) t += p;
var s_a = BigInteger.ModPow(t, a + u * x, p);
sha256.Initialize();
var k_a = sha256.ComputeHash(s_a.To256Bytes());
hash = sha256.ComputeHash(algo.p);

View file

@ -42,7 +42,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">