2019-10-31 06:39:35 +08:00
|
|
|
/*
|
2021-01-28 20:54:57 +08:00
|
|
|
* Copyright 2001-2021 The OpenSSL Project Authors. All Rights Reserved.
|
2019-10-31 06:39:35 +08:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
|
|
|
* this file except in compliance with the License. You can obtain a copy
|
|
|
|
* in the file LICENSE in the source distribution or at
|
|
|
|
* https://www.openssl.org/source/license.html
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <openssl/ocsp.h>
|
|
|
|
#include <openssl/http.h>
|
|
|
|
#include "../http/http_local.h"
|
|
|
|
|
|
|
|
#ifndef OPENSSL_NO_OCSP
|
|
|
|
|
2020-12-26 23:21:41 +08:00
|
|
|
OSSL_HTTP_REQ_CTX *OCSP_sendreq_new(BIO *io, const char *path,
|
2021-01-18 19:53:55 +08:00
|
|
|
const OCSP_REQUEST *req, int maxline)
|
2019-10-31 06:39:35 +08:00
|
|
|
{
|
2021-01-18 19:53:55 +08:00
|
|
|
OSSL_HTTP_REQ_CTX *rctx = NULL;
|
|
|
|
|
2021-03-21 05:04:58 +08:00
|
|
|
if ((rctx = OSSL_HTTP_REQ_CTX_new(io, io,
|
2021-01-18 19:53:55 +08:00
|
|
|
maxline, 0 /* default max_resp_len */,
|
|
|
|
0 /* no timeout, blocking indefinitely */,
|
|
|
|
NULL, 1 /* expect_asn1 */)) == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
2021-03-21 05:04:58 +08:00
|
|
|
if (!OSSL_HTTP_REQ_CTX_set_request_line(rctx, 1 /* POST */, NULL, NULL, path))
|
2021-01-18 19:53:55 +08:00
|
|
|
goto err;
|
|
|
|
|
2021-03-21 05:17:46 +08:00
|
|
|
if (req != NULL
|
|
|
|
&& !OSSL_HTTP_REQ_CTX_set1_req(rctx, "application/ocsp-request",
|
|
|
|
ASN1_ITEM_rptr(OCSP_REQUEST),
|
|
|
|
(ASN1_VALUE *)req))
|
2021-01-18 19:53:55 +08:00
|
|
|
goto err;
|
|
|
|
|
|
|
|
return rctx;
|
|
|
|
|
|
|
|
err:
|
|
|
|
OSSL_HTTP_REQ_CTX_free(rctx);
|
|
|
|
return NULL;
|
2019-10-31 06:39:35 +08:00
|
|
|
}
|
|
|
|
|
2020-12-26 23:21:41 +08:00
|
|
|
int OCSP_sendreq_nbio(OCSP_RESPONSE **presp, OSSL_HTTP_REQ_CTX *rctx)
|
2019-10-31 06:39:35 +08:00
|
|
|
{
|
|
|
|
*presp = (OCSP_RESPONSE *)
|
2020-12-26 23:21:41 +08:00
|
|
|
OSSL_HTTP_REQ_CTX_sendreq_d2i(rctx, ASN1_ITEM_rptr(OCSP_RESPONSE));
|
2019-10-31 06:39:35 +08:00
|
|
|
return *presp != NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
OCSP_RESPONSE *OCSP_sendreq_bio(BIO *b, const char *path, OCSP_REQUEST *req)
|
|
|
|
{
|
|
|
|
OCSP_RESPONSE *resp = NULL;
|
2020-12-26 23:21:41 +08:00
|
|
|
OSSL_HTTP_REQ_CTX *ctx;
|
2019-10-31 06:39:35 +08:00
|
|
|
|
|
|
|
ctx = OCSP_sendreq_new(b, path, req, -1 /* default max resp line length */);
|
|
|
|
if (ctx == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
2021-03-01 21:06:32 +08:00
|
|
|
OCSP_sendreq_nbio(&resp, ctx);
|
2019-10-31 06:39:35 +08:00
|
|
|
|
|
|
|
/* this indirectly calls ERR_clear_error(): */
|
2020-12-26 23:21:41 +08:00
|
|
|
OSSL_HTTP_REQ_CTX_free(ctx);
|
2019-10-31 06:39:35 +08:00
|
|
|
|
2021-03-01 21:06:32 +08:00
|
|
|
return resp;
|
2019-10-31 06:39:35 +08:00
|
|
|
}
|
|
|
|
#endif /* !defined(OPENSSL_NO_OCSP) */
|