ocsp_http.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /*
  2. * Copyright 2001-2019 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. # ifndef OPENSSL_NO_SOCK
  34. int OCSP_sendreq_nbio(OCSP_RESPONSE **presp, OCSP_REQ_CTX *rctx)
  35. {
  36. *presp = (OCSP_RESPONSE *)
  37. OCSP_REQ_CTX_nbio_d2i(rctx, ASN1_ITEM_rptr(OCSP_RESPONSE));
  38. return *presp != NULL;
  39. }
  40. OCSP_RESPONSE *OCSP_sendreq_bio(BIO *b, const char *path, OCSP_REQUEST *req)
  41. {
  42. OCSP_RESPONSE *resp = NULL;
  43. OCSP_REQ_CTX *ctx;
  44. int rv;
  45. ctx = OCSP_sendreq_new(b, path, req, -1 /* default max resp line length */);
  46. if (ctx == NULL)
  47. return NULL;
  48. rv = OCSP_sendreq_nbio(&resp, ctx);
  49. /* this indirectly calls ERR_clear_error(): */
  50. OCSP_REQ_CTX_free(ctx);
  51. return rv == 1 ? resp : NULL;
  52. }
  53. # endif /* !defined(OPENSSL_NO_SOCK) */
  54. #endif /* !defined(OPENSSL_NO_OCSP) */