ssl/ssl_test.cc
// Test that the early callback can swap the maximum version.
Test that the early callback can swap the maximum version.
Test that the early callback can swap the maximum version .
TEST(SSLTest, EarlyCallbackVersionSwitch) {
  bssl::UniquePtr<X509> cert = GetTestCertificate();
  bssl::UniquePtr<EVP_PKEY> key = GetTestKey();
  bssl::UniquePtr<SSL_CTX> server_ctx(SSL_CTX_new(TLS_method()));
  bssl::UniquePtr<SSL_CTX> client_ctx(SSL_CTX_new(TLS_method()));
  ASSERT_TRUE(cert);
  ASSERT_TRUE(key);
  ASSERT_TRUE(server_ctx);
  ASSERT_TRUE(client_ctx);
  ASSERT_TRUE(SSL_CTX_use_certificate(server_ctx.get(), cert.get()));
  ASSERT_TRUE(SSL_CTX_use_PrivateKey(server_ctx.get(), key.get()));
  ASSERT_TRUE(SSL_CTX_set_max_proto_version(client_ctx.get(), TLS1_3_VERSION));
  ASSERT_TRUE(SSL_CTX_set_max_proto_version(server_ctx.get(), TLS1_3_VERSION));
  SSL_CTX_set_select_certificate_cb(
      server_ctx.get(),
      [](const SSL_CLIENT_HELLO *client_hello) -> ssl_select_cert_result_t {
        if (!SSL_set_max_proto_version(client_hello->ssl, TLS1_2_VERSION)) {
          return ssl_select_cert_error;
        }
        return ssl_select_cert_success;
      });
  bssl::UniquePtr<SSL> client, server;
  ASSERT_TRUE(ConnectClientAndServer(&client, &server, client_ctx.get(),
                                     server_ctx.get()));
  EXPECT_EQ(TLS1_2_VERSION, SSL_version(client.get()));
}
TEST ( SSLTest , EarlyCallbackVersionSwitch ) { bssl :: UniquePtr < X509 > cert = GetTestCertificate ( ) ; bssl :: UniquePtr < EVP_PKEY > key = GetTestKey ( ) ; bssl :: UniquePtr < SSL_CTX > server_ctx ( SSL_CTX_new ( TLS_method ( ) ) ) ; bssl :: UniquePtr < SSL_CTX > client_ctx ( SSL_CTX_new ( TLS_method ( ) ) ) ; ASSERT_TRUE ( cert ) ; ASSERT_TRUE ( key ) ; ASSERT_TRUE ( server_ctx ) ; ASSERT_TRUE ( client_ctx ) ; ASSERT_TRUE ( SSL_CTX_use_certificate ( server_ctx . get ( ) , cert . get ( ) ) ) ; ASSERT_TRUE ( SSL_CTX_use_PrivateKey ( server_ctx . get ( ) , key . get ( ) ) ) ; ASSERT_TRUE ( SSL_CTX_set_max_proto_version ( client_ctx . get ( ) , TLS1_3_VERSION ) ) ; ASSERT_TRUE ( SSL_CTX_set_max_proto_version ( server_ctx . get ( ) , TLS1_3_VERSION ) ) ; SSL_CTX_set_select_certificate_cb ( server_ctx . get ( ) , [ ] ( const SSL_CLIENT_HELLO * client_hello ) -> ssl_select_cert_result_t { if ( ! SSL_set_max_proto_version ( client_hello -> ssl , TLS1_2_VERSION ) ) { return ssl_select_cert_error ; } return ssl_select_cert_success ; } ) ; bssl :: UniquePtr < SSL > client , server ; ASSERT_TRUE ( ConnectClientAndServer ( & client , & server , client_ctx . get ( ) , server_ctx . get ( ) ) ) ; EXPECT_EQ ( TLS1_2_VERSION , SSL_version ( client . get ( ) ) ) ; }
Test that the early callback can swap the maximum version.
Test that the early callback can swap the maximum version .