Skip to content

Commit

Permalink
Merge pull request #27 from opsre/fix_dnsNames
Browse files Browse the repository at this point in the history
  • Loading branch information
eryajf authored Nov 22, 2024
2 parents 7d93a36 + b6e634f commit 1e0ab67
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion pkg/export/record_cert.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package export
import (
"context"
"crypto/tls"
"crypto/x509"
"fmt"
"net"
"strings"
Expand Down Expand Up @@ -93,7 +94,7 @@ func GetCertInfo(record provider.GetRecordCertReq) (certInfo provider.RecordCert
cert := certs[0]
certInfo.SubjectCommonName = cert.Subject.CommonName
certInfo.IssuerCommonName = cert.Issuer.CommonName
if strings.Contains(certInfo.SubjectCommonName, record.DomainName) || strings.Contains(certInfo.IssuerCommonName, record.DomainName) {
if strings.Contains(certInfo.SubjectCommonName, record.DomainName) || checkCertMatched(record, cert) {
certInfo.CertMatched = true
} else {
certInfo.CertMatched = false
Expand Down Expand Up @@ -160,3 +161,14 @@ func isPortOpen(domain string) bool {
defer conn.Close()
return true
}

// checkCertMatched 检查证书是否匹配
// https://github.com/opsre/cloud_dns_exporter/issues/25
func checkCertMatched(record provider.GetRecordCertReq, cert *x509.Certificate) bool {
for _, name := range cert.DNSNames {
if strings.Contains(name, record.DomainName) {
return true
}
}
return false
}

0 comments on commit 1e0ab67

Please sign in to comment.