Don't list certs if we were told which cert to use. (#10616)

This commit is contained in:
Nick Cabatoff 2021-01-19 08:39:59 -05:00 committed by GitHub
parent 5e60bd9677
commit ffe301a5df
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 19 additions and 9 deletions

View File

@ -414,21 +414,31 @@ func (b *backend) loadTrustedCerts(ctx context.Context, storage logical.Storage,
pool = x509.NewCertPool()
trusted = make([]*ParsedCert, 0)
trustedNonCAs = make([]*ParsedCert, 0)
names, err := storage.List(ctx, "cert/")
if err != nil {
b.Logger().Error("failed to list trusted certs", "error", err)
return
}
for _, name := range names {
// If we are trying to select a single CertEntry and this isn't it
if certName != "" && name != certName {
continue
var names []string
if certName != "" {
names = append(names, certName)
} else {
var err error
names, err = storage.List(ctx, "cert/")
if err != nil {
b.Logger().Error("failed to list trusted certs", "error", err)
return
}
}
for _, name := range names {
entry, err := b.Cert(ctx, storage, strings.TrimPrefix(name, "cert/"))
if err != nil {
b.Logger().Error("failed to load trusted cert", "name", name, "error", err)
continue
}
if entry == nil {
// This could happen when the certName was provided and the cert doesn't exist,
// or just if between the LIST and the GET the cert was deleted.
continue
}
parsed := parsePEM([]byte(entry.Certificate))
if len(parsed) == 0 {
b.Logger().Error("failed to parse certificate", "name", name)