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

Add set_ticket_key_callback (SSL_CTX_set_tlsext_ticket_key_cb) #330

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

toidiu
Copy link

@toidiu toidiu commented Mar 11, 2025

Add a wrapper for the SSL_CTX_set_tlsext_ticket_key_cb, which allows consumers to configure the EVP_CIPHER_CTX and HMAC_CTX used for encrypting/decrypting session tickets.

See https://docs.openssl.org/1.0.2/man3/SSL_CTX_set_tlsext_ticket_key_cb/ for more details.

Add a wrapper for the `SSL_CTX_set_tlsext_ticket_key_cb`, which allows
consumers to configure the EVP_CIPHER_CTX and HMAC_CTX used for
encrypting/decrypting session tickets.

See https://docs.openssl.org/1.0.2/man3/SSL_CTX_set_tlsext_ticket_key_cb/
for more details.
@toidiu toidiu marked this pull request as ready for review March 11, 2025 04:29
/// # Note
///
/// This is a decryption specific status code.
DecryptTicketUnrecognized,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically decryption can fail due to a server-side issue, so might be better to name this variant DecryptTicketFailed

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this mode, callback returns -1 to abort the handshake, 0 if the ticket key was unrecognized, and 1 or 2 on success. If it returns 2, the ticket will be renewed.

I got unrecognized wording from the boring docs and took it to mean that the server couldn't find the ticket when it tried to lookup the key_name in its store. Shouldn't a server-side issue be an Error?

In this mode, callback returns 1 on success, 0 to decline sending a ticket, and -1 on error.

Also since we are on an older version of boring, the "0 to decline sending a ticket" code doesn't apply to our version yet. Once we upgrade, this name should be change to be less Decrypting specific. I am not familiar how liberally we handle breaking changes in this repo and wonder if we should rename this to be more future proof?

Copy link
Collaborator

@rushilmehra rushilmehra Mar 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah interestingly boringssl changed the documentation and added support for ejecting from encryption during the callback ~4 months ago

Boringssl breaks its API at will, but we follow semver for our public API, so it's best to future-proof as much as possible

Copy link
Author

@toidiu toidiu Mar 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Boringssl breaks its API at will, but we follow semver for our public API, so it's best to future-proof as much as possible

I updated the the status code to Noop which seems appropriate for both cases in the future: 2a43889

Also added a test for the Noop decryption case: 28f7678

Comment on lines +1239 to +1240
#[cfg(feature = "rpk")]
assert!(!self.is_rpk, "This API is not supported for RPK");
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I copied this from the other callbacks and not sure if it applies here. What is RPK and does it apply for this callback?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RPK is raw public keys (https://datatracker.ietf.org/doc/html/rfc7250), it's fine to leave these callbacks unimplemented there

@toidiu toidiu force-pushed the toidiu/ticket_key_callback branch from 5a54a4d to 28f7678 Compare March 11, 2025 19:22
@toidiu toidiu requested a review from rushilmehra March 11, 2025 21:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants