Skip to content

Commit

Permalink
tls: introduce tls::certificate_data type alias declaration
Browse files Browse the repository at this point in the history
  • Loading branch information
nielsdevreede-rl committed Jan 28, 2025
1 parent abfddd0 commit 4678025
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
4 changes: 3 additions & 1 deletion include/seastar/net/tls.hh
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,8 @@ namespace tls {
*/
future<std::vector<subject_alt_name>> get_alt_name_information(connected_socket& socket, std::unordered_set<subject_alt_name_type> types = {});

using certificate_data = std::vector<uint8_t>;

/**
* 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
Expand All @@ -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<std::vector<std::vector<uint8_t>>> get_peer_certificate_chain(connected_socket& socket);
future<std::vector<certificate_data>> get_peer_certificate_chain(connected_socket& socket);

/**
* Checks if the socket was connected using session resume.
Expand Down
6 changes: 3 additions & 3 deletions src/net/tls.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1790,7 +1790,7 @@ class session : public enable_lw_shared_from_this<session> {
}, std::move(types));
}

future<std::vector<std::vector<uint8_t>>> get_peer_certificate_chain() {
future<std::vector<certificate_data>> 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);
Expand Down Expand Up @@ -1938,7 +1938,7 @@ class tls_connected_socket_impl : public net::connected_socket_impl, public sess
future<std::vector<subject_alt_name>> get_alt_name_information(std::unordered_set<subject_alt_name_type> types) {
return _session->get_alt_name_information(std::move(types));
}
future<std::vector<std::vector<uint8_t>>> get_peer_certificate_chain() {
future<std::vector<certificate_data>> get_peer_certificate_chain() {
return _session->get_peer_certificate_chain();
}
future<> wait_input_shutdown() override {
Expand Down Expand Up @@ -2132,7 +2132,7 @@ future<std::vector<tls::subject_alt_name>> tls::get_alt_name_information(connect
return get_tls_socket(socket)->get_alt_name_information(std::move(types));
}

future<std::vector<std::vector<uint8_t>>> tls::get_peer_certificate_chain(connected_socket& socket) {
future<std::vector<tls::certificate_data>> tls::get_peer_certificate_chain(connected_socket& socket) {
return get_tls_socket(socket)->get_peer_certificate_chain();
}

Expand Down
2 changes: 1 addition & 1 deletion tests/unit/tls_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint8_t>(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<char *>(contents.data()), contents.size());
return contents;
};
Expand Down

0 comments on commit 4678025

Please sign in to comment.