mirror of
https://github.com/SagerNet/sing-box.git
synced 2024-12-27 03:25:38 +08:00
89c723e3e4
Refactor Authenticator interface to struct & Update smux & Update gVisor to 20231204.0 & Update quic-go to v0.40.1 & Update wireguard-go & Add GSO support for TUN/WireGuard & Fix router pre-start & Fix bind forwarder to interface for systems stack
43 lines
1.1 KiB
Go
43 lines
1.1 KiB
Go
package tls
|
|
|
|
import (
|
|
"context"
|
|
"net"
|
|
"os"
|
|
|
|
"github.com/sagernet/sing-box/common/badtls"
|
|
C "github.com/sagernet/sing-box/constant"
|
|
"github.com/sagernet/sing-box/log"
|
|
"github.com/sagernet/sing-box/option"
|
|
aTLS "github.com/sagernet/sing/common/tls"
|
|
)
|
|
|
|
func NewServer(ctx context.Context, logger log.Logger, options option.InboundTLSOptions) (ServerConfig, error) {
|
|
if !options.Enabled {
|
|
return nil, nil
|
|
}
|
|
if options.ECH != nil && options.ECH.Enabled {
|
|
return NewECHServer(ctx, logger, options)
|
|
} else if options.Reality != nil && options.Reality.Enabled {
|
|
return NewRealityServer(ctx, logger, options)
|
|
} else {
|
|
return NewSTDServer(ctx, logger, options)
|
|
}
|
|
}
|
|
|
|
func ServerHandshake(ctx context.Context, conn net.Conn, config ServerConfig) (Conn, error) {
|
|
ctx, cancel := context.WithTimeout(ctx, C.TCPTimeout)
|
|
defer cancel()
|
|
tlsConn, err := aTLS.ServerHandshake(ctx, conn, config)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
readWaitConn, err := badtls.NewReadWaitConn(tlsConn)
|
|
if err == nil {
|
|
return readWaitConn, nil
|
|
} else if err != os.ErrInvalid {
|
|
return nil, err
|
|
}
|
|
return tlsConn, nil
|
|
}
|