forked from pete911/certinfo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
print.go
67 lines (54 loc) · 1.74 KB
/
print.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package main
import (
"fmt"
"github.com/pete911/certinfo/pkg/cert"
)
func PrintCertificatesLocations(certificateLocations []cert.CertificateLocation, printChains, printPem bool) {
for _, certificateLocation := range certificateLocations {
fmt.Printf("--- [%s] ---\n", certificateLocation.Name())
printCertificates(certificateLocation.Certificates, printPem)
if certificateLocation.VerifiedChains != nil {
fmt.Printf("--- %d verified chains ---\n", len(certificateLocation.VerifiedChains))
}
if printChains {
for i, chain := range certificateLocation.VerifiedChains {
fmt.Printf("--- chain %d ---\n", i+1)
printCertificates(chain, printPem)
}
}
}
}
func printCertificates(certificates []cert.Certificate, printPem bool) {
for _, certificate := range certificates {
fmt.Println(certificate)
fmt.Println()
if printPem {
fmt.Println(string(certificate.ToPEM()))
}
}
}
func PrintPemOnly(certificateLocations []cert.CertificateLocation, printChains bool) {
for _, certificateLocation := range certificateLocations {
for _, certificate := range certificateLocation.Certificates {
fmt.Print(string(certificate.ToPEM()))
}
if printChains {
for _, chains := range certificateLocation.VerifiedChains {
fmt.Println()
for _, chain := range chains {
fmt.Print(string(chain.ToPEM()))
}
}
}
}
}
func PrintCertificatesExpiry(certificateLocations []cert.CertificateLocation) {
for _, certificateLocation := range certificateLocations {
fmt.Printf("--- [%s] ---\n", certificateLocation.Name())
for _, certificate := range certificateLocation.Certificates {
fmt.Printf("Subject: %s\n", certificate.SubjectString())
fmt.Printf("Expiry: %s\n", certificate.ExpiryString())
fmt.Println()
}
}
}