Documentation
¶
Overview ¶
Package ssl 实现证书管理模块:ACME 自动签发与续期、上传证书、读取文件证书, 并可把证书写到目录供其他服务使用,同时为 Web 服务模块提供按 SNI 选择证书的能力。
Index ¶
- Constants
- type ACMEConfig
- type Account
- type Cert
- type CertInfo
- type CertState
- type CertView
- type Mapping
- type Module
- func (m *Module) GetCertificate(hello *tls.ClientHelloInfo) (*tls.Certificate, error)
- func (m *Module) HasCertificate(name string) bool
- func (m *Module) ID() string
- func (m *Module) ImportLucky(doc luckyimport.Document, opts luckyimport.Options) (*luckyimport.Report, error)
- func (m *Module) Init(env module.Env) error
- func (m *Module) Routes(r module.Router)
- func (m *Module) Start(ctx context.Context) error
- func (m *Module) Stop() error
- func (m *Module) Summary() []module.SummaryItem
- func (m *Module) Title() string
- type Settings
Constants ¶
const ( SourceACME = "acme" SourceUpload = "upload" SourceFile = "file" )
证书来源
const ID = "ssl"
ID 是模块标识。
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ACMEConfig ¶
type ACMEConfig struct {
Domains []string `json:"domains"`
Email string `json:"email"`
// CA 为预置名称或 custom
CA string `json:"ca"`
DirectoryURL string `json:"directoryUrl"`
// EAB 用于 ZeroSSL、Google 等需要外部账户绑定的 CA
EABKid string `json:"eabKid"`
EABHMAC string `json:"eabHmac"`
KeyType string `json:"keyType"`
// Provider 与 Credentials 为 DNS 服务商,用于写入 _acme-challenge TXT 记录
Provider string `json:"provider"`
Credentials dnsprovider.Credentials `json:"credentials"`
// Zone 显式指定主域名,留空自动推断
Zone string `json:"zone"`
// Resolvers 为检查 TXT 生效所用的递归 DNS,留空使用系统配置
Resolvers []string `json:"resolvers"`
// PropagationTimeout 为等待 TXT 生效的最长时间(秒)
PropagationTimeout int `json:"propagationTimeout"`
// SkipPropagationCheck 跳过本地生效检查,等待固定时间后直接通知 CA 验证
SkipPropagationCheck bool `json:"skipPropagationCheck"`
// DisableAuthoritativeCheck 只通过递归 DNS 检查 TXT 是否生效,不查询权威服务器
DisableAuthoritativeCheck bool `json:"disableAuthoritativeCheck"`
}
ACMEConfig 是 ACME 自动签发参数,验证方式为 DNS-01。
type Account ¶
type Account struct {
Email string `json:"email"`
DirectoryURL string `json:"directoryUrl"`
KeyPEM string `json:"keyPem"`
// Registration 为 lego registration.Resource 的 JSON
Registration string `json:"registration"`
}
Account 是缓存的 ACME 账户,按 CA 地址与邮箱区分。
type Cert ¶
type Cert struct {
Key string `json:"key"`
Remark string `json:"remark"`
Enable bool `json:"enable"`
Source string `json:"source"`
ACME ACMEConfig `json:"acme"`
// CertFile / KeyFile 为文件来源的路径,定期重新读取
CertFile string `json:"certFile"`
KeyFile string `json:"keyFile"`
// 证书内容(PEM)。CertPEM 为包含中间证书的完整链
CertPEM string `json:"certPem"`
KeyPEM string `json:"keyPem"`
IssuerPEM string `json:"issuerPem"`
Mapping Mapping `json:"mapping"`
// UpdatedAt 为证书内容最近一次变化时间
UpdatedAt time.Time `json:"updatedAt,omitzero"`
}
Cert 是一张证书。
type CertInfo ¶
type CertInfo struct {
Domains []string `json:"domains"`
Issuer string `json:"issuer"`
NotBefore time.Time `json:"notBefore"`
NotAfter time.Time `json:"notAfter"`
Fingerprint string `json:"fingerprint"`
}
CertInfo 是从证书内容解析出的信息。
type CertState ¶
type CertState struct {
Obtaining bool `json:"obtaining"`
LastError string `json:"lastError,omitempty"`
LastAttempt time.Time `json:"lastAttempt,omitzero"`
NextRetry time.Time `json:"nextRetry,omitzero"`
MappingNote string `json:"mappingNote,omitempty"`
}
CertState 是证书的运行状态(不持久化)。
type Mapping ¶
type Mapping struct {
Enable bool `json:"enable"`
Dir string `json:"dir"`
// Script 在证书文件变化后执行,例如重载 nginx
Script string `json:"script"`
}
Mapping 把证书写到目录供其他服务使用,文件名为 <备注>.crt/.key/.pem/_issuerCertificate.crt(与 Lucky 一致)。
type Module ¶
type Module struct {
// contains filtered or unexported fields
}
Module 是证书模块。
func (*Module) GetCertificate ¶
func (m *Module) GetCertificate(hello *tls.ClientHelloInfo) (*tls.Certificate, error)
GetCertificate 按 SNI 选择证书,供 Web 服务模块的 tls.Config 使用。
func (*Module) HasCertificate ¶
HasCertificate 判断是否有覆盖该域名的证书。
func (*Module) ImportLucky ¶
func (m *Module) ImportLucky(doc luckyimport.Document, opts luckyimport.Options) (*luckyimport.Report, error)
ImportLucky 实现 luckyimport.Importer。
func (*Module) Summary ¶
func (m *Module) Summary() []module.SummaryItem
Summary 实现 module.Summarizer:证书数量与最近到期时间。
type Settings ¶
type Settings struct {
// Enable 为自动续签开关,关闭后不再自动签发(已有证书仍可使用)
Enable bool `json:"enable"`
// RenewBeforeDays 为到期前多少天续签
RenewBeforeDays int `json:"renewBeforeDays"`
// ShortLivedRenewHours 为短期证书(有效期不足 10 天)到期前多少小时续签
ShortLivedRenewHours int `json:"shortLivedRenewHours"`
DefaultEmail string `json:"defaultEmail"`
}
Settings 是模块级配置。