2022-07-06 12:39:44 +08:00
|
|
|
package sniff
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"crypto/tls"
|
|
|
|
"io"
|
|
|
|
|
|
|
|
"github.com/sagernet/sing-box/adapter"
|
|
|
|
C "github.com/sagernet/sing-box/constant"
|
2022-07-08 23:03:57 +08:00
|
|
|
"github.com/sagernet/sing/common/bufio"
|
2022-07-06 12:39:44 +08:00
|
|
|
)
|
|
|
|
|
2024-07-07 15:45:50 +08:00
|
|
|
func TLSClientHello(ctx context.Context, metadata *adapter.InboundContext, reader io.Reader) error {
|
2022-07-06 12:39:44 +08:00
|
|
|
var clientHello *tls.ClientHelloInfo
|
|
|
|
err := tls.Server(bufio.NewReadOnlyConn(reader), &tls.Config{
|
|
|
|
GetConfigForClient: func(argHello *tls.ClientHelloInfo) (*tls.Config, error) {
|
|
|
|
clientHello = argHello
|
|
|
|
return nil, nil
|
|
|
|
},
|
|
|
|
}).HandshakeContext(ctx)
|
|
|
|
if clientHello != nil {
|
2024-07-07 15:45:50 +08:00
|
|
|
metadata.Protocol = C.ProtocolTLS
|
|
|
|
metadata.Domain = clientHello.ServerName
|
|
|
|
return nil
|
2022-07-06 12:39:44 +08:00
|
|
|
}
|
2024-07-07 15:45:50 +08:00
|
|
|
return err
|
2022-07-06 12:39:44 +08:00
|
|
|
}
|