Skip to main content

Crate ferogram_e2e

Crate ferogram_e2e 

Source
Expand description

Telegram secret chats (end-to-end encryption) for ferogram.

This crate is part of ferogram, an async Rust MTProto client built by Ankit Chaubey.

Most users should enable the e2e feature of the ferogram crate and use ferogram::e2e, which re-exports this crate and connects it to ferogram::Client. Use ferogram-e2e directly only to drive secret chats from another client by implementing E2eTransport; in that case E2eClient::request_secret_chat_raw takes the peer’s user id and access hash directly.

§What’s in here

  • Key exchange: Diffie-Hellman handshake with Telegram’s validity checks (dh).
  • Messages: MTProto 2.0 encryption of the inner TL layer (crypto, tl).
  • Files: per-file AES-256-IGE encryption plus chunked upload (upload).
  • Chat state: sequence numbers, TTLs, re-keying, optional binary persistence (state).
  • High-level API: E2eClient to request, accept and use secret chats, and E2eEvent for what comes back from the update stream.

§Security notes

Persisted chat state (see E2eClient::for_session and E2eClient::with_persistence) contains the 256-byte auth_key of every chat, unencrypted. The file is created with mode 0600 on Unix; on other platforms keep it somewhere only your process can read.

§Example

ⓘ
// With the `e2e` feature of `ferogram` enabled:
use ferogram::e2e::{E2eClient, E2eClientExt, E2eEvent};

let e2e = E2eClient::new(client.clone());
let chat_id = e2e.request_secret_chat("@username").await?;

let mut stream = client.stream_updates();
while let Some(update) = stream.next().await {
    if let Some(E2eEvent::ChatReady { chat_id }) = e2e.handle_client_update(&update).await? {
        e2e.send_text(chat_id, "hello", 0).await?;
    }
}

Re-exports§

pub use chat::E2eClient;
pub use error::E2eError;
pub use tl::DecryptedAction;
pub use tl::DecryptedMedia;
pub use tl::DecryptedMessage;
pub use tl::DecryptedMessageLayer;
pub use tl::DocumentAttribute;
pub use transport::E2eTransport;
pub use update::E2eEvent;

Modules§

chat
High-level secret chat client (E2eClient): request, accept, send, receive, re-key.
crypto
Cryptographic primitives for Telegram secret chats (MTProto 2.0).
dh
Diffie-Hellman helpers for the secret chat key exchange.
error
Error type for the secret chat layer.
state
Per-chat state and the store that keeps it (in memory, optionally on disk).
tl
Inner TL layer of Telegram secret chats.
transport
Transport abstraction between the E2E layer and a Telegram client.
update
Turning raw Telegram updates into E2eEvents.
upload
Chunked upload of encrypted file ciphertext for messages.sendEncryptedFile.

Enums§

EncryptedFile
EncryptedFile