Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

net: functions describing ssl connection #2651

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions include/seastar/net/tls.hh
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,30 @@ namespace tls {
*/
future<session_data> get_session_resume_data(connected_socket&);

/**
* Returns true if the hanshake has been completed.
*
* If the socket is not connected a system_error exception will be thrown.
* If the socket is not a TLS socket an exception will be thrown.
*/
bool is_operational(connected_socket& socket);

/**
* Returns the cipher suite used in the connection.
*
* If the socket is not connected a system_error exception will be thrown.
* If the socket is not a TLS socket an exception will be thrown.
*/
sstring get_cipher_suite(connected_socket& socket);

/**
* Returns the protocol version used in the connection.
*
* If the socket is not connected a system_error exception will be thrown.
* If the socket is not a TLS socket an exception will be thrown.
*/
sstring get_protocol_version(connected_socket& socket);

std::ostream& operator<<(std::ostream&, const subject_alt_name::value_type&);
std::ostream& operator<<(std::ostream&, const subject_alt_name&);

Expand Down
34 changes: 34 additions & 0 deletions src/net/tls.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1810,6 +1810,19 @@ class session : public enable_lw_shared_from_this<session> {
}

struct session_ref;

bool is_operational() const {
return gnutls_record_get_direction(*this) >= 0; // handshake succeeded
}

sstring get_cipher_suite() const {
return gnutls_ciphersuite_get(*this);
}

sstring get_protocol_version() const {
return gnutls_protocol_get_name(gnutls_protocol_get_version(*this));
}

private:

using x509_ctr_ptr = std::unique_ptr<gnutls_x509_crt_int, void (*)(gnutls_x509_crt_t)>;
Expand Down Expand Up @@ -1953,6 +1966,15 @@ class tls_connected_socket_impl : public net::connected_socket_impl, public sess
future<session_data> get_session_resume_data() {
return _session->get_session_resume_data();
}
bool is_operational() {
return _session->is_operational();
}
sstring get_cipher_suite() {
return _session->get_cipher_suite();
}
sstring get_protocol_version() {
return _session->get_protocol_version();
}
};


Expand Down Expand Up @@ -2147,6 +2169,18 @@ future<tls::session_data> tls::get_session_resume_data(connected_socket& socket)
return get_tls_socket(socket)->get_session_resume_data();
}

bool tls::is_operational(connected_socket& socket) {
return get_tls_socket(socket)->is_operational();
}

sstring tls::get_cipher_suite(connected_socket& socket) {
return get_tls_socket(socket)->get_cipher_suite();
}

sstring tls::get_protocol_version(connected_socket& socket) {
return get_tls_socket(socket)->get_protocol_version();
}

std::string_view tls::format_as(subject_alt_name_type type) {
switch (type) {
case subject_alt_name_type::dnsname:
Expand Down