From c05bc1a3e91cdbf03023d8526bae4448a081f705 Mon Sep 17 00:00:00 2001 From: Laurent Date: Fri, 21 Aug 2020 13:48:26 +0200 Subject: [PATCH] 5G SA authentication: authentication request, partial authentication response --- openair3/NAS/COMMON/NR_NAS_defs.h | 5 ++++- openair3/NAS/NR_UE/nr_user_def.h | 2 ++ openair3/NAS/NR_UE/ue_process_nas.c | 31 +++++++++++++++++++++++++---- openair3/UICC/usim_interface.h | 2 ++ 4 files changed, 35 insertions(+), 5 deletions(-) diff --git a/openair3/NAS/COMMON/NR_NAS_defs.h b/openair3/NAS/COMMON/NR_NAS_defs.h index 441e0db8d3..78939908c3 100644 --- a/openair3/NAS/COMMON/NR_NAS_defs.h +++ b/openair3/NAS/COMMON/NR_NAS_defs.h @@ -288,7 +288,10 @@ typedef struct { Extendedprotocoldiscriminator_t epd:8; Security_header_t sh:8; SGSmobilitymanagementmessages_t mt:8; -} authenticationresponseHeader_t; + uint8_t iei; + uint8_t RESlen; + uint8_t RES[16]; +} authenticationresponse_t; diff --git a/openair3/NAS/NR_UE/nr_user_def.h b/openair3/NAS/NR_UE/nr_user_def.h index f8fb39a39d..62658a86a7 100644 --- a/openair3/NAS/NR_UE/nr_user_def.h +++ b/openair3/NAS/NR_UE/nr_user_def.h @@ -6,7 +6,9 @@ typedef struct { uicc_t *uicc; } nr_user_nas_t; +#define STATIC_ASSERT(test_for_true) _Static_assert((test_for_true), "(" #test_for_true ") failed") #define myCalloc(var, type) type * var=(type*)calloc(sizeof(type),1); +#define arrayCpy(tO, FroM) STATIC_ASSERT(sizeof(tO) == sizeof(FroM)) ; memcpy(tO, FroM, sizeof(tO)) int identityResponse(void **msg, nr_user_nas_t *UE); #endif diff --git a/openair3/NAS/NR_UE/ue_process_nas.c b/openair3/NAS/NR_UE/ue_process_nas.c index 09c331cc28..314ed16934 100644 --- a/openair3/NAS/NR_UE/ue_process_nas.c +++ b/openair3/NAS/NR_UE/ue_process_nas.c @@ -13,6 +13,13 @@ void nas_schedule(void) { */ void SGSauthenticationReq(void *msg, nr_user_nas_t *UE) { + authenticationrequestHeader_t *amsg=(authenticationrequestHeader_t *) msg; + arrayCpy(UE->uicc->rand,amsg->RAND); + arrayCpy(UE->uicc->autn,amsg->AUTN); + nas_schedule(); +} + +void SGSidentityReq(void *msg, nr_user_nas_t *UE) { Identityrequest_t *idmsg=(Identityrequest_t *) msg; if (idmsg->it == SUCI ) { @@ -22,9 +29,6 @@ void SGSauthenticationReq(void *msg, nr_user_nas_t *UE) { LOG_E(NAS,"Not developped: identity request for %d\n", idmsg->it); } -void SGSidentityReq(void *msg, nr_user_nas_t *UE) { -} - void SGSsecurityModeCommand(void *msg, nr_user_nas_t *UE) { } @@ -109,7 +113,26 @@ int identityResponse(void **msg, nr_user_nas_t *UE) { } int authenticationResponse(void **msg,nr_user_nas_t *UE) { - return -1; + if (UE->uicc == NULL) + // config file section hardcoded as "uicc", nevertheless it opens to manage several UEs or a multi SIM UE + UE->uicc=init_uicc("uicc"); + + myCalloc(resp, authenticationresponse_t); + resp->epd=SGSmobilitymanagementmessages; + resp->sh=0; + resp->mt=Authenticationresponse; + resp->iei=IEI_AuthenticationResponse; + resp->RESlen=sizeof(resp->RES); + // Verify the AUTN + uint8_t ik[16], ck[16], res[8], AUTN[16]; + milenage_generate(UE->uicc->opc, UE->uicc->amf, UE->uicc->key, + UE->uicc->sqn, UE->uicc->rand, AUTN, ik, ck, res); + + if ( memcmp(UE-uicc->autn, AUTN ) { +} else { +} +*msg=resp; + return sizeof(authenticationresponse_t); } int securityModeComplete(void **msg, nr_user_nas_t *UE) { diff --git a/openair3/UICC/usim_interface.h b/openair3/UICC/usim_interface.h index a3fa7b1bf3..5d4ae2e16b 100644 --- a/openair3/UICC/usim_interface.h +++ b/openair3/UICC/usim_interface.h @@ -46,6 +46,8 @@ typedef struct { uint8_t amf[2]; uint8_t sqn[6]; int nmc_size; + uint8_t rand[16]; + uint8_t autn[16]; } uicc_t; /*