[SSL证书]免费证书申请增加HTTP认证方式

This commit is contained in:
刘祥超
2020-12-03 18:19:28 +08:00
parent 60e971e79b
commit bdd26a8c41
4 changed files with 48 additions and 1 deletions

View File

@@ -1,7 +1,7 @@
package teaconst package teaconst
const ( const (
Version = "0.0.4" Version = "0.0.5"
ProductName = "Edge Node" ProductName = "Edge Node"
ProcessName = "edge-node" ProcessName = "edge-node"

View File

@@ -141,6 +141,16 @@ func (this *HTTPRequest) Do() {
// 开始调用 // 开始调用
func (this *HTTPRequest) doBegin() { func (this *HTTPRequest) doBegin() {
// 特殊URL处理
if len(this.rawURI) > 1 && this.rawURI[1] == '.' {
// ACME
// TODO 需要配置是否启用ACME检测
if strings.HasPrefix(this.rawURI, "/.well-known/acme-challenge/") {
this.doACME()
return
}
}
// 临时关闭页面 // 临时关闭页面
if this.web.Shutdown != nil && this.web.Shutdown.IsOn { if this.web.Shutdown != nil && this.web.Shutdown.IsOn {
this.doShutdown() this.doShutdown()

View File

@@ -0,0 +1,33 @@
package nodes
import (
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/TeaOSLab/EdgeNode/internal/logs"
"github.com/TeaOSLab/EdgeNode/internal/rpc"
"net/http"
"path/filepath"
)
func (this *HTTPRequest) doACME() {
// TODO 对请求进行校验,防止恶意攻击
token := filepath.Base(this.RawReq.URL.Path)
rpcClient, err := rpc.SharedRPC()
if err != nil {
logs.Error("RPC", "[ACME]rpc failed: "+err.Error())
return
}
keyResp, err := rpcClient.ACMEAuthenticationRPC().FindACMEAuthenticationKeyWithToken(rpcClient.Context(), &pb.FindACMEAuthenticationKeyWithTokenRequest{Token: token})
if err != nil {
logs.Error("RPC", "[ACME]read key for token failed: "+err.Error())
return
}
if len(keyResp.Key) == 0 {
this.writer.WriteHeader(http.StatusNotFound)
} else {
this.writer.Header().Set("Content-Type", "text/plain")
_, _ = this.writer.WriteString(keyResp.Key)
}
}

View File

@@ -89,6 +89,10 @@ func (this *RPCClient) FileChunkRPC() pb.FileChunkServiceClient {
return pb.NewFileChunkServiceClient(this.pickConn()) return pb.NewFileChunkServiceClient(this.pickConn())
} }
func (this *RPCClient) ACMEAuthenticationRPC() pb.ACMEAuthenticationServiceClient {
return pb.NewACMEAuthenticationServiceClient(this.pickConn())
}
// 节点上下文信息 // 节点上下文信息
func (this *RPCClient) Context() context.Context { func (this *RPCClient) Context() context.Context {
ctx := context.Background() ctx := context.Background()