diff --git a/include/seastar/net/tls.hh b/include/seastar/net/tls.hh index 36bbfb9095..cdef240228 100644 --- a/include/seastar/net/tls.hh +++ b/include/seastar/net/tls.hh @@ -494,6 +494,8 @@ namespace tls { */ future> get_alt_name_information(connected_socket& socket, std::unordered_set types = {}); + using certificate_data = std::vector; + /** * Get the raw certificate (chain) that the connected peer is using. * This function forces the TLS handshake. If the handshake didn't happen before the @@ -503,7 +505,7 @@ namespace tls { * certificate during the handshake, the function returns an empty certificate chain. * If the socket is not connected the system_error exception will be thrown. */ - future>> get_peer_certificate_chain(connected_socket& socket); + future> get_peer_certificate_chain(connected_socket& socket); /** * Checks if the socket was connected using session resume. diff --git a/src/net/tls.cc b/src/net/tls.cc index 8806d95385..3a3aa0d54f 100644 --- a/src/net/tls.cc +++ b/src/net/tls.cc @@ -1790,7 +1790,7 @@ class session : public enable_lw_shared_from_this { }, std::move(types)); } - future>> get_peer_certificate_chain() { + future> get_peer_certificate_chain() { return state_checked_access([this] { unsigned int list_size = 0; const gnutls_datum_t* client_cert_list = gnutls_certificate_get_peers(*this, &list_size); @@ -1938,7 +1938,7 @@ class tls_connected_socket_impl : public net::connected_socket_impl, public sess future> get_alt_name_information(std::unordered_set types) { return _session->get_alt_name_information(std::move(types)); } - future>> get_peer_certificate_chain() { + future> get_peer_certificate_chain() { return _session->get_peer_certificate_chain(); } future<> wait_input_shutdown() override { @@ -2132,7 +2132,7 @@ future> tls::get_alt_name_information(connect return get_tls_socket(socket)->get_alt_name_information(std::move(types)); } -future>> tls::get_peer_certificate_chain(connected_socket& socket) { +future> tls::get_peer_certificate_chain(connected_socket& socket) { return get_tls_socket(socket)->get_peer_certificate_chain(); } diff --git a/tests/unit/tls_test.cc b/tests/unit/tls_test.cc index b008d3ff16..f437d5380f 100644 --- a/tests/unit/tls_test.cc +++ b/tests/unit/tls_test.cc @@ -1483,7 +1483,7 @@ SEASTAR_THREAD_TEST_CASE(test_peer_certificate_chain_handling) { c.shutdown_output(); auto read_file = [](std::filesystem::path const& path) { - auto contents = std::vector(std::filesystem::file_size(path)); + auto contents = tls::certificate_data(std::filesystem::file_size(path)); std::ifstream{path, std::ios_base::binary}.read(reinterpret_cast(contents.data()), contents.size()); return contents; };