mirror of
https://github.com/refraction-networking/uquic.git
synced 2025-04-04 12:47:36 +03:00
use an array for the stateless reset token in the transport parameters
This commit is contained in:
parent
dd8c590b13
commit
6cf20310fe
6 changed files with 31 additions and 26 deletions
|
@ -271,6 +271,7 @@ var _ = Describe("Crypto Setup TLS", func() {
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
|
||||||
sChunkChan, sInitialStream, sHandshakeStream := initStreams()
|
sChunkChan, sInitialStream, sHandshakeStream := initStreams()
|
||||||
|
var token [16]byte
|
||||||
server, err := NewCryptoSetupServer(
|
server, err := NewCryptoSetupServer(
|
||||||
sInitialStream,
|
sInitialStream,
|
||||||
sHandshakeStream,
|
sHandshakeStream,
|
||||||
|
@ -279,7 +280,7 @@ var _ = Describe("Crypto Setup TLS", func() {
|
||||||
&EncryptedExtensionsTransportParameters{
|
&EncryptedExtensionsTransportParameters{
|
||||||
NegotiatedVersion: protocol.VersionTLS,
|
NegotiatedVersion: protocol.VersionTLS,
|
||||||
SupportedVersions: []protocol.VersionNumber{protocol.VersionTLS},
|
SupportedVersions: []protocol.VersionNumber{protocol.VersionTLS},
|
||||||
Parameters: TransportParameters{StatelessResetToken: bytes.Repeat([]byte{42}, 16)},
|
Parameters: TransportParameters{StatelessResetToken: &token},
|
||||||
},
|
},
|
||||||
func([]byte) {},
|
func([]byte) {},
|
||||||
serverConf,
|
serverConf,
|
||||||
|
@ -359,9 +360,10 @@ var _ = Describe("Crypto Setup TLS", func() {
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
|
||||||
sChunkChan, sInitialStream, sHandshakeStream := initStreams()
|
sChunkChan, sInitialStream, sHandshakeStream := initStreams()
|
||||||
|
var token [16]byte
|
||||||
sTransportParameters := &TransportParameters{
|
sTransportParameters := &TransportParameters{
|
||||||
IdleTimeout: 0x1337 * time.Second,
|
IdleTimeout: 0x1337 * time.Second,
|
||||||
StatelessResetToken: bytes.Repeat([]byte{42}, 16),
|
StatelessResetToken: &token,
|
||||||
}
|
}
|
||||||
server, err := NewCryptoSetupServer(
|
server, err := NewCryptoSetupServer(
|
||||||
sInitialStream,
|
sInitialStream,
|
||||||
|
|
|
@ -24,9 +24,9 @@ var _ = Describe("Transport Parameters", func() {
|
||||||
IdleTimeout: 42 * time.Second,
|
IdleTimeout: 42 * time.Second,
|
||||||
OriginalConnectionID: protocol.ConnectionID{0xde, 0xad, 0xbe, 0xef},
|
OriginalConnectionID: protocol.ConnectionID{0xde, 0xad, 0xbe, 0xef},
|
||||||
AckDelayExponent: 14,
|
AckDelayExponent: 14,
|
||||||
StatelessResetToken: []byte{0xde, 0xad, 0xbe, 0xef, 0xca, 0xfe},
|
StatelessResetToken: &[16]byte{0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, 0x00},
|
||||||
}
|
}
|
||||||
Expect(p.String()).To(Equal("&handshake.TransportParameters{OriginalConnectionID: 0xdeadbeef, InitialMaxStreamDataBidiLocal: 0x1234, InitialMaxStreamDataBidiRemote: 0x2345, InitialMaxStreamDataUni: 0x3456, InitialMaxData: 0x4567, MaxBidiStreams: 1337, MaxUniStreams: 7331, IdleTimeout: 42s, AckDelayExponent: 14, StatelessResetToken: 0xdeadbeefcafe}"))
|
Expect(p.String()).To(Equal("&handshake.TransportParameters{OriginalConnectionID: 0xdeadbeef, InitialMaxStreamDataBidiLocal: 0x1234, InitialMaxStreamDataBidiRemote: 0x2345, InitialMaxStreamDataUni: 0x3456, InitialMaxData: 0x4567, MaxBidiStreams: 1337, MaxUniStreams: 7331, IdleTimeout: 42s, AckDelayExponent: 14, StatelessResetToken: 0x112233445566778899aabbccddeeff00}"))
|
||||||
})
|
})
|
||||||
|
|
||||||
getRandomValue := func() uint64 {
|
getRandomValue := func() uint64 {
|
||||||
|
@ -36,6 +36,8 @@ var _ = Describe("Transport Parameters", func() {
|
||||||
}
|
}
|
||||||
|
|
||||||
It("marshals und unmarshals", func() {
|
It("marshals und unmarshals", func() {
|
||||||
|
var token [16]byte
|
||||||
|
rand.Read(token[:])
|
||||||
params := &TransportParameters{
|
params := &TransportParameters{
|
||||||
InitialMaxStreamDataBidiLocal: protocol.ByteCount(getRandomValue()),
|
InitialMaxStreamDataBidiLocal: protocol.ByteCount(getRandomValue()),
|
||||||
InitialMaxStreamDataBidiRemote: protocol.ByteCount(getRandomValue()),
|
InitialMaxStreamDataBidiRemote: protocol.ByteCount(getRandomValue()),
|
||||||
|
@ -45,7 +47,7 @@ var _ = Describe("Transport Parameters", func() {
|
||||||
MaxBidiStreams: getRandomValue(),
|
MaxBidiStreams: getRandomValue(),
|
||||||
MaxUniStreams: getRandomValue(),
|
MaxUniStreams: getRandomValue(),
|
||||||
DisableMigration: true,
|
DisableMigration: true,
|
||||||
StatelessResetToken: bytes.Repeat([]byte{100}, 16),
|
StatelessResetToken: &token,
|
||||||
OriginalConnectionID: protocol.ConnectionID{0xde, 0xad, 0xbe, 0xef},
|
OriginalConnectionID: protocol.ConnectionID{0xde, 0xad, 0xbe, 0xef},
|
||||||
AckDelayExponent: 13,
|
AckDelayExponent: 13,
|
||||||
}
|
}
|
||||||
|
@ -68,9 +70,10 @@ var _ = Describe("Transport Parameters", func() {
|
||||||
})
|
})
|
||||||
|
|
||||||
It("errors when the stateless_reset_token has the wrong length", func() {
|
It("errors when the stateless_reset_token has the wrong length", func() {
|
||||||
params := &TransportParameters{StatelessResetToken: bytes.Repeat([]byte{100}, 15)}
|
|
||||||
b := &bytes.Buffer{}
|
b := &bytes.Buffer{}
|
||||||
params.marshal(b)
|
utils.BigEndian.WriteUint16(b, uint16(statelessResetTokenParameterID))
|
||||||
|
utils.BigEndian.WriteUint16(b, 15)
|
||||||
|
b.Write(make([]byte, 15))
|
||||||
p := &TransportParameters{}
|
p := &TransportParameters{}
|
||||||
Expect(p.unmarshal(b.Bytes(), protocol.PerspectiveServer)).To(MatchError("wrong length for stateless_reset_token: 15 (expected 16)"))
|
Expect(p.unmarshal(b.Bytes(), protocol.PerspectiveServer)).To(MatchError("wrong length for stateless_reset_token: 15 (expected 16)"))
|
||||||
})
|
})
|
||||||
|
@ -190,9 +193,8 @@ var _ = Describe("Transport Parameters", func() {
|
||||||
})
|
})
|
||||||
|
|
||||||
It("errors if the client sent a stateless_reset_token", func() {
|
It("errors if the client sent a stateless_reset_token", func() {
|
||||||
params := &TransportParameters{
|
var token [16]byte
|
||||||
StatelessResetToken: make([]byte, 16),
|
params := &TransportParameters{StatelessResetToken: &token}
|
||||||
}
|
|
||||||
b := &bytes.Buffer{}
|
b := &bytes.Buffer{}
|
||||||
params.marshal(b)
|
params.marshal(b)
|
||||||
p := &TransportParameters{}
|
p := &TransportParameters{}
|
||||||
|
|
|
@ -46,7 +46,7 @@ type TransportParameters struct {
|
||||||
IdleTimeout time.Duration
|
IdleTimeout time.Duration
|
||||||
DisableMigration bool
|
DisableMigration bool
|
||||||
|
|
||||||
StatelessResetToken []byte
|
StatelessResetToken *[16]byte
|
||||||
OriginalConnectionID protocol.ConnectionID
|
OriginalConnectionID protocol.ConnectionID
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -94,9 +94,9 @@ func (p *TransportParameters) unmarshal(data []byte, sentBy protocol.Perspective
|
||||||
if paramLen != 16 {
|
if paramLen != 16 {
|
||||||
return fmt.Errorf("wrong length for stateless_reset_token: %d (expected 16)", paramLen)
|
return fmt.Errorf("wrong length for stateless_reset_token: %d (expected 16)", paramLen)
|
||||||
}
|
}
|
||||||
b := make([]byte, 16)
|
var token [16]byte
|
||||||
r.Read(b)
|
r.Read(token[:])
|
||||||
p.StatelessResetToken = b
|
p.StatelessResetToken = &token
|
||||||
case originalConnectionIDParameterID:
|
case originalConnectionIDParameterID:
|
||||||
if sentBy == protocol.PerspectiveClient {
|
if sentBy == protocol.PerspectiveClient {
|
||||||
return errors.New("client sent an original_connection_id")
|
return errors.New("client sent an original_connection_id")
|
||||||
|
@ -216,10 +216,10 @@ func (p *TransportParameters) marshal(b *bytes.Buffer) {
|
||||||
utils.BigEndian.WriteUint16(b, uint16(disableMigrationParameterID))
|
utils.BigEndian.WriteUint16(b, uint16(disableMigrationParameterID))
|
||||||
utils.BigEndian.WriteUint16(b, 0)
|
utils.BigEndian.WriteUint16(b, 0)
|
||||||
}
|
}
|
||||||
if len(p.StatelessResetToken) > 0 {
|
if p.StatelessResetToken != nil {
|
||||||
utils.BigEndian.WriteUint16(b, uint16(statelessResetTokenParameterID))
|
utils.BigEndian.WriteUint16(b, uint16(statelessResetTokenParameterID))
|
||||||
utils.BigEndian.WriteUint16(b, uint16(len(p.StatelessResetToken))) // should always be 16 bytes
|
utils.BigEndian.WriteUint16(b, 16)
|
||||||
b.Write(p.StatelessResetToken)
|
b.Write(p.StatelessResetToken[:])
|
||||||
}
|
}
|
||||||
// original_connection_id
|
// original_connection_id
|
||||||
if p.OriginalConnectionID.Len() > 0 {
|
if p.OriginalConnectionID.Len() > 0 {
|
||||||
|
@ -232,9 +232,9 @@ func (p *TransportParameters) marshal(b *bytes.Buffer) {
|
||||||
// String returns a string representation, intended for logging.
|
// String returns a string representation, intended for logging.
|
||||||
func (p *TransportParameters) String() string {
|
func (p *TransportParameters) String() string {
|
||||||
logString := "&handshake.TransportParameters{OriginalConnectionID: %s, InitialMaxStreamDataBidiLocal: %#x, InitialMaxStreamDataBidiRemote: %#x, InitialMaxStreamDataUni: %#x, InitialMaxData: %#x, MaxBidiStreams: %d, MaxUniStreams: %d, IdleTimeout: %s, AckDelayExponent: %d"
|
logString := "&handshake.TransportParameters{OriginalConnectionID: %s, InitialMaxStreamDataBidiLocal: %#x, InitialMaxStreamDataBidiRemote: %#x, InitialMaxStreamDataUni: %#x, InitialMaxData: %#x, MaxBidiStreams: %d, MaxUniStreams: %d, IdleTimeout: %s, AckDelayExponent: %d"
|
||||||
if len(p.StatelessResetToken) > 0 { // the client never sends a stateless reset token
|
if p.StatelessResetToken != nil { // the client never sends a stateless reset token
|
||||||
logString += ", StatelessResetToken: %#x"
|
logString += ", StatelessResetToken: %#x"
|
||||||
}
|
}
|
||||||
logString += "}"
|
logString += "}"
|
||||||
return fmt.Sprintf(logString, p.OriginalConnectionID, p.InitialMaxStreamDataBidiLocal, p.InitialMaxStreamDataBidiRemote, p.InitialMaxStreamDataUni, p.InitialMaxData, p.MaxBidiStreams, p.MaxUniStreams, p.IdleTimeout, p.AckDelayExponent, p.StatelessResetToken)
|
return fmt.Sprintf(logString, p.OriginalConnectionID, p.InitialMaxStreamDataBidiLocal, p.InitialMaxStreamDataBidiRemote, p.InitialMaxStreamDataUni, p.InitialMaxData, p.MaxBidiStreams, p.MaxUniStreams, p.IdleTimeout, p.AckDelayExponent, *p.StatelessResetToken)
|
||||||
}
|
}
|
||||||
|
|
|
@ -430,6 +430,8 @@ func (s *server) createNewSession(
|
||||||
srcConnID protocol.ConnectionID,
|
srcConnID protocol.ConnectionID,
|
||||||
version protocol.VersionNumber,
|
version protocol.VersionNumber,
|
||||||
) (quicSession, error) {
|
) (quicSession, error) {
|
||||||
|
// TODO(#855): generate a real token
|
||||||
|
token := [16]byte{42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42}
|
||||||
params := &handshake.TransportParameters{
|
params := &handshake.TransportParameters{
|
||||||
InitialMaxStreamDataBidiLocal: protocol.InitialMaxStreamData,
|
InitialMaxStreamDataBidiLocal: protocol.InitialMaxStreamData,
|
||||||
InitialMaxStreamDataBidiRemote: protocol.InitialMaxStreamData,
|
InitialMaxStreamDataBidiRemote: protocol.InitialMaxStreamData,
|
||||||
|
@ -440,9 +442,8 @@ func (s *server) createNewSession(
|
||||||
MaxUniStreams: uint64(s.config.MaxIncomingUniStreams),
|
MaxUniStreams: uint64(s.config.MaxIncomingUniStreams),
|
||||||
AckDelayExponent: protocol.AckDelayExponent,
|
AckDelayExponent: protocol.AckDelayExponent,
|
||||||
DisableMigration: true,
|
DisableMigration: true,
|
||||||
// TODO(#855): generate a real token
|
StatelessResetToken: &token,
|
||||||
StatelessResetToken: bytes.Repeat([]byte{42}, 16),
|
OriginalConnectionID: origDestConnID,
|
||||||
OriginalConnectionID: origDestConnID,
|
|
||||||
}
|
}
|
||||||
sess, err := s.newSession(
|
sess, err := s.newSession(
|
||||||
&conn{pconn: s.conn, currentAddr: remoteAddr},
|
&conn{pconn: s.conn, currentAddr: remoteAddr},
|
||||||
|
|
|
@ -952,7 +952,7 @@ func (s *session) processTransportParametersForClient(data []byte) (*handshake.T
|
||||||
|
|
||||||
params := &eetp.Parameters
|
params := &eetp.Parameters
|
||||||
// check that the server sent a stateless reset token
|
// check that the server sent a stateless reset token
|
||||||
if len(params.StatelessResetToken) == 0 {
|
if params.StatelessResetToken == nil {
|
||||||
return nil, errors.New("server didn't send stateless_reset_token")
|
return nil, errors.New("server didn't send stateless_reset_token")
|
||||||
}
|
}
|
||||||
// check the Retry token
|
// check the Retry token
|
||||||
|
|
|
@ -1661,7 +1661,7 @@ var _ = Describe("Client Session", func() {
|
||||||
SupportedVersions: []protocol.VersionNumber{sess.version},
|
SupportedVersions: []protocol.VersionNumber{sess.version},
|
||||||
Parameters: handshake.TransportParameters{
|
Parameters: handshake.TransportParameters{
|
||||||
OriginalConnectionID: protocol.ConnectionID{0xde, 0xca, 0xfb, 0xad},
|
OriginalConnectionID: protocol.ConnectionID{0xde, 0xca, 0xfb, 0xad},
|
||||||
StatelessResetToken: []byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16},
|
StatelessResetToken: &[16]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
_, err := sess.processTransportParametersForClient(eetp.Marshal())
|
_, err := sess.processTransportParametersForClient(eetp.Marshal())
|
||||||
|
@ -1675,7 +1675,7 @@ var _ = Describe("Client Session", func() {
|
||||||
SupportedVersions: []protocol.VersionNumber{sess.version},
|
SupportedVersions: []protocol.VersionNumber{sess.version},
|
||||||
Parameters: handshake.TransportParameters{
|
Parameters: handshake.TransportParameters{
|
||||||
OriginalConnectionID: protocol.ConnectionID{0xde, 0xca, 0xfb, 0xad},
|
OriginalConnectionID: protocol.ConnectionID{0xde, 0xca, 0xfb, 0xad},
|
||||||
StatelessResetToken: []byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16},
|
StatelessResetToken: &[16]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
_, err := sess.processTransportParametersForClient(eetp.Marshal())
|
_, err := sess.processTransportParametersForClient(eetp.Marshal())
|
||||||
|
@ -1687,7 +1687,7 @@ var _ = Describe("Client Session", func() {
|
||||||
|
|
||||||
BeforeEach(func() {
|
BeforeEach(func() {
|
||||||
params = handshake.TransportParameters{
|
params = handshake.TransportParameters{
|
||||||
StatelessResetToken: []byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16},
|
StatelessResetToken: &[16]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16},
|
||||||
OriginalConnectionID: sess.origDestConnID,
|
OriginalConnectionID: sess.origDestConnID,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue