Enhance MTProxy connection handling by introducing DrainPostInitEE function to read and discard fake-TLS records after initialization. Update VerifyResPQ to accept a bufio.Reader for improved error handling and support for cleartext HTTP detection. Refactor checkEE and checkDD functions to utilize the new logic, ensuring robust response verification.
Publish mtproxy_checker Docker image / test (push) Successful in 7s
Publish mtproxy_checker Docker image / build-and-push (push) Successful in 53s

This commit is contained in:
Denozordec
2026-04-11 02:00:09 +07:00
parent bb1f71a6b2
commit 6a6183a994
2 changed files with 96 additions and 12 deletions
+8 -2
View File
@@ -1,10 +1,12 @@
package checker
import (
"bufio"
"context"
"errors"
"fmt"
"net"
"time"
"mtproxy_checker/internal/faketls"
"mtproxy_checker/internal/mtproxy"
@@ -62,7 +64,11 @@ func checkEE(ctx context.Context, conn net.Conn, p *secret.Parsed, dcID int16) e
if err := faketls.WriteTLSApplicationData(conn, hdr); err != nil {
return fmt.Errorf("write mtproxy header: %w", err)
}
if err := tgquick.VerifyResPQ(ctx, conn, enc, dec, true); err != nil {
br := bufio.NewReader(conn)
if err := tgquick.DrainPostInitEE(ctx, br, conn, dec, 2*time.Second); err != nil {
return err
}
if err := tgquick.VerifyResPQ(ctx, conn, enc, dec, br); err != nil {
if errors.Is(err, tgquick.ErrPeerClosed) {
return fmt.Errorf("%w", ErrProxyClosed)
}
@@ -79,7 +85,7 @@ func checkDD(ctx context.Context, conn net.Conn, p *secret.Parsed, dcID int16) e
if _, err := conn.Write(hdr); err != nil {
return fmt.Errorf("write mtproxy header: %w", err)
}
if err := tgquick.VerifyResPQ(ctx, conn, enc, dec, false); err != nil {
if err := tgquick.VerifyResPQ(ctx, conn, enc, dec, nil); err != nil {
if errors.Is(err, tgquick.ErrPeerClosed) {
return fmt.Errorf("%w", ErrProxyClosed)
}