-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
crl provider: Static and FileWatcher provider implementations #6670
Changes from 1 commit
978cb44
7d032e0
cdbc298
95991d8
32e3158
00de36e
8033cab
338a7f4
d1f63fe
01afa97
401eb79
c88d12d
1feaae3
a9a84f1
5a0acad
f3c830b
4ea1b34
aeebd4e
735ac20
5c76a60
0bc7757
f844c8c
a4da85e
c3ba07e
ffe5c34
6d28181
7814373
1a46b65
d7f1555
2f1935d
0a7b086
8d05f28
ccbf7f6
99ecab0
9e5a70d
5643760
8898959
b16af8b
21f4301
51b42aa
f0c1ca4
08188d1
9b8d07e
ad15e23
8e02546
e6a690d
340757d
1e4c5ac
f654d18
53d6b05
1f398eb
f3dcca1
131e6e7
bc14ea8
96bf905
0ce6a2c
c57a08a
4c53c56
7fedab5
1025333
d9ba363
150e585
d7cf48f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
…ments
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,7 @@ import ( | |
"errors" | ||
"fmt" | ||
"net" | ||
"os" | ||
"testing" | ||
|
||
lru "github.com/hashicorp/golang-lru" | ||
|
@@ -381,15 +382,20 @@ func (s) TestClientServerHandshake(t *testing.T) { | |
} | ||
|
||
makeStaticCRLProvider := func(containsRevoked bool) *RevocationConfig { | ||
cRLProvider := MakeStaticCRLProvider() | ||
var crl *CRL | ||
|
||
rawCRLs := make([][]byte, 1) | ||
var path string | ||
if containsRevoked { | ||
gtcooke94 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
crl = loadCRL(t, testdata.Path("crl/provider/crl_server_revoked.pem")) | ||
path = testdata.Path("crl/provider/crl_server_revoked.pem") | ||
} else { | ||
crl = loadCRL(t, testdata.Path("crl/provider/crl_empty.pem")) | ||
path = testdata.Path("crl/provider/crl_empty.pem") | ||
} | ||
cRLProvider.AddCRL(crl) | ||
|
||
rawCRL, err := os.ReadFile(path) | ||
if err != nil { | ||
t.Fatalf("readFile(%v) failed err = %v", path, err) | ||
} | ||
rawCRLs = append(rawCRLs, rawCRL) | ||
cRLProvider := MakeStaticCRLProvider(rawCRLs) | ||
return &RevocationConfig{ | ||
AllowUndetermined: true, | ||
CRLProvider: cRLProvider, | ||
|
@@ -619,14 +625,14 @@ func (s) TestClientServerHandshake(t *testing.T) { | |
// server custom check fails | ||
{ | ||
desc: "Client sets peer cert, reload root function with verifyFuncGood; Server sets bad custom check; mutualTLS", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see you changed this test case and it's not a new one - just curious as to why you changed it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's a good catch, I was experimenting with some chains and accidentally submitted (it doesn't influence the outputs). Will revert it back There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
clientCert: []tls.Certificate{cs.ClientCert3}, | ||
clientGetRoot: getRootCAsForClientCRL, | ||
clientCert: []tls.Certificate{cs.ClientCert1}, | ||
clientGetRoot: getRootCAsForClient, | ||
clientVerifyFunc: clientVerifyFuncGood, | ||
clientVType: CertVerification, | ||
clientExpectHandshakeError: true, | ||
serverMutualTLS: true, | ||
serverCert: []tls.Certificate{cs.ServerCert3}, | ||
serverGetRoot: getRootCAsForServerCRL, | ||
serverCert: []tls.Certificate{cs.ServerCert1}, | ||
serverGetRoot: getRootCAsForServer, | ||
serverVerifyFunc: verifyFuncBad, | ||
serverVType: CertVerification, | ||
serverExpectError: true, | ||
|
@@ -707,7 +713,7 @@ func (s) TestClientServerHandshake(t *testing.T) { | |
}, | ||
// Client: set valid credentials with the revocation config | ||
// Server: set valid credentials with the revocation config | ||
// Expected Behavior: success, because non of the certificate chains sent in the connection are revoked | ||
// Expected Behavior: success, because none of the certificate chains sent in the connection are revoked | ||
{ | ||
desc: "Client sets peer cert, reload root function with verifyFuncGood; Server sets peer cert, reload root function; mutualTLS", | ||
clientCert: []tls.Certificate{cs.ClientCert1}, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,24 +45,33 @@ type CRLProvider interface { | |
CRL(cert *x509.Certificate) (*CRL, error) | ||
} | ||
|
||
// StaticCRLProvider implements CRLProvider interface by accepting CRL structs | ||
// and storing them in-memory. | ||
// StaticCRLProvider implements CRLProvider interface by accepting raw content | ||
// of CRL files at creation time and storing parsed CRL structs in-memory. | ||
dfawley marked this conversation as resolved.
Show resolved
Hide resolved
|
||
type StaticCRLProvider struct { | ||
// TODO CRL is sort of our internal representation - provide an API for | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that the way this has been structured makes it easy for users to construct There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
// people to read into it, or provide a simpler type in the API then | ||
// internally convert to this form | ||
crls map[string]*CRL | ||
} | ||
|
||
// MakeStaticCRLProvider returns a new instance of the StaticCRLProvider. | ||
func MakeStaticCRLProvider() *StaticCRLProvider { | ||
// MakeStaticCRLProvider processes raw content of CRL files, adds parsed CRL | ||
// structs into in-memory, and returns a new instance of the StaticCRLProvider. | ||
func MakeStaticCRLProvider(rawCRLs [][]byte) *StaticCRLProvider { | ||
dfawley marked this conversation as resolved.
Show resolved
Hide resolved
|
||
p := StaticCRLProvider{} | ||
p.crls = make(map[string]*CRL) | ||
for idx, rawCRL := range rawCRLs { | ||
cRL, err := NewCRL(rawCRL) | ||
if err != nil { | ||
grpclogLogger.Warningf("Can't parse raw CRL number %v from the slice: %v", idx, err) | ||
continue | ||
} | ||
p.addCRL(cRL) | ||
} | ||
return &p | ||
} | ||
|
||
// AddCRL adds/updates provided CRL to in-memory storage. | ||
func (p *StaticCRLProvider) AddCRL(crl *CRL) { | ||
func (p *StaticCRLProvider) addCRL(crl *CRL) { | ||
key := crl.CertList.Issuer.ToRDNSequence().String() | ||
p.crls[key] = crl | ||
} | ||
|
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.
Nit: remove the blank line please.
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.
Done