Skip to content

Sync with upstream: Go 1.19.6 (no new change in 1.19.7) #172

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

Merged
merged 4 commits into from
Mar 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cipher_suites.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
"crypto/cipher"
"crypto/des"
"crypto/hmac"

// "crypto/internal/boring"
"crypto/rc4"
"crypto/sha1"
"crypto/sha256"
Expand Down
3 changes: 1 addition & 2 deletions common.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ const (
extensionCertificateAuthorities uint16 = 47
extensionSignatureAlgorithmsCert uint16 = 50
extensionKeyShare uint16 = 51
extensionNextProtoNeg uint16 = 13172 // not IANA assigned // Pending discussion on whether or not remove this. crypto/tls removed it on Nov 21, 2019.
extensionRenegotiationInfo uint16 = 0xff01
)

Expand Down Expand Up @@ -1405,7 +1404,7 @@ func (c *Certificate) leaf() (*x509.Certificate, error) {
}

type handshakeMessage interface {
marshal() []byte
marshal() ([]byte, error)
unmarshal([]byte) bool
}

Expand Down
47 changes: 37 additions & 10 deletions conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -1007,18 +1007,37 @@ func (c *Conn) writeRecordLocked(typ recordType, data []byte) (int, error) {
return n, nil
}

// writeRecord writes a TLS record with the given type and payload to the
// connection and updates the record layer state.
func (c *Conn) writeRecord(typ recordType, data []byte) (int, error) {
// writeHandshakeRecord writes a handshake message to the connection and updates
// the record layer state. If transcript is non-nil the marshalled message is
// written to it.
func (c *Conn) writeHandshakeRecord(msg handshakeMessage, transcript transcriptHash) (int, error) {
c.out.Lock()
defer c.out.Unlock()

return c.writeRecordLocked(typ, data)
data, err := msg.marshal()
if err != nil {
return 0, err
}
if transcript != nil {
transcript.Write(data)
}

return c.writeRecordLocked(recordTypeHandshake, data)
}

// writeChangeCipherRecord writes a ChangeCipherSpec message to the connection and
// updates the record layer state.
func (c *Conn) writeChangeCipherRecord() error {
c.out.Lock()
defer c.out.Unlock()
_, err := c.writeRecordLocked(recordTypeChangeCipherSpec, []byte{1})
return err
}

// readHandshake reads the next handshake message from
// the record layer.
func (c *Conn) readHandshake() (any, error) {
// the record layer. If transcript is non-nil, the message
// is written to the passed transcriptHash.
func (c *Conn) readHandshake(transcript transcriptHash) (any, error) {
for c.hand.Len() < 4 {
if err := c.readRecord(); err != nil {
return nil, err
Expand Down Expand Up @@ -1106,6 +1125,11 @@ func (c *Conn) readHandshake() (any, error) {
if !m.unmarshal(data) {
return nil, c.in.setErrorLocked(c.sendAlert(alertUnexpectedMessage))
}

if transcript != nil {
transcript.Write(data)
}

return m, nil
}

Expand Down Expand Up @@ -1181,7 +1205,7 @@ func (c *Conn) handleRenegotiation() error {
return errors.New("tls: internal error: unexpected renegotiation")
}

msg, err := c.readHandshake()
msg, err := c.readHandshake(nil)
if err != nil {
return err
}
Expand Down Expand Up @@ -1227,7 +1251,7 @@ func (c *Conn) handlePostHandshakeMessage() error {
return c.handleRenegotiation()
}

msg, err := c.readHandshake()
msg, err := c.readHandshake(nil)
if err != nil {
return err
}
Expand Down Expand Up @@ -1263,7 +1287,11 @@ func (c *Conn) handleKeyUpdate(keyUpdate *keyUpdateMsg) error {
defer c.out.Unlock()

msg := &keyUpdateMsg{}
_, err := c.writeRecordLocked(recordTypeHandshake, msg.marshal())
msgBytes, err := msg.marshal()
if err != nil {
return err
}
_, err = c.writeRecordLocked(recordTypeHandshake, msgBytes)
if err != nil {
// Surface the error at the next write.
c.out.setErrorLocked(err)
Expand Down Expand Up @@ -1523,7 +1551,6 @@ func (c *Conn) connectionStateLocked() ConnectionState {
} else {
state.ekm = c.ekm
}

return state
}

Expand Down
Loading