Skip to content

Commit

Permalink
subcommands: Fix nil pointer issue in ca-show
Browse files Browse the repository at this point in the history
The `keys ca show --pretty` has a null pointer issue when users have
run `keys ca update` with a file that has a bunch of trailing
whitespace. This detects that situation and prevents the crash.

Signed-off-by: Andy Doan <andy@foundries.io>
  • Loading branch information
doanac authored and detsch committed Sep 21, 2023
1 parent ca2a6a6 commit 7916bc5
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions subcommands/keys/ca_show.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"encoding/asn1"
"encoding/pem"
"fmt"
"strings"

"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -106,6 +107,11 @@ func extKeyUsage(ext []x509.ExtKeyUsage) string {
func prettyPrint(cert string) {
for len(cert) > 0 {
block, remaining := pem.Decode([]byte(cert))
if block == nil {
// could be excessive whitespace
cert = strings.TrimSpace(string(remaining))
continue
}
cert = string(remaining)
c, err := x509.ParseCertificate(block.Bytes)
if err != nil {
Expand Down

0 comments on commit 7916bc5

Please sign in to comment.