Skip to content

Conversation

@maskit
Copy link
Member

@maskit maskit commented Apr 7, 2023

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 make 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 OCSP stuff basically runs 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.

@maskit maskit added the TLS label Apr 7, 2023
@maskit maskit added this to the 10.0.0 milestone Apr 7, 2023
@maskit maskit self-assigned this Apr 7, 2023
@bneradt
Copy link
Contributor

bneradt commented Apr 8, 2023

[approve ci fedora]

@bryancall bryancall requested a review from ywkaras April 10, 2023 22:10
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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. I added error handling.

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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What process is listening on this port?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

return resp;
}
}
return resp;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

BIO_free_all(cbio);
if (resp) {
return resp;
}
Copy link
Contributor

@ywkaras ywkaras Apr 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;
    }

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed the memory leak.

Why do we need to check (res + len) == p ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To check for garbage at the end of the response.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@ywkaras
Copy link
Contributor

ywkaras commented Apr 14, 2023

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

@maskit
Copy link
Member Author

maskit commented Apr 14, 2023

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.

@maskit
Copy link
Member Author

maskit commented Apr 14, 2023

[approve ci]

@maskit maskit merged commit 4cf91f8 into apache:master Apr 17, 2023
cmcfarlen pushed a commit to cmcfarlen/trafficserver that referenced this pull request Jun 3, 2024
* asf/master: (40 commits)
  Change remap filter behavior to match ip_allow.yaml (apache#9631)
  Cleanup: Get rid of dead code from Cache (apache#9621)
  Replace obsolete Debug() macro with Dbg() in SocksProxy.cc. (apache#9613)
  Updates for the new go-httpbin v2.6.0 release. (apache#9633)
  Fix debian symbol not found for test_HttpTransact (apache#9617)
  add traffic_ctl to cmake (apache#9628)
  Fix Proxy Protocol outbound (apache#9632)
  DOC: Fix variable name `proxy.config.exec_thread.autoconfig.enabled`. (apache#9629)
  traffic_ctl: metric monitor. Handle SIGINT to drop collected stats. (apache#9570)
  traffic_ctl: plugin msg command, print out the response from server. (apache#9610)
  Doc: document IP allow filter for remap. (apache#9626)
  Cleanup: Rename d with vol (apache#9619)
  Ensure a reason phrase when sending an HTTP/1 response (apache#9615)
  Cmake plugins and install things (apache#9597)
  quic: Fix session cleanup assert. (apache#9622)
  Enables switching SSL certificates on QUIC with QUICHE (apache#9347)
  Use FetchSM for OCSP HTTP requests (apache#9591)
  Make a couple of the threads configs correct (apache#9604)
  Change submit_and_wait to take ink_hrtime. Fix test_AIO for io_uring. (apache#9555)
  Update build_h3_tools for mac (apache#9608)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants