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

Commit 71f35a4

Browse files
expose the function to derive the peer's public key from the cert chain
1 parent b3618ca commit 71f35a4

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
@@ -66,9 +66,7 @@ func (i *Identity) ConfigForAny() (*tls.Config, <-chan ic.PubKey) {
6666
//
6767
// It should be used to create a new tls.Config before securing either an
6868
// incoming or outgoing connection.
69-
func (i *Identity) ConfigForPeer(
70-
remote peer.ID,
71-
) (*tls.Config, <-chan ic.PubKey) {
69+
func (i *Identity) ConfigForPeer(remote peer.ID) (*tls.Config, <-chan ic.PubKey) {
7270
keyCh := make(chan ic.PubKey, 1)
7371
// We need to check the peer ID in the VerifyPeerCertificate callback.
7472
// The tls.Config it is also used for listening, and we might also have concurrent dials.
@@ -88,7 +86,7 @@ func (i *Identity) ConfigForPeer(
8886
chain[i] = cert
8987
}
9088

91-
pubKey, err := getRemotePubKey(chain)
89+
pubKey, err := PubKeyFromCertChain(chain)
9290
if err != nil {
9391
return err
9492
}
@@ -101,8 +99,8 @@ func (i *Identity) ConfigForPeer(
10199
return conf, keyCh
102100
}
103101

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

0 commit comments

Comments
 (0)