66 "github.com/0xJacky/Nginx-UI/internal/nginx"
77 "github.com/0xJacky/Nginx-UI/model"
88 "github.com/gin-gonic/gin"
9+ "github.com/go-acme/lego/v4/certcrypto"
910 "github.com/gorilla/websocket"
1011 "net/http"
1112 "strings"
@@ -18,10 +19,11 @@ const (
1819)
1920
2021type IssueCertResponse struct {
21- Status string `json:"status"`
22- Message string `json:"message"`
23- SSLCertificate string `json:"ssl_certificate,omitempty"`
24- SSLCertificateKey string `json:"ssl_certificate_key,omitempty"`
22+ Status string `json:"status"`
23+ Message string `json:"message"`
24+ SSLCertificate string `json:"ssl_certificate,omitempty"`
25+ SSLCertificateKey string `json:"ssl_certificate_key,omitempty"`
26+ KeyType certcrypto.KeyType `json:"key_type"`
2527}
2628
2729func handleIssueCertLogChan (conn * websocket.Conn , log * cert.Logger , logChan chan string ) {
@@ -75,13 +77,20 @@ func IssueCert(c *gin.Context) {
7577 return
7678 }
7779
78- certModel , err := model .FirstOrCreateCert (c .Param ("name" ))
79-
80+ certModel , err := model .FirstOrCreateCert (c .Param ("name" ), payload .GetKeyType ())
8081 if err != nil {
8182 logger .Error (err )
8283 return
8384 }
8485
86+ certInfo , err := cert .GetCertInfo (certModel .SSLCertificatePath )
87+ if err != nil {
88+ logger .Error ("get certificate info error" , err )
89+ return
90+ }
91+ payload .Resource = certModel .Resource
92+ payload .NotBefore = certInfo .NotBefore
93+
8594 logChan := make (chan string , 1 )
8695 errChan := make (chan error , 1 )
8796
@@ -113,7 +122,7 @@ func IssueCert(c *gin.Context) {
113122 return
114123 }
115124
116- certDirName := strings .Join (payload .ServerName , "_" )
125+ certDirName := strings .Join (payload .ServerName , "_" ) + "_" + string ( payload . GetKeyType ())
117126 sslCertificatePath := nginx .GetConfPath ("ssl" , certDirName , "fullchain.cer" )
118127 sslCertificateKeyPath := nginx .GetConfPath ("ssl" , certDirName , "private.key" )
119128
@@ -125,6 +134,7 @@ func IssueCert(c *gin.Context) {
125134 KeyType : payload .KeyType ,
126135 ChallengeMethod : payload .ChallengeMethod ,
127136 DnsCredentialID : payload .DNSCredentialID ,
137+ Resource : payload .Resource ,
128138 })
129139
130140 if err != nil {
@@ -144,6 +154,7 @@ func IssueCert(c *gin.Context) {
144154 Message : "Issued certificate successfully" ,
145155 SSLCertificate : sslCertificatePath ,
146156 SSLCertificateKey : sslCertificateKeyPath ,
157+ KeyType : payload .GetKeyType (),
147158 })
148159
149160 if err != nil {
0 commit comments