Skip to content

Commit fc8da03

Browse files
authored
advancedtls: unexport parts of API not meant to be public (#7118)
1 parent 006e2ba commit fc8da03

File tree

4 files changed

+26
-29
lines changed

4 files changed

+26
-29
lines changed

security/advancedtls/advancedtls.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -172,10 +172,6 @@ type ClientOptions struct {
172172
// If this is set, we will perform this customized check after doing the
173173
// normal check(s) indicated by setting VType.
174174
VerifyPeer CustomVerificationFunc
175-
// ServerNameOverride is for testing only. If set to a non-empty string,
176-
// it will override the virtual host name of authority (e.g. :authority
177-
// header field) in requests.
178-
ServerNameOverride string
179175
// RootOptions is OPTIONAL on client side. If not set, we will try to use the
180176
// default trust certificates in users' OS system.
181177
RootOptions RootCertificateOptions
@@ -193,6 +189,11 @@ type ClientOptions struct {
193189
// By default, the maximum version supported by this package is used,
194190
// which is currently TLS 1.3.
195191
MaxVersion uint16
192+
// serverNameOverride is for testing only. If set to a non-empty string, it
193+
// will override the virtual host name of authority (e.g. :authority header
194+
// field) in requests and the target hostname used during server cert
195+
// verification.
196+
serverNameOverride string
196197
}
197198

198199
// ServerOptions contains the fields needed to be filled by the server.
@@ -244,7 +245,7 @@ func (o *ClientOptions) config() (*tls.Config, error) {
244245
return nil, fmt.Errorf("the minimum TLS version is larger than the maximum TLS version")
245246
}
246247
config := &tls.Config{
247-
ServerName: o.ServerNameOverride,
248+
ServerName: o.serverNameOverride,
248249
// We have to set InsecureSkipVerify to true to skip the default checks and
249250
// use the verification function we built from buildVerifyFunc.
250251
InsecureSkipVerify: true,
@@ -548,7 +549,7 @@ func buildVerifyFunc(c *advancedTLSCreds,
548549
if verifiedChains == nil {
549550
verifiedChains = [][]*x509.Certificate{rawCertList}
550551
}
551-
if err := CheckChainRevocation(verifiedChains, *c.revocationConfig); err != nil {
552+
if err := checkChainRevocation(verifiedChains, *c.revocationConfig); err != nil {
552553
return err
553554
}
554555
}

security/advancedtls/advancedtls_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -902,7 +902,7 @@ func (s) TestAdvancedTLSOverrideServerName(t *testing.T) {
902902
RootOptions: RootCertificateOptions{
903903
RootCACerts: cs.ClientTrust1,
904904
},
905-
ServerNameOverride: expectedServerName,
905+
serverNameOverride: expectedServerName,
906906
}
907907
c, err := NewClientCreds(clientOptions)
908908
if err != nil {

security/advancedtls/crl.go

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -75,22 +75,18 @@ type RevocationConfig struct {
7575
CRLProvider CRLProvider
7676
}
7777

78-
// RevocationStatus is the revocation status for a certificate or chain.
79-
type RevocationStatus int
78+
// revocationStatus is the revocation status for a certificate or chain.
79+
type revocationStatus int
8080

8181
const (
8282
// RevocationUndetermined means we couldn't find or verify a CRL for the cert.
83-
RevocationUndetermined RevocationStatus = iota
83+
RevocationUndetermined revocationStatus = iota
8484
// RevocationUnrevoked means we found the CRL for the cert and the cert is not revoked.
8585
RevocationUnrevoked
8686
// RevocationRevoked means we found the CRL and the cert is revoked.
8787
RevocationRevoked
8888
)
8989

90-
func (s RevocationStatus) String() string {
91-
return [...]string{"RevocationUndetermined", "RevocationUnrevoked", "RevocationRevoked"}[s]
92-
}
93-
9490
// CRL contains a pkix.CertificateList and parsed extensions that aren't
9591
// provided by the golang CRL parser.
9692
// All CRLs should be loaded using NewCRL() for bytes directly or ReadCRLFile()
@@ -192,25 +188,25 @@ func x509NameHash(r pkix.RDNSequence) string {
192188
return fmt.Sprintf("%08x", fileHash)
193189
}
194190

195-
// CheckRevocation checks the connection for revoked certificates based on RFC5280.
191+
// checkRevocation checks the connection for revoked certificates based on RFC5280.
196192
// This implementation has the following major limitations:
197193
// - Indirect CRL files are not supported.
198194
// - CRL loading is only supported from directories in the X509_LOOKUP_hash_dir format.
199195
// - OnlySomeReasons is not supported.
200196
// - Delta CRL files are not supported.
201197
// - Certificate CRLDistributionPoint must be URLs, but are then ignored and converted into a file path.
202198
// - CRL checks are done after path building, which goes against RFC4158.
203-
func CheckRevocation(conn tls.ConnectionState, cfg RevocationConfig) error {
204-
return CheckChainRevocation(conn.VerifiedChains, cfg)
199+
func checkRevocation(conn tls.ConnectionState, cfg RevocationConfig) error {
200+
return checkChainRevocation(conn.VerifiedChains, cfg)
205201
}
206202

207-
// CheckChainRevocation checks the verified certificate chain
203+
// checkChainRevocation checks the verified certificate chain
208204
// for revoked certificates based on RFC5280.
209-
func CheckChainRevocation(verifiedChains [][]*x509.Certificate, cfg RevocationConfig) error {
205+
func checkChainRevocation(verifiedChains [][]*x509.Certificate, cfg RevocationConfig) error {
210206
// Iterate the verified chains looking for one that is RevocationUnrevoked.
211207
// A single RevocationUnrevoked chain is enough to allow the connection, and a single RevocationRevoked
212208
// chain does not mean the connection should fail.
213-
count := make(map[RevocationStatus]int)
209+
count := make(map[revocationStatus]int)
214210
for _, chain := range verifiedChains {
215211
switch checkChain(chain, cfg) {
216212
case RevocationUnrevoked:
@@ -236,7 +232,7 @@ func CheckChainRevocation(verifiedChains [][]*x509.Certificate, cfg RevocationCo
236232
// 1. If any certificate is RevocationRevoked, return RevocationRevoked.
237233
// 2. If any certificate is RevocationUndetermined, return RevocationUndetermined.
238234
// 3. If all certificates are RevocationUnrevoked, return RevocationUnrevoked.
239-
func checkChain(chain []*x509.Certificate, cfg RevocationConfig) RevocationStatus {
235+
func checkChain(chain []*x509.Certificate, cfg RevocationConfig) revocationStatus {
240236
chainStatus := RevocationUnrevoked
241237
for _, c := range chain {
242238
switch checkCert(c, chain, cfg) {
@@ -318,7 +314,7 @@ func fetchCRL(c *x509.Certificate, crlVerifyCrt []*x509.Certificate, cfg Revocat
318314
// RevocationUndetermined.
319315
// c is the certificate to check.
320316
// crlVerifyCrt is the group of possible certificates to verify the crl.
321-
func checkCert(c *x509.Certificate, crlVerifyCrt []*x509.Certificate, cfg RevocationConfig) RevocationStatus {
317+
func checkCert(c *x509.Certificate, crlVerifyCrt []*x509.Certificate, cfg RevocationConfig) revocationStatus {
322318
crl, err := fetchCRL(c, crlVerifyCrt, cfg)
323319
if err != nil {
324320
// We couldn't load any valid CRL files for the certificate, so we don't
@@ -343,7 +339,7 @@ func checkCert(c *x509.Certificate, crlVerifyCrt []*x509.Certificate, cfg Revoca
343339
return revocation
344340
}
345341

346-
func checkCertRevocation(c *x509.Certificate, crl *CRL) (RevocationStatus, error) {
342+
func checkCertRevocation(c *x509.Certificate, crl *CRL) (revocationStatus, error) {
347343
// Per section 5.3.3 we prime the certificate issuer with the CRL issuer.
348344
// Subsequent entries use the previous entry's issuer.
349345
rawEntryIssuer := crl.rawIssuer

security/advancedtls/crl_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ qsSIp8gfxSyzkJP+Ngkm2DdLjlJQCZ9R0MZP9Xj4
229229
var revocationTests = []struct {
230230
desc string
231231
in x509.Certificate
232-
revoked RevocationStatus
232+
revoked revocationStatus
233233
}{
234234
{
235235
desc: "Single revoked",
@@ -601,24 +601,24 @@ func TestRevokedCert(t *testing.T) {
601601

602602
for _, tt := range revocationTests {
603603
t.Run(fmt.Sprintf("%v with x509 crl hash dir", tt.desc), func(t *testing.T) {
604-
err := CheckRevocation(tt.in, RevocationConfig{
604+
err := checkRevocation(tt.in, RevocationConfig{
605605
RootDir: testdata.Path("crl"),
606606
AllowUndetermined: tt.allowUndetermined,
607607
Cache: cache,
608608
})
609-
t.Logf("CheckRevocation err = %v", err)
609+
t.Logf("checkRevocation err = %v", err)
610610
if tt.revoked && err == nil {
611611
t.Error("Revoked certificate chain was allowed")
612612
} else if !tt.revoked && err != nil {
613613
t.Error("Unrevoked certificate not allowed")
614614
}
615615
})
616616
t.Run(fmt.Sprintf("%v with static provider", tt.desc), func(t *testing.T) {
617-
err := CheckRevocation(tt.in, RevocationConfig{
617+
err := checkRevocation(tt.in, RevocationConfig{
618618
AllowUndetermined: tt.allowUndetermined,
619619
CRLProvider: cRLProvider,
620620
})
621-
t.Logf("CheckRevocation err = %v", err)
621+
t.Logf("checkRevocation err = %v", err)
622622
if tt.revoked && err == nil {
623623
t.Error("Revoked certificate chain was allowed")
624624
} else if !tt.revoked && err != nil {
@@ -739,7 +739,7 @@ func TestVerifyConnection(t *testing.T) {
739739
cliCfg := tls.Config{
740740
RootCAs: cp,
741741
VerifyConnection: func(cs tls.ConnectionState) error {
742-
return CheckRevocation(cs, RevocationConfig{RootDir: dir})
742+
return checkRevocation(cs, RevocationConfig{RootDir: dir})
743743
},
744744
}
745745
conn, err := tls.Dial(lis.Addr().Network(), lis.Addr().String(), &cliCfg)

0 commit comments

Comments
 (0)