Skip to content

Commit 4c72f60

Browse files
committed
Bug#35317484 router fails to start with ECC certificates
Starting Router with a ECC certificate fails with error-msg: no RSA certificate even though router should run fine with ECC certificates. Change ------ - Allow ECC certificates - added test which starts router with ECDSA, ECDH_RSA and ECDH_DSA certs. Change-Id: I7a1e4d05110223406cfef88d7e24d6bf6e16bfbf
1 parent 71d81e3 commit 4c72f60

File tree

2 files changed

+89
-5
lines changed

2 files changed

+89
-5
lines changed

router/src/harness/src/tls_server_context.cc

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -350,13 +350,21 @@ stdx::expected<void, std::error_code> TlsServerContext::load_key_and_cert(
350350
// internal pointer, don't free
351351
if (X509 *x509 = SSL_CTX_get0_certificate(ssl_ctx_.get())) {
352352
auto key_size_res = get_rsa_key_size(x509);
353-
if (!key_size_res) return stdx::make_unexpected(key_size_res.error());
353+
if (!key_size_res) {
354+
auto ec = key_size_res.error();
354355

355-
const auto key_size = *key_size_res;
356+
if (ec != TlsCertErrc::kNoRSACert) {
357+
return stdx::make_unexpected(key_size_res.error());
358+
}
359+
360+
// if it isn't a RSA Key ... just continue.
361+
} else {
362+
const auto key_size = *key_size_res;
356363

357-
if (key_size < kMinRsaKeySize) {
358-
return stdx::make_unexpected(
359-
make_error_code(TlsCertErrc::kRSAKeySizeToSmall));
364+
if (key_size < kMinRsaKeySize) {
365+
return stdx::make_unexpected(
366+
make_error_code(TlsCertErrc::kRSAKeySizeToSmall));
367+
}
360368
}
361369
} else {
362370
// doesn't exist

router/tests/component/test_routing.cc

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,82 @@ TEST_F(RouterRoutingTest, ConnectTimeoutShutdownEarlyXProtocol) {
419419
connect_thread.join();
420420
}
421421

422+
TEST_F(RouterRoutingTest, EccCertificate) {
423+
RecordProperty("Bug", "35317484");
424+
RecordProperty("Description",
425+
"Check if router can start with a ECC certificate");
426+
427+
const auto server_classic_port = port_pool_.get_next_available();
428+
const auto server_x_port = port_pool_.get_next_available();
429+
const auto router_classic_ecdh_rsa_port = port_pool_.get_next_available();
430+
const auto router_classic_ecdh_dsa_port = port_pool_.get_next_available();
431+
const auto router_classic_ecdsa_port = port_pool_.get_next_available();
432+
433+
const std::string json_stmts = get_data_dir().join("bootstrap_gr.js").str();
434+
435+
launch_mysql_server_mock(json_stmts, server_classic_port, EXIT_SUCCESS, false,
436+
/*http_port*/ 0, server_x_port);
437+
438+
TempDirectory conf_dir("conf-ecc-certificate");
439+
auto writer = config_writer(conf_dir.name());
440+
writer.section(
441+
"routing:classic_ecdh_rsa",
442+
{
443+
{"bind_port", std::to_string(router_classic_ecdh_rsa_port)},
444+
{"mode", "read-write"},
445+
{"destinations", "127.0.0.1:" + std::to_string(server_classic_port)},
446+
{"routing_strategy", "round-robin"},
447+
{"protocol", "classic"},
448+
{"client_ssl_key",
449+
SSL_TEST_DATA_DIR "/ecdh_rsa_certs/server-key.pem"},
450+
{"client_ssl_cert",
451+
SSL_TEST_DATA_DIR "/ecdh_rsa_certs/server-cert.pem"},
452+
});
453+
writer.section(
454+
"routing:classic_ecdh_dsa",
455+
{
456+
{"bind_port", std::to_string(router_classic_ecdh_dsa_port)},
457+
{"mode", "read-write"},
458+
{"destinations", "127.0.0.1:" + std::to_string(server_classic_port)},
459+
{"routing_strategy", "round-robin"},
460+
{"protocol", "classic"},
461+
{"client_ssl_key",
462+
SSL_TEST_DATA_DIR "/ecdh_dsa_certs/server-key.pem"},
463+
{"client_ssl_cert",
464+
SSL_TEST_DATA_DIR "/ecdh_dsa_certs/server-cert.pem"},
465+
});
466+
writer.section(
467+
"routing:classic_ecdsa",
468+
{
469+
{"bind_port", std::to_string(router_classic_ecdsa_port)},
470+
{"mode", "read-write"},
471+
{"destinations", "127.0.0.1:" + std::to_string(server_classic_port)},
472+
{"routing_strategy", "round-robin"},
473+
{"protocol", "classic"},
474+
{"client_ssl_key", SSL_TEST_DATA_DIR "/ecdsa_certs/server-key.pem"},
475+
{"client_ssl_cert", SSL_TEST_DATA_DIR "/ecdsa_certs/server-cert.pem"},
476+
});
477+
ASSERT_NO_FATAL_FAILURE(router_spawner().spawn({"-c", writer.write()}));
478+
479+
{
480+
mysqlrouter::MySQLSession client;
481+
EXPECT_NO_THROW(client.connect("127.0.0.1", router_classic_ecdh_rsa_port,
482+
"root", "fake-pass", "", ""));
483+
}
484+
485+
{
486+
mysqlrouter::MySQLSession client;
487+
EXPECT_NO_THROW(client.connect("127.0.0.1", router_classic_ecdh_dsa_port,
488+
"root", "fake-pass", "", ""));
489+
}
490+
491+
{
492+
mysqlrouter::MySQLSession client;
493+
EXPECT_NO_THROW(client.connect("127.0.0.1", router_classic_ecdsa_port,
494+
"root", "fake-pass", "", ""));
495+
}
496+
}
497+
422498
/**
423499
* check empty packet leads to an error.
424500
*

0 commit comments

Comments
 (0)