crypto/tls: add LocalCertificate to ConnectionState

Adds a new field to ConnectionState, LocalCertificate, which contains
the certificate chain which was presented to the connection peer, if one
was.

Fixes #24673

Change-Id: Iae758fef4a2808e3295324890f4b2f55c71fcc4c
Reviewed-on: https://go-review.googlesource.com/c/go/+/788866
Auto-Submit: Roland Shoemaker <roland@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
TryBot-Bypass: Roland Shoemaker <roland@golang.org>
Reviewed-by: Daniel McCarney <daniel@binaryparadox.net>
This commit is contained in:
yuhan6665
2026-09-10 23:04:52 -04:00
parent b0f1538eb8
commit ed6f4f7375
6 changed files with 23 additions and 0 deletions
+5
View File
@@ -325,6 +325,11 @@ type ConnectionState struct {
// are a server, or if we received a HelloRetryRequest if we are a client.
HelloRetryRequest bool
// LocalCertificate is the certificate chain presented to the peer, if any,
// during the handshake. This field is only populated for connections which
// are not resumed (DidResume is false).
LocalCertificate [][]byte
// ekm is a closure exposed via ExportKeyingMaterial.
ekm func(label string, context []byte, length int) ([]byte, error)
+2
View File
@@ -60,6 +60,7 @@ type Conn struct {
ocspResponse []byte // stapled OCSP response
scts [][]byte // signed certificate timestamps from server
peerCertificates []*x509.Certificate
localCertificate [][]byte
// verifiedChains contains the certificate chains that we built, as
// opposed to the ones presented by the server.
verifiedChains [][]*x509.Certificate
@@ -1690,6 +1691,7 @@ func (c *Conn) connectionStateLocked() ConnectionState {
state.ServerName = c.serverName
state.CipherSuite = c.cipherSuite
state.PeerCertificates = c.peerCertificates
state.LocalCertificate = c.localCertificate
state.VerifiedChains = c.verifiedChains
state.SignedCertificateTimestamps = c.scts
state.OCSPResponse = c.ocspResponse
+4
View File
@@ -730,6 +730,10 @@ func (hs *clientHandshakeState) doFullHandshake() error {
}
}
if chainToSend != nil {
hs.c.localCertificate = chainToSend.Certificate
}
shd, ok := msg.(*serverHelloDoneMsg)
if !ok {
c.sendAlert(alertUnexpectedMessage)
+4
View File
@@ -756,6 +756,10 @@ func (hs *clientHandshakeStateTLS13) sendClientCertificate() error {
return err
}
if cert != nil {
hs.c.localCertificate = cert.Certificate
}
certMsg := new(certificateMsgTLS13)
certMsg.certificate = *cert
+5
View File
@@ -280,6 +280,11 @@ func (hs *serverHandshakeState) processClientHello() error {
}
return err
}
if hs.cert != nil {
hs.c.localCertificate = hs.cert.Certificate
}
if hs.clientHello.scts {
hs.hello.scts = hs.cert.SignedCertificateTimestamps
}
+3
View File
@@ -587,6 +587,9 @@ func (hs *serverHandshakeStateTLS13) pickCertificate() error {
}
return err
}
if certificate != nil {
hs.c.localCertificate = certificate.Certificate
}
hs.sigAlg, err = selectSignatureScheme(c.vers, certificate, hs.clientHello.supportedSignatureAlgorithms)
if err != nil {
// getCertificate returned a certificate that is unsupported or