mirror of
https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake.git
synced 2025-10-13 11:11:30 -04:00
Represent fingerprint internally as byte array
This commit is contained in:
parent
fa2f6824d9
commit
2f89fbc2ed
4 changed files with 20 additions and 4 deletions
|
@ -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() {
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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 "":
|
||||
|
|
|
@ -344,6 +344,12 @@ func TestEncodeClientPollRequests(t *testing.T) {
|
|||
defaultBridgeFingerprint,
|
||||
nil,
|
||||
},
|
||||
{
|
||||
"unknown",
|
||||
"fake",
|
||||
"123123",
|
||||
fmt.Errorf(""),
|
||||
},
|
||||
} {
|
||||
req1 := &ClientPollRequest{
|
||||
NAT: test.natType,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue