diff options
author | Tomas Mraz <tomas@openssl.org> | 2022-05-13 16:45:07 +0200 |
---|---|---|
committer | Pauli <pauli@openssl.org> | 2022-06-03 12:07:18 +1000 |
commit | e44795bd5db081260ef05c7be6fd17c080ed9437 (patch) | |
tree | 77c7073c3ae0edc4b704a9521ee64c9f51320678 | |
parent | 99e1cc7bcae2e3707913881d7108c92b7a9bf7a1 (diff) | |
download | openssl-new-e44795bd5db081260ef05c7be6fd17c080ed9437.tar.gz |
First working empty protocol test
Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/18307)
-rw-r--r-- | ssl/quic/quic_impl.c | 60 | ||||
-rw-r--r-- | ssl/quic/quic_local.h | 12 | ||||
-rw-r--r-- | test/build.info | 8 | ||||
-rw-r--r-- | test/quicapitest.c | 128 | ||||
-rw-r--r-- | test/recipes/75-test_quicapi.t | 37 |
5 files changed, 227 insertions, 18 deletions
diff --git a/ssl/quic/quic_impl.c b/ssl/quic/quic_impl.c index bc10a4b615..1c673d23b6 100644 --- a/ssl/quic/quic_impl.c +++ b/ssl/quic/quic_impl.c @@ -11,7 +11,7 @@ #include <openssl/objects.h> #include "quic_local.h" -__owur int ossl_quic_new(SSL *s) +int ossl_quic_new(SSL *s) { return s->method->ssl_clear(s); } @@ -26,57 +26,89 @@ int ossl_quic_clear(SSL *s) return 1; } -__owur int ossl_quic_accept(SSL *s) +int ossl_quic_accept(SSL *s) { return 1; } -__owur int ossl_quic_connect(SSL *s) +int ossl_quic_connect(SSL *s) { return 1; } -__owur int ossl_quic_read(SSL *s, void *buf, size_t len, size_t *readbytes) +int ossl_quic_read(SSL *s, void *buf, size_t len, size_t *readbytes) { - return 1; + BIO *rbio = SSL_get_rbio(s); + + if (rbio == NULL) + return 0; + + return BIO_read_ex(rbio, buf, len, readbytes); } -__owur int ossl_quic_peek(SSL *s, void *buf, size_t len, size_t *readbytes) +int ossl_quic_peek(SSL *s, void *buf, size_t len, size_t *readbytes) { return 1; } -__owur int ossl_quic_write(SSL *s, const void *buf, size_t len, size_t *written) +int ossl_quic_write(SSL *s, const void *buf, size_t len, size_t *written) { - return 1; + BIO *wbio = SSL_get_wbio(s); + + if (wbio == NULL) + return 0; + + return BIO_write_ex(wbio, buf, len, written); } -__owur int ossl_quic_shutdown(SSL *s) +int ossl_quic_shutdown(SSL *s) { return 1; } -__owur long ossl_quic_ctrl(SSL *s, int cmd, long larg, void *parg) +long ossl_quic_ctrl(SSL *s, int cmd, long larg, void *parg) { return 0; } -__owur long ossl_quic_ctx_ctrl(SSL_CTX *s, int cmd, long larg, void *parg) +long ossl_quic_ctx_ctrl(SSL_CTX *s, int cmd, long larg, void *parg) { return 0; } -__owur long ossl_quic_callback_ctrl(SSL *s, int cmd, void (*fp) (void)) +long ossl_quic_callback_ctrl(SSL *s, int cmd, void (*fp) (void)) { return 0; } -__owur long ossl_quic_ctx_callback_ctrl(SSL_CTX *s, int cmd, void (*fp) (void)) +long ossl_quic_ctx_callback_ctrl(SSL_CTX *s, int cmd, void (*fp) (void)) { return 0; } -__owur size_t ossl_quic_pending(const SSL *s) +size_t ossl_quic_pending(const SSL *s) { return 0; } + +long ossl_quic_default_timeout(void) +{ + return 0; +} + +int ossl_quic_num_ciphers(void) +{ + return 1; +} + +const SSL_CIPHER *ossl_quic_get_cipher(unsigned int u) +{ + static const SSL_CIPHER ciph = { 0 }; + + return &ciph; +} + +int ossl_quic_renegotiate_check(SSL *ssl, int initok) +{ + return 1; +} diff --git a/ssl/quic/quic_local.h b/ssl/quic/quic_local.h index ffb617184f..3b738e541b 100644 --- a/ssl/quic/quic_local.h +++ b/ssl/quic/quic_local.h @@ -33,7 +33,7 @@ const SSL_METHOD *func_name(void) \ ossl_quic_write, \ ossl_quic_shutdown, \ NULL /* renegotiate */, \ - NULL /* renegotiate_check */, \ + ossl_quic_renegotiate_check, \ NULL /* read_bytes */, \ NULL /* write_bytes */, \ NULL /* dispatch_alert */, \ @@ -42,9 +42,9 @@ const SSL_METHOD *func_name(void) \ NULL /* get_cipher_by_char */, \ NULL /* put_cipher_by_char */, \ ossl_quic_pending, \ - NULL /* num_ciphers */, \ - NULL /* get_cipher */, \ - NULL /* default_timeout */, \ + ossl_quic_num_ciphers, \ + ossl_quic_get_cipher, \ + ossl_quic_default_timeout, \ &enc_data, \ ssl_undefined_void_function, \ ossl_quic_callback_ctrl, \ @@ -67,5 +67,9 @@ __owur long ossl_quic_ctx_ctrl(SSL_CTX *s, int cmd, long larg, void *parg); __owur long ossl_quic_callback_ctrl(SSL *s, int cmd, void (*fp) (void)); __owur long ossl_quic_ctx_callback_ctrl(SSL_CTX *s, int cmd, void (*fp) (void)); __owur size_t ossl_quic_pending(const SSL *s); +__owur long ossl_quic_default_timeout(void); +__owur int ossl_quic_num_ciphers(void); +__owur const SSL_CIPHER *ossl_quic_get_cipher(unsigned int u); +int ossl_quic_renegotiate_check(SSL *ssl, int initok); #endif diff --git a/test/build.info b/test/build.info index fd72890539..0f7420825e 100644 --- a/test/build.info +++ b/test/build.info @@ -934,6 +934,14 @@ ENDIF INCLUDE[build_wincrypt_test]=../include DEPEND[build_wincrypt_test]=../libssl ../libcrypto + IF[{- !$disabled{'quic'} -}] + PROGRAMS{noinst}=quicapitest + ENDIF + + SOURCE[quicapitest]=quicapitest.c helpers/ssltestlib.c + INCLUDE[quicapitest]=../include ../apps/include + DEPEND[quicapitest]=../libcrypto ../libssl libtestutil.a + {- use File::Spec::Functions; use File::Basename; diff --git a/test/quicapitest.c b/test/quicapitest.c new file mode 100644 index 0000000000..1b647768d4 --- /dev/null +++ b/test/quicapitest.c @@ -0,0 +1,128 @@ +/* + * Copyright 2022 The OpenSSL Project Authors. All Rights Reserved. + * + * 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 <stdio.h> +#include <string.h> + +#include <openssl/opensslconf.h> +#include <openssl/quic.h> + +#include "helpers/ssltestlib.h" +#include "testutil.h" +#include "testutil/output.h" + +static OSSL_LIB_CTX *libctx = NULL; +static OSSL_PROVIDER *defctxnull = NULL; + +static int is_fips = 0; + +/* + * Test that we read what we've written. + */ +static int test_quic_write_read(void) +{ + SSL_CTX *cctx = NULL, *sctx = NULL; + SSL *clientquic = NULL, *serverquic = NULL; + int j, ret = 0; + char buf[20]; + static char *msg = "A test message"; + size_t msglen = strlen(msg); + size_t numbytes = 0; + + if (!TEST_true(create_ssl_ctx_pair(libctx, OSSL_QUIC_server_method(), + OSSL_QUIC_client_method(), + 0, + 0, + &sctx, &cctx, NULL, NULL)) + || !TEST_true(create_ssl_objects(sctx, cctx, &serverquic, &clientquic, + NULL, NULL)) + || !TEST_true(create_bare_ssl_connection(serverquic, clientquic, + SSL_ERROR_NONE, 0))) + goto end; + + for (j = 0; j < 2; j++) { + /* Check that sending and receiving app data is ok */ + if (!TEST_true(SSL_write_ex(clientquic, msg, msglen, &numbytes)) + || !TEST_true(SSL_read_ex(serverquic, buf, sizeof(buf), + &numbytes)) + || !TEST_mem_eq(buf, numbytes, msg, msglen)) + goto end; + + if (!TEST_true(SSL_write_ex(serverquic, msg, msglen, &numbytes)) + || !TEST_true(SSL_read_ex(clientquic, buf, sizeof(buf), + &numbytes)) + || !TEST_mem_eq(buf, numbytes, msg, msglen)) + goto end; + } + + ret = 1; + + end: + SSL_free(serverquic); + SSL_free(clientquic); + SSL_CTX_free(sctx); + SSL_CTX_free(cctx); + + return ret; +} + +OPT_TEST_DECLARE_USAGE("provider config\n") + +int setup_tests(void) +{ + char *modulename; + char *configfile; + + libctx = OSSL_LIB_CTX_new(); + if (!TEST_ptr(libctx)) + return 0; + + defctxnull = OSSL_PROVIDER_load(NULL, "null"); + + /* + * Verify that the default and fips providers in the default libctx are not + * available + */ + if (!TEST_false(OSSL_PROVIDER_available(NULL, "default")) + || !TEST_false(OSSL_PROVIDER_available(NULL, "fips"))) + return 0; + + if (!test_skip_common_options()) { + TEST_error("Error parsing test options\n"); + return 0; + } + + if (!TEST_ptr(modulename = test_get_argument(0)) + || !TEST_ptr(configfile = test_get_argument(1))) + return 0; + + if (!TEST_true(OSSL_LIB_CTX_load_config(libctx, configfile))) + return 0; + + /* Check we have the expected provider available */ + if (!TEST_true(OSSL_PROVIDER_available(libctx, modulename))) + return 0; + + /* Check the default provider is not available */ + if (strcmp(modulename, "default") != 0 + && !TEST_false(OSSL_PROVIDER_available(libctx, "default"))) + return 0; + + if (strcmp(modulename, "fips") == 0) + is_fips = 1; + + ADD_TEST(test_quic_write_read); + return 1; +} + +void cleanup_tests(void) +{ + OSSL_PROVIDER_unload(defctxnull); + OSSL_LIB_CTX_free(libctx); +} diff --git a/test/recipes/75-test_quicapi.t b/test/recipes/75-test_quicapi.t new file mode 100644 index 0000000000..6e96d458ed --- /dev/null +++ b/test/recipes/75-test_quicapi.t @@ -0,0 +1,37 @@ +#! /usr/bin/env perl +# Copyright 2022 The OpenSSL Project Authors. All Rights Reserved. +# +# 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 + + +use OpenSSL::Test::Utils; +use OpenSSL::Test qw/:DEFAULT srctop_file srctop_dir bldtop_dir/; + +BEGIN { +setup("test_quicapi"); +} + +use lib srctop_dir('Configurations'); +use lib bldtop_dir('.'); + +my $no_fips = disabled('fips') || ($ENV{NO_FIPS} // 0); + +plan skip_all => "QUIC protocol is not supported by this OpenSSL build" + if disabled('quic'); + +plan tests => + ($no_fips ? 0 : 1) # quicapitest with fips + + 1; # quicapitest with default provider + +ok(run(test(["quicapitest", "default", + srctop_file("test", "default.cnf")])), + "running quicapitest"); + +unless ($no_fips) { + ok(run(test(["quicapitest", "fips", + srctop_file("test", "fips-and-base.cnf")])), + "running quicapitest"); +} |