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

Export methods to allow generating custom certificates #99

Closed

Conversation

peterargue
Copy link

@peterargue peterargue commented Nov 5, 2021

Closes: libp2p/go-libp2p#1538

This PR refactors keyToCertificate into 3 methods

  • DefaultCertTemplate (exported), which returns the default certificate template used to generate the self-signed certificate,
  • generateSignedExtension, which generates the signed extension
  • keyToCertificate, which accepts an x509.Certificate template, adds the signed extension and returns the tls.Certificate object.

This PR also adds a new optional parameter to NewIdentity, which can provide a custom certificate template.

The changes are intended to be backwards compatible and add the ability for a caller to specify the x509 certificate fields they wish to include in the generated certificate.

@marten-seemann
Copy link
Collaborator

As discussed before, the missing issuer is a separate issue that will be solved by #100. Do I understand correctly that once that PR is merged, you'll only need to expose a single method?

@peterargue
Copy link
Author

yea, we only really need the GenerateSignedExtension method exposed. if needed, we could implement our own custom certificates as long as we could generate the extension.

@peterargue peterargue force-pushed the export-keytocert-and-generateext branch from 059fdbc to 1764007 Compare November 23, 2021 19:58
@peterargue
Copy link
Author

peterargue commented Nov 23, 2021

If you'd prefer not to export the methods, I could refactor this to accept options that optionally set a template. that would avoid exporting any methods and keep the api backwards compatible.
e.g.

func NewIdentity(privKey ic.PrivKey, opts ...IdentityOption) (*Identity, error) {
	config := IdentityConfig{}
	for _, opt := range opts {
		opt(&config)
	}

	var err error
	if config.CertTemplate == nil {
		config.CertTemplate, err = defaultCertTemplate()
		if err != nil {
			return nil, err
		}
	}

	cert, err := keyToCertificate(privKey, config.CertTemplate)
	if err != nil {
		return nil, err
	}

@peterargue peterargue force-pushed the export-keytocert-and-generateext branch from 1764007 to 449626c Compare March 22, 2022 03:44
@peterargue
Copy link
Author

@marten-seemann does this look ok?

@marten-seemann
Copy link
Collaborator

@peterargue We just moved go-libp2p-tls into go-libp2p (libp2p/go-libp2p#1466). Could you re-target this PR to go-libp2p please? Sorry for the inconvenience!

@peterargue
Copy link
Author

for sure. no problem

@MarcoPolo
Copy link

Closing this as it's handled already in libp2p/go-libp2p#1481

@MarcoPolo MarcoPolo closed this Aug 19, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

tls: allow generating TLS key pairs for use outside of libp2p
3 participants