Unverified Commit 46e9e9f9 authored by Marten Seemann's avatar Marten Seemann Committed by GitHub

Merge pull request #33 from libp2p/expose-pubkey-from-certchain

expose the function to derive the peer's public key from the cert chain
parents cc53c4f8 71f35a4b
Pipeline #648 failed with stages
in 0 seconds
...@@ -68,9 +68,7 @@ func (i *Identity) ConfigForAny() (*tls.Config, <-chan ic.PubKey) { ...@@ -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 // It should be used to create a new tls.Config before securing either an
// incoming or outgoing connection. // incoming or outgoing connection.
func (i *Identity) ConfigForPeer( func (i *Identity) ConfigForPeer(remote peer.ID) (*tls.Config, <-chan ic.PubKey) {
remote peer.ID,
) (*tls.Config, <-chan ic.PubKey) {
keyCh := make(chan ic.PubKey, 1) keyCh := make(chan ic.PubKey, 1)
// We need to check the peer ID in the VerifyPeerCertificate callback. // 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. // The tls.Config it is also used for listening, and we might also have concurrent dials.
...@@ -90,7 +88,7 @@ func (i *Identity) ConfigForPeer( ...@@ -90,7 +88,7 @@ func (i *Identity) ConfigForPeer(
chain[i] = cert chain[i] = cert
} }
pubKey, err := getRemotePubKey(chain) pubKey, err := PubKeyFromCertChain(chain)
if err != nil { if err != nil {
return err return err
} }
...@@ -103,8 +101,8 @@ func (i *Identity) ConfigForPeer( ...@@ -103,8 +101,8 @@ func (i *Identity) ConfigForPeer(
return conf, keyCh return conf, keyCh
} }
// getRemotePubKey derives the remote's public key from the certificate chain. // PubKeyFromCertChain verifies the certificate chain and extract the remote's public key.
func getRemotePubKey(chain []*x509.Certificate) (ic.PubKey, error) { func PubKeyFromCertChain(chain []*x509.Certificate) (ic.PubKey, error) {
if len(chain) != 1 { if len(chain) != 1 {
return nil, errors.New("expected one certificates in the chain") return nil, errors.New("expected one certificates in the chain")
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment