diff --git a/src/tests/.gitignore b/src/tests/.gitignore index 2d2bfd9..adf1f5e 100644 --- a/src/tests/.gitignore +++ b/src/tests/.gitignore @@ -2,6 +2,7 @@ /base64_vector.cc /ocb-aes /encrypt-decrypt +/nonce-incr /*.d/ *.log *.trs diff --git a/src/tests/Makefile.am b/src/tests/Makefile.am index 388a391..0d3d495 100644 --- a/src/tests/Makefile.am +++ b/src/tests/Makefile.am @@ -31,8 +31,8 @@ displaytests = \ unicode-later-combining.test \ window-resize.test -check_PROGRAMS = ocb-aes encrypt-decrypt base64 -TESTS = ocb-aes encrypt-decrypt base64 $(displaytests) +check_PROGRAMS = ocb-aes encrypt-decrypt base64 nonce-incr +TESTS = ocb-aes encrypt-decrypt base64 nonce-incr $(displaytests) XFAIL_TESTS = \ e2e-failure.test \ emulation-attributes-256color8.test @@ -53,6 +53,10 @@ base64_SOURCES = base64.cc base64_vector.cc base64_vector.h genbase64.pl base64_CPPFLAGS = $(ocb_aes_CPPFLAGS) base64_LDADD = $(ocb_aes_LDADD) +nonce_incr_SOURCES = nonce-incr.cc +nonce_incr_CPPFLAGS = -I$(srcdir)/../network -I$(srcdir)/../crypto -I$(srcdir)/../util $(CRYPTO_CFLAGS) +nonce_incr_LDADD = ../network/libmoshnetwork.a ../crypto/libmoshcrypto.a ../util/libmoshutil.a $(CRYPTO_LIBS) + clean-local: clean-local-check .PHONY: clean-local-check clean-local-check: diff --git a/src/tests/nonce-incr.cc b/src/tests/nonce-incr.cc new file mode 100644 index 0000000..3a107bc --- /dev/null +++ b/src/tests/nonce-incr.cc @@ -0,0 +1,73 @@ +/* + Mosh: the mobile shell + Copyright 2012 Keith Winstein + + This program 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. + + This program 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 this program. If not, see . + + In addition, as a special exception, the copyright holders give + permission to link the code of portions of this program with the + OpenSSL library under certain conditions as described in each + individual source file, and distribute linked combinations including + the two. + + You must obey the GNU General Public License in all respects for all + of the code used other than OpenSSL. If you modify file(s) with this + exception, you may extend this exception to your version of the + file(s), but you are not obligated to do so. If you do not wish to do + so, delete this exception statement from your version. If you delete + this exception statement from all source files in the program, then + also delete it here. +*/ + +/* Tests that the Mosh network layer seems to be using unique nonces */ + +#include +#include +#include + +#include "network.h" + +int main() +{ + std::set nonces; + const unsigned int NUM_EXAMPLES = 1000000; + + for ( unsigned int i = 0; i < NUM_EXAMPLES; i++ ) { + Network::Packet packet( Network::TO_CLIENT, 0, 0, "test" ); + nonces.insert( packet.toMessage().nonce.val() ); + } + + for ( unsigned int i = 0; i < NUM_EXAMPLES; i++ ) { + Network::Packet packet( Network::TO_SERVER, 0, 0, "test" ); + nonces.insert( packet.toMessage().nonce.val() ); + } + + for ( unsigned int i = 0; i < NUM_EXAMPLES; i++ ) { + { + Network::Packet packet( Network::TO_SERVER, 0, 0, "test" ); + nonces.insert( packet.toMessage().nonce.val() ); + } + + { + Network::Packet packet( Network::TO_CLIENT, 0, 0, "test" ); + nonces.insert( packet.toMessage().nonce.val() ); + } + } + + if ( nonces.size() == 4 * NUM_EXAMPLES ) { + return EXIT_SUCCESS; + } + + return EXIT_FAILURE; +}