-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Security: Implement perfect forward secrecy for MTProto #4618
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: v1
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. It's much appreciated. My only worries are:
- If this breaks, I don't know if I'll be able to provide a timely fix myself.
- There'll likely be an expectation that v2 (if I ever finish that) will support PFS too.
I'm assuming the performance hit is not something we should worry about, since by default they expire after a day (although the first connection might be noticeably slower, specially with pure-Python encryption on mobile devices).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there are shortcomings in this implementation.
first it does not handle the -404 error code at the transport level, telegram clearly says that temporary keys could be deleted from the server before they expire, you have to regenerate the key in this case
the AUTH_KEY_PERM_EMPTY error should also be handled, sometimes telegram may forget which persistent key the temporary key is bound to, again the key must be regenerated.
in the case of -404 if the key was generated within 60 seconds of the error you simply have to reconnect instead of regenerating it because it happens that immediately after generating it the server still does not accept the key.
I am happy to hear! Thanks, also for your comments. I'll provide a patch shortly.
At least for the latter issue, I can offer that I'll give implementing this in v2 a try in the next weeks.
I would think so, too. After the temporary key has been generated and bound, performance should be back to normal until the key needs to be changed. |
|
Thanks for your review @andrew-ld.
I fixed this and will provide a patch shortly. I am not sure if this is the correct place, so please let me know about any further changes you would like to see. Accessing a private method is also not really a nice thing here.
Yes, I have also read that part of the docs. Therefore, the current implementation should always attempt to regenerate the key if I am not missing something. I have changed the following to test this: If I run the following program, the expired key is handled, as expected, by reconnecting (which triggers the generation of a new key). As before, please let me know if I am missing something here. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i dont think that always re-generate the temp auth key is a good idea, the client must keep the generated temp key in memory and re-generate only if needed
Sorry for the late reply - could you please elaborate what changes you'd like to see in this regard? |
Hi!
Thanks for the great work with Telethon.
Quite a while ago I have implemented support for perfect forward secrecy in MTProto (cf. https://core.telegram.org/api/pfs) and would love to share this work with the community.
I understand that v1 is feature frozen, however, I think that this provides an advantage in security for all users and is not a new feature per se but rather a security fix.
This PR also fixes two bugs (type confusion, error handling on seq_no too low/too high) that can cause issues.
I have tested this with both a personal account and a bot token and did not encouter any problems.
I have also tested the behavior on the expiration of a temporary auth key.