ferogram-e2e
Telegram secret chats (end-to-end encryption) for ferogram.
Implements Telegram's secret chat protocol (MTProto 2.0): key exchange, message and file encryption, re-keying, and self-destruct timers. ferogram re-exports this as ferogram::e2e behind the e2e feature, so most people never depend on it directly. For installation instructions see the ferogram README.
Beta. This crate is
0.1.0-b1. The encryption layer has unit tests and the full flow (request, accept, send, receive) has been tried in live secret chats, but it is still young. Expect API changes before0.1.0.
What it does
- Diffie-Hellman key exchange with Telegram's validity checks (
dh) - MTProto 2.0 message encryption and decryption, key fingerprints (
crypto) - The inner secret chat TL layer: text, photos, documents, locations, contacts, service actions (
tl) - Per-file AES-256-IGE encryption plus chunked upload and download of encrypted files (
upload) - Chat state: sequence numbers, TTLs, re-keying, gap detection and resend requests (
state) E2eClientto request, accept and use secret chats (with ferogram,request_secret_chattakes a@username, phone or user id and looks up the access hash itself), andE2eEventfor what comes back from the update streamE2eTransporttrait, so any client can drive it (the crate does not depend onferogram)
Usage
With ferogram, enable the e2e feature:
= { = "0.6", = ["e2e"] }
use ;
// Keeps chats in `mybot.e2e` next to the session, so they survive restarts.
let e2e = for_session?;
let chat_id = e2e.request_secret_chat.await?;
let mut stream = client.stream_updates;
while let Some = stream.next.await
A runnable version is in ferogram/examples/secret_chat.rs.
Storage
E2eClient::for_session stores chats in a small binary file, <session_name>.e2e (mybot.session becomes mybot.e2e). Writes are atomic, the file is checksummed, and on Unix it is created with mode 0600. E2eClient::new keeps everything in memory, and E2eClient::with_persistence(client, path) takes an explicit path.
The file holds each chat's auth_key unencrypted. Keep it somewhere only your process can read.
Other clients
Implement E2eTransport (invoke and invoke_on_dc) for your client type and feed raw tl::enums::Updates into E2eClient::handle_update.
Known limitations
- Secret chats work between users only (not groups or channels), as in Telegram itself.
Stack position
ferogram
└ ferogram-e2e <-- here
├ ferogram-crypto
└ ferogram-tl-types
License
This project is licensed under either the MIT License or Apache License 2.0, at your option. See LICENSE-MIT and LICENSE-APACHE for details.
Author: Ankit Chaubey (@ankit-chaubey)