-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
credentials: Apply defaults to TLS configs provided through GetConfigForClient #7754
Merged
arjan-bal
merged 6 commits into
grpc:master
from
arjan-bal:defaults-in-get-config-for-client
Oct 22, 2024
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
87016c7
Apply secure defaults to TLS configs provided through GetConfigForClient
arjan-bal 67dfb32
Add cases which return nil from GetConfigForClient
arjan-bal 042ec4b
better variable names
arjan-bal 0b1146d
Use a getter for tls config in tests
arjan-bal 5da078b
Inline TLS configs in test cases
arjan-bal 0922abc
Merge remote-tracking branch 'source/master' into defaults-in-get-con…
arjan-bal 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -200,25 +200,41 @@ | |
|
||
// NewTLS uses c to construct a TransportCredentials based on TLS. | ||
func NewTLS(c *tls.Config) TransportCredentials { | ||
tc := &tlsCreds{credinternal.CloneTLSConfig(c)} | ||
tc.config.NextProtos = credinternal.AppendH2ToNextProtos(tc.config.NextProtos) | ||
cfg := applyDefaults(c) | ||
if cfg.GetConfigForClient != nil { | ||
oldFn := cfg.GetConfigForClient | ||
cfg.GetConfigForClient = func(hello *tls.ClientHelloInfo) (*tls.Config, error) { | ||
cfgForClient, err := oldFn(hello) | ||
if err != nil || cfgForClient == nil { | ||
return cfgForClient, err | ||
gtcooke94 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
return applyDefaults(cfgForClient), nil | ||
} | ||
} | ||
tc := &tlsCreds{config: cfg} | ||
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. nit tc -> creds 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. removed the temporary variable an inlined the return. |
||
return tc | ||
} | ||
|
||
func applyDefaults(c *tls.Config) *tls.Config { | ||
config := credinternal.CloneTLSConfig(c) | ||
config.NextProtos = credinternal.AppendH2ToNextProtos(config.NextProtos) | ||
// If the user did not configure a MinVersion and did not configure a | ||
// MaxVersion < 1.2, use MinVersion=1.2, which is required by | ||
// https://datatracker.ietf.org/doc/html/rfc7540#section-9.2 | ||
if tc.config.MinVersion == 0 && (tc.config.MaxVersion == 0 || tc.config.MaxVersion >= tls.VersionTLS12) { | ||
tc.config.MinVersion = tls.VersionTLS12 | ||
if config.MinVersion == 0 && (config.MaxVersion == 0 || config.MaxVersion >= tls.VersionTLS12) { | ||
config.MinVersion = tls.VersionTLS12 | ||
} | ||
// If the user did not configure CipherSuites, use all "secure" cipher | ||
// suites reported by the TLS package, but remove some explicitly forbidden | ||
// by https://datatracker.ietf.org/doc/html/rfc7540#appendix-A | ||
if tc.config.CipherSuites == nil { | ||
if config.CipherSuites == nil { | ||
for _, cs := range tls.CipherSuites() { | ||
if _, ok := tls12ForbiddenCipherSuites[cs.ID]; !ok { | ||
tc.config.CipherSuites = append(tc.config.CipherSuites, cs.ID) | ||
config.CipherSuites = append(config.CipherSuites, cs.ID) | ||
} | ||
} | ||
} | ||
return tc | ||
return config | ||
} | ||
|
||
// NewClientTLSFromCert constructs TLS credentials from the provided root | ||
|
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.
Don't shorten names -
cfg
->config
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.
Changed as suggested.