-
Notifications
You must be signed in to change notification settings - Fork 122
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 TLS 1.3 cipher selection and fix SSL_get_ciphers #2092
Open
smittals2
wants to merge
38
commits into
aws:main
Choose a base branch
from
smittals2:get_ciphers
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 14 commits
Commits
Show all changes
38 commits
Select commit
Hold shift + click to select a range
bc7b951
combine the two cipher lists
smittals2 e80cb6e
defining default TLS 1.3 ciphersuites
smittals2 c49f32d
configure TLS 1.3 ciphersuites by default
smittals2 bfb369f
remove default TLS 13 ciphersuites macro
smittals2 ef0f455
fix update function for ctx->cipher_list
smittals2 aacb978
remove default tls13_cipher_list coonfiguirating in SSL_CTX
smittals2 b6f297b
testing for new SSL_Get_ciphers functionality
smittals2 749513a
configure TLS 1.3 ciphersuites by default
smittals2 1e818d5
modified existing tests to work with TLS 1.3 configured by default
smittals2 425e9a5
documentation update
smittals2 656b710
fixed logic for configuring in_group_flags
smittals2 2622e1e
changed TLS 1.3 ciphersuite ordering
smittals2 fe430f4
Merge branch 'main' into get_ciphers
smittals2 72603cc
add differentiation for AES HW acceleration when ordering ciphers for…
eb28574
use const
smittals2 5fcdd4a
remove old include
smittals2 d4e5047
clean up comments
smittals2 6707995
removing hardcoded tls1.3 logic pt1
smittals2 ff11f99
moved default tls1.3 ciphersuite preferences to internal header
smittals2 849bf37
cleaning up pt2
smittals2 3f467ff
fixing conditionals in collecting ciphers
smittals2 dbbd45c
changed cipherlist condition
smittals2 94d2189
minor pr comments
smittals2 7669f46
changed tls 1.3 cipher order
smittals2 fc0c20c
revert sorting order
smittals2 9ee29c8
new test for tls 1.3
smittals2 e38bfa3
modified ssl->config to hold tls 1.3 ciphersuite state
smittals2 dbd660a
revert default TLS 1.2 ciphersuites
smittals2 272ef8f
change uniqptr init
smittals2 0991f2f
minor edits to logic
smittals2 0d7b302
fixed test
smittals2 2c809d3
set Tls 1.3 ciphersuites explicitly
smittals2 7798ef6
Merge branch 'main' into get_ciphers
smittals2 8442723
changed SSLCipherPreferenceList initialization
smittals2 ae84e27
change server side cipher selection logic
smittals2 0e66ad6
added config/ctx testing
smittals2 a755968
indentation and documentation
smittals2 2c6d018
pr comments
smittals2 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -142,6 +142,7 @@ | |
|
||
#include <assert.h> | ||
#include <string.h> | ||
#include <vector> | ||
|
||
#include <openssl/err.h> | ||
#include <openssl/md5.h> | ||
|
@@ -1234,7 +1235,89 @@ static bool is_known_default_alias_keyword_filter_rule(const char *rule, | |
return false; | ||
} | ||
|
||
bool ssl_create_cipher_list(UniquePtr<SSLCipherPreferenceList> *out_cipher_list, | ||
// update_cipher_list updates |ctx->cipher_list| by: | ||
smittals2 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// 1. Removing any existing TLS 1.3 ciphersuites | ||
// 2. Adding configured ciphersuites from |ctx->tls13_cipher_list| | ||
// 3. Configuring a new |ctx->cipher_list->in_group_flags| | ||
// This function maintains the ordering of ciphersuites and places TLS 1.3 | ||
// ciphersuites at the front of the list. | ||
smittals2 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// Returns one on success and zero on failure. | ||
static int update_cipher_list(SSL_CTX *ctx) { | ||
bssl::UniquePtr<STACK_OF(SSL_CIPHER)> tmp_cipher_list; | ||
int num_removed_tls13_ciphers = 0, num_added_tls13_ciphers = 0; | ||
Array<bool> updated_in_group_flags; | ||
|
||
if (ctx->cipher_list && ctx->cipher_list->ciphers) { | ||
tmp_cipher_list.reset(sk_SSL_CIPHER_dup(ctx->cipher_list->ciphers.get())); | ||
} else { | ||
tmp_cipher_list.reset(sk_SSL_CIPHER_new_null()); | ||
} | ||
|
||
if (tmp_cipher_list == NULL) { | ||
smittals2 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return 0; | ||
} | ||
|
||
int num_updated_tls12_ciphers = sk_SSL_CIPHER_num(tmp_cipher_list.get()); | ||
|
||
// Delete any existing TLSv1.3 ciphersuites. These will be first in the list | ||
smittals2 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
while (sk_SSL_CIPHER_num(tmp_cipher_list.get()) > 0 && | ||
SSL_CIPHER_get_min_version(sk_SSL_CIPHER_value(tmp_cipher_list.get(), 0)) | ||
== TLS1_3_VERSION) { | ||
sk_SSL_CIPHER_delete(tmp_cipher_list.get(), 0); | ||
num_removed_tls13_ciphers++; | ||
num_updated_tls12_ciphers--; | ||
} | ||
|
||
// Insert the new TLSv1.3 ciphersuites with corresponding in_group_flags | ||
if (ctx->tls13_cipher_list != NULL && ctx->tls13_cipher_list->ciphers != NULL) { | ||
STACK_OF(SSL_CIPHER) *tls13_cipher_stack = ctx->tls13_cipher_list->ciphers.get(); | ||
num_added_tls13_ciphers = sk_SSL_CIPHER_num(tls13_cipher_stack); | ||
for (int i = sk_SSL_CIPHER_num(tls13_cipher_stack) - 1; i >= 0; i--) { | ||
const SSL_CIPHER *tls13_cipher = sk_SSL_CIPHER_value(tls13_cipher_stack, i); | ||
if (!sk_SSL_CIPHER_unshift(tmp_cipher_list.get(), tls13_cipher)) { | ||
return 0; | ||
} | ||
} | ||
} | ||
|
||
if (!updated_in_group_flags.Init(num_added_tls13_ciphers + num_updated_tls12_ciphers)) { | ||
return 0; | ||
} | ||
std::fill(updated_in_group_flags.begin(), updated_in_group_flags.end(), false); | ||
|
||
// Copy in_group_flags from |ctx->tls13_cipher_list| | ||
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. What does 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. |
||
if (ctx->tls13_cipher_list && ctx->tls13_cipher_list->in_group_flags) { | ||
const auto& tls13_flags = ctx->tls13_cipher_list->in_group_flags; | ||
// Ensure the last element in in_group_flags is 0. The last ciphersuite | ||
// in a list must be the end of any group in that list. | ||
if (tls13_flags[num_added_tls13_ciphers - 1] != 0) { | ||
tls13_flags[num_added_tls13_ciphers - 1] = false; | ||
} | ||
for (int i = 0; i < num_added_tls13_ciphers; i++) { | ||
updated_in_group_flags[i] = tls13_flags[i]; | ||
} | ||
} | ||
|
||
// Copy in_group_flags from |ctx->cipher_list| | ||
if (ctx->cipher_list && ctx->cipher_list->in_group_flags) { | ||
for (int i = 0; i < num_updated_tls12_ciphers; i++) { | ||
updated_in_group_flags[i + num_added_tls13_ciphers] = | ||
ctx->cipher_list->in_group_flags[i + num_removed_tls13_ciphers]; | ||
} | ||
} | ||
|
||
Span<const bool> flags_span(updated_in_group_flags.data(), updated_in_group_flags.size()); | ||
ctx->cipher_list = MakeUnique<SSLCipherPreferenceList>(); | ||
if (ctx->cipher_list == NULL) { | ||
return 0; | ||
} | ||
ctx->cipher_list->Init(std::move(tmp_cipher_list), flags_span); | ||
|
||
return 1; | ||
} | ||
|
||
bool ssl_create_cipher_list(SSL_CTX *ctx, | ||
UniquePtr<SSLCipherPreferenceList> *out_cipher_list, | ||
const bool has_aes_hw, const char *rule_str, | ||
bool strict, bool config_tls13) { | ||
// Return with error if nothing to do. | ||
|
@@ -1367,6 +1450,9 @@ bool ssl_create_cipher_list(UniquePtr<SSLCipherPreferenceList> *out_cipher_list, | |
return false; | ||
} | ||
|
||
// Update |ctx->cipher_list| with any ciphers in |ctx->tls13_cipher_list| | ||
update_cipher_list(ctx); | ||
smittals2 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
return true; | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Please update SSL_get_ciphers documentation to note it returns all ciphers 1.2 and 1.3
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.
The current documentation covers this case ("cipher list for |ssl|") but I'll make it more explicit. We just weren't living up to this contract initially.