ocsp_http.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*
  2. * Copyright 2001-2020 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. int OCSP_REQ_CTX_set1_req(OCSP_REQ_CTX *rctx, const OCSP_REQUEST *req)
  14. {
  15. return OCSP_REQ_CTX_i2d(rctx, "application/ocsp-request",
  16. ASN1_ITEM_rptr(OCSP_REQUEST), (ASN1_VALUE *)req);
  17. }
  18. OCSP_REQ_CTX *OCSP_sendreq_new(BIO *io, const char *path, OCSP_REQUEST *req,
  19. int maxline)
  20. {
  21. BIO *req_mem = HTTP_asn1_item2bio(ASN1_ITEM_rptr(OCSP_REQUEST),
  22. (ASN1_VALUE *)req);
  23. OCSP_REQ_CTX *res =
  24. HTTP_REQ_CTX_new(io, io, 0 /* no HTTP proxy used */, NULL, NULL, path,
  25. NULL /* headers */, "application/ocsp-request",
  26. req_mem /* may be NULL */,
  27. maxline, 0 /* default max_resp_len */,
  28. 0 /* no timeout, blocking indefinite */, NULL,
  29. 1 /* expect_asn1 */);
  30. BIO_free(req_mem);
  31. return res;
  32. }
  33. int OCSP_sendreq_nbio(OCSP_RESPONSE **presp, OCSP_REQ_CTX *rctx)
  34. {
  35. *presp = (OCSP_RESPONSE *)
  36. OCSP_REQ_CTX_nbio_d2i(rctx, ASN1_ITEM_rptr(OCSP_RESPONSE));
  37. return *presp != NULL;
  38. }
  39. OCSP_RESPONSE *OCSP_sendreq_bio(BIO *b, const char *path, OCSP_REQUEST *req)
  40. {
  41. OCSP_RESPONSE *resp = NULL;
  42. OCSP_REQ_CTX *ctx;
  43. int rv;
  44. ctx = OCSP_sendreq_new(b, path, req, -1 /* default max resp line length */);
  45. if (ctx == NULL)
  46. return NULL;
  47. rv = OCSP_sendreq_nbio(&resp, ctx);
  48. /* this indirectly calls ERR_clear_error(): */
  49. OCSP_REQ_CTX_free(ctx);
  50. return rv == 1 ? resp : NULL;
  51. }
  52. #endif /* !defined(OPENSSL_NO_OCSP) */