From 12d2c480864d6e60e78d77a6bb7a8c9585900456 Mon Sep 17 00:00:00 2001 From: David Benjamin Date: Sun, 24 Jul 2016 10:56:51 -0400 Subject: [PATCH] Add a packed renegotiation test. Ridiculous as it is, the protocol does not forbid packing HelloRequest and Finished into the same record. Add a test for this case. Change-Id: I8e1455b261f56169309070bf44d14d40a63eae50 Reviewed-on: https://boringssl-review.googlesource.com/8901 Reviewed-by: Steven Valdez Reviewed-by: David Benjamin --- ssl/test/runner/common.go | 4 ++++ ssl/test/runner/conn.go | 4 ++++ ssl/test/runner/handshake_server.go | 5 ++++- ssl/test/runner/runner.go | 18 ++++++++++++++++++ 4 files changed, 30 insertions(+), 1 deletion(-) diff --git a/ssl/test/runner/common.go b/ssl/test/runner/common.go index b2d31dc2..240a7ecd 100644 --- a/ssl/test/runner/common.go +++ b/ssl/test/runner/common.go @@ -997,6 +997,10 @@ type ProtocolBugs struct { // SkipHelloRetryRequest, if true, causes the TLS 1.3 server to not send // HelloRetryRequest. SkipHelloRetryRequest bool + + // PackHelloRequestWithFinished, if true, causes the TLS server to send + // HelloRequest in the same record as Finished. + PackHelloRequestWithFinished bool } func (c *Config) serverInit() { diff --git a/ssl/test/runner/conn.go b/ssl/test/runner/conn.go index fbd501a0..1b6c5573 100644 --- a/ssl/test/runner/conn.go +++ b/ssl/test/runner/conn.go @@ -1268,6 +1268,10 @@ func (c *Conn) Write(b []byte) (int, error) { c.out.Lock() defer c.out.Unlock() + // Flush any pending handshake data. PackHelloRequestWithFinished may + // have been set and the handshake not followed by Renegotiate. + c.flushHandshake() + if err := c.out.err; err != nil { return 0, err } diff --git a/ssl/test/runner/handshake_server.go b/ssl/test/runner/handshake_server.go index f8b5deed..aeda2f15 100644 --- a/ssl/test/runner/handshake_server.go +++ b/ssl/test/runner/handshake_server.go @@ -1391,7 +1391,10 @@ func (hs *serverHandshakeState) sendFinished(out []byte) error { if !c.config.Bugs.SkipFinished && len(postCCSBytes) > 0 { c.writeRecord(recordTypeHandshake, postCCSBytes) - c.flushHandshake() + if !c.config.Bugs.PackHelloRequestWithFinished { + // Defer flushing until renegotiation. + c.flushHandshake() + } } c.cipherSuite = hs.suite diff --git a/ssl/test/runner/runner.go b/ssl/test/runner/runner.go index fd263e63..f8cb4d94 100644 --- a/ssl/test/runner/runner.go +++ b/ssl/test/runner/runner.go @@ -5021,6 +5021,24 @@ func addRenegotiationTests() { }, }) + // Test renegotiation works if HelloRequest and server Finished come in + // the same record. + testCases = append(testCases, testCase{ + name: "Renegotiate-Client-Packed", + config: Config{ + MaxVersion: VersionTLS12, + Bugs: ProtocolBugs{ + PackHandshakeFlight: true, + PackHelloRequestWithFinished: true, + }, + }, + renegotiate: 1, + flags: []string{ + "-renegotiate-freely", + "-expect-total-renegotiations", "1", + }, + }) + // Renegotiation is forbidden in TLS 1.3. // // TODO(davidben): This test current asserts that we ignore