@@ -2,6 +2,7 @@ package tcp
2
2
3
3
import (
4
4
"context"
5
+ "slices"
5
6
"strings"
6
7
7
8
"github.com/xtls/xray-core/common"
@@ -33,17 +34,24 @@ func Dial(ctx context.Context, dest net.Destination, streamSettings *internet.Me
33
34
if IsFromMitm (tlsConfig .ServerName ) {
34
35
tlsConfig .ServerName = mitmServerName
35
36
}
36
- r , ok := tlsConfig .Rand .(* tls.RandCarrier )
37
- isFromMitmVerify := ok && len (r .VerifyPeerCertInNames ) > 0 && IsFromMitm (r .VerifyPeerCertInNames [0 ])
38
- if isFromMitmVerify {
39
- r .VerifyPeerCertInNames = r .VerifyPeerCertInNames [1 :]
40
- after := mitmServerName
41
- for {
42
- if len (after ) > 0 {
43
- r .VerifyPeerCertInNames = append (r .VerifyPeerCertInNames , after )
44
- }
45
- _ , after , _ = strings .Cut (after , "." )
46
- if ! strings .Contains (after , "." ) {
37
+ isFromMitmVerify := false
38
+ if r , ok := tlsConfig .Rand .(* tls.RandCarrier ); ok && len (r .VerifyPeerCertInNames ) > 0 {
39
+ for i , name := range r .VerifyPeerCertInNames {
40
+ if IsFromMitm (name ) {
41
+ isFromMitmVerify = true
42
+ r .VerifyPeerCertInNames [0 ], r .VerifyPeerCertInNames [i ] = r .VerifyPeerCertInNames [i ], r .VerifyPeerCertInNames [0 ]
43
+ r .VerifyPeerCertInNames = r .VerifyPeerCertInNames [1 :]
44
+ after := mitmServerName
45
+ for {
46
+ if len (after ) > 0 {
47
+ r .VerifyPeerCertInNames = append (r .VerifyPeerCertInNames , after )
48
+ }
49
+ _ , after , _ = strings .Cut (after , "." )
50
+ if ! strings .Contains (after , "." ) {
51
+ break
52
+ }
53
+ }
54
+ slices .Reverse (r .VerifyPeerCertInNames )
47
55
break
48
56
}
49
57
}
0 commit comments