mirror of
https://github.com/XTLS/REALITY.git
synced 2026-09-27 09:28:06 +03:00
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:
@@ -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)
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user