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

[tor-commits] [pluggable-transports/snowflake] branch main updated: Represent fingerprint internally as byte array



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

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

The following commit(s) were added to refs/heads/main by this push:
     new 2f89fbc  Represent fingerprint internally as byte array
2f89fbc is described below

commit 2f89fbc2ed3e25d2b4be76edc600cca37de91864
Author: Arlo Breault <arlolra@xxxxxxxxx>
AuthorDate: Thu Mar 17 10:46:37 2022 -0400

    Represent fingerprint internally as byte array
---
 broker/broker.go                 |  2 +-
 broker/ipc.go                    | 12 +++++++++---
 common/messages/client.go        |  4 ++++
 common/messages/messages_test.go |  6 ++++++
 4 files changed, 20 insertions(+), 4 deletions(-)

diff --git a/broker/broker.go b/broker/broker.go
index 6e85fbd..10129d7 100644
--- a/broker/broker.go
+++ b/broker/broker.go
@@ -143,7 +143,7 @@ func (ctx *BrokerContext) AddSnowflake(id string, proxyType string, natType stri
 type ClientOffer struct {
 	natType     string
 	sdp         []byte
-	fingerprint string
+	fingerprint [20]byte
 }
 
 func main() {
diff --git a/broker/ipc.go b/broker/ipc.go
index 2ef4ccd..e11a33c 100644
--- a/broker/ipc.go
+++ b/broker/ipc.go
@@ -2,6 +2,7 @@ package main
 
 import (
 	"container/heap"
+	"encoding/hex"
 	"fmt"
 	"log"
 	"net"
@@ -130,11 +131,16 @@ func (i *IPC) ClientOffers(arg messages.Arg, response *[]byte) error {
 	}
 
 	offer := &ClientOffer{
-		natType:     req.NAT,
-		sdp:         []byte(req.Offer),
-		fingerprint: req.Fingerprint,
+		natType: req.NAT,
+		sdp:     []byte(req.Offer),
 	}
 
+	fingerprint, err := hex.DecodeString(req.Fingerprint)
+	if err != nil {
+		return sendClientResponse(&messages.ClientPollResponse{Error: err.Error()}, response)
+	}
+	copy(offer.fingerprint[:], fingerprint)
+
 	// Only hand out known restricted snowflakes to unrestricted clients
 	var snowflakeHeap *SnowflakeHeap
 	if offer.natType == NATUnrestricted {
diff --git a/common/messages/client.go b/common/messages/client.go
index 4d435ab..96f8ed8 100644
--- a/common/messages/client.go
+++ b/common/messages/client.go
@@ -5,6 +5,7 @@ package messages
 
 import (
 	"bytes"
+	"encoding/hex"
 	"encoding/json"
 	"fmt"
 
@@ -105,6 +106,9 @@ func DecodeClientPollRequest(data []byte) (*ClientPollRequest, error) {
 	if message.Fingerprint == "" {
 		message.Fingerprint = defaultBridgeFingerprint
 	}
+	if hex.DecodedLen(len(message.Fingerprint)) != 20 {
+		return nil, fmt.Errorf("cannot decode fingerprint")
+	}
 
 	switch message.NAT {
 	case "":
diff --git a/common/messages/messages_test.go b/common/messages/messages_test.go
index 5365aa8..dd1f4fb 100644
--- a/common/messages/messages_test.go
+++ b/common/messages/messages_test.go
@@ -344,6 +344,12 @@ func TestEncodeClientPollRequests(t *testing.T) {
 				defaultBridgeFingerprint,
 				nil,
 			},
+			{
+				"unknown",
+				"fake",
+				"123123",
+				fmt.Errorf(""),
+			},
 		} {
 			req1 := &ClientPollRequest{
 				NAT:         test.natType,

-- 
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