| 1030 | } |
| 1031 | |
| 1032 | static TS_OCSP_RESPONSE * |
| 1033 | query_responder(const char *uri, const char *user_agent, TS_OCSP_REQUEST *req, int req_timeout, bool use_get) |
| 1034 | { |
| 1035 | ink_hrtime start, end; |
| 1036 | TS_OCSP_RESPONSE *resp = nullptr; |
| 1037 | |
| 1038 | start = ink_get_hrtime(); |
| 1039 | end = ink_hrtime_add(start, ink_hrtime_from_sec(req_timeout)); |
| 1040 | |
| 1041 | HTTPRequest httpreq; |
| 1042 | |
| 1043 | httpreq.set_request_line(use_get, uri); |
| 1044 | |
| 1045 | // Host header |
| 1046 | const char *host = strstr(uri, "://") + 3; |
| 1047 | const char *slash = strchr(host, '/'); |
| 1048 | if (slash == nullptr) { |
| 1049 | slash = host + strlen(host); |
| 1050 | } |
| 1051 | int host_len = slash - host; |
| 1052 | httpreq.add_header("Host", 4, host, host_len); |
| 1053 | |
| 1054 | // User-Agent header |
| 1055 | if (user_agent != nullptr) { |
| 1056 | httpreq.add_header("User-Agent", user_agent); |
| 1057 | } |
| 1058 | |
| 1059 | // Content-Type, Content-Length, Request Body |
| 1060 | if (!use_get) { |
| 1061 | if (httpreq.set_body("application/ocsp-request", ASN1_ITEM_rptr(TS_OCSP_REQUEST), reinterpret_cast<const ASN1_VALUE *>(req)) != |
| 1062 | 1) { |
| 1063 | Error("failed to make a request for OCSP server; uri=%s", uri); |
| 1064 | return nullptr; |
| 1065 | } |
| 1066 | } |
| 1067 | |
| 1068 | // Send request |
| 1069 | Event *e = eventProcessor.schedule_imm(&httpreq, ET_NET); |
| 1070 | |
| 1071 | // Wait until the request completes |
| 1072 | do { |
| 1073 | ink_hrtime_sleep(HRTIME_MSECONDS(1)); |
| 1074 | } while (!httpreq.is_done() && (ink_get_hrtime() < end)); |
| 1075 | |
| 1076 | if (!httpreq.is_done()) { |
| 1077 | Error("OCSP request was timed out; uri=%s", uri); |
| 1078 | if (!httpreq.is_initiated()) { |
| 1079 | Dbg(dbg_ctl_ssl_ocsp, "Request is not initiated yet. Cancelling the event."); |
| 1080 | e->cancel(&httpreq); |
| 1081 | } |
| 1082 | } |
| 1083 | |
| 1084 | if (httpreq.is_success()) { |
| 1085 | // Parse the response |
| 1086 | int len; |
| 1087 | unsigned char *res = httpreq.get_response_body(&len); |
| 1088 | const unsigned char *p = res; |
| 1089 | resp = reinterpret_cast<TS_OCSP_RESPONSE *>(ASN1_item_d2i(nullptr, &p, len, ASN1_ITEM_rptr(TS_OCSP_RESPONSE))); |
no test coverage detected