Skip to content

Commit

Permalink
don't show field if no san information
Browse files Browse the repository at this point in the history
  • Loading branch information
nothinux committed Mar 5, 2022
1 parent fceb838 commit cf95b60
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
21 changes: 12 additions & 9 deletions certify.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,16 +143,19 @@ func CertInfo(cert *x509.Certificate) string {
buf.WriteString(fmt.Sprintf("%16s%v\n", "", parseExtKeyUsage(cert.ExtKeyUsage)))
buf.WriteString(fmt.Sprintf("%8sX509v3 Basic Constraints:\n", ""))
buf.WriteString(fmt.Sprintf("%12sCA: %v\n", "", cert.IsCA))
buf.WriteString(fmt.Sprintf("%8sX509v3 Subject Alternative Name:\n", ""))
if len(cert.IPAddresses) != 0 {
var ips []string
for _, ip := range cert.IPAddresses {
ips = append(ips, ip.String())

if len(cert.IPAddresses) != 0 || len(cert.DNSNames) != 0 {
buf.WriteString(fmt.Sprintf("%8sX509v3 Subject Alternative Name:\n", ""))
if len(cert.IPAddresses) != 0 {
var ips []string
for _, ip := range cert.IPAddresses {
ips = append(ips, ip.String())
}
buf.WriteString(fmt.Sprintf("%12sIP Address: %v\n", "", strings.Join(ips, ", ")))
}
if len(cert.DNSNames) != 0 {
buf.WriteString(fmt.Sprintf("%12sDNS: %v\n", "", strings.Join(cert.DNSNames, ", ")))
}
buf.WriteString(fmt.Sprintf("%12sIP Address: %v\n", "", strings.Join(ips, ", ")))
}
if len(cert.DNSNames) != 0 {
buf.WriteString(fmt.Sprintf("%12sDNS: %v\n", "", strings.Join(cert.DNSNames, ", ")))
}

buf.WriteString(fmt.Sprintf("%8sSignature Algorithm: %v\n", "", cert.SignatureAlgorithm))
Expand Down
6 changes: 3 additions & 3 deletions helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ func parseExtKeyUsage(ekus []x509.ExtKeyUsage) string {

for _, eku := range ekus {
if eku == x509.ExtKeyUsageAny {
extku = append(extku, "ExtKeyUsageAny")
extku = append(extku, "Any Usage")
} else if eku == x509.ExtKeyUsageClientAuth {
extku = append(extku, "ExtKeyUsageClientAuth")
extku = append(extku, "TLS Web Client Authentication")
} else if eku == x509.ExtKeyUsageServerAuth {
extku = append(extku, "ExtKeyUsageServerAuth")
extku = append(extku, "TLS Web Server Authentication")
} else {
extku = append(extku, strconv.Itoa(int(eku)))
}
Expand Down

0 comments on commit cf95b60

Please sign in to comment.