SSL证书自动设置Leaf字段以提升性能

This commit is contained in:
刘祥超
2021-12-06 10:54:43 +08:00
parent 0c2215ec74
commit d56b1c2f83

View File

@@ -11,7 +11,7 @@ import (
"time" "time"
) )
// SSL证书 // SSLCertConfig SSL证书
type SSLCertConfig struct { type SSLCertConfig struct {
Id int64 `yaml:"id" json:"id"` Id int64 `yaml:"id" json:"id"`
IsOn bool `yaml:"isOn" json:"isOn"` IsOn bool `yaml:"isOn" json:"isOn"`
@@ -34,7 +34,7 @@ type SSLCertConfig struct {
timeEnd time.Time timeEnd time.Time
} }
// 校验 // Init 校验
func (this *SSLCertConfig) Init() error { func (this *SSLCertConfig) Init() error {
var commonNames []string // 发行组织 var commonNames []string // 发行组织
var dnsNames []string // 域名 var dnsNames []string // 域名
@@ -91,6 +91,11 @@ func (this *SSLCertConfig) Init() error {
if err != nil { if err != nil {
continue continue
} }
if cert.Leaf == nil {
cert.Leaf = c
}
for _, dnsName := range c.DNSNames { for _, dnsName := range c.DNSNames {
if !lists.ContainsString(dnsNames, dnsName) { if !lists.ContainsString(dnsNames, dnsName) {
dnsNames = append(dnsNames, dnsName) dnsNames = append(dnsNames, dnsName)
@@ -117,7 +122,7 @@ func (this *SSLCertConfig) Init() error {
return nil return nil
} }
// 校验是否匹配某个域名 // MatchDomain 校验是否匹配某个域名
func (this *SSLCertConfig) MatchDomain(domain string) bool { func (this *SSLCertConfig) MatchDomain(domain string) bool {
if len(this.DNSNames) == 0 { if len(this.DNSNames) == 0 {
return false return false
@@ -125,17 +130,17 @@ func (this *SSLCertConfig) MatchDomain(domain string) bool {
return configutils.MatchDomains(this.DNSNames, domain) return configutils.MatchDomains(this.DNSNames, domain)
} }
// 获取证书对象 // CertObject 获取证书对象
func (this *SSLCertConfig) CertObject() *tls.Certificate { func (this *SSLCertConfig) CertObject() *tls.Certificate {
return this.cert return this.cert
} }
// 开始时间 // TimeBegin 开始时间
func (this *SSLCertConfig) TimeBegin() time.Time { func (this *SSLCertConfig) TimeBegin() time.Time {
return this.timeBegin return this.timeBegin
} }
// 结束时间 // TimeEnd 结束时间
func (this *SSLCertConfig) TimeEnd() time.Time { func (this *SSLCertConfig) TimeEnd() time.Time {
return this.timeEnd return this.timeEnd
} }