Skip to content

Commit

Permalink
check values
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcoPolo committed Jan 23, 2025
1 parent ac80c8a commit 5f86c11
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
6 changes: 3 additions & 3 deletions p2p/transport/webtransport/crypto.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ func generateCert(key ic.PrivKey, start, end time.Time) (*x509.Certificate, *ecd
}

type ErrCertHashMismatch struct {
Expected [][]byte
Actual []byte
Expected []byte
Actual [][]byte
}

func (e ErrCertHashMismatch) Error() string {
Expand All @@ -114,7 +114,7 @@ func verifyRawCerts(rawCerts [][]byte, certHashes []multihash.DecodedMultihash)
for _, h := range certHashes {
digests = append(digests, h.Digest)
}
return ErrCertHashMismatch{Expected: digests, Actual: hash[:]}
return ErrCertHashMismatch{Expected: hash[:], Actual: digests}
}

cert, err := x509.ParseCertificate(leaf)
Expand Down
6 changes: 5 additions & 1 deletion p2p/transport/webtransport/transport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,11 @@ func TestHashVerification(t *testing.T) {
var trErr *quic.TransportError
require.ErrorAs(t, err, &trErr)
require.Equal(t, quic.TransportErrorCode(0x12a), trErr.ErrorCode)
require.ErrorContains(t, trErr, "cert hash not found")
var errMismatchHash libp2pwebtransport.ErrCertHashMismatch
require.ErrorAs(t, err, &errMismatchHash)

e := sha256.Sum256([]byte("foobar"))
require.EqualValues(t, e[:], errMismatchHash.Actual[0])
})

t.Run("fails when adding a wrong hash", func(t *testing.T) {
Expand Down

0 comments on commit 5f86c11

Please sign in to comment.