mirror of
https://github.com/shankar0123/certctl.git
synced 2026-06-07 17:51:29 +00:00
feat: S/MIME certificate support in integration tests + test env docs
Add S/MIME (emailProtection EKU) end-to-end test coverage: - ValidateCommonName() now accepts email addresses for S/MIME certs - S/MIME test profile (prof-test-smime) in seed data - Phase 11 test: issuance, EKU, KeyUsage, email SAN verification - EST config enabled in test Docker Compose - Portable KeyUsage parsing (awk, works on BSD/GNU) - Full test environment documentation (docs/test-env.md) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -3,6 +3,7 @@ package handler
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
"net/mail"
|
||||
"strings"
|
||||
)
|
||||
|
||||
@@ -13,6 +14,7 @@ type ValidationError struct {
|
||||
}
|
||||
|
||||
// ValidateCommonName validates a certificate common name.
|
||||
// Accepts hostnames (TLS), IP addresses, and email addresses (S/MIME).
|
||||
func ValidateCommonName(cn string) error {
|
||||
if cn == "" {
|
||||
return ValidationError{Field: "common_name", Message: "common_name is required"}
|
||||
@@ -20,6 +22,13 @@ func ValidateCommonName(cn string) error {
|
||||
if len(cn) > 253 {
|
||||
return ValidationError{Field: "common_name", Message: "common_name must be 253 characters or fewer"}
|
||||
}
|
||||
// If CN contains @, validate as email address (S/MIME certificates)
|
||||
if strings.Contains(cn, "@") {
|
||||
if _, err := mail.ParseAddress(cn); err != nil {
|
||||
return ValidationError{Field: "common_name", Message: fmt.Sprintf("invalid email format for S/MIME common name: %v", err)}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
// Basic hostname validation: allow alphanumeric, dots, hyphens
|
||||
if err := isValidHostname(cn); err != nil {
|
||||
return ValidationError{Field: "common_name", Message: fmt.Sprintf("invalid hostname format: %v", err)}
|
||||
|
||||
Reference in New Issue
Block a user