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

crypto/tls: cache peerCerts across client connections #52202

Closed
moredure opened this issue Apr 7, 2022 · 1 comment
Closed

crypto/tls: cache peerCerts across client connections #52202

moredure opened this issue Apr 7, 2022 · 1 comment

Comments

@moredure
Copy link
Contributor

moredure commented Apr 7, 2022

(client) Is it possible to cache provided certificates certs := make([]*x509.Certificate, len(certificates)) across different connections to the same server ?

// verifyServerCertificate parses and verifies the provided chain, setting
// c.verifiedChains and c.peerCertificates or sending the appropriate alert.
func (c *Conn) verifyServerCertificate(certificates [][]byte) error {
	certs := make([]*x509.Certificate, len(certificates))
	for i, asn1Data := range certificates {
		cert, err := x509.ParseCertificate(asn1Data)
		if err != nil {
			c.sendAlert(alertBadCertificate)
			return errors.New("tls: failed to parse certificate from server: " + err.Error())
		}
		certs[i] = cert
	}
@moredure
Copy link
Contributor Author

moredure commented Apr 7, 2022

Looks like I am not the first with this thing
I just emptied connection PeerCertificates and VerifiedChains with nils after connection and it's good to go -20% in-use memory!

@moredure moredure closed this as completed Apr 7, 2022
@golang golang locked and limited conversation to collaborators Apr 10, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants