mirror of
https://github.com/usual2970/certimate.git
synced 2025-10-05 14:04:54 +00:00
add upload certificate node
This commit is contained in:
@@ -5,8 +5,10 @@ import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/usual2970/certimate/internal/app"
|
||||
"github.com/usual2970/certimate/internal/domain"
|
||||
@@ -176,6 +178,31 @@ func (s *CertificateService) ArchiveFile(ctx context.Context, req *dtos.Certific
|
||||
}
|
||||
}
|
||||
|
||||
func (s *CertificateService) ValidateCertificate(ctx context.Context, req *dtos.CertificateValidateCertificateReq) (*dtos.CertificateValidateCertificateResp, error) {
|
||||
info, err := certs.ParseCertificateFromPEM(req.Certificate)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if time.Now().After(info.NotAfter) {
|
||||
return nil, errors.New("证书已过期")
|
||||
}
|
||||
|
||||
return &dtos.CertificateValidateCertificateResp{
|
||||
Domains: strings.Join(info.DNSNames, ";"),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *CertificateService) ValidatePrivateKey(ctx context.Context, req *dtos.CertificateValidatePrivateKeyReq) error {
|
||||
if strings.Contains(req.PrivateKey, "-----BEGIN RSA PRIVATE KEY-----") {
|
||||
_, err := certs.ParsePKCS1PrivateKeyFromPEM(req.PrivateKey)
|
||||
return err
|
||||
} else {
|
||||
_, err := certs.ParseECPrivateKeyFromPEM(req.PrivateKey)
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
func buildExpireSoonNotification(certificates []*domain.Certificate) *struct {
|
||||
Subject string
|
||||
Message string
|
||||
|
Reference in New Issue
Block a user