Linting and formatting

This commit is contained in:
Zen Wen
2025-10-13 00:50:28 +08:00
parent dd610e5f75
commit d155ea3795
3 changed files with 15 additions and 18 deletions

View File

@@ -432,18 +432,18 @@ func (a *ACMEHandler) HandleGetExpiredDomains(w http.ResponseWriter, r *http.Req
// to renew the certificate, and sends a JSON response indicating the result of the renewal process. // to renew the certificate, and sends a JSON response indicating the result of the renewal process.
func (a *ACMEHandler) HandleRenewCertificate(w http.ResponseWriter, r *http.Request) { func (a *ACMEHandler) HandleRenewCertificate(w http.ResponseWriter, r *http.Request) {
domainPara, err := utils.PostPara(r, "domains") domainPara, err := utils.PostPara(r, "domains")
//Clean each domain //Clean each domain
cleanedDomains := []string{} cleanedDomains := []string{}
if (domainPara != "") { if domainPara != "" {
for _, d := range strings.Split(domainPara, ",") { for _, d := range strings.Split(domainPara, ",") {
// Apply normalization on each domain // Apply normalization on each domain
nd, err := utils.NormalizeDomain(d) nd, err := utils.NormalizeDomain(d)
if err != nil { if err != nil {
utils.SendErrorResponse(w, jsonEscape(err.Error())) utils.SendErrorResponse(w, jsonEscape(err.Error()))
return return
} }
cleanedDomains = append(cleanedDomains, nd) cleanedDomains = append(cleanedDomains, nd)
} }
} }
@@ -507,7 +507,6 @@ func (a *ACMEHandler) HandleRenewCertificate(w http.ResponseWriter, r *http.Requ
dns = true dns = true
} }
// Default propagation timeout is 300 seconds // Default propagation timeout is 300 seconds
propagationTimeout := 300 propagationTimeout := 300
if dns { if dns {
@@ -549,7 +548,6 @@ func (a *ACMEHandler) HandleRenewCertificate(w http.ResponseWriter, r *http.Requ
a.Logf("Could not extract SANs from PEM, using domainPara only", err) a.Logf("Could not extract SANs from PEM, using domainPara only", err)
} }
// Extract DNS servers from the request // Extract DNS servers from the request
var dnsServers []string var dnsServers []string
dnsServersPara, err := utils.PostPara(r, "dnsServers") dnsServersPara, err := utils.PostPara(r, "dnsServers")

View File

@@ -40,8 +40,6 @@ func ExtractDomains(certBytes []byte) ([]string, error) {
return []string{}, errors.New("decode cert bytes failed") return []string{}, errors.New("decode cert bytes failed")
} }
func ExtractIssuerName(certBytes []byte) (string, error) { func ExtractIssuerName(certBytes []byte) (string, error) {
// Parse the PEM block // Parse the PEM block
block, _ := pem.Decode(certBytes) block, _ := pem.Decode(certBytes)
@@ -71,9 +69,9 @@ func ExtractDomainsFromPEM(pemFilePath string) ([]string, error) {
certBytes, err := os.ReadFile(pemFilePath) certBytes, err := os.ReadFile(pemFilePath)
if err != nil { if err != nil {
return nil, err return nil, err
} }
domains,err := ExtractDomains(certBytes) domains, err := ExtractDomains(certBytes)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@@ -207,16 +207,17 @@ func ValidateListeningAddress(address string) bool {
// - Converts to lowercase // - Converts to lowercase
// - Removes trailing dot (FQDN canonicalization) // - Removes trailing dot (FQDN canonicalization)
// - Checks that the domain conforms to standard rules: // - Checks that the domain conforms to standard rules:
// * Each label ≤ 63 characters // - Each label ≤ 63 characters
// * Only letters, digits, and hyphens // - Only letters, digits, and hyphens
// * Labels do not start or end with a hyphen // - Labels do not start or end with a hyphen
// * Full domain ≤ 253 characters // - Full domain ≤ 253 characters
//
// Returns an empty string if the domain is invalid. // Returns an empty string if the domain is invalid.
func NormalizeDomain(d string) (string, error) { func NormalizeDomain(d string) (string, error) {
d = strings.TrimSpace(d) d = strings.TrimSpace(d)
d = strings.ToLower(d) d = strings.ToLower(d)
d = strings.TrimSuffix(d, ".") d = strings.TrimSuffix(d, ".")
if len(d) == 0 { if len(d) == 0 {
return "", errors.New("domain is empty") return "", errors.New("domain is empty")
} }
@@ -226,7 +227,7 @@ func NormalizeDomain(d string) (string, error) {
labels := strings.Split(d, ".") labels := strings.Split(d, ".")
for index, label := range labels { for index, label := range labels {
if index ==0 { if index == 0 {
if len(label) == 1 && label == "*" { if len(label) == 1 && label == "*" {
continue continue
} }
@@ -239,11 +240,11 @@ func NormalizeDomain(d string) (string, error) {
} }
for i, r := range label { for i, r := range label {
if !(unicode.IsLetter(r) || unicode.IsDigit(r) || r == '-') { if !unicode.IsLetter(r) && !unicode.IsDigit(r) && r != '-' {
return "", errors.New("Domain '" + d + "' not valid: Invalid character '" + string(r) + "' in label") return "", errors.New("Domain '" + d + "' not valid: Invalid character '" + string(r) + "' in label")
} }
if (i == 0 || i == len(label)-1) && r == '-' { if (i == 0 || i == len(label)-1) && r == '-' {
return "", errors.New("Domain '" + d + "' not valid: label '"+ label +"' starts or ends with hyphen") return "", errors.New("Domain '" + d + "' not valid: label '" + label + "' starts or ends with hyphen")
} }
} }
} }