Skip to content

Commit

Permalink
Progress on Retry handling
Browse files Browse the repository at this point in the history
  • Loading branch information
mpiraux committed Apr 28, 2020
1 parent 1c9d0d8 commit af4a2fa
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 deletions.
11 changes: 9 additions & 2 deletions agents/handshake_agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,10 @@ func (a *HandshakeAgent) Run(conn *Connection) {
}
close(conn.ConnectionRestart)
case *RetryPacket:
// TODO: Validate this, https://tools.ietf.org/html/draft-ietf-quic-tls-25#section-5.8
if !a.IgnoreRetry && bytes.Equal(conn.DestinationCID, p.OriginalDestinationCID) && !a.receivedRetry { // TODO: Check the original_connection_id TP too
// TODO: Validate this, https://tools.ietf.org/html/draft-ietf-quic-tls-27#section-5.8
if !a.IgnoreRetry && !a.receivedRetry {
spew.Dump(p)
a.Logger.Println("A Retry packet was received, restarting the connection")
a.receivedRetry = true
conn.DestinationCID = p.Header().(*LongHeader).SourceCID
tlsTP, alpn := conn.TLSTPHandler, conn.ALPN
Expand Down Expand Up @@ -120,6 +122,11 @@ func (a *HandshakeAgent) Run(conn *Connection) {
case i := <-tlsStatus:
s := i.(TLSStatus)
if s.Error != nil {
if s.Completed && a.receivedRetry && !bytes.Equal(conn.TLSTPHandler.ReceivedParameters.OriginalConnectionId, conn.OriginalDestinationCID){
a.Logger.Println("The server include an invalid original_connection_id after sending a Retry")
s.Completed = false
s.Error = errors.New(fmt.Sprint("invalid original_connection_id"))
}
a.HandshakeStatus.Submit(HandshakeStatus{s.Completed, s.Packet, s.Error})
}
tlsCompleted = s.Completed
Expand Down
14 changes: 2 additions & 12 deletions packets.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,26 +270,16 @@ func NewInitialPacket(conn *Connection) *InitialPacket {

type RetryPacket struct {
abstractPacket
OriginalDestinationCID ConnectionID
RetryToken []byte
RetryIntegrityTag [16]byte
}
func ReadRetryPacket(buffer *bytes.Reader, conn *Connection) *RetryPacket {
p := new(RetryPacket)
h := ReadLongHeader(buffer, conn) // TODO: This should not be a full-length long header. Retry header ?
p.header = h
if conn.Version < 0xff000019 {
OCIDL, _ := buffer.ReadByte()
p.OriginalDestinationCID = make([]byte, OCIDL)
buffer.Read(p.OriginalDestinationCID)
p.RetryToken = make([]byte, buffer.Len())
} else {
p.RetryToken = make([]byte, buffer.Len() - len(p.RetryIntegrityTag))
}
p.RetryToken = make([]byte, buffer.Len() - len(p.RetryIntegrityTag))
buffer.Read(p.RetryToken)
if conn.Version >= 0xff000019 {
buffer.Read(p.RetryIntegrityTag[:])
}
buffer.Read(p.RetryIntegrityTag[:])
return p
}
func (p *RetryPacket) GetRetransmittableFrames() []Frame { return nil }
Expand Down

0 comments on commit af4a2fa

Please sign in to comment.