@@ -35,10 +35,10 @@ import (
3535 credinternal "google.golang.org/grpc/internal/credentials"
3636)
3737
38- // VerificationFuncParams contains parameters available to users when
39- // implementing CustomVerificationFunc.
38+ // HandshakeVerificationInfo contains information about a handshake needed for
39+ // verification for use when implementing the `PostHandshakeVerificationFunc`
4040// The fields in this struct are read-only.
41- type VerificationFuncParams struct {
41+ type HandshakeVerificationInfo struct {
4242 // The target server name that the client connects to when establishing the
4343 // connection. This field is only meaningful for client side. On server side,
4444 // this field would be an empty string.
@@ -54,17 +54,36 @@ type VerificationFuncParams struct {
5454 Leaf * x509.Certificate
5555}
5656
57- // VerificationResults contains the information about results of
58- // CustomVerificationFunc.
59- // VerificationResults is an empty struct for now. It may be extended in the
57+ // VerificationFuncParams contains parameters available to users when
58+ // implementing CustomVerificationFunc.
59+ // The fields in this struct are read-only.
60+ //
61+ // Deprecated: use HandshakeVerificationInfo instead.
62+ type VerificationFuncParams = HandshakeVerificationInfo
63+
64+ // PostHandshakeVerificationResults contains the information about results of
65+ // PostHandshakeVerificationFunc.
66+ // PostHandshakeVerificationResults is an empty struct for now. It may be extended in the
6067// future to include more information.
61- type VerificationResults struct {}
68+ type PostHandshakeVerificationResults struct {}
69+
70+ // Deprecated: use PostHandshakeVerificationResults instead.
71+ type VerificationResults = PostHandshakeVerificationResults
72+
73+ // PostHandshakeVerificationFunc is the function defined by users to perform
74+ // custom verification checks after chain building and regular handshake
75+ // verification has been completed.
76+ // PostHandshakeVerificationFunc should return (nil, error) if the authorization
77+ // should fail, with the error containing information on why it failed.
78+ type PostHandshakeVerificationFunc func (params * HandshakeVerificationInfo ) (* PostHandshakeVerificationResults , error )
6279
6380// CustomVerificationFunc is the function defined by users to perform custom
6481// verification check.
6582// CustomVerificationFunc returns nil if the authorization fails; otherwise
6683// returns an empty struct.
67- type CustomVerificationFunc func (params * VerificationFuncParams ) (* VerificationResults , error )
84+ //
85+ // Deprecated: use PostHandshakeVerificationFunc instead.
86+ type CustomVerificationFunc = PostHandshakeVerificationFunc
6887
6988// GetRootCAsParams contains the parameters available to users when
7089// implementing GetRootCAs.
@@ -167,11 +186,18 @@ type ClientOptions struct {
167186 // IdentityOptions is OPTIONAL on client side. This field only needs to be
168187 // set if mutual authentication is required on server side.
169188 IdentityOptions IdentityCertificateOptions
189+ // AdditionalPeerVerification is a custom verification check after certificate signature
190+ // check.
191+ // If this is set, we will perform this customized check after doing the
192+ // normal check(s) indicated by setting VerificationType.
193+ AdditionalPeerVerification PostHandshakeVerificationFunc
170194 // VerifyPeer is a custom verification check after certificate signature
171195 // check.
172196 // If this is set, we will perform this customized check after doing the
173- // normal check(s) indicated by setting VType.
174- VerifyPeer CustomVerificationFunc
197+ // normal check(s) indicated by setting VerificationType.
198+ //
199+ // Deprecated: use AdditionalPeerVerification instead.
200+ VerifyPeer PostHandshakeVerificationFunc
175201 // RootOptions is OPTIONAL on client side. If not set, we will try to use the
176202 // default trust certificates in users' OS system.
177203 RootOptions RootCertificateOptions
@@ -206,11 +232,18 @@ type ClientOptions struct {
206232type ServerOptions struct {
207233 // IdentityOptions is REQUIRED on server side.
208234 IdentityOptions IdentityCertificateOptions
235+ // AdditionalPeerVerification is a custom verification check after certificate signature
236+ // check.
237+ // If this is set, we will perform this customized check after doing the
238+ // normal check(s) indicated by setting VerificationType.
239+ AdditionalPeerVerification PostHandshakeVerificationFunc
209240 // VerifyPeer is a custom verification check after certificate signature
210241 // check.
211242 // If this is set, we will perform this customized check after doing the
212- // normal check(s) indicated by setting VType.
213- VerifyPeer CustomVerificationFunc
243+ // normal check(s) indicated by setting VerificationType.
244+ //
245+ // Deprecated: use AdditionalPeerVerification instead.
246+ VerifyPeer PostHandshakeVerificationFunc
214247 // RootOptions is OPTIONAL on server side. This field only needs to be set if
215248 // mutual authentication is required(RequireClientCert is true).
216249 RootOptions RootCertificateOptions
@@ -239,13 +272,18 @@ type ServerOptions struct {
239272}
240273
241274func (o * ClientOptions ) config () (* tls.Config , error ) {
275+ // TODO(gtcooke94) Remove this block when o.VerifyPeer is remoed.
276+ // VerifyPeer is deprecated, but do this to aid the transitory migration time.
277+ if o .AdditionalPeerVerification == nil {
278+ o .AdditionalPeerVerification = o .VerifyPeer
279+ }
242280 // TODO(gtcooke94). VType is deprecated, eventually remove this block. This
243281 // will ensure that users still explicitly setting `VType` will get the
244282 // setting to the right place.
245283 if o .VType != CertAndHostVerification {
246284 o .VerificationType = o .VType
247285 }
248- if o .VerificationType == SkipVerification && o .VerifyPeer == nil {
286+ if o .VerificationType == SkipVerification && o .AdditionalPeerVerification == nil {
249287 return nil , fmt .Errorf ("client needs to provide custom verification mechanism if choose to skip default verification" )
250288 }
251289 // Make sure users didn't specify more than one fields in
@@ -321,13 +359,18 @@ func (o *ClientOptions) config() (*tls.Config, error) {
321359}
322360
323361func (o * ServerOptions ) config () (* tls.Config , error ) {
362+ // TODO(gtcooke94) Remove this block when o.VerifyPeer is remoed.
363+ // VerifyPeer is deprecated, but do this to aid the transitory migration time.
364+ if o .AdditionalPeerVerification == nil {
365+ o .AdditionalPeerVerification = o .VerifyPeer
366+ }
324367 // TODO(gtcooke94). VType is deprecated, eventually remove this block. This
325368 // will ensure that users still explicitly setting `VType` will get the
326369 // setting to the right place.
327370 if o .VType != CertAndHostVerification {
328371 o .VerificationType = o .VType
329372 }
330- if o .RequireClientCert && o .VerificationType == SkipVerification && o .VerifyPeer == nil {
373+ if o .RequireClientCert && o .VerificationType == SkipVerification && o .AdditionalPeerVerification == nil {
331374 return nil , fmt .Errorf ("server needs to provide custom verification mechanism if choose to skip default verification, but require client certificate(s)" )
332375 }
333376 // Make sure users didn't specify more than one fields in
@@ -416,7 +459,7 @@ func (o *ServerOptions) config() (*tls.Config, error) {
416459// using TLS.
417460type advancedTLSCreds struct {
418461 config * tls.Config
419- verifyFunc CustomVerificationFunc
462+ verifyFunc PostHandshakeVerificationFunc
420463 getRootCAs func (params * GetRootCAsParams ) (* GetRootCAsResults , error )
421464 isClient bool
422465 verificationType VerificationType
@@ -579,7 +622,7 @@ func buildVerifyFunc(c *advancedTLSCreds,
579622 }
580623 // Perform custom verification check if specified.
581624 if c .verifyFunc != nil {
582- _ , err := c .verifyFunc (& VerificationFuncParams {
625+ _ , err := c .verifyFunc (& HandshakeVerificationInfo {
583626 ServerName : serverName ,
584627 RawCerts : rawCerts ,
585628 VerifiedChains : chains ,
@@ -602,7 +645,7 @@ func NewClientCreds(o *ClientOptions) (credentials.TransportCredentials, error)
602645 config : conf ,
603646 isClient : true ,
604647 getRootCAs : o .RootOptions .GetRootCertificates ,
605- verifyFunc : o .VerifyPeer ,
648+ verifyFunc : o .AdditionalPeerVerification ,
606649 verificationType : o .VerificationType ,
607650 revocationConfig : o .RevocationConfig ,
608651 }
@@ -621,7 +664,7 @@ func NewServerCreds(o *ServerOptions) (credentials.TransportCredentials, error)
621664 config : conf ,
622665 isClient : false ,
623666 getRootCAs : o .RootOptions .GetRootCertificates ,
624- verifyFunc : o .VerifyPeer ,
667+ verifyFunc : o .AdditionalPeerVerification ,
625668 verificationType : o .VerificationType ,
626669 revocationConfig : o .RevocationConfig ,
627670 }
0 commit comments