2023-06-08 10:46:33 -04:00
|
|
|
package node
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2023-07-27 21:13:11 -04:00
|
|
|
|
2023-07-29 07:27:15 -04:00
|
|
|
"github.com/InazumaV/V2bX/common/file"
|
|
|
|
"github.com/InazumaV/V2bX/node/lego"
|
2023-07-27 21:13:11 -04:00
|
|
|
log "github.com/sirupsen/logrus"
|
2023-06-08 10:46:33 -04:00
|
|
|
)
|
|
|
|
|
2023-07-27 19:06:45 -04:00
|
|
|
func (c *Controller) renewCertTask() error {
|
2023-06-15 22:04:39 -04:00
|
|
|
l, err := lego.New(c.CertConfig)
|
|
|
|
if err != nil {
|
2023-07-27 21:13:11 -04:00
|
|
|
log.WithField("tag", c.tag).Info("new lego error: ", err)
|
2023-07-27 19:06:45 -04:00
|
|
|
return nil
|
2023-06-15 22:04:39 -04:00
|
|
|
}
|
|
|
|
err = l.RenewCert()
|
|
|
|
if err != nil {
|
2023-07-27 21:13:11 -04:00
|
|
|
log.WithField("tag", c.tag).Info("renew cert error: ", err)
|
|
|
|
return nil
|
2023-06-15 22:04:39 -04:00
|
|
|
}
|
2023-07-27 19:06:45 -04:00
|
|
|
return nil
|
2023-06-15 22:04:39 -04:00
|
|
|
}
|
|
|
|
|
2023-06-08 10:46:33 -04:00
|
|
|
func (c *Controller) requestCert() error {
|
|
|
|
switch c.CertConfig.CertMode {
|
|
|
|
case "reality", "none", "":
|
|
|
|
return nil
|
2023-07-13 02:16:21 -04:00
|
|
|
case "file":
|
|
|
|
if c.CertConfig.CertFile == "" || c.CertConfig.KeyFile == "" {
|
|
|
|
return fmt.Errorf("cert file path or key file path not exist")
|
|
|
|
}
|
2023-07-23 13:24:28 -04:00
|
|
|
return nil
|
2023-06-08 10:46:33 -04:00
|
|
|
case "dns", "http":
|
2023-07-13 02:16:21 -04:00
|
|
|
if c.CertConfig.CertFile == "" || c.CertConfig.KeyFile == "" {
|
|
|
|
return fmt.Errorf("cert file path or key file path not exist")
|
|
|
|
}
|
2023-06-08 10:46:33 -04:00
|
|
|
if file.IsExist(c.CertConfig.CertFile) && file.IsExist(c.CertConfig.KeyFile) {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
l, err := lego.New(c.CertConfig)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("create lego object error: %s", err)
|
|
|
|
}
|
|
|
|
err = l.CreateCert()
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("create cert error: %s", err)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return fmt.Errorf("unsupported certmode: %s", c.CertConfig.CertMode)
|
|
|
|
}
|