Skip to content

Commit db19e64

Browse files
validate that certhashes are valid multihashes
1 parent 494efd0 commit db19e64

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

multiaddr_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ func TestConstructFails(t *testing.T) {
7575
"/ip4/127.0.0.1/tcp",
7676
"/ip4/127.0.0.1/quic/1234",
7777
"/ip4/127.0.0.1/udp/1234/quic/webtransport/certhash",
78+
"/ip4/127.0.0.1/udp/1234/quic/webtransport/certhash/b2uaraocy6yrdblb4sfptaddgimjmmp", // 1 character missing from certhash
7879
"/ip4/127.0.0.1/ipfs",
7980
"/ip4/127.0.0.1/ipfs/tcp",
8081
"/ip4/127.0.0.1/p2p",
@@ -159,8 +160,8 @@ func TestConstructSucceeds(t *testing.T) {
159160
"/ip4/127.0.0.1/tcp/1234/",
160161
"/ip4/127.0.0.1/udp/1234/quic",
161162
"/ip4/127.0.0.1/udp/1234/quic/webtransport",
162-
"/ip4/127.0.0.1/udp/1234/quic/webtransport/certhash/zt1Zv2yaZ",
163-
"/ip4/127.0.0.1/udp/1234/quic/webtransport/certhash/zt1Zv2yaZ/certhash/zt1Zv2yaY",
163+
"/ip4/127.0.0.1/udp/1234/quic/webtransport/certhash/b2uaraocy6yrdblb4sfptaddgimjmmpy",
164+
"/ip4/127.0.0.1/udp/1234/quic/webtransport/certhash/b2uaraocy6yrdblb4sfptaddgimjmmpy/certhash/zQmbWTwYGcmdyK9CYfNBcfs9nhZs17a6FQ4Y8oea278xx41",
164165
"/ip4/127.0.0.1/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC",
165166
"/ip4/127.0.0.1/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC/tcp/1234",
166167
"/ip4/127.0.0.1/ipfs/k2k4r8oqamigqdo6o7hsbfwd45y70oyynp98usk7zmyfrzpqxh1pohl7",
@@ -546,8 +547,7 @@ func TestRoundTrip(t *testing.T) {
546547
"/ip4/127.0.0.1/tcp/123/tls",
547548
"/ip4/127.0.0.1/udp/123",
548549
"/ip4/127.0.0.1/udp/123/ip6/::",
549-
"/ip4/127.0.0.1/udp/1234/quic/webtransport/certhash/zt1Zv2yaZ",
550-
"/ip4/127.0.0.1/udp/1234/quic/webtransport/certhash/zt1Zv2yaZ/certhash/zt1Zv2yaY",
550+
"/ip4/127.0.0.1/udp/1234/quic/webtransport/certhash/zQmbWTwYGcmdyK9CYfNBcfs9nhZs17a6FQ4Y8oea278xx41",
551551
"/p2p/QmbHVEEepCi7rn7VL7Exxpd2Ci9NNB6ifvqwhsrbRMgQFP",
552552
"/p2p/QmbHVEEepCi7rn7VL7Exxpd2Ci9NNB6ifvqwhsrbRMgQFP/unix/a/b/c",
553553
} {

transcoders.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,13 @@ var TranscoderCertHash = NewTranscoderFromFunctions(certHashStB, certHashBtS, ni
379379

380380
func certHashStB(s string) ([]byte, error) {
381381
_, data, err := multibase.Decode(s)
382-
return data, err
382+
if err != nil {
383+
return nil, err
384+
}
385+
if _, err := mh.Decode(data); err != nil {
386+
return nil, err
387+
}
388+
return data, nil
383389
}
384390

385391
func certHashBtS(b []byte) (string, error) {

0 commit comments

Comments
 (0)