middleware-manager/models/mtls.go
hhftechnologies 44a80ab152 add legacy_p12 option for PKCS#12 generation
add a legacy_p12 boolean to CreateClientRequest (backend model and frontend type) to support generating PKCS#12 files with legacy encryption for iOS/older device compatibility. CertGenerator now selects pkcs12.Legacy when legacy_p12 is true (defaults to Modern otherwise). UI: add a checkbox to the client cert creation dialog and initialize form state to include legacy_p12.
2026-03-01 13:23:10 +05:30

74 lines
2.8 KiB
Go

package models
import (
"time"
)
// MTLSConfig represents the global mTLS configuration (singleton)
type MTLSConfig struct {
ID int `json:"id"`
Enabled bool `json:"enabled"`
CACert string `json:"ca_cert,omitempty"`
CAKey string `json:"-"` // Never expose private key via API
CACertPath string `json:"ca_cert_path"`
CASubject string `json:"ca_subject"`
CAExpiry *time.Time `json:"ca_expiry,omitempty"`
CertsBasePath string `json:"certs_base_path"`
HasCA bool `json:"has_ca"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
// MTLSClient represents a client certificate
type MTLSClient struct {
ID string `json:"id"`
Name string `json:"name"`
Cert string `json:"cert,omitempty"`
Key string `json:"-"` // Never expose private key via API
P12 []byte `json:"-"` // Binary data, downloaded separately
P12PasswordHint string `json:"p12_password_hint,omitempty"`
Subject string `json:"subject"`
Expiry *time.Time `json:"expiry,omitempty"`
Revoked bool `json:"revoked"`
RevokedAt *time.Time `json:"revoked_at,omitempty"`
CreatedAt time.Time `json:"created_at"`
}
// CreateCARequest represents the request to create a new Certificate Authority
type CreateCARequest struct {
CommonName string `json:"common_name" binding:"required"`
Organization string `json:"organization"`
Country string `json:"country"`
ValidityDays int `json:"validity_days"` // Default: 1825 (5 years)
}
// CreateClientRequest represents the request to create a new client certificate
type CreateClientRequest struct {
Name string `json:"name" binding:"required"`
ValidityDays int `json:"validity_days"` // Default: 730 (2 years)
P12Password string `json:"p12_password" binding:"required"`
LegacyP12 bool `json:"legacy_p12"` // Use legacy encryption for iOS/older device compatibility
}
// UpdateMTLSConfigRequest represents the request to update resource mTLS settings
type UpdateMTLSConfigRequest struct {
MTLSEnabled bool `json:"mtls_enabled"`
}
// MTLSConfigResponse is the API response for mTLS configuration
type MTLSConfigResponse struct {
MTLSConfig
ClientCount int `json:"client_count"`
}
// MTLSMiddlewareConfig represents the mtlswhitelist plugin configuration
type MTLSMiddlewareConfig struct {
// Rules for certificate validation (JSON array of rules)
Rules string `json:"rules"`
// RequestHeaders to add to requests with cert info (JSON object)
RequestHeaders string `json:"request_headers"`
// RejectMessage to return when certificate validation fails
RejectMessage string `json:"reject_message"`
// RefreshInterval in seconds for external data
RefreshInterval int `json:"refresh_interval"`
}