Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
mf
go-multiaddr
Commits
75a10eef
Commit
75a10eef
authored
Aug 29, 2015
by
Leif Ryge
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
more strict validation of .onion addresses
parent
ed310561
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
8 additions
and
3 deletions
+8
-3
codec.go
codec.go
+6
-3
multiaddr_test.go
multiaddr_test.go
+2
-0
No files found.
codec.go
View file @
75a10eef
...
...
@@ -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
...
...
multiaddr_test.go
View file @
75a10eef
...
...
@@ -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"
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment