mirror of
https://github.com/certimate-go/certimate.git
synced 2026-07-20 21:01:41 +08:00
refactor: clean code
This commit is contained in:
parent
dbaecdd801
commit
64dbdeb757
@ -5,7 +5,7 @@ import (
|
||||
|
||||
"github.com/certimate-go/certimate/internal/domain"
|
||||
"github.com/certimate-go/certimate/pkg/core"
|
||||
chlgimpl "github.com/certimate-go/certimate/pkg/core/certifier/challengers/dns01/azure-dns"
|
||||
chlgimpl "github.com/certimate-go/certimate/pkg/core/certifier/challengers/dns01/azure"
|
||||
xmaps "github.com/certimate-go/certimate/pkg/utils/maps"
|
||||
)
|
||||
|
||||
|
||||
@ -5,7 +5,7 @@ import (
|
||||
|
||||
"github.com/certimate-go/certimate/internal/domain"
|
||||
"github.com/certimate-go/certimate/pkg/core"
|
||||
chlgimpl "github.com/certimate-go/certimate/pkg/core/certifier/challengers/dns01/googlecloud-dns"
|
||||
chlgimpl "github.com/certimate-go/certimate/pkg/core/certifier/challengers/dns01/googlecloud"
|
||||
xmaps "github.com/certimate-go/certimate/pkg/utils/maps"
|
||||
)
|
||||
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
package azuredns
|
||||
package azure
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
@ -1,4 +1,4 @@
|
||||
package googleclouddns
|
||||
package googlecloud
|
||||
|
||||
import (
|
||||
"context"
|
||||
@ -138,7 +138,7 @@ func (c *Certmgr) Replace(ctx context.Context, certIdOrName string, certPEM, pri
|
||||
websiteSSLUploadReq := &onepanelsdk.WebsiteSSLUploadRequest{
|
||||
SSLID: sslId,
|
||||
Type: "paste",
|
||||
Description: "upload from certimate",
|
||||
Description: "upload from Certimate",
|
||||
Certificate: certPEM,
|
||||
PrivateKey: privkeyPEM,
|
||||
}
|
||||
@ -155,7 +155,7 @@ func (c *Certmgr) Replace(ctx context.Context, certIdOrName string, certPEM, pri
|
||||
websiteSSLUploadReq := &onepanelsdk2.WebsiteSSLUploadRequest{
|
||||
SSLID: sslId,
|
||||
Type: "paste",
|
||||
Description: "upload from certimate",
|
||||
Description: "upload from Certimate",
|
||||
Certificate: certPEM,
|
||||
PrivateKey: privkeyPEM,
|
||||
}
|
||||
|
||||
@ -92,10 +92,10 @@ func (c *Certmgr) Upload(ctx context.Context, certPEM, privkeyPEM string) (*Uplo
|
||||
}
|
||||
|
||||
if describeServerCertificatesResp.Body.ServerCertificates != nil && describeServerCertificatesResp.Body.ServerCertificates.ServerCertificate != nil {
|
||||
fingerprintSha256 := sha256.Sum256(certX509.Raw)
|
||||
fingerprintSha256Hex := hex.EncodeToString(fingerprintSha256[:])
|
||||
fingerprintSha1 := sha1.Sum(certX509.Raw)
|
||||
fingerprintSha1Hex := hex.EncodeToString(fingerprintSha1[:])
|
||||
fingerprintSha256 := sha256.Sum256(certX509.Raw)
|
||||
fingerprintSha256Hex := hex.EncodeToString(fingerprintSha256[:])
|
||||
for _, certItem := range describeServerCertificatesResp.Body.ServerCertificates.ServerCertificate {
|
||||
if tea.Int32Value(certItem.IsAliCloudCertificate) != 0 {
|
||||
continue
|
||||
@ -106,9 +106,11 @@ func (c *Certmgr) Upload(ctx context.Context, certPEM, privkeyPEM string) (*Uplo
|
||||
continue
|
||||
}
|
||||
|
||||
// 对比证书 SHA-1 或 SHA-256 摘要
|
||||
// 对比证书指纹
|
||||
//
|
||||
// 注意,虽然文档中描述为 SHA-256 摘要,但示例给出的是 SHA-1 摘要,因此这里都尝试对比一下
|
||||
oldFingerprint := strings.ReplaceAll(tea.StringValue(certItem.Fingerprint), ":", "")
|
||||
if !strings.EqualFold(fingerprintSha256Hex, oldFingerprint) && !strings.EqualFold(fingerprintSha1Hex, oldFingerprint) {
|
||||
if !strings.EqualFold(fingerprintSha1Hex, oldFingerprint) && !strings.EqualFold(fingerprintSha256Hex, oldFingerprint) {
|
||||
continue
|
||||
}
|
||||
|
||||
|
||||
@ -98,16 +98,15 @@ func (c *Certmgr) Upload(ctx context.Context, certPEM, privkeyPEM string) (*Uplo
|
||||
}
|
||||
|
||||
for _, certItem := range listCertificatesResp.CertificateSummaryList {
|
||||
// 对比证书有效期
|
||||
if certItem.NotBefore == nil || !certItem.NotBefore.Equal(certX509.NotBefore) {
|
||||
continue
|
||||
}
|
||||
if certItem.NotAfter == nil || !certItem.NotAfter.Equal(certX509.NotAfter) {
|
||||
// 对比证书备用名称
|
||||
if !strings.EqualFold(strings.Join(certX509.DNSNames, ","), strings.Join(certItem.SubjectAlternativeNameSummaries, ",")) {
|
||||
continue
|
||||
}
|
||||
|
||||
// 对比证书多域名
|
||||
if !strings.EqualFold(strings.Join(certX509.DNSNames, ","), strings.Join(certItem.SubjectAlternativeNameSummaries, ",")) {
|
||||
// 对比证书有效期
|
||||
if certItem.NotBefore == nil || !certItem.NotBefore.Equal(certX509.NotBefore) {
|
||||
continue
|
||||
} else if certItem.NotAfter == nil || !certItem.NotAfter.Equal(certX509.NotAfter) {
|
||||
continue
|
||||
}
|
||||
|
||||
|
||||
@ -12,6 +12,7 @@ import (
|
||||
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
|
||||
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
|
||||
"github.com/Azure/azure-sdk-for-go/sdk/security/keyvault/azcertificates"
|
||||
"github.com/samber/lo"
|
||||
|
||||
"github.com/certimate-go/certimate/pkg/core"
|
||||
xcert "github.com/certimate-go/certimate/pkg/utils/cert"
|
||||
@ -94,11 +95,9 @@ func (c *Certmgr) Upload(ctx context.Context, certPEM, privkeyPEM string) (*Uplo
|
||||
// 对比证书有效期
|
||||
if certItem.Attributes == nil {
|
||||
continue
|
||||
}
|
||||
if certItem.Attributes.NotBefore == nil || !certItem.Attributes.NotBefore.Equal(certX509.NotBefore) {
|
||||
} else if !lo.FromPtr(certItem.Attributes.NotBefore).Equal(certX509.NotBefore) {
|
||||
continue
|
||||
}
|
||||
if certItem.Attributes.Expires == nil || !certItem.Attributes.Expires.Equal(certX509.NotAfter) {
|
||||
} else if !lo.FromPtr(certItem.Attributes.Expires).Equal(certX509.NotAfter) {
|
||||
continue
|
||||
}
|
||||
|
||||
|
||||
@ -78,6 +78,11 @@ func (c *Certmgr) Upload(ctx context.Context, certPEM, privkeyPEM string) (*Uplo
|
||||
continue
|
||||
}
|
||||
|
||||
// 对比证书备用名称
|
||||
if certItem.CertDNSNames != strings.Join(certX509.DNSNames, ",") {
|
||||
continue
|
||||
}
|
||||
|
||||
// 对比证书有效期
|
||||
oldCertNotBefore, _ := time.Parse("2006-01-02T15:04:05Z", certItem.CertStartTime)
|
||||
oldCertNotAfter, _ := time.Parse("2006-01-02T15:04:05Z", certItem.CertStopTime)
|
||||
@ -85,11 +90,6 @@ func (c *Certmgr) Upload(ctx context.Context, certPEM, privkeyPEM string) (*Uplo
|
||||
continue
|
||||
}
|
||||
|
||||
// 对比证书多域名
|
||||
if certItem.CertDNSNames != strings.Join(certX509.DNSNames, ",") {
|
||||
continue
|
||||
}
|
||||
|
||||
// 对比证书内容
|
||||
getCertDetailResp, err := c.sdkClient.GetCertRawData(certItem.CertId)
|
||||
c.logger.Debug("sdk request 'cert.GetCertRawData'", slog.String("params.certId", certItem.CertId), slog.Any("response", getCertDetailResp))
|
||||
|
||||
@ -90,16 +90,15 @@ func (c *Certmgr) Upload(ctx context.Context, certPEM, privkeyPEM string) (*Uplo
|
||||
return nil, fmt.Errorf("failed to execute sdk request 'cdn.ListCertInfo': %w", err)
|
||||
}
|
||||
|
||||
fingerprintSha1 := sha1.Sum(certX509.Raw)
|
||||
fingerprintSha1Hex := hex.EncodeToString(fingerprintSha1[:])
|
||||
fingerprintSha256 := sha256.Sum256(certX509.Raw)
|
||||
fingerprintSha256Hex := hex.EncodeToString(fingerprintSha256[:])
|
||||
for _, certItem := range listCertInfoResp.Result.CertInfo {
|
||||
// 对比证书 SHA-1 摘要
|
||||
fingerprintSha1 := sha1.Sum(certX509.Raw)
|
||||
if !strings.EqualFold(hex.EncodeToString(fingerprintSha1[:]), certItem.CertFingerprint.Sha1) {
|
||||
// 对比证书指纹
|
||||
if !strings.EqualFold(fingerprintSha1Hex, certItem.CertFingerprint.Sha1) {
|
||||
continue
|
||||
}
|
||||
|
||||
// 对比证书 SHA-256 摘要
|
||||
fingerprintSha256 := sha256.Sum256(certX509.Raw)
|
||||
if !strings.EqualFold(hex.EncodeToString(fingerprintSha256[:]), certItem.CertFingerprint.Sha256) {
|
||||
} else if !strings.EqualFold(fingerprintSha256Hex, certItem.CertFingerprint.Sha256) {
|
||||
continue
|
||||
}
|
||||
|
||||
|
||||
@ -124,7 +124,7 @@ func (c *Certmgr) Upload(ctx context.Context, certPEM, privkeyPEM string) (*Uplo
|
||||
&model.CreateLoadbalanceCertificationBody{
|
||||
Name: lo.ToPtr(certName),
|
||||
Type: lo.ToPtr(lo.Ternary(c.config.IsSNI, model.CreateLoadbalanceCertificationBodyTypeEnumSni, model.CreateLoadbalanceCertificationBodyTypeEnumServer)),
|
||||
Description: lo.ToPtr("upload from certimate"),
|
||||
Description: lo.ToPtr("upload from Certimate"),
|
||||
PublicKey: lo.ToPtr(certPEM),
|
||||
PrivateKey: lo.ToPtr(privkeyPEM),
|
||||
},
|
||||
|
||||
@ -154,8 +154,10 @@ func (c *Certmgr) tryGetResultIfCertExists(ctx context.Context, certPEM string)
|
||||
break
|
||||
}
|
||||
|
||||
fingerprintSha1 := sha1.Sum(certX509.Raw)
|
||||
fingerprintSha1Hex := hex.EncodeToString(fingerprintSha1[:])
|
||||
for _, certItem := range getCertificateListResp.ReturnObj.List {
|
||||
// 对比证书多域名
|
||||
// 对比证书备用名称
|
||||
if !strings.EqualFold(strings.Join(certX509.DNSNames, ","), certItem.DomainName) {
|
||||
continue
|
||||
}
|
||||
@ -170,9 +172,7 @@ func (c *Certmgr) tryGetResultIfCertExists(ctx context.Context, certPEM string)
|
||||
}
|
||||
|
||||
// 对比证书指纹
|
||||
fingerprint := sha1.Sum(certX509.Raw)
|
||||
fingerprintHex := hex.EncodeToString(fingerprint[:])
|
||||
if !strings.EqualFold(fingerprintHex, certItem.Fingerprint) {
|
||||
if !strings.EqualFold(fingerprintSha1Hex, certItem.Fingerprint) {
|
||||
continue
|
||||
}
|
||||
|
||||
|
||||
@ -94,7 +94,7 @@ func (c *Certmgr) Upload(ctx context.Context, certPEM, privkeyPEM string) (*Uplo
|
||||
ClientToken: lo.ToPtr(security.RandomString(32)),
|
||||
RegionID: lo.ToPtr(c.config.RegionId),
|
||||
Name: lo.ToPtr(certName),
|
||||
Description: lo.ToPtr("upload from certimate"),
|
||||
Description: lo.ToPtr("upload from Certimate"),
|
||||
Type: lo.ToPtr("Server"),
|
||||
Certificate: lo.ToPtr(certPEM),
|
||||
PrivateKey: lo.ToPtr(privkeyPEM),
|
||||
|
||||
@ -95,6 +95,8 @@ func (c *Certmgr) Upload(ctx context.Context, certPEM, privkeyPEM string) (*Uplo
|
||||
return nil, fmt.Errorf("failed to execute sdk request 'ListCertificates': %w", err)
|
||||
}
|
||||
|
||||
fingerprintSha1 := sha1.Sum(certX509.Raw)
|
||||
fingerprintSha1Hex := hex.EncodeToString(fingerprintSha1[:])
|
||||
for _, certItem := range listCertificatesResp.Certificates {
|
||||
// 对比证书扩展名称
|
||||
if !slices.Equal(certX509.DNSNames, certItem.DNSNames) {
|
||||
@ -108,8 +110,6 @@ func (c *Certmgr) Upload(ctx context.Context, certPEM, privkeyPEM string) (*Uplo
|
||||
}
|
||||
|
||||
// 对比证书指纹
|
||||
fingerprintSha1 := sha1.Sum(certX509.Raw)
|
||||
fingerprintSha1Hex := hex.EncodeToString(fingerprintSha1[:])
|
||||
if !strings.EqualFold(fingerprintSha1Hex, certItem.SHA1Fingerprint) {
|
||||
continue
|
||||
}
|
||||
|
||||
@ -104,7 +104,7 @@ func (c *Certmgr) Upload(ctx context.Context, certPEM, privkeyPEM string) (*Uplo
|
||||
continue
|
||||
}
|
||||
|
||||
// 对比证书多域名
|
||||
// 对比证书备用名称
|
||||
if !strings.EqualFold(strings.Join(certX509.DNSNames, ","), strings.Join(certItem.DnsNames, ",")) {
|
||||
continue
|
||||
}
|
||||
|
||||
@ -137,8 +137,10 @@ func (c *Certmgr) tryGetResultIfCertExists(ctx context.Context, certPEM string)
|
||||
break
|
||||
}
|
||||
|
||||
fingerprintSha1 := sha1.Sum(certX509.Raw)
|
||||
fingerprintSha1Hex := hex.EncodeToString(fingerprintSha1[:])
|
||||
for _, certItem := range listUserCertificatesResp.Ret.Certs {
|
||||
// 对比证书多域名
|
||||
// 对比证书备用名称
|
||||
if !strings.EqualFold(strings.Join(certX509.DNSNames, ","), strings.Join(certItem.Domains, ",")) {
|
||||
continue
|
||||
}
|
||||
@ -149,9 +151,7 @@ func (c *Certmgr) tryGetResultIfCertExists(ctx context.Context, certPEM string)
|
||||
}
|
||||
|
||||
// 对比证书指纹
|
||||
fingerprint := sha1.Sum(certX509.Raw)
|
||||
fingerprintHex := hex.EncodeToString(fingerprint[:])
|
||||
if !strings.EqualFold(fingerprintHex, certItem.FingerPrint) {
|
||||
if !strings.EqualFold(fingerprintSha1Hex, certItem.FingerPrint) {
|
||||
continue
|
||||
}
|
||||
|
||||
|
||||
@ -132,7 +132,7 @@ func (c *Certmgr) Upload(ctx context.Context, certPEM, privkeyPEM string) (*Uplo
|
||||
createCertificateReq := &ksyunkcmsdk.CreateCertificateRequest{
|
||||
Region: lo.ToPtr(c.config.Region),
|
||||
CertificateName: lo.ToPtr(fmt.Sprintf("certimate-%d", time.Now().UnixMilli())),
|
||||
Description: lo.ToPtr("upload from certimate"),
|
||||
Description: lo.ToPtr("upload from Certimate"),
|
||||
Source: lo.ToPtr("kcm"),
|
||||
SSLCertificateId: lo.ToPtr(upres.CertId),
|
||||
}
|
||||
@ -159,7 +159,7 @@ func (c *Certmgr) Replace(ctx context.Context, certIdOrName string, certPEM, pri
|
||||
// REF: https://apiexplorer.ksyun.com/#/api/96/ModifyCertificate/2016-03-04/1013
|
||||
modifyCertificateReq := &ksyunkcmsdk.ModifyCertificateRequest{
|
||||
Region: lo.ToPtr(c.config.Region),
|
||||
Description: lo.ToPtr("upload from certimate"),
|
||||
Description: lo.ToPtr("upload from Certimate"),
|
||||
SSLCertificateId: lo.ToPtr(upres.CertId),
|
||||
}
|
||||
modifyCertificateResp, err := c.sdkClient.ModifyCertificateWithContext(ctx, modifyCertificateReq)
|
||||
|
||||
@ -93,7 +93,7 @@ func (c *Certmgr) Upload(ctx context.Context, certPEM, privkeyPEM string) (*Uplo
|
||||
continue
|
||||
}
|
||||
|
||||
// 对比证书多域名
|
||||
// 对比证书备用名称
|
||||
if !slices.Equal(certX509.DNSNames, sslItem.DnsNames) {
|
||||
continue
|
||||
}
|
||||
@ -118,7 +118,6 @@ func (c *Certmgr) Upload(ctx context.Context, certPEM, privkeyPEM string) (*Uplo
|
||||
continue
|
||||
}
|
||||
default:
|
||||
// 未知算法,跳过
|
||||
continue
|
||||
}
|
||||
|
||||
|
||||
@ -147,12 +147,12 @@ func (c *Certmgr) tryGetResultIfCertExists(ctx context.Context, certPEM string)
|
||||
}
|
||||
|
||||
for _, sslItem := range sslCenterListResp.Data.Records {
|
||||
// 对比证书的多域名
|
||||
// 对比证书备用名称
|
||||
if sslItem.Domain != strings.Join(certX509.DNSNames, ", ") {
|
||||
continue
|
||||
}
|
||||
|
||||
// 对比证书的有效期
|
||||
// 对比证书有效期
|
||||
if sslItem.StartDate != certX509.NotBefore.Unix() || sslItem.ExpireDate != certX509.NotAfter.Unix() {
|
||||
continue
|
||||
}
|
||||
|
||||
@ -146,28 +146,30 @@ func (c *Certmgr) tryGetResultIfCertExists(ctx context.Context, certPEM string)
|
||||
}
|
||||
|
||||
for _, certItem := range getCertificateListResp.CertificateList {
|
||||
// 优刻得未提供可唯一标识证书的字段,只能通过多个字段尝试对比来判断是否为同一证书
|
||||
// 先分别对比证书的多域名、品牌、有效期,再对比签名算法
|
||||
|
||||
// 对比证书备用名称
|
||||
if len(certX509.DNSNames) == 0 || certItem.Domains != strings.Join(certX509.DNSNames, ",") {
|
||||
continue
|
||||
}
|
||||
|
||||
// 对比证书颁发者
|
||||
if len(certX509.Issuer.Organization) == 0 || certItem.Brand != certX509.Issuer.Organization[0] {
|
||||
continue
|
||||
}
|
||||
|
||||
if int64(certItem.NotBefore) != certX509.NotBefore.UnixMilli() || int64(certItem.NotAfter) != certX509.NotAfter.UnixMilli() {
|
||||
// 对比证书有效期
|
||||
if int64(certItem.NotBefore) != certX509.NotBefore.UnixMilli() {
|
||||
continue
|
||||
} else if int64(certItem.NotAfter) != certX509.NotAfter.UnixMilli() {
|
||||
continue
|
||||
}
|
||||
|
||||
// 对比证书签名算法
|
||||
getCertificateDetailInfoReq := c.sdkClient.NewGetCertificateDetailInfoRequest()
|
||||
getCertificateDetailInfoReq.CertificateID = ucloud.Int(certItem.CertificateID)
|
||||
getCertificateDetailInfoResp, err := c.sdkClient.GetCertificateDetailInfo(getCertificateDetailInfoReq)
|
||||
if err != nil {
|
||||
return nil, false, fmt.Errorf("failed to execute sdk request 'ussl.GetCertificateDetailInfo': %w", err)
|
||||
}
|
||||
|
||||
switch certX509.SignatureAlgorithm {
|
||||
case x509.SHA256WithRSA:
|
||||
if !strings.EqualFold(getCertificateDetailInfoResp.CertificateInfo.Algorithm, "SHA256-RSA") {
|
||||
|
||||
@ -96,16 +96,15 @@ func (c *Certmgr) Upload(ctx context.Context, certPEM, privkeyPEM string) (*Uplo
|
||||
return nil, fmt.Errorf("failed to execute sdk request 'cdn.ListCertInfo': %w", err)
|
||||
}
|
||||
|
||||
fingerprintSha1 := sha1.Sum(certX509.Raw)
|
||||
fingerprintSha1Hex := hex.EncodeToString(fingerprintSha1[:])
|
||||
fingerprintSha256 := sha256.Sum256(certX509.Raw)
|
||||
fingerprintSha256Hex := hex.EncodeToString(fingerprintSha256[:])
|
||||
for _, certItem := range listCertInfoResp.CertInfo {
|
||||
// 对比证书 SHA-1 摘要
|
||||
fingerprintSha1 := sha1.Sum(certX509.Raw)
|
||||
if !strings.EqualFold(hex.EncodeToString(fingerprintSha1[:]), ve.StringValue(certItem.CertFingerprint.Sha1)) {
|
||||
// 对比证书指纹
|
||||
if !strings.EqualFold(fingerprintSha1Hex, ve.StringValue(certItem.CertFingerprint.Sha1)) {
|
||||
continue
|
||||
}
|
||||
|
||||
// 对比证书 SHA-256 摘要
|
||||
fingerprintSha256 := sha256.Sum256(certX509.Raw)
|
||||
if !strings.EqualFold(hex.EncodeToString(fingerprintSha256[:]), ve.StringValue(certItem.CertFingerprint.Sha256)) {
|
||||
} else if !strings.EqualFold(fingerprintSha256Hex, ve.StringValue(certItem.CertFingerprint.Sha256)) {
|
||||
continue
|
||||
}
|
||||
|
||||
|
||||
@ -109,7 +109,7 @@ func (c *Certmgr) Upload(ctx context.Context, certPEM, privkeyPEM string) (*Uplo
|
||||
Name: lo.ToPtr(certName),
|
||||
Certificate: lo.ToPtr(certPEM),
|
||||
PrivateKey: lo.ToPtr(privkeyPEM),
|
||||
Comment: lo.ToPtr("upload from certimate"),
|
||||
Comment: lo.ToPtr("upload from Certimate"),
|
||||
}
|
||||
createCertificateResp, err := c.sdkClient.CreateCertificateWithContext(ctx, createCertificateReq)
|
||||
c.logger.Debug("sdk request 'certificatemanagement.CreateCertificate'", slog.Any("request", createCertificateReq), slog.Any("response", createCertificateResp))
|
||||
@ -141,7 +141,7 @@ func (c *Certmgr) Replace(ctx context.Context, certIdOrName string, certPEM, pri
|
||||
Name: lo.ToPtr(certName),
|
||||
Certificate: lo.ToPtr(certPEM),
|
||||
PrivateKey: lo.ToPtr(privkeyPEM),
|
||||
Comment: lo.ToPtr("upload from certimate"),
|
||||
Comment: lo.ToPtr("upload from Certimate"),
|
||||
}
|
||||
updateCertificateResp, err := c.sdkClient.UpdateCertificateWithContext(ctx, certId, updateCertificateReq)
|
||||
c.logger.Debug("sdk request 'certificatemanagement.UpdateCertificate'", slog.Any("request", updateCertificateReq), slog.Any("response", updateCertificateResp))
|
||||
|
||||
@ -95,6 +95,10 @@ func (c *Certmgr) Upload(ctx context.Context, certPEM, privkeyPEM string) (*Uplo
|
||||
return nil, fmt.Errorf("failed to execute sdk request 'cdn.DescribeCertificates': %w", err)
|
||||
}
|
||||
|
||||
fingerprintMd5 := md5.Sum(certX509.Raw)
|
||||
fingerprintMd5Hex := hex.EncodeToString(fingerprintMd5[:])
|
||||
fingerprintSha1 := sha1.Sum(certX509.Raw)
|
||||
fingerprintSha1Hex := hex.EncodeToString(fingerprintSha1[:])
|
||||
for _, certItem := range describeCertificatesResp.Response.DataSet {
|
||||
// 对比证书通用名称
|
||||
if !strings.EqualFold(certX509.Subject.CommonName, certItem.Common) {
|
||||
@ -118,10 +122,6 @@ func (c *Certmgr) Upload(ctx context.Context, certPEM, privkeyPEM string) (*Uplo
|
||||
// 对比证书指纹
|
||||
//
|
||||
// 注意,虽然文档中描述为 MD5 摘要,但示例给出的是 SHA-1 摘要,因此这里都尝试对比一下
|
||||
fingerprintMd5 := md5.Sum(certX509.Raw)
|
||||
fingerprintMd5Hex := hex.EncodeToString(fingerprintMd5[:])
|
||||
fingerprintSha1 := sha1.Sum(certX509.Raw)
|
||||
fingerprintSha1Hex := hex.EncodeToString(fingerprintSha1[:])
|
||||
if !strings.EqualFold(fingerprintMd5Hex, certItem.Fingerprint) && !strings.EqualFold(fingerprintSha1Hex, certItem.Fingerprint) {
|
||||
continue
|
||||
}
|
||||
@ -137,7 +137,6 @@ func (c *Certmgr) Upload(ctx context.Context, certPEM, privkeyPEM string) (*Uplo
|
||||
continue
|
||||
}
|
||||
default:
|
||||
// 未知算法,跳过
|
||||
continue
|
||||
}
|
||||
|
||||
|
||||
@ -95,6 +95,10 @@ func (c *Certmgr) Upload(ctx context.Context, certPEM, privkeyPEM string) (*Uplo
|
||||
return nil, fmt.Errorf("failed to execute sdk request 'zga.DescribeCertificates': %w", err)
|
||||
}
|
||||
|
||||
fingerprintMd5 := md5.Sum(certX509.Raw)
|
||||
fingerprintMd5Hex := hex.EncodeToString(fingerprintMd5[:])
|
||||
fingerprintSha1 := sha1.Sum(certX509.Raw)
|
||||
fingerprintSha1Hex := hex.EncodeToString(fingerprintSha1[:])
|
||||
for _, certItem := range describeCertificatesResp.Response.DataSet {
|
||||
// 对比证书通用名称
|
||||
if !strings.EqualFold(certX509.Subject.CommonName, certItem.Common) {
|
||||
@ -118,10 +122,6 @@ func (c *Certmgr) Upload(ctx context.Context, certPEM, privkeyPEM string) (*Uplo
|
||||
// 对比证书指纹
|
||||
//
|
||||
// 注意,虽然文档中描述为 MD5 摘要,但示例给出的是 SHA-1 摘要,因此这里都尝试对比一下
|
||||
fingerprintMd5 := md5.Sum(certX509.Raw)
|
||||
fingerprintMd5Hex := hex.EncodeToString(fingerprintMd5[:])
|
||||
fingerprintSha1 := sha1.Sum(certX509.Raw)
|
||||
fingerprintSha1Hex := hex.EncodeToString(fingerprintSha1[:])
|
||||
if !strings.EqualFold(fingerprintMd5Hex, certItem.Fingerprint) && !strings.EqualFold(fingerprintSha1Hex, certItem.Fingerprint) {
|
||||
continue
|
||||
}
|
||||
@ -137,7 +137,6 @@ func (c *Certmgr) Upload(ctx context.Context, certPEM, privkeyPEM string) (*Uplo
|
||||
continue
|
||||
}
|
||||
default:
|
||||
// 未知算法,跳过
|
||||
continue
|
||||
}
|
||||
|
||||
|
||||
@ -102,7 +102,7 @@ func (d *Deployer) deployToCertificate(ctx context.Context, certPEM, privkeyPEM
|
||||
SSLCertId: d.config.CertificateId,
|
||||
IsOn: true,
|
||||
Name: fmt.Sprintf("certimate-%d", time.Now().UnixMilli()),
|
||||
Description: "upload from certimate",
|
||||
Description: "upload from Certimate",
|
||||
ServerName: certX509.Subject.CommonName,
|
||||
IsCA: false,
|
||||
CertData: base64.StdEncoding.EncodeToString([]byte(certPEM)),
|
||||
|
||||
@ -102,7 +102,7 @@ func (d *Deployer) deployToCertificate(ctx context.Context, certPEM, privkeyPEM
|
||||
SSLCertId: d.config.CertificateId,
|
||||
IsOn: true,
|
||||
Name: fmt.Sprintf("certimate-%d", time.Now().UnixMilli()),
|
||||
Description: "upload from certimate",
|
||||
Description: "upload from Certimate",
|
||||
ServerName: certX509.Subject.CommonName,
|
||||
IsCA: false,
|
||||
CertData: base64.StdEncoding.EncodeToString([]byte(certPEM)),
|
||||
|
||||
@ -102,7 +102,7 @@ func (d *Deployer) deployToCertificate(ctx context.Context, certPEM, privkeyPEM
|
||||
{
|
||||
updateSSLCertReq := &lecdnclientv3.UpdateCertificateRequest{
|
||||
Name: fmt.Sprintf("certimate-%d", time.Now().UnixMilli()),
|
||||
Description: "upload from certimate",
|
||||
Description: "upload from Certimate",
|
||||
Type: "upload",
|
||||
SSLPEM: certPEM,
|
||||
SSLKey: privkeyPEM,
|
||||
@ -120,7 +120,7 @@ func (d *Deployer) deployToCertificate(ctx context.Context, certPEM, privkeyPEM
|
||||
updateSSLCertReq := &lecdnmasterv3.UpdateCertificateRequest{
|
||||
ClientId: d.config.ClientId,
|
||||
Name: fmt.Sprintf("certimate-%d", time.Now().UnixMilli()),
|
||||
Description: "upload from certimate",
|
||||
Description: "upload from Certimate",
|
||||
Type: "upload",
|
||||
SSLPEM: certPEM,
|
||||
SSLKey: privkeyPEM,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user