diff --git a/client/lib/webrtc.go b/client/lib/webrtc.go index bca262d..7af1186 100644 --- a/client/lib/webrtc.go +++ b/client/lib/webrtc.go @@ -4,7 +4,7 @@ import ( "crypto/rand" "encoding/hex" "errors" - "fmt" + "gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/v2/common/messages" "io" "log" "net" @@ -318,7 +318,12 @@ func (c *WebRTCPeer) preparePeerConnection( } ordered := false var maxRetransmission uint16 = 0 - protocol := fmt.Sprintf("%s", c.clientID.String()) + connectionMetadata := messages.ClientConnectionMetadata{ClientID: c.clientID[:]} + encodedMetadata, err := connectionMetadata.EncodeConnectionMetadata() + if err != nil { + return err + } + protocol := encodedMetadata dataChannelOptions := &webrtc.DataChannelInit{ Ordered: &ordered, Protocol: &protocol, diff --git a/common/messages/client.go b/common/messages/client.go index 9e7a235..5d1f0d6 100644 --- a/common/messages/client.go +++ b/common/messages/client.go @@ -152,7 +152,7 @@ func DecodeClientPollResponse(data []byte) (*ClientPollResponse, error) { } type ClientConnectionMetadata struct { - ClientID string `json:"client_id"` + ClientID []byte `json:"client_id"` } func (meta *ClientConnectionMetadata) EncodeConnectionMetadata() (string, error) { diff --git a/server/lib/http.go b/server/lib/http.go index 0d2e820..6da2d0f 100644 --- a/server/lib/http.go +++ b/server/lib/http.go @@ -5,8 +5,7 @@ import ( "crypto/rand" "crypto/sha256" "encoding/binary" - "encoding/hex" - "fmt" + "gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/v2/common/messages" "io" "log" "net" @@ -120,10 +119,11 @@ func (handler *httpHandler) turboTunnelUDPLikeMode(conn net.Conn, addr net.Addr, // packet received on this WebSocket connection pertains to the same // ClientID. clientID := turbotunnel.ClientID{} - _, err := hex.Decode(clientID[:], []byte(protocol)) + metaData, err := messages.DecodeConnectionMetadata(protocol) if err != nil { - return fmt.Errorf("reading ClientID: %w", err) + return err } + copy(clientID[:], metaData.ClientID[:]) // Store a short-term mapping from the ClientID to the client IP // address attached to this WebSocket connection. tor will want us to