From e40745db9f0a19a7e404afec133464a1ff834d24 Mon Sep 17 00:00:00 2001 From: Kyle Isom Date: Fri, 1 Apr 2016 15:21:25 -0700 Subject: [PATCH] certdump now reliably gets certs via stdin. There was an issue doing something like cfssl bundle -domain kyleisom.net | jq .bundle | certdump which seems to have been caused by the way that newlines were encoded inside. The input is now massaged a bit to make it more palatable to the cert parser. --- cmd/certdump/certdump.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/cmd/certdump/certdump.go b/cmd/certdump/certdump.go index c942b98..187e441 100644 --- a/cmd/certdump/certdump.go +++ b/cmd/certdump/certdump.go @@ -1,6 +1,7 @@ package main import ( + "bytes" "crypto/dsa" "crypto/ecdsa" "crypto/elliptic" @@ -214,12 +215,17 @@ func main() { flag.BoolVar(&leafOnly, "l", false, "only show the leaf certificate") flag.Parse() - if flag.NArg() == 0 || (flag.NArg() == 1 && flag.Arg(1) == "-") { + if flag.NArg() == 0 || (flag.NArg() == 1 && flag.Arg(0) == "-") { certs, err := ioutil.ReadAll(os.Stdin) if err != nil { Warn(err, "couldn't read certificates from standard input") os.Exit(1) } + + // This is needed for getting certs from JSON/jq. + certs = bytes.TrimSpace(certs) + certs = bytes.Replace(certs, []byte(`\n`), []byte{0xa}, -1) + certs = bytes.Trim(certs, `"`) displayAllCerts(certs, leafOnly) } else { for _, filename := range flag.Args() {