diff options
author | Matt Caswell <matt@openssl.org> | 2022-12-06 16:44:09 +0000 |
---|---|---|
committer | Hugo Landau <hlandau@openssl.org> | 2023-02-22 05:34:04 +0000 |
commit | f10e5885f01582c449eff8df70b61c916d9224cf (patch) | |
tree | 8aab3996dc831bdf9a5d592dc0c2ceaa73858d5d /test/helpers | |
parent | 6d1f6933595ea66c2e8367fef01e2824b4f3ce6b (diff) | |
download | openssl-new-f10e5885f01582c449eff8df70b61c916d9224cf.tar.gz |
Add a test for a server that doesn't provide transport params
Check that we fail if the server has failed to provide transport params.
Reviewed-by: Hugo Landau <hlandau@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/20030)
Diffstat (limited to 'test/helpers')
-rw-r--r-- | test/helpers/quictestlib.c | 43 | ||||
-rw-r--r-- | test/helpers/quictestlib.h | 9 |
2 files changed, 37 insertions, 15 deletions
diff --git a/test/helpers/quictestlib.c b/test/helpers/quictestlib.c index 871a0e208f..b9c437ba57 100644 --- a/test/helpers/quictestlib.c +++ b/test/helpers/quictestlib.c @@ -12,6 +12,7 @@ #include "../testutil.h" #include "internal/quic_wire_pkt.h" #include "internal/quic_record_tx.h" +#include "internal/quic_error.h" #include "internal/packet.h" #define GROWTH_ALLOWANCE 1024 @@ -156,13 +157,13 @@ int qtest_create_quic_connection(QUIC_TSERVER *qtserv, SSL *clientssl) * the communications and don't expect network delays. This shouldn't * be done in a real application. */ - if (!clienterr) + if (!clienterr && retc <= 0) SSL_tick(clientssl); - if (!servererr) { + if (!servererr && rets <= 0) { ossl_quic_tserver_tick(qtserv); servererr = ossl_quic_tserver_is_term_any(qtserv, NULL); - if (!servererr && !rets) - rets = ossl_quic_tserver_is_connected(qtserv); + if (!servererr) + rets = ossl_quic_tserver_is_handshake_complete(qtserv); } if (clienterr && servererr) @@ -172,13 +173,32 @@ int qtest_create_quic_connection(QUIC_TSERVER *qtserv, SSL *clientssl) TEST_info("No progress made"); goto err; } - } while (retc <=0 || rets <= 0); + } while ((retc <= 0 && !clienterr) || (rets <= 0 && !servererr)); - ret = 1; + if (!clienterr && !servererr) + ret = 1; err: return ret; } +int qtest_check_server_protocol_err(QUIC_TSERVER *qtserv) +{ + QUIC_TERMINATE_CAUSE cause; + + ossl_quic_tserver_tick(qtserv); + + /* + * Check that the server has received the protocol violation error + * connection close from the client + */ + if (!TEST_true(ossl_quic_tserver_is_term_any(qtserv, &cause)) + || !TEST_true(cause.remote) + || !TEST_uint64_t_eq(cause.error_code, QUIC_ERR_PROTOCOL_VIOLATION)) + return 0; + + return 1; +} + void ossl_quic_fault_free(OSSL_QUIC_FAULT *fault) { if (fault == NULL) @@ -438,12 +458,13 @@ int ossl_quic_fault_resize_message(OSSL_QUIC_FAULT *fault, size_t newlen) int ossl_quic_fault_delete_extension(OSSL_QUIC_FAULT *fault, unsigned int exttype, unsigned char *ext, - size_t *extlen, size_t *msglen) + size_t *extlen) { PACKET pkt, sub, subext; unsigned int type; const unsigned char *start, *end; size_t newlen; + size_t msglen = fault->handbuflen; if (!PACKET_buf_init(&pkt, ext, *extlen)) return 0; @@ -455,7 +476,7 @@ int ossl_quic_fault_delete_extension(OSSL_QUIC_FAULT *fault, do { start = PACKET_data(&sub); if (!PACKET_get_net_2(&sub, &type) - || !PACKET_as_length_prefixed_2(&sub, &subext)) + || !PACKET_get_length_prefixed_2(&sub, &subext)) return 0; } while (type != exttype); @@ -489,8 +510,10 @@ int ossl_quic_fault_delete_extension(OSSL_QUIC_FAULT *fault, *extlen = newlen + 2; /* We can now resize the message */ - *msglen -= (end - start); - if (!ossl_quic_fault_resize_message(fault, *msglen)) + if ((size_t)(end - start) + SSL3_HM_HEADER_LENGTH > msglen) + return 0; /* Should not happen */ + msglen -= (end - start) + SSL3_HM_HEADER_LENGTH; + if (!ossl_quic_fault_resize_message(fault, msglen)) return 0; return 1; diff --git a/test/helpers/quictestlib.h b/test/helpers/quictestlib.h index 430d4f71c3..d5fe58900a 100644 --- a/test/helpers/quictestlib.h +++ b/test/helpers/quictestlib.h @@ -22,6 +22,8 @@ int qtest_create_quic_objects(SSL_CTX *clientctx, char *certfile, char *keyfile, OSSL_QUIC_FAULT **fault); int qtest_create_quic_connection(QUIC_TSERVER *qtserv, SSL *clientssl); +int qtest_check_server_protocol_err(QUIC_TSERVER *qtserv); + void ossl_quic_fault_free(OSSL_QUIC_FAULT *fault); typedef int (*ossl_quic_fault_on_packet_plain_cb)(OSSL_QUIC_FAULT *fault, @@ -81,11 +83,8 @@ int ossl_quic_fault_resize_message(OSSL_QUIC_FAULT *fault, size_t newlen); * Delete an extension from an extension block. |exttype| is the type of the * extension to be deleted. |ext| points to the extension block. On entry * |*extlen| contains the length of the extension block. It is updated with the - * new length on exit. On entry |*msglen| is the length of the handshake message - * (without the header). On exit it is updated with the new message length. - * ossl_quic_fault_resize_handshake() is called automatically so there is no - * need to call it explicitly. + * new length on exit. */ int ossl_quic_fault_delete_extension(OSSL_QUIC_FAULT *fault, unsigned int exttype, unsigned char *ext, - size_t *extlen, size_t *msglen); + size_t *extlen); |