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

Rework set_external_psks to use opaque structures #2557

Merged
merged 9 commits into from
Feb 10, 2021

Conversation

lrstewart
Copy link
Contributor

@lrstewart lrstewart commented Feb 4, 2021

Description of changes:

Part 1 of correcting the PSK APIs to use opaque structures. This change is solely focused on s2n_connection_set_external_psks. s2n_psk_selection_callback is out of scope.

Most of the test changes are due to name / return type changes, but I also add some additional validation since more APIs will now be public.

Call-outs:

I kept the methods for setting identity and secret separate, although they could possibly be combined with each other or with the _new method. However, I think separate methods are clearer and easier to use.

Testing:

How is this change tested (unit tests, fuzz tests, etc.)? Unit tests

Is this a refactor change? Yes, although it changes inputs rather than the underlying logic. The old tests continue working, just with some name changes.

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

@lrstewart lrstewart changed the title Rework _set_external_psks to use opaque structures Rework set_external_psks to use opaque structures Feb 4, 2021
@codecov
Copy link

codecov bot commented Feb 4, 2021

Codecov Report

Merging #2557 (bc91404) into main (5620b28) will decrease coverage by 0.01%.
The diff coverage is 88.09%.

@@            Coverage Diff             @@
##             main    #2557      +/-   ##
==========================================
- Coverage   82.16%   82.14%   -0.02%     
==========================================
  Files         272      272              
  Lines       19092    19133      +41     
==========================================
+ Hits        15686    15717      +31     
- Misses       3406     3416      +10     

Impacted file tree graph

@lrstewart lrstewart marked this pull request as ready for review February 4, 2021 21:02
tls/s2n_psk.c Outdated Show resolved Hide resolved
tls/s2n_psk.c Outdated
if (psk->type == S2N_PSK_TYPE_EXTERNAL) {
GUARD(s2n_psk_free(psk));
GUARD_AS_POSIX(s2n_psk_wipe(psk));
Copy link
Contributor

@maddeleine maddeleine Feb 5, 2021

Choose a reason for hiding this comment

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

Why are we wiping the psk instead of freeing it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No logic has actually changed here-- I just renamed "s2n_psk_free" to "s2n_psk_wipe", which is more accurate. We need to free all the blobs allocated for the psk, but not the memory allocated for the psk data structure itself. The memory allocated for the psk data structure is owned by the s2n_array.

We should use uint32_t to count PSKs, since the max length of an
s2n_array is uint32_max. I also added a test to makes sure that
we handle too-large extensions, in case the customer configures
too many PSKs.
Only the client sends its identity list over the wire.
tls/s2n_psk.c Outdated Show resolved Hide resolved
error/s2n_errno.c Outdated Show resolved Hide resolved
error/s2n_errno.h Outdated Show resolved Hide resolved
tls/s2n_psk.c Outdated Show resolved Hide resolved
tls/s2n_psk.c Show resolved Hide resolved
tls/s2n_psk.c Outdated Show resolved Hide resolved
tls/s2n_psk.c Show resolved Hide resolved
tls/s2n_psk.c Outdated Show resolved Hide resolved
tls/s2n_psk.h Show resolved Hide resolved
tls/s2n_psk.c Outdated Show resolved Hide resolved
utils/s2n_safety.h Show resolved Hide resolved
tls/s2n_psk.c Show resolved Hide resolved
tls/s2n_psk.h Show resolved Hide resolved
tls/s2n_psk.h Outdated Show resolved Hide resolved
@lrstewart lrstewart merged commit bcebb35 into aws:main Feb 10, 2021
@lrstewart lrstewart deleted the psk_apis_1 branch February 10, 2021 21:33
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.

5 participants