Skip to content

Commit

Permalink
TLS messages are now sent in the right encryption level instead of pi…
Browse files Browse the repository at this point in the history
…ping everything in Handshake packets
  • Loading branch information
mpiraux committed Sep 17, 2018
1 parent 73161fa commit 55d74be
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 10 deletions.
13 changes: 4 additions & 9 deletions agents/tls_agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ func (a *TLSAgent) Run(conn *Connection) {
if _, ok := packet.(Framer); !ok {
break
}
cryptoStream := conn.CryptoStreams.Get(packet.PNSpace())
cryptoChan := cryptoChans[packet.PNSpace()]

var handshakeData []byte
Expand All @@ -75,7 +74,7 @@ func (a *TLSAgent) Run(conn *Connection) {
switch packet.(type) {
case Framer:
if len(handshakeData) > 0 {
responseData, notCompleted, err := conn.Tls.HandleMessage(handshakeData, PNSpaceToEpoch[packet.PNSpace()])
tlsOutput, notCompleted, err := conn.Tls.HandleMessage(handshakeData, PNSpaceToEpoch[packet.PNSpace()])

if err != nil {
a.Logger.Printf("TLS error occured: %s\n", err.Error())
Expand All @@ -97,14 +96,10 @@ func (a *TLSAgent) Run(conn *Connection) {
}
}

if len(responseData) > 0 && !a.DisableFrameSending {
var responseEncryptionLevel EncryptionLevel
if packet.EncryptionLevel() == EncryptionLevelInitial {
responseEncryptionLevel = EncryptionLevelHandshake
} else {
responseEncryptionLevel = packet.EncryptionLevel()
if len(tlsOutput) > 0 && !a.DisableFrameSending {
for _, m := range tlsOutput {
conn.FrameQueue.Submit(QueuedFrame{NewCryptoFrame(conn.CryptoStreams.Get(EpochToPNSpace[m.Epoch]), m.Data), EpochToEncryptionLevel[m.Epoch]})
}
conn.FrameQueue.Submit(QueuedFrame{NewCryptoFrame(cryptoStream, responseData), responseEncryptionLevel})
}

if !notCompleted && conn.CryptoStates[EncryptionLevel1RTT] == nil {
Expand Down
7 changes: 7 additions & 0 deletions common.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,13 @@ var PNSpaceToEpoch = map[PNSpace]pigotls.Epoch{
PNSpaceAppData: pigotls.Epoch1RTT,
}

var EpochToPNSpace = map[pigotls.Epoch]PNSpace {
pigotls.EpochInitial: PNSpaceInitial,
pigotls.EpochHandshake: PNSpaceHandshake,
pigotls.Epoch0RTT: PNSpaceAppData,
pigotls.Epoch1RTT: PNSpaceAppData,
}

func (pns PNSpace) String() string {
return PNSpaceToString[pns]
}
Expand Down
3 changes: 2 additions & 1 deletion connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,12 @@ func (c *Connection) GetInitialPacket() *InitialPacket {
}
c.Tls.SetQUICTransportParameters(extensionData)

clientHello, notComplete, err := c.Tls.HandleMessage(nil, pigotls.EpochInitial)
tlsOutput, notComplete, err := c.Tls.HandleMessage(nil, pigotls.EpochInitial)
if err != nil || !notComplete {
println(err.Error())
return nil
}
clientHello := tlsOutput[0].Data
c.ClientRandom = make([]byte, 32, 32)
copy(c.ClientRandom, clientHello[11:11+32])
cryptoFrame := NewCryptoFrame(c.CryptoStreams.Get(PNSpaceInitial), clientHello)
Expand Down
7 changes: 7 additions & 0 deletions crypto.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ var packetTypeToEncryptionLevel = map[PacketType]EncryptionLevel{
ShortHeaderPacket: EncryptionLevel1RTT,
}

var EpochToEncryptionLevel = map[pigotls.Epoch]EncryptionLevel {
pigotls.EpochInitial: EncryptionLevelInitial,
pigotls.Epoch0RTT: EncryptionLevel0RTT,
pigotls.EpochHandshake: EncryptionLevelHandshake,
pigotls.Epoch1RTT: EncryptionLevel1RTT,
}

type DirectionalEncryptionLevel struct {
EncryptionLevel
Read bool
Expand Down

0 comments on commit 55d74be

Please sign in to comment.