Skip to content

Add native MTProxy support#298

Open
makarovstas wants to merge 5 commits into
KurimuzonAkuma:devfrom
makarovstas:dev
Open

Add native MTProxy support#298
makarovstas wants to merge 5 commits into
KurimuzonAkuma:devfrom
makarovstas:dev

Conversation

@makarovstas

@makarovstas makarovstas commented Apr 3, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds first-class MTProxy support directly into the transport layer. Users can now connect through an MTProxy server by passing
scheme: "mtproxy" in the proxy dict — the same way SOCKS5 proxies are configured.

All three secret formats are supported:

Prefix Protocol
ee<32 hex><domain hex> Fake-TLS with SNI domain
dd<32 hex> Fake-TLS without fixed SNI
<32 hex> Plain obfuscation (obf2)

Usage

from pyrogram import Client

client = Client(
    "session",
    api_id=...,
    api_hash=...,
    proxy={
        "scheme": "mtproxy",
        "hostname": "your.mtproxy.host",
        "port": 443,
        "secret": "eeeab756314c868a251adde878bdf93b7473746f726167652e79616e646578636c6f75642e6e6574",
    },
)

The secret is the standard MTProxy secret string from the proxy's connection link (tg://proxy?...).

Implementation details

  • TCP — new _connect_via_mtproxy, _connect_via_mtproxy_obf2, _connect_via_mtproxy_faketls methods handle the handshake; send/recv transparently encrypt/decrypt traffic using AES-CTR once the connection is established

  • TCPAbridged — skips the abridged \xef marker byte for MTProxy connections (the protocol tag is embedded in the obfuscation nonce instead)

  • Connection — injects dc_id into the proxy dict before passing it to the transport so the nonce can encode the target DC

  • ProxyDict — added optional secret field

Fake-TLS implementation follows the mtprotoproxy spec: HMAC-SHA256 signed ClientHello padded to ≥ 512 bytes, padded-intermediate framing (0xdd × 4) after the TLS handshake.

@KurimuzonAkuma KurimuzonAkuma self-assigned this Apr 3, 2026
@makarovstas

Copy link
Copy Markdown
Contributor Author

@KurimuzonAkuma hi bratello 🙂

@KurimuzonAkuma

Copy link
Copy Markdown
Owner

@makarovstas Да там вайбкод нейрослоп от клода, я еще не тестил, боюсь.....

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants