Handle responds to requests for the CA to sign the certificate request present in the "certificate_request" parameter for the host named in the "hostname" parameter. The certificate should be PEM-encoded. If provided, subject information from the "subject" parameter will be used in place of the subj
(w http.ResponseWriter, r *http.Request)
| 112 | // provided, subject information from the "subject" parameter will be used |
| 113 | // in place of the subject information from the CSR. |
| 114 | func (h *Handler) Handle(w http.ResponseWriter, r *http.Request) error { |
| 115 | log.Info("signature request received") |
| 116 | |
| 117 | body, err := io.ReadAll(r.Body) |
| 118 | if err != nil { |
| 119 | return err |
| 120 | } |
| 121 | r.Body.Close() |
| 122 | |
| 123 | var req jsonSignRequest |
| 124 | |
| 125 | err = json.Unmarshal(body, &req) |
| 126 | if err != nil { |
| 127 | return errors.NewBadRequestString("Unable to parse sign request") |
| 128 | } |
| 129 | |
| 130 | signReq := jsonReqToTrue(req) |
| 131 | |
| 132 | if req.Request == "" { |
| 133 | return errors.NewBadRequestString("missing parameter 'certificate_request'") |
| 134 | } |
| 135 | |
| 136 | var cert []byte |
| 137 | profile, err := signer.Profile(h.signer, req.Profile) |
| 138 | if err != nil { |
| 139 | return err |
| 140 | } |
| 141 | |
| 142 | if profile.Provider != nil { |
| 143 | log.Error("profile requires authentication") |
| 144 | return errors.NewBadRequestString("authentication required") |
| 145 | } |
| 146 | |
| 147 | cert, err = h.signer.Sign(signReq) |
| 148 | if err != nil { |
| 149 | log.Warningf("failed to sign request: %v", err) |
| 150 | return err |
| 151 | } |
| 152 | |
| 153 | result := map[string]interface{}{"certificate": string(cert)} |
| 154 | if req.Bundle { |
| 155 | if h.bundler == nil { |
| 156 | return api.SendResponseWithMessage(w, result, NoBundlerMessage, |
| 157 | errors.New(errors.PolicyError, errors.InvalidRequest).ErrorCode) |
| 158 | } |
| 159 | |
| 160 | bundle, err := h.bundler.BundleFromPEMorDER(cert, nil, bundler.Optimal, "") |
| 161 | if err != nil { |
| 162 | return err |
| 163 | } |
| 164 | |
| 165 | result["bundle"] = bundle |
| 166 | } |
| 167 | log.Info("wrote response") |
| 168 | return api.SendResponse(w, result) |
| 169 | } |
| 170 | |
| 171 | // An AuthHandler verifies and signs incoming signature requests. |
nothing calls this directly
no test coverage detected