@@ -87,31 +87,52 @@ type PostHandshakeVerificationFunc func(params *HandshakeVerificationInfo) (*Pos
8787// Deprecated: use PostHandshakeVerificationFunc instead.
8888type CustomVerificationFunc = PostHandshakeVerificationFunc
8989
90- // GetRootCAsParams contains the parameters available to users when
91- // implementing GetRootCAs.
92- type GetRootCAsParams struct {
93- RawConn net.Conn
90+ // ConnectionInfo contains the parameters available to users when
91+ // implementing GetRootCertificates.
92+ type ConnectionInfo struct {
93+ // RawConn is the raw net.Conn representing a connection.
94+ RawConn net.Conn
95+ // RawCerts is the byte representation of the presented peer cert chain.
9496 RawCerts [][]byte
9597}
9698
97- // GetRootCAsResults contains the results of GetRootCAs.
99+ // GetRootCAsParams contains the parameters available to users when
100+ // implementing GetRootCAs.
101+ //
102+ // Deprecated: use ConnectionInfo instead.
103+ type GetRootCAsParams = ConnectionInfo
104+
105+ // RootCertificates is the result of GetRootCertificates.
98106// If users want to reload the root trust certificate, it is required to return
99107// the proper TrustCerts in GetRootCAs.
100- type GetRootCAsResults struct {
108+ type RootCertificates struct {
109+ // TrustCerts is the pool of trusted certificates.
101110 TrustCerts * x509.CertPool
102111}
103112
113+ // GetRootCAsResults contains the results of GetRootCAs.
114+ // If users want to reload the root trust certificate, it is required to return
115+ // the proper TrustCerts in GetRootCAs.
116+ //
117+ // Deprecated: use RootCertificates instead.
118+ type GetRootCAsResults = RootCertificates
119+
104120// RootCertificateOptions contains options to obtain root trust certificates
105121// for both the client and the server.
106122// At most one option could be set. If none of them are set, we
107123// use the system default trust certificates.
108124type RootCertificateOptions struct {
125+ // If RootCertificates is set, it will be used every time when verifying
126+ // the peer certificates, without performing root certificate reloading.
127+ RootCertificates * x509.CertPool
109128 // If RootCACerts is set, it will be used every time when verifying
110129 // the peer certificates, without performing root certificate reloading.
130+ //
131+ // Deprecated: use RootCertificates instead.
111132 RootCACerts * x509.CertPool
112133 // If GetRootCertificates is set, it will be invoked to obtain root certs for
113134 // every new connection.
114- GetRootCertificates func (params * GetRootCAsParams ) (* GetRootCAsResults , error )
135+ GetRootCertificates func (params * ConnectionInfo ) (* RootCertificates , error )
115136 // If RootProvider is set, we will use the root certs from the Provider's
116137 // KeyMaterial() call in the new connections. The Provider must have initial
117138 // credentials if specified. Otherwise, KeyMaterial() will block forever.
@@ -277,6 +298,12 @@ func (o *Options) clientConfig() (*tls.Config, error) {
277298 if o .MaxTLSVersion == 0 {
278299 o .MaxTLSVersion = o .MaxVersion
279300 }
301+ // TODO(gtcooke94) RootCACerts is deprecated, eventually remove this block.
302+ // This will ensure that users still explicitly setting RootCACerts will get
303+ // the setting int the right place.
304+ if o .RootOptions .RootCACerts != nil {
305+ o .RootOptions .RootCertificates = o .RootOptions .RootCACerts
306+ }
280307 if o .VerificationType == SkipVerification && o .AdditionalPeerVerification == nil {
281308 return nil , fmt .Errorf ("client needs to provide custom verification mechanism if choose to skip default verification" )
282309 }
@@ -312,19 +339,19 @@ func (o *Options) clientConfig() (*tls.Config, error) {
312339 }
313340 // Propagate root-certificate-related fields in tls.Config.
314341 switch {
315- case o .RootOptions .RootCACerts != nil :
316- config .RootCAs = o .RootOptions .RootCACerts
342+ case o .RootOptions .RootCertificates != nil :
343+ config .RootCAs = o .RootOptions .RootCertificates
317344 case o .RootOptions .GetRootCertificates != nil :
318345 // In cases when users provide GetRootCertificates callback, since this
319346 // callback is not contained in tls.Config, we have nothing to set here.
320347 // We will invoke the callback in ClientHandshake.
321348 case o .RootOptions .RootProvider != nil :
322- o .RootOptions .GetRootCertificates = func (* GetRootCAsParams ) (* GetRootCAsResults , error ) {
349+ o .RootOptions .GetRootCertificates = func (* ConnectionInfo ) (* RootCertificates , error ) {
323350 km , err := o .RootOptions .RootProvider .KeyMaterial (context .Background ())
324351 if err != nil {
325352 return nil , err
326353 }
327- return & GetRootCAsResults {TrustCerts : km .Roots }, nil
354+ return & RootCertificates {TrustCerts : km .Roots }, nil
328355 }
329356 default :
330357 // No root certificate options specified by user. Use the certificates
@@ -381,6 +408,12 @@ func (o *Options) serverConfig() (*tls.Config, error) {
381408 if o .MaxTLSVersion == 0 {
382409 o .MaxTLSVersion = o .MaxVersion
383410 }
411+ // TODO(gtcooke94) RootCACerts is deprecated, eventually remove this block.
412+ // This will ensure that users still explicitly setting RootCACerts will get
413+ // the setting int the right place.
414+ if o .RootOptions .RootCACerts != nil {
415+ o .RootOptions .RootCertificates = o .RootOptions .RootCACerts
416+ }
384417 if o .RequireClientCert && o .VerificationType == SkipVerification && o .AdditionalPeerVerification == nil {
385418 return nil , fmt .Errorf ("server needs to provide custom verification mechanism if choose to skip default verification, but require client certificate(s)" )
386419 }
@@ -420,19 +453,19 @@ func (o *Options) serverConfig() (*tls.Config, error) {
420453 }
421454 // Propagate root-certificate-related fields in tls.Config.
422455 switch {
423- case o .RootOptions .RootCACerts != nil :
424- config .ClientCAs = o .RootOptions .RootCACerts
456+ case o .RootOptions .RootCertificates != nil :
457+ config .ClientCAs = o .RootOptions .RootCertificates
425458 case o .RootOptions .GetRootCertificates != nil :
426459 // In cases when users provide GetRootCertificates callback, since this
427460 // callback is not contained in tls.Config, we have nothing to set here.
428461 // We will invoke the callback in ServerHandshake.
429462 case o .RootOptions .RootProvider != nil :
430- o .RootOptions .GetRootCertificates = func (* GetRootCAsParams ) (* GetRootCAsResults , error ) {
463+ o .RootOptions .GetRootCertificates = func (* ConnectionInfo ) (* RootCertificates , error ) {
431464 km , err := o .RootOptions .RootProvider .KeyMaterial (context .Background ())
432465 if err != nil {
433466 return nil , err
434467 }
435- return & GetRootCAsResults {TrustCerts : km .Roots }, nil
468+ return & RootCertificates {TrustCerts : km .Roots }, nil
436469 }
437470 default :
438471 // No root certificate options specified by user. Use the certificates
@@ -477,12 +510,12 @@ func (o *Options) serverConfig() (*tls.Config, error) {
477510// advancedTLSCreds is the credentials required for authenticating a connection
478511// using TLS.
479512type advancedTLSCreds struct {
480- config * tls.Config
481- verifyFunc PostHandshakeVerificationFunc
482- getRootCAs func (params * GetRootCAsParams ) (* GetRootCAsResults , error )
483- isClient bool
484- revocationOptions * RevocationOptions
485- verificationType VerificationType
513+ config * tls.Config
514+ verifyFunc PostHandshakeVerificationFunc
515+ getRootCertificates func (params * ConnectionInfo ) (* RootCertificates , error )
516+ isClient bool
517+ revocationOptions * RevocationOptions
518+ verificationType VerificationType
486519}
487520
488521func (c advancedTLSCreds ) Info () credentials.ProtocolInfo {
@@ -548,10 +581,10 @@ func (c *advancedTLSCreds) ServerHandshake(rawConn net.Conn) (net.Conn, credenti
548581
549582func (c * advancedTLSCreds ) Clone () credentials.TransportCredentials {
550583 return & advancedTLSCreds {
551- config : credinternal .CloneTLSConfig (c .config ),
552- verifyFunc : c .verifyFunc ,
553- getRootCAs : c .getRootCAs ,
554- isClient : c .isClient ,
584+ config : credinternal .CloneTLSConfig (c .config ),
585+ verifyFunc : c .verifyFunc ,
586+ getRootCertificates : c .getRootCertificates ,
587+ isClient : c .isClient ,
555588 }
556589}
557590
@@ -588,8 +621,8 @@ func buildVerifyFunc(c *advancedTLSCreds,
588621 rootCAs = c .config .ClientCAs
589622 }
590623 // Reload root CA certs.
591- if rootCAs == nil && c .getRootCAs != nil {
592- results , err := c .getRootCAs ( & GetRootCAsParams {
624+ if rootCAs == nil && c .getRootCertificates != nil {
625+ results , err := c .getRootCertificates ( & ConnectionInfo {
593626 RawConn : rawConn ,
594627 RawCerts : rawCerts ,
595628 })
@@ -661,12 +694,12 @@ func NewClientCreds(o *Options) (credentials.TransportCredentials, error) {
661694 return nil , err
662695 }
663696 tc := & advancedTLSCreds {
664- config : conf ,
665- isClient : true ,
666- getRootCAs : o .RootOptions .GetRootCertificates ,
667- verifyFunc : o .AdditionalPeerVerification ,
668- revocationOptions : o .RevocationOptions ,
669- verificationType : o .VerificationType ,
697+ config : conf ,
698+ isClient : true ,
699+ getRootCertificates : o .RootOptions .GetRootCertificates ,
700+ verifyFunc : o .AdditionalPeerVerification ,
701+ revocationOptions : o .RevocationOptions ,
702+ verificationType : o .VerificationType ,
670703 }
671704 tc .config .NextProtos = credinternal .AppendH2ToNextProtos (tc .config .NextProtos )
672705 return tc , nil
@@ -680,12 +713,12 @@ func NewServerCreds(o *Options) (credentials.TransportCredentials, error) {
680713 return nil , err
681714 }
682715 tc := & advancedTLSCreds {
683- config : conf ,
684- isClient : false ,
685- getRootCAs : o .RootOptions .GetRootCertificates ,
686- verifyFunc : o .AdditionalPeerVerification ,
687- revocationOptions : o .RevocationOptions ,
688- verificationType : o .VerificationType ,
716+ config : conf ,
717+ isClient : false ,
718+ getRootCertificates : o .RootOptions .GetRootCertificates ,
719+ verifyFunc : o .AdditionalPeerVerification ,
720+ revocationOptions : o .RevocationOptions ,
721+ verificationType : o .VerificationType ,
689722 }
690723 tc .config .NextProtos = credinternal .AppendH2ToNextProtos (tc .config .NextProtos )
691724 return tc , nil
0 commit comments