Commit 01ac0373 authored by David Fifield's avatar David Fifield
Browse files

Add random padding to the first client→server volley.

This is an experimental workaround for possible TLS-in-DTLS
fingerprinting and throttling in China.

https://github.com/net4people/bbs/issues/255
parent 8e5ea826
Loading
Loading
Loading
Loading
+8 −5
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ The Dial function connects to a Snowflake server:
package snowflake_client

import (
	"bytes"
	"context"
	"errors"
	"log"
@@ -35,6 +36,7 @@ import (
	"strings"
	"time"

	"git.torproject.org/pluggable-transports/snowflake.git/v2/common/encapsulation"
	"git.torproject.org/pluggable-transports/snowflake.git/v2/common/event"
	"git.torproject.org/pluggable-transports/snowflake.git/v2/common/nat"
	"git.torproject.org/pluggable-transports/snowflake.git/v2/common/turbotunnel"
@@ -317,13 +319,14 @@ func newSession(snowflakes SnowflakeCollector) (net.PacketConn, *smux.Session, e
			return nil, errors.New("handler: Received invalid Snowflake")
		}
		log.Println("---- Handler: snowflake assigned ----")
		buf := bytes.NewBuffer(nil)
		// Send the magic Turbo Tunnel token.
		_, err := conn.Write(turbotunnel.Token[:])
		if err != nil {
			return nil, err
		}
		buf.Write(turbotunnel.Token[:])
		// Send ClientID prefix.
		_, err = conn.Write(clientID[:])
		buf.Write(clientID[:])
		// Send some amount of padding.
		encapsulation.WritePadding(buf, int(2000.0 + rand.NormFloat64() * 100.0))
		_, err := conn.Write(buf.Bytes())
		if err != nil {
			return nil, err
		}