From 3f40b2f19a04f068d7f724bfc1f637176719cad7 Mon Sep 17 00:00:00 2001 From: Marten Seemann Date: Fri, 4 Sep 2020 10:46:05 +0700 Subject: [PATCH] make sure to only pass handshake messages that keys are available for --- fuzzing/handshake/fuzz.go | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/fuzzing/handshake/fuzz.go b/fuzzing/handshake/fuzz.go index 71d81421..51a2c594 100644 --- a/fuzzing/handshake/fuzz.go +++ b/fuzzing/handshake/fuzz.go @@ -135,6 +135,27 @@ func toEncryptionLevel(n uint8) protocol.EncryptionLevel { } } +func maxEncLevel(cs handshake.CryptoSetup, encLevel protocol.EncryptionLevel) protocol.EncryptionLevel { + switch encLevel { + case protocol.EncryptionInitial: + return protocol.EncryptionInitial + case protocol.EncryptionHandshake: + // Handshake opener not available. We can't possibly read a Handshake handshake message. + if opener, err := cs.GetHandshakeOpener(); err != nil || opener == nil { + return protocol.EncryptionInitial + } + return protocol.EncryptionHandshake + case protocol.Encryption1RTT: + // 1-RTT opener not available. We can't possibly read a post-handshake message. + if opener, err := cs.Get1RTTOpener(); err != nil || opener == nil { + return maxEncLevel(cs, protocol.EncryptionHandshake) + } + return protocol.Encryption1RTT + default: + panic("unexpected encryption level") + } +} + // PrefixLen is the number of bytes used for configuration const PrefixLen = 2 @@ -230,7 +251,7 @@ messageLoop: if len(b) > 0 && b[0] == messageToReplace { fmt.Println("replacing message to the server", messageType(b[0]).String()) b = data - encLevel = messageToReplaceEncLevel + encLevel = maxEncLevel(server, messageToReplaceEncLevel) } server.HandleMessage(b, encLevel) case c := <-sChunkChan: @@ -239,7 +260,7 @@ messageLoop: if len(b) > 0 && b[0] == messageToReplace { fmt.Println("replacing message to the client", messageType(b[0]).String()) b = data - encLevel = messageToReplaceEncLevel + encLevel = maxEncLevel(client, messageToReplaceEncLevel) } client.HandleMessage(b, encLevel) case <-done: // test done