Skip to content

Commit

Permalink
Merge pull request #33 from libp2p/expose-pubkey-from-certchain
Browse files Browse the repository at this point in the history
expose the function to derive the peer's public key from the cert chain
  • Loading branch information
marten-seemann committed Aug 1, 2019
2 parents 08736ac + f7ede37 commit cca3e39
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions p2p/security/tls/crypto.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,7 @@ func (i *Identity) ConfigForAny() (*tls.Config, <-chan ic.PubKey) {
//
// It should be used to create a new tls.Config before securing either an
// incoming or outgoing connection.
func (i *Identity) ConfigForPeer(
remote peer.ID,
) (*tls.Config, <-chan ic.PubKey) {
func (i *Identity) ConfigForPeer(remote peer.ID) (*tls.Config, <-chan ic.PubKey) {
keyCh := make(chan ic.PubKey, 1)
// We need to check the peer ID in the VerifyPeerCertificate callback.
// The tls.Config it is also used for listening, and we might also have concurrent dials.
Expand All @@ -90,7 +88,7 @@ func (i *Identity) ConfigForPeer(
chain[i] = cert
}

pubKey, err := getRemotePubKey(chain)
pubKey, err := PubKeyFromCertChain(chain)
if err != nil {
return err
}
Expand All @@ -103,8 +101,8 @@ func (i *Identity) ConfigForPeer(
return conf, keyCh
}

// getRemotePubKey derives the remote's public key from the certificate chain.
func getRemotePubKey(chain []*x509.Certificate) (ic.PubKey, error) {
// PubKeyFromCertChain verifies the certificate chain and extract the remote's public key.
func PubKeyFromCertChain(chain []*x509.Certificate) (ic.PubKey, error) {
if len(chain) != 1 {
return nil, errors.New("expected one certificates in the chain")
}
Expand Down

0 comments on commit cca3e39

Please sign in to comment.