Skip to content

Commit

Permalink
Cleans up the Client Random export and integrates with zero_rtt
Browse files Browse the repository at this point in the history
  • Loading branch information
mpiraux committed Sep 17, 2018
1 parent 55d74be commit 7e69a81
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 9 deletions.
3 changes: 0 additions & 3 deletions connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ type Connection struct {

CryptoStates map[EncryptionLevel]*CryptoState

ClientRandom []byte
ExporterSecret []byte

ReceivedPacketHandler func([]byte, unsafe.Pointer)
Expand Down Expand Up @@ -108,8 +107,6 @@ func (c *Connection) GetInitialPacket() *InitialPacket {
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)

if len(c.Tls.ZeroRTTSecret()) > 0 {
Expand Down
1 change: 1 addition & 0 deletions scenarii/zero_rtt.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ forLoop1:
handshakeAgent := &agents.HandshakeAgent{TLSAgent: connAgents.Get("TLSAgent").(*agents.TLSAgent), SocketAgent: connAgents.Get("SocketAgent").(*agents.SocketAgent)}
connAgents.Add(handshakeAgent)
defer connAgents.CloseConnection(false, 0, "")
defer trace.Complete(conn)

incPackets = make(chan interface{}, 1000)
conn.IncomingPackets.Register(incPackets)
Expand Down
29 changes: 23 additions & 6 deletions trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"time"
"strings"
"unsafe"
"github.com/mpiraux/pigotls"
)

// Contains the result of a test run against a given host.
Expand All @@ -20,10 +21,14 @@ type Trace struct {
ErrorCode uint8 `json:"error_code"` // A scenario-specific error code that reports its verdict
Stream []TracePacket `json:"stream"` // A clear-text copy of the packets that were sent and received
Pcap []byte `json:"pcap"` // The packet capture file associated with the trace
DecryptedPcap []byte `json:"decrypted_pcap"`
ClientRandom []byte `json:"client_random"`
ExporterSecret []byte `json:"exporter_secret"`
EarlyExporterSecret []byte `json:"early_exporter_secret"`
Secrets map[pigotls.Epoch]Secrets `json:"secrets"`
}

type Secrets struct {
Epoch pigotls.Epoch `json:"epoch"`
Read []byte `json:"read"`
Write []byte `json:"write"`
}

func NewTrace(scenarioName string, scenarioVersion int, host string) *Trace {
Expand Down Expand Up @@ -74,9 +79,21 @@ func (t *Trace) AttachTo(conn *Connection) {
}

func (t *Trace) Complete(conn *Connection) {
t.ClientRandom = conn.ClientRandom
t.ExporterSecret = conn.ExporterSecret
t.EarlyExporterSecret = conn.Tls.EarlyExporterSecret()
if len(t.ClientRandom) == 0 {
t.ClientRandom = conn.Tls.ClientRandom()
}
if t.Secrets == nil {
t.Secrets = make(map[pigotls.Epoch]Secrets)
}
if _, ok := t.Secrets[pigotls.Epoch0RTT]; !ok && len(conn.Tls.ZeroRTTSecret()) > 0 {
t.Secrets[pigotls.Epoch0RTT] = Secrets{Epoch: pigotls.Epoch0RTT, Write: conn.Tls.ZeroRTTSecret()}
}
if _, ok := t.Secrets[pigotls.EpochHandshake]; !ok && len(conn.Tls.HandshakeReadSecret()) > 0 || len(conn.Tls.HandshakeWriteSecret()) > 0 {
t.Secrets[pigotls.EpochHandshake] = Secrets{Epoch: pigotls.EpochHandshake, Read: conn.Tls.HandshakeReadSecret(), Write: conn.Tls.HandshakeWriteSecret()}
}
if _, ok := t.Secrets[pigotls.Epoch1RTT]; !ok && len(conn.Tls.ProtectedReadSecret()) > 0 || len(conn.Tls.ProtectedWriteSecret()) > 0 {
t.Secrets[pigotls.Epoch1RTT] = Secrets{Epoch: pigotls.Epoch1RTT, Read: conn.Tls.ProtectedReadSecret(), Write: conn.Tls.ProtectedWriteSecret()}
}
}

type Direction string
Expand Down

0 comments on commit 7e69a81

Please sign in to comment.