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

Method Handle

api/generator/generator.go:229–317  ·  view source on GitHub ↗

Handle responds to requests for the CA to generate a new private key and certificate on behalf of the client. The format for these requests is documented in the API documentation.

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

Source from the content-addressed store, hash-verified

227// key and certificate on behalf of the client. The format for these
228// requests is documented in the API documentation.
229func (cg *CertGeneratorHandler) Handle(w http.ResponseWriter, r *http.Request) error {
230 log.Info("request for CSR")
231
232 req := new(genSignRequest)
233 req.Request = csr.New()
234
235 body, err := io.ReadAll(r.Body)
236 if err != nil {
237 log.Warningf("failed to read request body: %v", err)
238 return errors.NewBadRequest(err)
239 }
240 r.Body.Close()
241
242 err = json.Unmarshal(body, req)
243 if err != nil {
244 log.Warningf("failed to unmarshal request: %v", err)
245 return errors.NewBadRequest(err)
246 }
247
248 if req.Request == nil {
249 log.Warning("empty request received")
250 return errors.NewBadRequestString("missing request section")
251 }
252
253 if req.Request.CA != nil {
254 log.Warningf("request received with CA section")
255 return errors.NewBadRequestString("ca section only permitted in initca")
256 }
257
258 csr, key, err := cg.generator.ProcessRequest(req.Request)
259 if err != nil {
260 log.Warningf("failed to process CSR: %v", err)
261 // The validator returns a *cfssl/errors.HttpError
262 return err
263 }
264
265 signReq := signer.SignRequest{
266 Request: string(csr),
267 Profile: req.Profile,
268 Label: req.Label,
269 }
270
271 certBytes, err := cg.signer.Sign(signReq)
272 if err != nil {
273 log.Warningf("failed to sign request: %v", err)
274 return err
275 }
276
277 reqSum, err := computeSum(csr)
278 if err != nil {
279 return errors.NewBadRequest(err)
280 }
281
282 certSum, err := computeSum(certBytes)
283 if err != nil {
284 return errors.NewBadRequest(err)
285 }
286

Callers

nothing calls this directly

Calls 14

InfoFunction · 0.92
NewFunction · 0.92
WarningfFunction · 0.92
NewBadRequestFunction · 0.92
WarningFunction · 0.92
NewBadRequestStringFunction · 0.92
SendResponseWithMessageFunction · 0.92
NewFunction · 0.92
SendResponseFunction · 0.92
computeSumFunction · 0.85
ProcessRequestMethod · 0.80
BundleFromPEMorDERMethod · 0.80

Tested by

no test coverage detected