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.
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user