mirror of
https://github.com/XTLS/Xray-core.git
synced 2026-07-04 02:38:42 +00:00
Add shadow-tls support
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
package singbridge
|
||||
|
||||
import (
|
||||
"context"
|
||||
gotls "crypto/tls"
|
||||
"os"
|
||||
|
||||
E "github.com/sagernet/sing/common/exceptions"
|
||||
M "github.com/sagernet/sing/common/metadata"
|
||||
"github.com/xtls/xray-core/common/net"
|
||||
"github.com/xtls/xray-core/transport/internet"
|
||||
"github.com/xtls/xray-core/transport/internet/tls"
|
||||
)
|
||||
|
||||
type XrayTLSDialer struct {
|
||||
dialer internet.Dialer
|
||||
clientFunc tls.CustomClientFunc
|
||||
}
|
||||
|
||||
func NewTLSDialer(dialer internet.Dialer, clientFunc tls.CustomClientFunc) *XrayTLSDialer {
|
||||
return &XrayTLSDialer{dialer, clientFunc}
|
||||
}
|
||||
|
||||
func (d *XrayTLSDialer) DialContext(ctx context.Context, network string, destination M.Socksaddr) (net.Conn, error) {
|
||||
var tlsConfig *gotls.Config
|
||||
conn, err := d.dialer.Dial(tls.ContextWithCustomClient(ctx, func(conn net.Conn, config *gotls.Config) net.Conn {
|
||||
tlsConfig = config
|
||||
return conn
|
||||
}), ToDestination(destination, ToNetwork(network)))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if tlsConfig == nil {
|
||||
return nil, E.New("missing TLS config")
|
||||
}
|
||||
return d.clientFunc(conn, tlsConfig), nil
|
||||
}
|
||||
|
||||
func (d *XrayTLSDialer) ListenPacket(ctx context.Context, destination M.Socksaddr) (net.PacketConn, error) {
|
||||
return nil, os.ErrInvalid
|
||||
}
|
||||
Reference in New Issue
Block a user