Few manual optimizations and corrections of AI generated code.
This commit is contained in:
26
ca.go
26
ca.go
@@ -348,9 +348,16 @@ func InitCA(overwrite bool) error {
|
|||||||
// Helper: issue a single certificate and key, save to files, return error if any
|
// Helper: issue a single certificate and key, save to files, return error if any
|
||||||
func issueSingleCertificate(def CertificateDefinition, overwrite, verbose bool) error {
|
func issueSingleCertificate(def CertificateDefinition, overwrite, verbose bool) error {
|
||||||
// Validate Name
|
// Validate Name
|
||||||
if !isValidName(def.Name) {
|
|
||||||
|
isValidName, err := regexp.MatchString(`^[A-Za-z0-9_-]+$`, def.Name)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("error validating certificate name: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if !isValidName {
|
||||||
return fmt.Errorf("certificate name must be specified and contain only letters, numbers, dash, or underscore")
|
return fmt.Errorf("certificate name must be specified and contain only letters, numbers, dash, or underscore")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize Subject if not specified
|
// Initialize Subject if not specified
|
||||||
if def.Subject == "" {
|
if def.Subject == "" {
|
||||||
def.Subject = def.Name
|
def.Subject = def.Name
|
||||||
@@ -372,14 +379,15 @@ func issueSingleCertificate(def CertificateDefinition, overwrite, verbose bool)
|
|||||||
}
|
}
|
||||||
|
|
||||||
var validityDur time.Duration
|
var validityDur time.Duration
|
||||||
if def.Validity != "" {
|
validity := def.Validity
|
||||||
validityDur, err = parseValidity(def.Validity)
|
if validity == "" {
|
||||||
|
validity = "1y"
|
||||||
|
}
|
||||||
|
|
||||||
|
validityDur, err = parseValidity(validity)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("invalid validity value: %v", err)
|
return fmt.Errorf("invalid validity value: %v", err)
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
validityDur = 365 * 24 * time.Hour // default 1 year
|
|
||||||
}
|
|
||||||
|
|
||||||
var subjectPKIX pkix.Name
|
var subjectPKIX pkix.Name
|
||||||
if isDNFormat(def.Subject) {
|
if isDNFormat(def.Subject) {
|
||||||
@@ -658,9 +666,3 @@ func optionalSlice(s string) []string {
|
|||||||
}
|
}
|
||||||
return []string{s}
|
return []string{s}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Helper: validate certificate name using regex
|
|
||||||
func isValidName(name string) bool {
|
|
||||||
matched, _ := regexp.MatchString(`^[A-Za-z0-9_-]+$`, name)
|
|
||||||
return matched
|
|
||||||
}
|
|
||||||
|
Reference in New Issue
Block a user