ocsp_http.c 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /*
  2. * Copyright 2001-2021 The OpenSSL Project Authors. All Rights Reserved.
  3. *
  4. * Licensed under the Apache License 2.0 (the "License"). You may not use
  5. * this file except in compliance with the License. You can obtain a copy
  6. * in the file LICENSE in the source distribution or at
  7. * https://www.openssl.org/source/license.html
  8. */
  9. #include <openssl/ocsp.h>
  10. #include <openssl/http.h>
  11. #ifndef OPENSSL_NO_OCSP
  12. OSSL_HTTP_REQ_CTX *OCSP_sendreq_new(BIO *io, const char *path,
  13. const OCSP_REQUEST *req, int buf_size)
  14. {
  15. OSSL_HTTP_REQ_CTX *rctx = OSSL_HTTP_REQ_CTX_new(io, io, buf_size);
  16. if (rctx == NULL)
  17. return NULL;
  18. /*-
  19. * by default:
  20. * no bio_update_fn (and consequently no arg)
  21. * no ssl
  22. * no proxy
  23. * no timeout (blocking indefinitely)
  24. * no expected content type
  25. * max_resp_len = 100 KiB
  26. */
  27. if (!OSSL_HTTP_REQ_CTX_set_request_line(rctx, 1 /* POST */,
  28. NULL, NULL, path))
  29. goto err;
  30. /* by default, no extra headers */
  31. if (!OSSL_HTTP_REQ_CTX_set_expected(rctx,
  32. NULL /* content_type */, 1 /* asn1 */,
  33. 0 /* timeout */, 0 /* keep_alive */))
  34. goto err;
  35. if (req != NULL
  36. && !OSSL_HTTP_REQ_CTX_set1_req(rctx, "application/ocsp-request",
  37. ASN1_ITEM_rptr(OCSP_REQUEST),
  38. (const ASN1_VALUE *)req))
  39. goto err;
  40. return rctx;
  41. err:
  42. OSSL_HTTP_REQ_CTX_free(rctx);
  43. return NULL;
  44. }
  45. OCSP_RESPONSE *OCSP_sendreq_bio(BIO *b, const char *path, OCSP_REQUEST *req)
  46. {
  47. OCSP_RESPONSE *resp = NULL;
  48. OSSL_HTTP_REQ_CTX *ctx;
  49. BIO *mem;
  50. ctx = OCSP_sendreq_new(b, path, req, 0 /* default buf_size */);
  51. if (ctx == NULL)
  52. return NULL;
  53. mem = OSSL_HTTP_REQ_CTX_exchange(ctx);
  54. /* ASN1_item_d2i_bio handles NULL bio gracefully */
  55. resp = (OCSP_RESPONSE *)ASN1_item_d2i_bio(ASN1_ITEM_rptr(OCSP_RESPONSE),
  56. mem, NULL);
  57. OSSL_HTTP_REQ_CTX_free(ctx);
  58. return resp;
  59. }
  60. #endif /* !defined(OPENSSL_NO_OCSP) */