mirror of
https://github.com/square/certigo.git
synced 2024-04-21 12:32:40 +00:00
Fixed empty fields in output, output of large arrays, and ip addresses and emails
-If a field in a cert is blank, prints N/A -Large arrays are now newline separated in the output, instead of all on one line -Displays cert alternate ip addresses and email addresses as well
This commit is contained in:
@@ -21,3 +21,26 @@ BuiOnD4OU0TS9gs7kw73qD7Kzh7MTsCLP77BrxtDAJvzYAMOyyZMnCg6ony9bCZe
|
||||
7N65svyFtk6EufWydgzM62FCfuN8TMEPuFV7dcpeQsRUed7/IiEhT6NjpNODF+pL
|
||||
lzFSVOaI0OaAO/6Y1lUp67BfmOdzqlIVZKaKSzpdYHoxjXj7WR9AcA==
|
||||
-----END CERTIFICATE-----
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIID5DCCAswCCQCgrrPEnfR7ezANBgkqhkiG9w0BAQUFADCBszELMAkGA1UEBhMC
|
||||
VVMxEzARBgNVBAgTCkNhbGlmb3JuaWExFjAUBgNVBAcTDVNhbiBGcmFuY2lzY28x
|
||||
GTAXBgNVBAoTEEFwZXJ0dXJlIFNjaWVuY2UxITAfBgNVBAsTGFJlc2VhcmNoIGFu
|
||||
ZCBEZXZlbG9wbWVudDEYMBYGA1UEAxMPQXBlcnR1cmVTY2llbmNlMR8wHQYJKoZI
|
||||
hvcNAQkBFhBhYmNAYXBlcnR1cmUuY29tMB4XDTE2MDUyNzIxMTUzMVoXDTE3MTAw
|
||||
OTIxMTUzMVowgbMxCzAJBgNVBAYTAlVTMRMwEQYDVQQIEwpDYWxpZm9ybmlhMRYw
|
||||
FAYDVQQHEw1TYW4gRnJhbmNpc2NvMRkwFwYDVQQKExBBcGVydHVyZSBTY2llbmNl
|
||||
MSEwHwYDVQQLExhSZXNlYXJjaCBhbmQgRGV2ZWxvcG1lbnQxGDAWBgNVBAMTD0Fw
|
||||
ZXJ0dXJlU2NpZW5jZTEfMB0GCSqGSIb3DQEJARYQYWJjQGFwZXJ0dXJlLmNvbTCC
|
||||
ASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAOSjJs9oaVFhOXx6YrIIkgwN
|
||||
AiL1nXmnfh8OmU62B75ZC1ob2nboWdTJEsCZk5Qrv+WqLSslOQYtONGw0K//4tOL
|
||||
TH8HEbNfLdjL6ooblgbh8CyttkENac9hfz8Z/83x3Bx2h2PTXaw8SN1GQpNm1KC+
|
||||
GrkqAyiahsO4o17/Wem4AXAfwGbYH96leyY5k0AfbmmkoIq3L0hHG5Rmg+Yf5Vti
|
||||
dJY1aWGxA/G7pOWQaRPlDp1xYtYD69cC3/XoZsGeTK+jLdEW50oq15a1wAc6qvMZ
|
||||
aTWQ7h0+T4AX8PiduZjSfmTbz2+cHBcaw7b+hGZjuhjDO+o5gQiyLtS+wF+yZlsC
|
||||
AwEAATANBgkqhkiG9w0BAQUFAAOCAQEADw2bzLhqngco0a3U5XVvC3yEGmJrDwVv
|
||||
em4fuL2/QTRsNM7APeQrZ4I7SSXWVd/XL/77CeJbwfmP9UlB2+eUpBuXUf4TArua
|
||||
KdLZM5HOjVWvBvCGXQxjAOVJITyd52uqeCT+kqRhEEfTmmo/DKUP6QIWYNgS7M62
|
||||
BuiOnD4OU0TS9gs7kw73qD7Kzh7MTsCLP77BrxtDAJvzYAMOyyZMnCg6ony9bCZe
|
||||
7N65svyFtk6EufWydgzM62FCfuN8TMEPuFV7dcpeQsRUed7/IiEhT6NjpNODF+pL
|
||||
lzFSVOaI0OaAO/6Y1lUp67BfmOdzqlIVZKaKSzpdYHoxjXj7WR9AcA==
|
||||
-----END CERTIFICATE-----
|
||||
|
||||
+66
-17
@@ -20,6 +20,7 @@ import (
|
||||
"bytes"
|
||||
"crypto/x509"
|
||||
"encoding/hex"
|
||||
"net"
|
||||
"os"
|
||||
"strings"
|
||||
"text/template"
|
||||
@@ -32,32 +33,38 @@ var layout = `Not Before: {{.NotBefore | certStart}}
|
||||
Not After : {{.NotAfter | certEnd}}
|
||||
Signature algorithm: {{.SignatureAlgorithm}}
|
||||
Subject Info:
|
||||
CommonName: {{.Subject.CommonName}}
|
||||
Organization: {{.Subject.Organization}}
|
||||
OrganizationalUnit: {{.Subject.OrganizationalUnit}}
|
||||
Country: {{.Subject.Country}}
|
||||
Locality: {{.Subject.Locality}}
|
||||
CommonName: {{.Subject.CommonName | formatEmptyString}}
|
||||
Organization: {{.Subject.Organization | formatEmptyArray}}
|
||||
OrganizationalUnit: {{.Subject.OrganizationalUnit | formatEmptyArray}}
|
||||
Country: {{.Subject.Country | formatEmptyArray}}
|
||||
Locality: {{.Subject.Locality | formatEmptyArray}}
|
||||
Issuer Info:
|
||||
CommonName: {{.Issuer.CommonName}}
|
||||
Organization: {{.Issuer.Organization}}
|
||||
OrganizationalUnit: {{.Issuer.OrganizationalUnit}}
|
||||
Country: {{.Issuer.Country}}
|
||||
Locality: {{.Issuer.Locality}}
|
||||
Subject Key ID : {{.SubjectKeyId | hexify}}
|
||||
Authority Key ID: {{.AuthorityKeyId | hexify}}
|
||||
Alternate DNS Names: {{.DNSNames}}
|
||||
CommonName: {{.Issuer.CommonName | formatEmptyString}}
|
||||
Organization: {{.Issuer.Organization | formatEmptyArray}}
|
||||
OrganizationalUnit: {{.Issuer.OrganizationalUnit | formatEmptyArray}}
|
||||
Country: {{.Issuer.Country | formatEmptyArray}}
|
||||
Locality: {{.Issuer.Locality | formatEmptyArray}}
|
||||
Subject Key ID : {{.SubjectKeyId | hexify | formatEmptyString}}
|
||||
Authority Key ID: {{.AuthorityKeyId | hexify | formatEmptyString}}
|
||||
Alternate DNS Names: {{.DNSNames | displayStringArray | formatEmptyString}}
|
||||
Alternate IP Addresses: {{.IPAddresses | displayIpArray | formatEmptyString}}
|
||||
Email Addresses: {{.EmailAddresses | displayStringArray | formatEmptyString}}
|
||||
Serial Number: {{.SerialNumber}}
|
||||
|
||||
`
|
||||
|
||||
// displayCert takes in an x509 Certificate object and prints out relevant
|
||||
// information. Start and end dates are colored based on whether or not
|
||||
// the certificate is expired, not expired, or close to expiring.
|
||||
func displayCert(cert *x509.Certificate) {
|
||||
cert.IPAddresses = append(cert.IPAddresses, net.ParseIP("74.125.19.99"))
|
||||
funcMap := template.FuncMap{
|
||||
"hexify": hexify,
|
||||
"certStart": certStart,
|
||||
"certEnd": certEnd,
|
||||
"hexify": hexify,
|
||||
"certStart": certStart,
|
||||
"certEnd": certEnd,
|
||||
"displayStringArray": displayStringArray,
|
||||
"displayIpArray": displayIpArray,
|
||||
"formatEmptyString": formatEmptyString,
|
||||
"formatEmptyArray": formatEmptyArray,
|
||||
}
|
||||
t := template.New("Cert template").Funcs(funcMap)
|
||||
t, _ = t.Parse(layout)
|
||||
@@ -65,6 +72,48 @@ func displayCert(cert *x509.Certificate) {
|
||||
|
||||
}
|
||||
|
||||
// formatEmptyString returns N/A if the input is empty,
|
||||
// else it returns the string itself.
|
||||
func formatEmptyString(str string) string {
|
||||
if str == "" {
|
||||
return "N/A"
|
||||
} else {
|
||||
return str
|
||||
}
|
||||
}
|
||||
|
||||
// formatEmptyArray returns N/A if the input is empty,
|
||||
// else it returns the array itself.
|
||||
func formatEmptyArray(arr []string) []string {
|
||||
if len(arr) == 0 {
|
||||
return []string{"N/A"}
|
||||
} else {
|
||||
return arr
|
||||
}
|
||||
}
|
||||
|
||||
// displayStringArray formats a given array of strings
|
||||
// as a newline separated string to return.
|
||||
func displayStringArray(arr []string) string {
|
||||
var str bytes.Buffer
|
||||
for _, elem := range arr {
|
||||
str.WriteString("\n ")
|
||||
str.WriteString(elem)
|
||||
}
|
||||
return str.String()
|
||||
}
|
||||
|
||||
// displayIpArray formats a given array of ip addresses
|
||||
// as a newline separated string to return.
|
||||
func displayIpArray(arr []net.IP) string {
|
||||
var str bytes.Buffer
|
||||
for _, elem := range arr {
|
||||
str.WriteString("\n ")
|
||||
str.WriteString(elem.String())
|
||||
}
|
||||
return str.String()
|
||||
}
|
||||
|
||||
// certStart takes a given start time for the validity of
|
||||
// a certificate and returns that time colored properly
|
||||
// based on how close it is to expiry. If it's more than
|
||||
|
||||
Reference in New Issue
Block a user