Skip to content
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

Attempt to resolve GH 17166 where agent crashes when no certs available #1639

Merged
merged 3 commits into from
Sep 16, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 3 additions & 0 deletions dependency/vault_pki.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@ func pemsCert(encoded []byte) (PemEncoded, *x509.Certificate, error) {
block, _ = pem.Decode(aPem)
switch {
case block == nil: // end of scan, no more PEMs found
if cert == nil {
return PemEncoded{}, nil, errors.New("Cert: not found")
}
return encPems, cert, nil
case strings.HasSuffix(block.Type, "PRIVATE KEY"):
// PKCS#1 and PKCS#8 matching to find private key
Expand Down
11 changes: 11 additions & 0 deletions dependency/vault_pki_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,17 @@ func Test_VaultPKI_notGoodFor(t *testing.T) {
}
}

func Test_VaultPKI_pemsCertNone(t *testing.T) {
_, cert, err := pemsCert(make([]byte, 0))
if err == nil {
t.Fatal("error should be not be nil as we don't have a cert")
eikenb marked this conversation as resolved.
Show resolved Hide resolved
}

if cert != nil {
t.Fatal("we should have a nil cert")
}
}

func Test_VaultPKI_pemsCert(t *testing.T) {
// tests w/ valid pems, and having it hidden behind various things
want := strings.TrimRight(strings.TrimSpace(validCert), "\n")
Expand Down