ocsp_http.c 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. #include "../http/http_local.h"
  12. #ifndef OPENSSL_NO_OCSP
  13. OSSL_HTTP_REQ_CTX *OCSP_sendreq_new(BIO *io, const char *path,
  14. const OCSP_REQUEST *req, int buf_size)
  15. {
  16. OSSL_HTTP_REQ_CTX *rctx = OSSL_HTTP_REQ_CTX_new(io, io, buf_size);
  17. if (rctx == NULL)
  18. return NULL;
  19. /*-
  20. * by default:
  21. * no bio_update_fn (and consequently no arg)
  22. * no ssl
  23. * no proxy
  24. * no timeout (blocking indefinitely)
  25. * no expected content type
  26. * max_resp_len = 100 KiB
  27. */
  28. if (!OSSL_HTTP_REQ_CTX_set_request_line(rctx, 1 /* POST */,
  29. NULL, NULL, path))
  30. goto err;
  31. /* by default, no extra headers */
  32. if (!OSSL_HTTP_REQ_CTX_set_expected(rctx,
  33. NULL /* content_type */, 1 /* asn1 */,
  34. 0 /* timeout */, 0 /* keep_alive */))
  35. goto err;
  36. if (req != NULL
  37. && !OSSL_HTTP_REQ_CTX_set1_req(rctx, "application/ocsp-request",
  38. ASN1_ITEM_rptr(OCSP_REQUEST),
  39. (const ASN1_VALUE *)req))
  40. goto err;
  41. return rctx;
  42. err:
  43. OSSL_HTTP_REQ_CTX_free(rctx);
  44. return NULL;
  45. }
  46. OCSP_RESPONSE *OCSP_sendreq_bio(BIO *b, const char *path, OCSP_REQUEST *req)
  47. {
  48. OCSP_RESPONSE *resp = NULL;
  49. OSSL_HTTP_REQ_CTX *ctx;
  50. BIO *mem;
  51. ctx = OCSP_sendreq_new(b, path, req, 0 /* default buf_size */);
  52. if (ctx == NULL)
  53. return NULL;
  54. mem = OSSL_HTTP_REQ_CTX_exchange(ctx);
  55. resp = (OCSP_RESPONSE *)
  56. ASN1_item_d2i_bio(ASN1_ITEM_rptr(OCSP_RESPONSE), mem, NULL);
  57. BIO_free(mem);
  58. /* this indirectly calls ERR_clear_error(): */
  59. OSSL_HTTP_REQ_CTX_free(ctx);
  60. return resp;
  61. }
  62. #endif /* !defined(OPENSSL_NO_OCSP) */