| 58 | #define HTML_STATUS(X) (!((X)->flags & AP_STATUS_SHORT)) |
| 59 | |
| 60 | int md_http_cert_status(request_rec *r) |
| 61 | { |
| 62 | int i; |
| 63 | md_json_t *resp, *mdj, *cj; |
| 64 | const md_srv_conf_t *sc; |
| 65 | const md_t *md; |
| 66 | md_pkey_spec_t *spec; |
| 67 | const char *keyname; |
| 68 | apr_bucket_brigade *bb; |
| 69 | apr_status_t rv; |
| 70 | |
| 71 | if (!r->parsed_uri.path || strcmp(MD_STATUS_RESOURCE, r->parsed_uri.path)) |
| 72 | return DECLINED; |
| 73 | |
| 74 | ap_log_rerror(APLOG_MARK, APLOG_TRACE2, 0, r, |
| 75 | "requesting status for: %s", r->hostname); |
| 76 | |
| 77 | /* We are looking for information about a staged certificate */ |
| 78 | sc = ap_get_module_config(r->server->module_config, &md_module); |
| 79 | if (!sc || !sc->mc || !sc->mc->reg || !sc->mc->certificate_status_enabled) return DECLINED; |
| 80 | md = md_get_by_domain(sc->mc->mds, r->hostname); |
| 81 | if (!md) return DECLINED; |
| 82 | |
| 83 | if (r->method_number != M_GET) { |
| 84 | ap_log_rerror(APLOG_MARK, APLOG_TRACE2, 0, r, |
| 85 | "md(%s): status supports only GET", md->name); |
| 86 | return HTTP_NOT_IMPLEMENTED; |
| 87 | } |
| 88 | |
| 89 | ap_log_rerror(APLOG_MARK, APLOG_TRACE2, 0, r, |
| 90 | "requesting status for MD: %s", md->name); |
| 91 | |
| 92 | rv = md_status_get_md_json(&mdj, md, sc->mc->reg, sc->mc->ocsp, r->pool); |
| 93 | if (APR_SUCCESS != rv) { |
| 94 | ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, APLOGNO(10204) |
| 95 | "loading md status for %s", md->name); |
| 96 | return HTTP_INTERNAL_SERVER_ERROR; |
| 97 | } |
| 98 | |
| 99 | ap_log_rerror(APLOG_MARK, APLOG_TRACE2, 0, r, |
| 100 | "status for MD: %s is %s", md->name, md_json_writep(mdj, r->pool, MD_JSON_FMT_INDENT)); |
| 101 | |
| 102 | resp = md_json_create(r->pool); |
| 103 | |
| 104 | if (md_json_has_key(mdj, MD_KEY_CERT, MD_KEY_VALID, NULL)) { |
| 105 | md_json_setj(md_json_getj(mdj, MD_KEY_CERT, MD_KEY_VALID, NULL), resp, MD_KEY_VALID, NULL); |
| 106 | } |
| 107 | |
| 108 | for (i = 0; i < md_cert_count(md); ++i) { |
| 109 | spec = md_pkeys_spec_get(md->pks, i); |
| 110 | keyname = md_pkey_spec_name(spec); |
| 111 | cj = md_json_create(r->pool); |
| 112 | |
| 113 | if (md_json_has_key(mdj, MD_KEY_CERT, keyname, MD_KEY_VALID, NULL)) { |
| 114 | md_json_setj(md_json_getj(mdj, MD_KEY_CERT, keyname, MD_KEY_VALID, NULL), |
| 115 | cj, MD_KEY_VALID, NULL); |
| 116 | } |
| 117 |
nothing calls this directly
no test coverage detected