Skip to content

Add nil check to validateChain #188

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

Merged
merged 1 commit into from
Mar 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions internal/scti/chain_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,10 @@ func isPrecertificate(cert *x509.Certificate) (bool, error) {
// the submitted chain in the order of submission.
// TODO(phboneff): make this a method func([][]byte) ([]*x509.Certificate, error)
func validateChain(rawChain [][]byte, validationOpts ChainValidationOpts) ([]*x509.Certificate, error) {
if len(rawChain) == 0 {
return nil, errors.New("empty certificate chain")
}

// First make sure the certs parse as X.509
chain := make([]*x509.Certificate, 0, len(rawChain))
intermediatePool := x509util.NewPEMCertPool()
Expand Down
10 changes: 10 additions & 0 deletions internal/scti/chain_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,16 @@ func TestValidateChain(t *testing.T) {
v.extKeyUsages = []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth}
},
},
{
desc: "empty-chain",
chain: [][]byte{},
wantErr: true,
},
{
desc: "nil-chain",
chain: nil,
wantErr: true,
},
}
for _, test := range tests {
t.Run(test.desc, func(t *testing.T) {
Expand Down
Loading