
- Define Certificate model with full X.509 attributes - Add CertificateAuthority model for CA management - Implement CertificateRequest model for CSR handling - Add CertificateRevocationList model for CRL support - Define User and Organization models for access control - Include comprehensive certificate type definitions (web, client, email, etc.) - Add status enums for certificates, requests, and organizations - Configure GORM relationships and constraints
56 lines
4.3 KiB
Go
56 lines
4.3 KiB
Go
package models
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/google/uuid"
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
// CertificateAuthority represents a Certificate Authority (Root or Intermediate)
|
|
type CertificateAuthority struct {
|
|
ID uuid.UUID `json:"id" gorm:"type:uuid;primary_key;default:gen_random_uuid()"` // ID of the CA
|
|
Name string `json:"name" gorm:"not null"` // Name of the CA
|
|
Description string `json:"description"` // Description of the CA
|
|
SerialNumber string `json:"serial_number" gorm:"not null;unique"` // Serial number of the CA
|
|
AttributeCommonName string `json:"attribute_common_name" gorm:"not null"` // Common name of the CA
|
|
AttributeOrganization string `json:"attribute_organization" gorm:"not null"` // Organization of the CA
|
|
AttributeOrganizationUnit string `json:"attribute_organization_unit" gorm:"not null"` // Organization unit of the CA
|
|
AttributeCountry string `json:"attribute_country" gorm:"not null"` // Country of the CA
|
|
AttributeState string `json:"attribute_state" gorm:"not null"` // State of the CA
|
|
AttributeLocality string `json:"attribute_locality" gorm:"not null"` // Locality of the CA
|
|
AttributeStreet string `json:"attribute_street" gorm:"not null"` // Street of the CA
|
|
AttributeEmail string `json:"attribute_email" gorm:"not null"` // Email address of the CA
|
|
AttributeAddress string `json:"attribute_address" gorm:"not null"` // Address of the CA
|
|
AttributePostalCode string `json:"attribute_postal_code" gorm:"not null"` // Postal code of the CA
|
|
AttributeNotBefore time.Time `json:"attribute_not_before" gorm:"not null"` // Not before time of the CA
|
|
AttributeNotAfter time.Time `json:"attribute_not_after" gorm:"not null"` // Not after time of the CA
|
|
Root bool `json:"root" gorm:"not null;default:false"` // If the CA is a root CA
|
|
ParentID *uuid.UUID `json:"parent_id" gorm:"type:uuid"` // ID of the parent CA
|
|
OrganizationID uuid.UUID `json:"organization_id" gorm:"type:uuid;not null"` // ID of the organization
|
|
FileID string `json:"file" gorm:"not null"` // ID of the CA certificate file
|
|
PrivateKeyID string `json:"private_key" gorm:"not null"` // ID of the private key file
|
|
CreatedAt time.Time `json:"created_at" gorm:"autoCreateTime"` // Created at time
|
|
UpdatedAt time.Time `json:"updated_at" gorm:"autoUpdateTime"` // Updated at time
|
|
DeletedAt gorm.DeletedAt `json:"deleted_at" gorm:"index"` // Deleted at time
|
|
|
|
// Relationships
|
|
Parent *CertificateAuthority `gorm:"foreignKey:ParentID"` // Parent CA
|
|
Organization *Organization `gorm:"foreignKey:OrganizationID"` // Organization of the CA
|
|
Children []*CertificateAuthority `gorm:"foreignKey:ParentID"` // Children of the CA
|
|
Certificates []*Certificate `gorm:"foreignKey:CertificateAuthorityID"` // Certificates of the CA
|
|
Requests []*CertificateRequest `gorm:"foreignKey:CertificateAuthorityID"` // Requests of the CA
|
|
CRLs []*CertificateRevocationList `gorm:"foreignKey:CertificateAuthorityID"` // CRLs of the CA
|
|
}
|
|
|
|
// TableName returns the table name for CertificateAuthority
|
|
func (ca *CertificateAuthority) TableName() string {
|
|
return "certificate_authorities"
|
|
}
|
|
|
|
// BeforeCreate generates a new UUID before creating the record
|
|
func (ca *CertificateAuthority) BeforeCreate(tx *gorm.DB) (err error) {
|
|
ca.ID = uuid.New()
|
|
return
|
|
}
|