ssl

package
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 17, 2026 License: Apache-2.0 Imports: 39 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package ssl 实现证书管理模块:ACME 自动签发与续期、上传证书、读取文件证书, 并可把证书写到目录供其他服务使用,同时为 Web 服务模块提供按 SNI 选择证书的能力。

Index

Constants

View Source
const (
	SourceACME   = "acme"
	SourceUpload = "upload"
	SourceFile   = "file"
)

证书来源

View Source
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 是一张证书。

func (*Cert) Validate

func (c *Cert) Validate(settings Settings) error

Validate 校验配置。上传来源要求证书与私钥匹配。

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"`
	// contains filtered or unexported fields
}

CertState 是证书的运行状态(不持久化)。

type CertView

type CertView struct {
	Cert
	Info  *CertInfo `json:"info,omitempty"`
	State CertState `json:"state"`
}

CertView 是 API 输出的证书,私钥与凭据脱敏。

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 New

func New() *Module

New 创建模块实例。

func (*Module) GetCertificate

func (m *Module) GetCertificate(hello *tls.ClientHelloInfo) (*tls.Certificate, error)

GetCertificate 按 SNI 选择证书,供 Web 服务模块的 tls.Config 使用。

func (*Module) HasCertificate

func (m *Module) HasCertificate(name string) bool

HasCertificate 判断是否有覆盖该域名的证书。

func (*Module) ID

func (m *Module) ID() string

ID 实现 module.Module。

func (*Module) ImportLucky

func (m *Module) ImportLucky(doc luckyimport.Document, opts luckyimport.Options) (*luckyimport.Report, error)

ImportLucky 实现 luckyimport.Importer。

func (*Module) Init

func (m *Module) Init(env module.Env) error

Init 实现 module.Module。

func (*Module) Routes

func (m *Module) Routes(r module.Router)

Routes 实现 module.Module。

func (*Module) Start

func (m *Module) Start(ctx context.Context) error

Start 实现 module.Module。

func (*Module) Stop

func (m *Module) Stop() error

Stop 实现 module.Module。

func (*Module) Summary

func (m *Module) Summary() []module.SummaryItem

Summary 实现 module.Summarizer:证书数量与最近到期时间。

func (*Module) Title

func (m *Module) Title() string

Title 实现 module.Module。

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 是模块级配置。

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL