wiz0u / WTelegramClient

Telegram Client API (MTProto) library written 100% in C# and .NET
https://wiz0u.github.io/WTelegramClient/
MIT License
958 stars 156 forks source link

Disconnect client with Fatal Error WTelegram.WTException: Server salt changed too often! Security issue? #216

Closed altbodhi closed 9 months ago

altbodhi commented 9 months ago

WTelegram-2023-12-04.log My app hosted on VM iis windows 2016 x64. Sometime (one in day, or 2-3 days) client disconnected with fatal exception:

Client_OnUpdate -> "TL.UpdateNewChannelMessage" WTelegram.WTException: Server salt changed too often! Security issue?
   at WTelegram.Client.ReadFrame(Byte[] data, Int32 dataLen)
   at WTelegram.Client.Reactor(Stream stream, CancellationTokenSource cts)
   at WTelegram.Client.Reactor(Stream stream, CancellationTokenSource cts)
   at WTelegram.Client.Invoke[T](IMethod`1 query)
   at WTelegram.Client.Invoke[T](IMethod`1 query)
   at WTelegram.Client.DoConnectAsync()

In this block code i got fatality:

    private async Task Client_OnUpdate(UpdatesBase updates)
    {
        updates.CollectUsersChats(Users, Chats);
        foreach (var update in updates.UpdateList)
        {
            logger.LogDebug("Client_OnUpdate -> {name}", update.GetType().Name);
            try
            {
                switch (update)
                {
                    case UpdateNewMessage unm: await HandleNewMessage(unm.message); break; // <= exn raised here  
                    default: break;
                }
            }
            catch (Exception ex)
            {
                logger.LogError(ex, "Client_OnUpdate -> {@update}", update);
            }
        }
    }

This is my config function:

    private string Config(string key, Dictionary<string, string>? addons = null)
    {
        switch (key)
        {
            case "api_hash": return bot.ApiHash;
            case "api_id": return bot.ApiId;
            case "phone_number": return bot.PhoneNumber;
            case "verification_code":
                NeedVerificationCode?.Invoke(Id);
                return ReadCode != null ? ReadCode() : "";
            case "session_pathname": return Path.Combine("sessions", bot.Id.ToString("000") + ".dat");
            default:
                if (addons == null) return null!;
                return addons.TryGetValue(key, out var val) ? val : null!;
        }
    }
altbodhi commented 9 months ago

This is continues. I add job in scheduler who run w32tm /resync every 10 minutes (windows 2016 x64). 7th succesfully reconnect

2023-12-07 23:01:38.2192|0|WARN|WTelegram|5>Server salt has changed: E18519AAC124FA9B -> CEE94B837B18776F 
2023-12-07 23:01:38.2192|0|FATAL|WTelegram|5>An exception occured in the reactor: WTelegram.WTException: Server salt changed too often! Security issue?
   at WTelegram.Client.ReadFrame(Byte[] data, Int32 dataLen)
   at WTelegram.Client.Reactor(Stream stream, CancellationTokenSource cts) 
2023-12-07 23:01:44.2230|0|INFO|WTelegram|Connecting to 91.108.56.145:443... 
2023-12-07 23:01:44.4752|0|DEBUG|WTelegram|5>Sending   InvokeWithLayer`1                        #0B53 
2023-12-07 23:01:45.0224|0|DEBUG|WTelegram|5>Receiving Updates                                  2023-12-07 16:01:44Z   
2023-12-07 23:01:45.0224|0|DEBUG|WTelegram|5>Sending   MsgContainer                             2023-12-07 16:01:44Z (svc) 
2023-12-07 23:01:45.0224|0|DEBUG|WTelegram|            → Messages_GetAvailableReactions         #9E54 
2023-12-07 23:01:45.0224|0|DEBUG|WTelegram|            → MsgsAck                                

but 8th again client falled

2023-12-08 11:00:49.7961|0|DEBUG|WTelegram|5>Sending   MsgContainer                             2023-12-08 04:00:48Z (svc) 
2023-12-08 11:00:49.7961|0|DEBUG|WTelegram|            → Messages_SendReaction                  #CCA0 
2023-12-08 11:00:49.7961|0|DEBUG|WTelegram|            → MsgsAck                                
2023-12-08 11:00:50.1012|0|DEBUG|WTelegram|5>Receiving RpcResult                                2023-12-08 04:00:49Z 
2023-12-08 11:00:50.1012|0|DEBUG|WTelegram|             → Updates                               #CCA0 
2023-12-08 11:00:53.7962|0|DEBUG|WTelegram|5>Sending   MsgContainer                             2023-12-08 04:00:52Z (svc) 
2023-12-08 11:00:53.7962|0|DEBUG|WTelegram|            → Messages_SendReaction                  #5D94 
2023-12-08 11:00:53.7962|0|DEBUG|WTelegram|            → MsgsAck                                
2023-12-08 11:00:53.9835|0|DEBUG|WTelegram|5>Sending   PingDelayDisconnect                      #4C95 
2023-12-08 11:00:54.0726|0|DEBUG|WTelegram|5>Receiving RpcResult                                2023-12-08 04:00:53Z 
2023-12-08 11:00:54.0726|0|DEBUG|WTelegram|             → Updates                               #5D94 
2023-12-08 11:00:54.2994|0|DEBUG|WTelegram|5>Receiving Pong                                     2023-12-08 04:00:54Z (svc)  
2023-12-08 11:01:20.1120|0|DEBUG|WTelegram|5>Receiving Updates                                  2023-12-08 04:01:19Z   
2023-12-08 11:01:20.1120|0|DEBUG|WTelegram|5>Receiving Updates                                  2023-12-08 04:01:19Z   
2023-12-08 11:01:20.1120|0|DEBUG|WTelegram|5>Sending   MsgContainer                             2023-12-08 04:01:19Z (svc) 
2023-12-08 11:01:20.1120|0|DEBUG|WTelegram|            → Messages_GetAvailableReactions         #3B93 
2023-12-08 11:01:20.1120|0|DEBUG|WTelegram|            → MsgsAck                                
2023-12-08 11:01:20.1120|0|WARN|WTelegram|5>Server salt has changed: E8840A620E01EE8F -> 80369E9AA9D5703B 
2023-12-08 11:01:20.1120|0|FATAL|WTelegram|5>An exception occured in the reactor: WTelegram.WTException: Server salt changed too often! Security issue?
   at WTelegram.Client.ReadFrame(Byte[] data, Int32 dataLen)
   at WTelegram.Client.Reactor(Stream stream, CancellationTokenSource cts) 
wiz0u commented 9 months ago

Please confirm 3.6.2-dev.1 fix your issue

altbodhi commented 9 months ago

Please confirm 3.6.2-dev.1 fix your issue Yes, 2th days don't have fatal errors in wt's log, including the error specified in this issue. Thank you!