Documentation
ΒΆ
Index ΒΆ
- Variables
- func GetCACCertificateTypes() []string
- func GetPIVSlotNames() map[string]string
- type APIConfig
- type AddTrustAnchorRequest
- type AuthEventFilters
- type AuthEventStats
- type AuthenticationResult
- type AzureKeyVaultProvider
- func (p *AzureKeyVaultProvider) Connect(ctx context.Context) error
- func (p *AzureKeyVaultProvider) Disconnect() error
- func (p *AzureKeyVaultProvider) GetCertificate(ctx context.Context, keyID string) (*x509.Certificate, error)
- func (p *AzureKeyVaultProvider) GetKey(ctx context.Context, keyID string) (crypto.PrivateKey, error)
- func (p *AzureKeyVaultProvider) GetProviderInfo() *HSMProviderInfo
- func (p *AzureKeyVaultProvider) ListKeys(ctx context.Context) ([]HSMKeyInfo, error)
- func (p *AzureKeyVaultProvider) Sign(ctx context.Context, keyID string, digest []byte) ([]byte, error)
- func (p *AzureKeyVaultProvider) ValidateKey(ctx context.Context, keyID string) error
- type BunRepository
- func (r *BunRepository) CreateAuthEvent(ctx context.Context, event *CertificateAuthEvent) error
- func (r *BunRepository) CreateCRL(ctx context.Context, crl *CertificateRevocationList) error
- func (r *BunRepository) CreateCertificate(ctx context.Context, cert *Certificate) error
- func (r *BunRepository) CreateOCSPResponse(ctx context.Context, resp *OCSPResponse) error
- func (r *BunRepository) CreatePolicy(ctx context.Context, policy *CertificatePolicy) error
- func (r *BunRepository) CreateTrustAnchor(ctx context.Context, anchor *TrustAnchor) error
- func (r *BunRepository) DeleteCRL(ctx context.Context, id string) error
- func (r *BunRepository) DeleteCertificate(ctx context.Context, id string) error
- func (r *BunRepository) DeleteExpiredOCSPResponses(ctx context.Context) error
- func (r *BunRepository) DeletePolicy(ctx context.Context, id string) error
- func (r *BunRepository) DeleteTrustAnchor(ctx context.Context, id string) error
- func (r *BunRepository) GetAuthEventStats(ctx context.Context, orgID string, since time.Time) (*AuthEventStats, error)
- func (r *BunRepository) GetCRL(ctx context.Context, id string) (*CertificateRevocationList, error)
- func (r *BunRepository) GetCRLByIssuer(ctx context.Context, issuer string) (*CertificateRevocationList, error)
- func (r *BunRepository) GetCertificate(ctx context.Context, id string) (*Certificate, error)
- func (r *BunRepository) GetCertificateByFingerprint(ctx context.Context, fingerprint string) (*Certificate, error)
- func (r *BunRepository) GetCertificateBySerialNumber(ctx context.Context, serialNumber string) (*Certificate, error)
- func (r *BunRepository) GetDefaultPolicy(ctx context.Context, orgID string) (*CertificatePolicy, error)
- func (r *BunRepository) GetDeviceCertificates(ctx context.Context, deviceID string) ([]*Certificate, error)
- func (r *BunRepository) GetExpiringCertificates(ctx context.Context, orgID string, days int) ([]*Certificate, error)
- func (r *BunRepository) GetOCSPResponse(ctx context.Context, certificateID string) (*OCSPResponse, error)
- func (r *BunRepository) GetPolicy(ctx context.Context, id string) (*CertificatePolicy, error)
- func (r *BunRepository) GetTrustAnchor(ctx context.Context, id string) (*TrustAnchor, error)
- func (r *BunRepository) GetTrustAnchorByFingerprint(ctx context.Context, fingerprint string) (*TrustAnchor, error)
- func (r *BunRepository) GetUserCertificates(ctx context.Context, userID string) ([]*Certificate, error)
- func (r *BunRepository) ListAuthEvents(ctx context.Context, filters AuthEventFilters) ([]*CertificateAuthEvent, error)
- func (r *BunRepository) ListCRLs(ctx context.Context, trustAnchorID string) ([]*CertificateRevocationList, error)
- func (r *BunRepository) ListCertificates(ctx context.Context, filters CertificateFilters) ([]*Certificate, error)
- func (r *BunRepository) ListPolicies(ctx context.Context, orgID string) ([]*CertificatePolicy, error)
- func (r *BunRepository) ListTrustAnchors(ctx context.Context, orgID string) ([]*TrustAnchor, error)
- func (r *BunRepository) RevokeCertificate(ctx context.Context, id string, reason string) error
- func (r *BunRepository) UpdateCRL(ctx context.Context, crl *CertificateRevocationList) error
- func (r *BunRepository) UpdateCertificate(ctx context.Context, cert *Certificate) error
- func (r *BunRepository) UpdateOCSPResponse(ctx context.Context, resp *OCSPResponse) error
- func (r *BunRepository) UpdatePolicy(ctx context.Context, policy *CertificatePolicy) error
- func (r *BunRepository) UpdateTrustAnchor(ctx context.Context, anchor *TrustAnchor) error
- type CACCardInfo
- type CACCertificate
- type Certificate
- type CertificateAuthEvent
- type CertificateFilters
- type CertificatePolicy
- type CertificateResponse
- type CertificateRevocationList
- type CertificateValidator
- type CertificatesResponse
- type CloudHSMProvider
- func (p *CloudHSMProvider) Connect(ctx context.Context) error
- func (p *CloudHSMProvider) Disconnect() error
- func (p *CloudHSMProvider) GetCertificate(ctx context.Context, keyID string) (*x509.Certificate, error)
- func (p *CloudHSMProvider) GetKey(ctx context.Context, keyID string) (crypto.PrivateKey, error)
- func (p *CloudHSMProvider) GetProviderInfo() *HSMProviderInfo
- func (p *CloudHSMProvider) ListKeys(ctx context.Context) ([]HSMKeyInfo, error)
- func (p *CloudHSMProvider) Sign(ctx context.Context, keyID string, digest []byte) ([]byte, error)
- func (p *CloudHSMProvider) ValidateKey(ctx context.Context, keyID string) error
- type Config
- type CreatePolicyRequest
- type ErrorResponse
- type GCPCloudHSMProvider
- func (p *GCPCloudHSMProvider) Connect(ctx context.Context) error
- func (p *GCPCloudHSMProvider) Disconnect() error
- func (p *GCPCloudHSMProvider) GetCertificate(ctx context.Context, keyID string) (*x509.Certificate, error)
- func (p *GCPCloudHSMProvider) GetKey(ctx context.Context, keyID string) (crypto.PrivateKey, error)
- func (p *GCPCloudHSMProvider) GetProviderInfo() *HSMProviderInfo
- func (p *GCPCloudHSMProvider) ListKeys(ctx context.Context) ([]HSMKeyInfo, error)
- func (p *GCPCloudHSMProvider) Sign(ctx context.Context, keyID string, digest []byte) ([]byte, error)
- func (p *GCPCloudHSMProvider) ValidateKey(ctx context.Context, keyID string) error
- type HSMConfig
- type HSMKeyInfo
- type HSMManager
- type HSMProvider
- type HSMProviderInfo
- type Handler
- func (h *Handler) AddTrustAnchor(c forge.Context) error
- func (h *Handler) AuthenticateWithCertificate(c forge.Context) error
- func (h *Handler) CreatePolicy(c forge.Context) error
- func (h *Handler) GetAuthStats(c forge.Context) error
- func (h *Handler) GetCertificate(c forge.Context) error
- func (h *Handler) GetExpiringCertificates(c forge.Context) error
- func (h *Handler) GetPolicy(c forge.Context) error
- func (h *Handler) GetTrustAnchors(c forge.Context) error
- func (h *Handler) ListCertificates(c forge.Context) error
- func (h *Handler) RegisterCertificate(c forge.Context) error
- func (h *Handler) RevokeCertificate(c forge.Context) error
- func (h *Handler) ValidateCertificate(c forge.Context) error
- type MTLSCertificateListResponse
- type MTLSCertificateResponse
- type MessageResponse
- type OCSPResponse
- type PIVCardInfo
- type PIVCertificate
- type PIVPINPolicy
- type PKCS11Provider
- func (p *PKCS11Provider) Connect(ctx context.Context) error
- func (p *PKCS11Provider) Disconnect() error
- func (p *PKCS11Provider) GetCertificate(ctx context.Context, keyID string) (*x509.Certificate, error)
- func (p *PKCS11Provider) GetKey(ctx context.Context, keyID string) (crypto.PrivateKey, error)
- func (p *PKCS11Provider) GetProviderInfo() *HSMProviderInfo
- func (p *PKCS11Provider) ListKeys(ctx context.Context) ([]HSMKeyInfo, error)
- func (p *PKCS11Provider) Sign(ctx context.Context, keyID string, digest []byte) ([]byte, error)
- func (p *PKCS11Provider) ValidateKey(ctx context.Context, keyID string) error
- type PinningConfig
- type Plugin
- func (p *Plugin) Description() string
- func (p *Plugin) HSMManager() *HSMManager
- func (p *Plugin) ID() string
- func (p *Plugin) Init(auth interface{}) error
- func (p *Plugin) Migrate() error
- func (p *Plugin) Name() string
- func (p *Plugin) RegisterHooks(hookRegistry *hooks.HookRegistry) error
- func (p *Plugin) RegisterRoutes(router forge.Router) error
- func (p *Plugin) RegisterServiceDecorators(services *registry.ServiceRegistry) error
- func (p *Plugin) Service() *Service
- func (p *Plugin) Shutdown() error
- func (p *Plugin) SmartCardProvider() *SmartCardProvider
- func (p *Plugin) Validator() *CertificateValidator
- func (p *Plugin) Version() string
- type RegisterCertificateRequest
- type Repository
- type RevocationChecker
- type RevocationConfig
- type SecurityConfig
- type Service
- func (s *Service) AddTrustAnchor(ctx context.Context, req *AddTrustAnchorRequest) (*TrustAnchor, error)
- func (s *Service) AuthenticateWithCertificate(ctx context.Context, certPEM []byte, orgID string) (*AuthenticationResult, error)
- func (s *Service) CreatePolicy(ctx context.Context, req *CreatePolicyRequest) (*CertificatePolicy, error)
- func (s *Service) GetAuthEventStats(ctx context.Context, orgID string, since time.Time) (*AuthEventStats, error)
- func (s *Service) GetCertificate(ctx context.Context, id string) (*Certificate, error)
- func (s *Service) GetExpiringCertificates(ctx context.Context, orgID string, days int) ([]*Certificate, error)
- func (s *Service) GetPolicy(ctx context.Context, id string) (*CertificatePolicy, error)
- func (s *Service) GetTrustAnchors(ctx context.Context, orgID string) ([]*TrustAnchor, error)
- func (s *Service) ListCertificates(ctx context.Context, filters CertificateFilters) ([]*Certificate, error)
- func (s *Service) RegisterCertificate(ctx context.Context, req *RegisterCertificateRequest) (*Certificate, error)
- func (s *Service) RevokeCertificate(ctx context.Context, id string, reason string) error
- type SessionConfig
- type SmartCardAuthRequest
- type SmartCardAuthResponse
- type SmartCardConfig
- type SmartCardProvider
- func (s *SmartCardProvider) AuthenticateWithCAC(ctx context.Context, cert *x509.Certificate, orgID string) (*SmartCardAuthResponse, error)
- func (s *SmartCardProvider) AuthenticateWithPIV(ctx context.Context, cert *x509.Certificate, orgID string) (*SmartCardAuthResponse, error)
- func (s *SmartCardProvider) ValidateCACCard(ctx context.Context, cert *x509.Certificate) (*CACCardInfo, error)
- func (s *SmartCardProvider) ValidatePIVCard(ctx context.Context, cert *x509.Certificate) (*PIVCardInfo, error)
- type StatusResponse
- type StringArray
- type SuccessResponse
- type TrustAnchor
- type TrustAnchorsConfig
- type TrustStoresResponse
- type ValidationConfig
- type ValidationError
- type ValidationResult
Constants ΒΆ
This section is empty.
Variables ΒΆ
var ( // Certificate Errors ErrCertificateNotFound = errors.New("certificate not found") ErrCertificateExpired = errors.New("certificate has expired") ErrCertificateRevoked = errors.New("certificate has been revoked") ErrCertificateInvalid = errors.New("certificate is invalid") ErrCertificateNotYetValid = errors.New("certificate is not yet valid") ErrCertificateSuspended = errors.New("certificate is suspended") // Validation Errors ErrInvalidSignature = errors.New("invalid certificate signature") ErrUntrustedCA = errors.New("certificate issued by untrusted CA") ErrInvalidKeyUsage = errors.New("invalid key usage for authentication") ErrKeyTooWeak = errors.New("certificate key size too weak") ErrUnsupportedAlgorithm = errors.New("unsupported key or signature algorithm") ErrCertificateChainInvalid = errors.New("certificate chain validation failed") // Pinning Errors ErrCertificateNotPinned = errors.New("certificate not pinned (required by policy)") ErrPinExpired = errors.New("certificate pin has expired") ErrPinMismatch = errors.New("certificate does not match pinned fingerprint") // Revocation Errors ErrCRLCheckFailed = errors.New("CRL check failed") ErrOCSPCheckFailed = errors.New("OCSP check failed") // PIV/CAC Errors ErrNotPIVCertificate = errors.New("certificate is not a PIV certificate") ErrNotCACCertificate = errors.New("certificate is not a CAC certificate") ErrSmartCardNotPresent = errors.New("smart card not present") ErrSmartCardLocked = errors.New("smart card is locked") ErrPINRequired = errors.New("smart card PIN required") ErrInvalidPIN = errors.New("invalid smart card PIN") // HSM Errors ErrHSMNotConfigured = errors.New("HSM not configured") ErrHSMConnectionFailed = errors.New("HSM connection failed") ErrHSMKeyNotFound = errors.New("HSM key not found") ErrHSMOperationFailed = errors.New("HSM operation failed") ErrHSMProviderUnsupported = errors.New("HSM provider not supported") // Policy Errors ErrPolicyNotFound = errors.New("certificate policy not found") ErrPolicyViolation = errors.New("certificate policy violation") ErrPolicyRequired = errors.New("certificate policy required but not found") // Trust Anchor Errors ErrTrustAnchorNotFound = errors.New("trust anchor not found") ErrTrustAnchorExpired = errors.New("trust anchor has expired") ErrNoTrustAnchors = errors.New("no trust anchors configured") // General Errors ErrCertificateParseFailed = errors.New("failed to parse certificate") ErrCRLParseFailed = errors.New("failed to parse CRL") ErrOCSPParseFailed = errors.New("failed to parse OCSP response") ErrInvalidPEM = errors.New("invalid PEM format") ErrMissingClientCert = errors.New("client certificate not provided") )
var ( // PIV OIDs OID_PIV_Authentication = asn1.ObjectIdentifier{2, 16, 840, 1, 101, 3, 2, 1, 3, 7} OID_PIV_CardAuth = asn1.ObjectIdentifier{2, 16, 840, 1, 101, 3, 2, 1, 3, 13} OID_PIV_DigitalSignature = asn1.ObjectIdentifier{2, 16, 840, 1, 101, 3, 2, 1, 3, 2} OID_PIV_KeyManagement = asn1.ObjectIdentifier{2, 16, 840, 1, 101, 3, 2, 1, 3, 4} // CAC OIDs OID_CAC_PKI = asn1.ObjectIdentifier{2, 16, 840, 1, 101, 2, 1, 11, 39} OID_CAC_Authentication = asn1.ObjectIdentifier{2, 16, 840, 1, 101, 2, 1, 11, 42} OID_CAC_Email = asn1.ObjectIdentifier{2, 16, 840, 1, 101, 2, 1, 11, 17} )
PIV/CAC OID Constants
Functions ΒΆ
func GetCACCertificateTypes ΒΆ
func GetCACCertificateTypes() []string
GetCACCertificateTypes returns CAC certificate types
func GetPIVSlotNames ΒΆ
GetPIVSlotNames returns human-readable PIV slot names
Types ΒΆ
type APIConfig ΒΆ
type APIConfig struct {
BasePath string `json:"basePath" yaml:"basePath"`
EnableManagement bool `json:"enableManagement" yaml:"enableManagement"` // Certificate management APIs
EnableValidation bool `json:"enableValidation" yaml:"enableValidation"` // Validation endpoint
EnableMetrics bool `json:"enableMetrics" yaml:"enableMetrics"`
}
APIConfig configures mTLS API endpoints
type AddTrustAnchorRequest ΒΆ
type AuthEventFilters ΒΆ
type AuthEventFilters struct {
OrganizationID string
CertificateID string
UserID string
EventType string
Status string
Since time.Time
Until time.Time
Limit int
Offset int
}
AuthEventFilters for filtering auth event queries
type AuthEventStats ΒΆ
type AuthEventStats struct {
TotalAttempts int
SuccessfulAuths int
FailedAuths int
ValidationErrors int
UniqueUsers int
UniqueCerts int
}
AuthEventStats contains authentication event statistics
type AuthenticationResult ΒΆ
type AuthenticationResult struct {
Success bool `json:"success"`
UserID string `json:"userId,omitempty"`
CertificateID string `json:"certificateId,omitempty"`
Certificate *Certificate `json:"certificate,omitempty"`
ValidationResult *ValidationResult `json:"validationResult,omitempty"`
Errors []error `json:"errors,omitempty"`
}
type AzureKeyVaultProvider ΒΆ
type AzureKeyVaultProvider struct {
// contains filtered or unexported fields
}
AzureKeyVaultProvider implements HSM provider for Azure Key Vault
func NewAzureKeyVaultProvider ΒΆ
func NewAzureKeyVaultProvider(config *Config) *AzureKeyVaultProvider
NewAzureKeyVaultProvider creates a new Azure Key Vault provider
func (*AzureKeyVaultProvider) Connect ΒΆ
func (p *AzureKeyVaultProvider) Connect(ctx context.Context) error
func (*AzureKeyVaultProvider) Disconnect ΒΆ
func (p *AzureKeyVaultProvider) Disconnect() error
func (*AzureKeyVaultProvider) GetCertificate ΒΆ
func (p *AzureKeyVaultProvider) GetCertificate(ctx context.Context, keyID string) (*x509.Certificate, error)
func (*AzureKeyVaultProvider) GetKey ΒΆ
func (p *AzureKeyVaultProvider) GetKey(ctx context.Context, keyID string) (crypto.PrivateKey, error)
func (*AzureKeyVaultProvider) GetProviderInfo ΒΆ
func (p *AzureKeyVaultProvider) GetProviderInfo() *HSMProviderInfo
func (*AzureKeyVaultProvider) ListKeys ΒΆ
func (p *AzureKeyVaultProvider) ListKeys(ctx context.Context) ([]HSMKeyInfo, error)
func (*AzureKeyVaultProvider) ValidateKey ΒΆ
func (p *AzureKeyVaultProvider) ValidateKey(ctx context.Context, keyID string) error
type BunRepository ΒΆ
type BunRepository struct {
// contains filtered or unexported fields
}
BunRepository implements Repository using Bun ORM
func NewBunRepository ΒΆ
func NewBunRepository(db *bun.DB) *BunRepository
NewBunRepository creates a new Bun repository
func (*BunRepository) CreateAuthEvent ΒΆ
func (r *BunRepository) CreateAuthEvent(ctx context.Context, event *CertificateAuthEvent) error
func (*BunRepository) CreateCRL ΒΆ
func (r *BunRepository) CreateCRL(ctx context.Context, crl *CertificateRevocationList) error
func (*BunRepository) CreateCertificate ΒΆ
func (r *BunRepository) CreateCertificate(ctx context.Context, cert *Certificate) error
func (*BunRepository) CreateOCSPResponse ΒΆ
func (r *BunRepository) CreateOCSPResponse(ctx context.Context, resp *OCSPResponse) error
func (*BunRepository) CreatePolicy ΒΆ
func (r *BunRepository) CreatePolicy(ctx context.Context, policy *CertificatePolicy) error
func (*BunRepository) CreateTrustAnchor ΒΆ
func (r *BunRepository) CreateTrustAnchor(ctx context.Context, anchor *TrustAnchor) error
func (*BunRepository) DeleteCRL ΒΆ
func (r *BunRepository) DeleteCRL(ctx context.Context, id string) error
func (*BunRepository) DeleteCertificate ΒΆ
func (r *BunRepository) DeleteCertificate(ctx context.Context, id string) error
func (*BunRepository) DeleteExpiredOCSPResponses ΒΆ
func (r *BunRepository) DeleteExpiredOCSPResponses(ctx context.Context) error
func (*BunRepository) DeletePolicy ΒΆ
func (r *BunRepository) DeletePolicy(ctx context.Context, id string) error
func (*BunRepository) DeleteTrustAnchor ΒΆ
func (r *BunRepository) DeleteTrustAnchor(ctx context.Context, id string) error
func (*BunRepository) GetAuthEventStats ΒΆ
func (r *BunRepository) GetAuthEventStats(ctx context.Context, orgID string, since time.Time) (*AuthEventStats, error)
func (*BunRepository) GetCRL ΒΆ
func (r *BunRepository) GetCRL(ctx context.Context, id string) (*CertificateRevocationList, error)
func (*BunRepository) GetCRLByIssuer ΒΆ
func (r *BunRepository) GetCRLByIssuer(ctx context.Context, issuer string) (*CertificateRevocationList, error)
func (*BunRepository) GetCertificate ΒΆ
func (r *BunRepository) GetCertificate(ctx context.Context, id string) (*Certificate, error)
func (*BunRepository) GetCertificateByFingerprint ΒΆ
func (r *BunRepository) GetCertificateByFingerprint(ctx context.Context, fingerprint string) (*Certificate, error)
func (*BunRepository) GetCertificateBySerialNumber ΒΆ
func (r *BunRepository) GetCertificateBySerialNumber(ctx context.Context, serialNumber string) (*Certificate, error)
func (*BunRepository) GetDefaultPolicy ΒΆ
func (r *BunRepository) GetDefaultPolicy(ctx context.Context, orgID string) (*CertificatePolicy, error)
func (*BunRepository) GetDeviceCertificates ΒΆ
func (r *BunRepository) GetDeviceCertificates(ctx context.Context, deviceID string) ([]*Certificate, error)
func (*BunRepository) GetExpiringCertificates ΒΆ
func (r *BunRepository) GetExpiringCertificates(ctx context.Context, orgID string, days int) ([]*Certificate, error)
func (*BunRepository) GetOCSPResponse ΒΆ
func (r *BunRepository) GetOCSPResponse(ctx context.Context, certificateID string) (*OCSPResponse, error)
func (*BunRepository) GetPolicy ΒΆ
func (r *BunRepository) GetPolicy(ctx context.Context, id string) (*CertificatePolicy, error)
func (*BunRepository) GetTrustAnchor ΒΆ
func (r *BunRepository) GetTrustAnchor(ctx context.Context, id string) (*TrustAnchor, error)
func (*BunRepository) GetTrustAnchorByFingerprint ΒΆ
func (r *BunRepository) GetTrustAnchorByFingerprint(ctx context.Context, fingerprint string) (*TrustAnchor, error)
func (*BunRepository) GetUserCertificates ΒΆ
func (r *BunRepository) GetUserCertificates(ctx context.Context, userID string) ([]*Certificate, error)
func (*BunRepository) ListAuthEvents ΒΆ
func (r *BunRepository) ListAuthEvents(ctx context.Context, filters AuthEventFilters) ([]*CertificateAuthEvent, error)
func (*BunRepository) ListCRLs ΒΆ
func (r *BunRepository) ListCRLs(ctx context.Context, trustAnchorID string) ([]*CertificateRevocationList, error)
func (*BunRepository) ListCertificates ΒΆ
func (r *BunRepository) ListCertificates(ctx context.Context, filters CertificateFilters) ([]*Certificate, error)
func (*BunRepository) ListPolicies ΒΆ
func (r *BunRepository) ListPolicies(ctx context.Context, orgID string) ([]*CertificatePolicy, error)
func (*BunRepository) ListTrustAnchors ΒΆ
func (r *BunRepository) ListTrustAnchors(ctx context.Context, orgID string) ([]*TrustAnchor, error)
func (*BunRepository) RevokeCertificate ΒΆ
func (*BunRepository) UpdateCRL ΒΆ
func (r *BunRepository) UpdateCRL(ctx context.Context, crl *CertificateRevocationList) error
func (*BunRepository) UpdateCertificate ΒΆ
func (r *BunRepository) UpdateCertificate(ctx context.Context, cert *Certificate) error
func (*BunRepository) UpdateOCSPResponse ΒΆ
func (r *BunRepository) UpdateOCSPResponse(ctx context.Context, resp *OCSPResponse) error
func (*BunRepository) UpdatePolicy ΒΆ
func (r *BunRepository) UpdatePolicy(ctx context.Context, policy *CertificatePolicy) error
func (*BunRepository) UpdateTrustAnchor ΒΆ
func (r *BunRepository) UpdateTrustAnchor(ctx context.Context, anchor *TrustAnchor) error
type CACCardInfo ΒΆ
type CACCardInfo struct {
CardID string `json:"cardId"`
CACNumber string `json:"cacNumber"`
PersonDN string `json:"personDn,omitempty"`
Certificates []CACCertificate `json:"certificates"`
IssueDate *time.Time `json:"issueDate,omitempty"`
ExpirationDate *time.Time `json:"expirationDate,omitempty"`
ReaderName string `json:"readerName,omitempty"`
}
CACCardInfo contains CAC card information
type CACCertificate ΒΆ
type CACCertificate struct {
CertificateType string `json:"certificateType"` // ID, Email, Signature, Encryption
Certificate *x509.Certificate `json:"-"`
Fingerprint string `json:"fingerprint"`
}
CACCertificate represents a certificate on a CAC
type Certificate ΒΆ
type Certificate struct {
bun.BaseModel `bun:"table:mtls_certificates,alias:cert"`
ID string `bun:"id,pk,type:varchar(36)" json:"id"`
OrganizationID string `bun:"organization_id,notnull,type:varchar(36)" json:"organizationId"`
UserID string `bun:"user_id,nullzero,type:varchar(36)" json:"userId,omitempty"` // null for device/machine certs
DeviceID string `bun:"device_id,nullzero,type:varchar(36)" json:"deviceId,omitempty"`
// Certificate Info
Subject string `bun:"subject,notnull" json:"subject"`
Issuer string `bun:"issuer,notnull" json:"issuer"`
SerialNumber string `bun:"serial_number,notnull,unique" json:"serialNumber"`
Fingerprint string `bun:"fingerprint,notnull,unique" json:"fingerprint"` // SHA-256
FingerprintSHA1 string `bun:"fingerprint_sha1,notnull" json:"fingerprintSha1"`
// Certificate Data
CertificatePEM string `bun:"certificate_pem,notnull,type:text" json:"-"` // Don't expose in JSON
PublicKeyPEM string `bun:"public_key_pem,notnull,type:text" json:"-"`
// Validity
NotBefore time.Time `bun:"not_before,notnull" json:"notBefore"`
NotAfter time.Time `bun:"not_after,notnull" json:"notAfter"`
// Certificate Type
CertificateType string `bun:"certificate_type,notnull" json:"certificateType"` // user, device, service
CertificateClass string `bun:"certificate_class,notnull" json:"certificateClass"` // standard, piv, cac, smartcard
// Status
Status string `bun:"status,notnull,default:'active'" json:"status"` // active, revoked, expired, suspended
RevokedAt *time.Time `bun:"revoked_at,nullzero" json:"revokedAt,omitempty"`
RevokedReason string `bun:"revoked_reason,nullzero" json:"revokedReason,omitempty"`
// PIV/CAC Specific
PIVCardID string `bun:"piv_card_id,nullzero" json:"pivCardId,omitempty"`
CACNumber string `bun:"cac_number,nullzero" json:"cacNumber,omitempty"`
// HSM Integration
HSMKeyID string `bun:"hsm_key_id,nullzero" json:"hsmKeyId,omitempty"`
HSMProvider string `bun:"hsm_provider,nullzero" json:"hsmProvider,omitempty"`
// Pinning
IsPinned bool `bun:"is_pinned,notnull,default:false" json:"isPinned"`
PinExpiresAt *time.Time `bun:"pin_expires_at,nullzero" json:"pinExpiresAt,omitempty"`
// Extensions
KeyUsage []string `bun:"key_usage,array,type:text[]" json:"keyUsage"`
ExtendedKeyUsage []string `bun:"extended_key_usage,array,type:text[]" json:"extendedKeyUsage"`
SubjectAltNames StringArray `bun:"subject_alt_names,type:jsonb" json:"subjectAltNames,omitempty"`
// Metadata
Metadata map[string]interface{} `bun:"metadata,type:jsonb" json:"metadata,omitempty"`
// Audit
CreatedAt time.Time `bun:"created_at,notnull,default:current_timestamp" json:"createdAt"`
UpdatedAt time.Time `bun:"updated_at,notnull,default:current_timestamp" json:"updatedAt"`
LastUsedAt *time.Time `bun:"last_used_at,nullzero" json:"lastUsedAt,omitempty"`
UseCount int `bun:"use_count,notnull,default:0" json:"useCount"`
}
Certificate represents a client certificate in the system
func (*Certificate) BeforeInsert ΒΆ
func (c *Certificate) BeforeInsert() error
BeforeInsert hook for Certificate
func (*Certificate) BeforeUpdate ΒΆ
func (c *Certificate) BeforeUpdate() error
BeforeUpdate hook for Certificate
type CertificateAuthEvent ΒΆ
type CertificateAuthEvent struct {
bun.BaseModel `bun:"table:mtls_auth_events,alias:cae"`
ID string `bun:"id,pk,type:varchar(36)" json:"id"`
CertificateID string `bun:"certificate_id,notnull,type:varchar(36)" json:"certificateId"`
OrganizationID string `bun:"organization_id,notnull,type:varchar(36)" json:"organizationId"`
UserID string `bun:"user_id,nullzero,type:varchar(36)" json:"userId,omitempty"`
// Event Details
EventType string `bun:"event_type,notnull" json:"eventType"` // auth_success, auth_failure, validation_error
Status string `bun:"status,notnull" json:"status"` // success, failed, error
// Validation Details
ValidationSteps map[string]interface{} `bun:"validation_steps,type:jsonb" json:"validationSteps,omitempty"`
FailureReason string `bun:"failure_reason,nullzero" json:"failureReason,omitempty"`
ErrorCode string `bun:"error_code,nullzero" json:"errorCode,omitempty"`
// Request Context
IPAddress string `bun:"ip_address,nullzero" json:"ipAddress,omitempty"`
UserAgent string `bun:"user_agent,nullzero" json:"userAgent,omitempty"`
RequestID string `bun:"request_id,nullzero" json:"requestId,omitempty"`
// Smart Card Info (if applicable)
SmartCardID string `bun:"smart_card_id,nullzero" json:"smartCardId,omitempty"`
CardReaderName string `bun:"card_reader_name,nullzero" json:"cardReaderName,omitempty"`
// Metadata
Metadata map[string]interface{} `bun:"metadata,type:jsonb" json:"metadata,omitempty"`
// Timestamp
CreatedAt time.Time `bun:"created_at,notnull,default:current_timestamp" json:"createdAt"`
}
CertificateAuthEvent tracks authentication events using certificates
type CertificateFilters ΒΆ
type CertificateFilters struct {
OrganizationID string
UserID string
DeviceID string
Status string
CertType string
Limit int
Offset int
}
CertificateFilters for filtering certificate queries
type CertificatePolicy ΒΆ
type CertificatePolicy struct {
bun.BaseModel `bun:"table:mtls_policies,alias:cp"`
ID string `bun:"id,pk,type:varchar(36)" json:"id"`
OrganizationID string `bun:"organization_id,notnull,type:varchar(36)" json:"organizationId"`
// Policy Info
Name string `bun:"name,notnull" json:"name"`
Description string `bun:"description,nullzero" json:"description,omitempty"`
// Validation Rules
RequirePinning bool `bun:"require_pinning,notnull,default:false" json:"requirePinning"`
AllowSelfSigned bool `bun:"allow_self_signed,notnull,default:false" json:"allowSelfSigned"`
RequireCRLCheck bool `bun:"require_crl_check,notnull,default:true" json:"requireCrlCheck"`
RequireOCSPCheck bool `bun:"require_ocsp_check,notnull,default:true" json:"requireOcspCheck"`
OCSPStapling bool `bun:"ocsp_stapling,notnull,default:false" json:"ocspStapling"`
// Certificate Requirements
MinKeySize int `bun:"min_key_size,notnull,default:2048" json:"minKeySize"`
AllowedKeyAlgorithms StringArray `bun:"allowed_key_algorithms,type:jsonb" json:"allowedKeyAlgorithms"`
AllowedSignatureAlgs StringArray `bun:"allowed_signature_algs,type:jsonb" json:"allowedSignatureAlgs"`
RequiredKeyUsage StringArray `bun:"required_key_usage,type:jsonb" json:"requiredKeyUsage,omitempty"`
RequiredEKU StringArray `bun:"required_eku,type:jsonb" json:"requiredEku,omitempty"`
// Validity Requirements
MaxCertificateAge int `bun:"max_certificate_age,notnull,default:365" json:"maxCertificateAge"` // days
MinRemainingValidity int `bun:"min_remaining_validity,notnull,default:30" json:"minRemainingValidity"` // days
// Trust Requirements
AllowedCAs StringArray `bun:"allowed_cas,type:jsonb" json:"allowedCas,omitempty"` // fingerprints
RequiredTrustLevel string `bun:"required_trust_level,notnull,default:'root'" json:"requiredTrustLevel"`
// Smart Card/PIV/CAC
RequirePIV bool `bun:"require_piv,notnull,default:false" json:"requirePiv"`
RequireCAC bool `bun:"require_cac,notnull,default:false" json:"requireCac"`
PIVAuthCertOnly bool `bun:"piv_auth_cert_only,notnull,default:true" json:"pivAuthCertOnly"`
// HSM Requirements
RequireHSM bool `bun:"require_hsm,notnull,default:false" json:"requireHsm"`
AllowedHSMProviders StringArray `bun:"allowed_hsm_providers,type:jsonb" json:"allowedHsmProviders,omitempty"`
// Status
Status string `bun:"status,notnull,default:'active'" json:"status"` // active, inactive
IsDefault bool `bun:"is_default,notnull,default:false" json:"isDefault"`
// Metadata
Metadata map[string]interface{} `bun:"metadata,type:jsonb" json:"metadata,omitempty"`
// Audit
CreatedAt time.Time `bun:"created_at,notnull,default:current_timestamp" json:"createdAt"`
UpdatedAt time.Time `bun:"updated_at,notnull,default:current_timestamp" json:"updatedAt"`
}
CertificatePolicy defines certificate validation policies
type CertificateResponse ΒΆ
type CertificateResponse struct {
Certificate interface{} `json:"certificate"`
}
type CertificateRevocationList ΒΆ
type CertificateRevocationList struct {
bun.BaseModel `bun:"table:mtls_crls,alias:crl"`
ID string `bun:"id,pk,type:varchar(36)" json:"id"`
OrganizationID string `bun:"organization_id,notnull,type:varchar(36)" json:"organizationId"`
TrustAnchorID string `bun:"trust_anchor_id,notnull,type:varchar(36)" json:"trustAnchorId"`
// CRL Info
Issuer string `bun:"issuer,notnull" json:"issuer"`
ThisUpdate time.Time `bun:"this_update,notnull" json:"thisUpdate"`
NextUpdate time.Time `bun:"next_update,notnull" json:"nextUpdate"`
// CRL Data
CRLPEM string `bun:"crl_pem,notnull,type:text" json:"-"`
CRLNumber string `bun:"crl_number,nullzero" json:"crlNumber,omitempty"`
// Distribution
DistributionPoint string `bun:"distribution_point,nullzero" json:"distributionPoint,omitempty"`
// Status
Status string `bun:"status,notnull,default:'valid'" json:"status"` // valid, expired, superseded
// Stats
RevokedCertCount int `bun:"revoked_cert_count,notnull,default:0" json:"revokedCertCount"`
// Audit
CreatedAt time.Time `bun:"created_at,notnull,default:current_timestamp" json:"createdAt"`
UpdatedAt time.Time `bun:"updated_at,notnull,default:current_timestamp" json:"updatedAt"`
LastFetchedAt time.Time `bun:"last_fetched_at,notnull,default:current_timestamp" json:"lastFetchedAt"`
}
CertificateRevocationList stores CRL data
type CertificateValidator ΒΆ
type CertificateValidator struct {
// contains filtered or unexported fields
}
CertificateValidator handles X.509 certificate validation
func NewCertificateValidator ΒΆ
func NewCertificateValidator(config *Config, repo Repository, revChecker *RevocationChecker) *CertificateValidator
NewCertificateValidator creates a new certificate validator
func (*CertificateValidator) ValidateCertificate ΒΆ
func (v *CertificateValidator) ValidateCertificate(ctx context.Context, certPEM []byte, orgID string) (*ValidationResult, error)
ValidateCertificate performs comprehensive certificate validation
type CertificatesResponse ΒΆ
type CertificatesResponse struct {
Certificates interface{} `json:"certificates"`
Count int `json:"count"`
}
type CloudHSMProvider ΒΆ
type CloudHSMProvider struct {
// contains filtered or unexported fields
}
CloudHSMProvider implements HSM provider for AWS CloudHSM
func NewCloudHSMProvider ΒΆ
func NewCloudHSMProvider(config *Config) *CloudHSMProvider
NewCloudHSMProvider creates a new AWS CloudHSM provider
func (*CloudHSMProvider) Disconnect ΒΆ
func (p *CloudHSMProvider) Disconnect() error
func (*CloudHSMProvider) GetCertificate ΒΆ
func (p *CloudHSMProvider) GetCertificate(ctx context.Context, keyID string) (*x509.Certificate, error)
func (*CloudHSMProvider) GetKey ΒΆ
func (p *CloudHSMProvider) GetKey(ctx context.Context, keyID string) (crypto.PrivateKey, error)
func (*CloudHSMProvider) GetProviderInfo ΒΆ
func (p *CloudHSMProvider) GetProviderInfo() *HSMProviderInfo
func (*CloudHSMProvider) ListKeys ΒΆ
func (p *CloudHSMProvider) ListKeys(ctx context.Context) ([]HSMKeyInfo, error)
func (*CloudHSMProvider) ValidateKey ΒΆ
func (p *CloudHSMProvider) ValidateKey(ctx context.Context, keyID string) error
type Config ΒΆ
type Config struct {
Enabled bool `json:"enabled" yaml:"enabled"`
// Certificate Validation
Validation ValidationConfig `json:"validation" yaml:"validation"`
// Revocation Checking
Revocation RevocationConfig `json:"revocation" yaml:"revocation"`
// PIV/CAC Smart Card Support
SmartCard SmartCardConfig `json:"smartCard" yaml:"smartCard"`
// HSM Integration
HSM HSMConfig `json:"hsm" yaml:"hsm"`
// Certificate Pinning
Pinning PinningConfig `json:"pinning" yaml:"pinning"`
// Trust Anchors
TrustAnchors TrustAnchorsConfig `json:"trustAnchors" yaml:"trustAnchors"`
// Session Management
Session SessionConfig `json:"session" yaml:"session"`
// API Endpoints
API APIConfig `json:"api" yaml:"api"`
// Security
Security SecurityConfig `json:"security" yaml:"security"`
}
Config holds the mTLS plugin configuration
func DefaultConfig ΒΆ
func DefaultConfig() *Config
DefaultConfig returns the default mTLS configuration
type CreatePolicyRequest ΒΆ
type CreatePolicyRequest struct {
OrganizationID string `json:"organizationId"`
Name string `json:"name"`
Description string `json:"description,omitempty"`
RequirePinning bool `json:"requirePinning"`
AllowSelfSigned bool `json:"allowSelfSigned"`
RequireCRLCheck bool `json:"requireCrlCheck"`
RequireOCSPCheck bool `json:"requireOcspCheck"`
MinKeySize int `json:"minKeySize"`
AllowedKeyAlgorithms StringArray `json:"allowedKeyAlgorithms,omitempty"`
AllowedSignatureAlgs StringArray `json:"allowedSignatureAlgs,omitempty"`
MaxCertificateAge int `json:"maxCertificateAge"`
MinRemainingValidity int `json:"minRemainingValidity"`
RequirePIV bool `json:"requirePiv"`
RequireCAC bool `json:"requireCac"`
RequireHSM bool `json:"requireHsm"`
IsDefault bool `json:"isDefault"`
Metadata map[string]interface{} `json:"metadata,omitempty"`
}
type ErrorResponse ΒΆ
type ErrorResponse = responses.ErrorResponse
Response types - use shared responses from core
type GCPCloudHSMProvider ΒΆ
type GCPCloudHSMProvider struct {
// contains filtered or unexported fields
}
GCPCloudHSMProvider implements HSM provider for GCP Cloud HSM
func NewGCPCloudHSMProvider ΒΆ
func NewGCPCloudHSMProvider(config *Config) *GCPCloudHSMProvider
NewGCPCloudHSMProvider creates a new GCP Cloud HSM provider
func (*GCPCloudHSMProvider) Connect ΒΆ
func (p *GCPCloudHSMProvider) Connect(ctx context.Context) error
func (*GCPCloudHSMProvider) Disconnect ΒΆ
func (p *GCPCloudHSMProvider) Disconnect() error
func (*GCPCloudHSMProvider) GetCertificate ΒΆ
func (p *GCPCloudHSMProvider) GetCertificate(ctx context.Context, keyID string) (*x509.Certificate, error)
func (*GCPCloudHSMProvider) GetKey ΒΆ
func (p *GCPCloudHSMProvider) GetKey(ctx context.Context, keyID string) (crypto.PrivateKey, error)
func (*GCPCloudHSMProvider) GetProviderInfo ΒΆ
func (p *GCPCloudHSMProvider) GetProviderInfo() *HSMProviderInfo
func (*GCPCloudHSMProvider) ListKeys ΒΆ
func (p *GCPCloudHSMProvider) ListKeys(ctx context.Context) ([]HSMKeyInfo, error)
func (*GCPCloudHSMProvider) ValidateKey ΒΆ
func (p *GCPCloudHSMProvider) ValidateKey(ctx context.Context, keyID string) error
type HSMConfig ΒΆ
type HSMConfig struct {
Enabled bool `json:"enabled" yaml:"enabled"`
// Provider Configuration
Provider string `json:"provider" yaml:"provider"` // pkcs11, cloudhsm, yubihsm, etc.
ProviderConfig map[string]string `json:"providerConfig" yaml:"providerConfig"`
// PKCS#11 Configuration
PKCS11Library string `json:"pkcs11Library" yaml:"pkcs11Library"`
PKCS11SlotID int `json:"pkcs11SlotId" yaml:"pkcs11SlotId"`
PKCS11PIN string `json:"pkcs11Pin" yaml:"pkcs11Pin"`
// AWS CloudHSM
CloudHSMClusterID string `json:"cloudHsmClusterId" yaml:"cloudHsmClusterId"`
CloudHSMRegion string `json:"cloudHsmRegion" yaml:"cloudHsmRegion"`
// Azure Key Vault
AzureVaultURL string `json:"azureVaultUrl" yaml:"azureVaultUrl"`
AzureTenantID string `json:"azureTenantId" yaml:"azureTenantId"`
// GCP Cloud HSM
GCPProjectID string `json:"gcpProjectId" yaml:"gcpProjectId"`
GCPLocation string `json:"gcpLocation" yaml:"gcpLocation"`
GCPKeyRing string `json:"gcpKeyRing" yaml:"gcpKeyRing"`
// Connection
ConnectionTimeout time.Duration `json:"connectionTimeout" yaml:"connectionTimeout"`
MaxConnections int `json:"maxConnections" yaml:"maxConnections"`
// Security
RequireHSM bool `json:"requireHsm" yaml:"requireHsm"` // Reject certs not backed by HSM
AllowedProviders []string `json:"allowedProviders" yaml:"allowedProviders"`
}
HSMConfig configures Hardware Security Module integration
type HSMKeyInfo ΒΆ
type HSMKeyInfo struct {
KeyID string `json:"keyId"`
Label string `json:"label"`
Algorithm string `json:"algorithm"`
KeySize int `json:"keySize"`
Certificate *x509.Certificate `json:"-"`
CreatedAt time.Time `json:"createdAt"`
Metadata map[string]interface{} `json:"metadata,omitempty"`
}
HSMKeyInfo contains information about an HSM key
type HSMManager ΒΆ
type HSMManager struct {
// contains filtered or unexported fields
}
HSMManager manages HSM connections and operations
func NewHSMManager ΒΆ
func NewHSMManager(config *Config, repo Repository) *HSMManager
NewHSMManager creates a new HSM manager
func (*HSMManager) GetProvider ΒΆ
func (m *HSMManager) GetProvider(name string) (HSMProvider, error)
GetProvider returns an HSM provider by name
func (*HSMManager) Init ΒΆ
func (m *HSMManager) Init(ctx context.Context) error
Init initializes HSM providers based on configuration
func (*HSMManager) Shutdown ΒΆ
func (m *HSMManager) Shutdown() error
Shutdown closes all HSM connections
func (*HSMManager) ValidateCertificateHSMBinding ΒΆ
func (m *HSMManager) ValidateCertificateHSMBinding(ctx context.Context, cert *Certificate) error
ValidateCertificateHSMBinding validates that a certificate is backed by HSM key
type HSMProvider ΒΆ
type HSMProvider interface {
// Connect establishes connection to HSM
Connect(ctx context.Context) error
// Disconnect closes HSM connection
Disconnect() error
// GetKey retrieves a key from HSM
GetKey(ctx context.Context, keyID string) (crypto.PrivateKey, error)
// Sign performs a signing operation using HSM key
Sign(ctx context.Context, keyID string, digest []byte) ([]byte, error)
// GetCertificate retrieves a certificate from HSM
GetCertificate(ctx context.Context, keyID string) (*x509.Certificate, error)
// ListKeys lists available keys in HSM
ListKeys(ctx context.Context) ([]HSMKeyInfo, error)
// ValidateKey validates that a key exists and is accessible
ValidateKey(ctx context.Context, keyID string) error
// GetProviderInfo returns HSM provider information
GetProviderInfo() *HSMProviderInfo
}
HSMProvider defines the interface for HSM providers
type HSMProviderInfo ΒΆ
type HSMProviderInfo struct {
Provider string `json:"provider"`
Version string `json:"version"`
Model string `json:"model,omitempty"`
SerialNumber string `json:"serialNumber,omitempty"`
Capabilities []string `json:"capabilities"`
Connected bool `json:"connected"`
Metadata map[string]string `json:"metadata,omitempty"`
}
HSMProviderInfo contains HSM provider information
type Handler ΒΆ
type Handler struct {
// contains filtered or unexported fields
}
Handler handles HTTP requests for mTLS operations
func (*Handler) AddTrustAnchor ΒΆ
AddTrustAnchor adds a new trust anchor POST /auth/mtls/trust-anchors
func (*Handler) AuthenticateWithCertificate ΒΆ
AuthenticateWithCertificate authenticates using client certificate POST /auth/mtls/authenticate
func (*Handler) CreatePolicy ΒΆ
CreatePolicy creates a certificate policy POST /auth/mtls/policies
func (*Handler) GetAuthStats ΒΆ
GetAuthStats retrieves authentication statistics GET /auth/mtls/stats/auth
func (*Handler) GetCertificate ΒΆ
GetCertificate retrieves a certificate by ID GET /auth/mtls/certificates/:id
func (*Handler) GetExpiringCertificates ΒΆ
GetExpiringCertificates retrieves certificates expiring soon GET /auth/mtls/certificates/expiring
func (*Handler) GetTrustAnchors ΒΆ
GetTrustAnchors lists trust anchors for an organization GET /auth/mtls/trust-anchors
func (*Handler) ListCertificates ΒΆ
ListCertificates lists certificates with filters GET /auth/mtls/certificates
func (*Handler) RegisterCertificate ΒΆ
RegisterCertificate registers a new certificate POST /auth/mtls/certificates
func (*Handler) RevokeCertificate ΒΆ
RevokeCertificate revokes a certificate POST /auth/mtls/certificates/:id/revoke
type MTLSCertificateListResponse ΒΆ
type MTLSCertificateListResponse struct {
Certificates []interface{} `json:"certificates"`
}
type MTLSCertificateResponse ΒΆ
type MTLSCertificateResponse struct {
Certificate interface{} `json:"certificate"`
}
type MessageResponse ΒΆ
type MessageResponse = responses.MessageResponse
type OCSPResponse ΒΆ
type OCSPResponse struct {
bun.BaseModel `bun:"table:mtls_ocsp_responses,alias:ocsp"`
ID string `bun:"id,pk,type:varchar(36)" json:"id"`
CertificateID string `bun:"certificate_id,notnull,type:varchar(36)" json:"certificateId"`
// OCSP Response
Status string `bun:"status,notnull" json:"status"` // good, revoked, unknown
ProducedAt time.Time `bun:"produced_at,notnull" json:"producedAt"`
ThisUpdate time.Time `bun:"this_update,notnull" json:"thisUpdate"`
NextUpdate *time.Time `bun:"next_update,nullzero" json:"nextUpdate,omitempty"`
// Response Data
ResponseData string `bun:"response_data,type:text" json:"-"`
ResponderID string `bun:"responder_id,nullzero" json:"responderId,omitempty"`
// Revocation Info (if revoked)
RevokedAt *time.Time `bun:"revoked_at,nullzero" json:"revokedAt,omitempty"`
RevocationReason string `bun:"revocation_reason,nullzero" json:"revocationReason,omitempty"`
// Cache
ExpiresAt time.Time `bun:"expires_at,notnull" json:"expiresAt"`
// Audit
CreatedAt time.Time `bun:"created_at,notnull,default:current_timestamp" json:"createdAt"`
UpdatedAt time.Time `bun:"updated_at,notnull,default:current_timestamp" json:"updatedAt"`
}
OCSPResponse stores OCSP response cache
type PIVCardInfo ΒΆ
type PIVCardInfo struct {
CardID string `json:"cardId"`
CardholderUUID string `json:"cardholderUuid,omitempty"`
ExpirationDate *time.Time `json:"expirationDate,omitempty"`
Certificates []PIVCertificate `json:"certificates"`
PINPolicy PIVPINPolicy `json:"pinPolicy"`
ReaderName string `json:"readerName,omitempty"`
}
PIVCardInfo contains PIV card information
type PIVCertificate ΒΆ
type PIVCertificate struct {
SlotID string `json:"slotId"` // 9A, 9C, 9D, 9E
SlotName string `json:"slotName"` // Authentication, Digital Signature, Key Management, Card Authentication
Certificate *x509.Certificate `json:"-"`
Fingerprint string `json:"fingerprint"`
}
PIVCertificate represents a certificate slot on a PIV card
type PIVPINPolicy ΒΆ
type PIVPINPolicy struct {
PINRequired bool `json:"pinRequired"`
PINMinLength int `json:"pinMinLength"`
PINMaxLength int `json:"pinMaxLength"`
Retries int `json:"retries"`
PINVerified bool `json:"pinVerified"`
}
PIVPINPolicy defines PIN requirements
type PKCS11Provider ΒΆ
type PKCS11Provider struct {
// contains filtered or unexported fields
}
PKCS11Provider implements HSM provider for PKCS#11 devices
func NewPKCS11Provider ΒΆ
func NewPKCS11Provider(config *Config) *PKCS11Provider
NewPKCS11Provider creates a new PKCS#11 provider
func (*PKCS11Provider) Disconnect ΒΆ
func (p *PKCS11Provider) Disconnect() error
func (*PKCS11Provider) GetCertificate ΒΆ
func (p *PKCS11Provider) GetCertificate(ctx context.Context, keyID string) (*x509.Certificate, error)
func (*PKCS11Provider) GetKey ΒΆ
func (p *PKCS11Provider) GetKey(ctx context.Context, keyID string) (crypto.PrivateKey, error)
func (*PKCS11Provider) GetProviderInfo ΒΆ
func (p *PKCS11Provider) GetProviderInfo() *HSMProviderInfo
func (*PKCS11Provider) ListKeys ΒΆ
func (p *PKCS11Provider) ListKeys(ctx context.Context) ([]HSMKeyInfo, error)
func (*PKCS11Provider) ValidateKey ΒΆ
func (p *PKCS11Provider) ValidateKey(ctx context.Context, keyID string) error
type PinningConfig ΒΆ
type PinningConfig struct {
Enabled bool `json:"enabled" yaml:"enabled"`
Required bool `json:"required" yaml:"required"` // Reject unpinned certs
PinExpiration time.Duration `json:"pinExpiration" yaml:"pinExpiration"`
AutoPin bool `json:"autoPin" yaml:"autoPin"` // Auto-pin on first use
PinRotationWarning time.Duration `json:"pinRotationWarning" yaml:"pinRotationWarning"`
}
PinningConfig configures certificate pinning
type Plugin ΒΆ
type Plugin struct {
// contains filtered or unexported fields
}
Plugin implements the AuthSome plugin interface for mTLS
func (*Plugin) Description ΒΆ
Description returns the plugin description
func (*Plugin) HSMManager ΒΆ
func (p *Plugin) HSMManager() *HSMManager
HSMManager returns the HSM manager for direct access (optional public method)
func (*Plugin) RegisterHooks ΒΆ
func (p *Plugin) RegisterHooks(hookRegistry *hooks.HookRegistry) error
RegisterHooks registers plugin hooks with the hook registry (implements Plugin interface)
func (*Plugin) RegisterRoutes ΒΆ
RegisterRoutes registers HTTP routes for the plugin
func (*Plugin) RegisterServiceDecorators ΒΆ
func (p *Plugin) RegisterServiceDecorators(services *registry.ServiceRegistry) error
RegisterServiceDecorators allows plugins to replace core services with decorated versions
func (*Plugin) Service ΒΆ
Service returns the mTLS service for direct access (optional public method)
func (*Plugin) SmartCardProvider ΒΆ
func (p *Plugin) SmartCardProvider() *SmartCardProvider
SmartCardProvider returns the smart card provider for direct access (optional public method)
func (*Plugin) Validator ΒΆ
func (p *Plugin) Validator() *CertificateValidator
Validator returns the certificate validator for direct access (optional public method)
type RegisterCertificateRequest ΒΆ
type RegisterCertificateRequest struct {
OrganizationID string `json:"organizationId"`
UserID string `json:"userId,omitempty"`
DeviceID string `json:"deviceId,omitempty"`
CertificatePEM string `json:"certificatePem"`
CertificateType string `json:"certificateType"` // user, device, service
CertificateClass string `json:"certificateClass"` // standard, piv, cac, smartcard
PIVCardID string `json:"pivCardId,omitempty"`
CACNumber string `json:"cacNumber,omitempty"`
HSMKeyID string `json:"hsmKeyId,omitempty"`
HSMProvider string `json:"hsmProvider,omitempty"`
IsPinned bool `json:"isPinned"`
Metadata map[string]interface{} `json:"metadata,omitempty"`
}
type Repository ΒΆ
type Repository interface {
// Certificates
CreateCertificate(ctx context.Context, cert *Certificate) error
GetCertificate(ctx context.Context, id string) (*Certificate, error)
GetCertificateByFingerprint(ctx context.Context, fingerprint string) (*Certificate, error)
GetCertificateBySerialNumber(ctx context.Context, serialNumber string) (*Certificate, error)
ListCertificates(ctx context.Context, filters CertificateFilters) ([]*Certificate, error)
UpdateCertificate(ctx context.Context, cert *Certificate) error
RevokeCertificate(ctx context.Context, id string, reason string) error
DeleteCertificate(ctx context.Context, id string) error
// Certificate queries
GetUserCertificates(ctx context.Context, userID string) ([]*Certificate, error)
GetDeviceCertificates(ctx context.Context, deviceID string) ([]*Certificate, error)
GetExpiringCertificates(ctx context.Context, orgID string, days int) ([]*Certificate, error)
// Trust Anchors
CreateTrustAnchor(ctx context.Context, anchor *TrustAnchor) error
GetTrustAnchor(ctx context.Context, id string) (*TrustAnchor, error)
GetTrustAnchorByFingerprint(ctx context.Context, fingerprint string) (*TrustAnchor, error)
ListTrustAnchors(ctx context.Context, orgID string) ([]*TrustAnchor, error)
UpdateTrustAnchor(ctx context.Context, anchor *TrustAnchor) error
DeleteTrustAnchor(ctx context.Context, id string) error
// CRLs
CreateCRL(ctx context.Context, crl *CertificateRevocationList) error
GetCRL(ctx context.Context, id string) (*CertificateRevocationList, error)
GetCRLByIssuer(ctx context.Context, issuer string) (*CertificateRevocationList, error)
ListCRLs(ctx context.Context, trustAnchorID string) ([]*CertificateRevocationList, error)
UpdateCRL(ctx context.Context, crl *CertificateRevocationList) error
DeleteCRL(ctx context.Context, id string) error
// OCSP Responses
CreateOCSPResponse(ctx context.Context, resp *OCSPResponse) error
GetOCSPResponse(ctx context.Context, certificateID string) (*OCSPResponse, error)
UpdateOCSPResponse(ctx context.Context, resp *OCSPResponse) error
DeleteExpiredOCSPResponses(ctx context.Context) error
// Auth Events
CreateAuthEvent(ctx context.Context, event *CertificateAuthEvent) error
ListAuthEvents(ctx context.Context, filters AuthEventFilters) ([]*CertificateAuthEvent, error)
GetAuthEventStats(ctx context.Context, orgID string, since time.Time) (*AuthEventStats, error)
// Policies
CreatePolicy(ctx context.Context, policy *CertificatePolicy) error
GetPolicy(ctx context.Context, id string) (*CertificatePolicy, error)
GetDefaultPolicy(ctx context.Context, orgID string) (*CertificatePolicy, error)
ListPolicies(ctx context.Context, orgID string) ([]*CertificatePolicy, error)
UpdatePolicy(ctx context.Context, policy *CertificatePolicy) error
DeletePolicy(ctx context.Context, id string) error
}
Repository defines the data access interface for mTLS
type RevocationChecker ΒΆ
type RevocationChecker struct {
// contains filtered or unexported fields
}
RevocationChecker handles certificate revocation checking via CRL and OCSP
func NewRevocationChecker ΒΆ
func NewRevocationChecker(config *Config, repo Repository) *RevocationChecker
NewRevocationChecker creates a new revocation checker
func (*RevocationChecker) CheckRevocation ΒΆ
func (r *RevocationChecker) CheckRevocation(ctx context.Context, cert *x509.Certificate) (string, error)
CheckRevocation checks if a certificate has been revoked
func (*RevocationChecker) CleanupExpiredCache ΒΆ
func (r *RevocationChecker) CleanupExpiredCache(ctx context.Context) error
CleanupExpiredCache removes expired OCSP responses from cache
type RevocationConfig ΒΆ
type RevocationConfig struct {
// CRL Configuration
EnableCRL bool `json:"enableCrl" yaml:"enableCrl"`
CRLCacheDuration time.Duration `json:"crlCacheDuration" yaml:"crlCacheDuration"`
CRLFetchTimeout time.Duration `json:"crlFetchTimeout" yaml:"crlFetchTimeout"`
CRLMaxSize int64 `json:"crlMaxSize" yaml:"crlMaxSize"` // bytes
AutoFetchCRL bool `json:"autoFetchCrl" yaml:"autoFetchCrl"`
// OCSP Configuration
EnableOCSP bool `json:"enableOcsp" yaml:"enableOcsp"`
OCSPCacheDuration time.Duration `json:"ocspCacheDuration" yaml:"ocspCacheDuration"`
OCSPTimeout time.Duration `json:"ocspTimeout" yaml:"ocspTimeout"`
OCSPStapling bool `json:"ocspStapling" yaml:"ocspStapling"`
// Fallback Behavior
FailOpen bool `json:"failOpen" yaml:"failOpen"` // Allow auth if revocation unavailable
PreferOCSP bool `json:"preferOcsp" yaml:"preferOcsp"`
}
RevocationConfig configures certificate revocation checking
type SecurityConfig ΒΆ
type SecurityConfig struct {
// Rate Limiting
RateLimitEnabled bool `json:"rateLimitEnabled" yaml:"rateLimitEnabled"`
MaxAttemptsPerMinute int `json:"maxAttemptsPerMinute" yaml:"maxAttemptsPerMinute"`
MaxAttemptsPerHour int `json:"maxAttemptsPerHour" yaml:"maxAttemptsPerHour"`
// Audit Logging
AuditAllAttempts bool `json:"auditAllAttempts" yaml:"auditAllAttempts"`
AuditFailures bool `json:"auditFailures" yaml:"auditFailures"`
AuditValidation bool `json:"auditValidation" yaml:"auditValidation"`
// Certificate Storage
StoreCertificates bool `json:"storeCertificates" yaml:"storeCertificates"`
StorePrivateKeys bool `json:"storePrivateKeys" yaml:"storePrivateKeys"` // Usually false
EncryptStorage bool `json:"encryptStorage" yaml:"encryptStorage"`
// Notifications
NotifyOnRevocation bool `json:"notifyOnRevocation" yaml:"notifyOnRevocation"`
NotifyOnExpiration bool `json:"notifyOnExpiration" yaml:"notifyOnExpiration"`
ExpirationWarning int `json:"expirationWarning" yaml:"expirationWarning"` // days
}
SecurityConfig configures security settings
type Service ΒΆ
type Service struct {
// contains filtered or unexported fields
}
Service handles mTLS business logic
func NewService ΒΆ
func NewService( config *Config, repo Repository, validator *CertificateValidator, revChecker *RevocationChecker, smartCard *SmartCardProvider, hsmManager *HSMManager, ) *Service
NewService creates a new mTLS service
func (*Service) AddTrustAnchor ΒΆ
func (s *Service) AddTrustAnchor(ctx context.Context, req *AddTrustAnchorRequest) (*TrustAnchor, error)
AddTrustAnchor adds a new trusted CA certificate
func (*Service) AuthenticateWithCertificate ΒΆ
func (s *Service) AuthenticateWithCertificate(ctx context.Context, certPEM []byte, orgID string) (*AuthenticationResult, error)
AuthenticateWithCertificate authenticates a user with a client certificate
func (*Service) CreatePolicy ΒΆ
func (s *Service) CreatePolicy(ctx context.Context, req *CreatePolicyRequest) (*CertificatePolicy, error)
CreatePolicy creates a certificate policy
func (*Service) GetAuthEventStats ΒΆ
func (s *Service) GetAuthEventStats(ctx context.Context, orgID string, since time.Time) (*AuthEventStats, error)
GetAuthEventStats retrieves authentication statistics
func (*Service) GetCertificate ΒΆ
GetCertificate retrieves a certificate by ID
func (*Service) GetExpiringCertificates ΒΆ
func (s *Service) GetExpiringCertificates(ctx context.Context, orgID string, days int) ([]*Certificate, error)
GetExpiringCertificates retrieves certificates expiring soon
func (*Service) GetTrustAnchors ΒΆ
GetTrustAnchors lists trust anchors for an organization
func (*Service) ListCertificates ΒΆ
func (s *Service) ListCertificates(ctx context.Context, filters CertificateFilters) ([]*Certificate, error)
ListCertificates lists certificates with filters
func (*Service) RegisterCertificate ΒΆ
func (s *Service) RegisterCertificate(ctx context.Context, req *RegisterCertificateRequest) (*Certificate, error)
RegisterCertificate registers a new client certificate
type SessionConfig ΒΆ
type SessionConfig struct {
// Session Creation
CreateSession bool `json:"createSession" yaml:"createSession"`
SessionDuration time.Duration `json:"sessionDuration" yaml:"sessionDuration"`
// Certificate Binding
BindToFingerprint bool `json:"bindToFingerprint" yaml:"bindToFingerprint"` // Bind session to cert
RequireSameCert bool `json:"requireSameCert" yaml:"requireSameCert"` // Require same cert for session
// Re-validation
RevalidateOnUse bool `json:"revalidateOnUse" yaml:"revalidateOnUse"`
RevalidateInterval time.Duration `json:"revalidateInterval" yaml:"revalidateInterval"`
}
SessionConfig configures mTLS session management
type SmartCardAuthRequest ΒΆ
type SmartCardAuthRequest struct {
OrganizationID string `json:"organizationId"`
CardType string `json:"cardType"` // piv, cac
ReaderName string `json:"readerName,omitempty"`
PIN string `json:"pin,omitempty"`
CertificateSlot string `json:"certificateSlot,omitempty"`
Metadata map[string]interface{} `json:"metadata,omitempty"`
}
SmartCardAuthRequest contains authentication request data
type SmartCardAuthResponse ΒΆ
type SmartCardAuthResponse struct {
Success bool `json:"success"`
UserID string `json:"userId,omitempty"`
CertificateID string `json:"certificateId,omitempty"`
CardInfo interface{} `json:"cardInfo,omitempty"`
ValidationResult *ValidationResult `json:"validationResult,omitempty"`
Error string `json:"error,omitempty"`
}
SmartCardAuthResponse contains authentication response
type SmartCardConfig ΒΆ
type SmartCardConfig struct {
Enabled bool `json:"enabled" yaml:"enabled"`
// PIV (Personal Identity Verification)
EnablePIV bool `json:"enablePiv" yaml:"enablePiv"`
PIVAuthCertOnly bool `json:"pivAuthCertOnly" yaml:"pivAuthCertOnly"` // Only accept PIV auth certificate
PIVRequiredOIDs []string `json:"pivRequiredOids" yaml:"pivRequiredOids"`
// CAC (Common Access Card)
EnableCAC bool `json:"enableCac" yaml:"enableCac"`
CACRequiredOIDs []string `json:"cacRequiredOids" yaml:"cacRequiredOids"`
// Card Reader Configuration
Readers []string `json:"readers" yaml:"readers"` // Specific readers to use (empty = all)
ReaderTimeout time.Duration `json:"readerTimeout" yaml:"readerTimeout"`
// PIN Configuration
RequirePIN bool `json:"requirePin" yaml:"requirePin"`
MaxPINAttempts int `json:"maxPinAttempts" yaml:"maxPinAttempts"`
PINMinLength int `json:"pinMinLength" yaml:"pinMinLength"`
PINMaxLength int `json:"pinMaxLength" yaml:"pinMaxLength"`
// Security
LockCardOnFailure bool `json:"lockCardOnFailure" yaml:"lockCardOnFailure"`
CardTimeout time.Duration `json:"cardTimeout" yaml:"cardTimeout"`
}
SmartCardConfig configures PIV/CAC smart card support
type SmartCardProvider ΒΆ
type SmartCardProvider struct {
// contains filtered or unexported fields
}
SmartCardProvider handles PIV/CAC smart card authentication
func NewSmartCardProvider ΒΆ
func NewSmartCardProvider(config *Config, repo Repository) *SmartCardProvider
NewSmartCardProvider creates a new smart card provider
func (*SmartCardProvider) AuthenticateWithCAC ΒΆ
func (s *SmartCardProvider) AuthenticateWithCAC(ctx context.Context, cert *x509.Certificate, orgID string) (*SmartCardAuthResponse, error)
AuthenticateWithCAC authenticates a user with CAC certificate
func (*SmartCardProvider) AuthenticateWithPIV ΒΆ
func (s *SmartCardProvider) AuthenticateWithPIV(ctx context.Context, cert *x509.Certificate, orgID string) (*SmartCardAuthResponse, error)
AuthenticateWithPIV authenticates a user with PIV certificate
func (*SmartCardProvider) ValidateCACCard ΒΆ
func (s *SmartCardProvider) ValidateCACCard(ctx context.Context, cert *x509.Certificate) (*CACCardInfo, error)
ValidateCACCard validates a CAC card and extracts certificate
func (*SmartCardProvider) ValidatePIVCard ΒΆ
func (s *SmartCardProvider) ValidatePIVCard(ctx context.Context, cert *x509.Certificate) (*PIVCardInfo, error)
ValidatePIVCard validates a PIV card and extracts certificate
type StatusResponse ΒΆ
type StatusResponse = responses.StatusResponse
type StringArray ΒΆ
type StringArray []string
StringArray is a custom type for string arrays stored as JSONB
func (*StringArray) Scan ΒΆ
func (s *StringArray) Scan(value interface{}) error
Scan implements the sql.Scanner interface
type SuccessResponse ΒΆ
type SuccessResponse = responses.SuccessResponse
type TrustAnchor ΒΆ
type TrustAnchor struct {
bun.BaseModel `bun:"table:mtls_trust_anchors,alias:ta"`
ID string `bun:"id,pk,type:varchar(36)" json:"id"`
OrganizationID string `bun:"organization_id,notnull,type:varchar(36)" json:"organizationId"`
// CA Info
Name string `bun:"name,notnull" json:"name"`
Subject string `bun:"subject,notnull" json:"subject"`
Issuer string `bun:"issuer,notnull" json:"issuer"`
SerialNumber string `bun:"serial_number,notnull" json:"serialNumber"`
Fingerprint string `bun:"fingerprint,notnull,unique" json:"fingerprint"`
// Certificate
CertificatePEM string `bun:"certificate_pem,notnull,type:text" json:"-"`
// Validity
NotBefore time.Time `bun:"not_before,notnull" json:"notBefore"`
NotAfter time.Time `bun:"not_after,notnull" json:"notAfter"`
// Trust Level
TrustLevel string `bun:"trust_level,notnull" json:"trustLevel"` // root, intermediate, self_signed
IsRootCA bool `bun:"is_root_ca,notnull,default:false" json:"isRootCA"`
// Revocation Checking
CRLEndpoints StringArray `bun:"crl_endpoints,type:jsonb" json:"crlEndpoints,omitempty"`
OCSPEndpoints StringArray `bun:"ocsp_endpoints,type:jsonb" json:"ocspEndpoints,omitempty"`
// Status
Status string `bun:"status,notnull,default:'active'" json:"status"` // active, revoked, expired
// Metadata
Metadata map[string]interface{} `bun:"metadata,type:jsonb" json:"metadata,omitempty"`
// Audit
CreatedAt time.Time `bun:"created_at,notnull,default:current_timestamp" json:"createdAt"`
UpdatedAt time.Time `bun:"updated_at,notnull,default:current_timestamp" json:"updatedAt"`
}
TrustAnchor represents a trusted CA certificate
type TrustAnchorsConfig ΒΆ
type TrustAnchorsConfig struct {
// System Trust Store
UseSystemStore bool `json:"useSystemStore" yaml:"useSystemStore"`
SystemStorePath string `json:"systemStorePath" yaml:"systemStorePath"`
// Custom Trust Anchors
CustomAnchors []string `json:"customAnchors" yaml:"customAnchors"` // Paths to CA certs
// Auto-Update
AutoUpdate bool `json:"autoUpdate" yaml:"autoUpdate"`
UpdateInterval time.Duration `json:"updateInterval" yaml:"updateInterval"`
// Validation
ValidateAnchors bool `json:"validateAnchors" yaml:"validateAnchors"`
RejectExpired bool `json:"rejectExpired" yaml:"rejectExpired"`
}
TrustAnchorsConfig configures trust anchor management
type TrustStoresResponse ΒΆ
type TrustStoresResponse struct {
TrustStores interface{} `json:"trust_stores"`
Count int `json:"count"`
}
type ValidationConfig ΒΆ
type ValidationConfig struct {
// Basic Validation
CheckExpiration bool `json:"checkExpiration" yaml:"checkExpiration"`
CheckNotBefore bool `json:"checkNotBefore" yaml:"checkNotBefore"`
CheckSignature bool `json:"checkSignature" yaml:"checkSignature"`
CheckKeyUsage bool `json:"checkKeyUsage" yaml:"checkKeyUsage"`
CheckExtendedKeyUsage bool `json:"checkExtendedKeyUsage" yaml:"checkExtendedKeyUsage"`
// Chain Validation
ValidateChain bool `json:"validateChain" yaml:"validateChain"`
MaxChainLength int `json:"maxChainLength" yaml:"maxChainLength"`
AllowSelfSigned bool `json:"allowSelfSigned" yaml:"allowSelfSigned"`
// Key Requirements
MinKeySize int `json:"minKeySize" yaml:"minKeySize"` // bits
AllowedKeyAlgorithms []string `json:"allowedKeyAlgorithms" yaml:"allowedKeyAlgorithms"`
AllowedSignatureAlgs []string `json:"allowedSignatureAlgs" yaml:"allowedSignatureAlgs"`
// Validity Requirements
MaxCertificateAge int `json:"maxCertificateAge" yaml:"maxCertificateAge"` // days
MinRemainingValidity int `json:"minRemainingValidity" yaml:"minRemainingValidity"` // days
// Required Extensions
RequiredKeyUsage []string `json:"requiredKeyUsage" yaml:"requiredKeyUsage"`
RequiredEKU []string `json:"requiredEku" yaml:"requiredEku"`
}
ValidationConfig configures certificate validation
type ValidationError ΒΆ
type ValidationError struct {
Code string
Message string
Field string
Details map[string]interface{}
Underlying error
}
ValidationError provides detailed validation failure information
func NewValidationError ΒΆ
func NewValidationError(code, message, field string, underlying error) *ValidationError
NewValidationError creates a new validation error
func (*ValidationError) Error ΒΆ
func (e *ValidationError) Error() string
func (*ValidationError) Unwrap ΒΆ
func (e *ValidationError) Unwrap() error
func (*ValidationError) WithDetail ΒΆ
func (e *ValidationError) WithDetail(key string, value interface{}) *ValidationError
WithDetail adds a detail to the validation error
type ValidationResult ΒΆ
type ValidationResult struct {
Valid bool `json:"valid"`
Certificate *x509.Certificate `json:"-"`
Chain []*x509.Certificate `json:"-"`
Errors []error `json:"errors,omitempty"`
Warnings []string `json:"warnings,omitempty"`
ValidationSteps map[string]interface{} `json:"validationSteps"`
TrustAnchor *TrustAnchor `json:"trustAnchor,omitempty"`
RevocationStatus string `json:"revocationStatus,omitempty"`
}
ValidationResult contains the result of certificate validation