diff options
Diffstat (limited to 'src/charon/plugins/unit_tester')
-rw-r--r-- | src/charon/plugins/unit_tester/Makefile.am | 4 | ||||
-rw-r--r-- | src/charon/plugins/unit_tester/Makefile.in | 57 | ||||
-rw-r--r-- | src/charon/plugins/unit_tester/tests.h | 9 | ||||
-rw-r--r-- | src/charon/plugins/unit_tester/tests/test_aes.c | 467 | ||||
-rw-r--r-- | src/charon/plugins/unit_tester/tests/test_auth_info.c | 29 | ||||
-rw-r--r-- | src/charon/plugins/unit_tester/tests/test_fips_prf.c | 64 | ||||
-rw-r--r-- | src/charon/plugins/unit_tester/tests/test_id.c | 69 | ||||
-rw-r--r-- | src/charon/plugins/unit_tester/tests/test_med_db.c | 2 | ||||
-rw-r--r-- | src/charon/plugins/unit_tester/tests/test_pool.c | 17 | ||||
-rw-r--r-- | src/charon/plugins/unit_tester/tests/test_rng.c | 221 | ||||
-rw-r--r-- | src/charon/plugins/unit_tester/tests/test_rsa_gen.c | 20 | ||||
-rw-r--r-- | src/charon/plugins/unit_tester/unit_tester.c | 2 | ||||
-rw-r--r-- | src/charon/plugins/unit_tester/unit_tester.h | 2 |
13 files changed, 135 insertions, 828 deletions
diff --git a/src/charon/plugins/unit_tester/Makefile.am b/src/charon/plugins/unit_tester/Makefile.am index 9c86aa69f..50c5e0362 100644 --- a/src/charon/plugins/unit_tester/Makefile.am +++ b/src/charon/plugins/unit_tester/Makefile.am @@ -8,7 +8,6 @@ plugin_LTLIBRARIES = libstrongswan-unit-tester.la libstrongswan_unit_tester_la_SOURCES = unit_tester.c unit_tester.h tests.h \ tests/test_enumerator.c \ tests/test_auth_info.c \ - tests/test_fips_prf.c \ tests/test_curl.c \ tests/test_mysql.c \ tests/test_sqlite.c \ @@ -16,11 +15,10 @@ libstrongswan_unit_tester_la_SOURCES = unit_tester.c unit_tester.h tests.h \ tests/test_rsa_gen.c \ tests/test_cert.c \ tests/test_med_db.c \ - tests/test_aes.c \ tests/test_chunk.c \ tests/test_pool.c \ tests/test_agent.c \ - tests/test_rng.c + tests/test_id.c libstrongswan_unit_tester_la_LDFLAGS = -module diff --git a/src/charon/plugins/unit_tester/Makefile.in b/src/charon/plugins/unit_tester/Makefile.in index 537ec127e..2ee5e48d8 100644 --- a/src/charon/plugins/unit_tester/Makefile.in +++ b/src/charon/plugins/unit_tester/Makefile.in @@ -1,4 +1,4 @@ -# Makefile.in generated by automake 1.10.1 from Makefile.am. +# Makefile.in generated by automake 1.10.2 from Makefile.am. # @configure_input@ # Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, @@ -51,10 +51,10 @@ pluginLTLIBRARIES_INSTALL = $(INSTALL) LTLIBRARIES = $(plugin_LTLIBRARIES) libstrongswan_unit_tester_la_LIBADD = am_libstrongswan_unit_tester_la_OBJECTS = unit_tester.lo \ - test_enumerator.lo test_auth_info.lo test_fips_prf.lo \ - test_curl.lo test_mysql.lo test_sqlite.lo test_mutex.lo \ - test_rsa_gen.lo test_cert.lo test_med_db.lo test_aes.lo \ - test_chunk.lo test_pool.lo test_agent.lo test_rng.lo + test_enumerator.lo test_auth_info.lo test_curl.lo \ + test_mysql.lo test_sqlite.lo test_mutex.lo test_rsa_gen.lo \ + test_cert.lo test_med_db.lo test_chunk.lo test_pool.lo \ + test_agent.lo test_id.lo libstrongswan_unit_tester_la_OBJECTS = \ $(am_libstrongswan_unit_tester_la_OBJECTS) libstrongswan_unit_tester_la_LINK = $(LIBTOOL) --tag=CC \ @@ -93,6 +93,7 @@ CPPFLAGS = @CPPFLAGS@ CYGPATH_W = @CYGPATH_W@ DEFS = @DEFS@ DEPDIR = @DEPDIR@ +DLLIB = @DLLIB@ DSYMUTIL = @DSYMUTIL@ DUMPBIN = @DUMPBIN@ ECHO_C = @ECHO_C@ @@ -115,6 +116,9 @@ LDFLAGS = @LDFLAGS@ LEX = @LEX@ LEXLIB = @LEXLIB@ LEX_OUTPUT_ROOT = @LEX_OUTPUT_ROOT@ +LIBGCRYPT_CFLAGS = @LIBGCRYPT_CFLAGS@ +LIBGCRYPT_CONFIG = @LIBGCRYPT_CONFIG@ +LIBGCRYPT_LIBS = @LIBGCRYPT_LIBS@ LIBOBJS = @LIBOBJS@ LIBS = @LIBS@ LIBTOOL = @LIBTOOL@ @@ -126,6 +130,7 @@ MAKEINFO = @MAKEINFO@ MKDIR_P = @MKDIR_P@ NM = @NM@ NMEDIT = @NMEDIT@ +OBJDUMP = @OBJDUMP@ OBJEXT = @OBJEXT@ OTOOL = @OTOOL@ OTOOL64 = @OTOOL64@ @@ -139,6 +144,8 @@ PATH_SEPARATOR = @PATH_SEPARATOR@ PERL = @PERL@ PKG_CONFIG = @PKG_CONFIG@ RANLIB = @RANLIB@ +RUBY = @RUBY@ +RUBYINCLUDE = @RUBYINCLUDE@ SED = @SED@ SET_MAKE = @SET_MAKE@ SHELL = @SHELL@ @@ -199,6 +206,7 @@ oldincludedir = @oldincludedir@ pdfdir = @pdfdir@ piddir = @piddir@ plugindir = @plugindir@ +pluto_plugins = @pluto_plugins@ prefix = @prefix@ program_transform_name = @program_transform_name@ psdir = @psdir@ @@ -210,6 +218,7 @@ srcdir = @srcdir@ strongswan_conf = @strongswan_conf@ sysconfdir = @sysconfdir@ target_alias = @target_alias@ +top_build_prefix = @top_build_prefix@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ xml_CFLAGS = @xml_CFLAGS@ @@ -220,7 +229,6 @@ plugin_LTLIBRARIES = libstrongswan-unit-tester.la libstrongswan_unit_tester_la_SOURCES = unit_tester.c unit_tester.h tests.h \ tests/test_enumerator.c \ tests/test_auth_info.c \ - tests/test_fips_prf.c \ tests/test_curl.c \ tests/test_mysql.c \ tests/test_sqlite.c \ @@ -228,11 +236,10 @@ libstrongswan_unit_tester_la_SOURCES = unit_tester.c unit_tester.h tests.h \ tests/test_rsa_gen.c \ tests/test_cert.c \ tests/test_med_db.c \ - tests/test_aes.c \ tests/test_chunk.c \ tests/test_pool.c \ tests/test_agent.c \ - tests/test_rng.c + tests/test_id.c libstrongswan_unit_tester_la_LDFLAGS = -module all: all-am @@ -243,8 +250,8 @@ $(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps) @for dep in $?; do \ case '$(am__configure_deps)' in \ *$$dep*) \ - cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh \ - && exit 0; \ + ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \ + && { if test -f $@; then exit 0; else break; fi; }; \ exit 1;; \ esac; \ done; \ @@ -304,19 +311,17 @@ mostlyclean-compile: distclean-compile: -rm -f *.tab.c -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_aes.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_agent.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_auth_info.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_cert.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_chunk.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_curl.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_enumerator.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_fips_prf.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_id.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_med_db.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_mutex.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_mysql.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_pool.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_rng.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_rsa_gen.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_sqlite.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/unit_tester.Plo@am__quote@ @@ -356,13 +361,6 @@ test_auth_info.lo: tests/test_auth_info.c @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o test_auth_info.lo `test -f 'tests/test_auth_info.c' || echo '$(srcdir)/'`tests/test_auth_info.c -test_fips_prf.lo: tests/test_fips_prf.c -@am__fastdepCC_TRUE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT test_fips_prf.lo -MD -MP -MF $(DEPDIR)/test_fips_prf.Tpo -c -o test_fips_prf.lo `test -f 'tests/test_fips_prf.c' || echo '$(srcdir)/'`tests/test_fips_prf.c -@am__fastdepCC_TRUE@ mv -f $(DEPDIR)/test_fips_prf.Tpo $(DEPDIR)/test_fips_prf.Plo -@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='tests/test_fips_prf.c' object='test_fips_prf.lo' libtool=yes @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o test_fips_prf.lo `test -f 'tests/test_fips_prf.c' || echo '$(srcdir)/'`tests/test_fips_prf.c - test_curl.lo: tests/test_curl.c @am__fastdepCC_TRUE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT test_curl.lo -MD -MP -MF $(DEPDIR)/test_curl.Tpo -c -o test_curl.lo `test -f 'tests/test_curl.c' || echo '$(srcdir)/'`tests/test_curl.c @am__fastdepCC_TRUE@ mv -f $(DEPDIR)/test_curl.Tpo $(DEPDIR)/test_curl.Plo @@ -412,13 +410,6 @@ test_med_db.lo: tests/test_med_db.c @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o test_med_db.lo `test -f 'tests/test_med_db.c' || echo '$(srcdir)/'`tests/test_med_db.c -test_aes.lo: tests/test_aes.c -@am__fastdepCC_TRUE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT test_aes.lo -MD -MP -MF $(DEPDIR)/test_aes.Tpo -c -o test_aes.lo `test -f 'tests/test_aes.c' || echo '$(srcdir)/'`tests/test_aes.c -@am__fastdepCC_TRUE@ mv -f $(DEPDIR)/test_aes.Tpo $(DEPDIR)/test_aes.Plo -@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='tests/test_aes.c' object='test_aes.lo' libtool=yes @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o test_aes.lo `test -f 'tests/test_aes.c' || echo '$(srcdir)/'`tests/test_aes.c - test_chunk.lo: tests/test_chunk.c @am__fastdepCC_TRUE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT test_chunk.lo -MD -MP -MF $(DEPDIR)/test_chunk.Tpo -c -o test_chunk.lo `test -f 'tests/test_chunk.c' || echo '$(srcdir)/'`tests/test_chunk.c @am__fastdepCC_TRUE@ mv -f $(DEPDIR)/test_chunk.Tpo $(DEPDIR)/test_chunk.Plo @@ -440,12 +431,12 @@ test_agent.lo: tests/test_agent.c @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o test_agent.lo `test -f 'tests/test_agent.c' || echo '$(srcdir)/'`tests/test_agent.c -test_rng.lo: tests/test_rng.c -@am__fastdepCC_TRUE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT test_rng.lo -MD -MP -MF $(DEPDIR)/test_rng.Tpo -c -o test_rng.lo `test -f 'tests/test_rng.c' || echo '$(srcdir)/'`tests/test_rng.c -@am__fastdepCC_TRUE@ mv -f $(DEPDIR)/test_rng.Tpo $(DEPDIR)/test_rng.Plo -@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='tests/test_rng.c' object='test_rng.lo' libtool=yes @AMDEPBACKSLASH@ +test_id.lo: tests/test_id.c +@am__fastdepCC_TRUE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT test_id.lo -MD -MP -MF $(DEPDIR)/test_id.Tpo -c -o test_id.lo `test -f 'tests/test_id.c' || echo '$(srcdir)/'`tests/test_id.c +@am__fastdepCC_TRUE@ mv -f $(DEPDIR)/test_id.Tpo $(DEPDIR)/test_id.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='tests/test_id.c' object='test_id.lo' libtool=yes @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o test_rng.lo `test -f 'tests/test_rng.c' || echo '$(srcdir)/'`tests/test_rng.c +@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o test_id.lo `test -f 'tests/test_id.c' || echo '$(srcdir)/'`tests/test_id.c mostlyclean-libtool: -rm -f *.lo @@ -458,7 +449,7 @@ ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) unique=`for i in $$list; do \ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ done | \ - $(AWK) '{ files[$$0] = 1; nonemtpy = 1; } \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ END { if (nonempty) { for (i in files) print i; }; }'`; \ mkid -fID $$unique tags: TAGS diff --git a/src/charon/plugins/unit_tester/tests.h b/src/charon/plugins/unit_tester/tests.h index 7a5aa5ab8..dcf2a5d18 100644 --- a/src/charon/plugins/unit_tester/tests.h +++ b/src/charon/plugins/unit_tester/tests.h @@ -11,8 +11,6 @@ * 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. - * - * $Id: tests.h 5003 2009-03-24 17:43:01Z martin $ */ /** @@ -25,8 +23,7 @@ DEFINE_TEST("simple enumerator", test_enumerate, FALSE) DEFINE_TEST("nested enumerator", test_enumerate_nested, FALSE) DEFINE_TEST("filtered enumerator", test_enumerate_filtered, FALSE) DEFINE_TEST("token enumerator", test_enumerate_token, FALSE) -DEFINE_TEST("auth info", test_auth_info, FALSE) -DEFINE_TEST("FIPS PRF", fips_prf_test, FALSE) +DEFINE_TEST("auth cfg", test_auth_cfg, FALSE) DEFINE_TEST("CURL get", test_curl_get, FALSE) DEFINE_TEST("MySQL operations", test_mysql, FALSE) DEFINE_TEST("SQLite operations", test_sqlite, FALSE) @@ -35,11 +32,9 @@ DEFINE_TEST("RSA key generation", test_rsa_gen, FALSE) DEFINE_TEST("RSA subjectPublicKeyInfo loading", test_rsa_load_any, FALSE) DEFINE_TEST("X509 certificate", test_cert_x509, FALSE) DEFINE_TEST("Mediation database key fetch", test_med_db, FALSE) -DEFINE_TEST("AES-128 encryption", test_aes128, FALSE) -DEFINE_TEST("AES-XCBC", test_aes_xcbc, FALSE) DEFINE_TEST("Base64 converter", test_chunk_base64, FALSE) DEFINE_TEST("IP pool", test_pool, FALSE) DEFINE_TEST("SSH agent", test_agent, FALSE) -DEFINE_TEST("RNG quality", test_rng, FALSE) +DEFINE_TEST("ID parts", test_id_parts, FALSE) /** @}*/ diff --git a/src/charon/plugins/unit_tester/tests/test_aes.c b/src/charon/plugins/unit_tester/tests/test_aes.c deleted file mode 100644 index 06e891d83..000000000 --- a/src/charon/plugins/unit_tester/tests/test_aes.c +++ /dev/null @@ -1,467 +0,0 @@ -/* - * Copyright (C) 2008 Martin Willi - * Hochschule fuer Technik Rapperswil - * - * 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 2 of the License, or (at your - * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>. - * - * 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. - */ - -#include <daemon.h> -#include <library.h> -#include <utils/mutex.h> - -#include <unistd.h> -#include <sched.h> -#include <pthread.h> - -/** - * run a test using given values - */ -static bool do_aes_test(u_char *key, int keysize, u_char *iv, - u_char *plain, u_char *cipher, int len) -{ - crypter_t *crypter; - chunk_t enc, dec; - bool good = TRUE; - - crypter = lib->crypto->create_crypter(lib->crypto, ENCR_AES_CBC, keysize); - if (!crypter) - { - return FALSE; - } - crypter->set_key(crypter, chunk_create(key, keysize)); - crypter->encrypt(crypter, - chunk_create(plain, len), chunk_create(iv, 16), &enc); - if (!memeq(enc.ptr, cipher, len)) - { - good = FALSE; - } - crypter->decrypt(crypter, enc, chunk_create(iv, 16), &dec); - if (!memeq(dec.ptr, plain, len)) - { - good = FALSE; - } - free(enc.ptr); - free(dec.ptr); - crypter->destroy(crypter); - return good; -} - -/******************************************************************************* - * AES-128 test - ******************************************************************************/ -bool test_aes128() -{ - /* - * Test 1 of RFC3602 - * Key : 0x06a9214036b8a15b512e03d534120006 - * IV : 0x3dafba429d9eb430b422da802c9fac41 - * Plaintext : "Single block msg" - * Ciphertext: 0xe353779c1079aeb82708942dbe77181a - */ - u_char key1[] = { - 0x06,0xa9,0x21,0x40,0x36,0xb8,0xa1,0x5b, - 0x51,0x2e,0x03,0xd5,0x34,0x12,0x00,0x06 - }; - u_char iv1[] = { - 0x3d,0xaf,0xba,0x42,0x9d,0x9e,0xb4,0x30, - 0xb4,0x22,0xda,0x80,0x2c,0x9f,0xac,0x41 - }; - u_char plain1[] = { - 'S','i','n','g','l','e',' ','b','l','o','c','k',' ','m','s','g' - }; - u_char cipher1[] = { - 0xe3,0x53,0x77,0x9c,0x10,0x79,0xae,0xb8, - 0x27,0x08,0x94,0x2d,0xbe,0x77,0x18,0x1a - }; - if (!do_aes_test(key1, 16, iv1, plain1, cipher1, sizeof(plain1))) - { - return FALSE; - } - - /* - * Test 2 of RFC3602 - * Key : 0xc286696d887c9aa0611bbb3e2025a45a - * IV : 0x562e17996d093d28ddb3ba695a2e6f58 - * Plaintext : 0x000102030405060708090a0b0c0d0e0f - * 101112131415161718191a1b1c1d1e1f - * Ciphertext: 0xd296cd94c2cccf8a3a863028b5e1dc0a - * 7586602d253cfff91b8266bea6d61ab1 - */ - u_char key2[] = { - 0xc2,0x86,0x69,0x6d,0x88,0x7c,0x9a,0xa0, - 0x61,0x1b,0xbb,0x3e,0x20,0x25,0xa4,0x5a - }; - u_char iv2[] = { - 0x56,0x2e,0x17,0x99,0x6d,0x09,0x3d,0x28, - 0xdd,0xb3,0xba,0x69,0x5a,0x2e,0x6f,0x58 - }; - u_char plain2[] = { - 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07, - 0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f, - 0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17, - 0x18,0x19,0x1a,0x1b,0x1c,0x1d,0x1e,0x1f - }; - u_char cipher2[] = { - 0xd2,0x96,0xcd,0x94,0xc2,0xcc,0xcf,0x8a, - 0x3a,0x86,0x30,0x28,0xb5,0xe1,0xdc,0x0a, - 0x75,0x86,0x60,0x2d,0x25,0x3c,0xff,0xf9, - 0x1b,0x82,0x66,0xbe,0xa6,0xd6,0x1a,0xb1 - }; - if (!do_aes_test(key2, 16, iv2, plain2, cipher2, sizeof(plain2))) - { - return FALSE; - } - - /* - * Test 3 of RFC3603 - * Key : 0x56e47a38c5598974bc46903dba290349 - * IV : 0x8ce82eefbea0da3c44699ed7db51b7d9 - * Plaintext : 0xa0a1a2a3a4a5a6a7a8a9aaabacadaeaf - * b0b1b2b3b4b5b6b7b8b9babbbcbdbebf - * c0c1c2c3c4c5c6c7c8c9cacbcccdcecf - * d0d1d2d3d4d5d6d7d8d9dadbdcdddedf - * Ciphertext: 0xc30e32ffedc0774e6aff6af0869f71aa - * 0f3af07a9a31a9c684db207eb0ef8e4e - * 35907aa632c3ffdf868bb7b29d3d46ad - * 83ce9f9a102ee99d49a53e87f4c3da55 - */ - u_char key3[] = { - 0x56,0xe4,0x7a,0x38,0xc5,0x59,0x89,0x74, - 0xbc,0x46,0x90,0x3d,0xba,0x29,0x03,0x49 - }; - u_char iv3[] = { - 0x8c,0xe8,0x2e,0xef,0xbe,0xa0,0xda,0x3c, - 0x44,0x69,0x9e,0xd7,0xdb,0x51,0xb7,0xd9 - }; - u_char plain3[] = { - 0xa0,0xa1,0xa2,0xa3,0xa4,0xa5,0xa6,0xa7, - 0xa8,0xa9,0xaa,0xab,0xac,0xad,0xae,0xaf, - 0xb0,0xb1,0xb2,0xb3,0xb4,0xb5,0xb6,0xb7, - 0xb8,0xb9,0xba,0xbb,0xbc,0xbd,0xbe,0xbf, - 0xc0,0xc1,0xc2,0xc3,0xc4,0xc5,0xc6,0xc7, - 0xc8,0xc9,0xca,0xcb,0xcc,0xcd,0xce,0xcf, - 0xd0,0xd1,0xd2,0xd3,0xd4,0xd5,0xd6,0xd7, - 0xd8,0xd9,0xda,0xdb,0xdc,0xdd,0xde,0xdf - }; - u_char cipher3[] = { - 0xc3,0x0e,0x32,0xff,0xed,0xc0,0x77,0x4e, - 0x6a,0xff,0x6a,0xf0,0x86,0x9f,0x71,0xaa, - 0x0f,0x3a,0xf0,0x7a,0x9a,0x31,0xa9,0xc6, - 0x84,0xdb,0x20,0x7e,0xb0,0xef,0x8e,0x4e, - 0x35,0x90,0x7a,0xa6,0x32,0xc3,0xff,0xdf, - 0x86,0x8b,0xb7,0xb2,0x9d,0x3d,0x46,0xad, - 0x83,0xce,0x9f,0x9a,0x10,0x2e,0xe9,0x9d, - 0x49,0xa5,0x3e,0x87,0xf4,0xc3,0xda,0x55 - }; - if (!do_aes_test(key3, 16, iv3, plain3, cipher3, sizeof(plain3))) - { - return FALSE; - } - return TRUE; -} - -/** - * run a single xcbc test for prf and signer - */ -static bool do_xcbc_test(u_int8_t *key, size_t keylen, u_int8_t *mac, - u_int8_t *plain, size_t len) -{ - signer_t *signer; - prf_t *prf; - u_int8_t res[16]; - - prf = lib->crypto->create_prf(lib->crypto, PRF_AES128_XCBC); - if (!prf) - { - return FALSE; - } - prf->set_key(prf, chunk_create(key, keylen)); - prf->get_bytes(prf, chunk_create(plain, len), res); - if (!memeq(res, mac, 16)) - { - DBG1(DBG_CFG, "expected %b\ngot %b", mac, 16, res, 16); - prf->destroy(prf); - return FALSE; - } - prf->destroy(prf); - - signer = lib->crypto->create_signer(lib->crypto, AUTH_AES_XCBC_96); - if (!signer) - { - return FALSE; - } - signer->set_key(signer, chunk_create(key, keylen)); - if (!signer->verify_signature(signer, chunk_create(plain, len), - chunk_create(mac, 12))) - { - return FALSE; - } - signer->destroy(signer); - return TRUE; -} - - -/******************************************************************************* - * AES_XCBC mac test - ******************************************************************************/ -bool test_aes_xcbc() -{ - /* Vectors from RFC 3566 */ - - /* Test Case #1 : AES-XCBC-MAC-96 with 0-byte input - * Key (K) : 000102030405060708090a0b0c0d0e0f - * Message (M) : <empty string> - * AES-XCBC-MAC : 75f0251d528ac01c4573dfd584d79f29 - * AES-XCBC-MAC-96: 75f0251d528ac01c4573dfd5 - */ - u_char key1[] = { - 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07, - 0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f - }; - u_char plain1[] = { - }; - u_char mac1[] = { - 0x75,0xf0,0x25,0x1d,0x52,0x8a,0xc0,0x1c, - 0x45,0x73,0xdf,0xd5,0x84,0xd7,0x9f,0x29 - }; - if (!do_xcbc_test(key1, 16, mac1, plain1, sizeof(plain1))) - { - return FALSE; - } - - /* - * Test Case #2 : AES-XCBC-MAC-96 with 3-byte input - * Key (K) : 000102030405060708090a0b0c0d0e0f - * Message (M) : 000102 - * AES-XCBC-MAC : 5b376580ae2f19afe7219ceef172756f - * AES-XCBC-MAC-96: 5b376580ae2f19afe7219cee - */ - u_char key2[] = { - 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07, - 0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f - }; - u_char plain2[] = { - 0x00,0x01,0x02 - }; - u_char mac2[] = { - 0x5b,0x37,0x65,0x80,0xae,0x2f,0x19,0xaf, - 0xe7,0x21,0x9c,0xee,0xf1,0x72,0x75,0x6f - }; - if (!do_xcbc_test(key2, 16, mac2, plain2, sizeof(plain2))) - { - return FALSE; - } - - /* Test Case #3 : AES-XCBC-MAC-96 with 16-byte input - * Key (K) : 000102030405060708090a0b0c0d0e0f - * Message (M) : 000102030405060708090a0b0c0d0e0f - * AES-XCBC-MAC : d2a246fa349b68a79998a4394ff7a263 - * AES-XCBC-MAC-96: d2a246fa349b68a79998a439 - */ - u_char key3[] = { - 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07, - 0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f - }; - u_char plain3[] = { - 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07, - 0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f - }; - u_char mac3[] = { - 0xd2,0xa2,0x46,0xfa,0x34,0x9b,0x68,0xa7, - 0x99,0x98,0xa4,0x39,0x4f,0xf7,0xa2,0x63 - }; - if (!do_xcbc_test(key3, 16, mac3, plain3, sizeof(plain3))) - { - return FALSE; - } - - /* Test Case #4 : AES-XCBC-MAC-96 with 20-byte input - * Key (K) : 000102030405060708090a0b0c0d0e0f - * Message (M) : 000102030405060708090a0b0c0d0e0f10111213 - * AES-XCBC-MAC : 47f51b4564966215b8985c63055ed308 - * AES-XCBC-MAC-96: 47f51b4564966215b8985c63 - */ - u_char key4[] = { - 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07, - 0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f - }; - u_char plain4[] = { - 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07, - 0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f, - 0x10,0x11,0x12,0x13 - }; - u_char mac4[] = { - 0x47,0xf5,0x1b,0x45,0x64,0x96,0x62,0x15, - 0xb8,0x98,0x5c,0x63,0x05,0x5e,0xd3,0x08 - }; - if (!do_xcbc_test(key4, 16, mac4, plain4, sizeof(plain4))) - { - return FALSE; - } - - /* Test Case #5 : AES-XCBC-MAC-96 with 32-byte input - * Key (K) : 000102030405060708090a0b0c0d0e0f - * Message (M) : 000102030405060708090a0b0c0d0e0f10111213141516171819 - * 1a1b1c1d1e1f - * AES-XCBC-MAC : f54f0ec8d2b9f3d36807734bd5283fd4 - * AES-XCBC-MAC-96: f54f0ec8d2b9f3d36807734b - */ - u_char key5[] = { - 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07, - 0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f - }; - u_char plain5[] = { - 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07, - 0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f, - 0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17, - 0x18,0x19,0x1a,0x1b,0x1c,0x1d,0x1e,0x1f - }; - u_char mac5[] = { - 0xf5,0x4f,0x0e,0xc8,0xd2,0xb9,0xf3,0xd3, - 0x68,0x07,0x73,0x4b,0xd5,0x28,0x3f,0xd4 - }; - if (!do_xcbc_test(key5, 16, mac5, plain5, sizeof(plain5))) - { - return FALSE; - } - - /* Test Case #7 : AES-XCBC-MAC-96 with 1000-byte input - * Key (K) : 000102030405060708090a0b0c0d0e0f - * Message (M) : 00000000000000000000 ... 00000000000000000000 - * [1000 bytes] - * AES-XCBC-MAC : f0dafee895db30253761103b5d84528f - * AES-XCBC-MAC-96: f0dafee895db30253761103b - */ - u_char key7[] = { - 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07, - 0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f - }; - u_char plain7[1000]; - memset(plain7, 0, 1000); - u_char mac7[] = { - 0xf0,0xda,0xfe,0xe8,0x95,0xdb,0x30,0x25, - 0x37,0x61,0x10,0x3b,0x5d,0x84,0x52,0x8f - }; - if (!do_xcbc_test(key7, 16, mac7, plain7, sizeof(plain7))) - { - return FALSE; - } - - /* variable key test, RFC4434 */ - - /* Test Case AES-XCBC-PRF-128 with 20-byte input - * Key : 00010203040506070809 - * Message : 000102030405060708090a0b0c0d0e0f10111213 - * PRF Output : 0fa087af7d866e7653434e602fdde835 - */ - u_char key8[] = { - 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07, - 0x08,0x09, - }; - u_char plain8[] = { - 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07, - 0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f, - 0x10,0x11,0x12,0x13 - }; - u_char mac8[] = { - 0x0f,0xa0,0x87,0xaf,0x7d,0x86,0x6e,0x76, - 0x53,0x43,0x4e,0x60,0x2f,0xdd,0xe8,0x35 - }; - if (!do_xcbc_test(key8, 10, mac8, plain8, sizeof(plain8))) - { - return FALSE; - } - - /* Test Case AES-XCBC-PRF-128 with 20-byte input - * Key : 000102030405060708090a0b0c0d0e0fedcb - * Message : 000102030405060708090a0b0c0d0e0f10111213 - * PRF Output : 8cd3c93ae598a9803006ffb67c40e9e4 - */ - u_char key9[] = { - 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07, - 0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f, - 0xed,0xcb - }; - u_char plain9[] = { - 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07, - 0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f, - 0x10,0x11,0x12,0x13 - }; - u_char mac9[] = { - 0x8c,0xd3,0xc9,0x3a,0xe5,0x98,0xa9,0x80, - 0x30,0x06,0xff,0xb6,0x7c,0x40,0xe9,0xe4 - }; - if (!do_xcbc_test(key9, 18, mac9, plain9, sizeof(plain9))) - { - return FALSE; - } - - - /* Test Case #10 : AES-XCBC-MAC-96 with 32-byte input using append mode - * Key (K) : 000102030405060708090a0b0c0d0e0f - * Message (M) : 000102030405060708090a0b0c0d0e0f10111213141516171819 - * 1a1b1c1d1e1f - * AES-XCBC-MAC : f54f0ec8d2b9f3d36807734bd5283fd4 - * AES-XCBC-MAC-96: f54f0ec8d2b9f3d36807734b - */ - u_char key10[] = { - 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07, - 0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f - }; - u_char plain10[] = { - 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07, - 0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f, - 0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17, - 0x18,0x19,0x1a,0x1b,0x1c,0x1d,0x1e,0x1f - }; - u_char mac10[] = { - 0xf5,0x4f,0x0e,0xc8,0xd2,0xb9,0xf3,0xd3, - 0x68,0x07,0x73,0x4b,0xd5,0x28,0x3f,0xd4 - }; - int i; - prf_t *prf = lib->crypto->create_prf(lib->crypto, PRF_AES128_XCBC); - u_char res[16]; - if (!prf) - { - return FALSE; - } - prf->set_key(prf, chunk_create(key10, sizeof(key10))); - for (i = 0; i < 4; i++) - { /* bytes 0 - 3, 1 byte at once */ - prf->get_bytes(prf, chunk_create(plain10 + i, 1), NULL); - } - for (i = 4; i < 5; i+=8) - { /* bytes 4 - 11, at once */ - prf->get_bytes(prf, chunk_create(plain10 + i, 8), NULL); - } - for (i = 12; i < 24; i+=4) - { /* bytes 12 - 23, in blocks of 4 */ - prf->get_bytes(prf, chunk_create(plain10 + i, 4), NULL); - } - for (i = 0; i < 4; i++) - { /* 4 zero blobs */ - prf->get_bytes(prf, chunk_create(NULL, 0), NULL); - } - for (i = 24; i < 25; i+=8) - { /* bytes 24 - 32, at once */ - prf->get_bytes(prf, chunk_create(plain10 + i, 8), res); - } - if (!memeq(res, mac10, 16)) - { - DBG1(DBG_CFG, "expected %b\ngot %b", mac10, 16, res, 16); - prf->destroy(prf); - return FALSE; - } - prf->destroy(prf); - - return TRUE; -} - diff --git a/src/charon/plugins/unit_tester/tests/test_auth_info.c b/src/charon/plugins/unit_tester/tests/test_auth_info.c index 1719190b1..37bdd1087 100644 --- a/src/charon/plugins/unit_tester/tests/test_auth_info.c +++ b/src/charon/plugins/unit_tester/tests/test_auth_info.c @@ -15,7 +15,7 @@ #include <daemon.h> #include <library.h> -#include <credentials/auth_info.h> +#include <config/auth_cfg.h> char buf[] = {0x01,0x02,0x03,0x04}; @@ -75,14 +75,14 @@ chunk_t certchunk = chunk_from_buf(certbuf); /******************************************************************************* * auth info test ******************************************************************************/ -bool test_auth_info() +bool test_auth_cfg() { - auth_info_t *auth = auth_info_create(), *auth2; + auth_cfg_t *auth = auth_cfg_create(), *auth2; certificate_t *c1, *c2; enumerator_t *enumerator; int round = 0; void *value; - auth_item_t type; + auth_rule_t type; c1 = lib->creds->create(lib->creds, CRED_CERTIFICATE, CERT_X509, BUILD_BLOB_ASN1_DER, certchunk, @@ -92,8 +92,9 @@ bool test_auth_info() return FALSE; } - auth->add_item(auth, AUTHN_SUBJECT_CERT, c1); - if (!auth->get_item(auth, AUTHN_SUBJECT_CERT, (void**)&c2)) + auth->add(auth, AUTH_RULE_SUBJECT_CERT, c1->get_ref(c1)); + c2 = auth->get(auth, AUTH_RULE_SUBJECT_CERT); + if (!c2) { return FALSE; } @@ -102,11 +103,11 @@ bool test_auth_info() return FALSE; } - enumerator = auth->create_item_enumerator(auth); + enumerator = auth->create_enumerator(auth); while (enumerator->enumerate(enumerator, &type, &value)) { round++; - if (round == 1 && type == AUTHN_SUBJECT_CERT && value == c1) + if (round == 1 && type == AUTH_RULE_SUBJECT_CERT && value == c1) { continue; } @@ -114,20 +115,20 @@ bool test_auth_info() } enumerator->destroy(enumerator); - auth2 = auth_info_create(); - auth2->add_item(auth2, AUTHN_CA_CERT, c1); - auth2->merge(auth2, auth); + auth2 = auth_cfg_create(); + auth2->add(auth2, AUTH_RULE_CA_CERT, c1->get_ref(c1)); + auth2->merge(auth2, auth, FALSE); round = 0; - enumerator = auth2->create_item_enumerator(auth2); + enumerator = auth2->create_enumerator(auth2); while (enumerator->enumerate(enumerator, &type, &value)) { round++; - if (round == 1 && type == AUTHN_CA_CERT && value == c1) + if (round == 1 && type == AUTH_RULE_CA_CERT && value == c1) { continue; } - if (round == 2 && type == AUTHN_SUBJECT_CERT && value == c1) + if (round == 2 && type == AUTH_RULE_SUBJECT_CERT && value == c1) { continue; } diff --git a/src/charon/plugins/unit_tester/tests/test_fips_prf.c b/src/charon/plugins/unit_tester/tests/test_fips_prf.c deleted file mode 100644 index 29612143e..000000000 --- a/src/charon/plugins/unit_tester/tests/test_fips_prf.c +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (C) 2007 Martin Willi - * Hochschule fuer Technik Rapperswil - * - * 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 2 of the License, or (at your - * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>. - * - * 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. - */ - -#include <utils/linked_list.h> -#include <daemon.h> - -/******************************************************************************* - * fips prf known value test - ******************************************************************************/ -bool fips_prf_test() -{ - prf_t *prf; - u_int8_t key_buf[] = { - 0xbd, 0x02, 0x9b, 0xbe, 0x7f, 0x51, 0x96, 0x0b, - 0xcf, 0x9e, 0xdb, 0x2b, 0x61, 0xf0, 0x6f, 0x0f, - 0xeb, 0x5a, 0x38, 0xb6 - }; - u_int8_t seed_buf[] = { - 0x00 - }; - u_int8_t result_buf[] = { - 0x20, 0x70, 0xb3, 0x22, 0x3d, 0xba, 0x37, 0x2f, - 0xde, 0x1c, 0x0f, 0xfc, 0x7b, 0x2e, 0x3b, 0x49, - 0x8b, 0x26, 0x06, 0x14, 0x3c, 0x6c, 0x18, 0xba, - 0xcb, 0x0f, 0x6c, 0x55, 0xba, 0xbb, 0x13, 0x78, - 0x8e, 0x20, 0xd7, 0x37, 0xa3, 0x27, 0x51, 0x16 - }; - chunk_t key = chunk_from_buf(key_buf); - chunk_t seed = chunk_from_buf(seed_buf); - chunk_t expected = chunk_from_buf(result_buf); - chunk_t result; - - prf = lib->crypto->create_prf(lib->crypto, PRF_FIPS_SHA1_160); - if (prf == NULL) - { - DBG1(DBG_CFG, "FIPS PRF implementation not found"); - return FALSE; - } - prf->set_key(prf, key); - prf->allocate_bytes(prf, seed, &result); - prf->destroy(prf); - if (!chunk_equals(result, expected)) - { - DBG1(DBG_CFG, "FIPS PRF result invalid:\nexpected: %Bresult: %B", - &expected, &result); - chunk_free(&result); - return FALSE; - } - chunk_free(&result); - return TRUE; -} - diff --git a/src/charon/plugins/unit_tester/tests/test_id.c b/src/charon/plugins/unit_tester/tests/test_id.c new file mode 100644 index 000000000..56dab2421 --- /dev/null +++ b/src/charon/plugins/unit_tester/tests/test_id.c @@ -0,0 +1,69 @@ +/* + * Copyright (C) 2009 Martin Willi + * Hochschule fuer Technik Rapperswil + * + * 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 2 of the License, or (at your + * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>. + * + * 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. + */ + +#include <daemon.h> + +/******************************************************************************* + * identification part enumeration test + ******************************************************************************/ +bool test_id_parts() +{ + identification_t *id; + enumerator_t *enumerator; + id_part_t part; + chunk_t data; + int i = 0; + + id = identification_create_from_string("C=CH, O=strongSwan, CN=tester"); + + enumerator = id->create_part_enumerator(id); + while (enumerator->enumerate(enumerator, &part, &data)) + { + switch (i++) + { + case 0: + if (part != ID_PART_RDN_C || + !chunk_equals(data, chunk_create("CH", 2))) + { + return FALSE; + } + break; + case 1: + if (part != ID_PART_RDN_O || + !chunk_equals(data, chunk_create("strongSwan", 10))) + { + return FALSE; + } + break; + case 2: + if (part != ID_PART_RDN_CN || + !chunk_equals(data, chunk_create("tester", 6))) + { + return FALSE; + } + break; + default: + return FALSE; + } + } + if (i < 3) + { + return FALSE; + } + enumerator->destroy(enumerator); + id->destroy(id); + return TRUE; +} + diff --git a/src/charon/plugins/unit_tester/tests/test_med_db.c b/src/charon/plugins/unit_tester/tests/test_med_db.c index d65eb0cc4..7b4603bd7 100644 --- a/src/charon/plugins/unit_tester/tests/test_med_db.c +++ b/src/charon/plugins/unit_tester/tests/test_med_db.c @@ -33,8 +33,8 @@ bool test_med_db() chunk_t keyid = chunk_from_buf(keyid_buf); identification_t *id, *found; enumerator_t *enumerator; - auth_info_t *auth; public_key_t *public; + auth_cfg_t *auth; bool good = FALSE; id = identification_create_from_encoding(ID_KEY_ID, keyid); diff --git a/src/charon/plugins/unit_tester/tests/test_pool.c b/src/charon/plugins/unit_tester/tests/test_pool.c index b11f71704..ba5330fd9 100644 --- a/src/charon/plugins/unit_tester/tests/test_pool.c +++ b/src/charon/plugins/unit_tester/tests/test_pool.c @@ -25,32 +25,24 @@ static void* testing(void *thread) { - int i; - auth_info_t *auth; + int i; host_t *addr[ALLOCS]; identification_t *id[ALLOCS]; - - auth = auth_info_create(); - /* prepare identities */ for (i = 0; i < ALLOCS; i++) { char buf[256]; - snprintf(buf, sizeof(buf), "%d-%d@strongswan.org", (int)thread, i); + snprintf(buf, sizeof(buf), "%d-%d@strongswan.org", (uintptr_t)thread, i); id[i] = identification_create_from_string(buf); - if (!id[i]) - { - return (void*)FALSE; - } } /* allocate addresses */ for (i = 0; i < ALLOCS; i++) { addr[i] = charon->attributes->acquire_address(charon->attributes, - "test", id[i], auth, NULL); + "test", id[i], NULL); if (!addr[i]) { return (void*)FALSE; @@ -69,7 +61,6 @@ static void* testing(void *thread) addr[i]->destroy(addr[i]); id[i]->destroy(id[i]); } - auth->destroy(auth); return (void*)TRUE; } @@ -79,7 +70,7 @@ static void* testing(void *thread) ******************************************************************************/ bool test_pool() { - int i; + uintptr_t i; void *res; pthread_t thread[THREADS]; diff --git a/src/charon/plugins/unit_tester/tests/test_rng.c b/src/charon/plugins/unit_tester/tests/test_rng.c deleted file mode 100644 index 60cbf2d36..000000000 --- a/src/charon/plugins/unit_tester/tests/test_rng.c +++ /dev/null @@ -1,221 +0,0 @@ -/* - * Copyright (C) 2008 Martin Willi - * Hochschule fuer Technik Rapperswil - * - * 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 2 of the License, or (at your - * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>. - * - * 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. - */ - -#include <daemon.h> -#include <library.h> -#include <utils/mutex.h> - -#include <unistd.h> -#include <sched.h> -#include <pthread.h> - -static bool test_monobit(chunk_t data) -{ - int i, j, bits = 0; - - for (i = 0; i < data.len; i++) - { - for (j = 0; j < 8; j++) - { - if (data.ptr[i] & (1<<j)) - { - bits++; - } - } - } - DBG1(DBG_CFG, " Monobit: %d/%d bits set", bits, data.len * 8); - if (bits > 9654 && bits < 10346) - { - return TRUE; - } - return FALSE; -} - -static bool test_poker(chunk_t data) -{ - int i, counter[16]; - double sum = 0.0; - - memset(counter, 0, sizeof(counter)); - - for (i = 0; i < data.len; i++) - { - counter[data.ptr[i] & 0x0F]++; - counter[(data.ptr[i] & 0xF0) >> 4]++; - } - - for (i = 0; i < countof(counter); i++) - { - sum += (counter[i] * counter[i]) / 5000.0 * 16.0; - } - sum -= 5000.0; - DBG1(DBG_CFG, " Poker: %f", sum); - if (sum > 1.03 && sum < 57.4) - { - return TRUE; - } - return FALSE; -} - -static bool test_runs(chunk_t data) -{ - int i, j, zero_runs[7], one_runs[7], zero = 0, one = 0, longrun = 0; - bool ok = TRUE; - - memset(one_runs, 0, sizeof(zero_runs)); - memset(zero_runs, 0, sizeof(one_runs)); - - for (i = 0; i < data.len; i++) - { - for (j = 0; j < 8; j++) - { - if (data.ptr[i] & (1<<j)) - { - if (one) - { - if (++one >= 34) - { - longrun++; - break; - } - } - else - { - zero_runs[min(6, zero)]++; - zero = 0; - one = 1; - } - } - else - { - if (zero) - { - if (++zero >= 34) - { - longrun++; - break; - } - } - else - { - one_runs[min(6, one)]++; - one = 0; - zero = 1; - } - } - } - } - - DBG1(DBG_CFG, " Runs: zero: %d/%d/%d/%d/%d/%d, one: %d/%d/%d/%d/%d/%d, " - "longruns: %d", - zero_runs[1], zero_runs[2], zero_runs[3], - zero_runs[4], zero_runs[5], zero_runs[6], - one_runs[1], one_runs[2], one_runs[3], - one_runs[4], one_runs[5], one_runs[6], - longrun); - - if (longrun) - { - return FALSE; - } - - for (i = 1; i < countof(zero_runs); i++) - { - switch (i) - { - case 1: - ok &= zero_runs[i] > 2267 && zero_runs[i] < 2733; - ok &= one_runs[i] > 2267 && one_runs[i] < 2733; - break; - case 2: - ok &= zero_runs[i] > 1079 && zero_runs[i] < 1421; - ok &= one_runs[i] > 1079 && one_runs[i] < 1421; - break; - case 3: - ok &= zero_runs[i] > 502 && zero_runs[i] < 748; - ok &= one_runs[i] > 502 && one_runs[i] < 748; - break; - case 4: - ok &= zero_runs[i] > 223 && zero_runs[i] < 402; - ok &= one_runs[i] > 223 && one_runs[i] < 402; - break; - case 5: - ok &= zero_runs[i] > 90 && zero_runs[i] < 223; - ok &= one_runs[i] > 90 && one_runs[i] < 223; - break; - case 6: - ok &= zero_runs[i] > 90 && zero_runs[i] < 223; - ok &= one_runs[i] > 90 && one_runs[i] < 223; - break; - } - if (!ok) - { - return FALSE; - } - } - return TRUE; -} - -static bool test_rng_quality(rng_quality_t quality) -{ - rng_t *rng; - chunk_t chunk; - - rng = lib->crypto->create_rng(lib->crypto, quality); - if (!rng) - { - return FALSE; - } - DBG1(DBG_CFG, "%N", rng_quality_names, quality); - rng->allocate_bytes(rng, 2500, &chunk); - - if (!test_monobit(chunk)) - { - return FALSE; - } - if (!test_poker(chunk)) - { - return FALSE; - } - if (!test_runs(chunk)) - { - return FALSE; - } - - free(chunk.ptr); - rng->destroy(rng); - return TRUE; -} - -/** - * run a test using given values - */ -bool test_rng() -{ - if (!test_rng_quality(RNG_WEAK)) - { - return FALSE; - } - if (!test_rng_quality(RNG_STRONG)) - { - return FALSE; - } - if (!test_rng_quality(RNG_REAL)) - { - return FALSE; - } - return TRUE; -} - diff --git a/src/charon/plugins/unit_tester/tests/test_rsa_gen.c b/src/charon/plugins/unit_tester/tests/test_rsa_gen.c index f13bb5bbf..1b7af63ee 100644 --- a/src/charon/plugins/unit_tester/tests/test_rsa_gen.c +++ b/src/charon/plugins/unit_tester/tests/test_rsa_gen.c @@ -22,7 +22,7 @@ bool test_rsa_gen() { char buf[] = {0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08}; - chunk_t data = chunk_from_buf(buf), sig; + chunk_t data = chunk_from_buf(buf), sig, crypt, plain; private_key_t *private; public_key_t *public; u_int key_size; @@ -59,6 +59,24 @@ bool test_rsa_gen() return FALSE; } free(sig.ptr); + if (!public->encrypt(public, data, &crypt)) + { + DBG1(DBG_CFG, "encrypting data with RSA failed"); + return FALSE; + } + if (!private->decrypt(private, crypt, &plain)) + { + DBG1(DBG_CFG, "decrypting data with RSA failed"); + return FALSE; + } + if (!chunk_equals(data, plain)) + { + DBG1(DBG_CFG, "decrpyted data invalid, expected %B, got %B", & + data, &plain); + return FALSE; + } + chunk_clear(&crypt); + chunk_clear(&plain); public->destroy(public); private->destroy(private); } diff --git a/src/charon/plugins/unit_tester/unit_tester.c b/src/charon/plugins/unit_tester/unit_tester.c index 28c6b4c11..c9651e601 100644 --- a/src/charon/plugins/unit_tester/unit_tester.c +++ b/src/charon/plugins/unit_tester/unit_tester.c @@ -11,8 +11,6 @@ * 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. - * - * $Id: unit_tester.c 3491 2008-02-22 14:04:00Z martin $ */ #include "unit_tester.h" diff --git a/src/charon/plugins/unit_tester/unit_tester.h b/src/charon/plugins/unit_tester/unit_tester.h index 760b0389b..33b13313d 100644 --- a/src/charon/plugins/unit_tester/unit_tester.h +++ b/src/charon/plugins/unit_tester/unit_tester.h @@ -11,8 +11,6 @@ * 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. - * - * $Id: unit_tester.h 5003 2009-03-24 17:43:01Z martin $ */ /** |