2019-10-31 06:39:35 +08:00
|
|
|
/*
|
2021-01-28 20:54:57 +08:00
|
|
|
* Copyright 2020-2021 The OpenSSL Project Authors. All Rights Reserved.
|
2019-10-31 06:39:35 +08:00
|
|
|
* Copyright Siemens AG 2020
|
|
|
|
*
|
|
|
|
* 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/http.h>
|
|
|
|
#include <openssl/pem.h>
|
|
|
|
#include <openssl/x509v3.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "testutil.h"
|
|
|
|
|
|
|
|
static const ASN1_ITEM *x509_it = NULL;
|
|
|
|
static X509 *x509 = 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
|
|
|
#define RPATH "/path/result.crt"
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
BIO *out;
|
|
|
|
char version;
|
|
|
|
int keep_alive;
|
|
|
|
} server_args;
|
|
|
|
|
|
|
|
/*-
|
|
|
|
* Pretty trivial HTTP mock server:
|
|
|
|
* For POST, copy request headers+body from mem BIO 'in' as response to 'out'.
|
|
|
|
* For GET, redirect to RPATH, else respond with 'rsp' of ASN1 type 'it'.
|
|
|
|
* Respond with HTTP version 1.'version' and 'keep_alive' (unless implicit).
|
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
|
|
|
static int mock_http_server(BIO *in, BIO *out, char version, int keep_alive,
|
2019-10-31 06:39:35 +08:00
|
|
|
ASN1_VALUE *rsp, const ASN1_ITEM *it)
|
|
|
|
{
|
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 char *req, *path;
|
2019-10-31 06:39:35 +08:00
|
|
|
long count = BIO_get_mem_data(in, (unsigned char **)&req);
|
|
|
|
const char *hdr = (char *)req;
|
|
|
|
int is_get = count >= 4 && strncmp(hdr, "GET ", 4) == 0;
|
|
|
|
int len;
|
|
|
|
|
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
|
|
|
/* first line should contain "<GET or POST> <path> HTTP/1.x" */
|
2019-10-31 06:39:35 +08:00
|
|
|
if (is_get)
|
|
|
|
hdr += 4;
|
|
|
|
else if (TEST_true(count >= 5 && strncmp(hdr, "POST ", 5) == 0))
|
|
|
|
hdr += 5;
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
|
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
|
|
|
path = hdr;
|
|
|
|
hdr = strchr(hdr, ' ');
|
|
|
|
if (hdr == NULL)
|
2019-10-31 06:39:35 +08:00
|
|
|
return 0;
|
|
|
|
len = strlen("HTTP/1.");
|
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
|
|
|
if (!TEST_strn_eq(++hdr, "HTTP/1.", len))
|
2019-10-31 06:39:35 +08:00
|
|
|
return 0;
|
|
|
|
hdr += len;
|
|
|
|
/* check for HTTP version 1.0 .. 1.1 */
|
|
|
|
if (!TEST_char_le('0', *hdr) || !TEST_char_le(*hdr++, '1'))
|
|
|
|
return 0;
|
|
|
|
if (!TEST_char_eq(*hdr++, '\r') || !TEST_char_eq(*hdr++, '\n'))
|
|
|
|
return 0;
|
|
|
|
count -= (hdr - req);
|
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
|
|
|
if (count < 0 || out == NULL)
|
2019-10-31 06:39:35 +08:00
|
|
|
return 0;
|
|
|
|
|
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
|
|
|
if (strncmp(path, RPATH, strlen(RPATH)) != 0) {
|
|
|
|
if (!is_get)
|
|
|
|
return 0;
|
|
|
|
return BIO_printf(out, "HTTP/1.%c 301 Moved Permanently\r\n"
|
|
|
|
"Location: %s\r\n\r\n",
|
|
|
|
version, RPATH) > 0; /* same server */
|
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
|
|
|
if (BIO_printf(out, "HTTP/1.%c 200 OK\r\n", version) <= 0)
|
2019-10-31 06:39:35 +08:00
|
|
|
return 0;
|
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
|
|
|
if ((version == '0') == keep_alive) /* otherwise, default */
|
|
|
|
if (BIO_printf(out, "Connection: %s\r\n",
|
|
|
|
version == '0' ? "keep-alive" : "close") <= 0)
|
|
|
|
return 0;
|
2019-10-31 06:39:35 +08:00
|
|
|
if (is_get) { /* construct new header and body */
|
|
|
|
if ((len = ASN1_item_i2d(rsp, NULL, it)) <= 0)
|
|
|
|
return 0;
|
|
|
|
if (BIO_printf(out, "Content-Type: application/x-x509-ca-cert\r\n"
|
|
|
|
"Content-Length: %d\r\n\r\n", len) <= 0)
|
|
|
|
return 0;
|
|
|
|
return ASN1_item_i2d_bio(it, out, rsp);
|
|
|
|
} else {
|
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
|
|
|
len = strlen("Connection: ");
|
|
|
|
if (strncmp(hdr, "Connection: ", len) == 0) {
|
|
|
|
/* skip req Connection header */
|
|
|
|
hdr = strstr(hdr + len, "\r\n");
|
|
|
|
if (hdr == NULL)
|
|
|
|
return 0;
|
|
|
|
hdr += 2;
|
|
|
|
}
|
|
|
|
/* echo remaining request header and body */
|
|
|
|
return BIO_write(out, hdr, count) == count;
|
2019-10-31 06:39:35 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static long http_bio_cb_ex(BIO *bio, int oper, const char *argp, size_t len,
|
|
|
|
int cmd, long argl, int ret, size_t *processed)
|
|
|
|
{
|
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
|
|
|
server_args *args = (server_args *)BIO_get_callback_arg(bio);
|
2019-10-31 06:39:35 +08:00
|
|
|
|
|
|
|
if (oper == (BIO_CB_CTRL | BIO_CB_RETURN) && cmd == BIO_CTRL_FLUSH)
|
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
|
|
|
ret = mock_http_server(bio, args->out, args->version, args->keep_alive,
|
2019-10-31 06:39:35 +08:00
|
|
|
(ASN1_VALUE *)x509, x509_it);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int test_http_x509(int do_get)
|
|
|
|
{
|
|
|
|
X509 *rcert = NULL;
|
|
|
|
BIO *wbio = BIO_new(BIO_s_mem());
|
|
|
|
BIO *rbio = BIO_new(BIO_s_mem());
|
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
|
|
|
server_args mock_args = { NULL, '0', 0 };
|
2021-05-05 06:09:43 +08:00
|
|
|
BIO *rsp, *req = ASN1_item_i2d_mem_bio(x509_it, (ASN1_VALUE *)x509);
|
2019-10-31 06:39:35 +08:00
|
|
|
STACK_OF(CONF_VALUE) *headers = NULL;
|
2021-05-05 06:09:43 +08:00
|
|
|
const char content_type[] = "application/x-x509-ca-cert";
|
2019-10-31 06:39:35 +08:00
|
|
|
int res = 0;
|
|
|
|
|
2021-05-05 06:09:43 +08:00
|
|
|
if (wbio == NULL || rbio == NULL || req == NULL)
|
2019-10-31 06:39:35 +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
|
|
|
mock_args.out = rbio;
|
2019-10-31 06:39:35 +08:00
|
|
|
BIO_set_callback_ex(wbio, http_bio_cb_ex);
|
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
|
|
|
BIO_set_callback_arg(wbio, (char *)&mock_args);
|
2019-10-31 06:39:35 +08:00
|
|
|
|
2021-05-05 06:09:43 +08:00
|
|
|
rsp = do_get ?
|
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
|
|
|
OSSL_HTTP_get("/will-be-redirected",
|
2021-05-05 06:09:43 +08:00
|
|
|
NULL /* proxy */, NULL /* no_proxy */,
|
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
|
|
|
wbio, rbio, NULL /* bio_update_fn */, NULL /* arg */,
|
2021-05-05 06:09:43 +08:00
|
|
|
0 /* buf_size */, headers, content_type,
|
|
|
|
1 /* expect_asn1 */,
|
2021-05-11 21:45:22 +08:00
|
|
|
OSSL_HTTP_DEFAULT_MAX_RESP_LEN, 0 /* timeout */)
|
2021-05-05 06:09:43 +08:00
|
|
|
: OSSL_HTTP_transfer(NULL, NULL /* host */, NULL /* port */, RPATH,
|
|
|
|
0 /* use_ssl */,NULL /* proxy */, NULL /* no_pr */,
|
|
|
|
wbio, rbio, NULL /* bio_fn */, NULL /* arg */,
|
|
|
|
0 /* buf_size */, headers, content_type,
|
|
|
|
req, content_type, 1 /* expect_asn1 */,
|
2021-05-11 21:45:22 +08:00
|
|
|
OSSL_HTTP_DEFAULT_MAX_RESP_LEN, 0 /* timeout */,
|
2021-05-05 06:09:43 +08:00
|
|
|
0 /* keep_alive */);
|
|
|
|
rcert = d2i_X509_bio(rsp, NULL);
|
|
|
|
BIO_free(rsp);
|
2019-10-31 06:39:35 +08:00
|
|
|
res = TEST_ptr(rcert) && TEST_int_eq(X509_cmp(x509, rcert), 0);
|
|
|
|
|
|
|
|
err:
|
|
|
|
X509_free(rcert);
|
2021-05-05 06:09:43 +08:00
|
|
|
BIO_free(req);
|
2019-10-31 06:39:35 +08:00
|
|
|
BIO_free(wbio);
|
|
|
|
BIO_free(rbio);
|
|
|
|
sk_CONF_VALUE_pop_free(headers, X509V3_conf_free);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
static int test_http_keep_alive(char version, int keep_alive, int kept_alive)
|
|
|
|
{
|
|
|
|
BIO *wbio = BIO_new(BIO_s_mem());
|
|
|
|
BIO *rbio = BIO_new(BIO_s_mem());
|
|
|
|
BIO *rsp;
|
|
|
|
server_args mock_args = { NULL, '0', 0 };
|
|
|
|
const char *const content_type = "application/x-x509-ca-cert";
|
|
|
|
OSSL_HTTP_REQ_CTX *rctx = NULL;
|
|
|
|
int i, res = 0;
|
|
|
|
|
|
|
|
if (wbio == NULL || rbio == NULL)
|
|
|
|
goto err;
|
|
|
|
mock_args.out = rbio;
|
|
|
|
mock_args.version = version;
|
|
|
|
mock_args.keep_alive = kept_alive;
|
|
|
|
BIO_set_callback_ex(wbio, http_bio_cb_ex);
|
|
|
|
BIO_set_callback_arg(wbio, (char *)&mock_args);
|
|
|
|
|
|
|
|
for (res = 1, i = 1; res && i <= 2; i++) {
|
|
|
|
rsp = OSSL_HTTP_transfer(&rctx, NULL /* server */, NULL /* port */,
|
|
|
|
RPATH, 0 /* use_ssl */,
|
|
|
|
NULL /* proxy */, NULL /* no_proxy */,
|
|
|
|
wbio, rbio, NULL /* bio_update_fn */, NULL,
|
|
|
|
0 /* buf_size */, NULL /* headers */,
|
|
|
|
NULL /* content_type */, NULL /* req => GET */,
|
|
|
|
content_type, 0 /* ASN.1 not expected */,
|
|
|
|
0 /* max_resp_len */, 0 /* timeout */,
|
|
|
|
keep_alive);
|
|
|
|
if (keep_alive == 2 && kept_alive == 0)
|
|
|
|
res = res && TEST_ptr_null(rsp)
|
|
|
|
&& TEST_int_eq(OSSL_HTTP_is_alive(rctx), 0);
|
|
|
|
else
|
|
|
|
res = res && TEST_ptr(rsp)
|
|
|
|
&& TEST_int_eq(OSSL_HTTP_is_alive(rctx), keep_alive > 0);
|
|
|
|
BIO_free(rsp);
|
|
|
|
(void)BIO_reset(rbio); /* discard response contents */
|
|
|
|
keep_alive = 0;
|
|
|
|
}
|
|
|
|
OSSL_HTTP_close(rctx, res);
|
|
|
|
|
|
|
|
err:
|
|
|
|
BIO_free(wbio);
|
|
|
|
BIO_free(rbio);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2021-01-29 05:10:47 +08:00
|
|
|
static int test_http_url_ok(const char *url, int exp_ssl, const char *exp_host,
|
|
|
|
const char *exp_port, const char *exp_path)
|
2020-09-03 19:32:56 +08:00
|
|
|
{
|
2021-01-29 05:10:47 +08:00
|
|
|
char *user, *host, *port, *path, *query, *frag;
|
|
|
|
int exp_num, num, ssl;
|
2020-09-03 19:32:56 +08:00
|
|
|
int res;
|
|
|
|
|
2021-03-08 14:58:04 +08:00
|
|
|
if (!TEST_int_eq(sscanf(exp_port, "%d", &exp_num), 1))
|
|
|
|
return 0;
|
2021-01-29 05:10:47 +08:00
|
|
|
res = TEST_true(OSSL_HTTP_parse_url(url, &ssl, &user, &host, &port, &num,
|
|
|
|
&path, &query, &frag))
|
2020-09-03 19:32:56 +08:00
|
|
|
&& TEST_str_eq(host, exp_host)
|
2021-01-29 05:10:47 +08:00
|
|
|
&& TEST_str_eq(port, exp_port)
|
|
|
|
&& TEST_int_eq(num, exp_num)
|
|
|
|
&& TEST_str_eq(path, exp_path)
|
2020-09-03 19:32:56 +08:00
|
|
|
&& TEST_int_eq(ssl, exp_ssl);
|
2021-01-29 05:10:47 +08:00
|
|
|
if (res && *user != '\0')
|
|
|
|
res = TEST_str_eq(user, "user:pass");
|
|
|
|
if (res && *frag != '\0')
|
|
|
|
res = TEST_str_eq(frag, "fr");
|
|
|
|
if (res && *query != '\0')
|
|
|
|
res = TEST_str_eq(query, "q");
|
|
|
|
OPENSSL_free(user);
|
2020-09-03 19:32:56 +08:00
|
|
|
OPENSSL_free(host);
|
|
|
|
OPENSSL_free(port);
|
|
|
|
OPENSSL_free(path);
|
2021-01-29 05:10:47 +08:00
|
|
|
OPENSSL_free(query);
|
|
|
|
OPENSSL_free(frag);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int test_http_url_path_query_ok(const char *url, const char *exp_path_qu)
|
|
|
|
{
|
|
|
|
char *host, *path;
|
|
|
|
int res;
|
|
|
|
|
|
|
|
res = TEST_true(OSSL_HTTP_parse_url(url, NULL, NULL, &host, NULL, NULL,
|
|
|
|
&path, NULL, NULL))
|
|
|
|
&& TEST_str_eq(host, "host")
|
|
|
|
&& TEST_str_eq(path, exp_path_qu);
|
|
|
|
OPENSSL_free(host);
|
|
|
|
OPENSSL_free(path);
|
2020-09-03 19:32:56 +08:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int test_http_url_dns(void)
|
|
|
|
{
|
2021-01-29 05:10:47 +08:00
|
|
|
return test_http_url_ok("host:65535/path", 0, "host", "65535", "/path");
|
|
|
|
}
|
|
|
|
|
|
|
|
static int test_http_url_path_query(void)
|
|
|
|
{
|
|
|
|
return test_http_url_path_query_ok("http://usr@host:1/p?q=x#frag", "/p?q=x")
|
|
|
|
&& test_http_url_path_query_ok("http://host?query#frag", "/?query")
|
|
|
|
&& test_http_url_path_query_ok("http://host:9999#frag", "/");
|
|
|
|
}
|
|
|
|
|
|
|
|
static int test_http_url_userinfo_query_fragment(void)
|
|
|
|
{
|
|
|
|
return test_http_url_ok("user:pass@host/p?q#fr", 0, "host", "80", "/p");
|
2020-09-03 19:32:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int test_http_url_ipv4(void)
|
|
|
|
{
|
2021-01-29 05:10:47 +08:00
|
|
|
return test_http_url_ok("https://1.2.3.4/p/q", 1, "1.2.3.4", "443", "/p/q");
|
2020-09-03 19:32:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int test_http_url_ipv6(void)
|
|
|
|
{
|
2021-03-08 16:59:35 +08:00
|
|
|
return test_http_url_ok("http://[FF01::101]:6", 0, "[FF01::101]", "6", "/");
|
2020-09-03 19:32:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int test_http_url_invalid(const char *url)
|
|
|
|
{
|
|
|
|
char *host = "1", *port = "1", *path = "1";
|
|
|
|
int num = 1, ssl = 1;
|
|
|
|
int res;
|
|
|
|
|
2021-01-29 05:10:47 +08:00
|
|
|
res = TEST_false(OSSL_HTTP_parse_url(url, &ssl, NULL, &host, &port, &num,
|
|
|
|
&path, NULL, NULL))
|
2020-09-03 19:32:56 +08:00
|
|
|
&& TEST_ptr_null(host)
|
|
|
|
&& TEST_ptr_null(port)
|
|
|
|
&& TEST_ptr_null(path);
|
|
|
|
if (!res) {
|
|
|
|
OPENSSL_free(host);
|
|
|
|
OPENSSL_free(port);
|
|
|
|
OPENSSL_free(path);
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int test_http_url_invalid_prefix(void)
|
|
|
|
{
|
|
|
|
return test_http_url_invalid("htttps://1.2.3.4:65535/pkix");
|
|
|
|
}
|
|
|
|
|
|
|
|
static int test_http_url_invalid_port(void)
|
|
|
|
{
|
|
|
|
return test_http_url_invalid("https://1.2.3.4:65536/pkix");
|
|
|
|
}
|
|
|
|
|
|
|
|
static int test_http_url_invalid_path(void)
|
|
|
|
{
|
|
|
|
return test_http_url_invalid("https://[FF01::101]pkix");
|
|
|
|
}
|
|
|
|
|
2019-10-31 06:39:35 +08:00
|
|
|
static int test_http_get_x509(void)
|
|
|
|
{
|
|
|
|
return test_http_x509(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int test_http_post_x509(void)
|
|
|
|
{
|
|
|
|
return test_http_x509(0);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
static int test_http_keep_alive_0_no_no(void)
|
|
|
|
{
|
|
|
|
return test_http_keep_alive('0', 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int test_http_keep_alive_1_no_no(void)
|
|
|
|
{
|
|
|
|
return test_http_keep_alive('1', 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int test_http_keep_alive_0_prefer_yes(void)
|
|
|
|
{
|
|
|
|
return test_http_keep_alive('0', 1, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int test_http_keep_alive_1_prefer_yes(void)
|
|
|
|
{
|
|
|
|
return test_http_keep_alive('1', 1, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int test_http_keep_alive_0_require_yes(void)
|
|
|
|
{
|
|
|
|
return test_http_keep_alive('0', 2, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int test_http_keep_alive_1_require_yes(void)
|
|
|
|
{
|
|
|
|
return test_http_keep_alive('1', 2, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int test_http_keep_alive_0_require_no(void)
|
|
|
|
{
|
|
|
|
return test_http_keep_alive('0', 2, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int test_http_keep_alive_1_require_no(void)
|
|
|
|
{
|
|
|
|
return test_http_keep_alive('1', 2, 0);
|
|
|
|
}
|
|
|
|
|
2019-10-31 06:39:35 +08:00
|
|
|
void cleanup_tests(void)
|
|
|
|
{
|
|
|
|
X509_free(x509);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
OPT_TEST_DECLARE_USAGE("cert.pem\n")
|
|
|
|
|
2019-10-31 06:39:35 +08:00
|
|
|
int setup_tests(void)
|
|
|
|
{
|
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
|
|
|
if (!test_skip_common_options())
|
2019-10-31 06:39:35 +08:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
x509_it = ASN1_ITEM_rptr(X509);
|
2020-12-29 02:45:01 +08:00
|
|
|
if (!TEST_ptr((x509 = load_cert_pem(test_get_argument(0), 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
|
|
|
return 0;
|
2019-10-31 06:39:35 +08:00
|
|
|
|
2020-09-03 19:32:56 +08:00
|
|
|
ADD_TEST(test_http_url_dns);
|
2021-01-29 05:10:47 +08:00
|
|
|
ADD_TEST(test_http_url_path_query);
|
|
|
|
ADD_TEST(test_http_url_userinfo_query_fragment);
|
2020-09-03 19:32:56 +08:00
|
|
|
ADD_TEST(test_http_url_ipv4);
|
|
|
|
ADD_TEST(test_http_url_ipv6);
|
|
|
|
ADD_TEST(test_http_url_invalid_prefix);
|
|
|
|
ADD_TEST(test_http_url_invalid_port);
|
|
|
|
ADD_TEST(test_http_url_invalid_path);
|
2019-10-31 06:39:35 +08:00
|
|
|
ADD_TEST(test_http_get_x509);
|
|
|
|
ADD_TEST(test_http_post_x509);
|
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
|
|
|
ADD_TEST(test_http_keep_alive_0_no_no);
|
|
|
|
ADD_TEST(test_http_keep_alive_1_no_no);
|
|
|
|
ADD_TEST(test_http_keep_alive_0_prefer_yes);
|
|
|
|
ADD_TEST(test_http_keep_alive_1_prefer_yes);
|
|
|
|
ADD_TEST(test_http_keep_alive_0_require_yes);
|
|
|
|
ADD_TEST(test_http_keep_alive_1_require_yes);
|
|
|
|
ADD_TEST(test_http_keep_alive_0_require_no);
|
|
|
|
ADD_TEST(test_http_keep_alive_1_require_no);
|
2019-10-31 06:39:35 +08:00
|
|
|
return 1;
|
|
|
|
}
|