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>
|
|
|
|
|
|
|
|
#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-05-12 14:37:54 +08:00
|
|
|
const OCSP_REQUEST *req, int buf_size)
|
2019-10-31 06:39:35 +08:00
|
|
|
{
|
2021-05-12 14:37:54 +08:00
|
|
|
OSSL_HTTP_REQ_CTX *rctx = OSSL_HTTP_REQ_CTX_new(io, io, buf_size);
|
2021-01-18 19:53:55 +08:00
|
|
|
|
2021-05-05 06:09:43 +08:00
|
|
|
if (rctx == NULL)
|
2021-01-18 19:53:55 +08:00
|
|
|
return NULL;
|
HTTP: Implement persistent connections (keep-alive)
Both at API and at CLI level (for the CMP app only, so far)
there is a new parameter/option: keep_alive.
* 0 means HTTP connections are not kept open after
receiving a response, which is the default behavior for HTTP 1.0.
* 1 means that persistent connections are requested.
* 2 means that persistent connections are required, i.e.,
in case the server does not grant them an error occurs.
For the CMP app the default value is 1, which means preferring to keep
the connection open. For all other internal uses of the HTTP client
(fetching an OCSP response, a cert, or a CRL) it does not matter
because these operations just take one round trip.
If the client application requested or required a persistent connection
and this was granted by the server, it can keep the OSSL_HTTP_REQ_CTX *
as long as it wants to send further requests and OSSL_HTTP_is_alive()
returns nonzero,
else it should call OSSL_HTTP_REQ_CTX_free() or OSSL_HTTP_close().
In case the client application keeps the OSSL_HTTP_REQ_CTX *
but the connection then dies for any reason at the server side, it will
notice this obtaining an I/O error when trying to send the next request.
This requires extending the HTTP header parsing and
rearranging the high-level HTTP client API. In particular:
* Split the monolithic OSSL_HTTP_transfer() into OSSL_HTTP_open(),
OSSL_HTTP_set_request(), a lean OSSL_HTTP_transfer(), and OSSL_HTTP_close().
* Split the timeout functionality accordingly and improve default behavior.
* Extract part of OSSL_HTTP_REQ_CTX_new() to OSSL_HTTP_REQ_CTX_set_expected().
* Extend struct ossl_http_req_ctx_st accordingly.
Use the new feature for the CMP client, which requires extending
related transaction management of CMP client and test server.
Update the documentation and extend the tests accordingly.
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/15053)
2021-04-28 06:26:14 +08:00
|
|
|
/*-
|
|
|
|
* by default:
|
|
|
|
* no bio_update_fn (and consequently no arg)
|
|
|
|
* no ssl
|
|
|
|
* no proxy
|
|
|
|
* no timeout (blocking indefinitely)
|
|
|
|
* no expected content type
|
|
|
|
* max_resp_len = 100 KiB
|
|
|
|
*/
|
|
|
|
if (!OSSL_HTTP_REQ_CTX_set_request_line(rctx, 1 /* POST */,
|
|
|
|
NULL, NULL, path))
|
2021-01-18 19:53:55 +08:00
|
|
|
goto err;
|
HTTP: Implement persistent connections (keep-alive)
Both at API and at CLI level (for the CMP app only, so far)
there is a new parameter/option: keep_alive.
* 0 means HTTP connections are not kept open after
receiving a response, which is the default behavior for HTTP 1.0.
* 1 means that persistent connections are requested.
* 2 means that persistent connections are required, i.e.,
in case the server does not grant them an error occurs.
For the CMP app the default value is 1, which means preferring to keep
the connection open. For all other internal uses of the HTTP client
(fetching an OCSP response, a cert, or a CRL) it does not matter
because these operations just take one round trip.
If the client application requested or required a persistent connection
and this was granted by the server, it can keep the OSSL_HTTP_REQ_CTX *
as long as it wants to send further requests and OSSL_HTTP_is_alive()
returns nonzero,
else it should call OSSL_HTTP_REQ_CTX_free() or OSSL_HTTP_close().
In case the client application keeps the OSSL_HTTP_REQ_CTX *
but the connection then dies for any reason at the server side, it will
notice this obtaining an I/O error when trying to send the next request.
This requires extending the HTTP header parsing and
rearranging the high-level HTTP client API. In particular:
* Split the monolithic OSSL_HTTP_transfer() into OSSL_HTTP_open(),
OSSL_HTTP_set_request(), a lean OSSL_HTTP_transfer(), and OSSL_HTTP_close().
* Split the timeout functionality accordingly and improve default behavior.
* Extract part of OSSL_HTTP_REQ_CTX_new() to OSSL_HTTP_REQ_CTX_set_expected().
* Extend struct ossl_http_req_ctx_st accordingly.
Use the new feature for the CMP client, which requires extending
related transaction management of CMP client and test server.
Update the documentation and extend the tests accordingly.
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/15053)
2021-04-28 06:26:14 +08:00
|
|
|
/* by default, no extra headers */
|
2021-05-05 06:09:43 +08:00
|
|
|
if (!OSSL_HTTP_REQ_CTX_set_expected(rctx,
|
|
|
|
NULL /* content_type */, 1 /* asn1 */,
|
|
|
|
0 /* timeout */, 0 /* keep_alive */))
|
|
|
|
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),
|
HTTP: Implement persistent connections (keep-alive)
Both at API and at CLI level (for the CMP app only, so far)
there is a new parameter/option: keep_alive.
* 0 means HTTP connections are not kept open after
receiving a response, which is the default behavior for HTTP 1.0.
* 1 means that persistent connections are requested.
* 2 means that persistent connections are required, i.e.,
in case the server does not grant them an error occurs.
For the CMP app the default value is 1, which means preferring to keep
the connection open. For all other internal uses of the HTTP client
(fetching an OCSP response, a cert, or a CRL) it does not matter
because these operations just take one round trip.
If the client application requested or required a persistent connection
and this was granted by the server, it can keep the OSSL_HTTP_REQ_CTX *
as long as it wants to send further requests and OSSL_HTTP_is_alive()
returns nonzero,
else it should call OSSL_HTTP_REQ_CTX_free() or OSSL_HTTP_close().
In case the client application keeps the OSSL_HTTP_REQ_CTX *
but the connection then dies for any reason at the server side, it will
notice this obtaining an I/O error when trying to send the next request.
This requires extending the HTTP header parsing and
rearranging the high-level HTTP client API. In particular:
* Split the monolithic OSSL_HTTP_transfer() into OSSL_HTTP_open(),
OSSL_HTTP_set_request(), a lean OSSL_HTTP_transfer(), and OSSL_HTTP_close().
* Split the timeout functionality accordingly and improve default behavior.
* Extract part of OSSL_HTTP_REQ_CTX_new() to OSSL_HTTP_REQ_CTX_set_expected().
* Extend struct ossl_http_req_ctx_st accordingly.
Use the new feature for the CMP client, which requires extending
related transaction management of CMP client and test server.
Update the documentation and extend the tests accordingly.
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/15053)
2021-04-28 06:26:14 +08:00
|
|
|
(const 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
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
2021-05-05 06:09:43 +08:00
|
|
|
BIO *mem;
|
2019-10-31 06:39:35 +08:00
|
|
|
|
HTTP: Implement persistent connections (keep-alive)
Both at API and at CLI level (for the CMP app only, so far)
there is a new parameter/option: keep_alive.
* 0 means HTTP connections are not kept open after
receiving a response, which is the default behavior for HTTP 1.0.
* 1 means that persistent connections are requested.
* 2 means that persistent connections are required, i.e.,
in case the server does not grant them an error occurs.
For the CMP app the default value is 1, which means preferring to keep
the connection open. For all other internal uses of the HTTP client
(fetching an OCSP response, a cert, or a CRL) it does not matter
because these operations just take one round trip.
If the client application requested or required a persistent connection
and this was granted by the server, it can keep the OSSL_HTTP_REQ_CTX *
as long as it wants to send further requests and OSSL_HTTP_is_alive()
returns nonzero,
else it should call OSSL_HTTP_REQ_CTX_free() or OSSL_HTTP_close().
In case the client application keeps the OSSL_HTTP_REQ_CTX *
but the connection then dies for any reason at the server side, it will
notice this obtaining an I/O error when trying to send the next request.
This requires extending the HTTP header parsing and
rearranging the high-level HTTP client API. In particular:
* Split the monolithic OSSL_HTTP_transfer() into OSSL_HTTP_open(),
OSSL_HTTP_set_request(), a lean OSSL_HTTP_transfer(), and OSSL_HTTP_close().
* Split the timeout functionality accordingly and improve default behavior.
* Extract part of OSSL_HTTP_REQ_CTX_new() to OSSL_HTTP_REQ_CTX_set_expected().
* Extend struct ossl_http_req_ctx_st accordingly.
Use the new feature for the CMP client, which requires extending
related transaction management of CMP client and test server.
Update the documentation and extend the tests accordingly.
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/15053)
2021-04-28 06:26:14 +08:00
|
|
|
ctx = OCSP_sendreq_new(b, path, req, 0 /* default buf_size */);
|
2019-10-31 06:39:35 +08:00
|
|
|
if (ctx == NULL)
|
|
|
|
return NULL;
|
2021-05-05 06:09:43 +08:00
|
|
|
mem = OSSL_HTTP_REQ_CTX_exchange(ctx);
|
2021-10-22 15:38:18 +08:00
|
|
|
/* ASN1_item_d2i_bio handles NULL bio gracefully */
|
|
|
|
resp = (OCSP_RESPONSE *)ASN1_item_d2i_bio(ASN1_ITEM_rptr(OCSP_RESPONSE),
|
|
|
|
mem, NULL);
|
2019-10-31 06:39:35 +08:00
|
|
|
|
2020-12-26 23:21:41 +08:00
|
|
|
OSSL_HTTP_REQ_CTX_free(ctx);
|
2021-03-01 21:06:32 +08:00
|
|
|
return resp;
|
2019-10-31 06:39:35 +08:00
|
|
|
}
|
|
|
|
#endif /* !defined(OPENSSL_NO_OCSP) */
|