mirror of
https://github.com/logos-messaging/go-multiaddr.git
synced 2026-01-03 21:43:06 +00:00
more strict validation of .onion addresses
This commit is contained in:
parent
ed310561bd
commit
75a10eef9b
9
codec.go
9
codec.go
@ -168,12 +168,15 @@ func addressStringToBytes(p Protocol, s string) ([]byte, error) {
|
||||
|
||||
case P_TOR:
|
||||
fields := strings.Split(s, ".onion")
|
||||
if len(fields) != 2 {
|
||||
return nil, fmt.Errorf("failed to parse ipfs addr: %s not a Tor .onion address.", s)
|
||||
if len(fields) != 2 || len(fields[1]) != 0 {
|
||||
return nil, fmt.Errorf("failed to parse tor addr: %s does not end with .onion", s)
|
||||
}
|
||||
b, err := base32.StdEncoding.DecodeString(strings.ToUpper(fields[0]))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to parse ipfs addr: %s %s", s, err)
|
||||
return nil, fmt.Errorf("failed to parse tor addr: %s %s", s, err)
|
||||
}
|
||||
if len(b) != 10 {
|
||||
return nil, fmt.Errorf("failed to parse tor addr: %s decoded to %s bytes, expected 10", s, len(b))
|
||||
}
|
||||
return b, nil
|
||||
case P_IPFS: // ipfs
|
||||
|
||||
@ -27,6 +27,8 @@ func TestConstructFails(t *testing.T) {
|
||||
"/tcp/65536",
|
||||
"/tor/9imaq4ygg2iegci7.onion",
|
||||
"/tor/aaimaq4ygg2iegci7.onion",
|
||||
"/tor/timaq4ygg2iegci7.onionxxx",
|
||||
"/tor/timaq4yg.onion",
|
||||
"/udp/1234/sctp",
|
||||
"/udp/1234/udt/1234",
|
||||
"/udp/1234/utp/1234",
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user