You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@trafficserver.apache.org by "maskit (via GitHub)" <gi...@apache.org> on 2023/04/07 20:43:34 UTC

[GitHub] [trafficserver] maskit opened a new pull request, #9591: Use FetchSM for OCSP HTTP requests

maskit opened a new pull request, #9591:
URL: https://github.com/apache/trafficserver/pull/9591

   This is a step to support OCSP, without boringocsp library that has never been open sourced.
   
   ATS has been using `OCSP_REQ_CTX` and related functions, which makes HTTP requests for OCSP, but many of them were deprecated on OpenSSL 3.0 and they are unavailable on BoringSSL. On this PR, I replaced those functions with ATS's FetchSM and functions that are available on BoringSSL.
   
   It still doesn't work with BoringSSL because there are still other functions only available on OpenSSL. I'm going to replace them on next PR.
   
   Changes on FetchSM are needed because the HTTP requests are made on ET_OCSP thread and the requests can be made before FetchSM gets ready. It should not affect existing plugins because those won't run until everything is initialized.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@trafficserver.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [trafficserver] ywkaras commented on a diff in pull request #9591: Use FetchSM for OCSP HTTP requests

Posted by "ywkaras (via GitHub)" <gi...@apache.org>.
ywkaras commented on code in PR #9591:
URL: https://github.com/apache/trafficserver/pull/9591#discussion_r1164557750


##########
iocore/net/OCSPStapling.cc:
##########
@@ -373,84 +511,72 @@ stapling_check_response(certinfo *cinf, OCSP_RESPONSE *rsp)
 }
 
 static OCSP_RESPONSE *
-query_responder(BIO *b, const char *host, const char *path, const char *user_agent, OCSP_REQUEST *req, int req_timeout)
+query_responder(const char *uri, const char *user_agent, OCSP_REQUEST *req, int req_timeout)
 {
   ink_hrtime start, end;
   OCSP_RESPONSE *resp = nullptr;
-  OCSP_REQ_CTX *ctx;
-  int rv;
 
   start = Thread::get_hrtime();
   end   = ink_hrtime_add(start, ink_hrtime_from_sec(req_timeout));
 
-  ctx = OCSP_sendreq_new(b, path, nullptr, -1);
-  OCSP_REQ_CTX_add1_header(ctx, "Host", host);
-  if (user_agent != nullptr) {
-    OCSP_REQ_CTX_add1_header(ctx, "User-Agent", user_agent);
-  }
-  OCSP_REQ_CTX_set1_req(ctx, req);
+  HTTPRequest httpreq;
+  bool use_post = true;
 
-  do {
-    rv = OCSP_sendreq_nbio(&resp, ctx);
-    ink_hrtime_sleep(HRTIME_MSECONDS(1));
-  } while ((rv == -1) && BIO_should_retry(b) && (Thread::get_hrtime() < end));
+  httpreq.set_request_line(use_post, uri);
 
-  OCSP_REQ_CTX_free(ctx);
+  // Host header
+  const char *host  = strstr(uri, "://") + 3;
+  const char *slash = strchr(host, '/');
+  if (slash == nullptr) {
+    slash = host + strlen(host);
+  }
+  int host_len = slash - host;
+  httpreq.add_header("Host", 4, host, host_len);
 
-  if (rv == 1) {
-    return resp;
+  // User-Agent header
+  if (user_agent != nullptr) {
+    httpreq.add_header("User-Agent", user_agent);
   }
 
-  Error("failed to connect to OCSP server; host=%s path=%s", host, path);
+  // Content-Type, Content-Length, Request Body
+  if (use_post) {
+    httpreq.set_body("application/ocsp-request", ASN1_ITEM_rptr(OCSP_REQUEST), (const ASN1_VALUE *)req);

Review Comment:
   You are ignoring the return value of this function.  Should set_body() return void, and call set_error() for errors?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@trafficserver.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [trafficserver] maskit commented on pull request #9591: Use FetchSM for OCSP HTTP requests

Posted by "maskit (via GitHub)" <gi...@apache.org>.
maskit commented on PR #9591:
URL: https://github.com/apache/trafficserver/pull/9591#issuecomment-1507883289

   [approve ci]


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@trafficserver.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [trafficserver] maskit commented on a diff in pull request #9591: Use FetchSM for OCSP HTTP requests

Posted by "maskit (via GitHub)" <gi...@apache.org>.
maskit commented on code in PR #9591:
URL: https://github.com/apache/trafficserver/pull/9591#discussion_r1166116663


##########
iocore/net/OCSPStapling.cc:
##########
@@ -57,6 +59,142 @@ struct certinfo {
   time_t expire_time;
 };
 
+extern ClassAllocator<FetchSM> FetchSMAllocator;
+
+class HTTPRequest : public Continuation

Review Comment:
   added anonymous namespace.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@trafficserver.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [trafficserver] ywkaras commented on a diff in pull request #9591: Use FetchSM for OCSP HTTP requests

Posted by "ywkaras (via GitHub)" <gi...@apache.org>.
ywkaras commented on code in PR #9591:
URL: https://github.com/apache/trafficserver/pull/9591#discussion_r1164655967


##########
iocore/net/OCSPStapling.cc:
##########
@@ -57,6 +59,142 @@ struct certinfo {
   time_t expire_time;
 };
 
+extern ClassAllocator<FetchSM> FetchSMAllocator;
+
+class HTTPRequest : public Continuation

Review Comment:
   This looks like it should be in an anonymous namespace.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@trafficserver.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [trafficserver] maskit commented on a diff in pull request #9591: Use FetchSM for OCSP HTTP requests

Posted by "maskit (via GitHub)" <gi...@apache.org>.
maskit commented on code in PR #9591:
URL: https://github.com/apache/trafficserver/pull/9591#discussion_r1164749388


##########
iocore/net/OCSPStapling.cc:
##########
@@ -57,6 +59,142 @@ struct certinfo {
   time_t expire_time;
 };
 
+extern ClassAllocator<FetchSM> FetchSMAllocator;
+
+class HTTPRequest : public Continuation
+{
+public:
+  static constexpr int MAX_RESP_LEN = 100 * 1024;
+
+  HTTPRequest()
+  {
+    mutex = new_ProxyMutex();
+    SET_HANDLER(&HTTPRequest::event_handler);
+  }
+
+  ~HTTPRequest()
+  {
+    this->_fsm->ext_destroy();
+    OPENSSL_free(this->_req_body);
+  }
+
+  int
+  event_handler(int event, Event *e)
+  {
+    if (event == TS_EVENT_IMMEDIATE) {
+      this->fetch();
+    } else {
+      auto fsm = reinterpret_cast<FetchSM *>(e);
+      auto req = reinterpret_cast<HTTPRequest *>(fsm->ext_get_user_data());
+      if (event == TS_FETCH_EVENT_EXT_BODY_DONE) {
+        req->set_done();
+      } else if (event == TS_EVENT_ERROR) {
+        req->set_error();
+      }
+    }
+
+    return 0;
+  }
+
+  void
+  set_request_line(bool use_post, const char *uri)
+  {
+    struct sockaddr_in sin;
+    memset(&sin, 0, sizeof(sin));
+    sin.sin_family      = AF_INET;
+    sin.sin_addr.s_addr = inet_addr("127.0.0.1");
+    sin.sin_port        = 65535;

Review Comment:
   Nothing. I don't think the address and port are actually used for something.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@trafficserver.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [trafficserver] bneradt commented on pull request #9591: Use FetchSM for OCSP HTTP requests

Posted by "bneradt (via GitHub)" <gi...@apache.org>.
bneradt commented on PR #9591:
URL: https://github.com/apache/trafficserver/pull/9591#issuecomment-1500990160

   [approve ci fedora]


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@trafficserver.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [trafficserver] ywkaras commented on a diff in pull request #9591: Use FetchSM for OCSP HTTP requests

Posted by "ywkaras (via GitHub)" <gi...@apache.org>.
ywkaras commented on code in PR #9591:
URL: https://github.com/apache/trafficserver/pull/9591#discussion_r1164665491


##########
iocore/net/OCSPStapling.cc:
##########
@@ -57,6 +59,142 @@ struct certinfo {
   time_t expire_time;
 };
 
+extern ClassAllocator<FetchSM> FetchSMAllocator;
+
+class HTTPRequest : public Continuation
+{
+public:
+  static constexpr int MAX_RESP_LEN = 100 * 1024;
+
+  HTTPRequest()
+  {
+    mutex = new_ProxyMutex();
+    SET_HANDLER(&HTTPRequest::event_handler);
+  }
+
+  ~HTTPRequest()
+  {
+    this->_fsm->ext_destroy();
+    OPENSSL_free(this->_req_body);
+  }
+
+  int
+  event_handler(int event, Event *e)
+  {
+    if (event == TS_EVENT_IMMEDIATE) {
+      this->fetch();
+    } else {
+      auto fsm = reinterpret_cast<FetchSM *>(e);
+      auto req = reinterpret_cast<HTTPRequest *>(fsm->ext_get_user_data());
+      if (event == TS_FETCH_EVENT_EXT_BODY_DONE) {
+        req->set_done();
+      } else if (event == TS_EVENT_ERROR) {
+        req->set_error();
+      }
+    }
+
+    return 0;
+  }
+
+  void
+  set_request_line(bool use_post, const char *uri)
+  {
+    struct sockaddr_in sin;
+    memset(&sin, 0, sizeof(sin));
+    sin.sin_family      = AF_INET;
+    sin.sin_addr.s_addr = inet_addr("127.0.0.1");
+    sin.sin_port        = 65535;

Review Comment:
   What process is listening on this port?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@trafficserver.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [trafficserver] ywkaras commented on pull request #9591: Use FetchSM for OCSP HTTP requests

Posted by "ywkaras (via GitHub)" <gi...@apache.org>.
ywkaras commented on PR #9591:
URL: https://github.com/apache/trafficserver/pull/9591#issuecomment-1507858781

   How did you test this?  Can you add a regression test?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@trafficserver.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [trafficserver] ywkaras commented on a diff in pull request #9591: Use FetchSM for OCSP HTTP requests

Posted by "ywkaras (via GitHub)" <gi...@apache.org>.
ywkaras commented on code in PR #9591:
URL: https://github.com/apache/trafficserver/pull/9591#discussion_r1166175561


##########
iocore/net/OCSPStapling.cc:
##########
@@ -373,84 +516,84 @@ stapling_check_response(certinfo *cinf, OCSP_RESPONSE *rsp)
 }
 
 static OCSP_RESPONSE *
-query_responder(BIO *b, const char *host, const char *path, const char *user_agent, OCSP_REQUEST *req, int req_timeout)
+query_responder(const char *uri, const char *user_agent, OCSP_REQUEST *req, int req_timeout)
 {
   ink_hrtime start, end;
   OCSP_RESPONSE *resp = nullptr;
-  OCSP_REQ_CTX *ctx;
-  int rv;
 
   start = Thread::get_hrtime();
   end   = ink_hrtime_add(start, ink_hrtime_from_sec(req_timeout));
 
-  ctx = OCSP_sendreq_new(b, path, nullptr, -1);
-  OCSP_REQ_CTX_add1_header(ctx, "Host", host);
-  if (user_agent != nullptr) {
-    OCSP_REQ_CTX_add1_header(ctx, "User-Agent", user_agent);
-  }
-  OCSP_REQ_CTX_set1_req(ctx, req);
+  HTTPRequest httpreq;
+  bool use_post = true;
 
-  do {
-    rv = OCSP_sendreq_nbio(&resp, ctx);
-    ink_hrtime_sleep(HRTIME_MSECONDS(1));
-  } while ((rv == -1) && BIO_should_retry(b) && (Thread::get_hrtime() < end));
+  httpreq.set_request_line(use_post, uri);
 
-  OCSP_REQ_CTX_free(ctx);
+  // Host header
+  const char *host  = strstr(uri, "://") + 3;
+  const char *slash = strchr(host, '/');
+  if (slash == nullptr) {
+    slash = host + strlen(host);
+  }
+  int host_len = slash - host;
+  httpreq.add_header("Host", 4, host, host_len);
 
-  if (rv == 1) {
-    return resp;
+  // User-Agent header
+  if (user_agent != nullptr) {
+    httpreq.add_header("User-Agent", user_agent);
   }
 
-  Error("failed to connect to OCSP server; host=%s path=%s", host, path);
+  // Content-Type, Content-Length, Request Body
+  if (use_post) {
+    if (httpreq.set_body("application/ocsp-request", ASN1_ITEM_rptr(OCSP_REQUEST), (const ASN1_VALUE *)req) != 1) {
+      Error("failed to make a request for OCSP server; uri=%s", uri);
+      return nullptr;
+    }
+  }
 
-  return nullptr;
-}
+  // Send request
+  eventProcessor.schedule_imm(&httpreq, ET_NET);
 
-static OCSP_RESPONSE *
-process_responder(OCSP_REQUEST *req, const char *host, const char *path, const char *port, const char *user_agent, int req_timeout)
-{
-  BIO *cbio           = nullptr;
-  OCSP_RESPONSE *resp = nullptr;
-  cbio                = BIO_new_connect(host);
-  if (!cbio) {
-    goto end;
-  }
-  if (port) {
-    BIO_set_conn_port(cbio, port);
-  }
+  // Wait until the request completes
+  do {
+    ink_hrtime_sleep(HRTIME_MSECONDS(1));
+  } while (!httpreq.is_done() && (Thread::get_hrtime() < end));
 
-  BIO_set_nbio(cbio, 1);
-  if (BIO_do_connect(cbio) <= 0 && !BIO_should_retry(cbio)) {
-    Debug("ssl_ocsp", "process_responder: failed to connect to OCSP server; host=%s port=%s path=%s", host, port, path);
-    goto end;
-  }
-  resp = query_responder(cbio, host, path, user_agent, req, req_timeout);
+  if (httpreq.is_success()) {
+    // Parse the response
+    int len;
+    const unsigned char *res = httpreq.get_response_body(&len);
+    const unsigned char *p   = res;
+    resp                     = reinterpret_cast<OCSP_RESPONSE *>(ASN1_item_d2i(nullptr, &p, len, ASN1_ITEM_rptr(OCSP_RESPONSE)));
 
-end:
-  if (cbio) {
-    BIO_free_all(cbio);
+    if (resp) {
+      return resp;
+    }

Review Comment:
   It seems to me that the array of char that is returned by `httpreq.get_response_body() is leaked.  I think you need to change this code to:
   ```
       // Parse the response
       int len;
       const unsigned char *res = httpreq.get_response_body(&len);
       const unsigned char *p   = res;
       resp                     = reinterpret_cast<OCSP_RESPONSE *>(ASN1_item_d2i(nullptr, &p, len, ASN1_ITEM_rptr(OCSP_RESPONSE)));
       free(res);
   
       if (resp) {
         if ((res + len) == p) {
           return resp;
         }
         Error("garbage at the end of response from OCSP server; uri=%s len=%d", uri, len);
         return nullptr;
       }
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@trafficserver.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [trafficserver] ywkaras commented on a diff in pull request #9591: Use FetchSM for OCSP HTTP requests

Posted by "ywkaras (via GitHub)" <gi...@apache.org>.
ywkaras commented on code in PR #9591:
URL: https://github.com/apache/trafficserver/pull/9591#discussion_r1166175561


##########
iocore/net/OCSPStapling.cc:
##########
@@ -373,84 +516,84 @@ stapling_check_response(certinfo *cinf, OCSP_RESPONSE *rsp)
 }
 
 static OCSP_RESPONSE *
-query_responder(BIO *b, const char *host, const char *path, const char *user_agent, OCSP_REQUEST *req, int req_timeout)
+query_responder(const char *uri, const char *user_agent, OCSP_REQUEST *req, int req_timeout)
 {
   ink_hrtime start, end;
   OCSP_RESPONSE *resp = nullptr;
-  OCSP_REQ_CTX *ctx;
-  int rv;
 
   start = Thread::get_hrtime();
   end   = ink_hrtime_add(start, ink_hrtime_from_sec(req_timeout));
 
-  ctx = OCSP_sendreq_new(b, path, nullptr, -1);
-  OCSP_REQ_CTX_add1_header(ctx, "Host", host);
-  if (user_agent != nullptr) {
-    OCSP_REQ_CTX_add1_header(ctx, "User-Agent", user_agent);
-  }
-  OCSP_REQ_CTX_set1_req(ctx, req);
+  HTTPRequest httpreq;
+  bool use_post = true;
 
-  do {
-    rv = OCSP_sendreq_nbio(&resp, ctx);
-    ink_hrtime_sleep(HRTIME_MSECONDS(1));
-  } while ((rv == -1) && BIO_should_retry(b) && (Thread::get_hrtime() < end));
+  httpreq.set_request_line(use_post, uri);
 
-  OCSP_REQ_CTX_free(ctx);
+  // Host header
+  const char *host  = strstr(uri, "://") + 3;
+  const char *slash = strchr(host, '/');
+  if (slash == nullptr) {
+    slash = host + strlen(host);
+  }
+  int host_len = slash - host;
+  httpreq.add_header("Host", 4, host, host_len);
 
-  if (rv == 1) {
-    return resp;
+  // User-Agent header
+  if (user_agent != nullptr) {
+    httpreq.add_header("User-Agent", user_agent);
   }
 
-  Error("failed to connect to OCSP server; host=%s path=%s", host, path);
+  // Content-Type, Content-Length, Request Body
+  if (use_post) {
+    if (httpreq.set_body("application/ocsp-request", ASN1_ITEM_rptr(OCSP_REQUEST), (const ASN1_VALUE *)req) != 1) {
+      Error("failed to make a request for OCSP server; uri=%s", uri);
+      return nullptr;
+    }
+  }
 
-  return nullptr;
-}
+  // Send request
+  eventProcessor.schedule_imm(&httpreq, ET_NET);
 
-static OCSP_RESPONSE *
-process_responder(OCSP_REQUEST *req, const char *host, const char *path, const char *port, const char *user_agent, int req_timeout)
-{
-  BIO *cbio           = nullptr;
-  OCSP_RESPONSE *resp = nullptr;
-  cbio                = BIO_new_connect(host);
-  if (!cbio) {
-    goto end;
-  }
-  if (port) {
-    BIO_set_conn_port(cbio, port);
-  }
+  // Wait until the request completes
+  do {
+    ink_hrtime_sleep(HRTIME_MSECONDS(1));
+  } while (!httpreq.is_done() && (Thread::get_hrtime() < end));
 
-  BIO_set_nbio(cbio, 1);
-  if (BIO_do_connect(cbio) <= 0 && !BIO_should_retry(cbio)) {
-    Debug("ssl_ocsp", "process_responder: failed to connect to OCSP server; host=%s port=%s path=%s", host, port, path);
-    goto end;
-  }
-  resp = query_responder(cbio, host, path, user_agent, req, req_timeout);
+  if (httpreq.is_success()) {
+    // Parse the response
+    int len;
+    const unsigned char *res = httpreq.get_response_body(&len);
+    const unsigned char *p   = res;
+    resp                     = reinterpret_cast<OCSP_RESPONSE *>(ASN1_item_d2i(nullptr, &p, len, ASN1_ITEM_rptr(OCSP_RESPONSE)));
 
-end:
-  if (cbio) {
-    BIO_free_all(cbio);
+    if (resp) {
+      return resp;
+    }

Review Comment:
   It seems to me that the array of char that is returned by `httpreq.get_response_body() is leaked.  I think you need to change this code to:
   ```
       // Parse the response
       int len;
       const unsigned char *res = httpreq.get_response_body(&len);
       const unsigned char *p   = res;
       resp                     = reinterpret_cast<OCSP_RESPONSE *>(ASN1_item_d2i(nullptr, &p, len, ASN1_ITEM_rptr(OCSP_RESPONSE)));
   
       if (resp) {
         if ((res + len) == p) {
           free(res);
           return resp;
         }
         const unsigned char *garbage = res + len;
         int glen = p - garbage; 
         if (glen <= 0) {
           garbage = "OPENSSL ERROR";
           glen = strlen(garbage);
         } 
         Error("garbage at the end of response from OCSP server; uri=%s len=%d garbage=%.*s", uri, len, garbage, glen);
         free(res);
         return nullptr;
       }
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@trafficserver.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [trafficserver] ywkaras commented on pull request #9591: Use FetchSM for OCSP HTTP requests

Posted by "ywkaras (via GitHub)" <gi...@apache.org>.
ywkaras commented on PR #9591:
URL: https://github.com/apache/trafficserver/pull/9591#issuecomment-1505987706

   Would it be an option to use libcurl instead?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@trafficserver.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [trafficserver] maskit commented on a diff in pull request #9591: Use FetchSM for OCSP HTTP requests

Posted by "maskit (via GitHub)" <gi...@apache.org>.
maskit commented on code in PR #9591:
URL: https://github.com/apache/trafficserver/pull/9591#discussion_r1164575910


##########
iocore/net/OCSPStapling.cc:
##########
@@ -373,84 +511,72 @@ stapling_check_response(certinfo *cinf, OCSP_RESPONSE *rsp)
 }
 
 static OCSP_RESPONSE *
-query_responder(BIO *b, const char *host, const char *path, const char *user_agent, OCSP_REQUEST *req, int req_timeout)
+query_responder(const char *uri, const char *user_agent, OCSP_REQUEST *req, int req_timeout)
 {
   ink_hrtime start, end;
   OCSP_RESPONSE *resp = nullptr;
-  OCSP_REQ_CTX *ctx;
-  int rv;
 
   start = Thread::get_hrtime();
   end   = ink_hrtime_add(start, ink_hrtime_from_sec(req_timeout));
 
-  ctx = OCSP_sendreq_new(b, path, nullptr, -1);
-  OCSP_REQ_CTX_add1_header(ctx, "Host", host);
-  if (user_agent != nullptr) {
-    OCSP_REQ_CTX_add1_header(ctx, "User-Agent", user_agent);
-  }
-  OCSP_REQ_CTX_set1_req(ctx, req);
+  HTTPRequest httpreq;
+  bool use_post = true;
 
-  do {
-    rv = OCSP_sendreq_nbio(&resp, ctx);
-    ink_hrtime_sleep(HRTIME_MSECONDS(1));
-  } while ((rv == -1) && BIO_should_retry(b) && (Thread::get_hrtime() < end));
+  httpreq.set_request_line(use_post, uri);
 
-  OCSP_REQ_CTX_free(ctx);
+  // Host header
+  const char *host  = strstr(uri, "://") + 3;
+  const char *slash = strchr(host, '/');
+  if (slash == nullptr) {
+    slash = host + strlen(host);
+  }
+  int host_len = slash - host;
+  httpreq.add_header("Host", 4, host, host_len);
 
-  if (rv == 1) {
-    return resp;
+  // User-Agent header
+  if (user_agent != nullptr) {
+    httpreq.add_header("User-Agent", user_agent);
   }
 
-  Error("failed to connect to OCSP server; host=%s path=%s", host, path);
+  // Content-Type, Content-Length, Request Body
+  if (use_post) {
+    httpreq.set_body("application/ocsp-request", ASN1_ITEM_rptr(OCSP_REQUEST), (const ASN1_VALUE *)req);

Review Comment:
   Good catch. I added error handling.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@trafficserver.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [trafficserver] ywkaras commented on a diff in pull request #9591: Use FetchSM for OCSP HTTP requests

Posted by "ywkaras (via GitHub)" <gi...@apache.org>.
ywkaras commented on code in PR #9591:
URL: https://github.com/apache/trafficserver/pull/9591#discussion_r1164737810


##########
iocore/net/OCSPStapling.cc:
##########
@@ -373,84 +511,75 @@ stapling_check_response(certinfo *cinf, OCSP_RESPONSE *rsp)
 }
 
 static OCSP_RESPONSE *
-query_responder(BIO *b, const char *host, const char *path, const char *user_agent, OCSP_REQUEST *req, int req_timeout)
+query_responder(const char *uri, const char *user_agent, OCSP_REQUEST *req, int req_timeout)
 {
   ink_hrtime start, end;
   OCSP_RESPONSE *resp = nullptr;
-  OCSP_REQ_CTX *ctx;
-  int rv;
 
   start = Thread::get_hrtime();
   end   = ink_hrtime_add(start, ink_hrtime_from_sec(req_timeout));
 
-  ctx = OCSP_sendreq_new(b, path, nullptr, -1);
-  OCSP_REQ_CTX_add1_header(ctx, "Host", host);
-  if (user_agent != nullptr) {
-    OCSP_REQ_CTX_add1_header(ctx, "User-Agent", user_agent);
-  }
-  OCSP_REQ_CTX_set1_req(ctx, req);
+  HTTPRequest httpreq;
+  bool use_post = true;
 
-  do {
-    rv = OCSP_sendreq_nbio(&resp, ctx);
-    ink_hrtime_sleep(HRTIME_MSECONDS(1));
-  } while ((rv == -1) && BIO_should_retry(b) && (Thread::get_hrtime() < end));
+  httpreq.set_request_line(use_post, uri);
 
-  OCSP_REQ_CTX_free(ctx);
+  // Host header
+  const char *host  = strstr(uri, "://") + 3;
+  const char *slash = strchr(host, '/');
+  if (slash == nullptr) {
+    slash = host + strlen(host);
+  }
+  int host_len = slash - host;
+  httpreq.add_header("Host", 4, host, host_len);
 
-  if (rv == 1) {
-    return resp;
+  // User-Agent header
+  if (user_agent != nullptr) {
+    httpreq.add_header("User-Agent", user_agent);
   }
 
-  Error("failed to connect to OCSP server; host=%s path=%s", host, path);
+  // Content-Type, Content-Length, Request Body
+  if (use_post) {
+    if (httpreq.set_body("application/ocsp-request", ASN1_ITEM_rptr(OCSP_REQUEST), (const ASN1_VALUE *)req) != 1) {
+      Error("failed to make a request for OCSP server; uri=%s", uri);
+      return nullptr;
+    }
+  }
 
-  return nullptr;
-}
+  // Send request
+  eventProcessor.schedule_imm(&httpreq, ET_NET);
 
-static OCSP_RESPONSE *
-process_responder(OCSP_REQUEST *req, const char *host, const char *path, const char *port, const char *user_agent, int req_timeout)
-{
-  BIO *cbio           = nullptr;
-  OCSP_RESPONSE *resp = nullptr;
-  cbio                = BIO_new_connect(host);
-  if (!cbio) {
-    goto end;
-  }
-  if (port) {
-    BIO_set_conn_port(cbio, port);
-  }
+  // Wait until the request completes
+  do {
+    ink_hrtime_sleep(HRTIME_MSECONDS(1));
+  } while (!httpreq.is_done() && (Thread::get_hrtime() < end));
 
-  BIO_set_nbio(cbio, 1);
-  if (BIO_do_connect(cbio) <= 0 && !BIO_should_retry(cbio)) {
-    Debug("ssl_ocsp", "process_responder: failed to connect to OCSP server; host=%s port=%s path=%s", host, port, path);
-    goto end;
-  }
-  resp = query_responder(cbio, host, path, user_agent, req, req_timeout);
+  if (httpreq.is_success()) {
+    // Parse the response
+    int len;
+    const unsigned char *p = httpreq.get_response_body(&len);
+    resp                   = reinterpret_cast<OCSP_RESPONSE *>(ASN1_item_d2i(nullptr, &p, len, ASN1_ITEM_rptr(OCSP_RESPONSE)));

Review Comment:
   Seems like you need to free `p` here.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@trafficserver.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [trafficserver] maskit commented on a diff in pull request #9591: Use FetchSM for OCSP HTTP requests

Posted by "maskit (via GitHub)" <gi...@apache.org>.
maskit commented on code in PR #9591:
URL: https://github.com/apache/trafficserver/pull/9591#discussion_r1166117004


##########
iocore/net/OCSPStapling.cc:
##########
@@ -373,84 +511,75 @@ stapling_check_response(certinfo *cinf, OCSP_RESPONSE *rsp)
 }
 
 static OCSP_RESPONSE *
-query_responder(BIO *b, const char *host, const char *path, const char *user_agent, OCSP_REQUEST *req, int req_timeout)
+query_responder(const char *uri, const char *user_agent, OCSP_REQUEST *req, int req_timeout)
 {
   ink_hrtime start, end;
   OCSP_RESPONSE *resp = nullptr;
-  OCSP_REQ_CTX *ctx;
-  int rv;
 
   start = Thread::get_hrtime();
   end   = ink_hrtime_add(start, ink_hrtime_from_sec(req_timeout));
 
-  ctx = OCSP_sendreq_new(b, path, nullptr, -1);
-  OCSP_REQ_CTX_add1_header(ctx, "Host", host);
-  if (user_agent != nullptr) {
-    OCSP_REQ_CTX_add1_header(ctx, "User-Agent", user_agent);
-  }
-  OCSP_REQ_CTX_set1_req(ctx, req);
+  HTTPRequest httpreq;
+  bool use_post = true;
 
-  do {
-    rv = OCSP_sendreq_nbio(&resp, ctx);
-    ink_hrtime_sleep(HRTIME_MSECONDS(1));
-  } while ((rv == -1) && BIO_should_retry(b) && (Thread::get_hrtime() < end));
+  httpreq.set_request_line(use_post, uri);
 
-  OCSP_REQ_CTX_free(ctx);
+  // Host header
+  const char *host  = strstr(uri, "://") + 3;
+  const char *slash = strchr(host, '/');
+  if (slash == nullptr) {
+    slash = host + strlen(host);
+  }
+  int host_len = slash - host;
+  httpreq.add_header("Host", 4, host, host_len);
 
-  if (rv == 1) {
-    return resp;
+  // User-Agent header
+  if (user_agent != nullptr) {
+    httpreq.add_header("User-Agent", user_agent);
   }
 
-  Error("failed to connect to OCSP server; host=%s path=%s", host, path);
+  // Content-Type, Content-Length, Request Body
+  if (use_post) {
+    if (httpreq.set_body("application/ocsp-request", ASN1_ITEM_rptr(OCSP_REQUEST), (const ASN1_VALUE *)req) != 1) {
+      Error("failed to make a request for OCSP server; uri=%s", uri);
+      return nullptr;
+    }
+  }
 
-  return nullptr;
-}
+  // Send request
+  eventProcessor.schedule_imm(&httpreq, ET_NET);
 
-static OCSP_RESPONSE *
-process_responder(OCSP_REQUEST *req, const char *host, const char *path, const char *port, const char *user_agent, int req_timeout)
-{
-  BIO *cbio           = nullptr;
-  OCSP_RESPONSE *resp = nullptr;
-  cbio                = BIO_new_connect(host);
-  if (!cbio) {
-    goto end;
-  }
-  if (port) {
-    BIO_set_conn_port(cbio, port);
-  }
+  // Wait until the request completes
+  do {
+    ink_hrtime_sleep(HRTIME_MSECONDS(1));
+  } while (!httpreq.is_done() && (Thread::get_hrtime() < end));
 
-  BIO_set_nbio(cbio, 1);
-  if (BIO_do_connect(cbio) <= 0 && !BIO_should_retry(cbio)) {
-    Debug("ssl_ocsp", "process_responder: failed to connect to OCSP server; host=%s port=%s path=%s", host, port, path);
-    goto end;
-  }
-  resp = query_responder(cbio, host, path, user_agent, req, req_timeout);
+  if (httpreq.is_success()) {
+    // Parse the response
+    int len;
+    const unsigned char *p = httpreq.get_response_body(&len);
+    resp                   = reinterpret_cast<OCSP_RESPONSE *>(ASN1_item_d2i(nullptr, &p, len, ASN1_ITEM_rptr(OCSP_RESPONSE)));
 
-end:
-  if (cbio) {
-    BIO_free_all(cbio);
+    if (resp) {
+      return resp;
+    }
   }
-  return resp;

Review Comment:
   Now error log has first 5 bytes of a response if ATS fails to parse it.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@trafficserver.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [trafficserver] maskit commented on a diff in pull request #9591: Use FetchSM for OCSP HTTP requests

Posted by "maskit (via GitHub)" <gi...@apache.org>.
maskit commented on code in PR #9591:
URL: https://github.com/apache/trafficserver/pull/9591#discussion_r1166217568


##########
iocore/net/OCSPStapling.cc:
##########
@@ -373,84 +516,84 @@ stapling_check_response(certinfo *cinf, OCSP_RESPONSE *rsp)
 }
 
 static OCSP_RESPONSE *
-query_responder(BIO *b, const char *host, const char *path, const char *user_agent, OCSP_REQUEST *req, int req_timeout)
+query_responder(const char *uri, const char *user_agent, OCSP_REQUEST *req, int req_timeout)
 {
   ink_hrtime start, end;
   OCSP_RESPONSE *resp = nullptr;
-  OCSP_REQ_CTX *ctx;
-  int rv;
 
   start = Thread::get_hrtime();
   end   = ink_hrtime_add(start, ink_hrtime_from_sec(req_timeout));
 
-  ctx = OCSP_sendreq_new(b, path, nullptr, -1);
-  OCSP_REQ_CTX_add1_header(ctx, "Host", host);
-  if (user_agent != nullptr) {
-    OCSP_REQ_CTX_add1_header(ctx, "User-Agent", user_agent);
-  }
-  OCSP_REQ_CTX_set1_req(ctx, req);
+  HTTPRequest httpreq;
+  bool use_post = true;
 
-  do {
-    rv = OCSP_sendreq_nbio(&resp, ctx);
-    ink_hrtime_sleep(HRTIME_MSECONDS(1));
-  } while ((rv == -1) && BIO_should_retry(b) && (Thread::get_hrtime() < end));
+  httpreq.set_request_line(use_post, uri);
 
-  OCSP_REQ_CTX_free(ctx);
+  // Host header
+  const char *host  = strstr(uri, "://") + 3;
+  const char *slash = strchr(host, '/');
+  if (slash == nullptr) {
+    slash = host + strlen(host);
+  }
+  int host_len = slash - host;
+  httpreq.add_header("Host", 4, host, host_len);
 
-  if (rv == 1) {
-    return resp;
+  // User-Agent header
+  if (user_agent != nullptr) {
+    httpreq.add_header("User-Agent", user_agent);
   }
 
-  Error("failed to connect to OCSP server; host=%s path=%s", host, path);
+  // Content-Type, Content-Length, Request Body
+  if (use_post) {
+    if (httpreq.set_body("application/ocsp-request", ASN1_ITEM_rptr(OCSP_REQUEST), (const ASN1_VALUE *)req) != 1) {
+      Error("failed to make a request for OCSP server; uri=%s", uri);
+      return nullptr;
+    }
+  }
 
-  return nullptr;
-}
+  // Send request
+  eventProcessor.schedule_imm(&httpreq, ET_NET);
 
-static OCSP_RESPONSE *
-process_responder(OCSP_REQUEST *req, const char *host, const char *path, const char *port, const char *user_agent, int req_timeout)
-{
-  BIO *cbio           = nullptr;
-  OCSP_RESPONSE *resp = nullptr;
-  cbio                = BIO_new_connect(host);
-  if (!cbio) {
-    goto end;
-  }
-  if (port) {
-    BIO_set_conn_port(cbio, port);
-  }
+  // Wait until the request completes
+  do {
+    ink_hrtime_sleep(HRTIME_MSECONDS(1));
+  } while (!httpreq.is_done() && (Thread::get_hrtime() < end));
 
-  BIO_set_nbio(cbio, 1);
-  if (BIO_do_connect(cbio) <= 0 && !BIO_should_retry(cbio)) {
-    Debug("ssl_ocsp", "process_responder: failed to connect to OCSP server; host=%s port=%s path=%s", host, port, path);
-    goto end;
-  }
-  resp = query_responder(cbio, host, path, user_agent, req, req_timeout);
+  if (httpreq.is_success()) {
+    // Parse the response
+    int len;
+    const unsigned char *res = httpreq.get_response_body(&len);
+    const unsigned char *p   = res;
+    resp                     = reinterpret_cast<OCSP_RESPONSE *>(ASN1_item_d2i(nullptr, &p, len, ASN1_ITEM_rptr(OCSP_RESPONSE)));
 
-end:
-  if (cbio) {
-    BIO_free_all(cbio);
+    if (resp) {
+      return resp;
+    }

Review Comment:
   Fixed the memory leak.
   
   Why do we need to check `(res + len) == p` ?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@trafficserver.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [trafficserver] maskit commented on a diff in pull request #9591: Use FetchSM for OCSP HTTP requests

Posted by "maskit (via GitHub)" <gi...@apache.org>.
maskit commented on code in PR #9591:
URL: https://github.com/apache/trafficserver/pull/9591#discussion_r1166241383


##########
iocore/net/OCSPStapling.cc:
##########
@@ -373,84 +516,84 @@ stapling_check_response(certinfo *cinf, OCSP_RESPONSE *rsp)
 }
 
 static OCSP_RESPONSE *
-query_responder(BIO *b, const char *host, const char *path, const char *user_agent, OCSP_REQUEST *req, int req_timeout)
+query_responder(const char *uri, const char *user_agent, OCSP_REQUEST *req, int req_timeout)
 {
   ink_hrtime start, end;
   OCSP_RESPONSE *resp = nullptr;
-  OCSP_REQ_CTX *ctx;
-  int rv;
 
   start = Thread::get_hrtime();
   end   = ink_hrtime_add(start, ink_hrtime_from_sec(req_timeout));
 
-  ctx = OCSP_sendreq_new(b, path, nullptr, -1);
-  OCSP_REQ_CTX_add1_header(ctx, "Host", host);
-  if (user_agent != nullptr) {
-    OCSP_REQ_CTX_add1_header(ctx, "User-Agent", user_agent);
-  }
-  OCSP_REQ_CTX_set1_req(ctx, req);
+  HTTPRequest httpreq;
+  bool use_post = true;
 
-  do {
-    rv = OCSP_sendreq_nbio(&resp, ctx);
-    ink_hrtime_sleep(HRTIME_MSECONDS(1));
-  } while ((rv == -1) && BIO_should_retry(b) && (Thread::get_hrtime() < end));
+  httpreq.set_request_line(use_post, uri);
 
-  OCSP_REQ_CTX_free(ctx);
+  // Host header
+  const char *host  = strstr(uri, "://") + 3;
+  const char *slash = strchr(host, '/');
+  if (slash == nullptr) {
+    slash = host + strlen(host);
+  }
+  int host_len = slash - host;
+  httpreq.add_header("Host", 4, host, host_len);
 
-  if (rv == 1) {
-    return resp;
+  // User-Agent header
+  if (user_agent != nullptr) {
+    httpreq.add_header("User-Agent", user_agent);
   }
 
-  Error("failed to connect to OCSP server; host=%s path=%s", host, path);
+  // Content-Type, Content-Length, Request Body
+  if (use_post) {
+    if (httpreq.set_body("application/ocsp-request", ASN1_ITEM_rptr(OCSP_REQUEST), (const ASN1_VALUE *)req) != 1) {
+      Error("failed to make a request for OCSP server; uri=%s", uri);
+      return nullptr;
+    }
+  }
 
-  return nullptr;
-}
+  // Send request
+  eventProcessor.schedule_imm(&httpreq, ET_NET);
 
-static OCSP_RESPONSE *
-process_responder(OCSP_REQUEST *req, const char *host, const char *path, const char *port, const char *user_agent, int req_timeout)
-{
-  BIO *cbio           = nullptr;
-  OCSP_RESPONSE *resp = nullptr;
-  cbio                = BIO_new_connect(host);
-  if (!cbio) {
-    goto end;
-  }
-  if (port) {
-    BIO_set_conn_port(cbio, port);
-  }
+  // Wait until the request completes
+  do {
+    ink_hrtime_sleep(HRTIME_MSECONDS(1));
+  } while (!httpreq.is_done() && (Thread::get_hrtime() < end));
 
-  BIO_set_nbio(cbio, 1);
-  if (BIO_do_connect(cbio) <= 0 && !BIO_should_retry(cbio)) {
-    Debug("ssl_ocsp", "process_responder: failed to connect to OCSP server; host=%s port=%s path=%s", host, port, path);
-    goto end;
-  }
-  resp = query_responder(cbio, host, path, user_agent, req, req_timeout);
+  if (httpreq.is_success()) {
+    // Parse the response
+    int len;
+    const unsigned char *res = httpreq.get_response_body(&len);
+    const unsigned char *p   = res;
+    resp                     = reinterpret_cast<OCSP_RESPONSE *>(ASN1_item_d2i(nullptr, &p, len, ASN1_ITEM_rptr(OCSP_RESPONSE)));
 
-end:
-  if (cbio) {
-    BIO_free_all(cbio);
+    if (resp) {
+      return resp;
+    }

Review Comment:
   OpenSSL's implementation (OSSL_HTTP_REQ_CTX_nbio_d2i) doesn't seem to check it. The check could be too strict and might find unexpected incompatibility. I don't want to have it on this PR.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@trafficserver.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [trafficserver] maskit commented on pull request #9591: Use FetchSM for OCSP HTTP requests

Posted by "maskit (via GitHub)" <gi...@apache.org>.
maskit commented on PR #9591:
URL: https://github.com/apache/trafficserver/pull/9591#issuecomment-1507883217

   The test I did is completely manual. Setup a test web server that serves ocsp_response.der used in tls_ocsp autest, setup ATS with certs for the autest, then launch ATS. I checked ssl_ocsp debug log.
   
   It would be great if we could have an autest for this, but I don't think we can have it because the URL for OCSP responder (http://localhost:8888) is written in the cert. I guess autest can open a port with a fixed number but I don't think that's something we want to do.
   
   Also, I'm testing the code on several of our prod servers. Although the memory leak exist, everything looks fine so far.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@trafficserver.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [trafficserver] ywkaras commented on a diff in pull request #9591: Use FetchSM for OCSP HTTP requests

Posted by "ywkaras (via GitHub)" <gi...@apache.org>.
ywkaras commented on code in PR #9591:
URL: https://github.com/apache/trafficserver/pull/9591#discussion_r1164937126


##########
iocore/net/OCSPStapling.cc:
##########
@@ -373,84 +511,75 @@ stapling_check_response(certinfo *cinf, OCSP_RESPONSE *rsp)
 }
 
 static OCSP_RESPONSE *
-query_responder(BIO *b, const char *host, const char *path, const char *user_agent, OCSP_REQUEST *req, int req_timeout)
+query_responder(const char *uri, const char *user_agent, OCSP_REQUEST *req, int req_timeout)
 {
   ink_hrtime start, end;
   OCSP_RESPONSE *resp = nullptr;
-  OCSP_REQ_CTX *ctx;
-  int rv;
 
   start = Thread::get_hrtime();
   end   = ink_hrtime_add(start, ink_hrtime_from_sec(req_timeout));
 
-  ctx = OCSP_sendreq_new(b, path, nullptr, -1);
-  OCSP_REQ_CTX_add1_header(ctx, "Host", host);
-  if (user_agent != nullptr) {
-    OCSP_REQ_CTX_add1_header(ctx, "User-Agent", user_agent);
-  }
-  OCSP_REQ_CTX_set1_req(ctx, req);
+  HTTPRequest httpreq;
+  bool use_post = true;
 
-  do {
-    rv = OCSP_sendreq_nbio(&resp, ctx);
-    ink_hrtime_sleep(HRTIME_MSECONDS(1));
-  } while ((rv == -1) && BIO_should_retry(b) && (Thread::get_hrtime() < end));
+  httpreq.set_request_line(use_post, uri);
 
-  OCSP_REQ_CTX_free(ctx);
+  // Host header
+  const char *host  = strstr(uri, "://") + 3;
+  const char *slash = strchr(host, '/');
+  if (slash == nullptr) {
+    slash = host + strlen(host);
+  }
+  int host_len = slash - host;
+  httpreq.add_header("Host", 4, host, host_len);
 
-  if (rv == 1) {
-    return resp;
+  // User-Agent header
+  if (user_agent != nullptr) {
+    httpreq.add_header("User-Agent", user_agent);
   }
 
-  Error("failed to connect to OCSP server; host=%s path=%s", host, path);
+  // Content-Type, Content-Length, Request Body
+  if (use_post) {
+    if (httpreq.set_body("application/ocsp-request", ASN1_ITEM_rptr(OCSP_REQUEST), (const ASN1_VALUE *)req) != 1) {
+      Error("failed to make a request for OCSP server; uri=%s", uri);
+      return nullptr;
+    }
+  }
 
-  return nullptr;
-}
+  // Send request
+  eventProcessor.schedule_imm(&httpreq, ET_NET);
 
-static OCSP_RESPONSE *
-process_responder(OCSP_REQUEST *req, const char *host, const char *path, const char *port, const char *user_agent, int req_timeout)
-{
-  BIO *cbio           = nullptr;
-  OCSP_RESPONSE *resp = nullptr;
-  cbio                = BIO_new_connect(host);
-  if (!cbio) {
-    goto end;
-  }
-  if (port) {
-    BIO_set_conn_port(cbio, port);
-  }
+  // Wait until the request completes
+  do {
+    ink_hrtime_sleep(HRTIME_MSECONDS(1));
+  } while (!httpreq.is_done() && (Thread::get_hrtime() < end));
 
-  BIO_set_nbio(cbio, 1);
-  if (BIO_do_connect(cbio) <= 0 && !BIO_should_retry(cbio)) {
-    Debug("ssl_ocsp", "process_responder: failed to connect to OCSP server; host=%s port=%s path=%s", host, port, path);
-    goto end;
-  }
-  resp = query_responder(cbio, host, path, user_agent, req, req_timeout);
+  if (httpreq.is_success()) {
+    // Parse the response
+    int len;
+    const unsigned char *p = httpreq.get_response_body(&len);
+    resp                   = reinterpret_cast<OCSP_RESPONSE *>(ASN1_item_d2i(nullptr, &p, len, ASN1_ITEM_rptr(OCSP_RESPONSE)));
 
-end:
-  if (cbio) {
-    BIO_free_all(cbio);
+    if (resp) {
+      return resp;
+    }
   }
-  return resp;

Review Comment:
   Probably also be good to put the value of `p` in the trace output for bad responses.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@trafficserver.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [trafficserver] ywkaras commented on a diff in pull request #9591: Use FetchSM for OCSP HTTP requests

Posted by "ywkaras (via GitHub)" <gi...@apache.org>.
ywkaras commented on code in PR #9591:
URL: https://github.com/apache/trafficserver/pull/9591#discussion_r1166221704


##########
iocore/net/OCSPStapling.cc:
##########
@@ -373,84 +516,84 @@ stapling_check_response(certinfo *cinf, OCSP_RESPONSE *rsp)
 }
 
 static OCSP_RESPONSE *
-query_responder(BIO *b, const char *host, const char *path, const char *user_agent, OCSP_REQUEST *req, int req_timeout)
+query_responder(const char *uri, const char *user_agent, OCSP_REQUEST *req, int req_timeout)
 {
   ink_hrtime start, end;
   OCSP_RESPONSE *resp = nullptr;
-  OCSP_REQ_CTX *ctx;
-  int rv;
 
   start = Thread::get_hrtime();
   end   = ink_hrtime_add(start, ink_hrtime_from_sec(req_timeout));
 
-  ctx = OCSP_sendreq_new(b, path, nullptr, -1);
-  OCSP_REQ_CTX_add1_header(ctx, "Host", host);
-  if (user_agent != nullptr) {
-    OCSP_REQ_CTX_add1_header(ctx, "User-Agent", user_agent);
-  }
-  OCSP_REQ_CTX_set1_req(ctx, req);
+  HTTPRequest httpreq;
+  bool use_post = true;
 
-  do {
-    rv = OCSP_sendreq_nbio(&resp, ctx);
-    ink_hrtime_sleep(HRTIME_MSECONDS(1));
-  } while ((rv == -1) && BIO_should_retry(b) && (Thread::get_hrtime() < end));
+  httpreq.set_request_line(use_post, uri);
 
-  OCSP_REQ_CTX_free(ctx);
+  // Host header
+  const char *host  = strstr(uri, "://") + 3;
+  const char *slash = strchr(host, '/');
+  if (slash == nullptr) {
+    slash = host + strlen(host);
+  }
+  int host_len = slash - host;
+  httpreq.add_header("Host", 4, host, host_len);
 
-  if (rv == 1) {
-    return resp;
+  // User-Agent header
+  if (user_agent != nullptr) {
+    httpreq.add_header("User-Agent", user_agent);
   }
 
-  Error("failed to connect to OCSP server; host=%s path=%s", host, path);
+  // Content-Type, Content-Length, Request Body
+  if (use_post) {
+    if (httpreq.set_body("application/ocsp-request", ASN1_ITEM_rptr(OCSP_REQUEST), (const ASN1_VALUE *)req) != 1) {
+      Error("failed to make a request for OCSP server; uri=%s", uri);
+      return nullptr;
+    }
+  }
 
-  return nullptr;
-}
+  // Send request
+  eventProcessor.schedule_imm(&httpreq, ET_NET);
 
-static OCSP_RESPONSE *
-process_responder(OCSP_REQUEST *req, const char *host, const char *path, const char *port, const char *user_agent, int req_timeout)
-{
-  BIO *cbio           = nullptr;
-  OCSP_RESPONSE *resp = nullptr;
-  cbio                = BIO_new_connect(host);
-  if (!cbio) {
-    goto end;
-  }
-  if (port) {
-    BIO_set_conn_port(cbio, port);
-  }
+  // Wait until the request completes
+  do {
+    ink_hrtime_sleep(HRTIME_MSECONDS(1));
+  } while (!httpreq.is_done() && (Thread::get_hrtime() < end));
 
-  BIO_set_nbio(cbio, 1);
-  if (BIO_do_connect(cbio) <= 0 && !BIO_should_retry(cbio)) {
-    Debug("ssl_ocsp", "process_responder: failed to connect to OCSP server; host=%s port=%s path=%s", host, port, path);
-    goto end;
-  }
-  resp = query_responder(cbio, host, path, user_agent, req, req_timeout);
+  if (httpreq.is_success()) {
+    // Parse the response
+    int len;
+    const unsigned char *res = httpreq.get_response_body(&len);
+    const unsigned char *p   = res;
+    resp                     = reinterpret_cast<OCSP_RESPONSE *>(ASN1_item_d2i(nullptr, &p, len, ASN1_ITEM_rptr(OCSP_RESPONSE)));
 
-end:
-  if (cbio) {
-    BIO_free_all(cbio);
+    if (resp) {
+      return resp;
+    }

Review Comment:
   To check for garbage at the end of the response.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@trafficserver.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [trafficserver] maskit merged pull request #9591: Use FetchSM for OCSP HTTP requests

Posted by "maskit (via GitHub)" <gi...@apache.org>.
maskit merged PR #9591:
URL: https://github.com/apache/trafficserver/pull/9591


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@trafficserver.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org