forked from acouzens/open5gs
add test vector for security
This commit is contained in:
parent
0bd56d0e49
commit
713d786f0c
|
@ -70,7 +70,7 @@ AM_PROG_AR
|
|||
AM_PROG_LIBTOOL
|
||||
|
||||
dnl Checks for compile flag
|
||||
# AX_CHECK_COMPILE_FLAG([-Wno-pointer-to-int-cast], [CFLAGS="$CFLAGS -Wno-pointer-to-int-cast"])
|
||||
AX_CHECK_COMPILE_FLAG([-Wno-unused-result], [CFLAGS="$CFLAGS -Wno-unused-result"])
|
||||
|
||||
dnl Checks for pointer size
|
||||
AC_CHECK_SIZEOF(void*, 4)
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
__type *free[__size], pool[__size]; \
|
||||
mutex_id mut; \
|
||||
} pool_##__name##_t; \
|
||||
pool_##__name##_t __name
|
||||
static pool_##__name##_t __name
|
||||
|
||||
#define pool_init(__pname, __size) do { \
|
||||
int __i; \
|
||||
|
|
|
@ -20,7 +20,6 @@ typedef char type_of_tpool1;
|
|||
typedef pt_type1 type_of_tpool2;
|
||||
|
||||
pool_declare(tpool1, type_of_tpool1, SIZE_OF_TPOOL1);
|
||||
pool_declare(tpool2, type_of_tpool2, SIZE_OF_TPOOL2);
|
||||
|
||||
static void pool_test_core1(abts_case *tc, void *data, int start)
|
||||
{
|
||||
|
|
|
@ -11,7 +11,8 @@ libs6a_la_SOURCES = \
|
|||
nodist_libs6a_la_SOURCES = \
|
||||
milenage.c \
|
||||
s6a_init.c s6a_config.c s6a_fd.c s6a_app.c s6a_dict.c \
|
||||
s6a_hss.c s6a_mme.c
|
||||
hss_ctx.c hss_init.c \
|
||||
mme_init.c
|
||||
|
||||
libs6a_la_DEPENDENCIES = \
|
||||
$(top_srcdir)/lib/s6a/freeDiameter/libs6afreeDiameter.la
|
||||
|
|
|
@ -0,0 +1,94 @@
|
|||
#define TRACE_MODULE _s6a_hss_ctx
|
||||
|
||||
#include "core_debug.h"
|
||||
#include "core_pool.h"
|
||||
|
||||
#include "hss_ctx.h"
|
||||
|
||||
pool_declare(ue_pool, ue_ctx_t, SIZE_OF_UE_POOL);
|
||||
|
||||
static list_t g_ue_list;
|
||||
|
||||
status_t hss_ctx_init(void)
|
||||
{
|
||||
pool_init(&ue_pool, SIZE_OF_UE_POOL);
|
||||
|
||||
return CORE_OK;
|
||||
}
|
||||
|
||||
void hss_ctx_final(void)
|
||||
{
|
||||
pool_final(&ue_pool);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
ue_ctx_t* hss_ue_ctx_add()
|
||||
{
|
||||
ue_ctx_t *ue = NULL;
|
||||
|
||||
/* Allocate new eNB context */
|
||||
pool_alloc_node(&ue_pool, &ue);
|
||||
d_assert(ue, return NULL, "HSS-UE context allocation failed");
|
||||
|
||||
/* Initialize eNB context */
|
||||
memset(ue, 0, sizeof(ue_ctx_t));
|
||||
|
||||
/* Add new eNB context to list */
|
||||
list_append(&g_ue_list, ue);
|
||||
|
||||
return ue;
|
||||
}
|
||||
|
||||
status_t hss_ue_ctx_remove(ue_ctx_t *ue)
|
||||
{
|
||||
d_assert(ue, return CORE_ERROR, "Null param");
|
||||
|
||||
list_remove(&g_ue_list, ue);
|
||||
pool_free_node(&ue_pool, ue);
|
||||
|
||||
return CORE_OK;
|
||||
}
|
||||
|
||||
status_t hss_ue_ctx_remove_all()
|
||||
{
|
||||
ue_ctx_t *ue = NULL, *next_ue = NULL;
|
||||
|
||||
ue = list_first(&g_ue_list);
|
||||
while (ue)
|
||||
{
|
||||
next_ue = list_next(ue);
|
||||
|
||||
hss_ue_ctx_remove(ue);
|
||||
|
||||
ue = next_ue;
|
||||
}
|
||||
|
||||
return CORE_OK;
|
||||
}
|
||||
|
||||
ue_ctx_t* hss_ue_ctx_find_by_imsi(c_uint8_t *imsi)
|
||||
{
|
||||
ue_ctx_t *ue = NULL;
|
||||
|
||||
ue = list_first(&g_ue_list);
|
||||
while (ue)
|
||||
{
|
||||
if (memcmp(ue->imsi, imsi, ue->imsi_len) == 0)
|
||||
break;
|
||||
|
||||
ue = list_next(ue);
|
||||
}
|
||||
|
||||
return ue;
|
||||
}
|
||||
|
||||
ue_ctx_t* hss_ue_ctx_first()
|
||||
{
|
||||
return list_first(&g_ue_list);
|
||||
}
|
||||
|
||||
ue_ctx_t* hss_ue_ctx_next(ue_ctx_t *ue)
|
||||
{
|
||||
return list_next(ue);
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
#ifndef __S6A_HSS_CTX_H__
|
||||
#define __S6A_HSS_CTX_H__
|
||||
|
||||
#include "core_list.h"
|
||||
#include "core_errno.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#define SIZE_OF_UE_POOL 128
|
||||
|
||||
#define MAX_IMSI_LEN 15
|
||||
#define MAX_KEY_LEN 16
|
||||
#define MAX_AMF_LEN 2
|
||||
|
||||
typedef struct _ue_ctx_t {
|
||||
lnode_t node; /**< A node of list_t */
|
||||
|
||||
c_uint8_t imsi[MAX_IMSI_LEN+1];
|
||||
c_uint8_t imsi_len;
|
||||
|
||||
c_uint8_t k[MAX_KEY_LEN];
|
||||
c_uint8_t op[MAX_KEY_LEN];
|
||||
c_uint8_t opc[MAX_KEY_LEN];
|
||||
c_uint8_t amf[MAX_AMF_LEN];
|
||||
} ue_ctx_t;
|
||||
|
||||
CORE_DECLARE(status_t) hss_ctx_init(void);
|
||||
CORE_DECLARE(void) hss_ctx_final(void);
|
||||
|
||||
CORE_DECLARE(ue_ctx_t*) hss_ue_ctx_add(void);
|
||||
CORE_DECLARE(status_t) hss_ue_ctx_remove(ue_ctx_t *ue);
|
||||
CORE_DECLARE(status_t) hss_ue_ctx_remove_all(void);
|
||||
CORE_DECLARE(ue_ctx_t*) hss_ue_ctx_find_by_imsi(c_uint8_t *imsi);
|
||||
CORE_DECLARE(ue_ctx_t*) hss_ue_ctx_first(void);
|
||||
CORE_DECLARE(ue_ctx_t*) hss_ue_ctx_next(ue_ctx_t *ue);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* !__S6A_HSS_CTX_H__ */
|
|
@ -1,14 +1,16 @@
|
|||
#define TRACE_MODULE _s6a_hss
|
||||
#define TRACE_MODULE _s6a_hss_init
|
||||
|
||||
#include "core_debug.h"
|
||||
#include "core_pool.h"
|
||||
|
||||
#include "hss_ctx.h"
|
||||
#include "s6a_app.h"
|
||||
|
||||
static struct disp_hdl *s6a_hdl_fb = NULL; /* handler for fallback cb */
|
||||
static struct disp_hdl *s6a_hdl_tr = NULL; /* handler for Test-Request req cb */
|
||||
static struct disp_hdl *hss_hdl_fb = NULL; /* handler for fallback cb */
|
||||
static struct disp_hdl *hss_hdl_tr = NULL; /* handler for Test-Request req cb */
|
||||
|
||||
/* Default callback for the application. */
|
||||
static int s6a_fb_cb(struct msg **msg, struct avp *avp,
|
||||
static int hss_fb_cb(struct msg **msg, struct avp *avp,
|
||||
struct session *sess, void *opaque, enum disp_action *act)
|
||||
{
|
||||
/* This CB should never be called */
|
||||
|
@ -18,7 +20,7 @@ static int s6a_fb_cb(struct msg **msg, struct avp *avp,
|
|||
}
|
||||
|
||||
/* Callback for incoming Test-Request messages */
|
||||
static int s6a_air_cb( struct msg **msg, struct avp *avp,
|
||||
static int hss_air_cb( struct msg **msg, struct avp *avp,
|
||||
struct session *sess, void *opaque, enum disp_action *act)
|
||||
{
|
||||
struct msg *ans, *qry;
|
||||
|
@ -100,33 +102,76 @@ out:
|
|||
return -1;
|
||||
}
|
||||
|
||||
int s6a_hss_init(void)
|
||||
int hss_init(void)
|
||||
{
|
||||
struct disp_when data;
|
||||
|
||||
|
||||
hss_ctx_init();
|
||||
|
||||
/* FIXME : this is a sample UE for testing */
|
||||
{
|
||||
ue_ctx_t *ue;
|
||||
|
||||
char k[16] = "\x46\x5B\x5C\xE8\xB1\x99\xB4\x9F\xAA\x5F\x0A\x2E\xE2\x38\xA6\xBC";
|
||||
char op[16] = "\x5F\x1D\x28\x9C\x5D\x35\x4D\x0A\x14\x0C\x25\x48\xF5\xF3\xE3\xBA";
|
||||
char opc[16] = "\xE8\xED\x28\x9D\xEB\xA9\x52\xE4\x28\x3B\x54\xE8\x8E\x61\x83\xCA";
|
||||
char amf[2] = { 0x80, 0x00 };
|
||||
|
||||
ue = hss_ue_ctx_add();
|
||||
d_assert(ue, return -1, "UE context add failed");
|
||||
|
||||
#define UE1_IMSI "001010123456800"
|
||||
strcpy((char*)ue->imsi, UE1_IMSI);
|
||||
ue->imsi_len = strlen(UE1_IMSI);
|
||||
|
||||
memcpy(ue->k, k, MAX_KEY_LEN);
|
||||
memcpy(ue->op, op, MAX_KEY_LEN);
|
||||
memcpy(ue->opc, opc, MAX_KEY_LEN);
|
||||
memcpy(ue->amf, amf, MAX_AMF_LEN);
|
||||
|
||||
ue = hss_ue_ctx_add();
|
||||
d_assert(ue, return -1, "UE context add failed");
|
||||
|
||||
#define UE2_IMSI "001010123456796"
|
||||
strcpy((char*)ue->imsi, UE2_IMSI);
|
||||
ue->imsi_len = strlen(UE2_IMSI);
|
||||
|
||||
memcpy(ue->k, k, MAX_KEY_LEN);
|
||||
memcpy(ue->op, op, MAX_KEY_LEN);
|
||||
memcpy(ue->opc, opc, MAX_KEY_LEN);
|
||||
memcpy(ue->amf, amf, MAX_AMF_LEN);
|
||||
}
|
||||
|
||||
memset(&data, 0, sizeof(data));
|
||||
data.app = s6a_appli;
|
||||
data.command = s6a_cmd_air;
|
||||
|
||||
/* fallback CB if command != unexpected message received */
|
||||
d_assert(fd_disp_register(s6a_fb_cb, DISP_HOW_APPID, &data, NULL,
|
||||
&s6a_hdl_fb) == 0, return -1,);
|
||||
d_assert(fd_disp_register(hss_fb_cb, DISP_HOW_APPID, &data, NULL,
|
||||
&hss_hdl_fb) == 0, return -1,);
|
||||
|
||||
/* Now specific handler for Authentication-Information-Request */
|
||||
d_assert(fd_disp_register(s6a_air_cb, DISP_HOW_CC, &data, NULL,
|
||||
&s6a_hdl_tr) == 0, return -1,);
|
||||
d_assert(fd_disp_register(hss_air_cb, DISP_HOW_CC, &data, NULL,
|
||||
&hss_hdl_tr) == 0, return -1,);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void s6a_hss_final(void)
|
||||
void hss_final(void)
|
||||
{
|
||||
if (s6a_hdl_fb) {
|
||||
(void) fd_disp_unregister(&s6a_hdl_fb, NULL);
|
||||
if (hss_hdl_fb) {
|
||||
(void) fd_disp_unregister(&hss_hdl_fb, NULL);
|
||||
}
|
||||
if (s6a_hdl_tr) {
|
||||
(void) fd_disp_unregister(&s6a_hdl_tr, NULL);
|
||||
if (hss_hdl_tr) {
|
||||
(void) fd_disp_unregister(&hss_hdl_tr, NULL);
|
||||
}
|
||||
|
||||
/* FIXME : this is a sample UE for testing */
|
||||
{
|
||||
hss_ue_ctx_remove_all();
|
||||
}
|
||||
|
||||
hss_ctx_final();
|
||||
|
||||
return;
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
#define TRACE_MODULE _s6a_mme
|
||||
#define TRACE_MODULE _s6a_mme_init
|
||||
|
||||
#include "core_debug.h"
|
||||
|
||||
|
@ -6,7 +6,7 @@
|
|||
|
||||
struct session_handler *s6a_mme_reg = NULL;
|
||||
|
||||
int s6a_mme_init(void)
|
||||
int mme_init(void)
|
||||
{
|
||||
d_assert(fd_sess_handler_create(&s6a_mme_reg,
|
||||
(void *)free, NULL, NULL) == 0, return -1,);
|
||||
|
@ -14,7 +14,7 @@ int s6a_mme_init(void)
|
|||
return 0;
|
||||
}
|
||||
|
||||
void s6a_mme_final(void)
|
||||
void mme_final(void)
|
||||
{
|
||||
d_assert(fd_sess_handler_destroy(&s6a_mme_reg, NULL) == 0,,);
|
||||
};
|
||||
}
|
|
@ -97,12 +97,12 @@ int s6a_app_init(int mode)
|
|||
|
||||
/* Start the signal handler thread */
|
||||
if (s6a_config->mode & MODE_MME) {
|
||||
CHECK_FCT( s6a_mme_init() );
|
||||
CHECK_FCT( mme_init() );
|
||||
}
|
||||
|
||||
/* Install the handlers for incoming messages */
|
||||
if (s6a_config->mode & MODE_HSS) {
|
||||
CHECK_FCT( s6a_hss_init() );
|
||||
CHECK_FCT( hss_init() );
|
||||
}
|
||||
|
||||
/* Advertise the support for the test application in the peer */
|
||||
|
@ -118,9 +118,9 @@ int s6a_app_init(int mode)
|
|||
void s6a_app_final(void)
|
||||
{
|
||||
if (s6a_config->mode & MODE_MME)
|
||||
s6a_mme_final();
|
||||
mme_final();
|
||||
if (s6a_config->mode & MODE_HSS)
|
||||
s6a_hss_final();
|
||||
hss_final();
|
||||
|
||||
CHECK_FCT_DO( fd_thr_term(&s6a_stats_th), );
|
||||
CHECK_POSIX_DO( pthread_mutex_destroy(&s6a_config->stats_lock), );
|
||||
|
|
|
@ -137,17 +137,17 @@ CORE_DECLARE(void) s6a_fd_final();
|
|||
CORE_DECLARE(int) s6a_app_init(int mode);
|
||||
CORE_DECLARE(void) s6a_app_final(void);
|
||||
|
||||
CORE_DECLARE(int) s6a_hss_init(void);
|
||||
CORE_DECLARE(void) s6a_hss_final(void);
|
||||
CORE_DECLARE(int) s6a_mme_init(void);
|
||||
CORE_DECLARE(void) s6a_mme_final(void);
|
||||
|
||||
CORE_DECLARE(char *) s6a_hss_config();
|
||||
CORE_DECLARE(char *) s6a_mme_config();
|
||||
CORE_DECLARE(status_t) s6a_config_apply();
|
||||
|
||||
CORE_DECLARE(int) s6a_dict_init(void);
|
||||
|
||||
CORE_DECLARE(int) mme_init(void);
|
||||
CORE_DECLARE(void) mme_final(void);
|
||||
CORE_DECLARE(int) hss_init(void);
|
||||
CORE_DECLARE(void) hss_final(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
|
Loading…
Reference in New Issue