mirror of
https://github.com/TeaOSLab/EdgeNode.git
synced 2025-11-08 03:00:27 +08:00
ACME申请证书时如果找不到Token,则直接跳过执行后面请求
This commit is contained in:
@@ -170,11 +170,12 @@ func (this *HTTPRequest) Do() {
|
|||||||
// ACME
|
// ACME
|
||||||
// TODO 需要配置是否启用ACME检测
|
// TODO 需要配置是否启用ACME检测
|
||||||
if strings.HasPrefix(this.rawURI, "/.well-known/acme-challenge/") {
|
if strings.HasPrefix(this.rawURI, "/.well-known/acme-challenge/") {
|
||||||
this.doACME()
|
if this.doACME() {
|
||||||
this.doEnd()
|
this.doEnd()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 套餐
|
// 套餐
|
||||||
if this.ReqServer.UserPlan != nil && !this.ReqServer.UserPlan.IsAvailable() {
|
if this.ReqServer.UserPlan != nil && !this.ReqServer.UserPlan.IsAvailable() {
|
||||||
|
|||||||
@@ -4,34 +4,36 @@ import (
|
|||||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||||
"github.com/TeaOSLab/EdgeNode/internal/remotelogs"
|
"github.com/TeaOSLab/EdgeNode/internal/remotelogs"
|
||||||
"github.com/TeaOSLab/EdgeNode/internal/rpc"
|
"github.com/TeaOSLab/EdgeNode/internal/rpc"
|
||||||
"net/http"
|
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (this *HTTPRequest) doACME() {
|
func (this *HTTPRequest) doACME() (shouldStop bool) {
|
||||||
// TODO 对请求进行校验,防止恶意攻击
|
// TODO 对请求进行校验,防止恶意攻击
|
||||||
|
|
||||||
token := filepath.Base(this.RawReq.URL.Path)
|
var token = filepath.Base(this.RawReq.URL.Path)
|
||||||
if token == "acme-challenge" || len(token) <= 32 {
|
if token == "acme-challenge" || len(token) <= 32 {
|
||||||
this.writer.WriteHeader(http.StatusNotFound)
|
return false
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
rpcClient, err := rpc.SharedRPC()
|
rpcClient, err := rpc.SharedRPC()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
remotelogs.Error("RPC", "[ACME]rpc failed: "+err.Error())
|
remotelogs.Error("RPC", "[ACME]rpc failed: "+err.Error())
|
||||||
return
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
keyResp, err := rpcClient.ACMEAuthenticationRPC().FindACMEAuthenticationKeyWithToken(rpcClient.Context(), &pb.FindACMEAuthenticationKeyWithTokenRequest{Token: token})
|
keyResp, err := rpcClient.ACMEAuthenticationRPC().FindACMEAuthenticationKeyWithToken(rpcClient.Context(), &pb.FindACMEAuthenticationKeyWithTokenRequest{Token: token})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
remotelogs.Error("RPC", "[ACME]read key for token failed: "+err.Error())
|
remotelogs.Error("RPC", "[ACME]read key for token failed: "+err.Error())
|
||||||
return
|
return false
|
||||||
}
|
}
|
||||||
if len(keyResp.Key) == 0 {
|
if len(keyResp.Key) == 0 {
|
||||||
this.writer.WriteHeader(http.StatusNotFound)
|
return false
|
||||||
} else {
|
}
|
||||||
|
|
||||||
|
this.tags = append(this.tags, "ACME")
|
||||||
|
|
||||||
this.writer.Header().Set("Content-Type", "text/plain")
|
this.writer.Header().Set("Content-Type", "text/plain")
|
||||||
_, _ = this.writer.WriteString(keyResp.Key)
|
_, _ = this.writer.WriteString(keyResp.Key)
|
||||||
}
|
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user