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

Refactor some s2n_resume functions #4648

Merged
merged 4 commits into from
Jul 23, 2024
Merged

Refactor some s2n_resume functions #4648

merged 4 commits into from
Jul 23, 2024

Conversation

maddeleine
Copy link
Contributor

@maddeleine maddeleine commented Jul 15, 2024

Resolved issues:

N/A

Description of changes:

I'm planning on making some changes to our resumption feature and it's going to be much easier for me to make these changes if I refactor the existing code. Essentially in this PR I refactored the encrypt/decrypt session ticket functions as follows:

  1. Changed name of functions to match module
  2. Changed to S2N_RESULT
  3. Changed ordering of initializations to be easier to follow
  4. Defer cleanups when possible

Call-outs:

Gist of old decrypt_ticket and old decrypt_cache functions: https://gist.github.com/maddeleine/284a6f2d7769cc05b74e509e61fa18a6.

Testing:

All existing tests pass. Looking for recommendations about tests I could add here.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

tls/s2n_resume.h Outdated Show resolved Hide resolved
tls/s2n_resume.c Outdated Show resolved Hide resolved
tls/s2n_resume.c Outdated Show resolved Hide resolved
tls/s2n_resume.c Outdated Show resolved Hide resolved
tls/s2n_resume.c Outdated Show resolved Hide resolved
tls/s2n_resume.c Outdated Show resolved Hide resolved
tls/s2n_resume.c Outdated Show resolved Hide resolved
tls/s2n_resume.c Outdated Show resolved Hide resolved
tls/s2n_resume.c Show resolved Hide resolved
tls/s2n_resume.c Outdated
Comment on lines 880 to 881

/* Session caching feature also uses this codepath */
Copy link
Contributor

Choose a reason for hiding this comment

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

This probably needs a more detailed comment. Without knowing the history / digging into s2n_deserialize_resumption_state, branching on the arguments to s2n_deserialize_resumption_state looks pretty strange.

Should we also open an issue to fix that logic? It works, but it's pretty odd.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What's the fix for this logic? No matter what, we're going to need a branch somewhere to make sure session cache isn't using the middle parameter.

Copy link
Contributor

Choose a reason for hiding this comment

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

Somewhere, but here may not be the right place. It's very unclear why we're branching here, and passing "NULL" to the method is odd. I'd say ideally we should branch further down the stack where the parameter should either be used or not used. Like, where we're checking for NULL.

Copy link
Contributor Author

@maddeleine maddeleine Jul 17, 2024

Choose a reason for hiding this comment

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

I took out the branching logic. That middle parameter never gets used if you're entering the codepath from the decrypt function in TLS1.2. There is still a branch to make sure the last code paragraph doesn't get executed if you're not using tickets.

Copy link
Contributor

Choose a reason for hiding this comment

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

Since there's confusion here, I was wondering if we could somehow write a test to prove no behavior change.

s2n_decrypt_session_cache was only called by s2n_resume_from_cache, which is only called here. That means that s2n_decrypt_session_cache could only be called for a TLS1.2 server connection.

At the other end, the "ticket" parameter is only used by s2n_deserialize_resumption_state for TLS1.2 tickets + client connections OR TLS1.3 tickets.

So I agree that the "ticket" parameter never gets used on the s2n_decrypt_session_cache path. We'd somehow need a TLS1.2 server decrypting a TLS1.3 ticket. Since s2n_resume_from_cache already assumes TLS1.2 tickets (it only allocates enough space for a TLS1.2 ticket), we're not making that path worse.

But that also means that testing this would be hard. The best I can think of is to resume from the session cache and verify that 1) conn->ticket isn't set 2) no psk exists. Not exactly a great test, so feel free not to implement it. Two people scrutinizing the code path is probably sufficient.

tls/s2n_resume.c Outdated Show resolved Hide resolved
tls/s2n_resume.c Outdated Show resolved Hide resolved
tls/s2n_resume.c Outdated Show resolved Hide resolved
tls/s2n_resume.c Outdated Show resolved Hide resolved
tls/s2n_resume.c Show resolved Hide resolved
@maddeleine maddeleine enabled auto-merge (squash) July 23, 2024 20:46
@maddeleine maddeleine merged commit c3a5680 into main Jul 23, 2024
37 checks passed
@maddeleine maddeleine deleted the stek_cleanup branch July 23, 2024 21:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants