Skip to content

Commit 26caaf5

Browse files
authored
Add nil check to validateChain (#188)
1 parent 6720024 commit 26caaf5

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

internal/scti/chain_validation.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,10 @@ func isPrecertificate(cert *x509.Certificate) (bool, error) {
146146
// the submitted chain in the order of submission.
147147
// TODO(phboneff): make this a method func([][]byte) ([]*x509.Certificate, error)
148148
func validateChain(rawChain [][]byte, validationOpts ChainValidationOpts) ([]*x509.Certificate, error) {
149+
if len(rawChain) == 0 {
150+
return nil, errors.New("empty certificate chain")
151+
}
152+
149153
// First make sure the certs parse as X.509
150154
chain := make([]*x509.Certificate, 0, len(rawChain))
151155
intermediatePool := x509util.NewPEMCertPool()

internal/scti/chain_validation_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,16 @@ func TestValidateChain(t *testing.T) {
249249
v.extKeyUsages = []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth}
250250
},
251251
},
252+
{
253+
desc: "empty-chain",
254+
chain: [][]byte{},
255+
wantErr: true,
256+
},
257+
{
258+
desc: "nil-chain",
259+
chain: nil,
260+
wantErr: true,
261+
},
252262
}
253263
for _, test := range tests {
254264
t.Run(test.desc, func(t *testing.T) {

0 commit comments

Comments
 (0)