td icon indicating copy to clipboard operation
td copied to clipboard

auth_key_id mismatch after `logOut`

Open keleftheriou opened this issue 3 years ago • 13 comments

I sometimes (but not always) see this type of error right after logging out. I’m not sure what it means or why it’s happening:

Session closed: [Error : 0 : Invalid mtproto message: auth_key_id mismatch [found = 0x0a0d3e6c6d84683c] [expected = 0xba91dcf84a3bff0a]] Session:1:main::Connect::HttpLongPoll::[123.123.123.123:443] to DcId{1} over HTTP

When the error occurs, my client never receives the final AuthorizationStateClosed update.

keleftheriou avatar Jun 21 '21 00:06 keleftheriou

Are you using TDLib on watchOS?

levlam avatar Jun 21 '21 00:06 levlam

Yes, I am using it on watchOS.

keleftheriou avatar Jun 21 '21 03:06 keleftheriou

What is probability of getting this error?

levlam avatar Jun 21 '21 13:06 levlam

About half the time. Is this somehow specific to watchOS?

keleftheriou avatar Jun 21 '21 16:06 keleftheriou

The problem is in HTTP transport and it currently used by default only on watchOS.

levlam avatar Jun 21 '21 17:06 levlam

You mean instead of HTTPS? Is it possible to change the default transport used on watchOS?

I’m currently using TdJson. Is the C++ TdStatic version any different in this regard?

Otherwise, what is the preferred way to build a watchOS client?

keleftheriou avatar Jun 21 '21 18:06 keleftheriou

No. On all other OS TCP transport is used by default. There is no access to raw sockets on watchOS, so it is forced to use HTTP transport.

levlam avatar Jun 21 '21 18:06 levlam

It appears this might have changed with watchOS 6, see here: https://github.com/socketio/socket.io-client-swift/issues/1215

From the watchOS 6 release notes:

URLSessionWebSocketTask and URLSessionStreamTask are now available for use in watchOS apps. (49779789)

Also URLSessionDataTask supports HTTPS.

Are any of these technically sufficient for a Telegram client on watchOS, if one was willing to spend the time to make the necessary changes?

keleftheriou avatar Jun 21 '21 19:06 keleftheriou

HTTPS makes no difference. Telegram doesn't have HTTP/HTTPS API. HTTP is used only as a transport.

levlam avatar Jun 21 '21 20:06 levlam

Thanks.

Is any of URLSessionWebSocketTask / URLSessionStreamTask / URLSessionDataTask technically sufficient for a Telegram client on watchOS, if one was willing to spend the time to make the necessary changes?

I’m trying to determine if I should build an independent watchOS client or not.

keleftheriou avatar Jun 21 '21 21:06 keleftheriou

TDLib already uses URLSessionDataTask. Existence of others makes no difference and is irrelevant to the issue.

levlam avatar Jun 21 '21 21:06 levlam

I see. Then what are the implications of TDLib using HTTP transport on watchOS?

Are there any security concerns or other downsides?

And is there anything I can do to prevent or handle the auth_key_id mismatch error?

keleftheriou avatar Jun 21 '21 22:06 keleftheriou

There are no downsides, except it is suboptimal, but watchOS has no better alternatives anyway. The error can't be avoided and needs to be properly handled in TDLib.

levlam avatar Jun 22 '21 00:06 levlam