commit 36b58407a8d8376df2adc6c371d74c09e2b0a417
Author: David Fifield <david(a)bamsoftware.com>
Date: Sat Feb 2 00:04:25 2019 -0700
Have NewUTLSRoundTripper take a *utls.Config.
Plan to use this for testing.
---
meek-client/meek-client.go | 2 +-
meek-client/utls.go | 25 +++++++++++++++++++------
2 files changed, 20 insertions(+), 7 deletions(-)
diff --git a/meek-client/meek-client.go b/meek-client/meek-client.go
index 11c26d2..462eeb3 100644
--- a/meek-client/meek-client.go
+++ b/meek-client/meek-client.go
@@ -323,7 +323,7 @@ func handler(conn *pt.SocksConn) error {
}
info.RoundTripper = helperRoundTripper
} else if utlsOK {
- info.RoundTripper, err = NewUTLSRoundTripper(utlsName)
+ info.RoundTripper, err = NewUTLSRoundTripper(utlsName, nil)
if err != nil {
return err
}
diff --git a/meek-client/utls.go b/meek-client/utls.go
index 832b3d6..bb288f7 100644
--- a/meek-client/utls.go
+++ b/meek-client/utls.go
@@ -94,7 +94,12 @@ func dialUTLS(network, addr string, cfg *utls.Config, clientHelloID *utls.Client
if err != nil {
return nil, err
}
+ serverName, _, err := net.SplitHostPort(addr)
+ if err != nil {
+ return nil, err
+ }
uconn := utls.UClient(conn, cfg, *clientHelloID)
+ uconn.SetSNI(serverName)
err = uconn.Handshake()
if err != nil {
return nil, err
@@ -110,6 +115,7 @@ type UTLSRoundTripper struct {
sync.Mutex
clientHelloID *utls.ClientHelloID
+ config *utls.Config
rt http.RoundTripper
}
@@ -130,7 +136,7 @@ func (rt *UTLSRoundTripper) RoundTrip(req *http.Request) (*http.Response, error)
// On the first call, make an http.Transport or http2.Transport
// as appropriate.
var err error
- rt.rt, err = makeRoundTripper(req, rt.clientHelloID)
+ rt.rt, err = makeRoundTripper(req, rt.clientHelloID, rt.config)
if err != nil {
return nil, err
}
@@ -139,13 +145,19 @@ func (rt *UTLSRoundTripper) RoundTrip(req *http.Request) (*http.Response, error)
return rt.rt.RoundTrip(req)
}
-func makeRoundTripper(req *http.Request, clientHelloID *utls.ClientHelloID) (http.RoundTripper, error) {
+func makeRoundTripper(req *http.Request, clientHelloID *utls.ClientHelloID, cfg *utls.Config) (http.RoundTripper, error) {
addr, err := addrForDial(req.URL)
if err != nil {
return nil, err
}
- cfg := &utls.Config{ServerName: req.URL.Hostname()}
- bootstrapConn, err := dialUTLS("tcp", addr, cfg, clientHelloID)
+
+ // Connect to the given address and initiate a TLS handshake using
+ // the given ClientHelloID. Return the resulting connection.
+ dial := func(network, addr string) (*utls.UConn, error) {
+ return dialUTLS(network, addr, cfg, clientHelloID)
+ }
+
+ bootstrapConn, err := dial("tcp", addr)
if err != nil {
return nil, err
}
@@ -169,7 +181,7 @@ func makeRoundTripper(req *http.Request, clientHelloID *utls.ClientHelloID) (htt
}
// Later dials make a new connection.
- uconn, err := dialUTLS(network, addr, cfg, clientHelloID)
+ uconn, err := dial(network, addr)
if err != nil {
return nil, err
}
@@ -225,7 +237,7 @@ var clientHelloIDMap = map[string]*utls.ClientHelloID{
"helloios_11_1": &utls.HelloIOS_11_1,
}
-func NewUTLSRoundTripper(name string) (http.RoundTripper, error) {
+func NewUTLSRoundTripper(name string, cfg *utls.Config) (http.RoundTripper, error) {
// Lookup is case-insensitive.
clientHelloID, ok := clientHelloIDMap[strings.ToLower(name)]
if !ok {
@@ -237,5 +249,6 @@ func NewUTLSRoundTripper(name string) (http.RoundTripper, error) {
}
return &UTLSRoundTripper{
clientHelloID: clientHelloID,
+ config: cfg,
}, nil
}