MCPcopy Create free account
hub / github.com/cloudflare/cfssl / Handle

Method Handle

api/signhandler/signhandler.go:219–300  ·  view source on GitHub ↗

Handle receives the incoming request, validates it, and processes it.

(w http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

217
218// Handle receives the incoming request, validates it, and processes it.
219func (h *AuthHandler) Handle(w http.ResponseWriter, r *http.Request) error {
220 log.Info("signature request received")
221
222 body, err := io.ReadAll(r.Body)
223 if err != nil {
224 log.Errorf("failed to read response body: %v", err)
225 return err
226 }
227 r.Body.Close()
228
229 var aReq auth.AuthenticatedRequest
230 err = json.Unmarshal(body, &aReq)
231 if err != nil {
232 log.Errorf("failed to unmarshal authenticated request: %v", err)
233 return errors.NewBadRequest(err)
234 }
235
236 var req jsonSignRequest
237 err = json.Unmarshal(aReq.Request, &req)
238 if err != nil {
239 log.Errorf("failed to unmarshal request from authenticated request: %v", err)
240 return errors.NewBadRequestString("Unable to parse authenticated sign request")
241 }
242
243 // Sanity checks to ensure that we have a valid policy. This
244 // should have been checked in NewAuthHandler.
245 policy := h.signer.Policy()
246 if policy == nil {
247 log.Critical("signer was initialised without a signing policy")
248 return errors.NewBadRequestString("invalid policy")
249 }
250
251 profile, err := signer.Profile(h.signer, req.Profile)
252 if err != nil {
253 return err
254 }
255
256 if profile.Provider == nil {
257 log.Error("profile has no authentication provider")
258 return errors.NewBadRequestString("no authentication provider")
259 }
260
261 validAuth := false
262 if profile.Provider.Verify(&aReq) {
263 validAuth = true
264 } else if profile.PrevProvider != nil && profile.PrevProvider.Verify(&aReq) {
265 validAuth = true
266 }
267 if !validAuth {
268 log.Warning("received authenticated request with invalid token")
269 return errors.NewBadRequestString("invalid token")
270 }
271
272 signReq := jsonReqToTrue(req)
273
274 if signReq.Request == "" {
275 return errors.NewBadRequestString("missing parameter 'certificate_request'")
276 }

Callers

nothing calls this directly

Calls 15

InfoFunction · 0.92
ErrorfFunction · 0.92
NewBadRequestFunction · 0.92
NewBadRequestStringFunction · 0.92
CriticalFunction · 0.92
ProfileFunction · 0.92
ErrorFunction · 0.92
WarningFunction · 0.92
SendResponseWithMessageFunction · 0.92
NewFunction · 0.92
SendResponseFunction · 0.92
jsonReqToTrueFunction · 0.85

Tested by

no test coverage detected