-
Notifications
You must be signed in to change notification settings - Fork 13
/
print.go
79 lines (64 loc) · 2.06 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
68
69
70
71
72
73
74
75
76
77
78
79
package main
import (
"fmt"
"github.com/pete911/certinfo/pkg/cert"
)
func PrintCertificatesLocations(certificateLocations []cert.CertificateLocation, printChains, printPem bool) {
for _, certificateLocation := range certificateLocations {
if certificateLocation.Error != nil {
fmt.Printf("--- [%s: %v] ---\n", certificateLocation.Name(), certificateLocation.Error)
fmt.Println()
continue
}
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 {
if certificateLocation.Error != nil {
fmt.Printf("--- [%s: %v] ---\n", certificateLocation.Name(), certificateLocation.Error)
fmt.Println()
continue
}
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()
}
}
}