From 9e93c19161e12abdb6122de268084101ae29e6f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A3=8E=E6=89=87=E6=BB=91=E7=BF=94=E7=BF=BC?= Date: Sat, 10 Aug 2024 13:06:00 +0800 Subject: [PATCH] Freedom: Combine fragmented tlshello if interval is 0 (#3663) Co-authored-by: RPRX <63339210+RPRX@users.noreply.github.com> Co-authored-by: Ahmadreza Dorkhah --- proxy/freedom/freedom.go | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/proxy/freedom/freedom.go b/proxy/freedom/freedom.go index 55ad353d..6abcc553 100644 --- a/proxy/freedom/freedom.go +++ b/proxy/freedom/freedom.go @@ -402,6 +402,7 @@ func (f *FragmentWriter) Write(b []byte) (int, error) { } data := b[5:recordLen] buf := make([]byte, 1024) + var hello []byte for from := 0; ; { to := from + int(randBetween(int64(f.fragment.LengthMin), int64(f.fragment.LengthMax))) if to > len(data) { @@ -413,12 +414,22 @@ func (f *FragmentWriter) Write(b []byte) (int, error) { from = to buf[3] = byte(l >> 8) buf[4] = byte(l) - _, err := f.writer.Write(buf[:5+l]) - time.Sleep(time.Duration(randBetween(int64(f.fragment.IntervalMin), int64(f.fragment.IntervalMax))) * time.Millisecond) - if err != nil { - return 0, err + if f.fragment.IntervalMax == 0 { // combine fragmented tlshello if interval is 0 + hello = append(hello, buf[:5+l]...) + } else { + _, err := f.writer.Write(buf[:5+l]) + time.Sleep(time.Duration(randBetween(int64(f.fragment.IntervalMin), int64(f.fragment.IntervalMax))) * time.Millisecond) + if err != nil { + return 0, err + } } if from == len(data) { + if len(hello) > 0 { + _, err := f.writer.Write(hello) + if err != nil { + return 0, err + } + } if len(b) > recordLen { n, err := f.writer.Write(b[recordLen:]) if err != nil {