use server generated connection IDs when accepting a connection

This commit is contained in:
Marten Seemann
2018-08-12 19:01:33 +07:00
parent 77f5d30338
commit 70992684af
3 changed files with 12 additions and 9 deletions

View File

@@ -26,7 +26,7 @@ type serverTLS struct {
params *handshake.TransportParameters
cookieGenerator *handshake.CookieGenerator
newSession func(connection, sessionRunner, protocol.ConnectionID, protocol.ConnectionID, protocol.PacketNumber, *Config, *mint.Config, *handshake.TransportParameters, utils.Logger, protocol.VersionNumber) (quicSession, error)
newSession func(connection, sessionRunner, protocol.ConnectionID, protocol.ConnectionID, protocol.ConnectionID, protocol.PacketNumber, *Config, *mint.Config, *handshake.TransportParameters, utils.Logger, protocol.VersionNumber) (quicSession, error)
sessionRunner sessionRunner
sessionChan chan<- tlsSession
@@ -128,12 +128,15 @@ func (s *serverTLS) handleInitialImpl(p *receivedPacket) (quicSession, protocol.
mconf := s.mintConf.Clone()
mconf.ExtensionHandler = extHandler
// TODO: change the connection ID
// This means that the server crypto setup will need two different null AEADs.
connID := hdr.DestConnectionID
connID, err := protocol.GenerateConnectionID(s.config.ConnectionIDLength)
if err != nil {
return nil, nil, err
}
s.logger.Debugf("Changing connection ID to %s.", connID)
sess, err := s.newSession(
&conn{pconn: s.conn, currentAddr: p.remoteAddr},
s.sessionRunner,
hdr.DestConnectionID,
hdr.SrcConnectionID,
connID,
1,
@@ -169,7 +172,7 @@ func (s *serverTLS) sendRetry(remoteAddr net.Addr, hdr *wire.Header) error {
OrigDestConnectionID: hdr.DestConnectionID,
Token: token,
}
s.logger.Debugf("-> Sending Retry")
s.logger.Debugf("Changing connection ID to %s.\n-> Sending Retry", connID)
replyHdr.Log(s.logger)
buf := &bytes.Buffer{}
if err := replyHdr.Write(buf, protocol.PerspectiveServer, hdr.Version); err != nil {

View File

@@ -114,7 +114,7 @@ var _ = Describe("Stateless TLS handling", func() {
data: bytes.Repeat([]byte{0}, protocol.MinInitialPacketSize),
}
run := make(chan struct{})
server.newSession = func(connection, sessionRunner, protocol.ConnectionID, protocol.ConnectionID, protocol.PacketNumber, *Config, *mint.Config, *handshake.TransportParameters, utils.Logger, protocol.VersionNumber) (quicSession, error) {
server.newSession = func(connection, sessionRunner, protocol.ConnectionID, protocol.ConnectionID, protocol.ConnectionID, protocol.PacketNumber, *Config, *mint.Config, *handshake.TransportParameters, utils.Logger, protocol.VersionNumber) (quicSession, error) {
sess := NewMockQuicSession(mockCtrl)
sess.EXPECT().handlePacket(p)
sess.EXPECT().run().Do(func() { close(run) })
@@ -133,8 +133,7 @@ var _ = Describe("Stateless TLS handling", func() {
Eventually(sessionChan).Should(Receive(&tlsSess))
// make sure we're using a server-generated connection ID
Expect(tlsSess.connID).ToNot(Equal(hdr.SrcConnectionID))
// TODO: use server-generated connection ID here
// Expect(tlsSess.connID).ToNot(Equal(hdr.DestConnectionID))
Expect(tlsSess.connID).ToNot(Equal(hdr.DestConnectionID))
Eventually(run).Should(BeClosed())
Eventually(done).Should(BeClosed())
})

View File

@@ -294,6 +294,7 @@ var newClientSession = func(
func newTLSServerSession(
conn connection,
runner sessionRunner,
origConnID protocol.ConnectionID,
destConnID protocol.ConnectionID,
srcConnID protocol.ConnectionID,
initialPacketNumber protocol.PacketNumber,
@@ -318,7 +319,7 @@ func newTLSServerSession(
s.preSetup()
cs, err := handshake.NewCryptoSetupTLSServer(
s.cryptoStream,
s.srcConnID,
origConnID,
mintConf,
handshakeEvent,
v,