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

Commit 46e9e9f

Browse files
Merge pull request #33 from libp2p/expose-pubkey-from-certchain
expose the function to derive the peer's public key from the cert chain
2 parents cc53c4f + 71f35a4 commit 46e9e9f

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

crypto.go

+4-6
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,7 @@ func (i *Identity) ConfigForAny() (*tls.Config, <-chan ic.PubKey) {
6868
//
6969
// It should be used to create a new tls.Config before securing either an
7070
// incoming or outgoing connection.
71-
func (i *Identity) ConfigForPeer(
72-
remote peer.ID,
73-
) (*tls.Config, <-chan ic.PubKey) {
71+
func (i *Identity) ConfigForPeer(remote peer.ID) (*tls.Config, <-chan ic.PubKey) {
7472
keyCh := make(chan ic.PubKey, 1)
7573
// We need to check the peer ID in the VerifyPeerCertificate callback.
7674
// The tls.Config it is also used for listening, and we might also have concurrent dials.
@@ -90,7 +88,7 @@ func (i *Identity) ConfigForPeer(
9088
chain[i] = cert
9189
}
9290

93-
pubKey, err := getRemotePubKey(chain)
91+
pubKey, err := PubKeyFromCertChain(chain)
9492
if err != nil {
9593
return err
9694
}
@@ -103,8 +101,8 @@ func (i *Identity) ConfigForPeer(
103101
return conf, keyCh
104102
}
105103

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

0 commit comments

Comments
 (0)