auth-vector verified

This commit is contained in:
Sukchan Lee 2017-03-03 23:35:17 +09:00
parent 1159b49bda
commit 4882496313
12 changed files with 166 additions and 39 deletions

View File

@ -85,9 +85,9 @@ extern "C" {
}
CORE_DECLARE(status_t) core_generate_random_bytes(
unsigned char *buf, int length);
c_uint8_t *buf, int length);
CORE_DECLARE(void *) core_ascii_to_hex(char *in, int len, char *out);
CORE_DECLARE(void *) core_ascii_to_hex(char *in, int len, void *out);
CORE_DECLARE(void *) core_int_to_buffer(c_uint64_t num,
c_uint8_t *buffer, int size);

View File

@ -1,22 +1,28 @@
#include "core_errno.h"
#include "core_lib.h"
void *core_ascii_to_hex(char *in, int len, char *out)
void *core_ascii_to_hex(char *in, int len, void *out)
{
int i, j, high, low;
for (i = 0, j = 0; i < len; i+=2, j+=1)
int i = 0, j = 0, k = 0, high, low;
c_uint8_t *out_p = out;
while(i < len)
{
high = c_isdigit(in[i]) ? in[i] - '0' :
c_islower(in[i]) ? in[i] - 'a' + 10 : in[i] - 'A' + 10;
low = c_isdigit(in[i+1]) ? in[i+1] - '0' :
c_islower(in[i+1]) ? in[i+1] - 'a' + 10 : in[i+1] - 'A' + 10;
#if 0
high = in[i] > '9' ? in[i] - 'A' + 10 : in[i] - '0';
low = in[i+1] > '9' ? in[i+1] - 'A' + 10 : in[i+1] - '0';
#endif
out[j] = (high << 4) | low;
if (!c_isspace(in[i]))
{
low = c_isdigit(in[i]) ? in[i] - '0' :
c_islower(in[i]) ? in[i] - 'a' + 10 : in[i] - 'A' + 10;
if ((k & 0x1) == 0)
{
high = low;
}
else
{
out_p[j] = (high << 4) | low;
j++;
}
k++;
}
i++;
}
return out;

View File

@ -2,7 +2,7 @@
#define DEV_RANDOM "/dev/urandom"
status_t core_generate_random_bytes(unsigned char *buf, int length)
status_t core_generate_random_bytes(c_uint8_t *buf, int length)
{
int fd = -1;

View File

@ -11,15 +11,15 @@ static void misc_test1(abts_case *tc, void *data)
static void misc_test2(abts_case *tc, void *data)
{
#define K "465B5CE8B199B49FAA5F0A2EE238A6BC"
#define OP "5F1D289C5D354D0A140C2548F5F3E3BA"
#define OPc "E8ED289DEBA952E4283B54E88E6183CA"
#define K "4 6 5B5 CE8 B199B49FAA5F0A2EE238A6BC "
#define OP "5F1D289C 5D354D0A 140C2548 F5F3E3BA"
#define OPc "E8ED2 89D EBA9 52E4 283B 54E8 8E61 83CA"
#define AMF "8000"
c_uint8_t k[16] = "\x46\x5B\x5C\xE8\xB1\x99\xB4\x9F\xAA\x5F\x0A\x2E\xE2\x38\xA6\xBC";
c_uint8_t op[16] = "\x5F\x1D\x28\x9C\x5D\x35\x4D\x0A\x14\x0C\x25\x48\xF5\xF3\xE3\xBA";
c_uint8_t opc[16] = "\xE8\xED\x28\x9D\xEB\xA9\x52\xE4\x28\x3B\x54\xE8\x8E\x61\x83\xCA";
c_uint8_t amf[2] = { 0x80, 0x00 };
#define LOWER "12abcdEF"
#define LOWER " 12abcdE F"
c_uint8_t lower[4] = "\x12\xab\xcd\xef";
char buffer[16];

View File

@ -4,7 +4,7 @@
#include "core_sha2_hmac.h"
void derive_kasme(const c_uint8_t *ck, const c_uint8_t *ik,
const c_uint8_t plmn[3], const c_uint8_t *sqn, const c_uint8_t *ak,
const c_uint8_t plmn_id[3], const c_uint8_t *sqn, const c_uint8_t *ak,
c_uint8_t *kasme)
{
c_uint8_t s[14];
@ -12,10 +12,10 @@ void derive_kasme(const c_uint8_t *ck, const c_uint8_t *ik,
int i;
memcpy(&k[0], ck, 16);
memcpy(&k[0], ik, 16);
memcpy(&k[16], ik, 16);
s[0] = 0x10;
memcpy(&s[1], plmn, 3);
memcpy(&s[1], plmn_id, 3);
s[4] = 0x00;
s[5] = 0x03;

View File

@ -4,7 +4,7 @@
#include "core.h"
void derive_kasme(const c_uint8_t *ck, const c_uint8_t *ik,
const c_uint8_t plmn[3], const c_uint8_t *sqn, const c_uint8_t *ak,
const c_uint8_t plmn_id[3], const c_uint8_t *sqn, const c_uint8_t *ak,
c_uint8_t *kasme);
#endif /* __3GPP_KDF_H__ */

View File

@ -189,19 +189,11 @@ int milenage_f2345(const c_uint8_t *opc, const c_uint8_t *k,
* @res: Buffer for RES = 64-bit signed response (f2), or %NULL
* @res_len: Max length for res; set to used length or 0 on failure
*/
void aaaa(const c_uint8_t *opc, const c_uint8_t *amf,
const c_uint8_t *k, const c_uint8_t *sqn, const c_uint8_t *_rand,
c_uint8_t *autn, c_uint8_t *ik, c_uint8_t *ck, c_uint8_t *ak,
c_uint8_t *res, size_t *res_len)
{
}
void milenage_generate(const c_uint8_t *opc, const c_uint8_t *amf,
const c_uint8_t *k, const c_uint8_t *sqn, const c_uint8_t *_rand,
c_uint8_t *autn, c_uint8_t *ik, c_uint8_t *ck, c_uint8_t *ak,
c_uint8_t *res, size_t *res_len)
{
#if 0
int i;
c_uint8_t mac_a[8];
@ -221,10 +213,8 @@ void milenage_generate(const c_uint8_t *opc, const c_uint8_t *amf,
autn[i] = sqn[i] ^ ak[i];
os_memcpy(autn + 6, amf, 2);
os_memcpy(autn + 8, mac_a, 8);
#endif
}
/**
* milenage_auts - Milenage AUTS validation
* @opc: OPc = 128-bit operator variant algorithm configuration field (encr.)

View File

@ -31,8 +31,5 @@ int milenage_f2345(const c_uint8_t *opc, const c_uint8_t *k,
c_uint8_t *ak, c_uint8_t *akstar);
void milenage_opc(const c_uint8_t *k, const c_uint8_t *op, c_uint8_t *opc);
void derive_kasme(const c_uint8_t *ck, const c_uint8_t *ik,
const c_uint8_t plmn[3], const c_uint8_t *sqn, const c_uint8_t *ak,
c_uint8_t *kasme);
#endif /* __MILENAGE_H__ */

View File

@ -7,7 +7,8 @@ testcellwire_SOURCES = \
abts.c testutil.c \
s1ap_enb_build.c \
s1ap_message_test.c nas_message_test.c \
enb_setup_test.c
enb_setup_test.c \
security_test.c
testcellwire_LDADD = \
$(top_srcdir)/src/libcellwire.la

View File

@ -26,6 +26,7 @@ const struct testlist {
{test_s1ap_message},
{test_enb_setup},
{test_nas_message},
{test_security},
};
#endif /* APR_TEST_INCLUDES */

131
test/security_test.c Normal file
View File

@ -0,0 +1,131 @@
#include "core_lib.h"
#include "core_debug.h"
#include "core_sha2_hmac.h"
#include "milenage.h"
#include "kasme.h"
#include "testutil.h"
static void security_test1(abts_case *tc, void *data)
{
char *_k = "465b5ce8 b199b49f aa5f0a2e e238a6bc";
char *_rand = "23553cbe 9637a89d 218ae64d ae47bf35";
char *_sqn = "ff9bb4d0 b607";
char *_amf = "b9b9";
char *_op = "cdc202d5 123e20f6 2b6d676a c72cb318";
char *_opc = "cd63cb71 954a9f4e 48a5994e 37a02baf";
char *_mac_a = "4a9ffac3 54dfafb3";
char *_mac_s = "01cfaf9e c4e871e9";
char *_res = "a54211d5 e3ba50bf";
char *_ck = "b40ba9a3 c58b2a05 bbf0d987 b21bf8cb";
char *_ik = "f769bcd7 51044604 12767271 1c6d3441";
char *_ak = "aa689c64 8370";
char *_akstar = "451e8bec a43b";
c_uint8_t k[16];
c_uint8_t rand[16];
c_uint8_t op[16];
c_uint8_t opc[16];
c_uint8_t sqn[6];
c_uint8_t amf[2];
c_uint8_t mac_a[8];
c_uint8_t mac_s[8];
c_uint8_t res[8];
c_uint8_t ck[16];
c_uint8_t ik[16];
c_uint8_t ak[6];
c_uint8_t akstar[6];
c_uint8_t tmp[16];
milenage_opc(
core_ascii_to_hex(_k, strlen(_k), k),
core_ascii_to_hex(_op, strlen(_op), op),
opc);
ABTS_TRUE(tc, memcmp(opc,
core_ascii_to_hex(_opc, strlen(_opc), tmp), 16) == 0);
milenage_f1(opc, k,
core_ascii_to_hex(_rand, strlen(_rand), rand),
core_ascii_to_hex(_sqn, strlen(_sqn), sqn),
core_ascii_to_hex(_amf, strlen(_amf), amf),
mac_a, mac_s);
ABTS_TRUE(tc, memcmp(mac_a,
core_ascii_to_hex(_mac_a, strlen(_mac_a), tmp), 8) == 0);
ABTS_TRUE(tc, memcmp(mac_s,
core_ascii_to_hex(_mac_s, strlen(_mac_s), tmp), 8) == 0);
milenage_f2345(opc, k, rand, res, ck, ik, ak, akstar);
ABTS_TRUE(tc, memcmp(res,
core_ascii_to_hex(_res, strlen(_res), tmp), 8) == 0);
ABTS_TRUE(tc, memcmp(ck,
core_ascii_to_hex(_ck, strlen(_ck), tmp), 16) == 0);
ABTS_TRUE(tc, memcmp(ik,
core_ascii_to_hex(_ik, strlen(_ik), tmp), 16) == 0);
ABTS_TRUE(tc, memcmp(ak,
core_ascii_to_hex(_ak, strlen(_ak), tmp), 6) == 0);
ABTS_TRUE(tc, memcmp(akstar,
core_ascii_to_hex(_akstar, strlen(_akstar), tmp), 6) == 0);
}
static void security_test2(abts_case *tc, void *data)
{
char *_key = "4a656665";
char *_message = "7768617420646f2079612077616e7420666f72206e6f7468696e673f";
char *_hmac = "5bdcc146bf60754e6a042426089575c75a003f089d2739839dec58b964ec3843";
c_uint8_t key[4];
c_uint8_t message[28];
c_uint8_t hmac[32];
c_uint8_t tmp[32];
hmac_sha256(
core_ascii_to_hex(_key, strlen(_key), key),
4,
core_ascii_to_hex(_message, strlen(_message), message),
28,
hmac, 32);
ABTS_TRUE(tc, memcmp(hmac,
core_ascii_to_hex(_hmac, strlen(_hmac), tmp), 32) == 0);
}
static void security_test3(abts_case *tc, void *data)
{
char *_ck = "B40BA9A3C58B2A05BBF0D987B21BF8CB";
char *_ik = "F769BCD751044604127672711C6D3441";
char *_plmn_id = "024830";
char *_sqn = "FD8EEF40DF7D";
char *_ak = "AA689C648370";
char *_kasme = "238E457E0F758BADBCA8D34BB2612C10428D426757CB5553B2B184FA64BFC549";
c_uint8_t ck[16];
c_uint8_t ik[16];
c_uint8_t plmn_id[3];
c_uint8_t sqn[6];
c_uint8_t ak[6];
c_uint8_t kasme[32];
c_uint8_t tmp[32];
derive_kasme(
core_ascii_to_hex(_ck, strlen(_ck), ck),
core_ascii_to_hex(_ik, strlen(_ik), ik),
core_ascii_to_hex(_plmn_id, strlen(_plmn_id), plmn_id),
core_ascii_to_hex(_sqn, strlen(_sqn), sqn),
core_ascii_to_hex(_ak, strlen(_ak), ak),
kasme);
ABTS_TRUE(tc, memcmp(kasme,
core_ascii_to_hex(_kasme, strlen(_kasme), tmp), 32) == 0);
}
abts_suite *test_security(abts_suite *suite)
{
suite = ADD_SUITE(suite)
abts_run_test(suite, security_test1, NULL);
abts_run_test(suite, security_test2, NULL);
abts_run_test(suite, security_test3, NULL);
return suite;
}

View File

@ -60,5 +60,6 @@ void test_initialize(void);
abts_suite *test_s1ap_message(abts_suite *suite);
abts_suite *test_enb_setup(abts_suite *suite);
abts_suite *test_nas_message(abts_suite *suite);
abts_suite *test_security(abts_suite *suite);
#endif /* CORE_TEST_INCLUDES */