Skip to content

Conversation

Copy link

Copilot AI commented Dec 28, 2025

When -D domain option is used to enable Fake-TLS mode, connections using EE mode (tag 0xeeeeeeee) were incorrectly rejected with "Expected random padding mode" error. This prevented the documented EE mode secret format (ee + secret + domain_hex) from working.

Changes

  • Refined validation in net/net-tcp-rpc-ext-server.c (lines 1318-1321) to properly allow EE/EF modes and reject DD mode when allow_only_tls flag is set

The original buggy check was:

if (tag != 0xdddddddd && allow_only_tls) {
  vkprintf (1, "Expected random padding mode\n");
  RETURN_TLS_ERROR(default_domain_info);
}

This incorrectly rejected EE/EF modes (Fake-TLS) and only allowed DD mode (random padding only) when -D was used.

The fixed validation is:

if (tag == 0xdddddddd && allow_only_tls) {
  vkprintf (1, "Expected Fake-TLS mode (EE/EF), got random padding mode (DD)\n");
  RETURN_TLS_ERROR(default_domain_info);
}

This properly rejects DD mode and allows EE/EF modes when -D is specified, maintaining security validation while fixing the bug.

Behavior

When -D option is used:

  • ✅ EE mode (0xeeeeeeee - Fake-TLS + Padding) is allowed
  • ✅ EF mode (0xefefefef - Fake-TLS compact) is allowed
  • ❌ DD mode (0xdddddddd - random padding only) is rejected with clear error message

The logic correctly separates two orthogonal concerns:

  • -D option sets allow_only_tls to enforce Fake-TLS transport modes (EE/EF)
  • -R option sets ext_rand_pad_only to restrict to DD mode only
Original prompt

This section details on the original issue you should resolve

<issue_title>Fake TSL not working</issue_title>
<issue_description>Hi!

I've tried to setup Fake-TLS configuration but it doesn't work in my case.

Stept to reproduce:

  1. Clean Ubuntu 24.04 (LTS) + update with all latest packages with apt-get update && apt-get upgrade
  2. Clone repo
  3. Install dependencies with apt install git curl build-essential libssl-dev zlib1g-dev
  4. Build with make && cd objs/bin
  5. Generate secret with head -c 16 /dev/urandom | xxd -ps and domain hex with echo -n www.google.com | xxd -plain
  6. Run with ./mtproto-proxy -u nobody -p 8888 -H 443 -S <generated secret> -D www.google.com --http-stats --aes-pwd proxy-secret proxy-multi.conf -M 1
  7. Connect in Telegram app with secret ee + <generated secret> + 7777772e676f6f676c652e636f6d

Telegram client (macOS 12.3.277495 Stable or iOS 12.2.4) cannot connect to proxy.
Same build but without -D www.google.com and standard secret in app setting works perfectly fine.

Any ideas what is the problem?

Included in the attachment log with -v flag

mtproto-verbose.log

</issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Remove incorrect check that was rejecting 0xeeeeeeee tag when allow_only_tls flag is set. This allows EE mode (Fake-TLS + Padding) to work properly when -D domain option is specified.

Co-authored-by: dvershinin <250071+dvershinin@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix Fake-TLS not working issue Fix Fake-TLS (EE mode) rejected when domain option specified Dec 28, 2025
Copilot AI requested a review from dvershinin December 28, 2025 13:17
@dvershinin
Copy link

@copilot why remove the validation entirely? Perhaps just relaxing it a bit is a better approach.

Instead of removing validation entirely, now properly validates that when -D (Fake-TLS) option is used:
- DD mode (0xdddddddd - random padding only) is rejected
- EE mode (0xeeeeeeee - Fake-TLS + Padding) is allowed
- EF mode (0xefefefef - Fake-TLS compact) is allowed

This maintains proper security validation while fixing the original bug.

Co-authored-by: dvershinin <250071+dvershinin@users.noreply.github.com>
Copy link
Author

Copilot AI commented Dec 28, 2025

@copilot why remove the validation entirely? Perhaps just relaxing it a bit is a better approach.

You're right. I've refined the validation instead of removing it entirely. The new check inverts the logic to properly reject DD mode (random padding only) when -D is used, while allowing EE/EF modes (Fake-TLS). This maintains security validation while fixing the bug. See commit 926ec36.

Copilot AI and others added 2 commits December 28, 2025 13:25
Co-authored-by: dvershinin <250071+dvershinin@users.noreply.github.com>
Co-authored-by: dvershinin <250071+dvershinin@users.noreply.github.com>
@dvershinin dvershinin marked this pull request as ready for review December 28, 2025 13:28
@dvershinin dvershinin merged commit 6f20cec into master Dec 28, 2025
3 checks passed
@dvershinin dvershinin deleted the copilot/fix-fake-tls-issue branch December 28, 2025 13:29
@dvershinin
Copy link

@copilot still not working, still same behavior as in https://github.com/user-attachments/files/24359663/mtproto-verbose.log

@dvershinin dvershinin restored the copilot/fix-fake-tls-issue branch December 28, 2025 16:43
@dvershinin
Copy link

@copilot hello

Copilot AI added a commit that referenced this pull request Dec 28, 2025
This fix reverts the problematic changes from PR #24 and PR #25 that broke
Fake-TLS connections:

1. Revert TLS ClientHello detection to original pattern: The change in PR #25
   incorrectly checked the length byte instead of TLS version, which could
   cause detection failures.

2. Remove the tag validation check that was incorrectly rejecting EE/EF modes:
   - For Fake-TLS connections (C_IS_TLS set), any valid tag should be accepted
   - For non-TLS connections with allow_only_tls=1, connection is rejected earlier
   - This check was unnecessary and was causing EE mode to fail

Fixes #23

Co-authored-by: dvershinin <250071+dvershinin@users.noreply.github.com>
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.

Fake TSL not working

2 participants