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.
This commit is contained in:
Kyle Isom 2016-04-01 15:21:25 -07:00
parent e33e8c3ce5
commit e40745db9f
1 changed files with 7 additions and 1 deletions

View File

@ -1,6 +1,7 @@
package main package main
import ( import (
"bytes"
"crypto/dsa" "crypto/dsa"
"crypto/ecdsa" "crypto/ecdsa"
"crypto/elliptic" "crypto/elliptic"
@ -214,12 +215,17 @@ func main() {
flag.BoolVar(&leafOnly, "l", false, "only show the leaf certificate") flag.BoolVar(&leafOnly, "l", false, "only show the leaf certificate")
flag.Parse() 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) certs, err := ioutil.ReadAll(os.Stdin)
if err != nil { if err != nil {
Warn(err, "couldn't read certificates from standard input") Warn(err, "couldn't read certificates from standard input")
os.Exit(1) 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) displayAllCerts(certs, leafOnly)
} else { } else {
for _, filename := range flag.Args() { for _, filename := range flag.Args() {