Skip to content
This repository has been archived by the owner on Aug 19, 2022. It is now read-only.

Commit

Permalink
improve the error message returned when peer verification fails
Browse files Browse the repository at this point in the history
  • Loading branch information
marten-seemann committed Apr 21, 2020
1 parent 6d5ce18 commit 333f6e0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
6 changes: 5 additions & 1 deletion crypto.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,11 @@ func (i *Identity) ConfigForPeer(remote peer.ID) (*tls.Config, <-chan ic.PubKey)
return err
}
if remote != "" && !remote.MatchesPublicKey(pubKey) {
return errors.New("peer IDs don't match")
peerID, err := peer.IDFromPublicKey(pubKey)
if err != nil {
peerID = peer.ID(fmt.Sprintf("(not determined: %s)", err.Error()))
}
return fmt.Errorf("peer IDs don't match: expected %s, got %s", remote, peerID)
}
keyCh <- pubKey
return nil
Expand Down
3 changes: 2 additions & 1 deletion transport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,8 @@ var _ = Describe("Transport", func() {
}()
// dial, but expect the wrong peer ID
_, err = clientTransport.SecureOutbound(context.Background(), clientInsecureConn, thirdPartyID)
Expect(err).To(MatchError("peer IDs don't match"))
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("peer IDs don't match"))
Eventually(done).Should(BeClosed())
})

Expand Down

0 comments on commit 333f6e0

Please sign in to comment.