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

Function initialCAHandler

api/initca/initca.go:27–55  ·  view source on GitHub ↗

initialCAHandler is an HTTP handler that accepts a JSON blob in the same format as the CSR endpoint; this blob should contain the identity information for the CA's root key. This endpoint is not suitable for creating intermediate certificates.

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

Source from the content-addressed store, hash-verified

25// identity information for the CA's root key. This endpoint is not
26// suitable for creating intermediate certificates.
27func initialCAHandler(w http.ResponseWriter, r *http.Request) error {
28 log.Info("setting up initial CA handler")
29 body, err := io.ReadAll(r.Body)
30 if err != nil {
31 log.Warningf("failed to read request body: %v", err)
32 return errors.NewBadRequest(err)
33 }
34 r.Body.Close()
35
36 req := new(csr.CertificateRequest)
37 req.KeyRequest = csr.NewKeyRequest()
38 err = json.Unmarshal(body, req)
39 if err != nil {
40 log.Warningf("failed to unmarshal request: %v", err)
41 return errors.NewBadRequest(err)
42 }
43
44 cert, _, key, err := initca.New(req)
45 if err != nil {
46 log.Warningf("failed to initialise new CA: %v", err)
47 return err
48 }
49
50 response := api.NewSuccessResponse(&NewCA{string(key), string(cert)})
51
52 enc := json.NewEncoder(w)
53 err = enc.Encode(response)
54 return err
55}
56
57// NewHandler returns a new http.Handler that handles request to
58// initialize a CA.

Callers

nothing calls this directly

Calls 7

InfoFunction · 0.92
WarningfFunction · 0.92
NewBadRequestFunction · 0.92
NewKeyRequestFunction · 0.92
NewFunction · 0.92
NewSuccessResponseFunction · 0.92
CloseMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…