Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: make certificate validation / creation configurable #3213

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

ethan-gallant
Copy link

@ethan-gallant ethan-gallant commented Feb 27, 2025

This enables creation of private LibP2P networks over QUIC. This is beneficial since QUIC does not support pnet #1432 and it also enables unique authentication schemes. It also enables peers to establish a chain of trust with each-other.

@ethan-gallant ethan-gallant marked this pull request as draft February 27, 2025 00:50
Comment on lines -242 to -263
func keyToCertificate(sk ic.PrivKey, certTmpl *x509.Certificate) (*tls.Certificate, error) {
certKey, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
if err != nil {
return nil, err
}

// after calling CreateCertificate, these will end up in Certificate.Extensions
extension, err := GenerateSignedExtension(sk, certKey.Public())
if err != nil {
return nil, err
}
certTmpl.ExtraExtensions = append(certTmpl.ExtraExtensions, extension)

certDER, err := x509.CreateCertificate(rand.Reader, certTmpl, certTmpl, certKey.Public(), certKey)
if err != nil {
return nil, err
}
return &tls.Certificate{
Certificate: [][]byte{certDER},
PrivateKey: certKey,
}, nil
}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This now lives as a part of the DefaultCertManager

@ethan-gallant ethan-gallant changed the title Make Certificate Validation / Creation Configurable feat: make certificate validation / creation configurable Feb 27, 2025
@sukunrt
Copy link
Member

sukunrt commented Feb 27, 2025

Can you explain how it enables Pnet?
Looks like you'll run into this specific problem:
#1432 (comment)

@ethan-gallant
Copy link
Author

Can you explain how it enables Pnet? Looks like you'll run into this specific problem: #1432 (comment)

This doesn't directly implement the Pnet protocol. However it does enable the same use-case of being able to create a private network of LibP2P peers with a pre-shared key.

@ethan-gallant ethan-gallant marked this pull request as ready for review March 11, 2025 01:53
Comment on lines -111 to +110
remotePubKey, err := p2ptls.PubKeyFromCertChain(qconn.ConnectionState().TLS.PeerCertificates)
remotePubKey, err := l.transport.identity.CertManager().VerifyCertChain(qconn.ConnectionState().TLS.PeerCertificates)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MarcoPolo is it the case that the peers identity has already been verified at this point?

e.g. is the authentication done here invalid aside from ensuring an already authenticated peer don't sneakily change its LibP2P identity?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We first calculate the the Peer's ID from the TLS handshake here: https://github.com/libp2p/go-libp2p/blob/master/p2p/transport/quic/transport.go#L288-L292 using the ConfigForPeer function.

This part gets peer's id so we can include it in the returned connection.

We are on the listening side here, so we don't have an expectation of what the peer should be (as opposed to dialing where you expect a certain peer id). We just return the peer id we learn about from the TLS handshake

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants