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

feat(bindings): add psk selection api #5101

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jmayclin
Copy link
Contributor

@jmayclin jmayclin commented Feb 8, 2025

Description of changes:

Add PSK Selection API

All known use cases for the Psk Callback are mut by just iterating over the identities. This functionality is exposed through the IdentitySelector.

If we were to add additional functionality to the OfferedPsk in the future, we might also want to expose that. So I added that workflow as well, through the OfferedPskSelector (gated behind #(cfg(test)))

Call-outs:

The lifetime stuff is rather dense internally, but the actual trait definition/implementors of the trait don't really have to directly deal with any of the complexity.

Testing:

Unit tests were added for the PSK callbacks

I also did some quite sanity checks to ensure that the lifetime stuff was preventing bad scenarios.

multiple selectors:

            let mut more_ids = psk_list.identities().unwrap();
            let mut offered_psks = psk_list.offered_psks().unwrap();
            let thing = more_ids.next();
            let psk = offered_psks.advance();

results in

error[E0499]: cannot borrow `*psk_list` as mutable more than once at a time
   --> s2n-tls/src/callbacks/psk_selection.rs:409:36
    |
408 |             let mut more_ids = psk_list.identities().unwrap();
    |                                -------- first mutable borrow occurs here
409 |             let mut offered_psks = psk_list.offered_psks().unwrap();
    |                                    ^^^^^^^^ second mutable borrow occurs here
410 |             let thing = more_ids.next();
    |                         -------- first borrow later used here

Repeated borrow from offered psk selector:

            let mut offered_psks = psk_list.offered_psks().unwrap();
            let psk = offered_psks.advance().unwrap().unwrap();
            let psk2 = offered_psks.advance().unwrap().unwrap();
            psk.identity();

results in

error[E0499]: cannot borrow `offered_psks` as mutable more than once at a time
   --> s2n-tls/src/callbacks/psk_selection.rs:410:24
    |
409 |             let psk = offered_psks.advance().unwrap().unwrap();
    |                       ------------ first mutable borrow occurs here
410 |             let psk2 = offered_psks.advance().unwrap().unwrap();
    |                        ^^^^^^^^^^^^ second mutable borrow occurs here
411 |             psk.identity();
    |             --- first borrow later used here

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

@github-actions github-actions bot added the s2n-core team label Feb 8, 2025
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.

1 participant