From e076ac087cb568ad0748f4d8469e6dcda811d7c8 Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Wed, 7 Dec 2011 00:10:18 +0100 Subject: add autotest script for milenage/auth testing --- tests/Makefile.am | 2 +- tests/auth/Makefile.am | 8 +++++ tests/auth/milenage_test.c | 78 +++++++++++++++++++++++++++++++++++++++++++++ tests/auth/milenage_test.ok | 8 +++++ tests/testsuite.at | 6 ++++ 5 files changed, 101 insertions(+), 1 deletion(-) create mode 100644 tests/auth/Makefile.am create mode 100644 tests/auth/milenage_test.c create mode 100644 tests/auth/milenage_test.ok (limited to 'tests') diff --git a/tests/Makefile.am b/tests/Makefile.am index c7d16aa3..9f52ae70 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -1,5 +1,5 @@ if ENABLE_TESTS -SUBDIRS = timer sms ussd smscb bits a5 conv +SUBDIRS = timer sms ussd smscb bits a5 conv auth if ENABLE_MSGFILE SUBDIRS += msgfile endif diff --git a/tests/auth/Makefile.am b/tests/auth/Makefile.am new file mode 100644 index 00000000..52976d02 --- /dev/null +++ b/tests/auth/Makefile.am @@ -0,0 +1,8 @@ +INCLUDES = $(all_includes) -I$(top_srcdir)/include +noinst_PROGRAMS = milenage_test +EXTRA_DIST = milenage_test.ok + +milenage_test_SOURCES = milenage_test.c +milenage_test_LDADD = $(top_builddir)/src/libosmocore.la \ + $(top_builddir)/src/gsm/libosmogsm.la + diff --git a/tests/auth/milenage_test.c b/tests/auth/milenage_test.c new file mode 100644 index 00000000..a143d26d --- /dev/null +++ b/tests/auth/milenage_test.c @@ -0,0 +1,78 @@ + +#include +#include +#include +#include + +#include +#include + +static void dump_auth_vec(struct osmo_auth_vector *vec) +{ + printf("RAND:\t%s\n", osmo_hexdump(vec->rand, sizeof(vec->rand))); + + if (vec->auth_types & OSMO_AUTH_TYPE_UMTS) { + printf("AUTN:\t%s\n", osmo_hexdump(vec->autn, sizeof(vec->autn))); + printf("IK:\t%s\n", osmo_hexdump(vec->ik, sizeof(vec->ik))); + printf("CK:\t%s\n", osmo_hexdump(vec->ck, sizeof(vec->ck))); + printf("RES:\t%s\n", osmo_hexdump(vec->res, vec->res_len)); + } + + if (vec->auth_types & OSMO_AUTH_TYPE_GSM) { + printf("SRES:\t%s\n", osmo_hexdump(vec->sres, sizeof(vec->sres))); + printf("Kc:\t%s\n", osmo_hexdump(vec->kc, sizeof(vec->kc))); + } +} + +static struct osmo_sub_auth_data test_aud = { + .type = OSMO_AUTH_TYPE_UMTS, + .algo = OSMO_AUTH_ALG_MILENAGE, + .umts = { + .opc = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, + 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f }, + .k = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, + 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f }, + .amf = { 0x00, 0x00 }, + .sqn = 0x22, + }, +}; + +int main(int argc, char **argv) +{ + struct osmo_auth_vector _vec; + struct osmo_auth_vector *vec = &_vec; + uint8_t _rand[16]; + int rc; + +#if 0 + srand(time(NULL)); + *(uint32_t *)&_rand[0] = rand(); + *(uint32_t *)(&_rand[4]) = rand(); + *(uint32_t *)(&_rand[8]) = rand(); + *(uint32_t *)(&_rand[12]) = rand(); +#else + memset(_rand, 0, sizeof(_rand)); +#endif + memset(vec, 0, sizeof(*vec)); + + rc = osmo_auth_gen_vec(vec, &test_aud, _rand); + if (rc < 0) { + fprintf(stderr, "error generating auth vector\n"); + exit(1); + } + + dump_auth_vec(vec); + + const uint8_t auts[14] = { 0x87, 0x11, 0xa0, 0xec, 0x9e, 0x16, 0x37, 0xdf, + 0x17, 0xf8, 0x0b, 0x38, 0x4e, 0xe4 }; + + rc = osmo_auth_gen_vec_auts(vec, &test_aud, auts, _rand, _rand); + if (rc < 0) { + printf("AUTS failed\n"); + } else { + printf("AUTS success: SEQ.MS = %lu\n", test_aud.umts.sqn); + } + + exit(0); + +} diff --git a/tests/auth/milenage_test.ok b/tests/auth/milenage_test.ok new file mode 100644 index 00000000..7e33278d --- /dev/null +++ b/tests/auth/milenage_test.ok @@ -0,0 +1,8 @@ +RAND: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 +AUTN: ec 93 20 c2 c2 12 00 00 c8 b7 de 2a 34 49 f1 bd +IK: 12 cb 2d d3 e0 ec 83 78 f6 fc 1d 60 6c 61 9f 47 +CK: 72 00 a1 84 d8 f2 c7 58 fb df 87 90 0d db f2 75 +RES: e9 fc 88 cc c8 a3 53 81 +SRES: 21 5f db 4d +Kc: 6d e8 16 a7 59 a4 29 12 +AUTS success: SEQ.MS = 33 diff --git a/tests/testsuite.at b/tests/testsuite.at index 237b6208..a503c5db 100644 --- a/tests/testsuite.at +++ b/tests/testsuite.at @@ -53,3 +53,9 @@ AT_KEYWORDS([ussd]) cat $abs_srcdir/ussd/ussd_test.ok > expout AT_CHECK([$abs_top_builddir/tests/ussd/ussd_test], [], [expout], [ignore]) AT_CLEANUP + +AT_SETUP([auth]) +AT_KEYWORDS([auth]) +cat $abs_srcdir/auth/milenage_test.ok > expout +AT_CHECK([$abs_top_builddir/tests/auth/milenage_test], [], [expout], [ignore]) +AT_CLEANUP -- cgit v1.2.3