| 168 | } |
| 169 | |
| 170 | static apr_status_t inspect_problem(md_acme_req_t *req, const md_http_response_t *res) |
| 171 | { |
| 172 | const char *ctype; |
| 173 | md_json_t *problem = NULL; |
| 174 | apr_status_t rv; |
| 175 | |
| 176 | ctype = apr_table_get(req->resp_hdrs, "content-type"); |
| 177 | ctype = md_util_parse_ct(res->req->pool, ctype); |
| 178 | if (ctype && !strcmp(ctype, "application/problem+json")) { |
| 179 | /* RFC 7807 */ |
| 180 | rv = md_json_read_http(&problem, req->p, res); |
| 181 | if (rv == APR_SUCCESS && problem) { |
| 182 | const char *ptype, *pdetail; |
| 183 | |
| 184 | req->resp_json = problem; |
| 185 | ptype = md_json_gets(problem, MD_KEY_TYPE, NULL); |
| 186 | |
| 187 | if (ptype) { |
| 188 | req->rv = problem_status_get(ptype); |
| 189 | pdetail = md_json_gets(problem, MD_KEY_DETAIL, NULL); |
| 190 | |
| 191 | md_result_problem_set(req->result, req->rv, ptype, pdetail, |
| 192 | md_json_getj(problem, MD_KEY_SUBPROBLEMS, NULL)); |
| 193 | |
| 194 | if (APR_STATUS_IS_EAGAIN(req->rv)) { |
| 195 | md_log_perror(MD_LOG_MARK, MD_LOG_DEBUG, req->rv, req->p, |
| 196 | "acme reports %s: %s", ptype, pdetail); |
| 197 | } |
| 198 | else { |
| 199 | md_log_perror(MD_LOG_MARK, MD_LOG_WARNING, req->rv, req->p, |
| 200 | "acme problem %s: %s", ptype, pdetail); |
| 201 | } |
| 202 | return req->rv; |
| 203 | } |
| 204 | } |
| 205 | } |
| 206 | |
| 207 | switch (res->status) { |
| 208 | case 400: |
| 209 | return APR_EINVAL; |
| 210 | case 401: /* sectigo returns this instead of 403 */ |
| 211 | case 403: |
| 212 | return APR_EACCES; |
| 213 | case 404: |
| 214 | return APR_ENOENT; |
| 215 | default: |
| 216 | md_log_perror(MD_LOG_MARK, MD_LOG_WARNING, 0, req->p, |
| 217 | "acme problem unknown: http status %d", res->status); |
| 218 | md_result_printf(req->result, APR_EGENERAL, "unexpected http status: %d", |
| 219 | res->status); |
| 220 | return req->result->status; |
| 221 | } |
| 222 | return APR_SUCCESS; |
| 223 | } |
| 224 | |
| 225 | /**************************************************************************************************/ |
| 226 | /* ACME requests with nonce handling */ |
no test coverage detected