parse the max_packet_size in the TLS transport parameters

This commit is contained in:
Marten Seemann
2018-03-10 14:14:09 +07:00
parent 6a2c4548f7
commit 0f401b0b37
2 changed files with 25 additions and 0 deletions

View File

@@ -132,6 +132,7 @@ var _ = Describe("Transport Parameters", func() {
initialMaxStreamIDBiDiParameterID: {0x33, 0x44, 0x55, 0x66},
initialMaxStreamIDUniParameterID: {0x44, 0x55, 0x66, 0x77},
idleTimeoutParameterID: {0x13, 0x37},
maxPacketSizeParameterID: {0x73, 0x31},
}
})
It("reads parameters", func() {
@@ -143,6 +144,7 @@ var _ = Describe("Transport Parameters", func() {
Expect(params.MaxUniStreamID).To(Equal(protocol.StreamID(0x44556677)))
Expect(params.IdleTimeout).To(Equal(0x1337 * time.Second))
Expect(params.OmitConnectionID).To(BeFalse())
Expect(params.MaxPacketSize).To(Equal(protocol.ByteCount(0x7331)))
})
It("saves if it should omit the connection ID", func() {
@@ -215,6 +217,18 @@ var _ = Describe("Transport Parameters", func() {
Expect(err).To(MatchError("wrong length for omit_connection_id: 1 (expected empty)"))
})
It("rejects the parameters if max_packet_size has the wrong length", func() {
parameters[maxPacketSizeParameterID] = []byte{0x11} // should be 2 bytes
_, err := readTransportParamters(paramsMapToList(parameters))
Expect(err).To(MatchError("wrong length for max_packet_size: 1 (expected 2)"))
})
It("rejects max_packet_sizes smaller than 1200 bytes", func() {
parameters[maxPacketSizeParameterID] = []byte{0x4, 0xaf} // 0x4af = 1199
_, err := readTransportParamters(paramsMapToList(parameters))
Expect(err).To(MatchError("invalid value for max_packet_size: 1199 (minimum 1200)"))
})
It("ignores unknown parameters", func() {
parameters[1337] = []byte{42}
_, err := readTransportParamters(paramsMapToList(parameters))

View File

@@ -20,6 +20,8 @@ type TransportParameters struct {
StreamFlowControlWindow protocol.ByteCount
ConnectionFlowControlWindow protocol.ByteCount
MaxPacketSize protocol.ByteCount
MaxBidiStreamID protocol.StreamID // only used for IETF QUIC
MaxUniStreamID protocol.StreamID // only used for IETF QUIC
MaxStreams uint32 // only used for gQUIC
@@ -137,6 +139,15 @@ func readTransportParamters(paramsList []transportParameter) (*TransportParamete
return nil, fmt.Errorf("wrong length for omit_connection_id: %d (expected empty)", len(p.Value))
}
params.OmitConnectionID = true
case maxPacketSizeParameterID:
if len(p.Value) != 2 {
return nil, fmt.Errorf("wrong length for max_packet_size: %d (expected 2)", len(p.Value))
}
maxPacketSize := protocol.ByteCount(binary.BigEndian.Uint16(p.Value))
if maxPacketSize < 1200 {
return nil, fmt.Errorf("invalid value for max_packet_size: %d (minimum 1200)", maxPacketSize)
}
params.MaxPacketSize = maxPacketSize
}
}