Refactor certificate output parsing and add unit tests for parseCertOutput function
This commit is contained in:
@@ -126,7 +126,15 @@ func (m *Manager) GetStatus(domain string) *CertStatus {
|
||||
return status
|
||||
}
|
||||
|
||||
for line := range strings.SplitSeq(string(out), "\n") {
|
||||
parseCertOutput(string(out), status)
|
||||
|
||||
return status
|
||||
}
|
||||
|
||||
// parseCertOutput parses the output of `openssl x509 -noout -enddate -issuer -subject`
|
||||
// and populates the given CertStatus.
|
||||
func parseCertOutput(output string, status *CertStatus) {
|
||||
for line := range strings.SplitSeq(output, "\n") {
|
||||
line = strings.TrimSpace(line)
|
||||
if strings.HasPrefix(line, "notAfter=") {
|
||||
dateStr := strings.TrimPrefix(line, "notAfter=")
|
||||
@@ -142,13 +150,11 @@ func (m *Manager) GetStatus(domain string) *CertStatus {
|
||||
status.IssuerCN = strings.TrimPrefix(line, "issuer=")
|
||||
}
|
||||
if strings.HasPrefix(line, "subject=") {
|
||||
if strings.Contains(line, "CN = *.") {
|
||||
if strings.Contains(line, "CN=*.") || strings.Contains(line, "CN = *.") {
|
||||
status.Wildcard = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return status
|
||||
}
|
||||
|
||||
// CertPath returns the fullchain.pem path for a domain.
|
||||
|
||||
Reference in New Issue
Block a user