Skip to content

Commit

Permalink
update: use VerifyData in RenegotiationInfoExt
Browse files Browse the repository at this point in the history
This make sure the renegotiation would work in certain scenarios instead of no scenarios.

Signed-off-by: Gaukas Wang <i@gaukas.wang>
  • Loading branch information
gaukas committed Apr 10, 2024
1 parent 2a6df0a commit b563ec4
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions u_tls_extensions.go
Original file line number Diff line number Diff line change
Expand Up @@ -1563,27 +1563,27 @@ type RenegotiationInfoExtension struct {
// If this is the initial handshake for a connection, then the
// "renegotiated_connection" field is of zero length in both the
// ClientHello and the ServerHello.
// RenegotiatedConnection []byte
RenegotiatedConnection []byte
}

func (e *RenegotiationInfoExtension) Len() int {
return 5 // + len(e.RenegotiatedConnection)
return 5 + len(e.RenegotiatedConnection)
}

func (e *RenegotiationInfoExtension) Read(b []byte) (int, error) {
if len(b) < e.Len() {
return 0, io.ErrShortBuffer
}

// dataLen := len(e.RenegotiatedConnection)
extBodyLen := 1 // + len(dataLen)
dataLen := len(e.RenegotiatedConnection)
extBodyLen := 1 + dataLen

b[0] = byte(extensionRenegotiationInfo >> 8)
b[1] = byte(extensionRenegotiationInfo & 0xff)
b[2] = byte(extBodyLen >> 8)
b[3] = byte(extBodyLen)
// b[4] = byte(dataLen)
// copy(b[5:], e.RenegotiatedConnection)
b[4] = byte(dataLen)
copy(b[5:], e.RenegotiatedConnection)

return e.Len(), io.EOF
}
Expand All @@ -1593,7 +1593,7 @@ func (e *RenegotiationInfoExtension) UnmarshalJSON(_ []byte) error {
return nil
}

func (e *RenegotiationInfoExtension) Write(_ []byte) (int, error) {
func (e *RenegotiationInfoExtension) Write(b []byte) (int, error) {
e.Renegotiation = RenegotiateOnceAsClient // none empty or other modes are unsupported
// extData := cryptobyte.String(b)
// var renegotiatedConnection cryptobyte.String
Expand All @@ -1602,7 +1602,10 @@ func (e *RenegotiationInfoExtension) Write(_ []byte) (int, error) {
// }
// e.RenegotiatedConnection = make([]byte, len(renegotiatedConnection))
// copy(e.RenegotiatedConnection, renegotiatedConnection)
return 0, nil

// we don't really want to parse it at all.

return len(b), nil
}

func (e *RenegotiationInfoExtension) writeToUConn(uc *UConn) error {
Expand All @@ -1612,6 +1615,10 @@ func (e *RenegotiationInfoExtension) writeToUConn(uc *UConn) error {
fallthrough
case RenegotiateFreelyAsClient:
uc.HandshakeState.Hello.SecureRenegotiationSupported = true
// TODO: don't do backward propagation here
if uc.handshakes > 0 {
e.RenegotiatedConnection = uc.clientFinished[:]
}
case RenegotiateNever:
default:
}
Expand Down

0 comments on commit b563ec4

Please sign in to comment.