Serialize SSL configuration in handoff and check it on application. A split SSL handshake may involve 2 binaries, potentially built at different versions: call them the "handoff/handback" binary and the "handshake" binary. We would like to guarantee that the handoff/handback binary does not make any promises that the handshake binary cannot keep. As a start, this commit serializes |kCiphers| to the handoff message. When the handoff message is applied to an |SSL|, any configured ciphers not listed in the handoff message will be removed, in order to prevent them from being negotiated. Subsequent commits will apply the same approach to other lists of features. Change-Id: Idf6dbeadb750c076ab0509c09b9d3f22eb162b9c Reviewed-on: https://boringssl-review.googlesource.com/c/29264 Reviewed-by: Matt Braithwaite <mab@google.com>
diff --git a/ssl/ssl_test.cc b/ssl/ssl_test.cc index 4792560..f7b299a 100644 --- a/ssl/ssl_test.cc +++ b/ssl/ssl_test.cc
@@ -4278,6 +4278,35 @@ } } +TEST(SSLTest, ApplyHandoffRemovesUnsupportedCiphers) { + bssl::UniquePtr<SSL_CTX> server_ctx(SSL_CTX_new(TLS_method())); + bssl::UniquePtr<SSL> server(SSL_new(server_ctx.get())); + + // handoff is a handoff message that has been artificially modified to pretend + // that only cipher 0x0A is supported. When it is applied to |server|, all + // ciphers but that one should be removed. + uint8_t handoff[] = { + 0x30, 0x81, 0x8e, 0x02, 0x01, 0x00, 0x04, 0x00, 0x04, 0x81, 0x82, 0x01, + 0x00, 0x00, 0x7e, 0x03, 0x03, 0x77, 0x62, 0x00, 0x9a, 0x13, 0x48, 0x23, + 0x46, 0x11, 0x6c, 0x0b, 0x1c, 0x91, 0x4e, 0xbc, 0x1c, 0xff, 0x54, 0xb9, + 0xe6, 0x3f, 0xa8, 0x8d, 0x49, 0x37, 0x7a, 0x9e, 0xbf, 0x36, 0xd5, 0x08, + 0x24, 0x00, 0x00, 0x1e, 0xc0, 0x2b, 0xc0, 0x2f, 0xc0, 0x2c, 0xc0, 0x30, + 0xcc, 0xa9, 0xcc, 0xa8, 0xc0, 0x09, 0xc0, 0x13, 0xc0, 0x0a, 0xc0, 0x14, + 0x00, 0x9c, 0x00, 0x9d, 0x00, 0x2f, 0x00, 0x35, 0x00, 0x0a, 0x01, 0x00, + 0x00, 0x37, 0xff, 0x01, 0x00, 0x01, 0x00, 0x00, 0x17, 0x00, 0x00, 0x00, + 0x23, 0x00, 0x00, 0x00, 0x0d, 0x00, 0x14, 0x00, 0x12, 0x04, 0x03, 0x08, + 0x04, 0x04, 0x01, 0x05, 0x03, 0x08, 0x05, 0x05, 0x01, 0x08, 0x06, 0x06, + 0x01, 0x02, 0x01, 0x00, 0x0b, 0x00, 0x02, 0x01, 0x00, 0x00, 0x0a, 0x00, + 0x08, 0x00, 0x06, 0x00, 0x1d, 0x00, 0x17, 0x00, 0x18, 0x04, 0x02, 0x00, + 0x0a, + }; + + EXPECT_EQ(20u, sk_SSL_CIPHER_num(SSL_get_ciphers(server.get()))); + ASSERT_TRUE( + SSL_apply_handoff(server.get(), {handoff, OPENSSL_ARRAY_SIZE(handoff)})); + EXPECT_EQ(1u, sk_SSL_CIPHER_num(SSL_get_ciphers(server.get()))); +} + TEST_P(SSLVersionTest, VerifyBeforeCertRequest) { // Configure the server to request client certificates. SSL_CTX_set_custom_verify(