2023-03-14 13:33:24 +08:00
|
|
|
package restls
|
|
|
|
|
|
|
|
import (
|
2023-03-14 16:50:27 +08:00
|
|
|
"context"
|
2023-03-14 13:33:24 +08:00
|
|
|
"net"
|
|
|
|
|
|
|
|
tls "github.com/3andne/restls-client-go"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
Mode string = "restls"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Restls struct {
|
2023-03-14 16:50:27 +08:00
|
|
|
*tls.UConn
|
2023-03-14 13:33:24 +08:00
|
|
|
}
|
|
|
|
|
2023-03-14 16:50:27 +08:00
|
|
|
func (r *Restls) Upstream() any {
|
|
|
|
return r.UConn.NetConn()
|
2023-03-14 13:33:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewRestls return a Restls Connection
|
2023-03-14 16:50:27 +08:00
|
|
|
func NewRestls(ctx context.Context, conn net.Conn, config *tls.Config) (net.Conn, error) {
|
|
|
|
clientHellowID := tls.HelloChrome_Auto
|
2023-03-14 13:33:24 +08:00
|
|
|
if config != nil {
|
|
|
|
clientIDPtr := config.ClientID.Load()
|
|
|
|
if clientIDPtr != nil {
|
2023-03-14 16:50:27 +08:00
|
|
|
clientHellowID = *clientIDPtr
|
2023-03-14 13:33:24 +08:00
|
|
|
}
|
|
|
|
}
|
2023-03-14 16:50:27 +08:00
|
|
|
restls := &Restls{
|
|
|
|
UConn: tls.UClient(conn, config, clientHellowID),
|
|
|
|
}
|
|
|
|
if err := restls.HandshakeContext(ctx); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return restls, nil
|
2023-03-14 13:33:24 +08:00
|
|
|
}
|