From d64905256a3e4bdae006728ff3e85ccd67f08afa Mon Sep 17 00:00:00 2001 From: Cedric Staub Date: Fri, 24 Jun 2016 22:37:27 -0700 Subject: [PATCH] Improve formatting, show if self-signed --- display.go | 3 ++- verify.go | 11 ++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/display.go b/display.go index b55845e..8472bd9 100644 --- a/display.go +++ b/display.go @@ -35,7 +35,7 @@ import ( var layout = `Serial: {{.SerialNumber}} Not Before: {{.NotBefore | certStart}} Not After : {{.NotAfter | certEnd}} -Signature : {{.SignatureAlgorithm | algorithm}} +Signature : {{.SignatureAlgorithm | algorithm}} {{if . | isSelfSigned}}(self-signed){{end}} Subject Info: {{if .Subject.CommonName}} CommonName: {{.Subject.CommonName}}{{end}} {{if .Subject.Organization}} Organization: {{.Subject.Organization}} {{end}} {{if .Subject.OrganizationalUnit}} @@ -80,6 +80,7 @@ func displayCert(cert certWithAlias) { "keyUsage": keyUsage, "extKeyUsage": extKeyUsage, "certWarnings": certWarnings, + "isSelfSigned": isSelfSigned, } t := template.New("Cert template").Funcs(funcMap) t, _ = t.Parse(layout) diff --git a/verify.go b/verify.go index a9af5f5..54bbab4 100644 --- a/verify.go +++ b/verify.go @@ -69,6 +69,11 @@ func verifyChain(certs []*x509.Certificate, dnsName, caPath string) { } else { name = fmt.Sprintf("Serial #%s", cert.SerialNumber.String()) } + + if isSelfSigned(cert) { + name += green.SprintfFunc()(" [self-signed]") + } + for _, alg := range badSignatureAlgorithms { if cert.SignatureAlgorithm == alg { name += red.SprintfFunc()(" [%s]", alg.String()) @@ -77,6 +82,10 @@ func verifyChain(certs []*x509.Certificate, dnsName, caPath string) { } names = append(names, name) } - fmt.Printf("\t[%d] %s\n", i, strings.Join(names, "\n\t\t=> ")) + fmt.Printf("[%d] %s\n", i, strings.Join(names, "\n\t=> ")) } } + +func isSelfSigned(cert *x509.Certificate) bool { + return cert.CheckSignatureFrom(cert) == nil +}