Skip to content

Commit 4879d51

Browse files
authored
advancedTLS: Swap to DenyUndetermined from AllowUndetermined in revocation settings (#7179)
* swap to `DenyUndetermined` from `AllowUndetermined`
1 parent befc29d commit 4879d51

File tree

3 files changed

+35
-25
lines changed

3 files changed

+35
-25
lines changed

security/advancedtls/advancedtls_test.go

+10-10
Original file line numberDiff line numberDiff line change
@@ -427,15 +427,15 @@ func (s) TestClientServerHandshake(t *testing.T) {
427427
return &GetRootCAsResults{TrustCerts: cs.ServerTrust3}, nil
428428
}
429429

430-
makeStaticCRLRevocationOptions := func(crlPath string, allowUndetermined bool) *RevocationOptions {
430+
makeStaticCRLRevocationOptions := func(crlPath string, denyUndetermined bool) *RevocationOptions {
431431
rawCRL, err := os.ReadFile(crlPath)
432432
if err != nil {
433433
t.Fatalf("readFile(%v) failed err = %v", crlPath, err)
434434
}
435435
cRLProvider := NewStaticCRLProvider([][]byte{rawCRL})
436436
return &RevocationOptions{
437-
AllowUndetermined: allowUndetermined,
438-
CRLProvider: cRLProvider,
437+
DenyUndetermined: denyUndetermined,
438+
CRLProvider: cRLProvider,
439439
}
440440
}
441441

@@ -758,18 +758,18 @@ func (s) TestClientServerHandshake(t *testing.T) {
758758
clientVerifyFunc: clientVerifyFuncGood,
759759
clientVerificationType: CertVerification,
760760
clientRevocationOptions: &RevocationOptions{
761-
RootDir: testdata.Path("crl"),
762-
AllowUndetermined: true,
763-
Cache: cache,
761+
RootDir: testdata.Path("crl"),
762+
DenyUndetermined: false,
763+
Cache: cache,
764764
},
765765
serverMutualTLS: true,
766766
serverCert: []tls.Certificate{cs.ServerCert1},
767767
serverGetRoot: getRootCAsForServer,
768768
serverVerificationType: CertVerification,
769769
serverRevocationOptions: &RevocationOptions{
770-
RootDir: testdata.Path("crl"),
771-
AllowUndetermined: true,
772-
Cache: cache,
770+
RootDir: testdata.Path("crl"),
771+
DenyUndetermined: false,
772+
Cache: cache,
773773
},
774774
},
775775
// Client: set valid credentials with the revocation config
@@ -813,7 +813,7 @@ func (s) TestClientServerHandshake(t *testing.T) {
813813
clientGetRoot: getRootCAsForClientCRL,
814814
clientVerifyFunc: clientVerifyFuncGood,
815815
clientVerificationType: CertVerification,
816-
clientRevocationOptions: makeStaticCRLRevocationOptions(testdata.Path("crl/provider_malicious_crl_empty.pem"), false),
816+
clientRevocationOptions: makeStaticCRLRevocationOptions(testdata.Path("crl/provider_malicious_crl_empty.pem"), true),
817817
serverMutualTLS: true,
818818
serverCert: []tls.Certificate{cs.ServerCertForCRL},
819819
serverGetRoot: getRootCAsForServerCRL,

security/advancedtls/crl.go

+13-3
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,13 @@ type RevocationOptions struct {
6161
// Directory format must match OpenSSL X509_LOOKUP_hash_dir(3).
6262
// Deprecated: use CRLProvider instead.
6363
RootDir string
64+
// DenyUndetermined controls if certificate chains with RevocationUndetermined
65+
// revocation status are allowed to complete.
66+
DenyUndetermined bool
6467
// AllowUndetermined controls if certificate chains with RevocationUndetermined
6568
// revocation status are allowed to complete.
69+
//
70+
// Deprecated: use DenyUndetermined instead
6671
AllowUndetermined bool
6772
// Cache will store CRL files if not nil, otherwise files are reloaded for every lookup.
6873
// Only used for caching CRLs when using the RootDir setting.
@@ -222,11 +227,16 @@ func checkChainRevocation(verifiedChains [][]*x509.Certificate, cfg RevocationOp
222227
count[RevocationRevoked]++
223228
continue
224229
case RevocationUndetermined:
230+
count[RevocationUndetermined]++
231+
// TODO(gtcooke94) Remove when deprecated AllowUndetermined is removed
232+
// For now, if the deprecated value is explicitly set, use it
225233
if cfg.AllowUndetermined {
226-
return nil
234+
cfg.DenyUndetermined = !cfg.AllowUndetermined
227235
}
228-
count[RevocationUndetermined]++
229-
continue
236+
if cfg.DenyUndetermined {
237+
continue
238+
}
239+
return nil
230240
}
231241
}
232242
return fmt.Errorf("no unrevoked chains found: %v", count)

security/advancedtls/crl_test.go

+12-12
Original file line numberDiff line numberDiff line change
@@ -546,10 +546,10 @@ func TestRevokedCert(t *testing.T) {
546546
}
547547

548548
var revocationTests = []struct {
549-
desc string
550-
in tls.ConnectionState
551-
revoked bool
552-
allowUndetermined bool
549+
desc string
550+
in tls.ConnectionState
551+
revoked bool
552+
denyUndetermined bool
553553
}{
554554
{
555555
desc: "Single unrevoked",
@@ -586,24 +586,24 @@ func TestRevokedCert(t *testing.T) {
586586
in: tls.ConnectionState{VerifiedChains: [][]*x509.Certificate{
587587
{&x509.Certificate{CRLDistributionPoints: []string{"test"}}},
588588
}},
589-
revoked: true,
589+
revoked: true,
590+
denyUndetermined: true,
590591
},
591592
{
592593
desc: "Undetermined allowed",
593594
in: tls.ConnectionState{VerifiedChains: [][]*x509.Certificate{
594595
{&x509.Certificate{CRLDistributionPoints: []string{"test"}}},
595596
}},
596-
revoked: false,
597-
allowUndetermined: true,
597+
revoked: false,
598598
},
599599
}
600600

601601
for _, tt := range revocationTests {
602602
t.Run(fmt.Sprintf("%v with x509 crl hash dir", tt.desc), func(t *testing.T) {
603603
err := checkRevocation(tt.in, RevocationOptions{
604-
RootDir: testdata.Path("crl"),
605-
AllowUndetermined: tt.allowUndetermined,
606-
Cache: cache,
604+
RootDir: testdata.Path("crl"),
605+
DenyUndetermined: tt.denyUndetermined,
606+
Cache: cache,
607607
})
608608
t.Logf("checkRevocation err = %v", err)
609609
if tt.revoked && err == nil {
@@ -614,8 +614,8 @@ func TestRevokedCert(t *testing.T) {
614614
})
615615
t.Run(fmt.Sprintf("%v with static provider", tt.desc), func(t *testing.T) {
616616
err := checkRevocation(tt.in, RevocationOptions{
617-
AllowUndetermined: tt.allowUndetermined,
618-
CRLProvider: cRLProvider,
617+
DenyUndetermined: tt.denyUndetermined,
618+
CRLProvider: cRLProvider,
619619
})
620620
t.Logf("checkRevocation err = %v", err)
621621
if tt.revoked && err == nil {

0 commit comments

Comments
 (0)