mirror of
https://github.com/go-acme/lego
synced 2026-03-14 14:35:48 +01:00
fix: use IPs to define the main domain (#2817)
This commit is contained in:
parent
2ce04a6586
commit
a7145a29ac
2 changed files with 24 additions and 5 deletions
|
|
@ -242,15 +242,15 @@ func ParsePEMCertificate(cert []byte) (*x509.Certificate, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetCertificateMainDomain(cert *x509.Certificate) (string, error) {
|
func GetCertificateMainDomain(cert *x509.Certificate) (string, error) {
|
||||||
return getMainDomain(cert.Subject, cert.DNSNames)
|
return getMainDomain(cert.Subject, cert.DNSNames, cert.IPAddresses)
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetCSRMainDomain(cert *x509.CertificateRequest) (string, error) {
|
func GetCSRMainDomain(cert *x509.CertificateRequest) (string, error) {
|
||||||
return getMainDomain(cert.Subject, cert.DNSNames)
|
return getMainDomain(cert.Subject, cert.DNSNames, cert.IPAddresses)
|
||||||
}
|
}
|
||||||
|
|
||||||
func getMainDomain(subject pkix.Name, dnsNames []string) (string, error) {
|
func getMainDomain(subject pkix.Name, dnsNames []string, ips []net.IP) (string, error) {
|
||||||
if subject.CommonName == "" && len(dnsNames) == 0 {
|
if subject.CommonName == "" && len(dnsNames) == 0 && len(ips) == 0 {
|
||||||
return "", errors.New("missing domain")
|
return "", errors.New("missing domain")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -258,9 +258,13 @@ func getMainDomain(subject pkix.Name, dnsNames []string) (string, error) {
|
||||||
return subject.CommonName, nil
|
return subject.CommonName, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(dnsNames) > 0 {
|
||||||
return dnsNames[0], nil
|
return dnsNames[0], nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return ips[0].String(), nil
|
||||||
|
}
|
||||||
|
|
||||||
func ExtractDomains(cert *x509.Certificate) []string {
|
func ExtractDomains(cert *x509.Certificate) []string {
|
||||||
var domains []string
|
var domains []string
|
||||||
if cert.Subject.CommonName != "" {
|
if cert.Subject.CommonName != "" {
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ package cmd
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"net"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
@ -100,6 +101,11 @@ func listCertificates(ctx *cli.Context) error {
|
||||||
} else {
|
} else {
|
||||||
fmt.Println(" Certificate Name:", name)
|
fmt.Println(" Certificate Name:", name)
|
||||||
fmt.Println(" Domains:", strings.Join(pCert.DNSNames, ", "))
|
fmt.Println(" Domains:", strings.Join(pCert.DNSNames, ", "))
|
||||||
|
|
||||||
|
if len(pCert.IPAddresses) > 0 {
|
||||||
|
fmt.Println(" IPs:", formatIPAddresses(pCert.IPAddresses))
|
||||||
|
}
|
||||||
|
|
||||||
fmt.Println(" Expiry Date:", pCert.NotAfter)
|
fmt.Println(" Expiry Date:", pCert.NotAfter)
|
||||||
fmt.Println(" Certificate Path:", filename)
|
fmt.Println(" Certificate Path:", filename)
|
||||||
fmt.Println()
|
fmt.Println()
|
||||||
|
|
@ -150,3 +156,12 @@ func listAccount(ctx *cli.Context) error {
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func formatIPAddresses(ipAddresses []net.IP) string {
|
||||||
|
var ips []string
|
||||||
|
for _, ip := range ipAddresses {
|
||||||
|
ips = append(ips, ip.String())
|
||||||
|
}
|
||||||
|
|
||||||
|
return strings.Join(ips, ", ")
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue