@@ -296,11 +296,16 @@ type VisionWriter struct {
296296 // internal
297297 writeOnceUserUUID []byte
298298 directWriteCounter stats.Counter
299+
300+ testseed []uint32
299301}
300302
301- func NewVisionWriter (writer buf.Writer , trafficState * TrafficState , isUplink bool , ctx context.Context , conn net.Conn , ob * session.Outbound ) * VisionWriter {
303+ func NewVisionWriter (writer buf.Writer , trafficState * TrafficState , isUplink bool , ctx context.Context , conn net.Conn , ob * session.Outbound , testseed [] uint32 ) * VisionWriter {
302304 w := make ([]byte , len (trafficState .UserUUID ))
303305 copy (w , trafficState .UserUUID )
306+ if len (testseed ) < 4 {
307+ testseed = []uint32 {900 , 500 , 900 , 256 }
308+ }
304309 return & VisionWriter {
305310 Writer : writer ,
306311 trafficState : trafficState ,
@@ -309,6 +314,7 @@ func NewVisionWriter(writer buf.Writer, trafficState *TrafficState, isUplink boo
309314 isUplink : isUplink ,
310315 conn : conn ,
311316 ob : ob ,
317+ testseed : testseed ,
312318 }
313319}
314320
@@ -347,7 +353,7 @@ func (w *VisionWriter) WriteMultiBuffer(mb buf.MultiBuffer) error {
347353
348354 if * isPadding {
349355 if len (mb ) == 1 && mb [0 ] == nil {
350- mb [0 ] = XtlsPadding (nil , CommandPaddingContinue , & w .writeOnceUserUUID , true , w .ctx ) // we do a long padding to hide vless header
356+ mb [0 ] = XtlsPadding (nil , CommandPaddingContinue , & w .writeOnceUserUUID , true , w .ctx , w . testseed ) // we do a long padding to hide vless header
351357 return w .Writer .WriteMultiBuffer (mb )
352358 }
353359 isComplete := IsCompleteRecord (mb )
@@ -365,13 +371,13 @@ func (w *VisionWriter) WriteMultiBuffer(mb buf.MultiBuffer) error {
365371 command = CommandPaddingDirect
366372 }
367373 }
368- mb [i ] = XtlsPadding (b , command , & w .writeOnceUserUUID , true , w .ctx )
374+ mb [i ] = XtlsPadding (b , command , & w .writeOnceUserUUID , true , w .ctx , w . testseed )
369375 * isPadding = false // padding going to end
370376 longPadding = false
371377 continue
372378 } else if ! w .trafficState .IsTLS12orAbove && w .trafficState .NumberOfPacketToFilter <= 1 { // For compatibility with earlier vision receiver, we finish padding 1 packet early
373379 * isPadding = false
374- mb [i ] = XtlsPadding (b , CommandPaddingEnd , & w .writeOnceUserUUID , longPadding , w .ctx )
380+ mb [i ] = XtlsPadding (b , CommandPaddingEnd , & w .writeOnceUserUUID , longPadding , w .ctx , w . testseed )
375381 break
376382 }
377383 var command byte = CommandPaddingContinue
@@ -381,7 +387,7 @@ func (w *VisionWriter) WriteMultiBuffer(mb buf.MultiBuffer) error {
381387 command = CommandPaddingDirect
382388 }
383389 }
384- mb [i ] = XtlsPadding (b , command , & w .writeOnceUserUUID , longPadding , w .ctx )
390+ mb [i ] = XtlsPadding (b , command , & w .writeOnceUserUUID , longPadding , w .ctx , w . testseed )
385391 }
386392 }
387393 return w .Writer .WriteMultiBuffer (mb )
@@ -488,20 +494,20 @@ func ReshapeMultiBuffer(ctx context.Context, buffer buf.MultiBuffer) buf.MultiBu
488494}
489495
490496// XtlsPadding add padding to eliminate length signature during tls handshake
491- func XtlsPadding (b * buf.Buffer , command byte , userUUID * []byte , longPadding bool , ctx context.Context ) * buf.Buffer {
497+ func XtlsPadding (b * buf.Buffer , command byte , userUUID * []byte , longPadding bool , ctx context.Context , testseed [] uint32 ) * buf.Buffer {
492498 var contentLen int32 = 0
493499 var paddingLen int32 = 0
494500 if b != nil {
495501 contentLen = b .Len ()
496502 }
497- if contentLen < 900 && longPadding {
498- l , err := rand .Int (rand .Reader , big .NewInt (500 ))
503+ if contentLen < int32 ( testseed [ 0 ]) && longPadding {
504+ l , err := rand .Int (rand .Reader , big .NewInt (int64 ( testseed [ 1 ]) ))
499505 if err != nil {
500506 errors .LogDebugInner (ctx , err , "failed to generate padding" )
501507 }
502- paddingLen = int32 (l .Int64 ()) + 900 - contentLen
508+ paddingLen = int32 (l .Int64 ()) + int32 ( testseed [ 2 ]) - contentLen
503509 } else {
504- l , err := rand .Int (rand .Reader , big .NewInt (256 ))
510+ l , err := rand .Int (rand .Reader , big .NewInt (int64 ( testseed [ 3 ]) ))
505511 if err != nil {
506512 errors .LogDebugInner (ctx , err , "failed to generate padding" )
507513 }
0 commit comments