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)
| 25 | // identity information for the CA's root key. This endpoint is not |
| 26 | // suitable for creating intermediate certificates. |
| 27 | func 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. |
nothing calls this directly
no test coverage detected
searching dependent graphs…