From: Nikos Mavrogiannopoulos Date: Tue, 29 Mar 2016 14:11:36 +0000 (+0200) Subject: tests: check gnutls_record_get_state() with DTLS X-Git-Tag: gnutls_3_5_0~224 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b2aa0a209756059e098c344617f4b3bf5e4eab9d;p=thirdparty%2Fgnutls.git tests: check gnutls_record_get_state() with DTLS Since in DTLS we relied on a sliding window to keep track of the sequence numbers we didn't provide a sensible value to application via gnutls_record_get_state(). This test makes sure that we report the "correct" value when asked. Correct being the next number after the last received packet. --- diff --git a/tests/Makefile.am b/tests/Makefile.am index 15fbaee99d..ff7b689311 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -96,7 +96,7 @@ ctests = mini-record-2 simple gc set_pkcs12_cred certder certuniqueid \ rehandshake-switch-cert-client-allow handshake-versions dtls-handshake-versions \ dtls-max-record tls-max-record alpn-server-prec ocsp-filename-memleak \ dh-params rehandshake-ext-secret pcert-list session-export-funcs \ - handshake-false-start version-checks + handshake-false-start version-checks key-material-dtls if HAVE_SECCOMP_TESTS ctests += dtls-with-seccomp tls-with-seccomp dtls-client-with-seccomp tls-client-with-seccomp diff --git a/tests/key-material-dtls.c b/tests/key-material-dtls.c new file mode 100644 index 0000000000..0d9334d1a1 --- /dev/null +++ b/tests/key-material-dtls.c @@ -0,0 +1,405 @@ +/* + * Copyright (C) 2016 Red Hat, Inc. + * Copyright (C) 2013-2016 Nikos Mavrogiannopoulos + * + * This file is part of GnuTLS. + * + * GnuTLS is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * GnuTLS is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GnuTLS; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#include + +#if defined(_WIN32) || !defined(ENABLE_ALPN) + +int main(int argc, char **argv) +{ + exit(77); +} + +#else + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "utils.h" + +static void terminate(void); + +/* This program tests whether the gnutls_record_get_state() works as + * expected. + */ + +static void server_log_func(int level, const char *str) +{ + fprintf(stderr, "server|<%d>| %s", level, str); +} + +static void client_log_func(int level, const char *str) +{ + fprintf(stderr, "client|<%d>| %s", level, str); +} + +/* These are global */ +static pid_t child; + +/* A very basic DTLS client, with anonymous authentication, that negotiates SRTP + */ + +static void dump(const char *name, uint8_t *data, unsigned data_size) +{ + unsigned i; + + fprintf(stderr, "%s", name); + for (i=0;i 0); + + if (ret < 0) { + fail("error: %s\n", gnutls_strerror(ret)); + } + + /* do not wait for the peer to close the connection. + */ + gnutls_bye(session, GNUTLS_SHUT_WR); + + close(fd); + gnutls_deinit(session); + + gnutls_anon_free_server_credentials(anoncred); + gnutls_dh_params_deinit(dh_params); + + gnutls_global_deinit(); + + if (debug) + success("server: finished\n"); +} + +static void start(void) +{ + int fd[2]; + int ret; + + ret = socketpair(AF_UNIX, SOCK_STREAM, 0, fd); + if (ret < 0) { + perror("socketpair"); + exit(1); + } + + child = fork(); + if (child < 0) { + perror("fork"); + fail("fork"); + exit(1); + } + + if (child) { + int status; + /* parent */ + + server(fd[0]); + wait(&status); + if (WEXITSTATUS(status) != 0) + fail("Child died with status %d\n", + WEXITSTATUS(status)); + } else { + close(fd[0]); + client(fd[1]); + exit(0); + } +} + +void doit(void) +{ + start(); +} + +#endif /* _WIN32 */