-
Notifications
You must be signed in to change notification settings - Fork 1.1k
feat: add configurable cipher suites for tls listening #10505
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
de67dbc
feat: add configurable cipher suites for tls listening
Emyrk a8c9b76
add unit tests
Emyrk f9c139a
Add tls options for ciphers
Emyrk 54b64f9
plumb through deployment options for ciphers
Emyrk 636d31c
tls.VersionName is go 1.21, copy the function
Emyrk 284653f
update golden files
Emyrk f4a679e
Nolint
Emyrk 9ffabc9
fixup! Nolint
Emyrk fc03499
Improve error message
Emyrk 17029bf
fixup! Improve error message
Emyrk c1584bf
update comment
Emyrk cab8c3b
Merge remote-tracking branch 'origin/main' into stevenmasley/choose_c…
Emyrk d0353b0
Fix typo
Emyrk 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
Next
Next commit
feat: add configurable cipher suites for tls listening
- Loading branch information
commit de67dbc220d480a6cc86ffe006b671226f6c8053
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| package cli | ||
|
|
||
| import ( | ||
| "bytes" | ||
| "context" | ||
| "crypto/tls" | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
|
|
||
| "cdr.dev/slog/sloggers/sloghuman" | ||
| "github.com/stretchr/testify/require" | ||
|
|
||
| "cdr.dev/slog" | ||
| ) | ||
|
|
||
| func Test_configureCipherSuites(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| cipherNames := func(ciphers []*tls.CipherSuite) []string { | ||
| var names []string | ||
| for _, c := range ciphers { | ||
| names = append(names, c.Name) | ||
| } | ||
| return names | ||
| } | ||
|
|
||
| cipherIDs := func(ciphers []*tls.CipherSuite) []uint16 { | ||
| var ids []uint16 | ||
| for _, c := range ciphers { | ||
| ids = append(ids, c.ID) | ||
| } | ||
| return ids | ||
| } | ||
|
|
||
| tests := []struct { | ||
| name string | ||
| wantErr string | ||
| wantWarnings []string | ||
| inputCiphers []string | ||
| minTLS uint16 | ||
| maxTLS uint16 | ||
| allowInsecure bool | ||
| expectCiphers []uint16 | ||
| }{ | ||
| { | ||
| name: "AllowInsecure", | ||
| minTLS: tls.VersionTLS10, | ||
| maxTLS: tls.VersionTLS13, | ||
| inputCiphers: append(cipherNames(tls.CipherSuites()), tls.InsecureCipherSuites()[0].Name), | ||
| allowInsecure: true, | ||
| wantWarnings: []string{ | ||
| "insecure tls cipher specified", | ||
| }, | ||
| expectCiphers: append(cipherIDs(tls.CipherSuites()), tls.InsecureCipherSuites()[0].ID), | ||
| }, | ||
| // Errors | ||
| { | ||
| name: "NoCiphers", | ||
| minTLS: tls.VersionTLS10, | ||
| maxTLS: tls.VersionTLS13, | ||
| wantErr: "no tls ciphers supported", | ||
| }, | ||
| { | ||
| name: "InsecureNotAllowed", | ||
| minTLS: tls.VersionTLS10, | ||
| maxTLS: tls.VersionTLS13, | ||
| inputCiphers: append(cipherNames(tls.CipherSuites()), tls.InsecureCipherSuites()[0].Name), | ||
| wantErr: "insecure tls ciphers specified", | ||
| }, | ||
| { | ||
| name: "TLS1.3", | ||
| minTLS: tls.VersionTLS13, | ||
| maxTLS: tls.VersionTLS13, | ||
| inputCiphers: cipherNames(tls.CipherSuites()), | ||
| wantErr: "tls ciphers cannot be specified when using minimum tls version 1.3", | ||
| }, | ||
| } | ||
| for _, tt := range tests { | ||
| tt := tt | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| t.Parallel() | ||
| ctx := context.Background() | ||
| var out bytes.Buffer | ||
| logger := slog.Make(sloghuman.Sink(&out)) | ||
|
|
||
| found, err := configureCipherSuites(ctx, logger, tt.inputCiphers, tt.allowInsecure, tt.minTLS, tt.maxTLS) | ||
| if tt.wantErr != "" { | ||
| require.ErrorContains(t, err, tt.wantErr) | ||
| } else { | ||
| require.NoError(t, err, "no error") | ||
| require.ElementsMatch(t, tt.expectCiphers, found, "expected ciphers") | ||
| if len(tt.wantWarnings) > 0 { | ||
| logger.Sync() | ||
| for _, w := range tt.wantWarnings { | ||
| assert.Contains(t, out.String(), w, "expected warning") | ||
| } | ||
| } | ||
| } | ||
| }) | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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
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.
Uh oh!
There was an error while loading. Please reload this page.