English
mtproto
The MTProto proxy inbound for Telegram clients with an ee secret: a fake TLS handshake signed by the secret, then obfuscated2 inside TLS application records. The inbound decrypts the client's side, encrypts it again for the datacenter the client asked for, and hands routing a TCP connection to that datacenter. A connection that no secret signs goes to a fallback, so a prober sees the site the secret names. Telegram's middle proxies (and sponsored channels with them) are not used.
| Crate | ours-mod-mtproto, modules/protocols/mtproto |
| Binary features | mtproto |
| Crate features | none |
requires
Nothing: the inbound only accepts connections; the connection to the datacenter goes through routing.
provides
Provide::Inbound { key: "mtproto" }, the schemainbounds.mtproto.
Syntax: mtproto.
Dependencies
ours-proto (decoy, fallback, users), ours-config, ours-clock, ours-api, ours-codec, ours-net-sys, ours-bufpool; aes, ctr, hmac, sha2.
Design
src/lib.rs—MODULEand the decoder (listener_members,fallbacks,hot_users).src/inbound.rs— the listener, the handshake, the choice between a datacenter and a fallback. A replayed hello is treated as a stranger's and goes to the fallback.src/faketls.rs— the fake TLS: a ClientHello whose random is an HMAC under the secret with the time folded in, a ServerHello signed the same way, records that only frame the data.src/obfs.rs— obfuscated2: the 64-byte header, AES-256-CTR per direction, the datacenter addresses.src/relay.rs— the relay between the client and the datacenter; both ciphers run in the relay's buffer, without extra copies.src/options.rs—MtprotoInboundOptions,MtprotoUser.
The hello's time is checked against ours_clock::Clock.
Reload
Users reload in place, as in http; validate_hot checks the new secrets first.
Limitations
Without fallbacks on a non-loopback address the inbound logs a warning: a prober's TLS handshake is cut off rather than answered by a real site.
Tests
Unit tests in src/inbound.rs, src/faketls.rs, src/obfs.rs, src/relay.rs; fuzzing in fuzz/.