mirror of
https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake.git
synced 2025-10-13 20:11:19 -04:00
Represent Bridge Fingerprint As String
This commit is contained in:
parent
dd61e2be0f
commit
f789dce6d2
7 changed files with 69 additions and 21 deletions
30
common/bridgefingerprint/fingerprint.go
Normal file
30
common/bridgefingerprint/fingerprint.go
Normal file
|
@ -0,0 +1,30 @@
|
|||
package bridgefingerprint
|
||||
|
||||
import (
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
)
|
||||
|
||||
type Fingerprint string
|
||||
|
||||
var ErrBridgeFingerprintInvalid = errors.New("bridge fingerprint invalid")
|
||||
|
||||
func FingerprintFromBytes(bytes []byte) (Fingerprint, error) {
|
||||
n := len(bytes)
|
||||
if n != 20 && n != 32 {
|
||||
return Fingerprint(""), ErrBridgeFingerprintInvalid
|
||||
}
|
||||
return Fingerprint(bytes), nil
|
||||
}
|
||||
|
||||
func FingerprintFromHexString(hexString string) (Fingerprint, error) {
|
||||
decoded, err := hex.DecodeString(hexString)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return FingerprintFromBytes(decoded)
|
||||
}
|
||||
|
||||
func (f Fingerprint) ToBytes() []byte {
|
||||
return []byte(f)
|
||||
}
|
|
@ -5,9 +5,9 @@ package messages
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"git.torproject.org/pluggable-transports/snowflake.git/v2/common/bridgefingerprint"
|
||||
|
||||
"git.torproject.org/pluggable-transports/snowflake.git/v2/common/nat"
|
||||
)
|
||||
|
@ -106,7 +106,8 @@ func DecodeClientPollRequest(data []byte) (*ClientPollRequest, error) {
|
|||
if message.Fingerprint == "" {
|
||||
message.Fingerprint = defaultBridgeFingerprint
|
||||
}
|
||||
if hex.DecodedLen(len(message.Fingerprint)) != 20 {
|
||||
|
||||
if _, err := bridgefingerprint.FingerprintFromHexString(message.Fingerprint); err != nil {
|
||||
return nil, fmt.Errorf("cannot decode fingerprint")
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue