-
Notifications
You must be signed in to change notification settings - Fork 473
/
cert_info.go
39 lines (33 loc) · 923 Bytes
/
cert_info.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
package models
import (
"crypto/x509"
"encoding/pem"
"time"
)
// CertInfo contains the information for a given certificate
type CertInfo struct {
SecretName string `json:"secretName"`
SecretNamespace string `json:"secretNamespace"`
DNSNames []string `json:"dnsNames"`
Issuer string `json:"issuer"`
NotBefore time.Time `json:"notBefore"`
NotAfter time.Time `json:"notAfter"`
Error string `json:"error"`
Accessible bool `json:"accessible"`
}
func (ci *CertInfo) Parse(certificate []byte) {
block, _ := pem.Decode(certificate)
if block == nil {
ci.Error = "unable to decode certificate"
return
}
cert, err := x509.ParseCertificate(block.Bytes)
if err != nil {
ci.Error = "unable to parse certificate"
return
}
ci.Issuer = cert.Issuer.String()
ci.NotBefore = cert.NotBefore
ci.NotAfter = cert.NotAfter
ci.Accessible = true
}