| 8 | ) |
| 9 | |
| 10 | func (this *HTTPRequest) doACME() (shouldStop bool) { |
| 11 | // TODO 对请求进行校验,防止恶意攻击 |
| 12 | |
| 13 | var token = filepath.Base(this.RawReq.URL.Path) |
| 14 | if token == "acme-challenge" || len(token) <= 32 { |
| 15 | return false |
| 16 | } |
| 17 | |
| 18 | rpcClient, err := rpc.SharedRPC() |
| 19 | if err != nil { |
| 20 | remotelogs.Error("RPC", "[ACME]rpc failed: "+err.Error()) |
| 21 | return false |
| 22 | } |
| 23 | |
| 24 | keyResp, err := rpcClient.ACMEAuthenticationRPC.FindACMEAuthenticationKeyWithToken(rpcClient.Context(), &pb.FindACMEAuthenticationKeyWithTokenRequest{Token: token}) |
| 25 | if err != nil { |
| 26 | remotelogs.Error("RPC", "[ACME]read key for token failed: "+err.Error()) |
| 27 | return false |
| 28 | } |
| 29 | if len(keyResp.Key) == 0 { |
| 30 | return false |
| 31 | } |
| 32 | |
| 33 | this.tags = append(this.tags, "ACME") |
| 34 | |
| 35 | this.writer.Header().Set("Content-Type", "text/plain") |
| 36 | _, _ = this.writer.WriteString(keyResp.Key) |
| 37 | |
| 38 | return true |
| 39 | } |