Skip to content

Commit d1bfd25

Browse files
rolandshoemakerpull[bot]
authored andcommitted
crypto/tls,crypto/x509: clarify certificate ownership
Clarify documentation in cases where certificates returned from various methods are not owned by the caller, and as such should not be modified. Change-Id: I06bdc4cf0f686c3d5e8bbb76fc71f2a4bdb955e3 Reviewed-on: https://go-review.googlesource.com/c/go/+/427155 Auto-Submit: Roland Shoemaker <[email protected]> Run-TryBot: Roland Shoemaker <[email protected]> Reviewed-by: Filippo Valsorda <[email protected]> Reviewed-by: Heschi Kreinick <[email protected]> TryBot-Result: Gopher Robot <[email protected]>
1 parent b0785a0 commit d1bfd25

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

src/crypto/tls/common.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,8 @@ type ConnectionState struct {
246246
// On the client side, it can't be empty. On the server side, it can be
247247
// empty if Config.ClientAuth is not RequireAnyClientCert or
248248
// RequireAndVerifyClientCert.
249+
//
250+
// PeerCertificates and its contents should not be modified.
249251
PeerCertificates []*x509.Certificate
250252

251253
// VerifiedChains is a list of one or more chains where the first element is
@@ -255,6 +257,8 @@ type ConnectionState struct {
255257
// On the client side, it's set if Config.InsecureSkipVerify is false. On
256258
// the server side, it's set if Config.ClientAuth is VerifyClientCertIfGiven
257259
// (and the peer provided a certificate) or RequireAndVerifyClientCert.
260+
//
261+
// VerifiedChains and its contents should not be modified.
258262
VerifiedChains [][]*x509.Certificate
259263

260264
// SignedCertificateTimestamps is a list of SCTs provided by the peer
@@ -554,6 +558,8 @@ type Config struct {
554558
// If GetCertificate is nil or returns nil, then the certificate is
555559
// retrieved from NameToCertificate. If NameToCertificate is nil, the
556560
// best element of Certificates will be used.
561+
//
562+
// Once a Certificate is returned it should not be modified.
557563
GetCertificate func(*ClientHelloInfo) (*Certificate, error)
558564

559565
// GetClientCertificate, if not nil, is called when a server requests a
@@ -569,6 +575,8 @@ type Config struct {
569575
//
570576
// GetClientCertificate may be called multiple times for the same
571577
// connection if renegotiation occurs or if TLS 1.3 is in use.
578+
//
579+
// Once a Certificate is returned it should not be modified.
572580
GetClientCertificate func(*CertificateRequestInfo) (*Certificate, error)
573581

574582
// GetConfigForClient, if not nil, is called after a ClientHello is
@@ -597,6 +605,8 @@ type Config struct {
597605
// setting InsecureSkipVerify, or (for a server) when ClientAuth is
598606
// RequestClientCert or RequireAnyClientCert, then this callback will
599607
// be considered but the verifiedChains argument will always be nil.
608+
//
609+
// verifiedChains and its contents should not be modified.
600610
VerifyPeerCertificate func(rawCerts [][]byte, verifiedChains [][]*x509.Certificate) error
601611

602612
// VerifyConnection, if not nil, is called after normal certificate

src/crypto/x509/verify.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -745,6 +745,8 @@ func (c *Certificate) isValid(certType int, currentChain []*Certificate, opts *V
745745
// Certificates that use SHA1WithRSA and ECDSAWithSHA1 signatures are not supported,
746746
// and will not be used to build chains.
747747
//
748+
// Certificates other than c in the returned chains should not be modified.
749+
//
748750
// WARNING: this function doesn't do any revocation checking.
749751
func (c *Certificate) Verify(opts VerifyOptions) (chains [][]*Certificate, err error) {
750752
// Platform-specific verification needs the ASN.1 contents so

0 commit comments

Comments
 (0)