-
Notifications
You must be signed in to change notification settings - Fork 4.6k
advancedtls: Rename VType #7149
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 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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 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 |
|---|---|---|
|
|
@@ -175,6 +175,11 @@ type ClientOptions struct { | |
| // RootOptions is OPTIONAL on client side. If not set, we will try to use the | ||
| // default trust certificates in users' OS system. | ||
| RootOptions RootCertificateOptions | ||
| // VerificationType defines what type of server verification is done. See | ||
| // the `VerificationType` enum for the different options. | ||
| // Default: CertAndHostVerification | ||
| VerificationType VerificationType | ||
| // DEPRECATED: Renamed to `VerificationType` | ||
| // VType is the verification type on the client side. | ||
| VType VerificationType | ||
| // RevocationConfig is the configurations for certificate revocation checks. | ||
|
|
@@ -210,6 +215,11 @@ type ServerOptions struct { | |
| RootOptions RootCertificateOptions | ||
| // If the server want the client to send certificates. | ||
| RequireClientCert bool | ||
| // VerificationType defines what type of client verification is done. See | ||
| // the `VerificationType` enum for the different options. | ||
| // Default: CertAndHostVerification | ||
| VerificationType VerificationType | ||
| // DEPRECATED: Renamed to `VerificationType` | ||
|
||
| // VType is the verification type on the server side. | ||
| VType VerificationType | ||
| // RevocationConfig is the configurations for certificate revocation checks. | ||
|
|
@@ -227,7 +237,13 @@ type ServerOptions struct { | |
| } | ||
|
|
||
| func (o *ClientOptions) config() (*tls.Config, error) { | ||
| if o.VType == SkipVerification && o.VerifyPeer == nil { | ||
| // TODO(gtcooke94). VType is deprecated, eventually remove this block. This | ||
| // will ensure that users still explicitly setting `VType` will get the | ||
| // setting to the right place. | ||
| if o.VType != CertAndHostVerification { | ||
| o.VerificationType = o.VType | ||
| } | ||
| if o.VerificationType == SkipVerification && o.VerifyPeer == nil { | ||
| return nil, fmt.Errorf("client needs to provide custom verification mechanism if choose to skip default verification") | ||
| } | ||
| // Make sure users didn't specify more than one fields in | ||
|
|
@@ -271,7 +287,7 @@ func (o *ClientOptions) config() (*tls.Config, error) { | |
| default: | ||
| // No root certificate options specified by user. Use the certificates | ||
| // stored in system default path as the last resort. | ||
| if o.VType != SkipVerification { | ||
| if o.VerificationType != SkipVerification { | ||
| systemRootCAs, err := x509.SystemCertPool() | ||
| if err != nil { | ||
| return nil, err | ||
|
|
@@ -303,7 +319,13 @@ func (o *ClientOptions) config() (*tls.Config, error) { | |
| } | ||
|
|
||
| func (o *ServerOptions) config() (*tls.Config, error) { | ||
| if o.RequireClientCert && o.VType == SkipVerification && o.VerifyPeer == nil { | ||
| // TODO(gtcooke94). VType is deprecated, eventually remove this block. This | ||
| // will ensure that users still explicitly setting `VType` will get the | ||
| // setting to the right place. | ||
| if o.VType != CertAndHostVerification { | ||
| o.VerificationType = o.VType | ||
| } | ||
| if o.RequireClientCert && o.VerificationType == SkipVerification && o.VerifyPeer == nil { | ||
| return nil, fmt.Errorf("server needs to provide custom verification mechanism if choose to skip default verification, but require client certificate(s)") | ||
| } | ||
| // Make sure users didn't specify more than one fields in | ||
|
|
@@ -351,7 +373,7 @@ func (o *ServerOptions) config() (*tls.Config, error) { | |
| default: | ||
| // No root certificate options specified by user. Use the certificates | ||
| // stored in system default path as the last resort. | ||
| if o.VType != SkipVerification && o.RequireClientCert { | ||
| if o.VerificationType != SkipVerification && o.RequireClientCert { | ||
| systemRootCAs, err := x509.SystemCertPool() | ||
| if err != nil { | ||
| return nil, err | ||
|
|
@@ -395,7 +417,7 @@ type advancedTLSCreds struct { | |
| verifyFunc CustomVerificationFunc | ||
| getRootCAs func(params *GetRootCAsParams) (*GetRootCAsResults, error) | ||
| isClient bool | ||
| vType VerificationType | ||
| verificationType VerificationType | ||
| revocationConfig *RevocationConfig | ||
| } | ||
|
|
||
|
|
@@ -495,7 +517,7 @@ func buildVerifyFunc(c *advancedTLSCreds, | |
| } | ||
| rawCertList[i] = cert | ||
| } | ||
| if c.vType == CertAndHostVerification || c.vType == CertVerification { | ||
| if c.verificationType == CertAndHostVerification || c.verificationType == CertVerification { | ||
| // perform possible trust credential reloading and certificate check | ||
| rootCAs := c.config.RootCAs | ||
| if !c.isClient { | ||
|
|
@@ -527,7 +549,7 @@ func buildVerifyFunc(c *advancedTLSCreds, | |
| opts.Intermediates.AddCert(cert) | ||
| } | ||
| // Perform default hostname check if specified. | ||
| if c.isClient && c.vType == CertAndHostVerification && serverName != "" { | ||
| if c.isClient && c.verificationType == CertAndHostVerification && serverName != "" { | ||
| parsedName, _, err := net.SplitHostPort(serverName) | ||
| if err != nil { | ||
| // If the serverName had no host port or if the serverName cannot be | ||
|
|
@@ -579,7 +601,7 @@ func NewClientCreds(o *ClientOptions) (credentials.TransportCredentials, error) | |
| isClient: true, | ||
| getRootCAs: o.RootOptions.GetRootCertificates, | ||
| verifyFunc: o.VerifyPeer, | ||
| vType: o.VType, | ||
| verificationType: o.VerificationType, | ||
| revocationConfig: o.RevocationConfig, | ||
| } | ||
| tc.config.NextProtos = credinternal.AppendH2ToNextProtos(tc.config.NextProtos) | ||
|
|
@@ -598,7 +620,7 @@ func NewServerCreds(o *ServerOptions) (credentials.TransportCredentials, error) | |
| isClient: false, | ||
| getRootCAs: o.RootOptions.GetRootCertificates, | ||
| verifyFunc: o.VerifyPeer, | ||
| vType: o.VType, | ||
| verificationType: o.VerificationType, | ||
| revocationConfig: o.RevocationConfig, | ||
| } | ||
| tc.config.NextProtos = credinternal.AppendH2ToNextProtos(tc.config.NextProtos) | ||
|
|
||
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
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.
The proper way to docstring this is:
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.
Fixed