[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [pluggable-transports/snowflake] 05/13: Add utls imitate setting to snowflake client



This is an automated email from the git hooks/post-receive script.

shelikhoo pushed a commit to branch main
in repository pluggable-transports/snowflake.

commit 9af0ad119b8b0f129f015c5347fe5a3b03596ff0
Author: Shelikhoo <xiaokangwang@xxxxxxxxxxx>
AuthorDate: Thu Feb 10 17:04:42 2022 +0000

    Add utls imitate setting to snowflake client
---
 client/lib/rendezvous.go | 27 +++++++++++++++++++++++----
 client/lib/snowflake.go  |  3 +++
 client/snowflake.go      |  2 ++
 3 files changed, 28 insertions(+), 4 deletions(-)

diff --git a/client/lib/rendezvous.go b/client/lib/rendezvous.go
index 98cd4d6..4c7c6f9 100644
--- a/client/lib/rendezvous.go
+++ b/client/lib/rendezvous.go
@@ -5,6 +5,8 @@ package snowflake_client
 
 import (
 	"errors"
+	"fmt"
+
 	"log"
 	"net/http"
 	"sync"
@@ -14,7 +16,9 @@ import (
 	"git.torproject.org/pluggable-transports/snowflake.git/v2/common/messages"
 	"git.torproject.org/pluggable-transports/snowflake.git/v2/common/nat"
 	"git.torproject.org/pluggable-transports/snowflake.git/v2/common/util"
+	utlsutil "git.torproject.org/pluggable-transports/snowflake.git/v2/common/utls"
 	"github.com/pion/webrtc/v3"
+	utls "github.com/refraction-networking/utls"
 )
 
 const (
@@ -51,10 +55,14 @@ func createBrokerTransport() http.RoundTripper {
 	return transport
 }
 
-// NewBrokerChannel construct a new BrokerChannel, where:
+func NewBrokerChannel(broker, ampCache, front string, keepLocalAddresses bool) (*BrokerChannel, error) {
+	return NewBrokerChannelWithUTlsClientID(broker, ampCache, front, keepLocalAddresses, "")
+}
+
+// NewBrokerChannelWithUTlsClientID construct a new BrokerChannel, where:
 // |broker| is the full URL of the facilitating program which assigns proxies
 // to clients, and |front| is the option fronting domain.
-func NewBrokerChannel(broker, ampCache, front string, keepLocalAddresses bool) (*BrokerChannel, error) {
+func NewBrokerChannelWithUTlsClientID(broker, ampCache, front string, keepLocalAddresses bool, utlsClientID string) (*BrokerChannel, error) {
 	log.Println("Rendezvous using Broker at:", broker)
 	if ampCache != "" {
 		log.Println("Through AMP cache at:", ampCache)
@@ -63,12 +71,23 @@ func NewBrokerChannel(broker, ampCache, front string, keepLocalAddresses bool) (
 		log.Println("Domain fronting using:", front)
 	}
 
+	brokerTransport := createBrokerTransport()
+
+	if utlsClientID != "" {
+		utlsClientHelloID, err := utlsutil.NameToUTlsID(utlsClientID)
+		if err != nil {
+			return nil, fmt.Errorf("unable to create broker channel: %v", err)
+		}
+		config := &utls.Config{}
+		brokerTransport = utlsutil.NewUTLSHTTPRoundTripper(utlsClientHelloID, config, brokerTransport, false)
+	}
+
 	var rendezvous RendezvousMethod
 	var err error
 	if ampCache != "" {
-		rendezvous, err = newAMPCacheRendezvous(broker, ampCache, front, createBrokerTransport())
+		rendezvous, err = newAMPCacheRendezvous(broker, ampCache, front, brokerTransport)
 	} else {
-		rendezvous, err = newHTTPRendezvous(broker, front, createBrokerTransport())
+		rendezvous, err = newHTTPRendezvous(broker, front, brokerTransport)
 	}
 	if err != nil {
 		return nil, err
diff --git a/client/lib/snowflake.go b/client/lib/snowflake.go
index 594c62c..19442d8 100644
--- a/client/lib/snowflake.go
+++ b/client/lib/snowflake.go
@@ -97,6 +97,9 @@ type ClientConfig struct {
 	// Max is the maximum number of snowflake proxy peers that the client should attempt to
 	// connect to. Defaults to 1.
 	Max int
+	// UTlsClientID is the type of user application that snowflake should imitate.
+	// If an empty value is provided, it will use Go's default TLS implementation
+	UTlsClientID string
 }
 
 // NewSnowflakeClient creates a new Snowflake transport client that can spawn multiple
diff --git a/client/snowflake.go b/client/snowflake.go
index 5a00206..addedb9 100644
--- a/client/snowflake.go
+++ b/client/snowflake.go
@@ -126,6 +126,7 @@ func main() {
 	frontDomain := flag.String("front", "", "front domain")
 	ampCacheURL := flag.String("ampcache", "", "URL of AMP cache to use as a proxy for signaling")
 	logFilename := flag.String("log", "", "name of log file")
+	utlsClientHelloID := flag.String("utls-imitate", "", "type of TLS client to imitate with utls")
 	logToStateDir := flag.Bool("log-to-state-dir", false, "resolve the log file relative to tor's pt state dir")
 	keepLocalAddresses := flag.Bool("keep-local-addresses", false, "keep local LAN address ICE candidates")
 	unsafeLogging := flag.Bool("unsafe-logging", false, "prevent logs from being scrubbed")
@@ -178,6 +179,7 @@ func main() {
 		ICEAddresses:       iceAddresses,
 		KeepLocalAddresses: *keepLocalAddresses || *oldKeepLocalAddresses,
 		Max:                *max,
+		UTlsClientID:       *utlsClientHelloID,
 	}
 
 	// Begin goptlib client process.

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits