-
Notifications
You must be signed in to change notification settings - Fork 1.6k
tls: Make session resume key shared across credentials builders creds #2709
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -339,6 +339,13 @@ future<tls::x509_cert> tls::x509_cert::from_file( | |
|
||
// wrapper for gnutls_datum, with raii free | ||
struct gnutls_datum : public gnutls_datum_t { | ||
gnutls_datum(size_t s) { | ||
data = reinterpret_cast<unsigned char*>(gnutls_malloc(s)); | ||
if (data == nullptr) { | ||
throw std::bad_alloc(); | ||
} | ||
size = s; | ||
} | ||
gnutls_datum() { | ||
data = nullptr; | ||
size = 0; | ||
|
@@ -436,12 +443,17 @@ class tls::certificate_credentials::impl: public gnutlsobj { | |
client_auth get_client_auth() const { | ||
return _client_auth; | ||
} | ||
void set_session_resume_mode(session_resume_mode m) { | ||
void set_session_resume_mode(session_resume_mode m, std::span<const uint8_t> key = {}) { | ||
_session_resume_mode = m; | ||
// (re-)generate session key | ||
if (m != session_resume_mode::NONE) { | ||
_session_resume_key = {}; | ||
gnutls_session_ticket_key_generate(&_session_resume_key); | ||
if (key.empty()) { | ||
gtls_chk(gnutls_session_ticket_key_generate(&_session_resume_key)); | ||
} else { | ||
_session_resume_key = gnutls_datum(key.size()); | ||
std::copy(key.begin(), key.end(), _session_resume_key.data); | ||
} | ||
} | ||
} | ||
session_resume_mode get_session_resume_mode() const { | ||
|
@@ -710,6 +722,11 @@ void tls::credentials_builder::set_priority_string(const sstring& prio) { | |
|
||
void tls::credentials_builder::set_session_resume_mode(session_resume_mode m) { | ||
_session_resume_mode = m; | ||
if (m != session_resume_mode::NONE) { | ||
gnutls_datum key; | ||
gtls_chk(gnutls_session_ticket_key_generate(&key)); | ||
_session_resume_key.assign(key.data, key.data + key.size); | ||
} | ||
} | ||
Comment on lines
723
to
730
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just an idea, If we want to tls renegotiation to work even when node is being restarted we need Which means we will need another API that could feed pregenerated There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that is unnecessary. If you have node restarts so frequent it impacts TLS session management, you have a bigger problem. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
It is not about frequency, it is about of amount of clients that are trying to reconnect at the same time. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The point is that a restart should be infrequent. Connections can use session resume across the nodes uptime or the ticket expiry, whichever comes first (lets hope the latter). But also remember that storing the session key across restarts would more or less require them to be clean restarts (because we do want to refresh the key at least on cert reload etc), which, in the case of crashes, makes it even less useful. |
||
|
||
template<typename Blobs, typename Visitor> | ||
|
@@ -760,7 +777,7 @@ void tls::credentials_builder::apply_to(certificate_credentials& creds) const { | |
|
||
creds._impl->set_client_auth(_client_auth); | ||
// Note: this causes server session key rotation on cert reload | ||
creds._impl->set_session_resume_mode(_session_resume_mode); | ||
creds._impl->set_session_resume_mode(_session_resume_mode, std::span{_session_resume_key.begin(), _session_resume_key.end()}); | ||
} | ||
|
||
shared_ptr<tls::certificate_credentials> tls::credentials_builder::build_certificate_credentials() const { | ||
|
@@ -925,6 +942,10 @@ class tls::reloadable_credentials_base { | |
return; | ||
} | ||
try { | ||
// force rebuilding session resume mode key if | ||
// enabled. should not reuse sessions across certificate | ||
// change (should not work anyway) | ||
set_session_resume_mode(_session_resume_mode); | ||
if (_creds) { | ||
_creds->rebuild(*this); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While this is internal, it's still a dangerous constructor (esp. the non-explicit conversion from any pointer).
Please change to std::span<std::byte>.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better solution is to make the constructor only take a size and do the alloc internally, as the memory must be allocated by gnutls_malloc. Better to enforce.